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

Side by Side Diff: webkit/plugins/ppapi/message_channel.cc

Issue 11264049: PPAPI: Make Messaging not PostTask and copy when out-of-process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month 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
« no previous file with comments | « no previous file | webkit/plugins/ppapi/plugin_module.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "webkit/plugins/ppapi/message_channel.h" 5 #include "webkit/plugins/ppapi/message_channel.h"
6 6
7 #include <cstdlib> 7 #include <cstdlib>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "ppapi/shared_impl/ppapi_globals.h" 13 #include "ppapi/shared_impl/ppapi_globals.h"
14 #include "ppapi/shared_impl/var.h" 14 #include "ppapi/shared_impl/var.h"
15 #include "ppapi/shared_impl/var_tracker.h" 15 #include "ppapi/shared_impl/var_tracker.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h" 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDOMMessageEvent.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h"
24 #include "v8/include/v8.h" 24 #include "v8/include/v8.h"
25 #include "webkit/plugins/ppapi/host_array_buffer_var.h" 25 #include "webkit/plugins/ppapi/host_array_buffer_var.h"
26 #include "webkit/plugins/ppapi/npapi_glue.h" 26 #include "webkit/plugins/ppapi/npapi_glue.h"
27 #include "webkit/plugins/ppapi/plugin_module.h"
27 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 28 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
28 29
29 using ppapi::ArrayBufferVar; 30 using ppapi::ArrayBufferVar;
30 using ppapi::PpapiGlobals; 31 using ppapi::PpapiGlobals;
31 using ppapi::StringVar; 32 using ppapi::StringVar;
32 using WebKit::WebBindings; 33 using WebKit::WebBindings;
33 using WebKit::WebElement; 34 using WebKit::WebElement;
34 using WebKit::WebDOMEvent; 35 using WebKit::WebDOMEvent;
35 using WebKit::WebDOMMessageEvent; 36 using WebKit::WebDOMMessageEvent;
36 using WebKit::WebPluginContainer; 37 using WebKit::WebPluginContainer;
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 352
352 v8::Local<v8::Value> v8_val; 353 v8::Local<v8::Value> v8_val;
353 if (!PPVarToV8Value(message_data, &v8_val)) { 354 if (!PPVarToV8Value(message_data, &v8_val)) {
354 NOTREACHED(); 355 NOTREACHED();
355 return; 356 return;
356 } 357 }
357 358
358 WebSerializedScriptValue serialized_val = 359 WebSerializedScriptValue serialized_val =
359 WebSerializedScriptValue::serialize(v8_val); 360 WebSerializedScriptValue::serialize(v8_val);
360 361
361 MessageLoop::current()->PostTask( 362 if (instance_->module()->IsProxied()) {
362 FROM_HERE, 363 // The proxy sent an asynchronous message, so the plugin is already
363 base::Bind(&MessageChannel::PostMessageToJavaScriptImpl, 364 // unblocked. Therefore, there's no need to PostTask.
364 weak_ptr_factory_.GetWeakPtr(), 365 PostMessageToJavaScriptImpl(serialized_val);
365 serialized_val)); 366 } else {
367 MessageLoop::current()->PostTask(
368 FROM_HERE,
369 base::Bind(&MessageChannel::PostMessageToJavaScriptImpl,
370 weak_ptr_factory_.GetWeakPtr(),
371 serialized_val));
372 }
366 } 373 }
367 374
368 void MessageChannel::PostMessageToJavaScriptImpl( 375 void MessageChannel::PostMessageToJavaScriptImpl(
369 const WebSerializedScriptValue& message_data) { 376 const WebSerializedScriptValue& message_data) {
370 DCHECK(instance_); 377 DCHECK(instance_);
371 378
372 WebPluginContainer* container = instance_->container(); 379 WebPluginContainer* container = instance_->container();
373 // It's possible that container() is NULL if the plugin has been removed from 380 // It's possible that container() is NULL if the plugin has been removed from
374 // the DOM (but the PluginInstance is not destroyed yet). 381 // the DOM (but the PluginInstance is not destroyed yet).
375 if (!container) 382 if (!container)
(...skipping 15 matching lines...) Expand all
391 // http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html 398 // http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html
392 // This currently behaves like Web Workers. On Firefox, Chrome, and Safari 399 // This currently behaves like Web Workers. On Firefox, Chrome, and Safari
393 // at least, postMessage on Workers does not provide the origin or source. 400 // at least, postMessage on Workers does not provide the origin or source.
394 // TODO(dmichael): Add origin if we change to a more iframe-like origin 401 // TODO(dmichael): Add origin if we change to a more iframe-like origin
395 // policy (see crbug.com/81537) 402 // policy (see crbug.com/81537)
396 403
397 container->element().dispatchEvent(msg_event); 404 container->element().dispatchEvent(msg_event);
398 } 405 }
399 406
400 void MessageChannel::PostMessageToNative(PP_Var message_data) { 407 void MessageChannel::PostMessageToNative(PP_Var message_data) {
401 // Make a copy of the message data for the Task we will run. 408 if (instance_->module()->IsProxied()) {
402 PP_Var var_copy(CopyPPVar(message_data)); 409 // In the proxied case, the copy will happen via serialization, and the
410 // message is asynchronous. Therefore there's no need to copy the Var, nor
411 // to PostTask.
412 PostMessageToNativeImpl(message_data);
413 } else {
414 // Make a copy of the message data for the Task we will run.
415 PP_Var var_copy(CopyPPVar(message_data));
403 416
404 MessageLoop::current()->PostTask(FROM_HERE, 417 MessageLoop::current()->PostTask(FROM_HERE,
405 base::Bind(&MessageChannel::PostMessageToNativeImpl, 418 base::Bind(&MessageChannel::PostMessageToNativeImpl,
406 weak_ptr_factory_.GetWeakPtr(), 419 weak_ptr_factory_.GetWeakPtr(),
407 var_copy)); 420 var_copy));
421 }
408 } 422 }
409 423
410 void MessageChannel::PostMessageToNativeImpl(PP_Var message_data) { 424 void MessageChannel::PostMessageToNativeImpl(PP_Var message_data) {
411 instance_->HandleMessage(message_data); 425 instance_->HandleMessage(message_data);
412 } 426 }
413 427
414 MessageChannel::~MessageChannel() { 428 MessageChannel::~MessageChannel() {
415 WebBindings::releaseObject(np_object_); 429 WebBindings::releaseObject(np_object_);
416 if (passthrough_object_) 430 if (passthrough_object_)
417 WebBindings::releaseObject(passthrough_object_); 431 WebBindings::releaseObject(passthrough_object_);
(...skipping 10 matching lines...) Expand all
428 // invokes: 442 // invokes:
429 // SetPassthroughObject(passthrough_object()); 443 // SetPassthroughObject(passthrough_object());
430 if (passthrough_object_) 444 if (passthrough_object_)
431 WebBindings::releaseObject(passthrough_object_); 445 WebBindings::releaseObject(passthrough_object_);
432 446
433 passthrough_object_ = passthrough; 447 passthrough_object_ = passthrough;
434 } 448 }
435 449
436 } // namespace ppapi 450 } // namespace ppapi
437 } // namespace webkit 451 } // namespace webkit
OLDNEW
« no previous file with comments | « no previous file | webkit/plugins/ppapi/plugin_module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698