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

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

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

Powered by Google App Engine
This is Rietveld 408576698