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/manifest.h" | 12 #include "chrome/common/extensions/manifest.h" |
13 #include "chrome/renderer/extensions/chrome_v8_context.h" | 13 #include "chrome/renderer/extensions/chrome_v8_context.h" |
14 #include "chrome/renderer/extensions/dispatcher.h" | 14 #include "chrome/renderer/extensions/dispatcher.h" |
15 #include "content/public/renderer/render_view.h" | 15 #include "content/public/renderer/render_view.h" |
16 #include "content/public/renderer/v8_value_converter.h" | 16 #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/WebFrame.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
17 | 20 |
18 using content::V8ValueConverter; | 21 using content::V8ValueConverter; |
19 | 22 |
20 namespace extensions { | 23 namespace extensions { |
21 | 24 |
22 RuntimeCustomBindings::RuntimeCustomBindings(Dispatcher* dispatcher, | 25 RuntimeCustomBindings::RuntimeCustomBindings(Dispatcher* dispatcher, |
23 ChromeV8Context* context) | 26 ChromeV8Context* context) |
24 : ChromeV8Extension(dispatcher, context->v8_context()), | 27 : ChromeV8Extension(dispatcher, context->v8_context()), |
25 context_(context) { | 28 context_(context) { |
26 RouteFunction("GetManifest", | 29 RouteFunction("GetManifest", |
(...skipping 16 matching lines...) Expand all Loading... |
43 content::RenderView* renderview = GetRenderView(); | 46 content::RenderView* renderview = GetRenderView(); |
44 if (!renderview) | 47 if (!renderview) |
45 return v8::Undefined(); | 48 return v8::Undefined(); |
46 | 49 |
47 // The Javascript code should validate/fill the arguments. | 50 // The Javascript code should validate/fill the arguments. |
48 CHECK(args.Length() >= 3 && | 51 CHECK(args.Length() >= 3 && |
49 args[0]->IsString() && | 52 args[0]->IsString() && |
50 args[1]->IsString() && | 53 args[1]->IsString() && |
51 args[2]->IsString()); | 54 args[2]->IsString()); |
52 | 55 |
53 std::string source_id = *v8::String::Utf8Value(args[0]->ToString()); | 56 ExtensionMsg_ExternalConnectionInfo info; |
54 std::string target_id = *v8::String::Utf8Value(args[1]->ToString()); | 57 info.source_id = *v8::String::Utf8Value(args[0]->ToString()); |
| 58 info.target_id = *v8::String::Utf8Value(args[1]->ToString()); |
| 59 info.source_url = renderview->GetWebView()->mainFrame()->document().url(); |
55 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); | 60 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); |
56 int port_id = -1; | 61 int port_id = -1; |
57 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( | 62 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( |
58 renderview->GetRoutingID(), | 63 renderview->GetRoutingID(), info, channel_name, &port_id)); |
59 source_id, | |
60 target_id, | |
61 channel_name, | |
62 &port_id)); | |
63 return v8::Integer::New(port_id); | 64 return v8::Integer::New(port_id); |
64 } | 65 } |
65 | 66 |
66 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( | 67 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( |
67 const v8::Arguments& args) { | 68 const v8::Arguments& args) { |
68 // Verify that the extension has permission to use native messaging. | 69 // Verify that the extension has permission to use native messaging. |
69 if (!dispatcher()->CheckContextAccessToExtensionAPI( | 70 if (!dispatcher()->CheckContextAccessToExtensionAPI( |
70 "nativeMessaging", context_)) { | 71 "nativeMessaging", context_)) { |
71 return v8::Undefined(); | 72 return v8::Undefined(); |
72 } | 73 } |
(...skipping 24 matching lines...) Expand all Loading... |
97 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( | 98 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( |
98 const v8::Arguments& args) { | 99 const v8::Arguments& args) { |
99 CHECK(context_->extension()); | 100 CHECK(context_->extension()); |
100 | 101 |
101 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 102 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
102 return converter->ToV8Value(context_->extension()->manifest()->value(), | 103 return converter->ToV8Value(context_->extension()->manifest()->value(), |
103 context_->v8_context()); | 104 context_->v8_context()); |
104 } | 105 } |
105 | 106 |
106 } // extensions | 107 } // extensions |
OLD | NEW |