| OLD | NEW |
| 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 "content/renderer/pepper/message_channel.h" | 5 #include "content/renderer/pepper/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" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 void MessageChannel::PostMessageToJavaScriptImpl( | 357 void MessageChannel::PostMessageToJavaScriptImpl( |
| 358 const WebSerializedScriptValue& message_data) { | 358 const WebSerializedScriptValue& message_data) { |
| 359 DCHECK(instance_); | 359 DCHECK(instance_); |
| 360 | 360 |
| 361 WebPluginContainer* container = instance_->container(); | 361 WebPluginContainer* container = instance_->container(); |
| 362 // It's possible that container() is NULL if the plugin has been removed from | 362 // It's possible that container() is NULL if the plugin has been removed from |
| 363 // the DOM (but the PluginInstance is not destroyed yet). | 363 // the DOM (but the PluginInstance is not destroyed yet). |
| 364 if (!container) | 364 if (!container) |
| 365 return; | 365 return; |
| 366 | 366 |
| 367 WebDOMEvent event = | |
| 368 container->element().document().createEvent("MessageEvent"); | |
| 369 WebDOMMessageEvent msg_event = event.to<WebDOMMessageEvent>(); | |
| 370 msg_event.initMessageEvent("message", // type | |
| 371 false, // canBubble | |
| 372 false, // cancelable | |
| 373 message_data, // data | |
| 374 "", // origin [*] | |
| 375 NULL, // source [*] | |
| 376 container->element().document(), // target document | |
| 377 ""); // lastEventId | |
| 378 // [*] Note that the |origin| is only specified for cross-document and server- | 367 // [*] Note that the |origin| is only specified for cross-document and server- |
| 379 // sent messages, while |source| is only specified for cross-document | 368 // sent messages, while |source| is only specified for cross-document |
| 380 // messages: | 369 // messages: |
| 381 // http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html | 370 // http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html |
| 382 // This currently behaves like Web Workers. On Firefox, Chrome, and Safari | 371 // This currently behaves like Web Workers. On Firefox, Chrome, and Safari |
| 383 // at least, postMessage on Workers does not provide the origin or source. | 372 // at least, postMessage on Workers does not provide the origin or source. |
| 384 // TODO(dmichael): Add origin if we change to a more iframe-like origin | 373 // TODO(dmichael): Add origin if we change to a more iframe-like origin |
| 385 // policy (see crbug.com/81537) | 374 // policy (see crbug.com/81537) |
| 375 WebDOMMessageEvent msg_event(message_data); |
| 386 container->element().dispatchEvent(msg_event); | 376 container->element().dispatchEvent(msg_event); |
| 387 } | 377 } |
| 388 | 378 |
| 389 PluginObject* MessageChannel::GetPluginObject(v8::Isolate* isolate) { | 379 PluginObject* MessageChannel::GetPluginObject(v8::Isolate* isolate) { |
| 390 return PluginObject::FromV8Object(isolate, | 380 return PluginObject::FromV8Object(isolate, |
| 391 v8::Local<v8::Object>::New(isolate, passthrough_object_)); | 381 v8::Local<v8::Object>::New(isolate, passthrough_object_)); |
| 392 } | 382 } |
| 393 | 383 |
| 394 void MessageChannel::EnqueuePluginMessage(v8::Local<v8::Value> v8_value) { | 384 void MessageChannel::EnqueuePluginMessage(v8::Local<v8::Value> v8_value) { |
| 395 plugin_message_queue_.push_back(VarConversionResult()); | 385 plugin_message_queue_.push_back(VarConversionResult()); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 478 v8::Local<v8::FunctionTemplate> function_template = template_cache_.Get(name); | 468 v8::Local<v8::FunctionTemplate> function_template = template_cache_.Get(name); |
| 479 if (!function_template.IsEmpty()) | 469 if (!function_template.IsEmpty()) |
| 480 return function_template; | 470 return function_template; |
| 481 function_template = gin::CreateFunctionTemplate( | 471 function_template = gin::CreateFunctionTemplate( |
| 482 isolate, base::Bind(memberFuncPtr, weak_ptr_factory_.GetWeakPtr())); | 472 isolate, base::Bind(memberFuncPtr, weak_ptr_factory_.GetWeakPtr())); |
| 483 template_cache_.Set(name, function_template); | 473 template_cache_.Set(name, function_template); |
| 484 return function_template; | 474 return function_template; |
| 485 } | 475 } |
| 486 | 476 |
| 487 } // namespace content | 477 } // namespace content |
| OLD | NEW |