Commit 018de9de authored by Maks Orlovich's avatar Maks Orlovich

Fix an isolation buglet involving DOMImplementation.

svn path=/trunk/KDE/kdelibs/; revision=1125019
parent 6dd25d41
......@@ -117,7 +117,8 @@ DOMImplementation DOMImplementation::getInterface(const DOMString &feature) cons
if (!impl)
throw DOMException(DOMException::NOT_FOUND_ERR);
return impl->getInterface(feature);
// This method is a no-op for us.
return impl;
}
CSSStyleSheet DOMImplementation::createCSSStyleSheet(const DOMString &title, const DOMString &media)
......@@ -149,7 +150,7 @@ Document::Document()
: Node()
{
// we always want an implementation
impl = DOMImplementationImpl::instance()->createDocument();
impl = DOMImplementationImpl::createDocument();
impl->ref();
}
......@@ -158,7 +159,7 @@ Document::Document(bool create)
{
if(create)
{
impl = DOMImplementationImpl::instance()->createDocument();
impl = DOMImplementationImpl::createDocument();
impl->ref();
}
else
......
......@@ -34,7 +34,7 @@ using namespace DOM;
HTMLDocument::HTMLDocument() : Document(false) // create the impl here
{
impl = DOMImplementationImpl::instance()->createHTMLDocument();
impl = DOMImplementationImpl::createHTMLDocument();
impl->ref();
}
......@@ -42,7 +42,7 @@ HTMLDocument::HTMLDocument() : Document(false) // create the impl here
HTMLDocument::HTMLDocument(KHTMLView *parent)
: Document(false) // create the impl here
{
impl = DOMImplementationImpl::instance()->createHTMLDocument(parent);
impl = DOMImplementationImpl::createHTMLDocument(parent);
impl->ref();
}
......
......@@ -57,8 +57,8 @@ using namespace DOM;
using namespace khtml;
HTMLDocumentImpl::HTMLDocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v)
: DocumentImpl(_implementation, v)
HTMLDocumentImpl::HTMLDocumentImpl(KHTMLView *v)
: DocumentImpl(v)
{
// kDebug( 6090 ) << "HTMLDocumentImpl constructor this = " << this;
htmlElement = 0;
......
......@@ -44,7 +44,7 @@ class HTMLDocumentImpl : public DOM::DocumentImpl
{
Q_OBJECT
public:
HTMLDocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v = 0);
HTMLDocumentImpl(KHTMLView *v = 0);
~HTMLDocumentImpl();
virtual bool isHTMLDocument() const { return true; }
......
......@@ -1995,12 +1995,12 @@ void KHTMLPart::begin( const KUrl &url, int xOffset, int yOffset )
bool servedAsXML = mime && mime->is( "text/xml" );
// ### not sure if XHTML documents served as text/xml should use DocumentImpl or HTMLDocumentImpl
if ( servedAsSVG ) {
d->m_doc = DOMImplementationImpl::instance()->createSVGDocument( d->m_view );
d->m_doc = DOMImplementationImpl::createSVGDocument( d->m_view );
} else {
if ( servedAsXML && !servedAsXHTML ) { // any XML derivative, except XHTML
d->m_doc = DOMImplementationImpl::instance()->createXMLDocument( d->m_view );
d->m_doc = DOMImplementationImpl::createXMLDocument( d->m_view );
} else {
d->m_doc = DOMImplementationImpl::instance()->createHTMLDocument( d->m_view );
d->m_doc = DOMImplementationImpl::createHTMLDocument( d->m_view );
// HTML or XHTML? (#86446)
static_cast<HTMLDocumentImpl *>(d->m_doc)->setHTMLRequested( !servedAsXHTML );
}
......
......@@ -37,8 +37,8 @@
namespace WebCore {
SVGDocument::SVGDocument(DOMImplementation* i, Frame* frame)
: Document(i, frame)
SVGDocument::SVGDocument( Frame* frame)
: Document(frame)
{
}
......
......@@ -36,7 +36,7 @@ namespace WebCore {
class SVGDocument : public Document {
public:
SVGDocument(DOMImplementation*, Frame*);
SVGDocument(Frame*);
virtual ~SVGDocument();
virtual bool isSVGDocument() const { return true; }
......
......@@ -64,10 +64,7 @@ SVGElement::~SVGElement()
bool SVGElement::isSupported(StringImpl* feature, StringImpl* version) const
{
if (DOMImplementation::instance()->hasFeature(feature, version))
return true;
return DOMImplementation::instance()->hasFeature(feature, version);
return DOMImplementation::hasFeature(feature, version);
}
......
......@@ -78,7 +78,7 @@ bool SVGTests::isValid() const
if (m_features) {
for (unsigned long i = 0; i < m_features->numberOfItems(); i++) {
String value = m_features->getItem(i, ec);
if (value.isEmpty() || !DOMImplementation::instance()->hasFeature(value, String()))
if (value.isEmpty() || !DOMImplementation::hasFeature(value, String()))
return false;
}
}
......
......@@ -132,8 +132,6 @@ using namespace khtml;
// ------------------------------------------------------------------------
DOMImplementationImpl *DOMImplementationImpl::m_instance = 0;
DOMImplementationImpl::DOMImplementationImpl()
{
}
......@@ -197,13 +195,7 @@ DocumentTypeImpl *DOMImplementationImpl::createDocumentType( const DOMString &qu
return 0;
}
return new DocumentTypeImpl(this,0,qualifiedName,publicId,systemId);
}
DOMImplementationImpl* DOMImplementationImpl::getInterface(const DOMString& /*feature*/) const
{
// ###
return 0;
return new DocumentTypeImpl(this, 0, qualifiedName, publicId, systemId);
}
DocumentImpl *DOMImplementationImpl::createDocument( const DOMString &namespaceURI, const DOMString &qualifiedName,
......@@ -219,7 +211,10 @@ DocumentImpl *DOMImplementationImpl::createDocument( const DOMString &namespaceU
// WRONG_DOCUMENT_ERR: Raised if doctype has already been used with a different document or was
// created from a different implementation.
if (dtype && (dtype->document() || dtype->implementation() != this)) {
// We elide the "different implementation" case here, since we're not doing interop
// of different implementations, and different impl objects exist only for
// isolation reasons
if (dtype && dtype->document()) {
exceptioncode = DOMException::WRONG_DOCUMENT_ERR;
return 0;
}
......@@ -227,9 +222,9 @@ DocumentImpl *DOMImplementationImpl::createDocument( const DOMString &namespaceU
// ### view can be 0 which can cause problems
DocumentImpl* doc;
if (namespaceURI == XHTML_NAMESPACE)
doc = new HTMLDocumentImpl(this, v);
doc = new HTMLDocumentImpl(v);
else
doc = new DocumentImpl(this, v);
doc = new DocumentImpl(v);
if (dtype) {
dtype->setDocument(doc);
......@@ -264,21 +259,21 @@ CSSStyleSheetImpl *DOMImplementationImpl::createCSSStyleSheet(DOMStringImpl* tit
DocumentImpl *DOMImplementationImpl::createDocument( KHTMLView *v )
{
DocumentImpl* doc = new DocumentImpl(this, v);
DocumentImpl* doc = new DocumentImpl(v);
return doc;
}
XMLDocumentImpl *DOMImplementationImpl::createXMLDocument( KHTMLView *v )
{
XMLDocumentImpl* doc = new XMLDocumentImpl(this, v);
XMLDocumentImpl* doc = new XMLDocumentImpl(v);
return doc;
}
HTMLDocumentImpl *DOMImplementationImpl::createHTMLDocument( KHTMLView *v )
{
HTMLDocumentImpl* doc = new HTMLDocumentImpl(this, v);
HTMLDocumentImpl* doc = new HTMLDocumentImpl(v);
return doc;
}
......@@ -286,7 +281,7 @@ HTMLDocumentImpl *DOMImplementationImpl::createHTMLDocument( KHTMLView *v )
// create SVG document
WebCore::SVGDocument *DOMImplementationImpl::createSVGDocument( KHTMLView *v )
{
WebCore::SVGDocument* doc = new WebCore::SVGDocument(this, v);
WebCore::SVGDocument* doc = new WebCore::SVGDocument(v);
return doc;
}
......@@ -303,16 +298,6 @@ HTMLDocumentImpl* DOMImplementationImpl::createHTMLDocument( const DOMString& ti
return r;
}
DOMImplementationImpl *DOMImplementationImpl::instance()
{
if (!m_instance) {
m_instance = new DOMImplementationImpl();
m_instance->ref();
}
return m_instance;
}
// ------------------------------------------------------------------------
ElementMappingCache::ElementMappingCache():m_dict()
......@@ -387,7 +372,7 @@ typedef QList<DocumentImpl*> ChangedDocuments ;
K_GLOBAL_STATIC(ChangedDocuments, s_changedDocuments)
// KHTMLView might be 0
DocumentImpl::DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v)
DocumentImpl::DocumentImpl(KHTMLView *v)
: NodeBaseImpl( 0 ), m_svgExtensions(0), m_counterDict(),
m_imageLoadEventTimer(0)
{
......@@ -417,8 +402,7 @@ DocumentImpl::DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v)
m_tokenizer = 0;
m_decoder = 0;
m_doctype = 0;
m_implementation = _implementation;
m_implementation->ref();
m_implementation = 0;
pMode = Strict;
hMode = XHtml;
m_htmlCompat = false;
......@@ -532,7 +516,8 @@ DocumentImpl::~DocumentImpl()
if (m_elemSheet ) m_elemSheet->deref();
if (m_doctype)
m_doctype->deref();
m_implementation->deref();
if (m_implementation)
m_implementation->deref();
delete m_dynamicDomRestyler;
delete m_jsEditor;
m_defaultView->deref();
......@@ -559,6 +544,10 @@ DocumentImpl::~DocumentImpl()
DOMImplementationImpl *DocumentImpl::implementation() const
{
if (!m_implementation) {
m_implementation = new DOMImplementationImpl();
m_implementation->ref();
}
return m_implementation;
}
......@@ -2120,7 +2109,7 @@ WTF::PassRefPtr<NodeImpl> DocumentImpl::cloneNode ( bool deep )
#endif
int exceptioncode;
WTF::RefPtr<NodeImpl> clone = m_implementation->createDocument("",
WTF::RefPtr<NodeImpl> clone = DOMImplementationImpl::createDocument("",
"",
0, 0,
exceptioncode);
......
......@@ -114,34 +114,25 @@ public:
DOMImplementationImpl();
~DOMImplementationImpl();
// DOM methods & attributes for DOMImplementation
bool hasFeature ( const DOMString &feature, const DOMString &version );
// DOM methods & attributes for DOMImplementation.
static bool hasFeature ( const DOMString &feature, const DOMString &version );
DocumentTypeImpl *createDocumentType( const DOMString &qualifiedName, const DOMString &publicId,
const DOMString &systemId, int &exceptioncode );
DocumentImpl *createDocument( const DOMString &namespaceURI, const DOMString &qualifiedName,
static DocumentImpl *createDocument( const DOMString &namespaceURI, const DOMString &qualifiedName,
DocumentTypeImpl* dtype,
KHTMLView* v, int &exceptioncode );
DOMImplementationImpl* getInterface(const DOMString& feature) const;
// From the DOMImplementationCSS interface
CSSStyleSheetImpl *createCSSStyleSheet(DOMStringImpl *title, DOMStringImpl *media, int &exceptioncode);
static CSSStyleSheetImpl *createCSSStyleSheet(DOMStringImpl *title, DOMStringImpl *media, int &exceptioncode);
// From the HTMLDOMImplementation interface
HTMLDocumentImpl* createHTMLDocument( const DOMString& title);
static HTMLDocumentImpl* createHTMLDocument( const DOMString& title);
// Other methods (not part of DOM)
DocumentImpl *createDocument( KHTMLView *v = 0 );
XMLDocumentImpl *createXMLDocument( KHTMLView *v = 0 );
HTMLDocumentImpl *createHTMLDocument( KHTMLView *v = 0 );
WebCore::SVGDocument *createSVGDocument( KHTMLView *v = 0 );
// Returns the static instance of this class - only one instance of this class should
// ever be present, and is used as a factory method for creating DocumentImpl objects
static DOMImplementationImpl *instance();
protected:
static DOMImplementationImpl *m_instance;
static DocumentImpl *createDocument( KHTMLView *v = 0 );
static XMLDocumentImpl *createXMLDocument( KHTMLView *v = 0 );
static HTMLDocumentImpl *createHTMLDocument( KHTMLView *v = 0 );
static WebCore::SVGDocument *createSVGDocument( KHTMLView *v = 0 );
};
/**
......@@ -203,7 +194,7 @@ class DocumentImpl : public QObject, private khtml::CachedObjectClient, public N
{
Q_OBJECT
public:
DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v);
DocumentImpl(KHTMLView *v);
~DocumentImpl();
// DOM methods & attributes for Document
......@@ -640,7 +631,8 @@ protected:
QString m_baseTarget;
mutable DocumentTypeImpl *m_doctype;
DOMImplementationImpl *m_implementation;
mutable DOMImplementationImpl *m_implementation; // lazily created
QString m_usersheet;
QString m_printSheet;
......@@ -806,7 +798,7 @@ protected:
class XMLDocumentImpl : public DocumentImpl
{
public:
XMLDocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v) : DocumentImpl(_implementation, v) { }
XMLDocumentImpl(KHTMLView *v) : DocumentImpl(v) { }
virtual void close ( );
};
......
......@@ -1272,7 +1272,7 @@ bool NodeImpl::hasAttributes() const
bool NodeImpl::isSupported(const DOMString &feature, const DOMString &version)
{
return DOMImplementationImpl::instance()->hasFeature(feature, version);
return DOMImplementationImpl::hasFeature(feature, version);
}
DocumentImpl* NodeImpl::ownerDocument() const
......@@ -1454,6 +1454,7 @@ void NodeImpl::setDocument(DocumentImpl* doc)
DOM::DOMString DOM::NodeImpl::lookupNamespaceURI(const DOM::DOMString& prefix)
{
//for details see http://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#lookupNamespaceURIAlgo
switch( this->nodeType() ) {
case Node::ELEMENT_NODE:
if( !this->namespaceURI().isNull() && this->prefix() == prefix ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment