Ignore:
Timestamp:
May 18, 2009, 4:48:30 PM (16 years ago)
Author:
[email protected]
Message:

2009-05-18 Yichao Yin <[email protected]>

Reviewed by George Staikos (and others).

Add XHTMLMP support to Webkit
XHTMLMP is a strict subset of XHTML 1.1. It extends XHTML Basic and add enhanced
functionality. Most of the functionalities have already been implemented by Webkit.

The changes include:
1) Adding <noscript> support
2) Document conformance validation
3) User Agent conformance validation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/dom/XMLTokenizerLibxml2.cpp

    r43663 r43842  
    66 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
    77 * Copyright (C) 2008 Holger Hans Peter Freyther
    8  * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
     8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
    99 *
    1010 * This library is free software; you can redistribute it and/or
     
    6464#endif
    6565
     66#if ENABLE(XHTMLMP)
     67#include "HTMLNames.h"
     68#include "HTMLScriptElement.h"
     69#endif
     70
    6671using namespace std;
    6772
     
    527532    , m_sawFirstElement(false)
    528533    , m_isXHTMLDocument(false)
     534#if ENABLE(XHTMLMP)
     535    , m_isXHTMLMPDocument(false)
     536    , m_hasDocTypeDeclaration(false)
     537#endif
    529538    , m_parserPaused(false)
    530539    , m_requestingScript(false)
     
    550559    , m_sawFirstElement(false)
    551560    , m_isXHTMLDocument(false)
     561#if ENABLE(XHTMLMP)
     562    , m_isXHTMLMPDocument(false)
     563    , m_hasDocTypeDeclaration(false)
     564#endif
    552565    , m_parserPaused(false)
    553566    , m_requestingScript(false)
     
    705718    }
    706719
    707     bool isFirstElement = !m_sawFirstElement;
    708     m_sawFirstElement = true;
     720#if ENABLE(XHTMLMP)
     721    // check if the DOCTYPE Declaration of XHTMLMP document exists
     722    if (!m_hasDocTypeDeclaration && m_doc->isXHTMLMPDocument()) {
     723        handleError(fatal, "DOCTYPE declaration lost.", lineNumber(), columnNumber());
     724        return;
     725    }
     726#endif
    709727
    710728    exitText();
     
    721739    }
    722740
     741#if ENABLE(XHTMLMP)
     742    if (!m_sawFirstElement && isXHTMLMPDocument()) {
     743        // As per the section 7.1 of OMA-WAP-XHTMLMP-V1_1-20061020-A.pdf,
     744        // we should make sure that the root element MUST be 'html' and
     745        // ensure the name of the default namespace on the root elment 'html'
     746        // MUST be 'http://www.w3.org/1999/xhtml'
     747        if (localName != HTMLNames::htmlTag.localName()) {
     748            handleError(fatal, "XHTMLMP document expects 'html' as root element.", lineNumber(), columnNumber());
     749            return;
     750        }
     751
     752        if (uri.isNull()) {
     753            m_defaultNamespaceURI = HTMLNames::xhtmlNamespaceURI;
     754            uri = m_defaultNamespaceURI;
     755        }
     756    }
     757#endif
     758
     759    bool isFirstElement = !m_sawFirstElement;
     760    m_sawFirstElement = true;
     761
    723762    QualifiedName qName(prefix, localName, uri);
    724763    RefPtr<Element> newElement = m_doc->createElement(qName, true);
     
    799838    m_requestingScript = true;
    800839
    801     String scriptHref = scriptElement->sourceAttributeValue();
    802     if (!scriptHref.isEmpty()) {
    803         // we have a src attribute
    804         String scriptCharset = scriptElement->scriptCharset();
    805         if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) {
    806             m_scriptElement = element;
    807             m_pendingScript->addClient(this);
    808 
    809             // m_pendingScript will be 0 if script was already loaded and ref() executed it
    810             if (m_pendingScript)
    811                 pauseParsing();
    812         } else
    813             m_scriptElement = 0;
    814     } else
    815         m_view->frame()->loader()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), m_doc->url(), m_scriptStartLine));
    816 
     840#if ENABLE(XHTMLMP)
     841    if (!scriptElement->shouldExecuteAsJavaScript())
     842        m_doc->setShouldProcessNoscriptElement(true);
     843    else
     844#endif
     845    {
     846        String scriptHref = scriptElement->sourceAttributeValue();
     847        if (!scriptHref.isEmpty()) {
     848            // we have a src attribute
     849            String scriptCharset = scriptElement->scriptCharset();
     850            if ((m_pendingScript = m_doc->docLoader()->requestScript(scriptHref, scriptCharset))) {
     851                m_scriptElement = element;
     852                m_pendingScript->addClient(this);
     853
     854                // m_pendingScript will be 0 if script was already loaded and ref() executed it
     855                if (m_pendingScript)
     856                    pauseParsing();
     857            } else
     858                m_scriptElement = 0;
     859        } else
     860            m_view->frame()->loader()->executeScript(ScriptSourceCode(scriptElement->scriptContent(), m_doc->url(), m_scriptStartLine));
     861    }
    817862    m_requestingScript = false;
    818863    setCurrentNode(parent.get());
     
    943988{
    944989    exitText();
     990#if ENABLE(XHTMLMP)
     991    m_hasDocTypeDeclaration = false;
     992#endif
    945993}
    946994
     
    9561004   
    9571005    if (m_doc) {
     1006#if ENABLE(WML) || ENABLE(XHTMLMP)
     1007        String extId = toString(externalID);
     1008#endif
    9581009#if ENABLE(WML)
    959         String extId = toString(externalID);
    9601010        if (isWMLDocument()
    9611011            && extId != "-//WAPFORUM//DTD WML 1.3//EN"
     
    9651015            handleError(fatal, "Invalid DTD Public ID", lineNumber(), columnNumber());
    9661016#endif
    967 
     1017#if ENABLE(XHTMLMP)
     1018        String dtdName = toString(name);
     1019        if (extId == "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"
     1020            || extId == "-//WAPFORUM//DTD XHTML Mobile 1.1//EN") {
     1021            if (dtdName != HTMLNames::htmlTag.localName()) {
     1022                handleError(fatal, "Invalid DOCTYPE declaration, expected 'html' as root element.", lineNumber(), columnNumber());
     1023                return;
     1024            }
     1025
     1026            if (m_doc->isXHTMLMPDocument())
     1027                setIsXHTMLMPDocument(true);
     1028            else
     1029                setIsXHTMLDocument(true);
     1030
     1031            m_hasDocTypeDeclaration = true;
     1032        }
     1033#endif
     1034
     1035#if ENABLE(XHTMLMP)
     1036        m_doc->addChild(DocumentType::create(m_doc, dtdName, extId, toString(systemID)));
     1037#elif ENABLE(WML)
     1038        m_doc->addChild(DocumentType::create(m_doc, toString(name), extId, toString(systemID)));
     1039#else
    9681040        m_doc->addChild(DocumentType::create(m_doc, toString(name), toString(externalID), toString(systemID)));
     1041#endif
    9691042    }
    9701043}
     
    11091182    ent = xmlGetDocEntity(ctxt->myDoc, name);
    11101183    if (!ent && (getTokenizer(closure)->isXHTMLDocument()
     1184#if ENABLE(XHTMLMP)
     1185                 || getTokenizer(closure)->isXHTMLMPDocument()
     1186#endif
    11111187#if ENABLE(WML)
    11121188                 || getTokenizer(closure)->isWMLDocument()
     
    11501226        || (extId == "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN")
    11511227        || (extId == "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN")
    1152         || (extId == "-//WAPFORUM//DTD XHTML Mobile 1.0//EN"))
     1228#if !ENABLE(XHTMLMP)
     1229        || (extId == "-//WAPFORUM//DTD XHTML Mobile 1.0//EN")
     1230#endif
     1231       )
    11531232        getTokenizer(closure)->setIsXHTMLDocument(true); // controls if we replace entities or not.
    11541233}
Note: See TracChangeset for help on using the changeset viewer.