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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // Destroys the guest WebContents and all its associated state, including | 112 // Destroys the guest WebContents and all its associated state, including |
112 // this BrowserPluginGuest, and its new unattached windows. | 113 // this BrowserPluginGuest, and its new unattached windows. |
113 void Destroy(); | 114 void Destroy(); |
114 | 115 |
115 // Returns the identifier that uniquely identifies a browser plugin guest | 116 // Returns the identifier that uniquely identifies a browser plugin guest |
116 // within an embedder. | 117 // within an embedder. |
117 int instance_id() const { return instance_id_; } | 118 int instance_id() const { return instance_id_; } |
118 | 119 |
119 bool OnMessageReceivedFromEmbedder(const IPC::Message& message); | 120 bool OnMessageReceivedFromEmbedder(const IPC::Message& message); |
120 | 121 |
121 void Initialize(const BrowserPluginHostMsg_Attach_Params& params, | |
122 WebContentsImpl* embedder_web_contents); | |
123 | |
124 WebContentsImpl* embedder_web_contents() const { | 122 WebContentsImpl* embedder_web_contents() const { |
125 return embedder_web_contents_; | 123 return embedder_web_contents_; |
126 } | 124 } |
127 | 125 |
128 // Returns the embedder's RenderWidgetHostView if it is available. | 126 // Returns the embedder's RenderWidgetHostView if it is available. |
129 // Returns NULL otherwise. | 127 // Returns NULL otherwise. |
130 RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); | 128 RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); |
131 | 129 |
132 bool focused() const { return focused_; } | 130 bool focused() const { return focused_; } |
133 bool visible() const { return guest_visible_; } | 131 bool visible() const { return guest_visible_; } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 // Returns whether the guest is attached to an embedder. | 168 // Returns whether the guest is attached to an embedder. |
171 bool attached() const { return embedder_web_contents_ != NULL; } | 169 bool attached() const { return embedder_web_contents_ != NULL; } |
172 | 170 |
173 // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| | 171 // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| |
174 // and initializes the guest with the provided |params|. Attaching a guest | 172 // and initializes the guest with the provided |params|. Attaching a guest |
175 // to an embedder implies that this guest's lifetime is no longer managed | 173 // to an embedder implies that this guest's lifetime is no longer managed |
176 // by its opener, and it can begin loading resources. |extra_params| are | 174 // by its opener, and it can begin loading resources. |extra_params| are |
177 // parameters passed into BrowserPlugin from JavaScript to be forwarded to | 175 // parameters passed into BrowserPlugin from JavaScript to be forwarded to |
178 // the content embedder. | 176 // the content embedder. |
179 void Attach(WebContentsImpl* embedder_web_contents, | 177 void Attach(WebContentsImpl* embedder_web_contents, |
180 BrowserPluginHostMsg_Attach_Params params, | 178 const BrowserPluginHostMsg_Attach_Params& params, |
181 const base::DictionaryValue& extra_params); | 179 const base::DictionaryValue& extra_params); |
182 | 180 |
183 // Returns whether BrowserPluginGuest is interested in receiving the given | 181 // Returns whether BrowserPluginGuest is interested in receiving the given |
184 // |message|. | 182 // |message|. |
185 static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); | 183 static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); |
186 gfx::Rect ToGuestRect(const gfx::Rect& rect); | 184 gfx::Rect ToGuestRect(const gfx::Rect& rect); |
187 | 185 |
188 void DragSourceEndedAt(int client_x, int client_y, int screen_x, | 186 void DragSourceEndedAt(int client_x, int client_y, int screen_x, |
189 int screen_y, blink::WebDragOperation operation); | 187 int screen_y, blink::WebDragOperation operation); |
190 | 188 |
(...skipping 15 matching lines...) Expand all Loading... |
206 class EmbedderWebContentsObserver; | 204 class EmbedderWebContentsObserver; |
207 | 205 |
208 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and | 206 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and |
209 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. | 207 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. |
210 BrowserPluginGuest(int instance_id, | 208 BrowserPluginGuest(int instance_id, |
211 bool has_render_view, | 209 bool has_render_view, |
212 WebContentsImpl* web_contents); | 210 WebContentsImpl* web_contents); |
213 | 211 |
214 void WillDestroy(); | 212 void WillDestroy(); |
215 | 213 |
| 214 void Initialize(const BrowserPluginHostMsg_Attach_Params& params, |
| 215 WebContentsImpl* embedder_web_contents, |
| 216 const base::DictionaryValue& extra_params); |
| 217 |
216 bool InAutoSizeBounds(const gfx::Size& size) const; | 218 bool InAutoSizeBounds(const gfx::Size& size) const; |
217 | 219 |
218 // Message handlers for messages from embedder. | 220 // Message handlers for messages from embedder. |
219 | 221 |
220 void OnCompositorFrameSwappedACK( | 222 void OnCompositorFrameSwappedACK( |
221 int instance_id, | 223 int instance_id, |
222 const FrameHostMsg_CompositorFrameSwappedACK_Params& params); | 224 const FrameHostMsg_CompositorFrameSwappedACK_Params& params); |
223 void OnCopyFromCompositingSurfaceAck(int instance_id, | 225 void OnCopyFromCompositingSurfaceAck(int instance_id, |
224 int request_id, | 226 int request_id, |
225 const SkBitmap& bitmap); | 227 const SkBitmap& bitmap); |
(...skipping 16 matching lines...) Expand all Loading... |
242 int instance_id, | 244 int instance_id, |
243 const FrameHostMsg_ReclaimCompositorResources_Params& params); | 245 const FrameHostMsg_ReclaimCompositorResources_Params& params); |
244 | 246 |
245 void OnHandleInputEvent(int instance_id, | 247 void OnHandleInputEvent(int instance_id, |
246 const gfx::Rect& guest_window_rect, | 248 const gfx::Rect& guest_window_rect, |
247 const blink::WebInputEvent* event); | 249 const blink::WebInputEvent* event); |
248 void OnLockMouse(bool user_gesture, | 250 void OnLockMouse(bool user_gesture, |
249 bool last_unlocked_by_target, | 251 bool last_unlocked_by_target, |
250 bool privileged); | 252 bool privileged); |
251 void OnLockMouseAck(int instance_id, bool succeeded); | 253 void OnLockMouseAck(int instance_id, bool succeeded); |
252 void OnNavigateGuest(int instance_id, const std::string& src); | |
253 void OnPluginDestroyed(int instance_id); | 254 void OnPluginDestroyed(int instance_id); |
254 // Resizes the guest's web contents. | 255 // Resizes the guest's web contents. |
255 void OnResizeGuest( | 256 void OnResizeGuest( |
256 int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params); | 257 int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params); |
257 void OnSetFocus(int instance_id, bool focused); | 258 void OnSetFocus(int instance_id, bool focused); |
258 // Sets the name of the guest so that other guests in the same partition can | 259 // Sets the name of the guest so that other guests in the same partition can |
259 // access it. | 260 // access it. |
260 void OnSetName(int instance_id, const std::string& name); | 261 void OnSetName(int instance_id, const std::string& name); |
261 // Updates the size state of the guest. | 262 // Updates the size state of the guest. |
262 void OnSetSize( | 263 void OnSetSize( |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 372 |
372 bool is_in_destruction_; | 373 bool is_in_destruction_; |
373 | 374 |
374 // Text input type states. | 375 // Text input type states. |
375 ui::TextInputType last_text_input_type_; | 376 ui::TextInputType last_text_input_type_; |
376 ui::TextInputMode last_input_mode_; | 377 ui::TextInputMode last_input_mode_; |
377 bool last_can_compose_inline_; | 378 bool last_can_compose_inline_; |
378 | 379 |
379 // This is a queue of messages that are destined to be sent to the embedder | 380 // This is a queue of messages that are destined to be sent to the embedder |
380 // once the guest is attached to a particular embedder. | 381 // once the guest is attached to a particular embedder. |
381 std::queue<IPC::Message*> pending_messages_; | 382 std::deque<linked_ptr<IPC::Message> > pending_messages_; |
382 | 383 |
383 BrowserPluginGuestDelegate* delegate_; | 384 BrowserPluginGuestDelegate* delegate_; |
384 | 385 |
385 // Weak pointer used to ask GeolocationPermissionContext about geolocation | 386 // Weak pointer used to ask GeolocationPermissionContext about geolocation |
386 // permission. | 387 // permission. |
387 base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_; | 388 base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_; |
388 | 389 |
389 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); | 390 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); |
390 }; | 391 }; |
391 | 392 |
392 } // namespace content | 393 } // namespace content |
393 | 394 |
394 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ | 395 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ |
OLD | NEW |