Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(296)

Side by Side Diff: content/browser/browser_plugin/browser_plugin_guest.h

Issue 272573005: <webview>: Move NewWindow API to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@guestview_manager_rename
Patch Set: Cleanup and fix tests Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 11 matching lines...) Expand all
22 #include <queue> 22 #include <queue>
23 23
24 #include "base/compiler_specific.h" 24 #include "base/compiler_specific.h"
25 #include "base/memory/weak_ptr.h" 25 #include "base/memory/weak_ptr.h"
26 #include "base/values.h" 26 #include "base/values.h"
27 #include "content/common/edit_command.h" 27 #include "content/common/edit_command.h"
28 #include "content/common/input/input_event_ack_state.h" 28 #include "content/common/input/input_event_ack_state.h"
29 #include "content/public/browser/browser_plugin_guest_delegate.h" 29 #include "content/public/browser/browser_plugin_guest_delegate.h"
30 #include "content/public/browser/web_contents_delegate.h" 30 #include "content/public/browser/web_contents_delegate.h"
31 #include "content/public/browser/web_contents_observer.h" 31 #include "content/public/browser/web_contents_observer.h"
32 #include "content/public/common/browser_plugin_permission_type.h"
33 #include "third_party/WebKit/public/web/WebCompositionUnderline.h" 32 #include "third_party/WebKit/public/web/WebCompositionUnderline.h"
34 #include "third_party/WebKit/public/web/WebDragOperation.h" 33 #include "third_party/WebKit/public/web/WebDragOperation.h"
35 #include "third_party/WebKit/public/web/WebDragStatus.h" 34 #include "third_party/WebKit/public/web/WebDragStatus.h"
36 #include "third_party/WebKit/public/web/WebInputEvent.h" 35 #include "third_party/WebKit/public/web/WebInputEvent.h"
37 #include "ui/base/ime/text_input_mode.h" 36 #include "ui/base/ime/text_input_mode.h"
38 #include "ui/base/ime/text_input_type.h" 37 #include "ui/base/ime/text_input_type.h"
39 #include "ui/gfx/rect.h" 38 #include "ui/gfx/rect.h"
40 #include "ui/surface/transport_dib.h" 39 #include "ui/surface/transport_dib.h"
41 40
42 struct BrowserPluginHostMsg_AutoSize_Params; 41 struct BrowserPluginHostMsg_AutoSize_Params;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // initialized yet and so it does not yet hold a SiteInstance. 86 // initialized yet and so it does not yet hold a SiteInstance.
88 // BrowserPluginGuest must be constructed and installed into a WebContents 87 // BrowserPluginGuest must be constructed and installed into a WebContents
89 // prior to its initialization because WebContents needs to determine what 88 // prior to its initialization because WebContents needs to determine what
90 // type of WebContentsView to construct on initialization. The content 89 // type of WebContentsView to construct on initialization. The content
91 // embedder needs to be aware of |guest_site_instance| on the guest's 90 // embedder needs to be aware of |guest_site_instance| on the guest's
92 // construction and so we pass it in here. 91 // construction and so we pass it in here.
93 static BrowserPluginGuest* Create( 92 static BrowserPluginGuest* Create(
94 int instance_id, 93 int instance_id,
95 SiteInstance* guest_site_instance, 94 SiteInstance* guest_site_instance,
96 WebContentsImpl* web_contents, 95 WebContentsImpl* web_contents,
97 scoped_ptr<base::DictionaryValue> extra_params); 96 scoped_ptr<base::DictionaryValue> extra_params,
98
99 static BrowserPluginGuest* CreateWithOpener(
100 int instance_id,
101 bool has_render_view,
102 WebContentsImpl* web_contents,
103 BrowserPluginGuest* opener); 97 BrowserPluginGuest* opener);
104 98
105 // Returns a WeakPtr to this BrowserPluginGuest. 99 // Returns a WeakPtr to this BrowserPluginGuest.
106 base::WeakPtr<BrowserPluginGuest> AsWeakPtr(); 100 base::WeakPtr<BrowserPluginGuest> AsWeakPtr();
107 101
108 // Called when the embedder WebContents is destroyed to give the 102 // Called when the embedder WebContents is destroyed to give the
109 // BrowserPluginGuest an opportunity to clean up after itself. 103 // BrowserPluginGuest an opportunity to clean up after itself.
110 void EmbedderDestroyed(); 104 void EmbedderDestroyed();
111 105
112 // Called when the embedder WebContents changes visibility. 106 // Called when the embedder WebContents changes visibility.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 const GURL& url, 154 const GURL& url,
161 PageTransition transition_type, 155 PageTransition transition_type,
162 RenderViewHost* render_view_host) OVERRIDE; 156 RenderViewHost* render_view_host) OVERRIDE;
163 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE; 157 virtual void DidStopLoading(RenderViewHost* render_view_host) OVERRIDE;
164 158
165 virtual void RenderViewReady() OVERRIDE; 159 virtual void RenderViewReady() OVERRIDE;
166 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; 160 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
167 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 161 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
168 162
169 // WebContentsDelegate implementation. 163 // WebContentsDelegate implementation.
164 // DONE
lazyboy 2014/05/12 23:00:20 Need to clean these up.
Fady Samuel 2014/05/13 18:59:02 Done.
170 virtual bool AddMessageToConsole(WebContents* source, 165 virtual bool AddMessageToConsole(WebContents* source,
171 int32 level, 166 int32 level,
172 const base::string16& message, 167 const base::string16& message,
173 int32 line_no, 168 int32 line_no,
174 const base::string16& source_id) OVERRIDE; 169 const base::string16& source_id) OVERRIDE;
175 // If a new window is created with target="_blank" and rel="noreferrer", then 170 // If a new window is created with target="_blank" and rel="noreferrer", then
176 // this method is called, indicating that the new WebContents is ready to be 171 // this method is called, indicating that the new WebContents is ready to be
177 // attached. 172 // attached.
173 // DONE
178 virtual void AddNewContents(WebContents* source, 174 virtual void AddNewContents(WebContents* source,
179 WebContents* new_contents, 175 WebContents* new_contents,
180 WindowOpenDisposition disposition, 176 WindowOpenDisposition disposition,
181 const gfx::Rect& initial_pos, 177 const gfx::Rect& initial_pos,
182 bool user_gesture, 178 bool user_gesture,
183 bool* was_blocked) OVERRIDE; 179 bool* was_blocked) OVERRIDE;
180 // Needs a bit of work
184 virtual void CanDownload(RenderViewHost* render_view_host, 181 virtual void CanDownload(RenderViewHost* render_view_host,
185 int request_id, 182 int request_id,
186 const std::string& request_method, 183 const std::string& request_method,
187 const base::Callback<void(bool)>& callback) OVERRIDE; 184 const base::Callback<void(bool)>& callback) OVERRIDE;
185 // DONE
188 virtual void LoadProgressChanged(WebContents* source, 186 virtual void LoadProgressChanged(WebContents* source,
189 double progress) OVERRIDE; 187 double progress) OVERRIDE;
188 // DONE
190 virtual void CloseContents(WebContents* source) OVERRIDE; 189 virtual void CloseContents(WebContents* source) OVERRIDE;
190 // DONE
191 virtual JavaScriptDialogManager* GetJavaScriptDialogManager() OVERRIDE; 191 virtual JavaScriptDialogManager* GetJavaScriptDialogManager() OVERRIDE;
192 // Needs to be moved out.
192 virtual ColorChooser* OpenColorChooser( 193 virtual ColorChooser* OpenColorChooser(
193 WebContents* web_contents, 194 WebContents* web_contents,
194 SkColor color, 195 SkColor color,
195 const std::vector<ColorSuggestion>& suggestions) OVERRIDE; 196 const std::vector<ColorSuggestion>& suggestions) OVERRIDE;
197 // Needs work.
196 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE; 198 virtual bool HandleContextMenu(const ContextMenuParams& params) OVERRIDE;
199 // Needs work.
197 virtual void HandleKeyboardEvent( 200 virtual void HandleKeyboardEvent(
198 WebContents* source, 201 WebContents* source,
199 const NativeWebKeyboardEvent& event) OVERRIDE; 202 const NativeWebKeyboardEvent& event) OVERRIDE;
203 // DONE
200 virtual void FindReply(WebContents* contents, 204 virtual void FindReply(WebContents* contents,
201 int request_id, 205 int request_id,
202 int number_of_matches, 206 int number_of_matches,
203 const gfx::Rect& selection_rect, 207 const gfx::Rect& selection_rect,
204 int active_match_ordinal, 208 int active_match_ordinal,
205 bool final_update) OVERRIDE; 209 bool final_update) OVERRIDE;
210 // DONE
206 virtual WebContents* OpenURLFromTab(WebContents* source, 211 virtual WebContents* OpenURLFromTab(WebContents* source,
207 const OpenURLParams& params) OVERRIDE; 212 const OpenURLParams& params) OVERRIDE;
213 // Needs work. Name attribute needs to move out.
208 virtual void WebContentsCreated(WebContents* source_contents, 214 virtual void WebContentsCreated(WebContents* source_contents,
209 int opener_render_frame_id, 215 int opener_render_frame_id,
210 const base::string16& frame_name, 216 const base::string16& frame_name,
211 const GURL& target_url, 217 const GURL& target_url,
212 WebContents* new_contents) OVERRIDE; 218 WebContents* new_contents) OVERRIDE;
219 // Done
213 virtual void RendererUnresponsive(WebContents* source) OVERRIDE; 220 virtual void RendererUnresponsive(WebContents* source) OVERRIDE;
221 // DONE
214 virtual void RendererResponsive(WebContents* source) OVERRIDE; 222 virtual void RendererResponsive(WebContents* source) OVERRIDE;
223 // Needs a little bit of work.
215 virtual void RunFileChooser(WebContents* web_contents, 224 virtual void RunFileChooser(WebContents* web_contents,
216 const FileChooserParams& params) OVERRIDE; 225 const FileChooserParams& params) OVERRIDE;
226 // DONE
217 virtual bool ShouldFocusPageAfterCrash() OVERRIDE; 227 virtual bool ShouldFocusPageAfterCrash() OVERRIDE;
228 // DONE
218 virtual void RequestMediaAccessPermission( 229 virtual void RequestMediaAccessPermission(
219 WebContents* web_contents, 230 WebContents* web_contents,
220 const MediaStreamRequest& request, 231 const MediaStreamRequest& request,
221 const MediaResponseCallback& callback) OVERRIDE; 232 const MediaResponseCallback& callback) OVERRIDE;
233 // Needs a tiny bit of work.
222 virtual bool PreHandleGestureEvent( 234 virtual bool PreHandleGestureEvent(
223 content::WebContents* source, 235 content::WebContents* source,
224 const blink::WebGestureEvent& event) OVERRIDE; 236 const blink::WebGestureEvent& event) OVERRIDE;
225 237
226 // Exposes the protected web_contents() from WebContentsObserver. 238 // Exposes the protected web_contents() from WebContentsObserver.
227 WebContentsImpl* GetWebContents() const; 239 WebContentsImpl* GetWebContents() const;
228 240
229 gfx::Point GetScreenCoordinates(const gfx::Point& relative_position) const; 241 gfx::Point GetScreenCoordinates(const gfx::Point& relative_position) const;
230 242
231 // Helper to send messages to embedder. This methods fills the message with 243 // Helper to send messages to embedder. This methods fills the message with
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 284 }
273 285
274 void SetZoom(double zoom_factor); 286 void SetZoom(double zoom_factor);
275 287
276 void PointerLockPermissionResponse(bool allow); 288 void PointerLockPermissionResponse(bool allow);
277 289
278 private: 290 private:
279 class EmbedderWebContentsObserver; 291 class EmbedderWebContentsObserver;
280 friend class TestBrowserPluginGuest; 292 friend class TestBrowserPluginGuest;
281 293
282 class DownloadRequest;
283 class NewWindowRequest;
284 class PermissionRequest;
285
286 // Tracks the name, and target URL of the new window and whether or not it has 294 // Tracks the name, and target URL of the new window and whether or not it has
287 // changed since the WebContents has been created and before the new window 295 // changed since the WebContents has been created and before the new window
288 // has been attached to a BrowserPlugin. Once the first navigation commits, we 296 // has been attached to a BrowserPlugin. Once the first navigation commits, we
289 // no longer track this information. 297 // no longer track this information.
290 struct NewWindowInfo { 298 struct NewWindowInfo {
291 bool changed; 299 bool changed;
292 GURL url; 300 GURL url;
293 std::string name; 301 std::string name;
294 NewWindowInfo(const GURL& url, const std::string& name) : 302 NewWindowInfo(const GURL& url, const std::string& name) :
295 changed(false), 303 changed(false),
296 url(url), 304 url(url),
297 name(name) {} 305 name(name) {}
298 }; 306 };
299 307
300 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and 308 // BrowserPluginGuest is a WebContentsObserver of |web_contents| and
301 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. 309 // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest.
302 BrowserPluginGuest(int instance_id, 310 BrowserPluginGuest(int instance_id,
303 bool has_render_view, 311 bool has_render_view,
304 WebContentsImpl* web_contents); 312 WebContentsImpl* web_contents);
305 313
306 // Destroy unattached new windows that have been opened by this 314 void WillDestroy(WebContents* web_contents);
307 // BrowserPluginGuest.
308 void DestroyUnattachedWindows();
309
310 void LoadURLWithParams(const GURL& url,
311 const Referrer& referrer,
312 PageTransition transition_type,
313 WebContents* web_contents);
314
315 // Returns the |request_id| generated for the |request| provided.
316 void RequestPermission(
317 BrowserPluginPermissionType permission_type,
318 scoped_refptr<BrowserPluginGuest::PermissionRequest> request,
319 const base::DictionaryValue& request_info);
320
321 // Creates a new guest window, and BrowserPluginGuest that is owned by this
322 // BrowserPluginGuest.
323 BrowserPluginGuest* CreateNewGuestWindow(const OpenURLParams& params);
324 315
325 bool InAutoSizeBounds(const gfx::Size& size) const; 316 bool InAutoSizeBounds(const gfx::Size& size) const;
326 317
327 void RequestNewWindowPermission(WindowOpenDisposition disposition,
328 const gfx::Rect& initial_bounds,
329 bool user_gesture,
330 WebContentsImpl* new_contents);
331
332 // Message handlers for messages from embedder. 318 // Message handlers for messages from embedder.
333 319
334 void OnCompositorFrameSwappedACK( 320 void OnCompositorFrameSwappedACK(
335 int instance_id, 321 int instance_id,
336 const FrameHostMsg_CompositorFrameSwappedACK_Params& params); 322 const FrameHostMsg_CompositorFrameSwappedACK_Params& params);
337 void OnCopyFromCompositingSurfaceAck(int instance_id, 323 void OnCopyFromCompositingSurfaceAck(int instance_id,
338 int request_id, 324 int request_id,
339 const SkBitmap& bitmap); 325 const SkBitmap& bitmap);
340 // Handles drag events from the embedder. 326 // Handles drag events from the embedder.
341 // When dragging, the drag events go to the embedder first, and if the drag 327 // When dragging, the drag events go to the embedder first, and if the drag
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 gfx::Size min_auto_size_; 468 gfx::Size min_auto_size_;
483 gfx::Size full_size_; 469 gfx::Size full_size_;
484 470
485 // Each copy-request is identified by a unique number. The unique number is 471 // Each copy-request is identified by a unique number. The unique number is
486 // used to keep track of the right callback. 472 // used to keep track of the right callback.
487 int copy_request_id_; 473 int copy_request_id_;
488 typedef base::Callback<void(bool, const SkBitmap&)> CopyRequestCallback; 474 typedef base::Callback<void(bool, const SkBitmap&)> CopyRequestCallback;
489 typedef std::map<int, const CopyRequestCallback> CopyRequestMap; 475 typedef std::map<int, const CopyRequestCallback> CopyRequestMap;
490 CopyRequestMap copy_request_callbacks_; 476 CopyRequestMap copy_request_callbacks_;
491 477
492 typedef std::map<BrowserPluginGuest*, NewWindowInfo> PendingWindowMap;
493 PendingWindowMap pending_new_windows_;
494 // A counter to generate a unique request id for a permission request.
495 // We only need the ids to be unique for a given BrowserPluginGuest.
496 int next_permission_request_id_;
497
498 // A map to store relevant info for a request keyed by the request's id.
499 typedef std::map<int, scoped_refptr<PermissionRequest> > RequestMap;
500 RequestMap permission_request_map_;
501
502 // Indicates that this BrowserPluginGuest has associated renderer-side state. 478 // Indicates that this BrowserPluginGuest has associated renderer-side state.
503 // This is used to determine whether or not to create a new RenderView when 479 // This is used to determine whether or not to create a new RenderView when
504 // this guest is attached. 480 // this guest is attached.
505 bool has_render_view_; 481 bool has_render_view_;
506 482
507 // Last seen size of guest contents (by OnUpdateRect). 483 // Last seen size of guest contents (by OnUpdateRect).
508 gfx::Size last_seen_view_size_; 484 gfx::Size last_seen_view_size_;
509 // Last seen autosize attribute state (by OnUpdateRect). 485 // Last seen autosize attribute state (by OnUpdateRect).
510 bool last_seen_auto_size_enabled_; 486 bool last_seen_auto_size_enabled_;
511 487
512 bool is_in_destruction_; 488 bool is_in_destruction_;
513 489
514 // Text input type states. 490 // Text input type states.
515 ui::TextInputType last_text_input_type_; 491 ui::TextInputType last_text_input_type_;
516 ui::TextInputMode last_input_mode_; 492 ui::TextInputMode last_input_mode_;
517 bool last_can_compose_inline_; 493 bool last_can_compose_inline_;
518 494
519 // This is a queue of messages that are destined to be sent to the embedder 495 // This is a queue of messages that are destined to be sent to the embedder
520 // once the guest is attached to a particular embedder. 496 // once the guest is attached to a particular embedder.
521 std::queue<IPC::Message*> pending_messages_; 497 std::queue<IPC::Message*> pending_messages_;
522 498
523 scoped_ptr<BrowserPluginGuestDelegate> delegate_; 499 scoped_ptr<BrowserPluginGuestDelegate> delegate_;
524 500
525 // These are parameters passed from JavaScript on attachment to the content
526 // embedder.
527 scoped_ptr<base::DictionaryValue> extra_attach_params_;
528
529 // Weak pointer used to ask GeolocationPermissionContext about geolocation 501 // Weak pointer used to ask GeolocationPermissionContext about geolocation
530 // permission. 502 // permission.
531 base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_; 503 base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_;
532 504
533 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); 505 DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest);
534 }; 506 };
535 507
536 } // namespace content 508 } // namespace content
537 509
538 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ 510 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698