OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/miscellaneous_bindings.h" | 5 #include "chrome/renderer/extensions/miscellaneous_bindings.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 class ExtensionImpl : public ChromeV8Extension { | 67 class ExtensionImpl : public ChromeV8Extension { |
68 public: | 68 public: |
69 explicit ExtensionImpl(ExtensionDispatcher* dispatcher) | 69 explicit ExtensionImpl(ExtensionDispatcher* dispatcher) |
70 : ChromeV8Extension("extensions/miscellaneous_bindings.js", | 70 : ChromeV8Extension("extensions/miscellaneous_bindings.js", |
71 IDR_MISCELLANEOUS_BINDINGS_JS, | 71 IDR_MISCELLANEOUS_BINDINGS_JS, |
72 arraysize(kExtensionDeps), kExtensionDeps, | 72 arraysize(kExtensionDeps), kExtensionDeps, |
73 dispatcher) { | 73 dispatcher) { |
74 } | 74 } |
75 ~ExtensionImpl() {} | 75 ~ExtensionImpl() {} |
76 | 76 |
77 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 77 void SetNativeFunctions(v8::Handle<v8::Object> object) { |
78 v8::Handle<v8::String> name) { | 78 RouteFunctionToStatic("OpenChannelToExtension", OpenChannelToExtension, |
79 if (name->Equals(v8::String::New("OpenChannelToExtension"))) { | 79 object); |
80 return v8::FunctionTemplate::New(OpenChannelToExtension); | 80 RouteFunctionToStatic("PostMessage", PostMessage, object); |
81 } else if (name->Equals(v8::String::New("PostMessage"))) { | 81 RouteFunctionToStatic("CloseChannel", CloseChannel, object); |
82 return v8::FunctionTemplate::New(PostMessage); | 82 RouteFunctionToStatic("PortAddRef", PortAddRef, object); |
83 } else if (name->Equals(v8::String::New("CloseChannel"))) { | 83 RouteFunctionToStatic("PortRelease", PortRelease, object); |
84 return v8::FunctionTemplate::New(CloseChannel); | 84 RouteFunctionToStatic("GetL10nMessage", GetL10nMessage, object); |
85 } else if (name->Equals(v8::String::New("PortAddRef"))) { | |
86 return v8::FunctionTemplate::New(PortAddRef); | |
87 } else if (name->Equals(v8::String::New("PortRelease"))) { | |
88 return v8::FunctionTemplate::New(PortRelease); | |
89 } else if (name->Equals(v8::String::New("GetL10nMessage"))) { | |
90 return v8::FunctionTemplate::New(GetL10nMessage); | |
91 } | |
92 return ChromeV8Extension::GetNativeFunction(name); | |
93 } | 85 } |
94 | 86 |
95 // Creates a new messaging channel to the given extension. | 87 // Creates a new messaging channel to the given extension. |
96 static v8::Handle<v8::Value> OpenChannelToExtension( | 88 static v8::Handle<v8::Value> OpenChannelToExtension( |
97 const v8::Arguments& args) { | 89 const v8::Arguments& args) { |
98 // 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 |
99 // the correct source. | 91 // the correct source. |
100 content::RenderView* renderview = GetCurrentRenderView(); | 92 content::RenderView* renderview = GetCurrentRenderView(); |
101 if (!renderview) | 93 if (!renderview) |
102 return v8::Undefined(); | 94 return v8::Undefined(); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 237 |
246 return v8::String::New(ReplaceStringPlaceholders( | 238 return v8::String::New(ReplaceStringPlaceholders( |
247 message, substitutions, NULL).c_str()); | 239 message, substitutions, NULL).c_str()); |
248 } | 240 } |
249 }; | 241 }; |
250 | 242 |
251 } // namespace | 243 } // namespace |
252 | 244 |
253 namespace extensions { | 245 namespace extensions { |
254 | 246 |
255 v8::Extension* MiscellaneousBindings::Get(ExtensionDispatcher* dispatcher) { | 247 ChromeV8Extension* MiscellaneousBindings::Get(ExtensionDispatcher* dispatcher) { |
256 static v8::Extension* extension = new ExtensionImpl(dispatcher); | 248 return new ExtensionImpl(dispatcher); |
257 return extension; | |
258 } | 249 } |
259 | 250 |
260 void MiscellaneousBindings::DeliverMessage( | 251 void MiscellaneousBindings::DeliverMessage( |
261 const ChromeV8ContextSet::ContextSet& contexts, | 252 const ChromeV8ContextSet::ContextSet& contexts, |
262 int target_port_id, | 253 int target_port_id, |
263 const std::string& message, | 254 const std::string& message, |
264 content::RenderView* restrict_to_render_view) { | 255 content::RenderView* restrict_to_render_view) { |
265 v8::HandleScope handle_scope; | 256 v8::HandleScope handle_scope; |
266 | 257 |
267 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); | 258 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); |
(...skipping 21 matching lines...) Expand all Loading... |
289 arguments.push_back(v8::String::New(message.c_str(), message.size())); | 280 arguments.push_back(v8::String::New(message.c_str(), message.size())); |
290 arguments.push_back(port_id_handle); | 281 arguments.push_back(port_id_handle); |
291 CHECK((*it)->CallChromeHiddenMethod("Port.dispatchOnMessage", | 282 CHECK((*it)->CallChromeHiddenMethod("Port.dispatchOnMessage", |
292 arguments.size(), | 283 arguments.size(), |
293 &arguments[0], | 284 &arguments[0], |
294 NULL)); | 285 NULL)); |
295 } | 286 } |
296 } | 287 } |
297 | 288 |
298 } // namespace extension | 289 } // namespace extension |
OLD | NEW |