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

Unified Diff: third_party/WebKit/Source/web/SuspendableScriptExecutor.cpp

Issue 2633253002: Split content script injections into multiple tasks (Closed)
Patch Set: rebase Created 3 years, 10 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
Index: third_party/WebKit/Source/web/SuspendableScriptExecutor.cpp
diff --git a/third_party/WebKit/Source/web/SuspendableScriptExecutor.cpp b/third_party/WebKit/Source/web/SuspendableScriptExecutor.cpp
index e82bc7444530affda32e9db61b3824a6da4bb777..7b09c1df319d8524aec79bc86e792df21365e396 100644
--- a/third_party/WebKit/Source/web/SuspendableScriptExecutor.cpp
+++ b/third_party/WebKit/Source/web/SuspendableScriptExecutor.cpp
@@ -129,7 +129,7 @@ Vector<v8::Local<v8::Value>> V8FunctionExecutor::execute(LocalFrame* frame) {
} // namespace
-void SuspendableScriptExecutor::createAndRun(
+SuspendableScriptExecutor* SuspendableScriptExecutor::create(
LocalFrame* frame,
int worldID,
const HeapVector<ScriptSourceCode>& sources,
@@ -139,10 +139,9 @@ void SuspendableScriptExecutor::createAndRun(
// toIsolate() here.
ScriptState* scriptState = ScriptState::forWorld(
frame, *DOMWrapperWorld::fromWorldId(toIsolate(frame), worldID));
- SuspendableScriptExecutor* executor = new SuspendableScriptExecutor(
+ return new SuspendableScriptExecutor(
frame, scriptState, callback,
new WebScriptExecutor(sources, worldID, userGesture));
- executor->run();
}
void SuspendableScriptExecutor::createAndRun(
@@ -182,6 +181,7 @@ SuspendableScriptExecutor::SuspendableScriptExecutor(
: SuspendableTimer(frame->document(), TaskType::Timer),
m_scriptState(scriptState),
m_callback(callback),
+ m_blockingOnload(false),
m_keepAlive(this),
m_executor(executor) {}
@@ -203,9 +203,23 @@ void SuspendableScriptExecutor::run() {
suspendIfNeeded();
}
+void SuspendableScriptExecutor::runAsync(bool blockOnload) {
haraken 2017/03/02 03:54:32 Use an enum instead of bool.
Kunihiko Sakamoto 2017/03/06 09:11:06 Done.
+ ExecutionContext* context = getExecutionContext();
+ DCHECK(context);
+ if (blockOnload) {
+ toDocument(getExecutionContext())->incrementLoadEventDelayCount();
+ m_blockingOnload = true;
+ }
+ startOneShot(0, BLINK_FROM_HERE);
+ suspendIfNeeded();
+}
+
void SuspendableScriptExecutor::executeAndDestroySelf() {
CHECK(m_scriptState->contextIsValid());
+ if (m_callback)
+ m_callback->willExecute();
+
ScriptState::Scope scriptScope(m_scriptState.get());
Vector<v8::Local<v8::Value>> results =
m_executor->execute(toDocument(getExecutionContext())->frame());
@@ -215,6 +229,9 @@ void SuspendableScriptExecutor::executeAndDestroySelf() {
if (!m_scriptState->contextIsValid())
return;
+ if (m_blockingOnload)
+ toDocument(getExecutionContext())->decrementLoadEventDelayCount();
+
if (m_callback)
m_callback->completed(results);

Powered by Google App Engine
This is Rietveld 408576698