| Differences between
and this patch
- a/Source/WebCore/ChangeLog +36 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2016-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 NOBODY (OOPS!).
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
1
2016-09-26  Wenson Hsieh  <wenson_hsieh@apple.com>
37
2016-09-26  Wenson Hsieh  <wenson_hsieh@apple.com>
2
38
3
        Seeking video doesn't update seek position
39
        Seeking video doesn't update seek position
- a/Source/WebCore/bindings/js/JSDocumentCustom.cpp -1 / +1 lines
Lines 175-181 JSValue JSDocument::getCSSCanvasContext(JSC::ExecState& state) a/Source/WebCore/bindings/js/JSDocumentCustom.cpp_sec1
175
175
176
void JSDocument::visitAdditionalChildren(SlotVisitor& visitor)
176
void JSDocument::visitAdditionalChildren(SlotVisitor& visitor)
177
{
177
{
178
    visitor.addOpaqueRoot(wrapped().scriptExecutionContext());
178
    visitor.addOpaqueRoot(static_cast<ScriptExecutionContext*>(&wrapped()));
179
}
179
}
180
180
181
} // namespace WebCore
181
} // namespace WebCore
- a/Source/WebCore/dom/DOMImplementation.cpp -1 / +2 lines
Lines 114-120 static inline Ref<XMLDocument> createXMLDocument(const String& namespaceURI) a/Source/WebCore/dom/DOMImplementation.cpp_sec1
114
ExceptionOr<Ref<XMLDocument>> DOMImplementation::createDocument(const String& namespaceURI, const String& qualifiedName, DocumentType* documentType)
114
ExceptionOr<Ref<XMLDocument>> DOMImplementation::createDocument(const String& namespaceURI, const String& qualifiedName, DocumentType* documentType)
115
{
115
{
116
    auto document = createXMLDocument(namespaceURI);
116
    auto document = createXMLDocument(namespaceURI);
117
117
    document->setContextDocument(m_document.contextDocument());
118
    document->setSecurityOriginPolicy(m_document.securityOriginPolicy());
118
    document->setSecurityOriginPolicy(m_document.securityOriginPolicy());
119
119
120
    RefPtr<Element> documentElement;
120
    RefPtr<Element> documentElement;
Lines 153-158 Ref<HTMLDocument> DOMImplementation::createHTMLDocument(const String& title) a/Source/WebCore/dom/DOMImplementation.cpp_sec2
153
        ASSERT(document->head());
153
        ASSERT(document->head());
154
        document->head()->appendChild(titleElement);
154
        document->head()->appendChild(titleElement);
155
    }
155
    }
156
    document->setContextDocument(m_document.contextDocument());
156
    document->setSecurityOriginPolicy(m_document.securityOriginPolicy());
157
    document->setSecurityOriginPolicy(m_document.securityOriginPolicy());
157
    return document;
158
    return document;
158
}
159
}
- a/Source/WebCore/dom/Document.cpp -2 / +11 lines
Lines 576-585 static bool isAttributeOnAllOwners(const WebCore::QualifiedName& attribute, cons a/Source/WebCore/dom/Document.cpp_sec1
576
}
576
}
577
#endif
577
#endif
578
578
579
Ref<Document> Document::create(ScriptExecutionContext& context)
579
Ref<Document> Document::create(Document& contextDocument)
580
{
580
{
581
    Ref<Document> document = adoptRef(*new Document(nullptr, URL()));
581
    Ref<Document> document = adoptRef(*new Document(nullptr, URL()));
582
    document->setSecurityOriginPolicy(context.securityOriginPolicy());
582
    document->setContextDocument(contextDocument);
583
    document->setSecurityOriginPolicy(contextDocument.securityOriginPolicy());
583
584
584
    return document;
585
    return document;
585
}
586
}
Lines 3505-3510 void Document::cloneDataFromDocument(const Document& other) a/Source/WebCore/dom/Document.cpp_sec2
3505
    m_documentURI = other.documentURI();
3506
    m_documentURI = other.documentURI();
3506
3507
3507
    setCompatibilityMode(other.m_compatibilityMode);
3508
    setCompatibilityMode(other.m_compatibilityMode);
3509
    setContextDocument(other.contextDocument());
3508
    setSecurityOriginPolicy(other.securityOriginPolicy());
3510
    setSecurityOriginPolicy(other.securityOriginPolicy());
3509
    overrideMIMEType(other.contentType());
3511
    overrideMIMEType(other.contentType());
3510
    setDecoder(other.decoder());
3512
    setDecoder(other.decoder());
Lines 4113-4118 void Document::takeDOMWindowFrom(Document* document) a/Source/WebCore/dom/Document.cpp_sec3
4113
    ASSERT(m_domWindow->frame() == m_frame);
4115
    ASSERT(m_domWindow->frame() == m_frame);
4114
}
4116
}
4115
4117
4118
Document& Document::contextDocument() const
4119
{
4120
    if (m_contextDocument)
4121
        return *m_contextDocument.get();
4122
    return const_cast<Document&>(*this);
4123
}
4124
4116
void Document::setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& attributeValue)
4125
void Document::setAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& attributeValue)
4117
{
4126
{
4118
    setAttributeEventListener(eventType, JSLazyEventListener::create(*this, attributeName, attributeValue));
4127
    setAttributeEventListener(eventType, JSLazyEventListener::create(*this, attributeName, attributeValue));
- a/Source/WebCore/dom/Document.h -2 / +6 lines
Lines 297-303 public: a/Source/WebCore/dom/Document.h_sec1
297
    {
297
    {
298
        return adoptRef(*new Document(frame, url, DefaultDocumentClass, NonRenderedPlaceholder));
298
        return adoptRef(*new Document(frame, url, DefaultDocumentClass, NonRenderedPlaceholder));
299
    }
299
    }
300
    static Ref<Document> create(ScriptExecutionContext&);
300
    static Ref<Document> create(Document&);
301
301
302
    virtual ~Document();
302
    virtual ~Document();
303
303
Lines 771-776 public: a/Source/WebCore/dom/Document.h_sec2
771
    // In DOM Level 2, the Document's DOMWindow is called the defaultView.
771
    // In DOM Level 2, the Document's DOMWindow is called the defaultView.
772
    DOMWindow* defaultView() const { return domWindow(); } 
772
    DOMWindow* defaultView() const { return domWindow(); } 
773
773
774
    Document& contextDocument() const;
775
    void setContextDocument(Document& document) { m_contextDocument = document.createWeakPtr(); }
776
774
    // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
777
    // Helper functions for forwarding DOMWindow event related tasks to the DOMWindow if it exists.
775
    void setWindowAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
778
    void setWindowAttributeEventListener(const AtomicString& eventType, const QualifiedName& attributeName, const AtomicString& value);
776
    void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
779
    void setWindowAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener>);
Lines 1411-1416 private: a/Source/WebCore/dom/Document.h_sec3
1411
1414
1412
    Frame* m_frame;
1415
    Frame* m_frame;
1413
    RefPtr<DOMWindow> m_domWindow;
1416
    RefPtr<DOMWindow> m_domWindow;
1417
    WeakPtr<Document> m_contextDocument;
1414
1418
1415
    Ref<CachedResourceLoader> m_cachedResourceLoader;
1419
    Ref<CachedResourceLoader> m_cachedResourceLoader;
1416
    RefPtr<DocumentParser> m_parser;
1420
    RefPtr<DocumentParser> m_parser;
Lines 1791-1797 inline bool Node::isDocumentNode() const a/Source/WebCore/dom/Document.h_sec4
1791
1795
1792
inline ScriptExecutionContext* Node::scriptExecutionContext() const
1796
inline ScriptExecutionContext* Node::scriptExecutionContext() const
1793
{
1797
{
1794
    return &document();
1798
    return &document().contextDocument();
1795
}
1799
}
1796
1800
1797
Element* eventTargetElementForDocument(Document*);
1801
Element* eventTargetElementForDocument(Document*);
- a/Source/WebCore/dom/Document.idl -1 / +1 lines
Lines 20-26 a/Source/WebCore/dom/Document.idl_sec1
20
20
21
[
21
[
22
    Constructor,
22
    Constructor,
23
    ConstructorCallWith=ScriptExecutionContext,
23
    ConstructorCallWith=Document,
24
    CustomToJSObject,
24
    CustomToJSObject,
25
    ExportMacro=WEBCORE_EXPORT,
25
    ExportMacro=WEBCORE_EXPORT,
26
    JSCustomHeader,
26
    JSCustomHeader,
- a/Source/WebCore/xml/XMLHttpRequest.cpp +1 lines
Lines 199-204 Document* XMLHttpRequest::responseXML(ExceptionCode& ec) a/Source/WebCore/xml/XMLHttpRequest.cpp_sec1
199
                m_responseDocument = XMLDocument::create(0, m_url);
199
                m_responseDocument = XMLDocument::create(0, m_url);
200
            // FIXME: Set Last-Modified.
200
            // FIXME: Set Last-Modified.
201
            m_responseDocument->setContent(m_responseBuilder.toStringPreserveCapacity());
201
            m_responseDocument->setContent(m_responseBuilder.toStringPreserveCapacity());
202
            m_responseDocument->setContextDocument(downcast<Document>(*scriptExecutionContext()));
202
            m_responseDocument->setSecurityOriginPolicy(scriptExecutionContext()->securityOriginPolicy());
203
            m_responseDocument->setSecurityOriginPolicy(scriptExecutionContext()->securityOriginPolicy());
203
            m_responseDocument->overrideMIMEType(mimeType);
204
            m_responseDocument->overrideMIMEType(mimeType);
204
205
- a/LayoutTests/imported/w3c/ChangeLog +16 lines
Line 1 a/LayoutTests/imported/w3c/ChangeLog_sec1
1
2016-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 NOBODY (OOPS!).
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
1
== Rolled over to ChangeLog-2016-09-26 ==
17
== Rolled over to ChangeLog-2016-09-26 ==
- a/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt -3 / +3 lines
Lines 1-7 a/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-false-expected.txt_sec1
1
1
2
PASS In window.document with click event 
2
PASS In window.document with click event 
3
PASS In window.document with load event 
3
PASS In window.document with load event 
4
FAIL In window.document.cloneNode(true) assert_array_equals: targets lengths differ, expected 8 got 0
4
PASS In window.document.cloneNode(true) 
5
FAIL In new Document() assert_array_equals: targets lengths differ, expected 8 got 0
5
PASS In new Document() 
6
FAIL In DOMImplementation.createHTMLDocument() assert_array_equals: targets lengths differ, expected 8 got 0
6
PASS In DOMImplementation.createHTMLDocument() 
7
7
- a/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt -3 / +3 lines
Lines 1-7 a/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-bubbles-true-expected.txt_sec1
1
1
2
PASS In window.document with click event 
2
PASS In window.document with click event 
3
PASS In window.document with load event 
3
PASS In window.document with load event 
4
FAIL In window.document.cloneNode(true) assert_array_equals: targets lengths differ, expected 14 got 0
4
PASS In window.document.cloneNode(true) 
5
FAIL In new Document() assert_array_equals: targets lengths differ, expected 14 got 0
5
PASS In new Document() 
6
FAIL In DOMImplementation.createHTMLDocument() assert_array_equals: targets lengths differ, expected 14 got 0
6
PASS In DOMImplementation.createHTMLDocument() 
7
7
- a/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document-expected.txt +3 lines
Line 0 a/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document-expected.txt_sec1
1
2
PASS Custom event on an element in another document 
3
- a/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html +22 lines
Line 0 a/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-other-document.html_sec1
1
<!doctype html>
2
<title>Custom event on an element in another document</title>
3
<script src="/resources/testharness.js"></script>
4
<script src="/resources/testharnessreport.js"></script>
5
<div id=log></div>
6
<script>
7
test(function() {
8
  var doc = document.implementation.createHTMLDocument("Demo");
9
  var element = doc.createElement("div");
10
  var called = false;
11
  element.addEventListener("foo", this.step_func(function(ev) {
12
    assert_false(called);
13
    called = true;
14
    assert_equals(ev.target, element);
15
  }));
16
  doc.body.appendChild(element);
17
18
  var event = new Event("foo");
19
  element.dispatchEvent(event);
20
  assert_true(called);
21
});
22
</script>
- a/LayoutTests/imported/w3c/web-platform-tests/dom/events/w3c-import.log +1 lines
Lines 29-34 List of files: a/LayoutTests/imported/w3c/web-platform-tests/dom/events/w3c-import.log_sec1
29
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-multiple-stopPropagation.html
29
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-multiple-stopPropagation.html
30
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-omitted-capture.html
30
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-omitted-capture.html
31
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-order.html
31
/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
32
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-propagation-stopped.html
33
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-propagation-stopped.html
33
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-redispatch.html
34
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-redispatch.html
34
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-reenter.html
35
/LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-dispatch-reenter.html

Return to Bug 162620