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

Side by Side Diff: content/browser/browser_plugin/browser_plugin_embedder_helper.cc

Issue 10829225: Browser Plugin: Add HTML5-like postMessage support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge with ToT. Added subframe targeting + test. Created 8 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) 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/browser/browser_plugin/browser_plugin_embedder_helper.h" 5 #include "content/browser/browser_plugin/browser_plugin_embedder_helper.h"
6 6
7 #include "content/browser/browser_plugin/browser_plugin_embedder.h" 7 #include "content/browser/browser_plugin/browser_plugin_embedder.h"
8 #include "content/browser/browser_plugin/browser_plugin_guest.h"
8 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/web_contents/web_contents_impl.h"
9 #include "content/common/browser_plugin_messages.h" 11 #include "content/common/browser_plugin_messages.h"
10 #include "content/common/view_messages.h" 12 #include "content/common/view_messages.h"
11 #include "content/public/browser/render_process_host.h" 13 #include "content/public/browser/render_process_host.h"
12 #include "content/public/browser/render_view_host.h" 14 #include "content/public/browser/render_view_host.h"
13 #include "content/public/browser/render_widget_host_view.h" 15 #include "content/public/browser/render_widget_host_view.h"
14 #include "ui/gfx/size.h" 16 #include "ui/gfx/size.h"
15 17
16 namespace content { 18 namespace content {
17 19
18 BrowserPluginEmbedderHelper::BrowserPluginEmbedderHelper( 20 BrowserPluginEmbedderHelper::BrowserPluginEmbedderHelper(
19 BrowserPluginEmbedder* embedder, 21 BrowserPluginEmbedder* embedder,
20 RenderViewHost* render_view_host) 22 RenderViewHost* render_view_host)
21 : RenderViewHostObserver(render_view_host), 23 : RenderViewHostObserver(render_view_host),
22 embedder_(embedder) { 24 embedder_(embedder) {
23 } 25 }
24 26
25 BrowserPluginEmbedderHelper::~BrowserPluginEmbedderHelper() { 27 BrowserPluginEmbedderHelper::~BrowserPluginEmbedderHelper() {
26 } 28 }
27 29
28 bool BrowserPluginEmbedderHelper::Send(IPC::Message* message) { 30 bool BrowserPluginEmbedderHelper::Send(IPC::Message* message) {
29 return RenderViewHostObserver::Send(message); 31 return RenderViewHostObserver::Send(message);
30 } 32 }
31 33
32 bool BrowserPluginEmbedderHelper::OnMessageReceived( 34 bool BrowserPluginEmbedderHelper::OnMessageReceived(
33 const IPC::Message& message) { 35 const IPC::Message& message) {
34 bool handled = true; 36 bool handled = true;
37 if (static_cast<content::RenderViewHostImpl*>(render_view_host())->
38 is_swapped_out()) {
39 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedderHelper, message)
40 IPC_MESSAGE_HANDLER(ViewHostMsg_RouteMessageEvent,
41 OnRouteMessageEvent)
42 IPC_MESSAGE_UNHANDLED(handled = false)
43 IPC_END_MESSAGE_MAP()
44 return handled;
45 }
35 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedderHelper, message) 46 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedderHelper, message)
36 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest, 47 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_NavigateGuest,
37 OnNavigateGuest); 48 OnNavigateGuest);
38 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest) 49 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_ResizeGuest, OnResizeGuest)
39 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK); 50 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_UpdateRect_ACK, OnUpdateRectACK);
40 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus); 51 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_SetFocus, OnSetFocus);
41 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_HandleInputEvent, 52 IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_HandleInputEvent,
42 OnHandleInputEvent(*static_cast<const IPC::SyncMessage*>(&message), 53 OnHandleInputEvent(*static_cast<const IPC::SyncMessage*>(&message),
43 &handled)) 54 &handled))
44 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed, 55 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_PluginDestroyed,
45 OnPluginDestroyed); 56 OnPluginDestroyed);
46 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo) 57 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Go, OnGo)
47 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop) 58 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Stop, OnStop)
48 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload) 59 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_Reload, OnReload)
49 IPC_MESSAGE_UNHANDLED(handled = false) 60 IPC_MESSAGE_UNHANDLED(handled = false)
50 IPC_END_MESSAGE_MAP() 61 IPC_END_MESSAGE_MAP()
62
51 return handled; 63 return handled;
52 } 64 }
53 65
54 void BrowserPluginEmbedderHelper::OnResizeGuest( 66 void BrowserPluginEmbedderHelper::OnResizeGuest(
55 int instance_id, 67 int instance_id,
56 const BrowserPluginHostMsg_ResizeGuest_Params& params) { 68 const BrowserPluginHostMsg_ResizeGuest_Params& params) {
57 embedder_->ResizeGuest(render_view_host(), instance_id, params); 69 embedder_->ResizeGuest(render_view_host(), instance_id, params);
58 } 70 }
59 71
60 void BrowserPluginEmbedderHelper::OnHandleInputEvent( 72 void BrowserPluginEmbedderHelper::OnHandleInputEvent(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 } 126 }
115 127
116 void BrowserPluginEmbedderHelper::OnSetFocus(int instance_id, bool focused) { 128 void BrowserPluginEmbedderHelper::OnSetFocus(int instance_id, bool focused) {
117 embedder_->SetFocus(instance_id, focused); 129 embedder_->SetFocus(instance_id, focused);
118 } 130 }
119 131
120 void BrowserPluginEmbedderHelper::OnPluginDestroyed(int instance_id) { 132 void BrowserPluginEmbedderHelper::OnPluginDestroyed(int instance_id) {
121 embedder_->PluginDestroyed(instance_id); 133 embedder_->PluginDestroyed(instance_id);
122 } 134 }
123 135
136 void BrowserPluginEmbedderHelper::OnRouteMessageEvent(
137 const ViewMsg_PostMessage_Params& params) {
138 // This helper's RVH corresponds to a swapped out RenderView living in
139 // the embedder's render process. If this RVH's WebContents has a
140 // BrowserPluginGuest, then we know this is actually a RVH for the
141 // guest for the purpose of catching ViewHostMsg_RouteMessageEvent and
142 // routing it to the guest WebContents.
143 // This code path is executed when the embedder tries to send a message
144 // back through event.source.postMessage within a 'message' event
145 // listener.
146 WebContentsImpl* guest_web_contents = static_cast<WebContentsImpl*>(
147 render_view_host()->GetDelegate());
148 if (!guest_web_contents->GetBrowserPluginGuest())
149 return;
150 embedder_->RouteMessageEvent(
151 guest_web_contents->GetBrowserPluginGuest()->instance_id(),
152 params.data,
153 params.source_frame_id,
154 params.target_origin,
155 params.target_frame_id);
156 }
157
124 void BrowserPluginEmbedderHelper::OnGo(int instance_id, int relative_index) { 158 void BrowserPluginEmbedderHelper::OnGo(int instance_id, int relative_index) {
125 embedder_->Go(instance_id, relative_index); 159 embedder_->Go(instance_id, relative_index);
126 } 160 }
127 161
128 void BrowserPluginEmbedderHelper::OnStop(int instance_id) { 162 void BrowserPluginEmbedderHelper::OnStop(int instance_id) {
129 embedder_->Stop(instance_id); 163 embedder_->Stop(instance_id);
130 } 164 }
131 165
132 void BrowserPluginEmbedderHelper::OnReload(int instance_id) { 166 void BrowserPluginEmbedderHelper::OnReload(int instance_id) {
133 embedder_->Reload(instance_id); 167 embedder_->Reload(instance_id);
134 } 168 }
135 169
136 } // namespace content 170 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698