| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/renderer/extensions/runtime_custom_bindings.h" | 5 #include "chrome/renderer/extensions/runtime_custom_bindings.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/renderer/extensions/api_activity_logger.h" | 10 #include "chrome/renderer/extensions/api_activity_logger.h" |
| 11 #include "chrome/renderer/extensions/chrome_v8_context.h" | |
| 12 #include "chrome/renderer/extensions/dispatcher.h" | |
| 13 #include "chrome/renderer/extensions/extension_helper.h" | 11 #include "chrome/renderer/extensions/extension_helper.h" |
| 14 #include "content/public/renderer/render_view.h" | 12 #include "content/public/renderer/render_view.h" |
| 15 #include "content/public/renderer/v8_value_converter.h" | 13 #include "content/public/renderer/v8_value_converter.h" |
| 16 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 17 #include "extensions/common/extension_messages.h" | 15 #include "extensions/common/extension_messages.h" |
| 18 #include "extensions/common/features/feature.h" | 16 #include "extensions/common/features/feature.h" |
| 19 #include "extensions/common/features/feature_provider.h" | 17 #include "extensions/common/features/feature_provider.h" |
| 20 #include "extensions/common/manifest.h" | 18 #include "extensions/common/manifest.h" |
| 19 #include "extensions/renderer/script_context.h" |
| 21 #include "third_party/WebKit/public/web/WebDocument.h" | 20 #include "third_party/WebKit/public/web/WebDocument.h" |
| 22 #include "third_party/WebKit/public/web/WebFrame.h" | 21 #include "third_party/WebKit/public/web/WebFrame.h" |
| 23 #include "third_party/WebKit/public/web/WebView.h" | 22 #include "third_party/WebKit/public/web/WebView.h" |
| 24 | 23 |
| 25 using content::V8ValueConverter; | 24 using content::V8ValueConverter; |
| 26 | 25 |
| 27 namespace extensions { | 26 namespace extensions { |
| 28 | 27 |
| 29 RuntimeCustomBindings::RuntimeCustomBindings(Dispatcher* dispatcher, | 28 RuntimeCustomBindings::RuntimeCustomBindings(ScriptContext* context) |
| 30 ChromeV8Context* context) | 29 : ObjectBackedNativeHandler(context) { |
| 31 : ChromeV8Extension(dispatcher, context) { | |
| 32 RouteFunction("GetManifest", | 30 RouteFunction("GetManifest", |
| 33 base::Bind(&RuntimeCustomBindings::GetManifest, | 31 base::Bind(&RuntimeCustomBindings::GetManifest, |
| 34 base::Unretained(this))); | 32 base::Unretained(this))); |
| 35 RouteFunction("OpenChannelToExtension", | 33 RouteFunction("OpenChannelToExtension", |
| 36 base::Bind(&RuntimeCustomBindings::OpenChannelToExtension, | 34 base::Bind(&RuntimeCustomBindings::OpenChannelToExtension, |
| 37 base::Unretained(this))); | 35 base::Unretained(this))); |
| 38 RouteFunction("OpenChannelToNativeApp", | 36 RouteFunction("OpenChannelToNativeApp", |
| 39 base::Bind(&RuntimeCustomBindings::OpenChannelToNativeApp, | 37 base::Bind(&RuntimeCustomBindings::OpenChannelToNativeApp, |
| 40 base::Unretained(this))); | 38 base::Unretained(this))); |
| 41 RouteFunction("GetExtensionViews", | 39 RouteFunction("GetExtensionViews", |
| 42 base::Bind(&RuntimeCustomBindings::GetExtensionViews, | 40 base::Bind(&RuntimeCustomBindings::GetExtensionViews, |
| 43 base::Unretained(this))); | 41 base::Unretained(this))); |
| 44 } | 42 } |
| 45 | 43 |
| 46 RuntimeCustomBindings::~RuntimeCustomBindings() {} | 44 RuntimeCustomBindings::~RuntimeCustomBindings() {} |
| 47 | 45 |
| 48 void RuntimeCustomBindings::OpenChannelToExtension( | 46 void RuntimeCustomBindings::OpenChannelToExtension( |
| 49 const v8::FunctionCallbackInfo<v8::Value>& args) { | 47 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 50 // Get the current RenderView so that we can send a routed IPC message from | 48 // Get the current RenderView so that we can send a routed IPC message from |
| 51 // the correct source. | 49 // the correct source. |
| 52 content::RenderView* renderview = GetRenderView(); | 50 content::RenderView* renderview = context()->GetRenderView(); |
| 53 if (!renderview) | 51 if (!renderview) |
| 54 return; | 52 return; |
| 55 | 53 |
| 56 // The Javascript code should validate/fill the arguments. | 54 // The Javascript code should validate/fill the arguments. |
| 57 CHECK_EQ(args.Length(), 3); | 55 CHECK_EQ(args.Length(), 3); |
| 58 CHECK(args[0]->IsString() && args[1]->IsString() && args[2]->IsBoolean()); | 56 CHECK(args[0]->IsString() && args[1]->IsString() && args[2]->IsBoolean()); |
| 59 | 57 |
| 60 ExtensionMsg_ExternalConnectionInfo info; | 58 ExtensionMsg_ExternalConnectionInfo info; |
| 61 | 59 |
| 62 // For messaging APIs, hosted apps should be considered a web page so hide | 60 // For messaging APIs, hosted apps should be considered a web page so hide |
| (...skipping 11 matching lines...) Expand all Loading... |
| 74 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( | 72 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( |
| 75 renderview->GetRoutingID(), info, channel_name, include_tls_channel_id, | 73 renderview->GetRoutingID(), info, channel_name, include_tls_channel_id, |
| 76 &port_id)); | 74 &port_id)); |
| 77 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); | 75 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); |
| 78 } | 76 } |
| 79 | 77 |
| 80 void RuntimeCustomBindings::OpenChannelToNativeApp( | 78 void RuntimeCustomBindings::OpenChannelToNativeApp( |
| 81 const v8::FunctionCallbackInfo<v8::Value>& args) { | 79 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 82 // Verify that the extension has permission to use native messaging. | 80 // Verify that the extension has permission to use native messaging. |
| 83 Feature::Availability availability = | 81 Feature::Availability availability = |
| 84 FeatureProvider::GetPermissionFeatures()-> | 82 FeatureProvider::GetPermissionFeatures() |
| 85 GetFeature("nativeMessaging")->IsAvailableToContext( | 83 ->GetFeature("nativeMessaging") |
| 86 GetExtensionForRenderView(), | 84 ->IsAvailableToContext(context()->extension(), |
| 87 context()->context_type(), | 85 context()->context_type(), |
| 88 context()->GetURL()); | 86 context()->GetURL()); |
| 89 if (!availability.is_available()) | 87 if (!availability.is_available()) |
| 90 return; | 88 return; |
| 91 | 89 |
| 92 // Get the current RenderView so that we can send a routed IPC message from | 90 // Get the current RenderView so that we can send a routed IPC message from |
| 93 // the correct source. | 91 // the correct source. |
| 94 content::RenderView* renderview = GetRenderView(); | 92 content::RenderView* renderview = context()->GetRenderView(); |
| 95 if (!renderview) | 93 if (!renderview) |
| 96 return; | 94 return; |
| 97 | 95 |
| 98 // The Javascript code should validate/fill the arguments. | 96 // The Javascript code should validate/fill the arguments. |
| 99 CHECK(args.Length() >= 2 && | 97 CHECK(args.Length() >= 2 && |
| 100 args[0]->IsString() && | 98 args[0]->IsString() && |
| 101 args[1]->IsString()); | 99 args[1]->IsString()); |
| 102 | 100 |
| 103 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString()); | 101 std::string extension_id = *v8::String::Utf8Value(args[0]->ToString()); |
| 104 std::string native_app_name = *v8::String::Utf8Value(args[1]->ToString()); | 102 std::string native_app_name = *v8::String::Utf8Value(args[1]->ToString()); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 v8::Local<v8::Value> window = context->Global(); | 170 v8::Local<v8::Value> window = context->Global(); |
| 173 DCHECK(!window.IsEmpty()); | 171 DCHECK(!window.IsEmpty()); |
| 174 v8_views->Set(v8::Integer::New(args.GetIsolate(), v8_index++), window); | 172 v8_views->Set(v8::Integer::New(args.GetIsolate(), v8_index++), window); |
| 175 } | 173 } |
| 176 } | 174 } |
| 177 | 175 |
| 178 args.GetReturnValue().Set(v8_views); | 176 args.GetReturnValue().Set(v8_views); |
| 179 } | 177 } |
| 180 | 178 |
| 181 } // namespace extensions | 179 } // namespace extensions |
| OLD | NEW |