DOMImplementation.cpp [plain text]
#include "config.h"
#include "DOMImplementation.h"
#include "CSSStyleSheet.h"
#include "DocumentType.h"
#include "Element.h"
#include "ExceptionCode.h"
#include "HTMLDocument.h"
#include "MediaList.h"
#include "RegularExpression.h"
#include "TextDocument.h"
namespace WebCore {
static bool qualifiedNameIsMalformed(const String&)
{
return false;
}
DOMImplementation::~DOMImplementation()
{
}
bool DOMImplementation::hasFeature (const String& feature, const String& version) const
{
String lower = feature.lower();
if (lower == "core" || lower == "html" || lower == "xml" || lower == "xhtml")
return version.isEmpty() || version == "1.0" || version == "2.0";
if (lower == "css"
|| lower == "css2"
|| lower == "events"
|| lower == "htmlevents"
|| lower == "mouseevents"
|| lower == "mutationevents"
|| lower == "range"
|| lower == "stylesheets"
|| lower == "traversal"
|| lower == "uievents"
|| lower == "views")
return version.isEmpty() || version == "2.0";
if (lower == "xpath")
return version.isEmpty() || version == "3.0";
return false;
}
PassRefPtr<DocumentType> DOMImplementation::createDocumentType(const String& qualifiedName,
const String& publicId, const String& systemId, ExceptionCode& ec)
{
if (qualifiedName.isNull()) {
ec = NAMESPACE_ERR;
return 0;
}
String prefix, localName;
if (!Document::parseQualifiedName(qualifiedName, prefix, localName)) {
ec = INVALID_CHARACTER_ERR;
return 0;
}
if (qualifiedNameIsMalformed(qualifiedName)) {
ec = NAMESPACE_ERR;
return 0;
}
ec = 0;
return new DocumentType(this, 0, qualifiedName, publicId, systemId);
}
DOMImplementation* DOMImplementation::getInterface(const String& ) const
{
return 0;
}
PassRefPtr<Document> DOMImplementation::createDocument(const String& namespaceURI,
const String& qualifiedName, DocumentType* doctype, ExceptionCode& ec)
{
if (!qualifiedName.isEmpty()) {
String prefix, localName;
if (!Document::parseQualifiedName(qualifiedName, prefix, localName)) {
ec = INVALID_CHARACTER_ERR;
return 0;
}
int colonpos = -1;
unsigned i;
StringImpl *qname = qualifiedName.impl();
for (i = 0; i < qname->length() && colonpos < 0; i++) {
if ((*qname)[i] == ':')
colonpos = i;
}
if (qualifiedNameIsMalformed(qualifiedName) ||
(colonpos >= 0 && namespaceURI.isNull()) ||
(colonpos == 3 && qualifiedName[0] == 'x' && qualifiedName[1] == 'm' && qualifiedName[2] == 'l' &&
namespaceURI != "http://www.w3.org/XML/1998/namespace")) {
ec = NAMESPACE_ERR;
return 0;
}
}
if (doctype && (doctype->document() || doctype->implementation() != this)) {
ec = WRONG_DOCUMENT_ERR;
return 0;
}
RefPtr<Document> doc = new Document(this, 0);
if (doctype)
doc->setDocType(new DocumentType(doc.get(), *doctype));
if (!qualifiedName.isEmpty())
doc->addChild(doc->createElementNS(namespaceURI, qualifiedName, ec));
ec = 0;
return doc.release();
}
PassRefPtr<CSSStyleSheet> DOMImplementation::createCSSStyleSheet(const String&, const String& media, ExceptionCode& ec)
{
ec = 0;
CSSStyleSheet* const nullSheet = 0;
RefPtr<CSSStyleSheet> sheet = new CSSStyleSheet(nullSheet);
sheet->setMedia(new MediaList(sheet.get(), media, true));
return sheet.release();
}
PassRefPtr<Document> DOMImplementation::createDocument(FrameView* v)
{
return new Document(this, v);
}
PassRefPtr<HTMLDocument> DOMImplementation::createHTMLDocument(FrameView* v)
{
return new HTMLDocument(this, v);
}
DOMImplementation* DOMImplementation::instance()
{
static RefPtr<DOMImplementation> i = new DOMImplementation;
return i.get();
}
bool DOMImplementation::isXMLMIMEType(const String& mimeType)
{
if (mimeType == "text/xml" || mimeType == "application/xml" || mimeType == "text/xsl")
return true;
static const char* validChars = "[0-9a-zA-Z_\\-+~!$\\^{}|.%'`#&*]"; static RegularExpression xmlTypeRegExp(DeprecatedString("^") + validChars + "+/" + validChars + "+\\+xml$");
if (xmlTypeRegExp.match(mimeType.deprecatedString()) > -1)
return true;
return false;
}
bool DOMImplementation::isTextMIMEType(const String& mimeType)
{
if (mimeType == "application/x-javascript" ||
(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 = createHTMLDocument();
d->open();
d->write("<html><head><title>" + title + "</title></head><body></body></html>");
return d.release();
}
}