| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/native_extension_bindings_system.h" | 5 #include "extensions/renderer/native_extension_bindings_system.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "content/public/common/console_message_level.h" | 9 #include "content/public/common/console_message_level.h" |
| 10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 send_event_listener_ipc_(send_event_listener_ipc), | 354 send_event_listener_ipc_(send_event_listener_ipc), |
| 355 api_system_( | 355 api_system_( |
| 356 base::Bind(&CallJsFunction), | 356 base::Bind(&CallJsFunction), |
| 357 base::Bind(&CallJsFunctionSync), | 357 base::Bind(&CallJsFunctionSync), |
| 358 base::Bind(&GetAPISchema), | 358 base::Bind(&GetAPISchema), |
| 359 base::Bind(&IsAPIFeatureAvailable), | 359 base::Bind(&IsAPIFeatureAvailable), |
| 360 base::Bind(&NativeExtensionBindingsSystem::SendRequest, | 360 base::Bind(&NativeExtensionBindingsSystem::SendRequest, |
| 361 base::Unretained(this)), | 361 base::Unretained(this)), |
| 362 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, | 362 base::Bind(&NativeExtensionBindingsSystem::OnEventListenerChanged, |
| 363 base::Unretained(this)), | 363 base::Unretained(this)), |
| 364 APILastError(base::Bind(&GetRuntime), base::Bind(&AddConsoleError))), | 364 APILastError(base::Bind(&GetLastErrorParents), |
| 365 base::Bind(&AddConsoleError))), |
| 365 weak_factory_(this) { | 366 weak_factory_(this) { |
| 366 api_system_.RegisterCustomType("storage.StorageArea", | 367 api_system_.RegisterCustomType("storage.StorageArea", |
| 367 base::Bind(&StorageArea::CreateStorageArea)); | 368 base::Bind(&StorageArea::CreateStorageArea)); |
| 368 api_system_.RegisterCustomType("types.ChromeSetting", | 369 api_system_.RegisterCustomType("types.ChromeSetting", |
| 369 base::Bind(&ChromeSetting::Create)); | 370 base::Bind(&ChromeSetting::Create)); |
| 370 api_system_.RegisterCustomType( | 371 api_system_.RegisterCustomType( |
| 371 "contentSettings.ContentSetting", | 372 "contentSettings.ContentSetting", |
| 372 base::Bind(&ContentSetting::Create, base::Bind(&CallJsFunction))); | 373 base::Bind(&ContentSetting::Create, base::Bind(&CallJsFunction))); |
| 373 api_system_.GetHooksForAPI("webRequest") | 374 api_system_.GetHooksForAPI("webRequest") |
| 374 ->SetDelegate(base::MakeUnique<WebRequestHooks>()); | 375 ->SetDelegate(base::MakeUnique<WebRequestHooks>()); |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 return v8::Local<v8::Object>(); | 572 return v8::Local<v8::Object>(); |
| 572 | 573 |
| 573 v8::Maybe<bool> success = | 574 v8::Maybe<bool> success = |
| 574 apis->CreateDataProperty(context, api_name, root_binding); | 575 apis->CreateDataProperty(context, api_name, root_binding); |
| 575 if (!success.IsJust() || !success.FromJust()) | 576 if (!success.IsJust() || !success.FromJust()) |
| 576 return v8::Local<v8::Object>(); | 577 return v8::Local<v8::Object>(); |
| 577 | 578 |
| 578 return root_binding; | 579 return root_binding; |
| 579 } | 580 } |
| 580 | 581 |
| 581 v8::Local<v8::Object> NativeExtensionBindingsSystem::GetRuntime( | 582 v8::Local<v8::Object> NativeExtensionBindingsSystem::GetLastErrorParents( |
| 582 v8::Local<v8::Context> context) { | 583 v8::Local<v8::Context> context, |
| 584 v8::Local<v8::Object>* secondary_parent) { |
| 585 if (secondary_parent && |
| 586 IsAPIFeatureAvailable(context, "extension.lastError")) { |
| 587 *secondary_parent = GetAPIHelper( |
| 588 context, gin::StringToSymbol(context->GetIsolate(), "extension")); |
| 589 } |
| 590 |
| 583 return GetAPIHelper(context, | 591 return GetAPIHelper(context, |
| 584 gin::StringToSymbol(context->GetIsolate(), "runtime")); | 592 gin::StringToSymbol(context->GetIsolate(), "runtime")); |
| 585 } | 593 } |
| 586 | 594 |
| 587 // static | 595 // static |
| 588 void NativeExtensionBindingsSystem::GetInternalAPI( | 596 void NativeExtensionBindingsSystem::GetInternalAPI( |
| 589 const v8::FunctionCallbackInfo<v8::Value>& info) { | 597 const v8::FunctionCallbackInfo<v8::Value>& info) { |
| 590 CHECK_EQ(1, info.Length()); | 598 CHECK_EQ(1, info.Length()); |
| 591 CHECK(info[0]->IsString()); | 599 CHECK(info[0]->IsString()); |
| 592 | 600 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 v8::Local<v8::Value>* binding_util_out) { | 703 v8::Local<v8::Value>* binding_util_out) { |
| 696 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle( | 704 gin::Handle<APIBindingJSUtil> handle = gin::CreateHandle( |
| 697 context->GetIsolate(), | 705 context->GetIsolate(), |
| 698 new APIBindingJSUtil( | 706 new APIBindingJSUtil( |
| 699 api_system_.type_reference_map(), api_system_.request_handler(), | 707 api_system_.type_reference_map(), api_system_.request_handler(), |
| 700 api_system_.event_handler(), base::Bind(&CallJsFunction))); | 708 api_system_.event_handler(), base::Bind(&CallJsFunction))); |
| 701 *binding_util_out = handle.ToV8(); | 709 *binding_util_out = handle.ToV8(); |
| 702 } | 710 } |
| 703 | 711 |
| 704 } // namespace extensions | 712 } // namespace extensions |
| OLD | NEW |