Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1213)

Unified Diff: Source/core/loader/ImageLoader.cpp

Issue 1163543002: Reland "Correctly set ScriptState in the image loader microtask" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: updates Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/dom/Microtask.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
};
« no previous file with comments | « Source/core/dom/Microtask.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698