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

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

Issue 15855010: Make ExtensionMsg_MessageInvoke run a module system function rather than a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: go Created 7 years, 6 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) 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/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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 CHECK_EQ(2, args.Length()); 127 CHECK_EQ(2, args.Length());
128 CHECK(args[0]->IsInt32()); 128 CHECK(args[0]->IsInt32());
129 CHECK(args[1]->IsBoolean()); 129 CHECK(args[1]->IsBoolean());
130 130
131 int port_id = args[0]->Int32Value(); 131 int port_id = args[0]->Int32Value();
132 if (!HasPortData(port_id)) 132 if (!HasPortData(port_id))
133 return v8::Undefined(); 133 return v8::Undefined();
134 134
135 // Send via the RenderThread because the RenderView might be closing. 135 // Send via the RenderThread because the RenderView might be closing.
136 bool notify_browser = args[1]->BooleanValue(); 136 bool notify_browser = args[1]->BooleanValue();
137 if (notify_browser) { 137 if (notify_browser)
138 content::RenderThread::Get()->Send( 138 content::RenderThread::Get()->Send(
139 new ExtensionHostMsg_CloseChannel(port_id, std::string())); 139 new ExtensionHostMsg_CloseChannel(port_id, std::string()));
140 }
141
142 ClearPortData(port_id); 140 ClearPortData(port_id);
143 141
144 return v8::Undefined(); 142 return v8::Undefined();
145 } 143 }
146 144
147 // A new port has been created for a context. This occurs both when script 145 // A new port has been created for a context. This occurs both when script
148 // opens a connection, and when a connection is opened to this script. 146 // opens a connection, and when a connection is opened to this script.
149 v8::Handle<v8::Value> PortAddRef(const v8::Arguments& args) { 147 v8::Handle<v8::Value> PortAddRef(const v8::Arguments& args) {
150 // Arguments are (int32 port_id). 148 // Arguments are (int32 port_id).
151 CHECK_EQ(1, args.Length()); 149 CHECK_EQ(1, args.Length());
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 251
254 v8::Handle<v8::Value> arguments[] = { 252 v8::Handle<v8::Value> arguments[] = {
255 v8::Integer::New(target_port_id), 253 v8::Integer::New(target_port_id),
256 v8::String::New(channel_name.c_str(), channel_name.size()), 254 v8::String::New(channel_name.c_str(), channel_name.size()),
257 tab, 255 tab,
258 v8::String::New(source_extension_id.c_str(), source_extension_id.size()), 256 v8::String::New(source_extension_id.c_str(), source_extension_id.size()),
259 v8::String::New(target_extension_id.c_str(), target_extension_id.size()), 257 v8::String::New(target_extension_id.c_str(), target_extension_id.size()),
260 v8::String::New(source_url_spec.c_str(), source_url_spec.size()) 258 v8::String::New(source_url_spec.c_str(), source_url_spec.size())
261 }; 259 };
262 260
263 v8::Handle<v8::Value> retval; 261 v8::Handle<v8::Value> retval = (*it)->module_system()->CallModuleMethod(
koz (OOO until 15th September) 2013/05/31 04:28:44 No more need for v8::TryCatch?
not at google - send to devlin 2013/05/31 22:47:07 Yeah CallModuleMethod handles it. I figure it's si
264 v8::TryCatch try_catch; 262 "miscellaneous_bindings",
265 if (!(*it)->CallChromeHiddenMethod("Port.dispatchOnConnect", 263 "dispatchOnConnect",
266 arraysize(arguments), arguments, 264 arraysize(arguments), arguments);
267 &retval)) {
268 continue;
269 }
270
271 if (try_catch.HasCaught()) {
272 LOG(ERROR) << "Exception caught when calling Port.dispatchOnConnect.";
273 continue;
274 }
275 265
276 if (retval.IsEmpty()) { 266 if (retval.IsEmpty()) {
277 LOG(ERROR) << "Empty return value from Port.dispatchOnConnect."; 267 LOG(ERROR) << "Empty return value from dispatchOnConnect.";
278 continue; 268 continue;
279 } 269 }
280 270
281 CHECK(retval->IsBoolean()); 271 CHECK(retval->IsBoolean());
282 if (retval->BooleanValue()) 272 port_created |= retval->BooleanValue();
283 port_created = true;
284 } 273 }
285 274
286 // If we didn't create a port, notify the other end of the channel (treat it 275 // If we didn't create a port, notify the other end of the channel (treat it
287 // as a disconnect). 276 // as a disconnect).
288 if (!port_created) { 277 if (!port_created) {
289 content::RenderThread::Get()->Send( 278 content::RenderThread::Get()->Send(
290 new ExtensionHostMsg_CloseChannel( 279 new ExtensionHostMsg_CloseChannel(
291 target_port_id, kReceivingEndDoesntExistError)); 280 target_port_id, kReceivingEndDoesntExistError));
292 } 281 }
293 } 282 }
(...skipping 12 matching lines...) Expand all
306 restrict_to_render_view != (*it)->GetRenderView()) { 295 restrict_to_render_view != (*it)->GetRenderView()) {
307 continue; 296 continue;
308 } 297 }
309 298
310 v8::Handle<v8::Context> context = (*it)->v8_context(); 299 v8::Handle<v8::Context> context = (*it)->v8_context();
311 v8::Context::Scope context_scope(context); 300 v8::Context::Scope context_scope(context);
312 301
313 // Check to see whether the context has this port before bothering to create 302 // Check to see whether the context has this port before bothering to create
314 // the message. 303 // the message.
315 v8::Handle<v8::Value> port_id_handle = v8::Integer::New(target_port_id); 304 v8::Handle<v8::Value> port_id_handle = v8::Integer::New(target_port_id);
316 v8::Handle<v8::Value> has_port; 305 v8::Handle<v8::Value> has_port = (*it)->module_system()->CallModuleMethod(
317 v8::TryCatch try_catch; 306 "miscellaneous_bindings",
318 if (!(*it)->CallChromeHiddenMethod("Port.hasPort", 1, &port_id_handle, 307 "hasPort",
319 &has_port)) { 308 1, &port_id_handle);
320 continue;
321 }
322
323 if (try_catch.HasCaught()) {
324 LOG(ERROR) << "Exception caught when calling Port.hasPort.";
325 continue;
326 }
327 309
328 CHECK(!has_port.IsEmpty()); 310 CHECK(!has_port.IsEmpty());
329 if (!has_port->BooleanValue()) 311 if (!has_port->BooleanValue())
330 continue; 312 continue;
331 313
332 std::vector<v8::Handle<v8::Value> > arguments; 314 std::vector<v8::Handle<v8::Value> > arguments;
333 315
334 // Convert the message to a v8 object; either a value or undefined. 316 // Convert the message to a v8 object; either a value or undefined.
335 // See PostMessage for more details. 317 // See PostMessage for more details.
336 if (message.empty()) { 318 if (message.empty()) {
337 arguments.push_back(v8::Undefined()); 319 arguments.push_back(v8::Undefined());
338 } else { 320 } else {
339 CHECK_EQ(1u, message.GetSize()); 321 CHECK_EQ(1u, message.GetSize());
340 const base::Value* message_value = NULL; 322 const base::Value* message_value = NULL;
341 message.Get(0, &message_value); 323 message.Get(0, &message_value);
342 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create()); 324 scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
343 arguments.push_back(converter->ToV8Value(message_value, context)); 325 arguments.push_back(converter->ToV8Value(message_value, context));
344 } 326 }
345 327
346 arguments.push_back(port_id_handle); 328 arguments.push_back(port_id_handle);
347 CHECK((*it)->CallChromeHiddenMethod("Port.dispatchOnMessage", 329 (*it)->module_system()->CallModuleMethod("miscellaneous_bindings",
348 arguments.size(), 330 "dispatchOnMessage",
349 &arguments[0], 331 &arguments);
350 NULL));
351 } 332 }
352 } 333 }
353 334
354 // static 335 // static
355 void MiscellaneousBindings::DispatchOnDisconnect( 336 void MiscellaneousBindings::DispatchOnDisconnect(
356 const ChromeV8ContextSet::ContextSet& contexts, 337 const ChromeV8ContextSet::ContextSet& contexts,
357 int port_id, 338 int port_id,
358 const std::string& error_message, 339 const std::string& error_message,
359 content::RenderView* restrict_to_render_view) { 340 content::RenderView* restrict_to_render_view) {
360 v8::HandleScope handle_scope; 341 v8::HandleScope handle_scope;
361 342
362 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin(); 343 for (ChromeV8ContextSet::ContextSet::const_iterator it = contexts.begin();
363 it != contexts.end(); ++it) { 344 it != contexts.end(); ++it) {
364 if (restrict_to_render_view && 345 if (restrict_to_render_view &&
365 restrict_to_render_view != (*it)->GetRenderView()) { 346 restrict_to_render_view != (*it)->GetRenderView()) {
366 continue; 347 continue;
367 } 348 }
368 349
369 std::vector<v8::Handle<v8::Value> > arguments; 350 std::vector<v8::Handle<v8::Value> > arguments;
370 arguments.push_back(v8::Integer::New(port_id)); 351 arguments.push_back(v8::Integer::New(port_id));
371 if (!error_message.empty()) { 352 if (!error_message.empty()) {
372 arguments.push_back(v8::String::New(error_message.c_str())); 353 arguments.push_back(v8::String::New(error_message.c_str()));
373 } else { 354 } else {
374 arguments.push_back(v8::Null()); 355 arguments.push_back(v8::Null());
375 } 356 }
376 (*it)->CallChromeHiddenMethod("Port.dispatchOnDisconnect", 357 (*it)->module_system()->CallModuleMethod("miscellaneous_bindings",
377 arguments.size(), &arguments[0], 358 "dispatchOnDisconnect",
378 NULL); 359 &arguments);
379 } 360 }
380 } 361 }
381 362
382 } // namespace extensions 363 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698