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