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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // Destroys the guest WebContents and all its associated state, including | 117 // Destroys the guest WebContents and all its associated state, including |
117 // this BrowserPluginGuest, and its new unattached windows. | 118 // this BrowserPluginGuest, and its new unattached windows. |
118 void Destroy(); | 119 void Destroy(); |
119 | 120 |
120 // Returns the identifier that uniquely identifies a browser plugin guest | 121 // Returns the identifier that uniquely identifies a browser plugin guest |
121 // within an embedder. | 122 // within an embedder. |
122 int instance_id() const { return instance_id_; } | 123 int instance_id() const { return instance_id_; } |
123 | 124 |
124 bool OnMessageReceivedFromEmbedder(const IPC::Message& message); | 125 bool OnMessageReceivedFromEmbedder(const IPC::Message& message); |
125 | 126 |
126 void Initialize(const BrowserPluginHostMsg_Attach_Params& params, | |
127 WebContentsImpl* embedder_web_contents); | |
128 | |
129 WebContentsImpl* embedder_web_contents() const { | 127 WebContentsImpl* embedder_web_contents() const { |
130 return embedder_web_contents_; | 128 return embedder_web_contents_; |
131 } | 129 } |
132 | 130 |
133 // Returns the embedder's RenderWidgetHostView if it is available. | 131 // Returns the embedder's RenderWidgetHostView if it is available. |
134 // Returns NULL otherwise. | 132 // Returns NULL otherwise. |
135 RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); | 133 RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); |
136 | 134 |
137 bool focused() const { return focused_; } | 135 bool focused() const { return focused_; } |
138 bool visible() const { return guest_visible_; } | 136 bool visible() const { return guest_visible_; } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // Returns whether the guest is attached to an embedder. | 176 // Returns whether the guest is attached to an embedder. |
179 bool attached() const { return embedder_web_contents_ != NULL; } | 177 bool attached() const { return embedder_web_contents_ != NULL; } |
180 | 178 |
181 // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| | 179 // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| |
182 // and initializes the guest with the provided |params|. Attaching a guest | 180 // and initializes the guest with the provided |params|. Attaching a guest |
183 // to an embedder implies that this guest's lifetime is no longer managed | 181 // to an embedder implies that this guest's lifetime is no longer managed |
184 // by its opener, and it can begin loading resources. |extra_params| are | 182 // by its opener, and it can begin loading resources. |extra_params| are |
185 // parameters passed into BrowserPlugin from JavaScript to be forwarded to | 183 // parameters passed into BrowserPlugin from JavaScript to be forwarded to |
186 // the content embedder. | 184 // the content embedder. |
187 void Attach(WebContentsImpl* embedder_web_contents, | 185 void Attach(WebContentsImpl* embedder_web_contents, |
188 BrowserPluginHostMsg_Attach_Params params, | 186 const BrowserPluginHostMsg_Attach_Params& params, |
189 const base::DictionaryValue& extra_params); | 187 const base::DictionaryValue& extra_params); |
190 | 188 |
191 // Returns whether BrowserPluginGuest is interested in receiving the given | 189 // Returns whether BrowserPluginGuest is interested in receiving the given |
192 // |message|. | 190 // |message|. |
193 static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); | 191 static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); |
194 gfx::Rect ToGuestRect(const gfx::Rect& rect); | 192 gfx::Rect ToGuestRect(const gfx::Rect& rect); |
195 | 193 |
196 void DragSourceEndedAt(int client_x, int client_y, int screen_x, | 194 void DragSourceEndedAt(int client_x, int client_y, int screen_x, |
197 int screen_y, blink::WebDragOperation operation); | 195 int screen_y, blink::WebDragOperation operation); |
198 | 196 |
(...skipping 22 matching lines...) Expand all Loading... |
221 friend class TestBrowserPluginGuest; | 219 friend class TestBrowserPluginGuest; |
222 | 220 |
223 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and | 221 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and |
224 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. | 222 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. |
225 BrowserPluginGuest(int instance_id, | 223 BrowserPluginGuest(int instance_id, |
226 bool has_render_view, | 224 bool has_render_view, |
227 WebContentsImpl* web_contents); | 225 WebContentsImpl* web_contents); |
228 | 226 |
229 void WillDestroy(WebContents* web_contents); | 227 void WillDestroy(WebContents* web_contents); |
230 | 228 |
| 229 void Initialize(const BrowserPluginHostMsg_Attach_Params& params, |
| 230 WebContentsImpl* embedder_web_contents, |
| 231 const base::DictionaryValue& extra_params); |
| 232 |
231 bool InAutoSizeBounds(const gfx::Size& size) const; | 233 bool InAutoSizeBounds(const gfx::Size& size) const; |
232 | 234 |
233 // Message handlers for messages from embedder. | 235 // Message handlers for messages from embedder. |
234 | 236 |
235 void OnCompositorFrameSwappedACK( | 237 void OnCompositorFrameSwappedACK( |
236 int instance_id, | 238 int instance_id, |
237 const FrameHostMsg_CompositorFrameSwappedACK_Params& params); | 239 const FrameHostMsg_CompositorFrameSwappedACK_Params& params); |
238 void OnCopyFromCompositingSurfaceAck(int instance_id, | 240 void OnCopyFromCompositingSurfaceAck(int instance_id, |
239 int request_id, | 241 int request_id, |
240 const SkBitmap& bitmap); | 242 const SkBitmap& bitmap); |
(...skipping 17 matching lines...) Expand all Loading... |
258 const FrameHostMsg_ReclaimCompositorResources_Params& params); | 260 const FrameHostMsg_ReclaimCompositorResources_Params& params); |
259 | 261 |
260 // Overridden in tests. | 262 // Overridden in tests. |
261 virtual void OnHandleInputEvent(int instance_id, | 263 virtual void OnHandleInputEvent(int instance_id, |
262 const gfx::Rect& guest_window_rect, | 264 const gfx::Rect& guest_window_rect, |
263 const blink::WebInputEvent* event); | 265 const blink::WebInputEvent* event); |
264 void OnLockMouse(bool user_gesture, | 266 void OnLockMouse(bool user_gesture, |
265 bool last_unlocked_by_target, | 267 bool last_unlocked_by_target, |
266 bool privileged); | 268 bool privileged); |
267 void OnLockMouseAck(int instance_id, bool succeeded); | 269 void OnLockMouseAck(int instance_id, bool succeeded); |
268 void OnNavigateGuest(int instance_id, const std::string& src); | |
269 void OnPluginDestroyed(int instance_id); | 270 void OnPluginDestroyed(int instance_id); |
270 // Resizes the guest's web contents. | 271 // Resizes the guest's web contents. |
271 void OnResizeGuest( | 272 void OnResizeGuest( |
272 int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params); | 273 int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params); |
273 void OnSetFocus(int instance_id, bool focused); | 274 void OnSetFocus(int instance_id, bool focused); |
274 // Sets the name of the guest so that other guests in the same partition can | 275 // Sets the name of the guest so that other guests in the same partition can |
275 // access it. | 276 // access it. |
276 void OnSetName(int instance_id, const std::string& name); | 277 void OnSetName(int instance_id, const std::string& name); |
277 // Updates the size state of the guest. | 278 // Updates the size state of the guest. |
278 void OnSetSize( | 279 void OnSetSize( |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 | 392 |
392 bool is_in_destruction_; | 393 bool is_in_destruction_; |
393 | 394 |
394 // Text input type states. | 395 // Text input type states. |
395 ui::TextInputType last_text_input_type_; | 396 ui::TextInputType last_text_input_type_; |
396 ui::TextInputMode last_input_mode_; | 397 ui::TextInputMode last_input_mode_; |
397 bool last_can_compose_inline_; | 398 bool last_can_compose_inline_; |
398 | 399 |
399 // This is a queue of messages that are destined to be sent to the embedder | 400 // This is a queue of messages that are destined to be sent to the embedder |
400 // once the guest is attached to a particular embedder. | 401 // once the guest is attached to a particular embedder. |
401 std::queue<IPC::Message*> pending_messages_; | 402 std::deque<linked_ptr<IPC::Message> > pending_messages_; |
402 | 403 |
403 scoped_ptr<BrowserPluginGuestDelegate> delegate_; | 404 scoped_ptr<BrowserPluginGuestDelegate> delegate_; |
404 | 405 |
405 // Weak pointer used to ask GeolocationPermissionContext about geolocation | 406 // Weak pointer used to ask GeolocationPermissionContext about geolocation |
406 // permission. | 407 // permission. |
407 base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_; | 408 base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_; |
408 | 409 |
409 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 410 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
410 }; | 411 }; |
411 | 412 |
412 } // namespace content | 413 } // namespace content |
413 | 414 |
414 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 415 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
OLD | NEW |