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. | |
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. | |
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. | |
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 typedef std::map<WebContents*, int64> GuestWebContentsMap; | |
awong
2012/09/09 18:08:09
Move these typedefs into the private section of Br
lazyboy
2012/09/10 16:30:17
Done.
lazyboy
2012/09/10 18:02:47
Had to move one back since the browsertest needs i
awong
2012/09/10 19:21:07
Can we at put them in the public section of Browse
lazyboy
2012/09/10 23:40:57
Moved to public section.
*TEST_F method doesn't ru
| |
52 typedef std::map<int, BrowserPluginGuest*> ContainerInstanceMap; | |
53 | |
54 // A browser plugin embedder provides functionality for WebContents to operate | |
55 // in the 'embedder' role. It manages list of guests inside the embedder. | |
56 // | |
57 // The embedder's WebContents manages the lifetime of the embedder. They are | |
58 // created when a renderer asks WebContents to navigate (for the first time) to | |
59 // some guest. It gets destroyed when either the WebContents goes away or there | |
60 // is a RenderViewHost swap in WebContents. | |
61 class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver, | |
62 public NotificationObserver { | |
63 public: | |
64 virtual ~BrowserPluginEmbedder(); | |
65 | |
66 static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents, | |
67 RenderViewHost* render_view_host); | |
68 | |
69 // Navigates in a guest (new or existing). | |
70 void NavigateGuest(RenderViewHost* render_view_host, | |
71 int instance_id, | |
72 int64 frame_id, | |
73 const std::string& src, | |
74 const gfx::Size& size); | |
75 | |
76 // Overrides factory for testing. Default (NULL) value indicates regular | |
77 // (non-test) environment. | |
78 static void set_factory_for_testing(BrowserPluginHostFactory* factory) { | |
79 factory_ = factory; | |
80 } | |
81 | |
82 private: | |
83 friend class BrowserPluginEmbedderHelper; | |
84 friend class TestBrowserPluginEmbedder; | |
85 | |
86 BrowserPluginEmbedder(WebContentsImpl* web_contents, | |
87 RenderViewHost* render_view_host); | |
88 | |
89 // Returns a guest browser plugin delegate by its container ID specified | |
90 // in BrowserPlugin. | |
91 BrowserPluginGuest* GetGuestByInstanceID(int instance_id) const; | |
92 // Adds a new guest to the embedder (overridable in test). | |
93 virtual void AddGuest(int instance_id, | |
awong
2012/09/09 18:08:09
Take a scoped_ptr<BrowserPluginGuest> as the argum
lazyboy
2012/09/10 16:30:17
Hmmm, can you explain a bit more? AddGuest is a co
awong
2012/09/10 19:21:07
Sorry, I misunderstood the lifetime and though tha
lazyboy
2012/09/10 23:40:57
Done.
| |
94 BrowserPluginGuest* guest, | |
95 int64 frame_id); | |
96 void DestroyGuestByInstanceID(int instance_id); | |
97 void DestroyGuests(); | |
98 | |
99 // Message handlers (direct/indirect via BrowserPluginEmbedderHelper). | |
100 // Routes update rect ack message to the appropriate guest. | |
101 void UpdateRectACK(int instance_id, int message_id, const gfx::Size& size); | |
102 void SetFocus(int instance_id, bool focused); | |
103 void ResizeGuest(int instance_id, | |
104 TransportDIB* damage_buffer, | |
105 int width, | |
106 int height, | |
107 bool resize_pending, | |
108 float scale_factor); | |
109 // Handles input events sent from the BrowserPlugin (embedder's renderer | |
110 // process) by passing them to appropriate guest's input handler. | |
111 void HandleInputEvent(int instance_id, | |
112 RenderViewHost* render_view_host, | |
113 const gfx::Rect& guest_rect, | |
114 const WebKit::WebInputEvent& event, | |
115 IPC::Message* reply_message); | |
116 void PluginDestroyed(int instance_id); | |
117 | |
118 // WebContentsObserver implementation. | |
awong
2012/09/09 18:08:09
Interface implementations should retain the same a
lazyboy
2012/09/10 16:30:17
Done.
| |
119 // Used to monitor frame navigation to clean up guests when a frame navigates | |
120 // away from the browser plugin it's hosting. | |
121 virtual void DidCommitProvisionalLoadForFrame( | |
122 int64 frame_id, | |
123 bool is_main_frame, | |
124 const GURL& url, | |
125 PageTransition transition_type, | |
126 RenderViewHost* render_view_host) OVERRIDE; | |
127 virtual void RenderViewDeleted(RenderViewHost* render_view_host) OVERRIDE; | |
128 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE; | |
129 | |
130 // NotificationObserver method override. | |
131 virtual void Observe(int type, | |
132 const NotificationSource& source, | |
133 const NotificationDetails& details) OVERRIDE; | |
134 | |
135 // Called when visiblity of web_contents changes, so the embedder will | |
136 // show/hide its guest. | |
137 void WebContentsVisibilityChanged(bool visible); | |
138 | |
139 // Static factory instance (always NULL for non-test). | |
140 static BrowserPluginHostFactory* factory_; | |
141 | |
142 // A scoped container for notification registries. | |
143 NotificationRegistrar registrar_; | |
144 | |
145 // Contains guests' WebContents, mapping to their frame ids. | |
146 GuestWebContentsMap guest_web_contents_container_; | |
147 ContainerInstanceMap guests_by_instance_id_; | |
148 RenderViewHost* render_view_host_; | |
149 | |
150 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder); | |
151 }; | |
152 | |
153 } // namespace content | |
154 | |
155 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_ | |
OLD | NEW |