OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/renderer/extensions/binding_generating_native_handler.h" | |
6 | |
7 #include "extensions/renderer/module_system.h" | |
8 | |
9 namespace extensions { | |
10 | |
11 BindingGeneratingNativeHandler::BindingGeneratingNativeHandler( | |
12 ModuleSystem* module_system, | |
13 const std::string& api_name, | |
14 const std::string& bind_to) | |
15 : module_system_(module_system), | |
16 api_name_(api_name), | |
17 bind_to_(bind_to) { | |
18 } | |
19 | |
20 v8::Handle<v8::Object> BindingGeneratingNativeHandler::NewInstance() { | |
21 v8::Isolate* isolate = module_system_->GetIsolate(); | |
22 v8::EscapableHandleScope scope(isolate); | |
23 v8::Handle<v8::Object> binding_module = | |
24 module_system_->Require("binding")->ToObject(); | |
25 v8::Handle<v8::Object> binding = binding_module | |
26 ->Get(v8::String::NewFromUtf8(isolate, "Binding"))->ToObject(); | |
27 v8::Handle<v8::Function> create_binding = binding | |
28 ->Get(v8::String::NewFromUtf8(isolate, "create")).As<v8::Function>(); | |
29 v8::Handle<v8::Value> argv[] = {v8::String::NewFromUtf8(isolate, | |
30 api_name_.c_str())}; | |
31 v8::Handle<v8::Object> binding_instance = | |
32 create_binding->Call(binding, arraysize(argv), argv)->ToObject(); | |
33 v8::Handle<v8::Function> generate = binding_instance | |
34 ->Get(v8::String::NewFromUtf8(isolate, "generate")).As<v8::Function>(); | |
35 v8::Local<v8::Object> object = v8::Object::New(isolate); | |
36 v8::Handle<v8::Value> compiled_schema = | |
37 generate->Call(binding_instance, 0, NULL); | |
38 if (!compiled_schema.IsEmpty()) { | |
39 object->Set(v8::String::NewFromUtf8(isolate, bind_to_.c_str()), | |
40 compiled_schema); | |
41 } | |
42 return scope.Escape(object); | |
43 } | |
44 | |
45 } // namespace extensions | |
OLD | NEW |