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

Side by Side Diff: third_party/WebKit/Source/web/SuspendableScriptExecutor.cpp

Issue 2633253002: Split content script injections into multiple tasks (Closed)
Patch Set: rebase Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "web/SuspendableScriptExecutor.h" 5 #include "web/SuspendableScriptExecutor.h"
6 6
7 #include "bindings/core/v8/ScriptController.h" 7 #include "bindings/core/v8/ScriptController.h"
8 #include "bindings/core/v8/ScriptSourceCode.h" 8 #include "bindings/core/v8/ScriptSourceCode.h"
9 #include "bindings/core/v8/V8PersistentValueVector.h" 9 #include "bindings/core/v8/V8PersistentValueVector.h"
10 #include "bindings/core/v8/WindowProxy.h" 10 #include "bindings/core/v8/WindowProxy.h"
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 m_receiver.newLocal(isolate), args.size(), 122 m_receiver.newLocal(isolate), args.size(),
123 args.data(), toIsolate(frame)) 123 args.data(), toIsolate(frame))
124 .ToLocal(&singleResult)) 124 .ToLocal(&singleResult))
125 results.push_back(singleResult); 125 results.push_back(singleResult);
126 } 126 }
127 return results; 127 return results;
128 } 128 }
129 129
130 } // namespace 130 } // namespace
131 131
132 void SuspendableScriptExecutor::createAndRun( 132 SuspendableScriptExecutor* SuspendableScriptExecutor::create(
133 LocalFrame* frame, 133 LocalFrame* frame,
134 int worldID, 134 int worldID,
135 const HeapVector<ScriptSourceCode>& sources, 135 const HeapVector<ScriptSourceCode>& sources,
136 bool userGesture, 136 bool userGesture,
137 WebScriptExecutionCallback* callback) { 137 WebScriptExecutionCallback* callback) {
138 // TODO(devlin): Passing in a v8::Isolate* directly would be better than 138 // TODO(devlin): Passing in a v8::Isolate* directly would be better than
139 // toIsolate() here. 139 // toIsolate() here.
140 ScriptState* scriptState = ScriptState::forWorld( 140 ScriptState* scriptState = ScriptState::forWorld(
141 frame, *DOMWrapperWorld::fromWorldId(toIsolate(frame), worldID)); 141 frame, *DOMWrapperWorld::fromWorldId(toIsolate(frame), worldID));
142 SuspendableScriptExecutor* executor = new SuspendableScriptExecutor( 142 return new SuspendableScriptExecutor(
143 frame, scriptState, callback, 143 frame, scriptState, callback,
144 new WebScriptExecutor(sources, worldID, userGesture)); 144 new WebScriptExecutor(sources, worldID, userGesture));
145 executor->run();
146 } 145 }
147 146
148 void SuspendableScriptExecutor::createAndRun( 147 void SuspendableScriptExecutor::createAndRun(
149 LocalFrame* frame, 148 LocalFrame* frame,
150 v8::Isolate* isolate, 149 v8::Isolate* isolate,
151 v8::Local<v8::Context> context, 150 v8::Local<v8::Context> context,
152 v8::Local<v8::Function> function, 151 v8::Local<v8::Function> function,
153 v8::Local<v8::Value> receiver, 152 v8::Local<v8::Value> receiver,
154 int argc, 153 int argc,
155 v8::Local<v8::Value> argv[], 154 v8::Local<v8::Value> argv[],
(...skipping 19 matching lines...) Expand all
175 } 174 }
176 175
177 SuspendableScriptExecutor::SuspendableScriptExecutor( 176 SuspendableScriptExecutor::SuspendableScriptExecutor(
178 LocalFrame* frame, 177 LocalFrame* frame,
179 ScriptState* scriptState, 178 ScriptState* scriptState,
180 WebScriptExecutionCallback* callback, 179 WebScriptExecutionCallback* callback,
181 Executor* executor) 180 Executor* executor)
182 : SuspendableTimer(frame->document(), TaskType::Timer), 181 : SuspendableTimer(frame->document(), TaskType::Timer),
183 m_scriptState(scriptState), 182 m_scriptState(scriptState),
184 m_callback(callback), 183 m_callback(callback),
184 m_blockingOnload(false),
185 m_keepAlive(this), 185 m_keepAlive(this),
186 m_executor(executor) {} 186 m_executor(executor) {}
187 187
188 SuspendableScriptExecutor::~SuspendableScriptExecutor() {} 188 SuspendableScriptExecutor::~SuspendableScriptExecutor() {}
189 189
190 void SuspendableScriptExecutor::fired() { 190 void SuspendableScriptExecutor::fired() {
191 executeAndDestroySelf(); 191 executeAndDestroySelf();
192 } 192 }
193 193
194 void SuspendableScriptExecutor::run() { 194 void SuspendableScriptExecutor::run() {
195 ExecutionContext* context = getExecutionContext(); 195 ExecutionContext* context = getExecutionContext();
196 DCHECK(context); 196 DCHECK(context);
197 if (!context->isContextSuspended()) { 197 if (!context->isContextSuspended()) {
198 suspendIfNeeded(); 198 suspendIfNeeded();
199 executeAndDestroySelf(); 199 executeAndDestroySelf();
200 return; 200 return;
201 } 201 }
202 startOneShot(0, BLINK_FROM_HERE); 202 startOneShot(0, BLINK_FROM_HERE);
203 suspendIfNeeded(); 203 suspendIfNeeded();
204 } 204 }
205 205
206 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.
207 ExecutionContext* context = getExecutionContext();
208 DCHECK(context);
209 if (blockOnload) {
210 toDocument(getExecutionContext())->incrementLoadEventDelayCount();
211 m_blockingOnload = true;
212 }
213 startOneShot(0, BLINK_FROM_HERE);
214 suspendIfNeeded();
215 }
216
206 void SuspendableScriptExecutor::executeAndDestroySelf() { 217 void SuspendableScriptExecutor::executeAndDestroySelf() {
207 CHECK(m_scriptState->contextIsValid()); 218 CHECK(m_scriptState->contextIsValid());
208 219
220 if (m_callback)
221 m_callback->willExecute();
222
209 ScriptState::Scope scriptScope(m_scriptState.get()); 223 ScriptState::Scope scriptScope(m_scriptState.get());
210 Vector<v8::Local<v8::Value>> results = 224 Vector<v8::Local<v8::Value>> results =
211 m_executor->execute(toDocument(getExecutionContext())->frame()); 225 m_executor->execute(toDocument(getExecutionContext())->frame());
212 226
213 // The script may have removed the frame, in which case contextDestroyed() 227 // The script may have removed the frame, in which case contextDestroyed()
214 // will have handled the disposal/callback. 228 // will have handled the disposal/callback.
215 if (!m_scriptState->contextIsValid()) 229 if (!m_scriptState->contextIsValid())
216 return; 230 return;
217 231
232 if (m_blockingOnload)
233 toDocument(getExecutionContext())->decrementLoadEventDelayCount();
234
218 if (m_callback) 235 if (m_callback)
219 m_callback->completed(results); 236 m_callback->completed(results);
220 237
221 dispose(); 238 dispose();
222 } 239 }
223 240
224 void SuspendableScriptExecutor::dispose() { 241 void SuspendableScriptExecutor::dispose() {
225 // Remove object as a ContextLifecycleObserver. 242 // Remove object as a ContextLifecycleObserver.
226 SuspendableObject::clearContext(); 243 SuspendableObject::clearContext();
227 m_keepAlive.clear(); 244 m_keepAlive.clear();
228 stop(); 245 stop();
229 } 246 }
230 247
231 DEFINE_TRACE(SuspendableScriptExecutor) { 248 DEFINE_TRACE(SuspendableScriptExecutor) {
232 visitor->trace(m_executor); 249 visitor->trace(m_executor);
233 SuspendableTimer::trace(visitor); 250 SuspendableTimer::trace(visitor);
234 } 251 }
235 252
236 } // namespace blink 253 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698