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 // A BrowserPluginGuest represents the browser side of browser <--> renderer | 5 // A BrowserPluginGuest is the browser side of a browser <--> embedder |
6 // communication. A BrowserPlugin (a WebPlugin) is on the renderer side of | 6 // renderer channel. A BrowserPlugin (a WebPlugin) is on the embedder |
7 // browser <--> guest renderer communication. The 'guest' renderer is a | 7 // renderer side of browser <--> embedder renderer communication. |
8 // <browser> tag. | |
9 // | 8 // |
10 // BrowserPluginGuest lives on the UI thread of the browser process. It has a | 9 // BrowserPluginGuest lives on the UI thread of the browser process. It has a |
11 // helper, BrowserPluginGuestHelper, which is a RenderViewHostObserver. The | 10 // helper, BrowserPluginGuestHelper, which is a RenderViewHostObserver. The |
12 // helper object receives messages (ViewHostMsg_*) directed at the browser | 11 // helper object intercepts messages (ViewHostMsg_*) directed at the browser |
13 // plugin and redirects them to this class. Any messages the embedder might be | 12 // process and redirects them to this class. Any messages about the guest render |
14 // interested in knowing or modifying about the guest should be listened for | 13 // process that the embedder might be interested in receiving should be listened |
15 // here. | 14 // for here. |
16 // | 15 // |
17 // Since BrowserPlugin is a WebPlugin, we need to provide overridden behaviors | 16 // BrowserPluginGuest is a WebContentsDelegate and WebContentsObserver for the |
18 // for messages like handleInputEvent, updateGeometry. Such messages get | 17 // guest WebContents. BrowserPluginGuest operates under the assumption that the |
19 // routed into BrowserPluginGuest via its embedder (BrowserPluginEmbedder). | 18 // guest will be accessible through only one RenderViewHost for the lifetime of |
20 // These are BrowserPluginHost_* messages sent from the BrowserPlugin. | 19 // the guest WebContents. Thus, cross-process navigation is not supported. |
21 // | |
22 // BrowserPluginGuest knows about its embedder process. Communication to | |
23 // renderer happens through the embedder process. | |
24 // | |
25 // A BrowserPluginGuest is also associated directly with the WebContents related | |
26 // to the BrowserPlugin. BrowserPluginGuest is a WebContentsDelegate and | |
27 // WebContentsObserver for the WebContents. | |
28 | 20 |
29 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 21 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
30 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 22 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
31 | 23 |
32 #include <map> | 24 #include <map> |
33 | 25 |
34 #include "base/compiler_specific.h" | 26 #include "base/compiler_specific.h" |
35 #include "base/id_map.h" | 27 #include "base/id_map.h" |
36 #include "base/time.h" | 28 #include "base/time.h" |
| 29 #include "content/port/common/input_event_ack_state.h" |
37 #include "content/public/browser/notification_observer.h" | 30 #include "content/public/browser/notification_observer.h" |
38 #include "content/public/browser/notification_registrar.h" | 31 #include "content/public/browser/notification_registrar.h" |
39 #include "content/public/browser/web_contents_delegate.h" | 32 #include "content/public/browser/web_contents_delegate.h" |
40 #include "content/public/browser/web_contents_observer.h" | 33 #include "content/public/browser/web_contents_observer.h" |
41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" | 34 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" |
42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" | 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
43 #include "ui/gfx/rect.h" | 37 #include "ui/gfx/rect.h" |
44 #include "ui/surface/transport_dib.h" | 38 #include "ui/surface/transport_dib.h" |
45 | 39 |
46 struct BrowserPluginHostMsg_AutoSize_Params; | 40 struct BrowserPluginHostMsg_AutoSize_Params; |
47 struct BrowserPluginHostMsg_CreateGuest_Params; | 41 struct BrowserPluginHostMsg_CreateGuest_Params; |
48 struct BrowserPluginHostMsg_ResizeGuest_Params; | 42 struct BrowserPluginHostMsg_ResizeGuest_Params; |
49 #if defined(OS_MACOSX) | 43 #if defined(OS_MACOSX) |
50 struct ViewHostMsg_ShowPopup_Params; | 44 struct ViewHostMsg_ShowPopup_Params; |
51 #endif | 45 #endif |
52 struct ViewHostMsg_UpdateRect_Params; | 46 struct ViewHostMsg_UpdateRect_Params; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 virtual void DidCommitProvisionalLoadForFrame( | 118 virtual void DidCommitProvisionalLoadForFrame( |
125 int64 frame_id, | 119 int64 frame_id, |
126 bool is_main_frame, | 120 bool is_main_frame, |
127 const GURL& url, | 121 const GURL& url, |
128 PageTransition transition_type, | 122 PageTransition transition_type, |
129 RenderViewHost* render_view_host) OVERRIDE; | 123 RenderViewHost* render_view_host) OVERRIDE; |
130 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE; | 124 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE; |
131 | 125 |
132 virtual void RenderViewReady() OVERRIDE; | 126 virtual void RenderViewReady() OVERRIDE; |
133 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | 127 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 128 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 129 |
134 | 130 |
135 // WebContentsDelegate implementation. | 131 // WebContentsDelegate implementation. |
136 virtual bool CanDownload(RenderViewHost* render_view_host, | 132 virtual bool CanDownload(RenderViewHost* render_view_host, |
137 int request_id, | 133 int request_id, |
138 const std::string& request_method) OVERRIDE; | 134 const std::string& request_method) OVERRIDE; |
139 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; | 135 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; |
140 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; | 136 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; |
141 virtual void RendererResponsive(WebContents* source) OVERRIDE; | 137 virtual void RendererResponsive(WebContents* source) OVERRIDE; |
142 virtual void RunFileChooser(WebContents* web_contents, | 138 virtual void RunFileChooser(WebContents* web_contents, |
143 const FileChooserParams& params) OVERRIDE; | 139 const FileChooserParams& params) OVERRIDE; |
144 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | 140 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; |
145 | 141 |
146 void UpdateRect(RenderViewHost* render_view_host, | |
147 const ViewHostMsg_UpdateRect_Params& params); | |
148 void UpdateRectACK( | 142 void UpdateRectACK( |
149 int message_id, | |
150 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, | 143 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, |
151 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params); | 144 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params); |
152 // Overrides default ShowWidget message so we show them on the correct | |
153 // coordinates. | |
154 void ShowWidget(RenderViewHost* render_view_host, | |
155 int route_id, | |
156 const gfx::Rect& initial_pos); | |
157 // On MacOSX popups are painted by the browser process. We handle them here | |
158 // so that they are positioned correctly. | |
159 #if defined(OS_MACOSX) | |
160 void ShowPopup(RenderViewHost* render_view_host, | |
161 const ViewHostMsg_ShowPopup_Params& params); | |
162 #endif | |
163 void SetCursor(const WebCursor& cursor); | |
164 // Handles input event acks so they are sent to browser plugin host (via | |
165 // embedder) instead of default view/widget host. | |
166 void HandleInputEventAck(RenderViewHost* render_view_host, bool handled); | |
167 | |
168 // The guest needs to notify the plugin in the embedder to start (or stop) | |
169 // accepting touch events. | |
170 void SetIsAcceptingTouchEvents(bool accept); | |
171 | 145 |
172 // The guest WebContents is visible if both its embedder is visible and | 146 // The guest WebContents is visible if both its embedder is visible and |
173 // the browser plugin element is visible. If either one is not then the | 147 // the browser plugin element is visible. If either one is not then the |
174 // WebContents is marked as hidden. A hidden WebContents will consume | 148 // WebContents is marked as hidden. A hidden WebContents will consume |
175 // fewer GPU and CPU resources. | 149 // fewer GPU and CPU resources. |
176 // | 150 // |
177 // When the every WebContents in a RenderProcessHost is hidden, it will lower | 151 // When the every WebContents in a RenderProcessHost is hidden, it will lower |
178 // the priority of the process (see RenderProcessHostImpl::WidgetHidden). | 152 // the priority of the process (see RenderProcessHostImpl::WidgetHidden). |
179 // | 153 // |
180 // It will also send a message to the guest renderer process to cleanup | 154 // It will also send a message to the guest renderer process to cleanup |
(...skipping 13 matching lines...) Expand all Loading... |
194 void DragStatusUpdate(WebKit::WebDragStatus drag_status, | 168 void DragStatusUpdate(WebKit::WebDragStatus drag_status, |
195 const WebDropData& drop_data, | 169 const WebDropData& drop_data, |
196 WebKit::WebDragOperationsMask drag_mask, | 170 WebKit::WebDragOperationsMask drag_mask, |
197 const gfx::Point& location); | 171 const gfx::Point& location); |
198 | 172 |
199 // Updates the size state of the guest. | 173 // Updates the size state of the guest. |
200 void SetSize( | 174 void SetSize( |
201 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, | 175 const BrowserPluginHostMsg_AutoSize_Params& auto_size_params, |
202 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params); | 176 const BrowserPluginHostMsg_ResizeGuest_Params& resize_guest_params); |
203 | 177 |
204 // Updates the cursor during dragging. | |
205 // During dragging, if the guest notifies to update the cursor for a drag, | |
206 // then it is necessary to route the cursor update to the embedder correctly | |
207 // so that the cursor updates properly. | |
208 void UpdateDragCursor(WebKit::WebDragOperation operation); | |
209 | |
210 // Exposes the protected web_contents() from WebContentsObserver. | 178 // Exposes the protected web_contents() from WebContentsObserver. |
211 WebContents* GetWebContents(); | 179 WebContents* GetWebContents(); |
212 | 180 |
213 // Kill the guest process. | 181 // Kill the guest process. |
214 void Terminate(); | 182 void Terminate(); |
215 | 183 |
216 // Grab the new damage buffer from the embedder, and resize the guest's | 184 // Grab the new damage buffer from the embedder, and resize the guest's |
217 // web contents. | 185 // web contents. |
218 void Resize(RenderViewHost* embedder_rvh, | 186 void Resize(RenderViewHost* embedder_rvh, |
219 const BrowserPluginHostMsg_ResizeGuest_Params& params); | 187 const BrowserPluginHostMsg_ResizeGuest_Params& params); |
220 | 188 |
221 // Overridden in tests. | 189 // Overridden in tests. |
222 // Handles input event routed through the embedder (which is initiated in the | 190 // Handles input event routed through the embedder (which is initiated in the |
223 // browser plugin (renderer side of the embedder)). | 191 // browser plugin (renderer side of the embedder)). |
224 virtual void HandleInputEvent(RenderViewHost* render_view_host, | 192 virtual void HandleInputEvent(RenderViewHost* render_view_host, |
225 const gfx::Rect& guest_window_rect, | 193 const gfx::Rect& guest_window_rect, |
226 const gfx::Rect& guest_screen_rect, | 194 const gfx::Rect& guest_screen_rect, |
227 const WebKit::WebInputEvent& event); | 195 const WebKit::WebInputEvent& event); |
228 virtual bool ViewTakeFocus(bool reverse); | |
229 // If possible, navigate the guest to |relative_index| entries away from the | 196 // If possible, navigate the guest to |relative_index| entries away from the |
230 // current navigation entry. | 197 // current navigation entry. |
231 virtual void Go(int relative_index); | 198 virtual void Go(int relative_index); |
232 // Overridden in tests. | 199 // Overridden in tests. |
233 virtual void SetFocus(bool focused); | 200 virtual void SetFocus(bool focused); |
234 // Reload the guest. | 201 // Reload the guest. |
235 virtual void Reload(); | 202 virtual void Reload(); |
236 // Stop loading the guest. | 203 // Stop loading the guest. |
237 virtual void Stop(); | 204 virtual void Stop(); |
238 // Overridden in tests. | 205 // Overridden in tests. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 TransportDIB* GetDamageBufferFromEmbedder( | 239 TransportDIB* GetDamageBufferFromEmbedder( |
273 RenderViewHost* embedder_rvh, | 240 RenderViewHost* embedder_rvh, |
274 const BrowserPluginHostMsg_ResizeGuest_Params& params); | 241 const BrowserPluginHostMsg_ResizeGuest_Params& params); |
275 | 242 |
276 // Called when a redirect notification occurs. | 243 // Called when a redirect notification occurs. |
277 void LoadRedirect(const GURL& old_url, | 244 void LoadRedirect(const GURL& old_url, |
278 const GURL& new_url, | 245 const GURL& new_url, |
279 bool is_top_level); | 246 bool is_top_level); |
280 | 247 |
281 bool InAutoSizeBounds(const gfx::Size& size) const; | 248 bool InAutoSizeBounds(const gfx::Size& size) const; |
| 249 |
| 250 // Message handlers. |
| 251 |
| 252 void OnHandleInputEventAck( |
| 253 WebKit::WebInputEvent::Type event_type, |
| 254 InputEventAckState ack_result); |
| 255 void OnHasTouchEventHandlers(bool accept); |
| 256 void OnSetCursor(const WebCursor& cursor); |
| 257 // On MacOSX popups are painted by the browser process. We handle them here |
| 258 // so that they are positioned correctly. |
| 259 #if defined(OS_MACOSX) |
| 260 void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params); |
| 261 #endif |
| 262 void OnShowWidget(int route_id, const gfx::Rect& initial_pos); |
| 263 // Overriden in tests |
| 264 virtual void OnTakeFocus(bool reverse); |
| 265 void OnUpdateDragCursor(WebKit::WebDragOperation operation); |
| 266 void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params); |
| 267 |
282 // Static factory instance (always NULL for non-test). | 268 // Static factory instance (always NULL for non-test). |
283 static content::BrowserPluginHostFactory* factory_; | 269 static content::BrowserPluginHostFactory* factory_; |
284 | 270 |
285 NotificationRegistrar notification_registrar_; | 271 NotificationRegistrar notification_registrar_; |
286 WebContentsImpl* embedder_web_contents_; | 272 WebContentsImpl* embedder_web_contents_; |
287 // An identifier that uniquely identifies a browser plugin guest within an | 273 // An identifier that uniquely identifies a browser plugin guest within an |
288 // embedder. | 274 // embedder. |
289 int instance_id_; | 275 int instance_id_; |
290 scoped_ptr<TransportDIB> damage_buffer_; | 276 scoped_ptr<TransportDIB> damage_buffer_; |
291 #if defined(OS_WIN) | 277 #if defined(OS_WIN) |
292 size_t damage_buffer_size_; | 278 size_t damage_buffer_size_; |
293 TransportDIB::Handle remote_damage_buffer_handle_; | 279 TransportDIB::Handle remote_damage_buffer_handle_; |
294 #endif | 280 #endif |
295 gfx::Size damage_view_size_; | 281 gfx::Size damage_view_size_; |
296 float damage_buffer_scale_factor_; | 282 float damage_buffer_scale_factor_; |
297 gfx::Rect guest_window_rect_; | 283 gfx::Rect guest_window_rect_; |
298 gfx::Rect guest_screen_rect_; | 284 gfx::Rect guest_screen_rect_; |
299 IDMap<RenderViewHost> pending_updates_; | |
300 int pending_update_counter_; | |
301 base::TimeDelta guest_hang_timeout_; | 285 base::TimeDelta guest_hang_timeout_; |
302 bool focused_; | 286 bool focused_; |
303 bool visible_; | 287 bool visible_; |
304 bool auto_size_enabled_; | 288 bool auto_size_enabled_; |
305 gfx::Size max_auto_size_; | 289 gfx::Size max_auto_size_; |
306 gfx::Size min_auto_size_; | 290 gfx::Size min_auto_size_; |
307 | 291 |
308 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 292 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
309 }; | 293 }; |
310 | 294 |
311 } // namespace content | 295 } // namespace content |
312 | 296 |
313 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 297 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
OLD | NEW |