Changeset 206462 in webkit


Ignore:
Timestamp:
Sep 27, 2016 1:55:20 PM (8 years ago)
Author:
Chris Dumez
Message:

It should be possible to dispatch events on documents that do not have a browsing context
https://bugs.webkit.org/show_bug.cgi?id=162620

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

  • web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt:
  • web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt:

Rebaseline several W3C tests now that more checks are passing.

  • web-platform-tests/dom/events/Event-dispatch-other-document-expected.txt: Added.
  • web-platform-tests/dom/events/Event-dispatch-other-document.html: Added.
  • web-platform-tests/dom/events/w3c-import.log:

Import more test coverage from W3C.

Source/WebCore:

It should be possible to dispatch events on documents that do not have a browsing
context (e.g. Documents created using DOMImplementation.createHTMLDocument()).
Gecko and Blink both allow this but WebKit did not.

The approach chosen to support this is similar to the one in Blink. When constructing
a new document (e.g. using DOMImplementation.createHTMLDocument()) we now keep track
of the context document. When requesting the scriptExecutionContext(), we now return
the context document if the document has one instead of the document itself.

Test: imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html

  • bindings/js/JSDocumentCustom.cpp:

(WebCore::JSDocument::visitAdditionalChildren):

  • dom/DOMImplementation.cpp:

(WebCore::DOMImplementation::createDocument):
(WebCore::DOMImplementation::createHTMLDocument):

  • dom/Document.cpp:

(WebCore::Document::create):
(WebCore::Document::cloneDataFromDocument):
(WebCore::Document::contextDocument):
(WebCore::Document::takeDOMWindowFrom): Deleted.

  • dom/Document.h:

(WebCore::Document::setContextDocument):
(WebCore::Node::scriptExecutionContext):
(WebCore::Node::isDocumentNode): Deleted.

  • dom/Document.idl:
  • xml/XMLHttpRequest.cpp:

(WebCore::XMLHttpRequest::responseXML):

Location:
trunk
Files:
2 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r206453 r206462  
     12016-09-27  Chris Dumez  <cdumez@apple.com>
     2
     3        It should be possible to dispatch events on documents that do not have a browsing context
     4        https://bugs.webkit.org/show_bug.cgi?id=162620
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt:
     9        * web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt:
     10        Rebaseline several W3C tests now that more checks are passing.
     11
     12        * web-platform-tests/dom/events/Event-dispatch-other-document-expected.txt: Added.
     13        * web-platform-tests/dom/events/Event-dispatch-other-document.html: Added.
     14        * web-platform-tests/dom/events/w3c-import.log:
     15        Import more test coverage from W3C.
     16
    1172016-09-27  Chris Dumez  <cdumez@apple.com>
    218
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt

    r200309 r206462  
    22PASS In window.document with click event
    33PASS In window.document with load event
    4 FAIL In window.document.cloneNode(true) assert_array_equals: targets lengths differ, expected 8 got 0
    5 FAIL In new Document() assert_array_equals: targets lengths differ, expected 8 got 0
    6 FAIL In DOMImplementation.createHTMLDocument() assert_array_equals: targets lengths differ, expected 8 got 0
     4PASS In window.document.cloneNode(true)
     5PASS In new Document()
     6PASS In DOMImplementation.createHTMLDocument()
    77
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt

    r203164 r206462  
    22PASS In window.document with click event
    33PASS In window.document with load event
    4 FAIL In window.document.cloneNode(true) assert_array_equals: targets lengths differ, expected 14 got 0
    5 FAIL In new Document() assert_array_equals: targets lengths differ, expected 14 got 0
    6 FAIL In DOMImplementation.createHTMLDocument() assert_array_equals: targets lengths differ, expected 14 got 0
     4PASS In window.document.cloneNode(true)
     5PASS In new Document()
     6PASS In DOMImplementation.createHTMLDocument()
    77
  • trunk/LayoutTests/imported/w3c/web-platform-tests/dom/events/w3c-import.log

    r204079 r206462  
    3030/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-omitted-capture.html
    3131/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-order.html
     32/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html
    3233/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-propagation-stopped.html
    3334/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-redispatch.html
  • trunk/Source/WebCore/ChangeLog

    r206457 r206462  
     12016-09-27  Chris Dumez  <cdumez@apple.com>
     2
     3        It should be possible to dispatch events on documents that do not have a browsing context
     4        https://bugs.webkit.org/show_bug.cgi?id=162620
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        It should be possible to dispatch events on documents that do not have a browsing
     9        context (e.g. Documents created using DOMImplementation.createHTMLDocument()).
     10        Gecko and Blink both allow this but WebKit did not.
     11
     12        The approach chosen to support this is similar to the one in Blink. When constructing
     13        a new document (e.g. using DOMImplementation.createHTMLDocument()) we now keep track
     14        of the context document. When requesting the scriptExecutionContext(), we now return
     15        the context document if the document has one instead of the document itself.
     16
     17        Test: imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html
     18
     19        * bindings/js/JSDocumentCustom.cpp:
     20        (WebCore::JSDocument::visitAdditionalChildren):
     21        * dom/DOMImplementation.cpp:
     22        (WebCore::DOMImplementation::createDocument):
     23        (WebCore::DOMImplementation::createHTMLDocument):
     24        * dom/Document.cpp:
     25        (WebCore::Document::create):
     26        (WebCore::Document::cloneDataFromDocument):
     27        (WebCore::Document::contextDocument):
     28        (WebCore::Document::takeDOMWindowFrom): Deleted.
     29        * dom/Document.h:
     30        (WebCore::Document::setContextDocument):
     31        (WebCore::Node::scriptExecutionContext):
     32        (WebCore::Node::isDocumentNode): Deleted.
     33        * dom/Document.idl:
     34        * xml/XMLHttpRequest.cpp:
     35        (WebCore::XMLHttpRequest::responseXML):
     36
    1372016-09-27  Alex Christensen  <achristensen@webkit.org>
    238
  • trunk/Source/WebCore/bindings/js/JSDocumentCustom.cpp

    r206386 r206462  
    176176void JSDocument::visitAdditionalChildren(SlotVisitor& visitor)
    177177{
    178     visitor.addOpaqueRoot(wrapped().scriptExecutionContext());
     178    visitor.addOpaqueRoot(static_cast<ScriptExecutionContext*>(&wrapped()));
    179179}
    180180
  • trunk/Source/WebCore/dom/DOMImplementation.cpp

    r205468 r206462  
    115115{
    116116    auto document = createXMLDocument(namespaceURI);
    117 
     117    document->setContextDocument(m_document.contextDocument());
    118118    document->setSecurityOriginPolicy(m_document.securityOriginPolicy());
    119119
     
    154154        document->head()->appendChild(titleElement);
    155155    }
     156    document->setContextDocument(m_document.contextDocument());
    156157    document->setSecurityOriginPolicy(m_document.securityOriginPolicy());
    157158    return document;
  • trunk/Source/WebCore/dom/Document.cpp

    r206395 r206462  
    577577#endif
    578578
    579 Ref<Document> Document::create(ScriptExecutionContext& context)
     579Ref<Document> Document::create(Document& contextDocument)
    580580{
    581581    Ref<Document> document = adoptRef(*new Document(nullptr, URL()));
    582     document->setSecurityOriginPolicy(context.securityOriginPolicy());
     582    document->setContextDocument(contextDocument);
     583    document->setSecurityOriginPolicy(contextDocument.securityOriginPolicy());
    583584
    584585    return document;
     
    35063507
    35073508    setCompatibilityMode(other.m_compatibilityMode);
     3509    setContextDocument(other.contextDocument());
    35083510    setSecurityOriginPolicy(other.securityOriginPolicy());
    35093511    overrideMIMEType(other.contentType());
     
    41124114    ASSERT(m_domWindow->document() == this);
    41134115    ASSERT(m_domWindow->frame() == m_frame);
     4116}
     4117
     4118Document& Document::contextDocument() const
     4119{
     4120    if (m_contextDocument)
     4121        return *m_contextDocument.get();
     4122    return const_cast<Document&>(*this);
    41144123}
    41154124
  • trunk/Source/WebCore/dom/Document.h

    r206395 r206462  
    298298        return adoptRef(*new Document(frame, url, DefaultDocumentClass, NonRenderedPlaceholder));
    299299    }
    300     static Ref<Document> create(ScriptExecutionContext&);
     300    static Ref<Document> create(Document&);
    301301
    302302    virtual ~Document();
     
    771771    // In DOM Level 2, the Document's DOMWindow is called the defaultView.
    772772    DOMWindow* defaultView() const { return domWindow(); }
     773
     774    Document& contextDocument() const;
     775    void setContextDocument(Document& document) { m_contextDocument = document.createWeakPtr(); }
    773776
    774777    // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
     
    14121415    Frame* m_frame;
    14131416    RefPtr<DOMWindow> m_domWindow;
     1417    WeakPtr<Document> m_contextDocument;
    14141418
    14151419    Ref<CachedResourceLoader> m_cachedResourceLoader;
     
    17921796inline ScriptExecutionContext* Node::scriptExecutionContext() const
    17931797{
    1794     return &document();
     1798    return &document().contextDocument();
    17951799}
    17961800
  • trunk/Source/WebCore/dom/Document.idl

    r205411 r206462  
    2121[
    2222    Constructor,
    23     ConstructorCallWith=ScriptExecutionContext,
     23    ConstructorCallWith=Document,
    2424    CustomToJSObject,
    2525    ExportMacro=WEBCORE_EXPORT,
  • trunk/Source/WebCore/xml/XMLHttpRequest.cpp

    r206254 r206462  
    200200            // FIXME: Set Last-Modified.
    201201            m_responseDocument->setContent(m_responseBuilder.toStringPreserveCapacity());
     202            m_responseDocument->setContextDocument(downcast<Document>(*scriptExecutionContext()));
    202203            m_responseDocument->setSecurityOriginPolicy(scriptExecutionContext()->securityOriginPolicy());
    203204            m_responseDocument->overrideMIMEType(mimeType);
Note: See TracChangeset for help on using the changeset viewer.