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

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

Issue 1192763002: extensions: Use V8 Maybe APIs in NativeHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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/binding_generating_native_handler.h" 5 #include "extensions/renderer/binding_generating_native_handler.h"
6 6
7 #include "extensions/renderer/module_system.h" 7 #include "extensions/renderer/script_context.h"
8 #include "extensions/renderer/v8_helpers.h"
8 9
9 namespace extensions { 10 namespace extensions {
10 11
12 using namespace v8_helpers;
13
11 BindingGeneratingNativeHandler::BindingGeneratingNativeHandler( 14 BindingGeneratingNativeHandler::BindingGeneratingNativeHandler(
12 ModuleSystem* module_system, 15 ScriptContext* context,
13 const std::string& api_name, 16 const std::string& api_name,
14 const std::string& bind_to) 17 const std::string& bind_to)
15 : module_system_(module_system), api_name_(api_name), bind_to_(bind_to) {} 18 : context_(context), api_name_(api_name), bind_to_(bind_to) {}
16 19
17 v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() { 20 v8::Local<v8::Object> BindingGeneratingNativeHandler::NewInstance() {
not at google - send to devlin 2015/06/23 17:26:22 // This long sequence of commands effectively runs
bashi 2015/06/24 00:04:32 Done.
18 v8::Isolate* isolate = module_system_->GetIsolate(); 21 v8::Isolate* isolate = context_->isolate();
19 v8::EscapableHandleScope scope(isolate); 22 v8::EscapableHandleScope scope(isolate);
20 v8::Local<v8::Object> binding_module = 23
21 module_system_->Require("binding")->ToObject(isolate); 24 v8::Local<v8::String> v8_api_name;
not at google - send to devlin 2015/06/23 17:26:23 See above, I think these stages should be associat
bashi 2015/06/24 00:04:32 Done.
22 v8::Local<v8::Object> binding = 25 v8::Local<v8::String> v8_bind_to;
23 binding_module->Get(v8::String::NewFromUtf8(isolate, "Binding")) 26 if (!ToV8String(isolate, api_name_.c_str(), &v8_api_name) ||
24 ->ToObject(isolate); 27 !ToV8String(isolate, bind_to_.c_str(), &v8_bind_to)) {
not at google - send to devlin 2015/06/23 17:26:23 Perhaps add a ToV8String() variation that takes a
bashi 2015/06/24 00:04:32 Done.
28 NOTREACHED();
29 return v8::Local<v8::Object>();
30 }
31
32 v8::Local<v8::Context> v8_context = context_->v8_context();
not at google - send to devlin 2015/06/23 17:26:23 // require('binding');
33 v8::Local<v8::Object> binding_module;
34 if (!context_->module_system()->Require("binding")
35 ->ToObject(v8_context)
not at google - send to devlin 2015/06/23 17:26:22 Hm, Require() should really return a v8::Object be
bashi 2015/06/24 00:04:32 Hmm, ModuleSystem::Require() returns what ModuleSy
not at google - send to devlin 2015/06/24 00:34:56 I see... maybe because require can fail? A Maybe<O
bashi 2015/06/24 03:30:44 Done. I needed to change some other places. Requir
36 .ToLocal(&binding_module)) {
37 NOTREACHED();
38 return v8::Local<v8::Object>();
39 }
40
41 v8::Local<v8::Value> binding_value;
not at google - send to devlin 2015/06/23 17:26:22 // require('binding').Binding;
42 v8::Local<v8::Object> binding;
43 if (!GetProperty(v8_context, binding_module, "Binding", &binding_value) ||
44 !binding_value->ToObject(v8_context).ToLocal(&binding)) {
not at google - send to devlin 2015/06/23 17:26:23 Is |binding_value| guaranteed to be an Object? Wha
bashi 2015/06/24 00:04:32 It depends on what "require('binding').Binding" re
not at google - send to devlin 2015/06/24 00:34:56 ok, cool.
45 NOTREACHED();
46 return v8::Local<v8::Object>();
47 }
48
49 v8::Local<v8::Value> create_binding_value;
not at google - send to devlin 2015/06/23 17:26:22 // require('Binding').Binding.create;
bashi 2015/06/24 00:04:32 Done.
50 if (!GetProperty(v8_context, binding, "create", &create_binding_value) ||
51 !create_binding_value->IsFunction()) {
52 NOTREACHED();
53 return v8::Local<v8::Object>();
54 }
25 v8::Local<v8::Function> create_binding = 55 v8::Local<v8::Function> create_binding =
26 binding->Get(v8::String::NewFromUtf8(isolate, "create")) 56 create_binding_value.As<v8::Function>();
27 .As<v8::Function>(); 57
28 v8::Local<v8::Value> argv[] = { 58 v8::Local<v8::Value> argv[] = {v8_api_name};
not at google - send to devlin 2015/06/23 17:26:22 // require('Binding').Binding.create(api_name);
bashi 2015/06/24 00:04:32 Done.
29 v8::String::NewFromUtf8(isolate, api_name_.c_str())}; 59 v8::Local<v8::Value> binding_instance_value;
30 v8::Local<v8::Object> binding_instance = 60 v8::Local<v8::Object> binding_instance;
31 create_binding->Call(binding, arraysize(argv), argv)->ToObject(isolate); 61 if (!CallFunction(v8_context, create_binding, binding, arraysize(argv), argv,
32 v8::Local<v8::Function> generate = 62 &binding_instance_value) ||
33 binding_instance->Get(v8::String::NewFromUtf8(isolate, "generate")) 63 !binding_instance_value->ToObject(v8_context)
34 .As<v8::Function>(); 64 .ToLocal(&binding_instance)) {
65 NOTREACHED();
66 return v8::Local<v8::Object>();
67 }
68
69 v8::Local<v8::Value> generate_value;
not at google - send to devlin 2015/06/23 17:26:23 // require('Binding').Binding.create(api_name).gen
bashi 2015/06/24 00:04:32 Done.
70 if (!GetProperty(v8_context, binding_instance, "generate", &generate_value) ||
71 !generate_value->IsFunction()) {
72 NOTREACHED();
73 return v8::Local<v8::Object>();
74 }
75 v8::Local<v8::Function> generate = generate_value.As<v8::Function>();
76
35 v8::Local<v8::Object> object = v8::Object::New(isolate); 77 v8::Local<v8::Object> object = v8::Object::New(isolate);
not at google - send to devlin 2015/06/23 17:26:23 // require('Binding').Binding.create(api_name).gen
bashi 2015/06/24 00:04:32 Done.
36 v8::Local<v8::Value> compiled_schema = 78 v8::Local<v8::Value> compiled_schema;
37 generate->Call(binding_instance, 0, NULL); 79 if (!CallFunction(v8_context, generate, binding_instance, 0, nullptr,
38 if (!compiled_schema.IsEmpty()) { 80 &compiled_schema)) {
39 object->Set(v8::String::NewFromUtf8(isolate, bind_to_.c_str()), 81 NOTREACHED();
40 compiled_schema); 82 return v8::Local<v8::Object>();
83 }
84
85 if (!SetProperty(v8_context, object, v8_bind_to, compiled_schema)) {
not at google - send to devlin 2015/06/23 17:26:23 // var result = {}; // result[bind_to] = ...;
bashi 2015/06/24 00:04:32 Done.
86 NOTREACHED();
87 return v8::Local<v8::Object>();
41 } 88 }
42 return scope.Escape(object); 89 return scope.Escape(object);
not at google - send to devlin 2015/06/23 17:26:22 // var result = {}; // result[bind_to] = ...; // r
bashi 2015/06/24 00:04:32 Done.
43 } 90 }
44 91
45 } // namespace extensions 92 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/binding_generating_native_handler.h ('k') | extensions/renderer/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698