OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // A BrowserPluginEmbedder has a list of guests it manages. |
| 6 // In the beginning when a renderer sees one or more guests (BrowserPlugin |
| 7 // instance(s)) and there is a request to navigate to them, the WebContents for |
| 8 // that renderer creates a BrowserPluginEmbedder for itself. The |
| 9 // BrowserPluginEmbedder, in turn, manages a set of BrowserPluginGuests -- one |
| 10 // BrowserPluginGuest for each guest in the embedding WebContents. Note that |
| 11 // each of these BrowserPluginGuest objects has its own WebContents. |
| 12 // BrowserPluginEmbedder routes any messages directed to a guest from the |
| 13 // renderer (BrowserPlugin) to the appropriate guest (identified by the guest's |
| 14 // |instance_id|). |
| 15 // |
| 16 // BrowserPluginEmbedder is responsible for cleaning up the guests when the |
| 17 // embedder frame navigates away to a different page or deletes the guests from |
| 18 // the existing page. |
| 19 |
| 20 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ |
| 21 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ |
| 22 |
| 23 #include <map> |
| 24 |
| 25 #include "base/compiler_specific.h" |
| 26 #include "content/public/browser/notification_observer.h" |
| 27 #include "content/public/browser/notification_registrar.h" |
| 28 #include "content/public/browser/web_contents_observer.h" |
| 29 |
| 30 class TransportDIB; |
| 31 class WebContentsImpl; |
| 32 |
| 33 namespace WebKit { |
| 34 class WebInputEvent; |
| 35 } |
| 36 |
| 37 namespace gfx { |
| 38 class Rect; |
| 39 class Size; |
| 40 } |
| 41 |
| 42 namespace content { |
| 43 |
| 44 class BrowserPluginGuest; |
| 45 class BrowserPluginHostFactory; |
| 46 |
| 47 // A browser plugin embedder provides functionality for WebContents to operate |
| 48 // in the 'embedder' role. It manages list of guests inside the embedder. |
| 49 // |
| 50 // The embedder's WebContents manages the lifetime of the embedder. They are |
| 51 // created when a renderer asks WebContents to navigate (for the first time) to |
| 52 // some guest. It gets destroyed when either the WebContents goes away or there |
| 53 // is a RenderViewHost swap in WebContents. |
| 54 class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver, |
| 55 public NotificationObserver { |
| 56 public: |
| 57 typedef std::map<int, WebContents*> ContainerInstanceMap; |
| 58 |
| 59 virtual ~BrowserPluginEmbedder(); |
| 60 |
| 61 static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents, |
| 62 RenderViewHost* render_view_host); |
| 63 |
| 64 // Navigates in a guest (new or existing). |
| 65 void NavigateGuest(RenderViewHost* render_view_host, |
| 66 int instance_id, |
| 67 int64 frame_id, |
| 68 const std::string& src, |
| 69 const gfx::Size& size); |
| 70 |
| 71 // WebContentsObserver implementation. |
| 72 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; |
| 73 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; |
| 74 |
| 75 // NotificationObserver method override. |
| 76 virtual void Observe(int type, |
| 77 const NotificationSource& source, |
| 78 const NotificationDetails& details) OVERRIDE; |
| 79 |
| 80 // Overrides factory for testing. Default (NULL) value indicates regular |
| 81 // (non-test) environment. |
| 82 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { |
| 83 factory_ = factory; |
| 84 } |
| 85 |
| 86 private: |
| 87 friend class BrowserPluginEmbedderHelper; |
| 88 friend class TestBrowserPluginEmbedder; |
| 89 |
| 90 BrowserPluginEmbedder(WebContentsImpl* web_contents, |
| 91 RenderViewHost* render_view_host); |
| 92 |
| 93 // Returns a guest browser plugin delegate by its container ID specified |
| 94 // in BrowserPlugin. |
| 95 BrowserPluginGuest* GetGuestByInstanceID(int instance_id) const; |
| 96 // Adds a new guest web_contents to the embedder (overridable in test). |
| 97 virtual void AddGuest(int instance_id, |
| 98 WebContents* guest_web_contents, |
| 99 int64 frame_id); |
| 100 void DestroyGuestByInstanceID(int instance_id); |
| 101 void DestroyGuests(); |
| 102 |
| 103 // Message handlers (direct/indirect via BrowserPluginEmbedderHelper). |
| 104 // Routes update rect ack message to the appropriate guest. |
| 105 void UpdateRectACK(int instance_id, int message_id, const gfx::Size& size); |
| 106 void SetFocus(int instance_id, bool focused); |
| 107 void ResizeGuest(int instance_id, |
| 108 TransportDIB* damage_buffer, |
| 109 #if defined(OS_WIN) |
| 110 int damage_buffer_size, |
| 111 #endif |
| 112 int width, |
| 113 int height, |
| 114 bool resize_pending, |
| 115 float scale_factor); |
| 116 // Handles input events sent from the BrowserPlugin (embedder's renderer |
| 117 // process) by passing them to appropriate guest's input handler. |
| 118 void HandleInputEvent(int instance_id, |
| 119 RenderViewHost* render_view_host, |
| 120 const gfx::Rect& guest_rect, |
| 121 const WebKit::WebInputEvent& event, |
| 122 IPC::Message* reply_message); |
| 123 void PluginDestroyed(int instance_id); |
| 124 |
| 125 // Called when visiblity of web_contents changes, so the embedder will |
| 126 // show/hide its guest. |
| 127 void WebContentsVisibilityChanged(bool visible); |
| 128 |
| 129 // Static factory instance (always NULL for non-test). |
| 130 static BrowserPluginHostFactory* factory_; |
| 131 |
| 132 // A scoped container for notification registries. |
| 133 NotificationRegistrar registrar_; |
| 134 |
| 135 // Contains guests' WebContents, mapping from their instance ids. |
| 136 ContainerInstanceMap guest_web_contents_by_instance_id_; |
| 137 RenderViewHost* render_view_host_; |
| 138 |
| 139 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder); |
| 140 }; |
| 141 |
| 142 } // namespace content |
| 143 |
| 144 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ |
OLD | NEW |