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

Side by Side Diff: extensions/renderer/script_context.cc

Issue 2339683006: [Blink] Modify SuspendableScriptExecutor to take a v8::Function (Closed)
Patch Set: Haraken's Created 4 years, 2 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 "extensions/renderer/script_context.h" 5 #include "extensions/renderer/script_context.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/string_split.h" 10 #include "base/strings/string_split.h"
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 } 195 }
196 196
197 v8::Local<v8::Object> global = v8_context()->Global(); 197 v8::Local<v8::Object> global = v8_context()->Global();
198 if (!web_frame_) 198 if (!web_frame_)
199 return handle_scope.Escape(function->Call(global, argc, argv)); 199 return handle_scope.Escape(function->Call(global, argc, argv));
200 return handle_scope.Escape( 200 return handle_scope.Escape(
201 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled( 201 v8::Local<v8::Value>(web_frame_->callFunctionEvenIfScriptDisabled(
202 function, global, argc, argv))); 202 function, global, argc, argv)));
203 } 203 }
204 204
205 void ScriptContext::SafeCallFunction(const v8::Local<v8::Function>& function,
206 int argc,
207 v8::Local<v8::Value> argv[]) {
208 v8::HandleScope handle_scope(isolate());
209 v8::Context::Scope scope(v8_context());
210 v8::MicrotasksScope microtasks(isolate(),
211 v8::MicrotasksScope::kDoNotRunMicrotasks);
212 v8::Local<v8::Object> global = v8_context()->Global();
213 if (web_frame_) {
214 web_frame_->requestExecuteV8Function(function, global, argc, argv, nullptr);
215 } else {
216 // TODO(devlin): This probably isn't safe.
dcheng 2016/10/04 05:58:49 Hmm, is it possible to attach devtools to a servic
Devlin 2016/10/04 19:40:05 That sounds like a question for falken. :) Regard
falken 2016/10/05 00:19:55 Yes, you can attach DevTools to service workers an
dgozman 2016/10/05 01:25:42 This should be fine as long as you execute JS via
217 function->Call(global, argc, argv);
218 }
219 }
220
205 v8::Local<v8::Value> ScriptContext::CallFunction( 221 v8::Local<v8::Value> ScriptContext::CallFunction(
206 const v8::Local<v8::Function>& function) const { 222 const v8::Local<v8::Function>& function) const {
207 DCHECK(thread_checker_.CalledOnValidThread()); 223 DCHECK(thread_checker_.CalledOnValidThread());
208 return CallFunction(function, 0, nullptr); 224 return CallFunction(function, 0, nullptr);
209 } 225 }
210 226
211 Feature::Availability ScriptContext::GetAvailability( 227 Feature::Availability ScriptContext::GetAvailability(
212 const std::string& api_name) { 228 const std::string& api_name) {
213 DCHECK(thread_checker_.CalledOnValidThread()); 229 DCHECK(thread_checker_.CalledOnValidThread());
214 if (base::StartsWith(api_name, "test", base::CompareCase::SENSITIVE)) { 230 if (base::StartsWith(api_name, "test", base::CompareCase::SENSITIVE)) {
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 v8::Local<v8::Value> argv[]) { 517 v8::Local<v8::Value> argv[]) {
502 return context_->CallFunction(function, argc, argv); 518 return context_->CallFunction(function, argc, argv);
503 } 519 }
504 520
505 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() { 521 gin::ContextHolder* ScriptContext::Runner::GetContextHolder() {
506 v8::HandleScope handle_scope(context_->isolate()); 522 v8::HandleScope handle_scope(context_->isolate());
507 return gin::PerContextData::From(context_->v8_context())->context_holder(); 523 return gin::PerContextData::From(context_->v8_context())->context_holder();
508 } 524 }
509 525
510 } // namespace extensions 526 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698