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/renderer_extension_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" |
11 #include "base/lazy_instance.h" | 11 #include "base/lazy_instance.h" |
12 #include "chrome/common/extensions/extension_message_bundle.h" | 12 #include "chrome/common/extensions/extension_message_bundle.h" |
13 #include "chrome/common/extensions/extension_messages.h" | 13 #include "chrome/common/extensions/extension_messages.h" |
14 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
15 #include "chrome/renderer/extensions/chrome_v8_context.h" | 15 #include "chrome/renderer/extensions/chrome_v8_context.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 static void ClearPortData(int port_id) { | 60 static void ClearPortData(int port_id) { |
61 g_extension_data.Get().ports.erase(port_id); | 61 g_extension_data.Get().ports.erase(port_id); |
62 } | 62 } |
63 | 63 |
64 const char kPortClosedError[] = "Attempting to use a disconnected port object"; | 64 const char kPortClosedError[] = "Attempting to use a disconnected port object"; |
65 const char* kExtensionDeps[] = { "extensions/event.js" }; | 65 const char* kExtensionDeps[] = { "extensions/event.js" }; |
66 | 66 |
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/renderer_extension_bindings.js", | 70 : ChromeV8Extension("extensions/miscellaneous_bindings.js", |
71 IDR_RENDERER_EXTENSION_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 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
78 v8::Handle<v8::String> name) { | 78 v8::Handle<v8::String> name) { |
79 if (name->Equals(v8::String::New("OpenChannelToExtension"))) { | 79 if (name->Equals(v8::String::New("OpenChannelToExtension"))) { |
80 return v8::FunctionTemplate::New(OpenChannelToExtension); | 80 return v8::FunctionTemplate::New(OpenChannelToExtension); |
81 } else if (name->Equals(v8::String::New("PostMessage"))) { | 81 } else if (name->Equals(v8::String::New("PostMessage"))) { |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return v8::Undefined(); | 243 return v8::Undefined(); |
244 } | 244 } |
245 | 245 |
246 return v8::String::New(ReplaceStringPlaceholders( | 246 return v8::String::New(ReplaceStringPlaceholders( |
247 message, substitutions, NULL).c_str()); | 247 message, substitutions, NULL).c_str()); |
248 } | 248 } |
249 }; | 249 }; |
250 | 250 |
251 } // namespace | 251 } // namespace |
252 | 252 |
253 v8::Extension* RendererExtensionBindings::Get(ExtensionDispatcher* dispatcher) { | 253 namespace extensions { |
| 254 |
| 255 v8::Extension* MiscellaneousBindings::Get(ExtensionDispatcher* dispatcher) { |
254 static v8::Extension* extension = new ExtensionImpl(dispatcher); | 256 static v8::Extension* extension = new ExtensionImpl(dispatcher); |
255 return extension; | 257 return extension; |
256 } | 258 } |
257 | 259 |
258 void RendererExtensionBindings::DeliverMessage( | 260 void MiscellaneousBindings::DeliverMessage( |
259 const ChromeV8ContextSet::ContextSet& contexts, | 261 const ChromeV8ContextSet::ContextSet& contexts, |
260 int target_port_id, | 262 int target_port_id, |
261 const std::string& message, | 263 const std::string& message, |
262 content::RenderView* restrict_to_render_view) { | 264 content::RenderView* restrict_to_render_view) { |
263 v8::HandleScope handle_scope; | 265 v8::HandleScope handle_scope; |
264 | 266 |
265 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); | 267 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); |
266 it != contexts.end(); ++it) { | 268 it != contexts.end(); ++it) { |
267 | 269 |
268 if (restrict_to_render_view && | 270 if (restrict_to_render_view && |
(...skipping 16 matching lines...) Expand all Loading... |
285 | 287 |
286 std::vector<v8::Handle<v8::Value> > arguments; | 288 std::vector<v8::Handle<v8::Value> > arguments; |
287 arguments.push_back(v8::String::New(message.c_str(), message.size())); | 289 arguments.push_back(v8::String::New(message.c_str(), message.size())); |
288 arguments.push_back(port_id_handle); | 290 arguments.push_back(port_id_handle); |
289 CHECK((*it)->CallChromeHiddenMethod("Port.dispatchOnMessage", | 291 CHECK((*it)->CallChromeHiddenMethod("Port.dispatchOnMessage", |
290 arguments.size(), | 292 arguments.size(), |
291 &arguments[0], | 293 &arguments[0], |
292 NULL)); | 294 NULL)); |
293 } | 295 } |
294 } | 296 } |
| 297 |
| 298 } // namespace extension |
OLD | NEW |