diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/WebCore/dom/DOMImplementation.cpp | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/WebCore/dom/DOMImplementation.cpp')
-rw-r--r-- | Source/WebCore/dom/DOMImplementation.cpp | 314 |
1 files changed, 77 insertions, 237 deletions
diff --git a/Source/WebCore/dom/DOMImplementation.cpp b/Source/WebCore/dom/DOMImplementation.cpp index 081c8560a..586fa1ccb 100644 --- a/Source/WebCore/dom/DOMImplementation.cpp +++ b/Source/WebCore/dom/DOMImplementation.cpp @@ -25,50 +25,46 @@ #include "config.h" #include "DOMImplementation.h" -#include "ContentType.h" #include "CSSStyleSheet.h" +#include "ContentType.h" #include "DocumentType.h" #include "Element.h" -#include "ExceptionCode.h" +#include "FTPDirectoryDocument.h" #include "Frame.h" #include "FrameLoader.h" #include "FrameLoaderClient.h" -#include "FTPDirectoryDocument.h" #include "HTMLDocument.h" -#include "HTMLViewSourceDocument.h" +#include "HTMLHeadElement.h" +#include "HTMLTitleElement.h" #include "Image.h" #include "ImageDocument.h" +#include "MIMETypeRegistry.h" +#include "MainFrame.h" #include "MediaDocument.h" #include "MediaList.h" -#include "MIMETypeRegistry.h" +#include "MediaPlayer.h" #include "Page.h" #include "PluginData.h" #include "PluginDocument.h" +#include "SVGDocument.h" +#include "SVGNames.h" #include "SecurityOrigin.h" +#include "SecurityOriginPolicy.h" #include "Settings.h" #include "StyleSheetContents.h" #include "SubframeLoader.h" +#include "Text.h" #include "TextDocument.h" -#include "XMLNames.h" +#include "XMLDocument.h" +#include <wtf/NeverDestroyed.h> #include <wtf/StdLibExtras.h> -#if ENABLE(SVG) -#include "SVGNames.h" -#include "SVGDocument.h" -#endif - namespace WebCore { -typedef HashSet<String, CaseFoldingHash> FeatureSet; - -#if ENABLE(SVG) -static void addString(FeatureSet& set, const char* string) -{ - set.add(string); -} -#endif +using namespace HTMLNames; #if ENABLE(VIDEO) + class DOMImplementationSupportsTypeClient : public MediaPlayerSupportsTypeClient { public: DOMImplementationSupportsTypeClient(bool needsHacks, const String& host) @@ -78,113 +74,13 @@ public: } private: - virtual bool mediaPlayerNeedsSiteSpecificHacks() const override { return m_needsHacks; } - virtual String mediaPlayerDocumentHost() const override { return m_host; } + bool mediaPlayerNeedsSiteSpecificHacks() const override { return m_needsHacks; } + String mediaPlayerDocumentHost() const override { return m_host; } bool m_needsHacks; String m_host; }; -#endif - -#if ENABLE(SVG) - -static bool isSupportedSVG10Feature(const String& feature, const String& version) -{ - if (!version.isEmpty() && version != "1.0") - return false; - - static bool initialized = false; - DEFINE_STATIC_LOCAL(FeatureSet, svgFeatures, ()); - if (!initialized) { -#if ENABLE(FILTERS) && ENABLE(SVG_FONTS) - addString(svgFeatures, "svg"); - addString(svgFeatures, "svg.static"); -#endif -// addString(svgFeatures, "svg.animation"); -// addString(svgFeatures, "svg.dynamic"); -// addString(svgFeatures, "svg.dom.animation"); -// addString(svgFeatures, "svg.dom.dynamic"); -#if ENABLE(FILTERS) && ENABLE(SVG_FONTS) - addString(svgFeatures, "dom"); - addString(svgFeatures, "dom.svg"); - addString(svgFeatures, "dom.svg.static"); -#endif -// addString(svgFeatures, "svg.all"); -// addString(svgFeatures, "dom.svg.all"); - initialized = true; - } - return feature.startsWith("org.w3c.", false) - && svgFeatures.contains(feature.right(feature.length() - 8)); -} - -static bool isSupportedSVG11Feature(const String& feature, const String& version) -{ - if (!version.isEmpty() && version != "1.1") - return false; - static bool initialized = false; - DEFINE_STATIC_LOCAL(FeatureSet, svgFeatures, ()); - if (!initialized) { - // Sadly, we cannot claim to implement any of the SVG 1.1 generic feature sets - // lack of Font and Filter support. - // http://bugs.webkit.org/show_bug.cgi?id=15480 -#if ENABLE(FILTERS) && ENABLE(SVG_FONTS) - addString(svgFeatures, "SVG"); - addString(svgFeatures, "SVGDOM"); - addString(svgFeatures, "SVG-static"); - addString(svgFeatures, "SVGDOM-static"); -#endif - addString(svgFeatures, "SVG-animation"); - addString(svgFeatures, "SVGDOM-animation"); -// addString(svgFeatures, "SVG-dynamic); -// addString(svgFeatures, "SVGDOM-dynamic); - addString(svgFeatures, "CoreAttribute"); - addString(svgFeatures, "Structure"); - addString(svgFeatures, "BasicStructure"); - addString(svgFeatures, "ContainerAttribute"); - addString(svgFeatures, "ConditionalProcessing"); - addString(svgFeatures, "Image"); - addString(svgFeatures, "Style"); - addString(svgFeatures, "ViewportAttribute"); - addString(svgFeatures, "Shape"); - addString(svgFeatures, "Text"); - addString(svgFeatures, "BasicText"); - addString(svgFeatures, "PaintAttribute"); - addString(svgFeatures, "BasicPaintAttribute"); - addString(svgFeatures, "OpacityAttribute"); - addString(svgFeatures, "GraphicsAttribute"); - addString(svgFeatures, "BaseGraphicsAttribute"); - addString(svgFeatures, "Marker"); -// addString(svgFeatures, "ColorProfile"); // requires color-profile, bug 6037 - addString(svgFeatures, "Gradient"); - addString(svgFeatures, "Pattern"); - addString(svgFeatures, "Clip"); - addString(svgFeatures, "BasicClip"); - addString(svgFeatures, "Mask"); -#if ENABLE(FILTERS) - addString(svgFeatures, "Filter"); - addString(svgFeatures, "BasicFilter"); -#endif - addString(svgFeatures, "DocumentEventsAttribute"); - addString(svgFeatures, "GraphicalEventsAttribute"); -// addString(svgFeatures, "AnimationEventsAttribute"); - addString(svgFeatures, "Cursor"); - addString(svgFeatures, "Hyperlinking"); - addString(svgFeatures, "XlinkAttribute"); - addString(svgFeatures, "ExternalResourcesRequired"); - addString(svgFeatures, "View"); - addString(svgFeatures, "Script"); - addString(svgFeatures, "Animation"); -#if ENABLE(SVG_FONTS) - addString(svgFeatures, "Font"); - addString(svgFeatures, "BasicFont"); -#endif - addString(svgFeatures, "Extensibility"); - initialized = true; - } - return feature.startsWith("http://www.w3.org/tr/svg11/feature#", false) - && svgFeatures.contains(feature.right(feature.length() - 35)); -} #endif DOMImplementation::DOMImplementation(Document& document) @@ -192,140 +88,81 @@ DOMImplementation::DOMImplementation(Document& document) { } -bool DOMImplementation::hasFeature(const String& feature, const String& version) -{ - if (feature.startsWith("http://www.w3.org/TR/SVG", false) - || feature.startsWith("org.w3c.dom.svg", false) - || feature.startsWith("org.w3c.svg", false)) { -#if ENABLE(SVG) - // FIXME: SVG 2.0 support? - return isSupportedSVG10Feature(feature, version) || isSupportedSVG11Feature(feature, version); -#else - UNUSED_PARAM(version); - return false; -#endif - } - - return true; -} - -PassRefPtr<DocumentType> DOMImplementation::createDocumentType(const String& qualifiedName, - const String& publicId, const String& systemId, ExceptionCode& ec) +ExceptionOr<Ref<DocumentType>> DOMImplementation::createDocumentType(const String& qualifiedName, const String& publicId, const String& systemId) { - String prefix, localName; - if (!Document::parseQualifiedName(qualifiedName, prefix, localName, ec)) - return 0; - + auto parseResult = Document::parseQualifiedName(qualifiedName); + if (parseResult.hasException()) + return parseResult.releaseException(); return DocumentType::create(m_document, qualifiedName, publicId, systemId); } -DOMImplementation* DOMImplementation::getInterface(const String& /*feature*/) +static inline Ref<XMLDocument> createXMLDocument(const String& namespaceURI) { - return 0; -} - -PassRefPtr<Document> DOMImplementation::createDocument(const String& namespaceURI, - const String& qualifiedName, DocumentType* doctype, ExceptionCode& ec) -{ - RefPtr<Document> doc; -#if ENABLE(SVG) if (namespaceURI == SVGNames::svgNamespaceURI) - doc = SVGDocument::create(0, URL()); - else -#endif + return SVGDocument::create(nullptr, URL()); if (namespaceURI == HTMLNames::xhtmlNamespaceURI) - doc = Document::createXHTML(0, URL()); - else - doc = Document::create(0, URL()); + return XMLDocument::createXHTML(nullptr, URL()); + return XMLDocument::create(nullptr, URL()); +} - doc->setSecurityOrigin(m_document.securityOrigin()); +ExceptionOr<Ref<XMLDocument>> DOMImplementation::createDocument(const String& namespaceURI, const String& qualifiedName, DocumentType* documentType) +{ + auto document = createXMLDocument(namespaceURI); + document->setContextDocument(m_document.contextDocument()); + document->setSecurityOriginPolicy(m_document.securityOriginPolicy()); - RefPtr<Node> documentElement; + RefPtr<Element> documentElement; if (!qualifiedName.isEmpty()) { - documentElement = doc->createElementNS(namespaceURI, qualifiedName, ec); - if (ec) - return 0; + ASSERT(!document->domWindow()); // If domWindow is not null, createElementNS could find CustomElementRegistry and arbitrary scripts. + auto result = document->createElementNS(namespaceURI, qualifiedName); + if (result.hasException()) + return result.releaseException(); + documentElement = result.releaseReturnValue(); } - if (doctype) - doc->appendChild(doctype); + if (documentType) + document->appendChild(*documentType); if (documentElement) - doc->appendChild(documentElement.release()); + document->appendChild(*documentElement); - return doc.release(); + return WTFMove(document); } -PassRefPtr<CSSStyleSheet> DOMImplementation::createCSSStyleSheet(const String&, const String& media, ExceptionCode&) +Ref<CSSStyleSheet> DOMImplementation::createCSSStyleSheet(const String&, const String& media) { // FIXME: Title should be set. // FIXME: Media could have wrong syntax, in which case we should generate an exception. auto sheet = CSSStyleSheet::create(StyleSheetContents::create()); - sheet.get().setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(media)); - return std::move(sheet); -} - -static inline bool isValidXMLMIMETypeChar(UChar c) -{ - // Valid characters per RFCs 3023 and 2045: - // 0-9a-zA-Z_-+~!$^{}|.%'`#&* - return isASCIIAlphanumeric(c) || c == '!' || c == '#' || c == '$' || c == '%' || c == '&' || c == '\'' || c == '*' || c == '+' - || c == '-' || c == '.' || c == '^' || c == '_' || c == '`' || c == '{' || c == '|' || c == '}' || c == '~'; + sheet->setMediaQueries(MediaQuerySet::create(media)); + return sheet; } -bool DOMImplementation::isXMLMIMEType(const String& mimeType) +Ref<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title) { - if (mimeType == "text/xml" || mimeType == "application/xml" || mimeType == "text/xsl") - return true; - - if (!mimeType.endsWith("+xml")) - return false; - - size_t slashPosition = mimeType.find('/'); - // Take into account the '+xml' ending of mimeType. - if (slashPosition == notFound || !slashPosition || slashPosition == mimeType.length() - 5) - return false; - - // Again, mimeType ends with '+xml', no need to check the validity of that substring. - for (size_t i = 0; i < mimeType.length() - 4; ++i) { - if (!isValidXMLMIMETypeChar(mimeType[i]) && i != slashPosition) - return false; + auto document = HTMLDocument::create(nullptr, URL()); + document->open(); + document->write("<!doctype html><html><head></head><body></body></html>"); + if (!title.isNull()) { + auto titleElement = HTMLTitleElement::create(titleTag, document); + titleElement->appendChild(document->createTextNode(title)); + ASSERT(document->head()); + document->head()->appendChild(titleElement); } - - return true; -} - -bool DOMImplementation::isTextMIMEType(const String& mimeType) -{ - if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) - || mimeType == "application/json" // Render JSON as text/plain. - || (mimeType.startsWith("text/") && mimeType != "text/html" - && mimeType != "text/xml" && mimeType != "text/xsl")) - return true; - - return false; -} - -PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title) -{ - RefPtr<HTMLDocument> d = HTMLDocument::create(0, URL()); - d->open(); - d->write("<!doctype html><html><body></body></html>"); - if (!title.isNull()) - d->setTitle(title); - d->setSecurityOrigin(m_document.securityOrigin()); - return d.release(); + document->setContextDocument(m_document.contextDocument()); + document->setSecurityOriginPolicy(m_document.securityOriginPolicy()); + return document; } -PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame* frame, const URL& url, bool inViewSourceMode) +Ref<Document> DOMImplementation::createDocument(const String& type, Frame* frame, const URL& url) { - if (inViewSourceMode) - return HTMLViewSourceDocument::create(frame, url, type); + // FIXME: Confusing to have this here with public DOM APIs for creating documents. This is different enough that it should perhaps be moved. + // FIXME: This function is doing case insensitive comparisons on MIME types. Should do equalLettersIgnoringASCIICase instead. // Plugins cannot take HTML and XHTML from us, and we don't even need to initialize the plugin database for those. if (type == "text/html") return HTMLDocument::create(frame, url); if (type == "application/xhtml+xml") - return Document::createXHTML(frame, url); + return XMLDocument::createXHTML(frame, url); #if ENABLE(FTPDIR) // Plugins cannot take FTP from us either @@ -333,10 +170,14 @@ PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame return FTPDirectoryDocument::create(frame, url); #endif - PluginData* pluginData = 0; - PluginData::AllowedPluginTypes allowedPluginTypes = PluginData::OnlyApplicationPlugins; + // If we want to useImageDocumentForSubframePDF, we'll let that override plugin support. + if (frame && !frame->isMainFrame() && MIMETypeRegistry::isPDFMIMEType(type) && frame->settings().useImageDocumentForSubframePDF()) + return ImageDocument::create(*frame, url); + + PluginData* pluginData = nullptr; + auto allowedPluginTypes = PluginData::OnlyApplicationPlugins; if (frame && frame->page()) { - if (frame->loader().subframeLoader().allowPlugins(NotAboutToInstantiatePlugin)) + if (frame->loader().subframeLoader().allowPlugins()) allowedPluginTypes = PluginData::AllPlugins; pluginData = &frame->page()->pluginData(); @@ -344,36 +185,35 @@ PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame // PDF is one image type for which a plugin can override built-in support. // We do not want QuickTime to take over all image types, obviously. - if ((MIMETypeRegistry::isPDFOrPostScriptMIMEType(type)) && pluginData && pluginData->supportsMimeType(type, allowedPluginTypes)) + if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(type) && pluginData && pluginData->supportsWebVisibleMimeType(type, allowedPluginTypes)) return PluginDocument::create(frame, url); if (Image::supportsType(type)) - return ImageDocument::create(frame, url); + return ImageDocument::create(*frame, url); -#if ENABLE(VIDEO) && !ENABLE(PLUGIN_PROXY_FOR_VIDEO) - // Check to see if the type can be played by our MediaPlayer, if so create a MediaDocument +#if ENABLE(VIDEO) + // Check to see if the type can be played by our MediaPlayer, if so create a MediaDocument // Key system is not applicable here. DOMImplementationSupportsTypeClient client(frame && frame->settings().needsSiteSpecificQuirks(), url.host()); MediaEngineSupportParameters parameters; parameters.type = type; parameters.url = url; if (MediaPlayer::supportsType(parameters, &client)) - return MediaDocument::create(frame, url); + return MediaDocument::create(frame, url); #endif // Everything else except text/plain can be overridden by plugins. In particular, Adobe SVG Viewer should be used for SVG, if installed. // Disallowing plug-ins to use text/plain prevents plug-ins from hijacking a fundamental type that the browser is expected to handle, // and also serves as an optimization to prevent loading the plug-in database in the common case. - if (type != "text/plain" && ((pluginData && pluginData->supportsMimeType(type, allowedPluginTypes)) || (frame && frame->loader().client().shouldAlwaysUsePluginDocument(type)))) + if (type != "text/plain" && ((pluginData && pluginData->supportsWebVisibleMimeType(type, allowedPluginTypes)) || (frame && frame->loader().client().shouldAlwaysUsePluginDocument(type)))) return PluginDocument::create(frame, url); - if (isTextMIMEType(type)) + if (MIMETypeRegistry::isTextMIMEType(type)) return TextDocument::create(frame, url); -#if ENABLE(SVG) if (type == "image/svg+xml") return SVGDocument::create(frame, url); -#endif - if (isXMLMIMEType(type)) - return Document::create(frame, url); + + if (MIMETypeRegistry::isXMLMIMEType(type)) + return XMLDocument::create(frame, url); return HTMLDocument::create(frame, url); } |