Chromium Code Reviews| Index: Source/core/loader/ImageLoader.cpp |
| diff --git a/Source/core/loader/ImageLoader.cpp b/Source/core/loader/ImageLoader.cpp |
| index 8e1adb8b22220c11f5fdf34f0fcf5e54bd36932e..b2853cf80ad000634668a748f19bbd13c76021fe 100644 |
| --- a/Source/core/loader/ImageLoader.cpp |
| +++ b/Source/core/loader/ImageLoader.cpp |
| @@ -23,6 +23,9 @@ |
| #include "core/loader/ImageLoader.h" |
| #include "bindings/core/v8/ScriptController.h" |
| +#include "bindings/core/v8/ScriptState.h" |
| +#include "bindings/core/v8/V8Binding.h" |
| +#include "bindings/core/v8/V8PerIsolateData.h" |
| #include "core/dom/Document.h" |
| #include "core/dom/Element.h" |
| #include "core/dom/IncrementLoadEventDelayCount.h" |
| @@ -85,9 +88,22 @@ public: |
| , m_updateBehavior(updateBehavior) |
| , m_weakFactory(this) |
| { |
| + v8::Isolate* isolate = V8PerIsolateData::mainThreadIsolate(); |
| + v8::HandleScope scope(isolate); |
| + v8::Local<v8::Context> context = isolate->GetCurrentContext(); |
| + // If we're invoked from C++ without a V8 context on the stack, we should |
| + // run the microtask in the context of the element's document's main world. |
| + if (context.IsEmpty()) |
| + m_scriptState = ScriptState::from(toV8Context(&loader->element()->document(), DOMWrapperWorld::mainWorld())); |
| + else |
| + m_scriptState = ScriptState::from(context); |
| + } |
| + |
| + ~Task() override |
| + { |
| } |
| - virtual void run() override |
| + void run() override |
| { |
| if (m_loader) { |
| #if ENABLE(OILPAN) |
| @@ -102,13 +118,19 @@ public: |
| if (Heap::willObjectBeLazilySwept(m_loader)) |
| return; |
| #endif |
| - m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBehavior); |
| + if (m_scriptState->contextIsValid()) { |
| + ScriptState::Scope scope(m_scriptState.get()); |
| + m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBehavior); |
| + } else { |
| + m_loader->doUpdateFromElement(m_shouldBypassMainWorldCSP, m_updateBehavior); |
|
haraken
2015/05/28 11:48:58
It's not clear that this never reaches shouldBypas
|
| + } |
| } |
| } |
| void clearLoader() |
| { |
| m_loader = 0; |
| + m_scriptState.clear(); |
| } |
| WeakPtr<Task> createWeakPtr() |
| @@ -120,6 +142,7 @@ private: |
| ImageLoader* m_loader; |
| BypassMainWorldBehavior m_shouldBypassMainWorldCSP; |
| UpdateFromElementBehavior m_updateBehavior; |
| + RefPtr<ScriptState> m_scriptState; |
| WeakPtrFactory<Task> m_weakFactory; |
| }; |