This source file includes following definitions.
- addString
- isSupportedSVG10Feature
- isSupportedSVG11Feature
- hasFeature
- hasFeatureForBindings
- createDocumentType
- getInterface
- createDocument
- createCSSStyleSheet
- isXMLMIMEType
- isJSONMIMEType
- isTextPlainType
- isTextMIMEType
- createHTMLDocument
- createDocument
- createDocument
#include "config.h"
#include "core/dom/DOMImplementation.h"
#include "HTMLNames.h"
#include "SVGNames.h"
#include "bindings/v8/ExceptionState.h"
#include "core/css/CSSStyleSheet.h"
#include "core/css/MediaList.h"
#include "core/css/StyleSheetContents.h"
#include "core/dom/ContextFeatures.h"
#include "core/dom/DocumentInit.h"
#include "core/dom/DocumentType.h"
#include "core/dom/Element.h"
#include "core/dom/ExceptionCode.h"
#include "core/dom/XMLDocument.h"
#include "core/dom/custom/CustomElementRegistrationContext.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/UseCounter.h"
#include "core/html/HTMLDocument.h"
#include "core/html/HTMLMediaElement.h"
#include "core/html/HTMLViewSourceDocument.h"
#include "core/html/ImageDocument.h"
#include "core/html/MediaDocument.h"
#include "core/html/PluginDocument.h"
#include "core/html/TextDocument.h"
#include "core/loader/FrameLoader.h"
#include "core/page/Page.h"
#include "core/svg/SVGDocument.h"
#include "platform/ContentType.h"
#include "platform/MIMETypeRegistry.h"
#include "platform/graphics/Image.h"
#include "platform/graphics/media/MediaPlayer.h"
#include "platform/plugins/PluginData.h"
#include "platform/weborigin/SecurityOrigin.h"
#include "wtf/StdLibExtras.h"
namespace WebCore {
typedef HashSet<String, CaseFoldingHash> FeatureSet;
static void addString(FeatureSet& set, const char* string)
{
set.add(string);
}
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(SVG_FONTS)
addString(svgFeatures, "svg");
addString(svgFeatures, "svg.static");
#endif
#if ENABLE(SVG_FONTS)
addString(svgFeatures, "dom");
addString(svgFeatures, "dom.svg");
addString(svgFeatures, "dom.svg.static");
#endif
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) {
#if 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, "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, "Gradient");
addString(svgFeatures, "Pattern");
addString(svgFeatures, "Clip");
addString(svgFeatures, "BasicClip");
addString(svgFeatures, "Mask");
addString(svgFeatures, "Filter");
addString(svgFeatures, "BasicFilter");
addString(svgFeatures, "DocumentEventsAttribute");
addString(svgFeatures, "GraphicalEventsAttribute");
addString(svgFeatures, "Cursor");
addString(svgFeatures, "Hyperlinking");
addString(svgFeatures, "XlinkAttribute");
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));
}
DOMImplementation::DOMImplementation(Document& document)
: m_document(document)
{
ScriptWrappable::init(this);
}
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)) {
return isSupportedSVG10Feature(feature, version) || isSupportedSVG11Feature(feature, version);
}
return true;
}
bool DOMImplementation::hasFeatureForBindings(const String& feature, const String& version)
{
if (!hasFeature(feature, version)) {
UseCounter::count(m_document, UseCounter::DOMImplementationHasFeatureReturnFalse);
return false;
}
return true;
}
PassRefPtr<DocumentType> DOMImplementation::createDocumentType(const AtomicString& qualifiedName,
const String& publicId, const String& systemId, ExceptionState& exceptionState)
{
AtomicString prefix, localName;
if (!Document::parseQualifiedName(qualifiedName, prefix, localName, exceptionState))
return nullptr;
return DocumentType::create(&m_document, qualifiedName, publicId, systemId);
}
DOMImplementation* DOMImplementation::getInterface(const String& )
{
return 0;
}
PassRefPtr<XMLDocument> DOMImplementation::createDocument(const AtomicString& namespaceURI,
const AtomicString& qualifiedName, DocumentType* doctype, ExceptionState& exceptionState)
{
RefPtr<XMLDocument> doc;
DocumentInit init = DocumentInit::fromContext(m_document.contextDocument());
if (namespaceURI == SVGNames::svgNamespaceURI) {
doc = SVGDocument::create(init);
} else if (namespaceURI == HTMLNames::xhtmlNamespaceURI) {
doc = XMLDocument::createXHTML(init.withRegistrationContext(m_document.registrationContext()));
} else {
doc = XMLDocument::create(init);
}
doc->setSecurityOrigin(m_document.securityOrigin()->isolatedCopy());
doc->setContextFeatures(m_document.contextFeatures());
RefPtr<Node> documentElement;
if (!qualifiedName.isEmpty()) {
documentElement = doc->createElementNS(namespaceURI, qualifiedName, exceptionState);
if (exceptionState.hadException())
return nullptr;
}
if (doctype)
doc->appendChild(doctype);
if (documentElement)
doc->appendChild(documentElement.release());
return doc.release();
}
PassRefPtrWillBeRawPtr<CSSStyleSheet> DOMImplementation::createCSSStyleSheet(const String&, const String& media)
{
RefPtrWillBeRawPtr<CSSStyleSheet> sheet = CSSStyleSheet::create(StyleSheetContents::create(strictCSSParserContext()));
sheet->setMediaQueries(MediaQuerySet::create(media));
return sheet;
}
bool DOMImplementation::isXMLMIMEType(const String& mimeType)
{
if (equalIgnoringCase(mimeType, "text/xml")
|| equalIgnoringCase(mimeType, "application/xml")
|| equalIgnoringCase(mimeType, "text/xsl"))
return true;
int length = mimeType.length();
if (length < 7)
return false;
if (mimeType[0] == '/' || mimeType[length - 5] == '/' || !mimeType.endsWith("+xml", false))
return false;
bool hasSlash = false;
for (int i = 0; i < length - 4; ++i) {
UChar ch = mimeType[i];
if (ch >= '0' && ch <= '9')
continue;
if (ch >= 'a' && ch <= 'z')
continue;
if (ch >= 'A' && ch <= 'Z')
continue;
switch (ch) {
case '_':
case '-':
case '+':
case '~':
case '!':
case '$':
case '^':
case '{':
case '}':
case '|':
case '.':
case '%':
case '\'':
case '`':
case '#':
case '&':
case '*':
continue;
case '/':
if (hasSlash)
return false;
hasSlash = true;
continue;
default:
return false;
}
}
return true;
}
bool DOMImplementation::isJSONMIMEType(const String& mimeType)
{
if (mimeType.startsWith("application/json", false))
return true;
if (mimeType.startsWith("application/", false)) {
size_t subtype = mimeType.find("+json", 12, false);
if (subtype != kNotFound) {
size_t parameterMarker = mimeType.find(";");
if (parameterMarker == kNotFound) {
unsigned endSubtype = static_cast<unsigned>(subtype) + 5;
return endSubtype == mimeType.length() || isASCIISpace(mimeType[endSubtype]);
}
return parameterMarker > subtype;
}
}
return false;
}
static bool isTextPlainType(const String& mimeType)
{
return mimeType.startsWith("text/", false)
&& !(equalIgnoringCase(mimeType, "text/html")
|| equalIgnoringCase(mimeType, "text/xml")
|| equalIgnoringCase(mimeType, "text/xsl"));
}
bool DOMImplementation::isTextMIMEType(const String& mimeType)
{
return MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || isJSONMIMEType(mimeType) || isTextPlainType(mimeType);
}
PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title)
{
DocumentInit init = DocumentInit::fromContext(m_document.contextDocument())
.withRegistrationContext(m_document.registrationContext());
RefPtr<HTMLDocument> d = HTMLDocument::create(init);
d->open();
d->write("<!doctype html><html><body></body></html>");
if (!title.isNull())
d->setTitle(title);
d->setSecurityOrigin(m_document.securityOrigin()->isolatedCopy());
d->setContextFeatures(m_document.contextFeatures());
return d.release();
}
PassRefPtr<Document> DOMImplementation::createDocument(const String& type, LocalFrame* frame, const KURL& url, bool inViewSourceMode)
{
return createDocument(type, DocumentInit(url, frame), inViewSourceMode);
}
PassRefPtr<Document> DOMImplementation::createDocument(const String& type, const DocumentInit& init, bool inViewSourceMode)
{
if (inViewSourceMode)
return HTMLViewSourceDocument::create(init, type);
if (type == "text/html")
return HTMLDocument::create(init);
if (type == "application/xhtml+xml")
return XMLDocument::createXHTML(init);
PluginData* pluginData = 0;
if (init.frame() && init.frame()->page() && init.frame()->loader().allowPlugins(NotAboutToInstantiatePlugin))
pluginData = init.frame()->page()->pluginData();
if ((type == "application/pdf" || type == "text/pdf") && pluginData && pluginData->supportsMimeType(type))
return PluginDocument::create(init);
if (Image::supportsType(type))
return ImageDocument::create(init);
if (HTMLMediaElement::supportsType(ContentType(type)))
return MediaDocument::create(init);
if (type != "text/plain" && pluginData && pluginData->supportsMimeType(type))
return PluginDocument::create(init);
if (isTextMIMEType(type))
return TextDocument::create(init);
if (type == "image/svg+xml")
return SVGDocument::create(init);
if (isXMLMIMEType(type))
return XMLDocument::create(init);
return HTMLDocument::create(init);
}
}