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

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

Issue 1146223008: Merge 196071 "Reland "Correctly set ScriptState in the image loa..." (Closed) Base URL: svn://svn.chromium.org/blink/branches/chromium/2403/
Patch Set: 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
===================================================================
--- Source/core/loader/ImageLoader.cpp (revision 196329)
+++ Source/core/loader/ImageLoader.cpp (working copy)
@@ -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"
@@ -86,10 +89,23 @@
, 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);
}
- virtual void run() override
+ ~Task() override
{
+ }
+
+ void run() override
+ {
if (m_loader) {
#if ENABLE(OILPAN)
// Oilpan: this WebThread::Task microtask may run after the
@@ -103,7 +119,12 @@
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);
+ }
}
}
@@ -110,6 +131,7 @@
void clearLoader()
{
m_loader = 0;
+ m_scriptState.clear();
}
WeakPtr<Task> createWeakPtr()
@@ -121,6 +143,7 @@
ImageLoader* m_loader;
BypassMainWorldBehavior m_shouldBypassMainWorldCSP;
UpdateFromElementBehavior m_updateBehavior;
+ RefPtr<ScriptState> m_scriptState;
WeakPtrFactory<Task> m_weakFactory;
};
@@ -376,7 +399,12 @@
image->removeClient(this);
m_image = nullptr;
}
- enqueueImageLoadingMicroTask(updateBehavior);
+
+ // Don't load images for inactive documents. We don't want to slow down the
+ // raw HTML parsing case by loading images we don't intend to display.
+ Document& document = m_element->document();
+ if (document.isActive())
+ enqueueImageLoadingMicroTask(updateBehavior);
}
KURL ImageLoader::imageSourceToKURL(AtomicString imageSourceURL) const
« 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