| 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 12 matching lines...) Expand all Loading... |
| 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; |
| 61 class RenderWidgetHostView; | 62 class RenderWidgetHostView; |
| 63 struct MediaStreamRequest; |
| 62 | 64 |
| 63 // A browser plugin guest provides functionality for WebContents to operate in | 65 // A browser plugin guest provides functionality for WebContents to operate in |
| 64 // the guest role and implements guest specific overrides for ViewHostMsg_* | 66 // the guest role and implements guest specific overrides for ViewHostMsg_* |
| 65 // messages. | 67 // messages. |
| 66 // | 68 // |
| 67 // BrowserPluginEmbedder is responsible for creating and destroying a guest. | 69 // BrowserPluginEmbedder is responsible for creating and destroying a guest. |
| 68 class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, | 70 class CONTENT_EXPORT BrowserPluginGuest : public NotificationObserver, |
| 69 public WebContentsDelegate, | 71 public WebContentsDelegate, |
| 70 public WebContentsObserver { | 72 public WebContentsObserver { |
| 71 public: | 73 public: |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 // WebContentsDelegate implementation. | 145 // WebContentsDelegate implementation. |
| 144 virtual bool CanDownload(RenderViewHost* render_view_host, | 146 virtual bool CanDownload(RenderViewHost* render_view_host, |
| 145 int request_id, | 147 int request_id, |
| 146 const std::string& request_method) OVERRIDE; | 148 const std::string& request_method) OVERRIDE; |
| 147 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; | 149 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; |
| 148 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; | 150 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; |
| 149 virtual void RendererResponsive(WebContents* source) OVERRIDE; | 151 virtual void RendererResponsive(WebContents* source) OVERRIDE; |
| 150 virtual void RunFileChooser(WebContents* web_contents, | 152 virtual void RunFileChooser(WebContents* web_contents, |
| 151 const FileChooserParams& params) OVERRIDE; | 153 const FileChooserParams& params) OVERRIDE; |
| 152 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; | 154 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; |
| 155 virtual void RequestMediaAccessPermission( |
| 156 WebContents* web_contents, |
| 157 const content::MediaStreamRequest& request, |
| 158 const content::MediaResponseCallback& callback) OVERRIDE; |
| 153 | 159 |
| 154 // Exposes the protected web_contents() from WebContentsObserver. | 160 // Exposes the protected web_contents() from WebContentsObserver. |
| 155 WebContents* GetWebContents(); | 161 WebContents* GetWebContents(); |
| 156 | 162 |
| 157 // Kill the guest process. | 163 // Kill the guest process. |
| 158 void Terminate(); | 164 void Terminate(); |
| 159 | 165 |
| 160 // Overridden in tests. | 166 // Overridden in tests. |
| 161 virtual void SetDamageBuffer( | 167 virtual void SetDamageBuffer( |
| 162 const BrowserPluginHostMsg_ResizeGuest_Params& params); | 168 const BrowserPluginHostMsg_ResizeGuest_Params& params); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 174 int instance_id() const { return instance_id_; } | 180 int instance_id() const { return instance_id_; } |
| 175 | 181 |
| 176 // Allow the embedder to call this for unhandled messages when | 182 // Allow the embedder to call this for unhandled messages when |
| 177 // BrowserPluginGuest is already destroyed. | 183 // BrowserPluginGuest is already destroyed. |
| 178 static void AcknowledgeBufferPresent(int route_id, | 184 static void AcknowledgeBufferPresent(int route_id, |
| 179 int gpu_host_id, | 185 int gpu_host_id, |
| 180 const std::string& mailbox_name, | 186 const std::string& mailbox_name, |
| 181 uint32 sync_point); | 187 uint32 sync_point); |
| 182 | 188 |
| 183 private: | 189 private: |
| 190 typedef std::pair<content::MediaStreamRequest, content::MediaResponseCallback> |
| 191 MediaStreamRequestAndCallbackPair; |
| 192 typedef std::map<int, MediaStreamRequestAndCallbackPair> |
| 193 MediaStreamRequestsMap; |
| 194 |
| 184 friend class TestBrowserPluginGuest; | 195 friend class TestBrowserPluginGuest; |
| 185 | 196 |
| 186 BrowserPluginGuest(int instance_id, | 197 BrowserPluginGuest(int instance_id, |
| 187 WebContentsImpl* embedder_web_contents, | 198 WebContentsImpl* embedder_web_contents, |
| 188 WebContentsImpl* web_contents, | 199 WebContentsImpl* web_contents, |
| 189 const BrowserPluginHostMsg_CreateGuest_Params& params); | 200 const BrowserPluginHostMsg_CreateGuest_Params& params); |
| 190 | 201 |
| 191 // Returns the embedder's routing ID. | 202 // Returns the embedder's routing ID. |
| 192 int embedder_routing_id() const; | 203 int embedder_routing_id() const; |
| 193 | 204 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 206 | 217 |
| 207 // Called when a redirect notification occurs. | 218 // Called when a redirect notification occurs. |
| 208 void LoadRedirect(const GURL& old_url, | 219 void LoadRedirect(const GURL& old_url, |
| 209 const GURL& new_url, | 220 const GURL& new_url, |
| 210 bool is_top_level); | 221 bool is_top_level); |
| 211 | 222 |
| 212 bool InAutoSizeBounds(const gfx::Size& size) const; | 223 bool InAutoSizeBounds(const gfx::Size& size) const; |
| 213 | 224 |
| 214 // Message handlers for messsages from embedder. | 225 // Message handlers for messsages from embedder. |
| 215 | 226 |
| 227 // Allows or denies a permission request access, after the embedder has had a |
| 228 // chance to decide. |
| 229 void OnRespondPermission(int instance_id, |
| 230 BrowserPluginPermissionType permission_type, |
| 231 int request_id, |
| 232 bool should_allow); |
| 216 // Handles drag events from the embedder. | 233 // Handles drag events from the embedder. |
| 217 // When dragging, the drag events go to the embedder first, and if the drag | 234 // When dragging, the drag events go to the embedder first, and if the drag |
| 218 // happens on the browser plugin, then the plugin sends a corresponding | 235 // happens on the browser plugin, then the plugin sends a corresponding |
| 219 // drag-message to the guest. This routes the drag-message to the guest | 236 // drag-message to the guest. This routes the drag-message to the guest |
| 220 // renderer. | 237 // renderer. |
| 221 void OnDragStatusUpdate(int instance_id, | 238 void OnDragStatusUpdate(int instance_id, |
| 222 WebKit::WebDragStatus drag_status, | 239 WebKit::WebDragStatus drag_status, |
| 223 const WebDropData& drop_data, | 240 const WebDropData& drop_data, |
| 224 WebKit::WebDragOperationsMask drag_mask, | 241 WebKit::WebDragOperationsMask drag_mask, |
| 225 const gfx::Point& location); | 242 const gfx::Point& location); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 base::TimeDelta guest_hang_timeout_; | 341 base::TimeDelta guest_hang_timeout_; |
| 325 bool focused_; | 342 bool focused_; |
| 326 bool guest_visible_; | 343 bool guest_visible_; |
| 327 bool embedder_visible_; | 344 bool embedder_visible_; |
| 328 std::string name_; | 345 std::string name_; |
| 329 bool auto_size_enabled_; | 346 bool auto_size_enabled_; |
| 330 gfx::Size max_auto_size_; | 347 gfx::Size max_auto_size_; |
| 331 gfx::Size min_auto_size_; | 348 gfx::Size min_auto_size_; |
| 332 bool destroy_called_; | 349 bool destroy_called_; |
| 333 | 350 |
| 351 // A counter to generate unique request id for a media access request. |
| 352 // We only need the ids to be unique for a given BrowserPluginGuest. |
| 353 int current_media_access_request_id_; |
| 354 // A map to store WebContents's media request object and callback. |
| 355 // We need to store these because we need a roundtrip to the embedder to know |
| 356 // if we allow or disallow the request. The key of the map is unique only for |
| 357 // a given BrowserPluginGuest. |
| 358 MediaStreamRequestsMap media_requests_map_; |
| 359 |
| 334 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 360 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
| 335 }; | 361 }; |
| 336 | 362 |
| 337 } // namespace content | 363 } // namespace content |
| 338 | 364 |
| 339 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 365 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
| OLD | NEW |