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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // the correct source. | 47 // the correct source. |
48 content::RenderView* renderview = GetRenderView(); | 48 content::RenderView* renderview = GetRenderView(); |
49 if (!renderview) | 49 if (!renderview) |
50 return; | 50 return; |
51 | 51 |
52 // The Javascript code should validate/fill the arguments. | 52 // The Javascript code should validate/fill the arguments. |
53 CHECK_EQ(2, args.Length()); | 53 CHECK_EQ(2, args.Length()); |
54 CHECK(args[0]->IsString() && args[1]->IsString()); | 54 CHECK(args[0]->IsString() && args[1]->IsString()); |
55 | 55 |
56 ExtensionMsg_ExternalConnectionInfo info; | 56 ExtensionMsg_ExternalConnectionInfo info; |
57 info.source_id = context()->extension() ? context()->extension()->id() : ""; | 57 info.source_id = context()->GetExtensionID(); |
58 info.target_id = *v8::String::Utf8Value(args[0]->ToString()); | 58 info.target_id = *v8::String::Utf8Value(args[0]->ToString()); |
59 info.source_url = renderview->GetWebView()->mainFrame()->document().url(); | 59 info.source_url = context()->GetURL(); |
60 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); | 60 std::string channel_name = *v8::String::Utf8Value(args[1]->ToString()); |
61 int port_id = -1; | 61 int port_id = -1; |
62 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( | 62 renderview->Send(new ExtensionHostMsg_OpenChannelToExtension( |
63 renderview->GetRoutingID(), info, channel_name, &port_id)); | 63 renderview->GetRoutingID(), info, channel_name, &port_id)); |
64 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); | 64 args.GetReturnValue().Set(static_cast<int32_t>(port_id)); |
65 } | 65 } |
66 | 66 |
67 void RuntimeCustomBindings::OpenChannelToNativeApp( | 67 void RuntimeCustomBindings::OpenChannelToNativeApp( |
68 const v8::FunctionCallbackInfo<v8::Value>& args) { | 68 const v8::FunctionCallbackInfo<v8::Value>& args) { |
69 // Verify that the extension has permission to use native messaging. | 69 // Verify that the extension has permission to use native messaging. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 const v8::FunctionCallbackInfo<v8::Value>& args) { | 107 const v8::FunctionCallbackInfo<v8::Value>& args) { |
108 CHECK(context()->extension()); | 108 CHECK(context()->extension()); |
109 | 109 |
110 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); | 110 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); |
111 args.GetReturnValue().Set( | 111 args.GetReturnValue().Set( |
112 converter->ToV8Value(context()->extension()->manifest()->value(), | 112 converter->ToV8Value(context()->extension()->manifest()->value(), |
113 context()->v8_context())); | 113 context()->v8_context())); |
114 } | 114 } |
115 | 115 |
116 } // namespace extensions | 116 } // namespace extensions |
OLD | NEW |