Index: content/renderer/browser_plugin/browser_plugin.cc |
diff --git a/content/renderer/browser_plugin/browser_plugin.cc b/content/renderer/browser_plugin/browser_plugin.cc |
index 712c41a93f060738323e498f6fa612bbd476bcd5..9c0b50e86ea400171527e5bd0550489eaa4ffdaf 100644 |
--- a/content/renderer/browser_plugin/browser_plugin.cc |
+++ b/content/renderer/browser_plugin/browser_plugin.cc |
@@ -64,7 +64,8 @@ BrowserPlugin::BrowserPlugin( |
resize_pending_(false), |
navigate_src_sent_(false), |
process_id_(-1), |
- persist_storage_(false) { |
+ persist_storage_(false), |
+ guest_routing_id_(MSG_ROUTING_NONE) { |
BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
bindings_.reset(new BrowserPluginBindings(this)); |
@@ -132,6 +133,15 @@ void BrowserPlugin::SetSrcAttribute(const std::string& src) { |
guest_crashed_ = false; |
} |
+NPObject* BrowserPlugin::GetContentWindow() const { |
+ if (guest_routing_id_ == MSG_ROUTING_NONE) |
+ return NULL; |
+ RenderViewImpl* guest_render_view = static_cast<RenderViewImpl*>( |
+ ChildThread::current()->ResolveRoute(guest_routing_id_)); |
+ WebKit::WebFrame* guest_frame = guest_render_view->GetWebView()->mainFrame(); |
+ return guest_frame->windowObject(); |
+} |
+ |
std::string BrowserPlugin::GetPartitionAttribute() const { |
std::string value; |
if (persist_storage_) |
@@ -348,6 +358,45 @@ void BrowserPlugin::AdvanceFocus(bool reverse) { |
render_view_->GetWebView()->advanceFocus(reverse); |
} |
+void BrowserPlugin::ReceiveMessage(int source_routing_id, |
+ const string16& source_origin, |
+ int source_frame_id, |
+ const string16& data) { |
+ // This is a swapped out RenderViewImpl for the guest in the embedder process. |
+ WebKit::WebFrame* source_frame = NULL; |
+ if (source_routing_id != MSG_ROUTING_NONE) { |
+ RenderViewImpl* source_render_view = static_cast<RenderViewImpl*>( |
+ ChildThread::current()->ResolveRoute(source_routing_id)); |
+ DCHECK(source_render_view->is_swapped_out()); |
+ if (source_render_view) { |
+ // TODO(fsamuel, nasko): Lookup based on the frame id, once |
+ // http://crbug.com/153701 is fixed and we can rely on having frame tree |
+ // updates again. |
+ source_frame = source_render_view->webview()->mainFrame(); |
+ } |
+ } |
+ WebKit::WebFrame* target_frame = render_view_->webview()->mainFrame(); |
+ WebKit::WebDOMEvent event = |
+ target_frame->document().createEvent("MessageEvent"); |
+ WebKit::WebDOMMessageEvent msg_event = event.to<WebKit::WebDOMMessageEvent>(); |
+ msg_event.initMessageEvent("message", |
+ // |canBubble| and |cancellable| are always false |
+ false, false, |
+ WebKit::WebSerializedScriptValue::fromString(data), |
+ source_origin, source_frame, ""); |
+ // TODO(fsamuel): Does it make sense to do an origin check here? When |
+ // the guest replies back to the embedder, the embedder cannot possibly |
+ // navigate away to a different origin because the guest's lifetime |
+ // is tied to the embedder's lifetime. If the embedder navigates away, |
+ // the guest is cleaned up. |
+ container()->element().dispatchEvent(msg_event); |
+} |
+ |
+void BrowserPlugin::GuestContentWindowReady(int guest_routing_id) { |
+ DCHECK(guest_routing_id != MSG_ROUTING_NONE); |
+ guest_routing_id_ = guest_routing_id; |
+} |
+ |
void BrowserPlugin::SetAcceptTouchEvents(bool accept) { |
if (container()) |
container()->setIsAcceptingTouchEvents(accept); |