Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(491)

Side by Side Diff: chrome/renderer/extensions/renderer_extension_bindings.cc

Issue 8143009: Reland 103263 - Revert 103263 - Merge 101221 - Reland 101111 - Only deliver extension messages to... (Closed) Base URL: svn://svn.chromium.org/chrome/branches/874/src/
Patch Set: Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/renderer_extension_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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 246
247 } // namespace 247 } // namespace
248 248
249 const char* RendererExtensionBindings::kName = 249 const char* RendererExtensionBindings::kName =
250 "chrome/RendererExtensionBindings"; 250 "chrome/RendererExtensionBindings";
251 251
252 v8::Extension* RendererExtensionBindings::Get(ExtensionDispatcher* dispatcher) { 252 v8::Extension* RendererExtensionBindings::Get(ExtensionDispatcher* dispatcher) {
253 static v8::Extension* extension = new ExtensionImpl(dispatcher); 253 static v8::Extension* extension = new ExtensionImpl(dispatcher);
254 return extension; 254 return extension;
255 } 255 }
256
257 void RendererExtensionBindings::DeliverMessage(
258 int target_port_id,
259 const std::string& message,
260 RenderView* restrict_to_render_view) {
261 v8::HandleScope handle_scope;
262
263 bindings_utils::ContextList contexts = bindings_utils::GetContexts();
264 for (bindings_utils::ContextList::iterator it = contexts.begin();
265 it != contexts.end(); ++it) {
266
267 v8::Handle<v8::Context> context = (*it)->context;
268 if (context.IsEmpty())
269 continue;
270
271 if (restrict_to_render_view &&
272 restrict_to_render_view != (*it)->GetRenderView()) {
273 continue;
274 }
275
276 // Check to see whether the context has this port before bothering to create
277 // the message.
278 v8::Handle<v8::Value> port_id_handle = v8::Integer::New(target_port_id);
279 v8::Handle<v8::Value> has_port =
280 bindings_utils::CallFunctionInContext(
281 context, "Port.hasPort", 1, &port_id_handle);
282 CHECK(!has_port.IsEmpty());
283 if (!has_port->BooleanValue())
284 continue;
285
286 std::vector<v8::Handle<v8::Value> > arguments;
287 arguments.push_back(v8::String::New(message.c_str(), message.size()));
288 arguments.push_back(port_id_handle);
289 bindings_utils::CallFunctionInContext(
290 context, "Port.dispatchOnMessage",
291 arguments.size(), &arguments[0]);
292 }
293 }
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/renderer_extension_bindings.h ('k') | chrome/renderer/resources/renderer_extension_bindings.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698