| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "core/xml/DocumentXSLT.h" | 6 #include "core/xml/DocumentXSLT.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/DOMWrapperWorld.h" | 8 #include "bindings/core/v8/DOMWrapperWorld.h" |
| 9 #include "bindings/core/v8/ScriptState.h" | 9 #include "bindings/core/v8/ScriptState.h" |
| 10 #include "bindings/core/v8/V8AbstractEventListener.h" | 10 #include "bindings/core/v8/V8AbstractEventListener.h" |
| 11 #include "bindings/core/v8/V8Binding.h" | 11 #include "bindings/core/v8/V8Binding.h" |
| 12 #include "core/dom/Document.h" | 12 #include "core/dom/Document.h" |
| 13 #include "core/dom/Node.h" | 13 #include "core/dom/Node.h" |
| 14 #include "core/dom/ProcessingInstruction.h" | 14 #include "core/dom/ProcessingInstruction.h" |
| 15 #include "core/events/Event.h" | 15 #include "core/events/Event.h" |
| 16 #include "core/events/EventListener.h" | 16 #include "core/events/EventListener.h" |
| 17 #include "core/frame/UseCounter.h" | 17 #include "core/frame/UseCounter.h" |
| 18 #include "core/inspector/InspectorInstrumentation.h" | 18 #include "core/inspector/InspectorInstrumentation.h" |
| 19 #include "core/xml/XSLStyleSheet.h" | 19 #include "core/xml/XSLStyleSheet.h" |
| 20 #include "core/xml/XSLTProcessor.h" | 20 #include "core/xml/XSLTProcessor.h" |
| 21 | 21 |
| 22 namespace blink { | 22 namespace blink { |
| 23 | 23 |
| 24 class DOMContentLoadedListener final : public V8AbstractEventListener { | 24 class DOMContentLoadedListener final : public ProcessingInstruction::DetachableE
ventListener, public V8AbstractEventListener { |
| 25 public: | 25 public: |
| 26 static PassRefPtr<DOMContentLoadedListener> create(ScriptState* scriptState,
ProcessingInstruction* pi) |
| 27 { |
| 28 return adoptRef(new DOMContentLoadedListener(scriptState, pi)); |
| 29 } |
| 30 |
| 31 using V8AbstractEventListener::ref; |
| 32 using V8AbstractEventListener::deref; |
| 33 |
| 26 virtual bool operator==(const EventListener&) | 34 virtual bool operator==(const EventListener&) |
| 27 { | 35 { |
| 28 return true; | 36 return true; |
| 29 } | 37 } |
| 30 | 38 |
| 31 virtual void handleEvent(ExecutionContext* context, Event* event) | 39 virtual void handleEvent(ExecutionContext* context, Event* event) |
| 32 { | 40 { |
| 33 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); | 41 ASSERT(RuntimeEnabledFeatures::xsltEnabled()); |
| 34 ASSERT(event->type() == "DOMContentLoaded"); | 42 ASSERT(event->type() == "DOMContentLoaded"); |
| 35 ScriptState::Scope scope(scriptState()); | 43 ScriptState::Scope scope(scriptState()); |
| 36 | 44 |
| 37 Document& document = *toDocument(context); | 45 Document& document = *toDocument(context); |
| 38 ASSERT(!document.parsing()); | 46 ASSERT(!document.parsing()); |
| 39 | 47 |
| 40 // Processing instruction (XML documents only). | 48 // Processing instruction (XML documents only). |
| 41 // We don't support linking to embedded CSS stylesheets, | 49 // We don't support linking to embedded CSS stylesheets, |
| 42 // see <https://bugs.webkit.org/show_bug.cgi?id=49281> for discussion. | 50 // see <https://bugs.webkit.org/show_bug.cgi?id=49281> for discussion. |
| 43 // Don't apply XSL transforms to already transformed documents. | 51 // Don't apply XSL transforms to already transformed documents. |
| 44 if (DocumentXSLT::hasTransformSourceDocument(document)) | 52 if (DocumentXSLT::hasTransformSourceDocument(document)) |
| 45 return; | 53 return; |
| 46 | 54 |
| 47 ProcessingInstruction* pi = DocumentXSLT::findXSLStyleSheet(document); | 55 ProcessingInstruction* pi = DocumentXSLT::findXSLStyleSheet(document); |
| 48 if (!pi || pi != m_processingInstruction || pi->isLoading()) | 56 if (!pi || pi != m_processingInstruction || pi->isLoading()) |
| 49 return; | 57 return; |
| 50 DocumentXSLT::applyXSLTransform(document, pi); | 58 DocumentXSLT::applyXSLTransform(document, pi); |
| 51 } | 59 } |
| 52 | 60 |
| 53 static PassRefPtr<DOMContentLoadedListener> create(ScriptState* scriptState,
ProcessingInstruction* pi) | 61 virtual void detach() override |
| 54 { | 62 { |
| 55 return adoptRef(new DOMContentLoadedListener(scriptState, pi)); | 63 m_processingInstruction = nullptr; |
| 64 } |
| 65 |
| 66 virtual EventListener* toEventListener() override |
| 67 { |
| 68 return this; |
| 56 } | 69 } |
| 57 | 70 |
| 58 private: | 71 private: |
| 59 DOMContentLoadedListener(ScriptState* scriptState, ProcessingInstruction* pi
) | 72 DOMContentLoadedListener(ScriptState* scriptState, ProcessingInstruction* pi
) |
| 60 : V8AbstractEventListener(false, scriptState) | 73 : V8AbstractEventListener(false, scriptState) |
| 61 , m_processingInstruction(pi) | 74 , m_processingInstruction(pi) |
| 62 { | 75 { |
| 63 } | 76 } |
| 64 | 77 |
| 78 virtual void refDetachableEventListener() override { ref(); } |
| 79 virtual void derefDetachableEventListener() override { deref(); } |
| 80 |
| 65 virtual v8::Local<v8::Value> callListenerFunction(v8::Handle<v8::Value> jsev
ent, Event*) | 81 virtual v8::Local<v8::Value> callListenerFunction(v8::Handle<v8::Value> jsev
ent, Event*) |
| 66 { | 82 { |
| 67 ASSERT_NOT_REACHED(); | 83 ASSERT_NOT_REACHED(); |
| 68 return v8::Local<v8::Value>(); | 84 return v8::Local<v8::Value>(); |
| 69 } | 85 } |
| 70 | 86 |
| 71 RefPtrWillBePersistent<ProcessingInstruction> m_processingInstruction; | 87 // If this event listener is attached to a ProcessingInstruction, keep a |
| 88 // weak reference back to it. That ProcessingInstruction is responsible for |
| 89 // detaching itself and clear out the reference. |
| 90 // |
| 91 // FIXME: Oilpan: when EventListener is on the heap, make this a WeakMember<
>, |
| 92 // which will remove the need for explicit detachment. |
| 93 ProcessingInstruction* m_processingInstruction; |
| 72 }; | 94 }; |
| 73 | 95 |
| 74 DocumentXSLT::DocumentXSLT() | 96 DocumentXSLT::DocumentXSLT() |
| 75 : m_transformSourceDocument(nullptr) | 97 : m_transformSourceDocument(nullptr) |
| 76 { | 98 { |
| 77 } | 99 } |
| 78 | 100 |
| 79 void DocumentXSLT::applyXSLTransform(Document& document, ProcessingInstruction*
pi) | 101 void DocumentXSLT::applyXSLTransform(Document& document, ProcessingInstruction*
pi) |
| 80 { | 102 { |
| 81 ASSERT(!pi->isLoading()); | 103 ASSERT(!pi->isLoading()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 112 | 134 |
| 113 bool DocumentXSLT::processingInstructionInsertedIntoDocument(Document& document,
ProcessingInstruction* pi) | 135 bool DocumentXSLT::processingInstructionInsertedIntoDocument(Document& document,
ProcessingInstruction* pi) |
| 114 { | 136 { |
| 115 if (!pi->isXSL()) | 137 if (!pi->isXSL()) |
| 116 return false; | 138 return false; |
| 117 | 139 |
| 118 if (!RuntimeEnabledFeatures::xsltEnabled() || !document.frame()) | 140 if (!RuntimeEnabledFeatures::xsltEnabled() || !document.frame()) |
| 119 return true; | 141 return true; |
| 120 | 142 |
| 121 ScriptState* scriptState = ScriptState::forMainWorld(document.frame()); | 143 ScriptState* scriptState = ScriptState::forMainWorld(document.frame()); |
| 122 RefPtr<EventListener> listener = DOMContentLoadedListener::create(scriptStat
e, pi); | 144 RefPtr<DOMContentLoadedListener> listener = DOMContentLoadedListener::create
(scriptState, pi); |
| 123 document.addEventListener(EventTypeNames::DOMContentLoaded, listener, false)
; | 145 document.addEventListener(EventTypeNames::DOMContentLoaded, listener, false)
; |
| 124 ASSERT(!pi->eventListenerForXSLT()); | 146 ASSERT(!pi->eventListenerForXSLT()); |
| 125 pi->setEventListenerForXSLT(listener); | 147 pi->setEventListenerForXSLT(listener.release()); |
| 126 return true; | 148 return true; |
| 127 } | 149 } |
| 128 | 150 |
| 129 bool DocumentXSLT::processingInstructionRemovedFromDocument(Document& document,
ProcessingInstruction* pi) | 151 bool DocumentXSLT::processingInstructionRemovedFromDocument(Document& document,
ProcessingInstruction* pi) |
| 130 { | 152 { |
| 131 if (!pi->isXSL()) | 153 if (!pi->isXSL()) |
| 132 return false; | 154 return false; |
| 133 | 155 |
| 134 if (!pi->eventListenerForXSLT()) | 156 if (!pi->eventListenerForXSLT()) |
| 135 return true; | 157 return true; |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 return *supplement; | 196 return *supplement; |
| 175 } | 197 } |
| 176 | 198 |
| 177 void DocumentXSLT::trace(Visitor* visitor) | 199 void DocumentXSLT::trace(Visitor* visitor) |
| 178 { | 200 { |
| 179 visitor->trace(m_transformSourceDocument); | 201 visitor->trace(m_transformSourceDocument); |
| 180 DocumentSupplement::trace(visitor); | 202 DocumentSupplement::trace(visitor); |
| 181 } | 203 } |
| 182 | 204 |
| 183 } // namespace blink | 205 } // namespace blink |
| OLD | NEW |