Chromium Code Reviews| 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..dd850b02410020bbcbe411b77a6170ec2f8e2441 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(BlockingOption blocking) { |
| + ExecutionContext* context = getExecutionContext(); |
| + DCHECK(context); |
| + if (blocking == OnloadBlocking) { |
| + toDocument(getExecutionContext())->incrementLoadEventDelayCount(); |
| + m_blockingOnload = true; |
|
haraken
2017/03/14 15:18:40
Can we replace the boolean with the BlockingOption
Kunihiko Sakamoto
2017/03/15 07:53:11
Done.
|
| + } |
| + 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); |