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/common/extensions/extension.h" | 10 #include "chrome/common/extensions/extension.h" |
11 #include "chrome/common/extensions/extension_messages.h" | 11 #include "chrome/common/extensions/extension_messages.h" |
| 12 #include "chrome/common/extensions/features/base_feature_provider.h" |
12 #include "chrome/common/extensions/manifest.h" | 13 #include "chrome/common/extensions/manifest.h" |
13 #include "chrome/renderer/extensions/chrome_v8_context.h" | 14 #include "chrome/renderer/extensions/chrome_v8_context.h" |
14 #include "chrome/renderer/extensions/dispatcher.h" | 15 #include "chrome/renderer/extensions/dispatcher.h" |
15 #include "content/public/renderer/render_view.h" | 16 #include "content/public/renderer/render_view.h" |
16 #include "content/public/renderer/v8_value_converter.h" | 17 #include "content/public/renderer/v8_value_converter.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
20 | 21 |
21 using content::V8ValueConverter; | 22 using content::V8ValueConverter; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); | 58 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); |
58 int port_id = -1; | 59 int port_id = -1; |
59 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( | 60 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( |
60 renderview->GetRoutingID(), info, channel_name, &port_id)); | 61 renderview->GetRoutingID(), info, channel_name, &port_id)); |
61 return v8::Integer::New(port_id); | 62 return v8::Integer::New(port_id); |
62 } | 63 } |
63 | 64 |
64 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( | 65 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( |
65 const v8::Arguments& args) { | 66 const v8::Arguments& args) { |
66 // Verify that the extension has permission to use native messaging. | 67 // Verify that the extension has permission to use native messaging. |
67 if (!dispatcher()->CheckContextAccessToExtensionAPI( | 68 if (!BaseFeatureProvider::GetByName("permission")->GetFeature( |
68 "nativeMessaging", context())) { | 69 "nativeMessaging")->IsAvailableToContext( |
| 70 GetExtensionForRenderView(), |
| 71 context()->context_type(), |
| 72 context()->GetURL()).is_available()) { |
69 return v8::Undefined(); | 73 return v8::Undefined(); |
70 } | 74 } |
71 | 75 |
72 // Get the current RenderView so that we can send a routed IPC message from | 76 // Get the current RenderView so that we can send a routed IPC message from |
73 // the correct source. | 77 // the correct source. |
74 content::RenderView* renderview = GetRenderView(); | 78 content::RenderView* renderview = GetRenderView(); |
75 if (!renderview) | 79 if (!renderview) |
76 return v8::Undefined(); | 80 return v8::Undefined(); |
77 | 81 |
78 // The Javascript code should validate/fill the arguments. | 82 // The Javascript code should validate/fill the arguments. |
(...skipping 16 matching lines...) Expand all Loading... |
95 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( | 99 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( |
96 const v8::Arguments& args) { | 100 const v8::Arguments& args) { |
97 CHECK(context()->extension()); | 101 CHECK(context()->extension()); |
98 | 102 |
99 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 103 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
100 return converter->ToV8Value(context()->extension()->manifest()->value(), | 104 return converter->ToV8Value(context()->extension()->manifest()->value(), |
101 context()->v8_context()); | 105 context()->v8_context()); |
102 } | 106 } |
103 | 107 |
104 } // namespace extensions | 108 } // namespace extensions |
OLD | NEW |