| 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 represents the browser side of browser <--> renderer |
| 6 // communication. A BrowserPlugin (a WebPlugin) is on the renderer side of | 6 // communication. A BrowserPlugin (a WebPlugin) is on the renderer side of |
| 7 // browser <--> guest renderer communication. The 'guest' renderer is a | 7 // browser <--> guest renderer communication. The 'guest' renderer is a |
| 8 // <browser> tag. | 8 // <browser> tag. |
| 9 // | 9 // |
| 10 // BrowserPluginGuest lives on the UI thread of the browser process. It has a | 10 // BrowserPluginGuest lives on the UI thread of the browser process. It has a |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 #include <map> | 32 #include <map> |
| 33 | 33 |
| 34 #include "base/compiler_specific.h" | 34 #include "base/compiler_specific.h" |
| 35 #include "base/id_map.h" | 35 #include "base/id_map.h" |
| 36 #include "base/time.h" | 36 #include "base/time.h" |
| 37 #include "content/public/browser/notification_observer.h" | 37 #include "content/public/browser/notification_observer.h" |
| 38 #include "content/public/browser/notification_registrar.h" | 38 #include "content/public/browser/notification_registrar.h" |
| 39 #include "content/public/browser/web_contents_delegate.h" | 39 #include "content/public/browser/web_contents_delegate.h" |
| 40 #include "content/public/browser/web_contents_observer.h" | 40 #include "content/public/browser/web_contents_observer.h" |
| 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" |
| 41 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" | 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" |
| 42 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" | |
| 43 #include "ui/gfx/rect.h" | 43 #include "ui/gfx/rect.h" |
| 44 | 44 |
| 45 struct BrowserPluginHostMsg_AutoSize_Params; | 45 struct BrowserPluginHostMsg_AutoSize_Params; |
| 46 struct BrowserPluginHostMsg_CreateGuest_Params; | 46 struct BrowserPluginHostMsg_CreateGuest_Params; |
| 47 struct BrowserPluginHostMsg_ResizeGuest_Params; | 47 struct BrowserPluginHostMsg_ResizeGuest_Params; |
| 48 class TransportDIB; | 48 class TransportDIB; |
| 49 struct ViewHostMsg_UpdateRect_Params; | 49 struct ViewHostMsg_UpdateRect_Params; |
| 50 class WebCursor; | 50 class WebCursor; |
| 51 struct WebDropData; | 51 struct WebDropData; |
| 52 | 52 |
| 53 namespace WebKit { | 53 namespace WebKit { |
| 54 class WebInputEvent; | 54 class WebInputEvent; |
| 55 } | 55 } |
| 56 | 56 |
| 57 namespace content { | 57 namespace content { |
| 58 | 58 |
| 59 class BrowserPluginHostFactory; | 59 class BrowserPluginHostFactory; |
| 60 class BrowserPluginEmbedder; | 60 class BrowserPluginEmbedder; |
| 61 class RenderProcessHost; | 61 class RenderProcessHost; |
| 62 struct MediaStreamRequest; |
| 62 | 63 |
| 63 // A browser plugin guest provides functionality for WebContents to operate in | 64 // A browser plugin guest provides functionality for WebContents to operate in |
| 64 // the guest role and implements guest specific overrides for ViewHostMsg_* | 65 // the guest role and implements guest specific overrides for ViewHostMsg_* |
| 65 // messages. | 66 // messages. |
| 66 // | 67 // |
| 67 // BrowserPluginEmbedder is responsible for creating and destroying a guest. | 68 // BrowserPluginEmbedder is responsible for creating and destroying a guest. |
| 68 class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, | 69 class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, |
| 69 public WebContentsDelegate, | 70 public WebContentsDelegate, |
| 70 public WebContentsObserver { | 71 public WebContentsObserver { |
| 71 public: | 72 public: |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 | 128 |
| 128 // WebContentsDelegate implementation. | 129 // WebContentsDelegate implementation. |
| 129 virtual bool CanDownload(RenderViewHost* render_view_host, | 130 virtual bool CanDownload(RenderViewHost* render_view_host, |
| 130 int request_id, | 131 int request_id, |
| 131 const std::string& request_method) OVERRIDE; | 132 const std::string& request_method) OVERRIDE; |
| 132 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; | 133 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; |
| 133 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; | 134 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; |
| 134 virtual void RunFileChooser(WebContents* web_contents, | 135 virtual void RunFileChooser(WebContents* web_contents, |
| 135 const FileChooserParams& params) OVERRIDE; | 136 const FileChooserParams& params) OVERRIDE; |
| 136 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | 137 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; |
| 138 virtual void RequestMediaAccessPermission( |
| 139 WebContents* web_contents, |
| 140 const content::MediaStreamRequest* request, |
| 141 const content::MediaResponseCallback& callback) OVERRIDE; |
| 137 | 142 |
| 138 void UpdateRect(RenderViewHost* render_view_host, | 143 void UpdateRect(RenderViewHost* render_view_host, |
| 139 const ViewHostMsg_UpdateRect_Params& params); | 144 const ViewHostMsg_UpdateRect_Params& params); |
| 140 void UpdateRectACK(int message_id, const gfx::Size& size); | 145 void UpdateRectACK(int message_id, const gfx::Size& size); |
| 141 // Overrides default ShowWidget message so we show them on the correct | 146 // Overrides default ShowWidget message so we show them on the correct |
| 142 // coordinates. | 147 // coordinates. |
| 143 void ShowWidget(RenderViewHost* render_view_host, | 148 void ShowWidget(RenderViewHost* render_view_host, |
| 144 int route_id, | 149 int route_id, |
| 145 const gfx::Rect& initial_pos); | 150 const gfx::Rect& initial_pos); |
| 146 void SetCursor(const WebCursor& cursor); | 151 void SetCursor(const WebCursor& cursor); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // Exposes the protected web_contents() from WebContentsObserver. | 198 // Exposes the protected web_contents() from WebContentsObserver. |
| 194 WebContents* GetWebContents(); | 199 WebContents* GetWebContents(); |
| 195 | 200 |
| 196 // Kill the guest process. | 201 // Kill the guest process. |
| 197 void Terminate(); | 202 void Terminate(); |
| 198 | 203 |
| 199 // Grab the new damage buffer from the embedder, and resize the guest's | 204 // Grab the new damage buffer from the embedder, and resize the guest's |
| 200 // web contents. | 205 // web contents. |
| 201 void Resize(RenderViewHost* embedder_rvh, | 206 void Resize(RenderViewHost* embedder_rvh, |
| 202 const BrowserPluginHostMsg_ResizeGuest_Params& params); | 207 const BrowserPluginHostMsg_ResizeGuest_Params& params); |
| 208 // Allows or denies a media access request, after the embedder has had a |
| 209 // chance to decide. |
| 210 void AllowMediaAccess(WebContents* embedder_web_contents, |
| 211 int request_id, |
| 212 bool should_allow); |
| 203 | 213 |
| 204 // Overridden in tests. | 214 // Overridden in tests. |
| 205 // Handles input event routed through the embedder (which is initiated in the | 215 // Handles input event routed through the embedder (which is initiated in the |
| 206 // browser plugin (renderer side of the embedder)). | 216 // browser plugin (renderer side of the embedder)). |
| 207 virtual void HandleInputEvent(RenderViewHost* render_view_host, | 217 virtual void HandleInputEvent(RenderViewHost* render_view_host, |
| 208 const gfx::Rect& guest_rect, | 218 const gfx::Rect& guest_rect, |
| 209 const WebKit::WebInputEvent& event, | 219 const WebKit::WebInputEvent& event, |
| 210 IPC::Message* reply_message); | 220 IPC::Message* reply_message); |
| 211 virtual bool ViewTakeFocus(bool reverse); | 221 virtual bool ViewTakeFocus(bool reverse); |
| 212 // If possible, navigate the guest to |relative_index| entries away from the | 222 // If possible, navigate the guest to |relative_index| entries away from the |
| 213 // current navigation entry. | 223 // current navigation entry. |
| 214 virtual void Go(int relative_index); | 224 virtual void Go(int relative_index); |
| 215 // Overridden in tests. | 225 // Overridden in tests. |
| 216 virtual void SetFocus(bool focused); | 226 virtual void SetFocus(bool focused); |
| 217 // Reload the guest. | 227 // Reload the guest. |
| 218 virtual void Reload(); | 228 virtual void Reload(); |
| 219 // Stop loading the guest. | 229 // Stop loading the guest. |
| 220 virtual void Stop(); | 230 virtual void Stop(); |
| 221 // Overridden in tests. | 231 // Overridden in tests. |
| 222 virtual void SetDamageBuffer(TransportDIB* damage_buffer, | 232 virtual void SetDamageBuffer(TransportDIB* damage_buffer, |
| 223 #if defined(OS_WIN) | 233 #if defined(OS_WIN) |
| 224 int damage_buffer_size, | 234 int damage_buffer_size, |
| 225 #endif | 235 #endif |
| 226 const gfx::Size& damage_view_size, | 236 const gfx::Size& damage_view_size, |
| 227 float scale_factor); | 237 float scale_factor); |
| 228 | 238 |
| 229 private: | 239 private: |
| 240 typedef std::pair<content::MediaStreamRequest, content::MediaResponseCallback> |
| 241 MediaStreamRequestAndCallbackPair; |
| 242 typedef std::map<int, MediaStreamRequestAndCallbackPair> |
| 243 MediaStreamRequestsMap; |
| 244 |
| 230 friend class TestBrowserPluginGuest; | 245 friend class TestBrowserPluginGuest; |
| 231 | 246 |
| 232 BrowserPluginGuest(int instance_id, | 247 BrowserPluginGuest(int instance_id, |
| 233 WebContentsImpl* web_contents, | 248 WebContentsImpl* web_contents, |
| 234 RenderViewHost* render_view_host, | 249 RenderViewHost* render_view_host, |
| 235 const BrowserPluginHostMsg_CreateGuest_Params& params); | 250 const BrowserPluginHostMsg_CreateGuest_Params& params); |
| 236 | 251 |
| 237 // Returns the identifier that uniquely identifies a browser plugin guest | 252 // Returns the identifier that uniquely identifies a browser plugin guest |
| 238 // within an embedder. | 253 // within an embedder. |
| 239 int instance_id() const { return instance_id_; } | 254 int instance_id() const { return instance_id_; } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 scoped_ptr<IPC::Message> pending_input_event_reply_; | 289 scoped_ptr<IPC::Message> pending_input_event_reply_; |
| 275 gfx::Rect guest_rect_; | 290 gfx::Rect guest_rect_; |
| 276 IDMap<RenderViewHost> pending_updates_; | 291 IDMap<RenderViewHost> pending_updates_; |
| 277 int pending_update_counter_; | 292 int pending_update_counter_; |
| 278 base::TimeDelta guest_hang_timeout_; | 293 base::TimeDelta guest_hang_timeout_; |
| 279 bool focused_; | 294 bool focused_; |
| 280 bool visible_; | 295 bool visible_; |
| 281 bool auto_size_; | 296 bool auto_size_; |
| 282 gfx::Size max_auto_size_; | 297 gfx::Size max_auto_size_; |
| 283 gfx::Size min_auto_size_; | 298 gfx::Size min_auto_size_; |
| 299 // A counter to generate unique request id for a media access request. |
| 300 // We only need the ids to be unique for a given BrowserPluginGuest. |
| 301 int current_media_access_request_id_; |
| 302 // A map to store WebContents's media request object and callback. |
| 303 // We need to store these because we need a roundtrip to the embedder to know |
| 304 // if we allow or disallow the request. The key of the map is unique only for |
| 305 // a given BrowserPluginGuest. |
| 306 MediaStreamRequestsMap media_requests_map_; |
| 284 | 307 |
| 285 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 308 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
| 286 }; | 309 }; |
| 287 | 310 |
| 288 } // namespace content | 311 } // namespace content |
| 289 | 312 |
| 290 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 313 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| OLD | NEW |