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" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 void V8ContextNativeHandler::GetAvailability( | 28 void V8ContextNativeHandler::GetAvailability( |
29 const v8::FunctionCallbackInfo<v8::Value>& args) { | 29 const v8::FunctionCallbackInfo<v8::Value>& args) { |
30 CHECK_EQ(args.Length(), 1); | 30 CHECK_EQ(args.Length(), 1); |
31 v8::Isolate* isolate = args.GetIsolate(); | 31 v8::Isolate* isolate = args.GetIsolate(); |
32 std::string api_name = *v8::String::Utf8Value(args[0]); | 32 std::string api_name = *v8::String::Utf8Value(args[0]); |
33 Feature::Availability availability = context_->GetAvailability(api_name); | 33 Feature::Availability availability = context_->GetAvailability(api_name); |
34 | 34 |
35 v8::Local<v8::Object> ret = v8::Object::New(isolate); | 35 v8::Local<v8::Object> ret = v8::Object::New(isolate); |
| 36 v8::Maybe<bool> maybe = |
| 37 ret->SetPrototype(context_->v8_context(), v8::Null(isolate)); |
| 38 CHECK(maybe.IsJust() && maybe.FromJust()); |
36 ret->Set(v8::String::NewFromUtf8(isolate, "is_available"), | 39 ret->Set(v8::String::NewFromUtf8(isolate, "is_available"), |
37 v8::Boolean::New(isolate, availability.is_available())); | 40 v8::Boolean::New(isolate, availability.is_available())); |
38 ret->Set(v8::String::NewFromUtf8(isolate, "message"), | 41 ret->Set(v8::String::NewFromUtf8(isolate, "message"), |
39 v8::String::NewFromUtf8(isolate, availability.message().c_str())); | 42 v8::String::NewFromUtf8(isolate, availability.message().c_str())); |
40 ret->Set(v8::String::NewFromUtf8(isolate, "result"), | 43 ret->Set(v8::String::NewFromUtf8(isolate, "result"), |
41 v8::Integer::New(isolate, availability.result())); | 44 v8::Integer::New(isolate, availability.result())); |
42 args.GetReturnValue().Set(ret); | 45 args.GetReturnValue().Set(ret); |
43 } | 46 } |
44 | 47 |
45 void V8ContextNativeHandler::GetModuleSystem( | 48 void V8ContextNativeHandler::GetModuleSystem( |
46 const v8::FunctionCallbackInfo<v8::Value>& args) { | 49 const v8::FunctionCallbackInfo<v8::Value>& args) { |
47 CHECK_EQ(args.Length(), 1); | 50 CHECK_EQ(args.Length(), 1); |
48 CHECK(args[0]->IsObject()); | 51 CHECK(args[0]->IsObject()); |
49 ScriptContext* context = ScriptContextSet::GetContextByObject( | 52 ScriptContext* context = ScriptContextSet::GetContextByObject( |
50 v8::Local<v8::Object>::Cast(args[0])); | 53 v8::Local<v8::Object>::Cast(args[0])); |
51 if (blink::WebFrame::scriptCanAccess(context->web_frame())) | 54 if (blink::WebFrame::scriptCanAccess(context->web_frame())) |
52 args.GetReturnValue().Set(context->module_system()->NewInstance()); | 55 args.GetReturnValue().Set(context->module_system()->NewInstance()); |
53 } | 56 } |
54 | 57 |
55 void V8ContextNativeHandler::RunWithNativesEnabled( | 58 void V8ContextNativeHandler::RunWithNativesEnabled( |
56 const v8::FunctionCallbackInfo<v8::Value>& args) { | 59 const v8::FunctionCallbackInfo<v8::Value>& args) { |
57 CHECK_EQ(args.Length(), 1); | 60 CHECK_EQ(args.Length(), 1); |
58 CHECK(args[0]->IsFunction()); | 61 CHECK(args[0]->IsFunction()); |
59 ModuleSystem::NativesEnabledScope natives_enabled(context()->module_system()); | 62 ModuleSystem::NativesEnabledScope natives_enabled(context()->module_system()); |
60 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0])); | 63 context()->CallFunction(v8::Local<v8::Function>::Cast(args[0])); |
61 } | 64 } |
62 | 65 |
63 } // namespace extensions | 66 } // namespace extensions |
OLD | NEW |