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. Any | 9 // BrowserPluginGuest lives on the UI thread of the browser process. Any |
10 // messages about the guest render process that the embedder might be interested | 10 // messages about the guest render process that the embedder might be interested |
11 // in receiving should be listened for here. | 11 // in receiving should be listened for here. |
12 // | 12 // |
13 // BrowserPluginGuest is a WebContentsObserver for the guest WebContents. | 13 // BrowserPluginGuest is a WebContentsObserver for the guest WebContents. |
14 // BrowserPluginGuest operates under the assumption that the guest will be | 14 // BrowserPluginGuest operates under the assumption that the guest will be |
15 // accessible through only one RenderViewHost for the lifetime of | 15 // accessible through only one RenderViewHost for the lifetime of |
16 // the guest WebContents. Thus, cross-process navigation is not supported. | 16 // the guest WebContents. Thus, cross-process navigation is not supported. |
17 | 17 |
18 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 18 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
19 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 19 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
20 | 20 |
21 #include <map> | 21 #include <map> |
22 #include <queue> | 22 #include <queue> |
23 | 23 |
24 #include "base/compiler_specific.h" | 24 #include "base/compiler_specific.h" |
| 25 #include "base/memory/linked_ptr.h" |
25 #include "base/memory/weak_ptr.h" | 26 #include "base/memory/weak_ptr.h" |
26 #include "base/values.h" | 27 #include "base/values.h" |
27 #include "content/common/edit_command.h" | 28 #include "content/common/edit_command.h" |
28 #include "content/common/input/input_event_ack_state.h" | 29 #include "content/common/input/input_event_ack_state.h" |
29 #include "content/public/browser/browser_plugin_guest_delegate.h" | 30 #include "content/public/browser/browser_plugin_guest_delegate.h" |
30 #include "content/public/browser/web_contents_observer.h" | 31 #include "content/public/browser/web_contents_observer.h" |
31 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" | 32 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" |
32 #include "third_party/WebKit/public/web/WebDragOperation.h" | 33 #include "third_party/WebKit/public/web/WebDragOperation.h" |
33 #include "third_party/WebKit/public/web/WebDragStatus.h" | 34 #include "third_party/WebKit/public/web/WebDragStatus.h" |
34 #include "third_party/WebKit/public/web/WebInputEvent.h" | 35 #include "third_party/WebKit/public/web/WebInputEvent.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 // Destroys the guest WebContents and all its associated state, including | 113 // Destroys the guest WebContents and all its associated state, including |
113 // this BrowserPluginGuest, and its new unattached windows. | 114 // this BrowserPluginGuest, and its new unattached windows. |
114 void Destroy(); | 115 void Destroy(); |
115 | 116 |
116 // Returns the identifier that uniquely identifies a browser plugin guest | 117 // Returns the identifier that uniquely identifies a browser plugin guest |
117 // within an embedder. | 118 // within an embedder. |
118 int instance_id() const { return instance_id_; } | 119 int instance_id() const { return instance_id_; } |
119 | 120 |
120 bool OnMessageReceivedFromEmbedder(const IPC::Message& message); | 121 bool OnMessageReceivedFromEmbedder(const IPC::Message& message); |
121 | 122 |
122 void Initialize(const BrowserPluginHostMsg_Attach_Params& params, | |
123 WebContentsImpl* embedder_web_contents); | |
124 | |
125 WebContentsImpl* embedder_web_contents() const { | 123 WebContentsImpl* embedder_web_contents() const { |
126 return embedder_web_contents_; | 124 return embedder_web_contents_; |
127 } | 125 } |
128 | 126 |
129 // Returns the embedder's RenderWidgetHostView if it is available. | 127 // Returns the embedder's RenderWidgetHostView if it is available. |
130 // Returns NULL otherwise. | 128 // Returns NULL otherwise. |
131 RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); | 129 RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); |
132 | 130 |
133 bool focused() const { return focused_; } | 131 bool focused() const { return focused_; } |
134 bool visible() const { return guest_visible_; } | 132 bool visible() const { return guest_visible_; } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // Returns whether the guest is attached to an embedder. | 171 // Returns whether the guest is attached to an embedder. |
174 bool attached() const { return embedder_web_contents_ != NULL; } | 172 bool attached() const { return embedder_web_contents_ != NULL; } |
175 | 173 |
176 // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| | 174 // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| |
177 // and initializes the guest with the provided |params|. Attaching a guest | 175 // and initializes the guest with the provided |params|. Attaching a guest |
178 // to an embedder implies that this guest's lifetime is no longer managed | 176 // to an embedder implies that this guest's lifetime is no longer managed |
179 // by its opener, and it can begin loading resources. |extra_params| are | 177 // by its opener, and it can begin loading resources. |extra_params| are |
180 // parameters passed into BrowserPlugin from JavaScript to be forwarded to | 178 // parameters passed into BrowserPlugin from JavaScript to be forwarded to |
181 // the content embedder. | 179 // the content embedder. |
182 void Attach(WebContentsImpl* embedder_web_contents, | 180 void Attach(WebContentsImpl* embedder_web_contents, |
183 BrowserPluginHostMsg_Attach_Params params, | 181 const BrowserPluginHostMsg_Attach_Params& params, |
184 const base::DictionaryValue& extra_params); | 182 const base::DictionaryValue& extra_params); |
185 | 183 |
186 // Returns whether BrowserPluginGuest is interested in receiving the given | 184 // Returns whether BrowserPluginGuest is interested in receiving the given |
187 // |message|. | 185 // |message|. |
188 static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); | 186 static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); |
189 gfx::Rect ToGuestRect(const gfx::Rect& rect); | 187 gfx::Rect ToGuestRect(const gfx::Rect& rect); |
190 | 188 |
191 void DragSourceEndedAt(int client_x, int client_y, int screen_x, | 189 void DragSourceEndedAt(int client_x, int client_y, int screen_x, |
192 int screen_y, blink::WebDragOperation operation); | 190 int screen_y, blink::WebDragOperation operation); |
193 | 191 |
(...skipping 22 matching lines...) Expand all Loading... |
216 friend class TestBrowserPluginGuest; | 214 friend class TestBrowserPluginGuest; |
217 | 215 |
218 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and | 216 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and |
219 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. | 217 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. |
220 BrowserPluginGuest(int instance_id, | 218 BrowserPluginGuest(int instance_id, |
221 bool has_render_view, | 219 bool has_render_view, |
222 WebContentsImpl* web_contents); | 220 WebContentsImpl* web_contents); |
223 | 221 |
224 void WillDestroy(); | 222 void WillDestroy(); |
225 | 223 |
| 224 void Initialize(const BrowserPluginHostMsg_Attach_Params& params, |
| 225 WebContentsImpl* embedder_web_contents, |
| 226 const base::DictionaryValue& extra_params); |
| 227 |
226 bool InAutoSizeBounds(const gfx::Size& size) const; | 228 bool InAutoSizeBounds(const gfx::Size& size) const; |
227 | 229 |
228 // Message handlers for messages from embedder. | 230 // Message handlers for messages from embedder. |
229 | 231 |
230 void OnCompositorFrameSwappedACK( | 232 void OnCompositorFrameSwappedACK( |
231 int instance_id, | 233 int instance_id, |
232 const FrameHostMsg_CompositorFrameSwappedACK_Params& params); | 234 const FrameHostMsg_CompositorFrameSwappedACK_Params& params); |
233 void OnCopyFromCompositingSurfaceAck(int instance_id, | 235 void OnCopyFromCompositingSurfaceAck(int instance_id, |
234 int request_id, | 236 int request_id, |
235 const SkBitmap& bitmap); | 237 const SkBitmap& bitmap); |
(...skipping 17 matching lines...) Expand all Loading... |
253 const FrameHostMsg_ReclaimCompositorResources_Params& params); | 255 const FrameHostMsg_ReclaimCompositorResources_Params& params); |
254 | 256 |
255 // Overridden in tests. | 257 // Overridden in tests. |
256 virtual void OnHandleInputEvent(int instance_id, | 258 virtual void OnHandleInputEvent(int instance_id, |
257 const gfx::Rect& guest_window_rect, | 259 const gfx::Rect& guest_window_rect, |
258 const blink::WebInputEvent* event); | 260 const blink::WebInputEvent* event); |
259 void OnLockMouse(bool user_gesture, | 261 void OnLockMouse(bool user_gesture, |
260 bool last_unlocked_by_target, | 262 bool last_unlocked_by_target, |
261 bool privileged); | 263 bool privileged); |
262 void OnLockMouseAck(int instance_id, bool succeeded); | 264 void OnLockMouseAck(int instance_id, bool succeeded); |
263 void OnNavigateGuest(int instance_id, const std::string& src); | |
264 void OnPluginDestroyed(int instance_id); | 265 void OnPluginDestroyed(int instance_id); |
265 // Resizes the guest's web contents. | 266 // Resizes the guest's web contents. |
266 void OnResizeGuest( | 267 void OnResizeGuest( |
267 int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params); | 268 int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params); |
268 void OnSetFocus(int instance_id, bool focused); | 269 void OnSetFocus(int instance_id, bool focused); |
269 // Sets the name of the guest so that other guests in the same partition can | 270 // Sets the name of the guest so that other guests in the same partition can |
270 // access it. | 271 // access it. |
271 void OnSetName(int instance_id, const std::string& name); | 272 void OnSetName(int instance_id, const std::string& name); |
272 // Updates the size state of the guest. | 273 // Updates the size state of the guest. |
273 void OnSetSize( | 274 void OnSetSize( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 | 387 |
387 bool is_in_destruction_; | 388 bool is_in_destruction_; |
388 | 389 |
389 // Text input type states. | 390 // Text input type states. |
390 ui::TextInputType last_text_input_type_; | 391 ui::TextInputType last_text_input_type_; |
391 ui::TextInputMode last_input_mode_; | 392 ui::TextInputMode last_input_mode_; |
392 bool last_can_compose_inline_; | 393 bool last_can_compose_inline_; |
393 | 394 |
394 // This is a queue of messages that are destined to be sent to the embedder | 395 // This is a queue of messages that are destined to be sent to the embedder |
395 // once the guest is attached to a particular embedder. | 396 // once the guest is attached to a particular embedder. |
396 std::queue<IPC::Message*> pending_messages_; | 397 std::deque<linked_ptr<IPC::Message> > pending_messages_; |
397 | 398 |
398 BrowserPluginGuestDelegate* delegate_; | 399 BrowserPluginGuestDelegate* delegate_; |
399 | 400 |
400 // Weak pointer used to ask GeolocationPermissionContext about geolocation | 401 // Weak pointer used to ask GeolocationPermissionContext about geolocation |
401 // permission. | 402 // permission. |
402 base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_; | 403 base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_; |
403 | 404 |
404 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 405 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
405 }; | 406 }; |
406 | 407 |
407 } // namespace content | 408 } // namespace content |
408 | 409 |
409 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 410 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
OLD | NEW |