| 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 is the browser side of a browser <--> embedder | 5 // A BrowserPluginGuest is the browser side of a browser <--> embedder |
| 6 // renderer channel. A BrowserPlugin (a WebPlugin) is on the embedder | 6 // renderer channel. A BrowserPlugin (a WebPlugin) is on the embedder |
| 7 // renderer side of browser <--> embedder renderer communication. | 7 // renderer side of browser <--> embedder renderer communication. |
| 8 // | 8 // |
| 9 // 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 |
| 10 // helper, BrowserPluginGuestHelper, which is a RenderViewHostObserver. The | 10 // helper, BrowserPluginGuestHelper, which is a RenderViewHostObserver. The |
| 11 // helper object intercepts messages (ViewHostMsg_*) directed at the browser | 11 // helper object intercepts messages (ViewHostMsg_*) directed at the browser |
| 12 // process and redirects them to this class. Any messages about the guest render | 12 // process and redirects them to this class. Any messages about the guest render |
| 13 // process that the embedder might be interested in receiving should be listened | 13 // process that the embedder might be interested in receiving should be listened |
| 14 // for here. | 14 // for here. |
| 15 // | 15 // |
| 16 // BrowserPluginGuest is a WebContentsDelegate and WebContentsObserver for the | 16 // BrowserPluginGuest is a WebContentsDelegate and WebContentsObserver for the |
| 17 // guest WebContents. BrowserPluginGuest operates under the assumption that the | 17 // guest WebContents. BrowserPluginGuest operates under the assumption that the |
| 18 // guest will be accessible through only one RenderViewHost for the lifetime of | 18 // guest will be accessible through only one RenderViewHost for the lifetime of |
| 19 // the guest WebContents. Thus, cross-process navigation is not supported. | 19 // the guest WebContents. Thus, cross-process navigation is not supported. |
| 20 | 20 |
| 21 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 21 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| 22 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 22 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| 23 | 23 |
| 24 #include <map> | 24 #include <map> |
| 25 | 25 |
| 26 #include "base/compiler_specific.h" | 26 #include "base/compiler_specific.h" |
| 27 #include "base/id_map.h" | 27 #include "base/id_map.h" |
| 28 #include "base/shared_memory.h" | 28 #include "base/shared_memory.h" |
| 29 #include "base/time.h" | 29 #include "base/time.h" |
| 30 #include "content/common/browser_plugin_message_enums.h" |
| 30 #include "content/port/common/input_event_ack_state.h" | 31 #include "content/port/common/input_event_ack_state.h" |
| 31 #include "content/public/browser/notification_observer.h" | 32 #include "content/public/browser/notification_observer.h" |
| 32 #include "content/public/browser/notification_registrar.h" | 33 #include "content/public/browser/notification_registrar.h" |
| 33 #include "content/public/browser/web_contents_delegate.h" | 34 #include "content/public/browser/web_contents_delegate.h" |
| 34 #include "content/public/browser/web_contents_observer.h" | 35 #include "content/public/browser/web_contents_observer.h" |
| 35 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" | 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragOperation.h" |
| 36 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" | 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDragStatus.h" |
| 37 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 38 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 38 #include "ui/gfx/rect.h" | 39 #include "ui/gfx/rect.h" |
| 39 #include "ui/surface/transport_dib.h" | 40 #include "ui/surface/transport_dib.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 51 | 52 |
| 52 namespace WebKit { | 53 namespace WebKit { |
| 53 class WebInputEvent; | 54 class WebInputEvent; |
| 54 } | 55 } |
| 55 | 56 |
| 56 namespace content { | 57 namespace content { |
| 57 | 58 |
| 58 class BrowserPluginHostFactory; | 59 class BrowserPluginHostFactory; |
| 59 class BrowserPluginEmbedder; | 60 class BrowserPluginEmbedder; |
| 60 class RenderProcessHost; | 61 class RenderProcessHost; |
| 62 struct MediaStreamRequest; |
| 61 | 63 |
| 62 // A browser plugin guest provides functionality for WebContents to operate in | 64 // A browser plugin guest provides functionality for WebContents to operate in |
| 63 // the guest role and implements guest specific overrides for ViewHostMsg_* | 65 // the guest role and implements guest specific overrides for ViewHostMsg_* |
| 64 // messages. | 66 // messages. |
| 65 // | 67 // |
| 66 // BrowserPluginEmbedder is responsible for creating and destroying a guest. | 68 // BrowserPluginEmbedder is responsible for creating and destroying a guest. |
| 67 class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, | 69 class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, |
| 68 public WebContentsDelegate, | 70 public WebContentsDelegate, |
| 69 public WebContentsObserver { | 71 public WebContentsObserver { |
| 70 public: | 72 public: |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // WebContentsDelegate implementation. | 142 // WebContentsDelegate implementation. |
| 141 virtual bool CanDownload(RenderViewHost* render_view_host, | 143 virtual bool CanDownload(RenderViewHost* render_view_host, |
| 142 int request_id, | 144 int request_id, |
| 143 const std::string& request_method) OVERRIDE; | 145 const std::string& request_method) OVERRIDE; |
| 144 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; | 146 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; |
| 145 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; | 147 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; |
| 146 virtual void RendererResponsive(WebContents* source) OVERRIDE; | 148 virtual void RendererResponsive(WebContents* source) OVERRIDE; |
| 147 virtual void RunFileChooser(WebContents* web_contents, | 149 virtual void RunFileChooser(WebContents* web_contents, |
| 148 const FileChooserParams& params) OVERRIDE; | 150 const FileChooserParams& params) OVERRIDE; |
| 149 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | 151 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; |
| 152 virtual void RequestMediaAccessPermission( |
| 153 WebContents* web_contents, |
| 154 const content::MediaStreamRequest& request, |
| 155 const content::MediaResponseCallback& callback) OVERRIDE; |
| 150 | 156 |
| 151 // Exposes the protected web_contents() from WebContentsObserver. | 157 // Exposes the protected web_contents() from WebContentsObserver. |
| 152 WebContents* GetWebContents(); | 158 WebContents* GetWebContents(); |
| 153 | 159 |
| 154 // Kill the guest process. | 160 // Kill the guest process. |
| 155 void Terminate(); | 161 void Terminate(); |
| 156 | 162 |
| 157 // Overridden in tests. | 163 // Overridden in tests. |
| 158 virtual void SetDamageBuffer( | 164 virtual void SetDamageBuffer( |
| 159 const BrowserPluginHostMsg_ResizeGuest_Params& params); | 165 const BrowserPluginHostMsg_ResizeGuest_Params& params); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 171 int instance_id() const { return instance_id_; } | 177 int instance_id() const { return instance_id_; } |
| 172 | 178 |
| 173 // Allow the embedder to call this for unhandled messages when | 179 // Allow the embedder to call this for unhandled messages when |
| 174 // BrowserPluginGuest is already destroyed. | 180 // BrowserPluginGuest is already destroyed. |
| 175 static void AcknowledgeBufferPresent(int route_id, | 181 static void AcknowledgeBufferPresent(int route_id, |
| 176 int gpu_host_id, | 182 int gpu_host_id, |
| 177 const std::string& mailbox_name, | 183 const std::string& mailbox_name, |
| 178 uint32 sync_point); | 184 uint32 sync_point); |
| 179 | 185 |
| 180 private: | 186 private: |
| 187 typedef std::pair<content::MediaStreamRequest, content::MediaResponseCallback> |
| 188 MediaStreamRequestAndCallbackPair; |
| 189 typedef std::map<int, MediaStreamRequestAndCallbackPair> |
| 190 MediaStreamRequestsMap; |
| 191 |
| 181 friend class TestBrowserPluginGuest; | 192 friend class TestBrowserPluginGuest; |
| 182 | 193 |
| 183 BrowserPluginGuest(int instance_id, | 194 BrowserPluginGuest(int instance_id, |
| 184 WebContentsImpl* embedder_web_contents, | 195 WebContentsImpl* embedder_web_contents, |
| 185 WebContentsImpl* web_contents, | 196 WebContentsImpl* web_contents, |
| 186 const BrowserPluginHostMsg_CreateGuest_Params& params); | 197 const BrowserPluginHostMsg_CreateGuest_Params& params); |
| 187 | 198 |
| 188 // Schedules this BrowserPluginGuest for deletion if it hasn't already been | 199 // Schedules this BrowserPluginGuest for deletion if it hasn't already been |
| 189 // scheduled. | 200 // scheduled. |
| 190 void Destroy(); | 201 void Destroy(); |
| 191 | 202 |
| 192 base::SharedMemory* damage_buffer() const { return damage_buffer_.get(); } | 203 base::SharedMemory* damage_buffer() const { return damage_buffer_.get(); } |
| 193 const gfx::Size& damage_view_size() const { return damage_view_size_; } | 204 const gfx::Size& damage_view_size() const { return damage_view_size_; } |
| 194 float damage_buffer_scale_factor() const { | 205 float damage_buffer_scale_factor() const { |
| 195 return damage_buffer_scale_factor_; | 206 return damage_buffer_scale_factor_; |
| 196 } | 207 } |
| 197 // Returns the damage buffer corresponding to the handle in resize |params|. | 208 // Returns the damage buffer corresponding to the handle in resize |params|. |
| 198 base::SharedMemory* GetDamageBufferFromEmbedder( | 209 base::SharedMemory* GetDamageBufferFromEmbedder( |
| 199 const BrowserPluginHostMsg_ResizeGuest_Params& params); | 210 const BrowserPluginHostMsg_ResizeGuest_Params& params); |
| 200 | 211 |
| 201 // Called when a redirect notification occurs. | 212 // Called when a redirect notification occurs. |
| 202 void LoadRedirect(const GURL& old_url, | 213 void LoadRedirect(const GURL& old_url, |
| 203 const GURL& new_url, | 214 const GURL& new_url, |
| 204 bool is_top_level); | 215 bool is_top_level); |
| 205 | 216 |
| 206 bool InAutoSizeBounds(const gfx::Size& size) const; | 217 bool InAutoSizeBounds(const gfx::Size& size) const; |
| 207 | 218 |
| 208 // Message handlers for messsages from embedder. | 219 // Message handlers for messsages from embedder. |
| 209 | 220 |
| 221 // Allows or denies a permission request access, after the embedder has had a |
| 222 // chance to decide. |
| 223 void OnRespondPermission(int instance_id, |
| 224 BrowserPluginPermissionType permission_type, |
| 225 int request_id, |
| 226 bool should_allow); |
| 210 // Handles drag events from the embedder. | 227 // Handles drag events from the embedder. |
| 211 // When dragging, the drag events go to the embedder first, and if the drag | 228 // When dragging, the drag events go to the embedder first, and if the drag |
| 212 // happens on the browser plugin, then the plugin sends a corresponding | 229 // happens on the browser plugin, then the plugin sends a corresponding |
| 213 // drag-message to the guest. This routes the drag-message to the guest | 230 // drag-message to the guest. This routes the drag-message to the guest |
| 214 // renderer. | 231 // renderer. |
| 215 void OnDragStatusUpdate(int instance_id, | 232 void OnDragStatusUpdate(int instance_id, |
| 216 WebKit::WebDragStatus drag_status, | 233 WebKit::WebDragStatus drag_status, |
| 217 const WebDropData& drop_data, | 234 const WebDropData& drop_data, |
| 218 WebKit::WebDragOperationsMask drag_mask, | 235 WebKit::WebDragOperationsMask drag_mask, |
| 219 const gfx::Point& location); | 236 const gfx::Point& location); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 base::TimeDelta guest_hang_timeout_; | 335 base::TimeDelta guest_hang_timeout_; |
| 319 bool focused_; | 336 bool focused_; |
| 320 bool guest_visible_; | 337 bool guest_visible_; |
| 321 bool embedder_visible_; | 338 bool embedder_visible_; |
| 322 std::string name_; | 339 std::string name_; |
| 323 bool auto_size_enabled_; | 340 bool auto_size_enabled_; |
| 324 gfx::Size max_auto_size_; | 341 gfx::Size max_auto_size_; |
| 325 gfx::Size min_auto_size_; | 342 gfx::Size min_auto_size_; |
| 326 bool destroy_called_; | 343 bool destroy_called_; |
| 327 | 344 |
| 345 // A counter to generate unique request id for a media access request. |
| 346 // We only need the ids to be unique for a given BrowserPluginGuest. |
| 347 int current_media_access_request_id_; |
| 348 // A map to store WebContents's media request object and callback. |
| 349 // We need to store these because we need a roundtrip to the embedder to know |
| 350 // if we allow or disallow the request. The key of the map is unique only for |
| 351 // a given BrowserPluginGuest. |
| 352 MediaStreamRequestsMap media_requests_map_; |
| 353 |
| 328 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 354 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
| 329 }; | 355 }; |
| 330 | 356 |
| 331 } // namespace content | 357 } // namespace content |
| 332 | 358 |
| 333 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 359 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| OLD | NEW |