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

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

Issue 2556153002: [Extensions] Convert more callers of CallModuleMethod (Closed)
Patch Set: revertdoc Created 4 years 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/module_system.h" 5 #include "extensions/renderer/module_system.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 !exports->IsUndefined()) 277 !exports->IsUndefined())
278 return handle_scope.Escape(exports); 278 return handle_scope.Escape(exports);
279 279
280 exports = LoadModule(*v8::String::Utf8Value(module_name)); 280 exports = LoadModule(*v8::String::Utf8Value(module_name));
281 SetPrivateProperty(v8_context, modules, module_name, exports); 281 SetPrivateProperty(v8_context, modules, module_name, exports);
282 return handle_scope.Escape(exports); 282 return handle_scope.Escape(exports);
283 } 283 }
284 284
285 v8::Local<v8::Value> ModuleSystem::CallModuleMethod( 285 v8::Local<v8::Value> ModuleSystem::CallModuleMethod(
286 const std::string& module_name, 286 const std::string& module_name,
287 const std::string& method_name) {
288 v8::EscapableHandleScope handle_scope(GetIsolate());
289 v8::Local<v8::Value> no_args;
290 return handle_scope.Escape(
291 CallModuleMethod(module_name, method_name, 0, &no_args));
292 }
293
294 v8::Local<v8::Value> ModuleSystem::CallModuleMethod(
295 const std::string& module_name,
296 const std::string& method_name, 287 const std::string& method_name,
297 int argc, 288 int argc,
298 v8::Local<v8::Value> argv[]) { 289 v8::Local<v8::Value> argv[]) {
299 TRACE_EVENT2("v8", 290 TRACE_EVENT2("v8",
300 "v8.callModuleMethod", 291 "v8.callModuleMethod",
301 "module_name", 292 "module_name",
302 module_name, 293 module_name,
303 "method_name", 294 "method_name",
304 method_name); 295 method_name);
305 296
(...skipping 18 matching lines...) Expand all
324 result = v8::Undefined(GetIsolate()); 315 result = v8::Undefined(GetIsolate());
325 } 316 }
326 } 317 }
327 return handle_scope.Escape(result); 318 return handle_scope.Escape(result);
328 } 319 }
329 320
330 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name, 321 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name,
331 const std::string& method_name) { 322 const std::string& method_name) {
332 v8::HandleScope handle_scope(GetIsolate()); 323 v8::HandleScope handle_scope(GetIsolate());
333 v8::Local<v8::Value> no_args; 324 v8::Local<v8::Value> no_args;
334 CallModuleMethodSafe(module_name, method_name, 0, &no_args); 325 CallModuleMethodSafe(module_name, method_name, 0, &no_args,
326 ScriptInjectionCallback::CompleteCallback());
335 } 327 }
336 328
337 void ModuleSystem::CallModuleMethodSafe( 329 void ModuleSystem::CallModuleMethodSafe(
338 const std::string& module_name, 330 const std::string& module_name,
339 const std::string& method_name, 331 const std::string& method_name,
340 std::vector<v8::Local<v8::Value>>* args) { 332 std::vector<v8::Local<v8::Value>>* args) {
341 CallModuleMethodSafe(module_name, method_name, args->size(), args->data()); 333 CallModuleMethodSafe(module_name, method_name, args->size(), args->data(),
334 ScriptInjectionCallback::CompleteCallback());
342 } 335 }
343 336
344 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name, 337 void ModuleSystem::CallModuleMethodSafe(const std::string& module_name,
345 const std::string& method_name, 338 const std::string& method_name,
346 int argc, 339 int argc,
347 v8::Local<v8::Value> argv[]) { 340 v8::Local<v8::Value> argv[]) {
341 CallModuleMethodSafe(module_name, method_name, argc, argv,
342 ScriptInjectionCallback::CompleteCallback());
343 }
344
345 void ModuleSystem::CallModuleMethodSafe(
346 const std::string& module_name,
347 const std::string& method_name,
348 int argc,
349 v8::Local<v8::Value> argv[],
350 const ScriptInjectionCallback::CompleteCallback& callback) {
348 TRACE_EVENT2("v8", "v8.callModuleMethodSafe", "module_name", module_name, 351 TRACE_EVENT2("v8", "v8.callModuleMethodSafe", "module_name", module_name,
349 "method_name", method_name); 352 "method_name", method_name);
350 353
351 v8::HandleScope handle_scope(GetIsolate()); 354 v8::HandleScope handle_scope(GetIsolate());
352 v8::Local<v8::Context> v8_context = context()->v8_context(); 355 v8::Local<v8::Context> v8_context = context()->v8_context();
353 v8::Context::Scope context_scope(v8_context); 356 v8::Context::Scope context_scope(v8_context);
354 357
355 v8::Local<v8::Function> function = 358 v8::Local<v8::Function> function =
356 GetModuleFunction(module_name, method_name); 359 GetModuleFunction(module_name, method_name);
357 if (function.IsEmpty()) { 360 if (function.IsEmpty()) {
358 NOTREACHED() << "GetModuleFunction() returns empty function handle"; 361 NOTREACHED() << "GetModuleFunction() returns empty function handle";
359 return; 362 return;
360 } 363 }
361 364
362 { 365 {
363 v8::TryCatch try_catch(GetIsolate()); 366 v8::TryCatch try_catch(GetIsolate());
364 try_catch.SetCaptureMessage(true); 367 try_catch.SetCaptureMessage(true);
365 context_->SafeCallFunction(function, argc, argv); 368 context_->SafeCallFunction(function, argc, argv, callback);
366 if (try_catch.HasCaught()) 369 if (try_catch.HasCaught())
367 HandleException(try_catch); 370 HandleException(try_catch);
368 } 371 }
369 } 372 }
370 373
371 void ModuleSystem::RegisterNativeHandler( 374 void ModuleSystem::RegisterNativeHandler(
372 const std::string& name, 375 const std::string& name,
373 std::unique_ptr<NativeHandler> native_handler) { 376 std::unique_ptr<NativeHandler> native_handler) {
374 ClobberExistingNativeHandler(name); 377 ClobberExistingNativeHandler(name);
375 native_handler_map_[name] = std::move(native_handler); 378 native_handler_map_[name] = std::move(native_handler);
(...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 !value->IsFunction()) { 826 !value->IsFunction()) {
824 Fatal(context_, module_name + "." + method_name + " is not a function"); 827 Fatal(context_, module_name + "." + method_name + " is not a function");
825 return function; 828 return function;
826 } 829 }
827 830
828 function = v8::Local<v8::Function>::Cast(value); 831 function = v8::Local<v8::Function>::Cast(value);
829 return function; 832 return function;
830 } 833 }
831 834
832 } // namespace extensions 835 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698