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" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToExtension( | 41 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToExtension( |
42 const v8::Arguments& args) { | 42 const v8::Arguments& args) { |
43 // Get the current RenderView so that we can send a routed IPC message from | 43 // Get the current RenderView so that we can send a routed IPC message from |
44 // the correct source. | 44 // the correct source. |
45 content::RenderView* renderview = GetRenderView(); | 45 content::RenderView* renderview = GetRenderView(); |
46 if (!renderview) | 46 if (!renderview) |
47 return v8::Undefined(); | 47 return v8::Undefined(); |
48 | 48 |
49 // The Javascript code should validate/fill the arguments. | 49 // The Javascript code should validate/fill the arguments. |
50 CHECK(args.Length() >= 3 && | 50 CHECK_EQ(2, args.Length()); |
51 args[0]->IsString() && | 51 CHECK(args[0]->IsString() && args[1]->IsString()); |
52 args[1]->IsString() && | |
53 args[2]->IsString()); | |
54 | 52 |
55 ExtensionMsg_ExternalConnectionInfo info; | 53 ExtensionMsg_ExternalConnectionInfo info; |
56 info.source_id = *v8::String::Utf8Value(args[0]->ToString()); | 54 info.source_id = context()->extension() ? context()->extension()->id() : ""; |
57 info.target_id = *v8::String::Utf8Value(args[1]->ToString()); | 55 info.target_id = *v8::String::Utf8Value(args[0]->ToString()); |
58 info.source_url = renderview->GetWebView()->mainFrame()->document().url(); | 56 info.source_url = renderview->GetWebView()->mainFrame()->document().url(); |
59 std::string channel_name = *v8::String::Utf8Value(args[2]->ToString()); | 57 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); |
60 int port_id = -1; | 58 int port_id = -1; |
61 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( | 59 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( |
62 renderview->GetRoutingID(), info, channel_name, &port_id)); | 60 renderview->GetRoutingID(), info, channel_name, &port_id)); |
63 return v8::Integer::New(port_id); | 61 return v8::Integer::New(port_id); |
64 } | 62 } |
65 | 63 |
66 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( | 64 v8::Handle<v8::Value> RuntimeCustomBindings::OpenChannelToNativeApp( |
67 const v8::Arguments& args) { | 65 const v8::Arguments& args) { |
68 // Verify that the extension has permission to use native messaging. | 66 // Verify that the extension has permission to use native messaging. |
69 if (!dispatcher()->CheckContextAccessToExtensionAPI( | 67 if (!dispatcher()->CheckContextAccessToExtensionAPI( |
(...skipping 26 matching lines...) Expand all Loading... |
96 | 94 |
97 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( | 95 v8::Handle<v8::Value> RuntimeCustomBindings::GetManifest( |
98 const v8::Arguments& args) { | 96 const v8::Arguments& args) { |
99 CHECK(context()->extension()); | 97 CHECK(context()->extension()); |
100 | 98 |
101 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 99 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
102 return converter->ToV8Value(context()->extension()->manifest()->value(), | 100 return converter->ToV8Value(context()->extension()->manifest()->value(), |
103 context()->v8_context()); | 101 context()->v8_context()); |
104 } | 102 } |
105 | 103 |
106 } // extensions | 104 } // namespace extensions |
OLD | NEW |