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