OLD | NEW |
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/v8_context_native_handler.h" | 5 #include "extensions/renderer/v8_context_native_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "extensions/common/features/feature.h" | 8 #include "extensions/common/features/feature.h" |
9 #include "extensions/renderer/dispatcher.h" | 9 #include "extensions/renderer/dispatcher.h" |
10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
11 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 11 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
12 | 12 |
13 namespace extensions { | 13 namespace extensions { |
14 | 14 |
15 V8ContextNativeHandler::V8ContextNativeHandler(ScriptContext* context, | 15 V8ContextNativeHandler::V8ContextNativeHandler(ScriptContext* context, |
16 Dispatcher* dispatcher) | 16 Dispatcher* dispatcher) |
17 : ObjectBackedNativeHandler(context), | 17 : ObjectBackedNativeHandler(context), |
18 context_(context), | 18 context_(context), |
19 dispatcher_(dispatcher) { | 19 dispatcher_(dispatcher) { |
20 RouteFunction("GetAvailability", | 20 RouteFunction("GetAvailability", |
21 base::Bind(&V8ContextNativeHandler::GetAvailability, | 21 base::Bind(&V8ContextNativeHandler::GetAvailability, |
22 base::Unretained(this))); | 22 base::Unretained(this))); |
23 RouteFunction("GetModuleSystem", | 23 RouteFunction("GetModuleSystem", |
24 base::Bind(&V8ContextNativeHandler::GetModuleSystem, | 24 base::Bind(&V8ContextNativeHandler::GetModuleSystem, |
25 base::Unretained(this))); | 25 base::Unretained(this))); |
26 RouteFunction( | 26 RouteFunction("RunWithNativesEnabled", "test", |
27 "RunWithNativesEnabled", | 27 base::Bind(&V8ContextNativeHandler::RunWithNativesEnabled, |
28 base::Bind(&V8ContextNativeHandler::RunWithNativesEnabled, | 28 base::Unretained(this))); |
29 base::Unretained(this))); | |
30 } | 29 } |
31 | 30 |
32 void V8ContextNativeHandler::GetAvailability( | 31 void V8ContextNativeHandler::GetAvailability( |
33 const v8::FunctionCallbackInfo<v8::Value>& args) { | 32 const v8::FunctionCallbackInfo<v8::Value>& args) { |
34 CHECK_EQ(args.Length(), 1); | 33 CHECK_EQ(args.Length(), 1); |
35 v8::Isolate* isolate = args.GetIsolate(); | 34 v8::Isolate* isolate = args.GetIsolate(); |
36 std::string api_name = *v8::String::Utf8Value(args[0]); | 35 std::string api_name = *v8::String::Utf8Value(args[0]); |
37 Feature::Availability availability = context_->GetAvailability(api_name); | 36 Feature::Availability availability = context_->GetAvailability(api_name); |
38 | 37 |
39 v8::Local<v8::Object> ret = v8::Object::New(isolate); | 38 v8::Local<v8::Object> ret = v8::Object::New(isolate); |
(...skipping 20 matching lines...) Expand all Loading... |
60 | 59 |
61 void V8ContextNativeHandler::RunWithNativesEnabled( | 60 void V8ContextNativeHandler::RunWithNativesEnabled( |
62 const v8::FunctionCallbackInfo<v8::Value>& args) { | 61 const v8::FunctionCallbackInfo<v8::Value>& args) { |
63 CHECK_EQ(args.Length(), 1); | 62 CHECK_EQ(args.Length(), 1); |
64 CHECK(args[0]->IsFunction()); | 63 CHECK(args[0]->IsFunction()); |
65 ModuleSystem::NativesEnabledScope natives_enabled(context()->module_system()); | 64 ModuleSystem::NativesEnabledScope natives_enabled(context()->module_system()); |
66 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0])); | 65 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0])); |
67 } | 66 } |
68 | 67 |
69 } // namespace extensions | 68 } // namespace extensions |
OLD | NEW |