| 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/script_context.h" | 9 #include "extensions/renderer/script_context.h" |
| 10 #include "extensions/renderer/script_context_set.h" | 10 #include "extensions/renderer/script_context_set.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 : ObjectBackedNativeHandler(context), context_(context) { | 16 : ObjectBackedNativeHandler(context), context_(context) { |
| 17 RouteFunction("GetAvailability", | 17 RouteFunction("GetAvailability", |
| 18 base::Bind(&V8ContextNativeHandler::GetAvailability, | 18 base::Bind(&V8ContextNativeHandler::GetAvailability, |
| 19 base::Unretained(this))); | 19 base::Unretained(this))); |
| 20 RouteFunction("GetModuleSystem", | 20 RouteFunction("GetModuleSystem", |
| 21 base::Bind(&V8ContextNativeHandler::GetModuleSystem, | 21 base::Bind(&V8ContextNativeHandler::GetModuleSystem, |
| 22 base::Unretained(this))); | 22 base::Unretained(this))); |
| 23 RouteFunction("RunWithNativesEnabled", "test", | |
| 24 base::Bind(&V8ContextNativeHandler::RunWithNativesEnabled, | |
| 25 base::Unretained(this))); | |
| 26 } | 23 } |
| 27 | 24 |
| 28 void V8ContextNativeHandler::GetAvailability( | 25 void V8ContextNativeHandler::GetAvailability( |
| 29 const v8::FunctionCallbackInfo<v8::Value>& args) { | 26 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 30 CHECK_EQ(args.Length(), 1); | 27 CHECK_EQ(args.Length(), 1); |
| 31 v8::Isolate* isolate = args.GetIsolate(); | 28 v8::Isolate* isolate = args.GetIsolate(); |
| 32 std::string api_name = *v8::String::Utf8Value(args[0]); | 29 std::string api_name = *v8::String::Utf8Value(args[0]); |
| 33 Feature::Availability availability = context_->GetAvailability(api_name); | 30 Feature::Availability availability = context_->GetAvailability(api_name); |
| 34 | 31 |
| 35 v8::Local<v8::Object> ret = v8::Object::New(isolate); | 32 v8::Local<v8::Object> ret = v8::Object::New(isolate); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 48 void V8ContextNativeHandler::GetModuleSystem( | 45 void V8ContextNativeHandler::GetModuleSystem( |
| 49 const v8::FunctionCallbackInfo<v8::Value>& args) { | 46 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 50 CHECK_EQ(args.Length(), 1); | 47 CHECK_EQ(args.Length(), 1); |
| 51 CHECK(args[0]->IsObject()); | 48 CHECK(args[0]->IsObject()); |
| 52 ScriptContext* context = ScriptContextSet::GetContextByObject( | 49 ScriptContext* context = ScriptContextSet::GetContextByObject( |
| 53 v8::Local<v8::Object>::Cast(args[0])); | 50 v8::Local<v8::Object>::Cast(args[0])); |
| 54 if (blink::WebFrame::scriptCanAccess(context->web_frame())) | 51 if (blink::WebFrame::scriptCanAccess(context->web_frame())) |
| 55 args.GetReturnValue().Set(context->module_system()->NewInstance()); | 52 args.GetReturnValue().Set(context->module_system()->NewInstance()); |
| 56 } | 53 } |
| 57 | 54 |
| 58 void V8ContextNativeHandler::RunWithNativesEnabled( | |
| 59 const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 60 CHECK_EQ(args.Length(), 1); | |
| 61 CHECK(args[0]->IsFunction()); | |
| 62 ModuleSystem::NativesEnabledScope natives_enabled(context()->module_system()); | |
| 63 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0])); | |
| 64 } | |
| 65 | |
| 66 } // namespace extensions | 55 } // namespace extensions |
| OLD | NEW |