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.
5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_
6 #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_
15 #include "base/callback.h"
16 #include "base/strings/string16.h"
17 #include "build/build_config.h"
18 #include "content/common/content_export.h"
19 #include "content/public/browser/bluetooth_chooser.h"
20 #include "content/public/browser/bluetooth_scanning_prompt.h"
21 #include "content/public/browser/eye_dropper.h"
22 #include "content/public/browser/invalidate_type.h"
23 #include "content/public/browser/media_stream_request.h"
24 #include "content/public/browser/serial_chooser.h"
25 #include "content/public/browser/web_contents.h"
26 #include "content/public/common/previews_state.h"
27 #include "content/public/common/window_container_type.mojom-forward.h"
28 #include "third_party/blink/public/common/mediastream/media_stream_request.h"
29 #include "third_party/blink/public/common/page/web_drag_operation.h"
30 #include "third_party/blink/public/common/security/security_style.h"
31 #include "third_party/blink/public/mojom/choosers/color_chooser.mojom-forward.h"
32 #include "third_party/blink/public/mojom/frame/blocked_navigation_types.mojom.h"
33 #include "third_party/blink/public/mojom/frame/fullscreen.mojom-forward.h"
34 #include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
35 #include "third_party/skia/include/core/SkColor.h"
36 #include "ui/base/window_open_disposition.h"
37 #include "ui/gfx/geometry/rect_f.h"
38 #include "ui/gfx/native_widget_types.h"
40 #if defined(OS_ANDROID)
41 #include "base/android/scoped_java_ref.h"
54 class FileChooserParams;
60 class EyeDropperListener;
61 class FileSelectListener;
62 class JavaScriptDialogManager;
63 class RenderFrameHost;
64 class RenderWidgetHost;
65 class SessionStorageNamespace;
67 class WebContentsImpl;
68 struct ContextMenuParams;
70 struct MediaPlayerWatchTime;
71 struct NativeWebKeyboardEvent;
73 struct SecurityStyleExplanations;
74 } // namespace content
78 class GeolocationContext;
96 class WebGestureEvent;
101 struct OpenURLParams;
103 enum class KeyboardEventProcessingResult;
105 // Result of an EnterPictureInPicture request.
106 enum class PictureInPictureResult {
107 // The request was successful.
110 // Picture-in-Picture is not supported by the embedder.
114 // Objects implement this interface to get notified about changes in the
115 // WebContents and to provide necessary functionality.
116 class CONTENT_EXPORT WebContentsDelegate {
118 WebContentsDelegate();
120 // Opens a new URL inside the passed in WebContents (if source is 0 open
121 // in the current front-most tab), unless |disposition| indicates the url
122 // should be opened in a new tab or window.
124 // A nullptr source indicates the current tab (callers should probably use
125 // OpenURL() for these cases which does it for you).
127 // Returns the WebContents the URL is opened in, or nullptr if the URL wasn't
128 // opened immediately.
129 virtual WebContents* OpenURLFromTab(WebContents* source,
130 const OpenURLParams& params);
132 // Allows the delegate to optionally cancel navigations that attempt to
133 // transfer to a different process between the start of the network load and
134 // commit. Defaults to true.
135 virtual bool ShouldTransferNavigation(bool is_main_frame_navigation);
137 // Called to inform the delegate that the WebContents's navigation state
138 // changed. The |changed_flags| indicates the parts of the navigation state
139 // that have been updated.
140 virtual void NavigationStateChanged(WebContents* source,
141 InvalidateTypes changed_flags) {}
143 // Called to inform the delegate that the WebContent's visible
144 // security state changed and that security UI should be updated.
145 virtual void VisibleSecurityStateChanged(WebContents* source) {}
147 // Creates a new tab with the already-created WebContents |new_contents|.
148 // The window for the added contents should be reparented correctly when this
149 // method returns. |target_url| is set to the value provided when
150 // |new_contents| was created. If |disposition| is NEW_POPUP, |initial_rect|
151 // should hold the initial position and size. If |was_blocked| is non-nullptr,
152 // then |*was_blocked| will be set to true if the popup gets blocked, and left
153 // unchanged otherwise.
154 virtual void AddNewContents(WebContents* source,
155 std::unique_ptr<WebContents> new_contents,
156 const GURL& target_url,
157 WindowOpenDisposition disposition,
158 const gfx::Rect& initial_rect,
160 bool* was_blocked) {}
162 // Selects the specified contents, bringing its container to the front.
163 virtual void ActivateContents(WebContents* contents) {}
165 // Notifies the delegate that this contents is starting or is done loading
166 // some resource. The delegate should use this notification to represent
167 // loading feedback. See WebContents::IsLoading()
168 // |to_different_document| will be true unless the load is a fragment
169 // navigation, or triggered by history.pushState/replaceState.
170 virtual void LoadingStateChanged(WebContents* source,
171 bool to_different_document) {}
173 // Request the delegate to close this web contents, and do whatever cleanup
175 virtual void CloseContents(WebContents* source) {}
177 // Request the delegate to resize this WebContents to the specified size in
178 // screen coordinates. The embedder is free to ignore the request.
179 virtual void SetContentsBounds(WebContents* source, const gfx::Rect& bounds) {
182 // Notification that the target URL has changed.
183 virtual void UpdateTargetURL(WebContents* source,
186 // Notification that there was a mouse event, along with the type of event.
187 // If |motion| is true, this is a normal motion event. If |exited| is true,
188 // the pointer left the contents area.
189 virtual void ContentsMouseEvent(WebContents* source,
193 // Request the delegate to change the zoom level of the current tab.
194 virtual void ContentsZoomChange(bool zoom_in) {}
196 // Called to determine if the WebContents can be overscrolled with touch/wheel
198 virtual bool CanOverscrollContent();
200 // Invoked prior to showing before unload handler confirmation dialog.
201 virtual void WillRunBeforeUnloadConfirm() {}
203 // Returns true if javascript dialogs and unload alerts are suppressed.
205 virtual bool ShouldSuppressDialogs(WebContents* source);
207 // Returns whether pending NavigationEntries for aborted browser-initiated
208 // navigations should be preserved (and thus returned from GetVisibleURL).
209 // Defaults to false.
210 virtual bool ShouldPreserveAbortedURLs(WebContents* source);
212 // A message was added to the console of a frame of the page. Returning true
213 // indicates that the delegate handled the message. If false is returned the
214 // default logging mechanism will be used for the message.
215 // NOTE: If you only need to monitor messages added to the console, rather
216 // than change the behavior when they are added, prefer using
217 // WebContentsObserver::OnDidAddMessageToConsole().
218 virtual bool DidAddMessageToConsole(
220 blink::mojom::ConsoleMessageLevel log_level,
221 const base::string16& message,
223 const base::string16& source_id);
225 // Tells us that we've finished firing this tab's beforeunload event.
226 // The proceed bool tells us whether the user chose to proceed closing the
227 // tab. Returns true if the tab can continue on firing its unload event.
228 // If we're closing the entire browser, then we'll want to delay firing
229 // unload events until all the beforeunload events have fired.
230 virtual void BeforeUnloadFired(WebContents* tab,
232 bool* proceed_to_fire_unload);
234 // Returns true if the location bar should be focused by default rather than
235 // the page contents. NOTE: this is only used if WebContents can't determine
236 // for itself whether the location bar should be focused by default. For a
237 // complete check, you should use WebContents::FocusLocationBarByDefault().
238 virtual bool ShouldFocusLocationBarByDefault(WebContents* source);
240 // Sets focus to the location bar or some other place that is appropriate.
241 // This is called when the tab wants to encourage user input, like for the
243 virtual void SetFocusToLocationBar() {}
245 // Returns whether the page should be focused when transitioning from crashed
246 // to live. Default is true.
247 virtual bool ShouldFocusPageAfterCrash();
249 // Returns whether the page should resume accepting requests for the new
250 // window. This is used when window creation is asynchronous
251 // and the navigations need to be delayed. Default is true.
252 virtual bool ShouldResumeRequestsForCreatedWindow();
254 // This is called when WebKit tells us that it is done tabbing through
255 // controls on the page. Provides a way for WebContentsDelegates to handle
256 // this. Returns true if the delegate successfully handled it.
257 virtual bool TakeFocus(WebContents* source,
260 // Invoked when the page loses mouse capture.
261 virtual void LostCapture() {}
263 // Asks the delegate if the given tab can download.
264 // Invoking the |callback| synchronously is OK.
265 virtual void CanDownload(const GURL& url,
266 const std::string& request_method,
267 base::OnceCallback<void(bool)> callback);
269 // Returns true if the context menu operation was handled by the delegate.
270 virtual bool HandleContextMenu(RenderFrameHost* render_frame_host,
271 const ContextMenuParams& params);
273 // Allows delegates to handle keyboard events before sending to the renderer.
274 // See enum for description of return values.
275 virtual KeyboardEventProcessingResult PreHandleKeyboardEvent(
277 const NativeWebKeyboardEvent& event);
279 // Allows delegates to handle unhandled keyboard messages coming back from
280 // the renderer. Returns true if the event was handled, false otherwise. A
281 // true value means no more processing should happen on the event. The default
282 // return value is false
283 virtual bool HandleKeyboardEvent(WebContents* source,
284 const NativeWebKeyboardEvent& event);
286 // Allows delegates to handle gesture events before sending to the renderer.
287 // Returns true if the |event| was handled and thus shouldn't be processed
288 // by the renderer's event handler. Note that the touch events that create
289 // the gesture are always passed to the renderer since the gesture is created
290 // and dispatched after the touches return without being "preventDefault()"ed.
291 virtual bool PreHandleGestureEvent(
293 const blink::WebGestureEvent& event);
295 // Called when an external drag event enters the web contents window. Return
296 // true to allow dragging and dropping on the web contents window or false to
297 // cancel the operation. This method is used by Chromium Embedded Framework.
298 virtual bool CanDragEnter(WebContents* source,
299 const DropData& data,
300 blink::WebDragOperationsMask operations_allowed);
302 // Shows the repost form confirmation dialog box.
303 virtual void ShowRepostFormWarningDialog(WebContents* source) {}
305 // Allows delegate to override navigation to the history entries.
306 // Returns true to allow WebContents to continue with the default processing.
307 virtual bool OnGoToEntryOffset(int offset);
309 // Allows delegate to control whether a new WebContents can be created by
310 // the WebContents itself.
312 // If an delegate returns true, it can optionally also override
313 // CreateCustomWebContents() below to provide their own WebContents.
314 virtual bool IsWebContentsCreationOverridden(
315 SiteInstance* source_site_instance,
316 content::mojom::WindowContainerType window_container_type,
317 const GURL& opener_url,
318 const std::string& frame_name,
319 const GURL& target_url);
321 // Allow delegate to creates a custom WebContents when
322 // WebContents::CreateNewWindow() is called. This function is only called
323 // when IsWebContentsCreationOverridden() returns true.
325 // In general, a delegate should return a pointer to a created WebContents
326 // so that the opener can be given a references to it as appropriate.
327 // Returning nullptr also makes sense if the delegate wishes to suppress
328 // all window creation, or if the delegate wants to ensure the opener
329 // cannot get a reference effectively creating a new browsing instance.
330 virtual WebContents* CreateCustomWebContents(
331 RenderFrameHost* opener,
332 SiteInstance* source_site_instance,
333 bool is_new_browsing_instance,
334 const GURL& opener_url,
335 const std::string& frame_name,
336 const GURL& target_url,
337 const std::string& partition_id,
338 SessionStorageNamespace* session_storage_namespace);
340 // Notifies the delegate about the creation of a new WebContents. This
341 // typically happens when popups are created.
342 virtual void WebContentsCreated(WebContents* source_contents,
343 int opener_render_process_id,
344 int opener_render_frame_id,
345 const std::string& frame_name,
346 const GURL& target_url,
347 WebContents* new_contents) {}
349 // Notifies the embedder that a new WebContents has been created to contain
350 // the contents of a portal.
351 virtual void PortalWebContentsCreated(WebContents* portal_web_contents) {}
353 // Notifies the embedder that an existing WebContents that it manages (e.g., a
354 // browser tab) has become the contents of a portal.
356 // During portal activation, WebContentsDelegate::ActivatePortalWebContents
357 // will be called to release the delegate's management of a WebContents.
358 // Shortly afterward, the portal will assume ownership of the contents and
359 // call this function to indicate that this is complete, passing the
360 // swapped-out contents as |portal_web_contents|.
362 // Implementations will likely want to apply changes analogous to those they
363 // would apply to a new WebContents in PortalWebContentsCreated.
364 virtual void WebContentsBecamePortal(WebContents* portal_web_contents) {}
366 // Notification that one of the frames in the WebContents is hung. |source| is
367 // the WebContents that is hung, and |render_widget_host| is the
368 // RenderWidgetHost that, while routing events to it, discovered the hang.
370 // |hang_monitor_restarter| can be used to restart the timer used to
371 // detect the hang. The timer is typically restarted when the renderer has
372 // become active, the tab got hidden, or the user has chosen to wait some
375 // Useful member functions on |render_widget_host|:
376 // - Getting the hung render process: GetProcess()
377 // - Querying whether the process is still hung: IsCurrentlyUnresponsive()
378 virtual void RendererUnresponsive(
380 RenderWidgetHost* render_widget_host,
381 base::RepeatingClosure hang_monitor_restarter) {}
383 // Notification that a process in the WebContents is no longer hung. |source|
384 // is the WebContents that was hung, and |render_widget_host| is the
385 // RenderWidgetHost that was passed in an earlier call to
386 // RendererUnresponsive().
387 virtual void RendererResponsive(WebContents* source,
388 RenderWidgetHost* render_widget_host) {}
390 // Invoked when a main fram navigation occurs.
391 virtual void DidNavigateMainFramePostCommit(WebContents* source) {}
393 // Returns a pointer to a service to manage JavaScript dialogs. May return
394 // nullptr in which case dialogs aren't shown.
395 virtual JavaScriptDialogManager* GetJavaScriptDialogManager(
396 WebContents* source);
398 // Called when color chooser should open. Returns the opened color chooser.
399 // Returns nullptr if we failed to open the color chooser (e.g. when there is
400 // a ColorChooserDialog already open on Windows). Ownership of the returned
401 // pointer is transferred to the caller.
402 virtual ColorChooser* OpenColorChooser(
403 WebContents* web_contents,
405 const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions);
407 // Called when an eye dropper should open. Returns the eye dropper window.
408 // The eye dropper is responsible for calling listener->ColorSelected() or
409 // listener->ColorSelectionCanceled().
410 // The ownership of the returned pointer is transferred to the caller.
411 virtual std::unique_ptr<EyeDropper> OpenEyeDropper(
412 RenderFrameHost* frame,
413 EyeDropperListener* listener);
415 // Called when a file selection is to be done.
416 // This function is responsible for calling listener->FileSelected() or
417 // listener->FileSelectionCanceled().
418 virtual void RunFileChooser(RenderFrameHost* render_frame_host,
419 std::unique_ptr<FileSelectListener> listener,
420 const blink::mojom::FileChooserParams& params);
422 // Request to enumerate a directory. This is equivalent to running the file
423 // chooser in directory-enumeration mode and having the user select the given
425 // This function is responsible for calling listener->FileSelected() or
426 // listener->FileSelectionCanceled().
427 virtual void EnumerateDirectory(WebContents* web_contents,
428 std::unique_ptr<FileSelectListener> listener,
429 const base::FilePath& path);
431 // Shows a chooser for the user to select a nearby Bluetooth device. The
432 // observer must live at least as long as the returned chooser object.
433 virtual std::unique_ptr<BluetoothChooser> RunBluetoothChooser(
434 RenderFrameHost* frame,
435 const BluetoothChooser::EventHandler& event_handler);
437 // Creates an info bar for the user to control the receiving of the SMS.
438 virtual void CreateSmsPrompt(RenderFrameHost*,
440 const std::string& one_time_code,
441 base::OnceCallback<void()> on_confirm,
442 base::OnceCallback<void()> on_cancel);
444 // Shows a prompt for the user to allow/block Bluetooth scanning. The
445 // observer must live at least as long as the returned prompt object.
446 virtual std::unique_ptr<BluetoothScanningPrompt> ShowBluetoothScanningPrompt(
447 RenderFrameHost* frame,
448 const BluetoothScanningPrompt::EventHandler& event_handler);
450 // Returns true if the delegate will embed a WebContents-owned fullscreen
451 // render widget. In this case, the delegate may access the widget by calling
452 // WebContents::GetFullscreenRenderWidgetHostView(). If false is returned,
453 // WebContents will be responsible for showing the fullscreen widget.
454 virtual bool EmbedsFullscreenWidget();
456 // Called when the renderer puts a tab into fullscreen mode.
457 // |requesting_frame| is the specific content frame requesting fullscreen.
458 virtual void EnterFullscreenModeForTab(
459 RenderFrameHost* requesting_frame,
460 const blink::mojom::FullscreenOptions& options) {}
462 // Called when the renderer puts a tab out of fullscreen mode.
463 virtual void ExitFullscreenModeForTab(WebContents*) {}
465 virtual bool IsFullscreenForTabOrPending(const WebContents* web_contents);
467 // Returns the actual display mode of the top-level browsing context.
468 // For example, it should return 'blink::mojom::DisplayModeFullscreen'
469 // whenever the browser window is put to fullscreen mode (either by the end
470 // user, or HTML API or from a web manifest setting). See
471 // http://w3c.github.io/manifest/#dfn-display-mode
472 virtual blink::mojom::DisplayMode GetDisplayMode(
473 const WebContents* web_contents);
475 // Register a new handler for URL requests with the given scheme.
476 // |user_gesture| is true if the registration is made in the context of a user
478 virtual void RegisterProtocolHandler(WebContents* web_contents,
479 const std::string& protocol,
481 bool user_gesture) {}
483 // Unregister the registered handler for URL requests with the given scheme.
484 // |user_gesture| is true if the registration is made in the context of a user
486 virtual void UnregisterProtocolHandler(WebContents* web_contents,
487 const std::string& protocol,
489 bool user_gesture) {}
491 // Result of string search in the page. This includes the number of matches
492 // found and the selection rect (in screen coordinates) for the string found.
493 // If |final_update| is false, it indicates that more results follow.
494 virtual void FindReply(WebContents* web_contents,
496 int number_of_matches,
497 const gfx::Rect& selection_rect,
498 int active_match_ordinal,
499 bool final_update) {}
502 virtual void DidRenderFrame() {}
505 #if defined(OS_ANDROID)
506 // Provides the rects of the current find-in-page matches.
507 // Sent as a reply to RequestFindMatchRects.
508 virtual void FindMatchRectsReply(WebContents* web_contents,
510 const std::vector<gfx::RectF>& rects,
511 const gfx::RectF& active_rect) {}
514 // Invoked when the preferred size of the contents has been changed.
515 virtual void UpdatePreferredSize(WebContents* web_contents,
516 const gfx::Size& pref_size) {}
518 // Invoked when the contents auto-resized and the container should match it.
519 virtual void ResizeDueToAutoResize(WebContents* web_contents,
520 const gfx::Size& new_size) {}
522 // Requests to lock the mouse. Once the request is approved or rejected,
523 // GotResponseToLockMouseRequest() will be called on the requesting tab
525 virtual void RequestToLockMouse(WebContents* web_contents,
527 bool last_unlocked_by_target) {}
529 // Notification that the page has lost the mouse lock.
530 virtual void LostMouseLock() {}
532 // Requests keyboard lock. Once the request is approved or rejected,
533 // GotResponseToKeyboardLockRequest() will be called on |web_contents|.
534 virtual void RequestKeyboardLock(WebContents* web_contents,
535 bool esc_key_locked) {}
537 // Notification that the keyboard lock request has been canceled.
538 virtual void CancelKeyboardLockRequest(WebContents* web_contents) {}
540 // Asks permission to use the camera and/or microphone. If permission is
541 // granted, a call should be made to |callback| with the devices. If the
542 // request is denied, a call should be made to |callback| with an empty list
543 // of devices. |request| has the details of the request (e.g. which of audio
544 // and/or video devices are requested, and lists of available devices).
545 virtual void RequestMediaAccessPermission(
546 WebContents* web_contents,
547 const MediaStreamRequest& request,
548 content::MediaResponseCallback callback);
550 // Checks if we have permission to access the microphone or camera. Note that
551 // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
552 // or MEDIA_DEVICE_VIDEO_CAPTURE.
553 virtual bool CheckMediaAccessPermission(RenderFrameHost* render_frame_host,
554 const GURL& security_origin,
555 blink::mojom::MediaStreamType type);
557 // Returns the ID of the default device for the given media device |type|.
558 // If the returned value is an empty string, it means that there is no
559 // default device for the given |type|.
560 virtual std::string GetDefaultMediaDeviceID(
561 WebContents* web_contents,
562 blink::mojom::MediaStreamType type);
564 #if defined(OS_ANDROID)
565 // Returns true if the given media should be blocked to load.
566 virtual bool ShouldBlockMediaRequest(const GURL& url);
568 // Tells the delegate to enter overlay mode.
569 // Overlay mode means that we are currently using AndroidOverlays to display
570 // video, and that the compositor's surface should support alpha and not be
571 // marked as opaque. See media/base/android/android_overlay.h.
572 virtual void SetOverlayMode(bool use_overlay_mode) {}
575 // Requests permission to access the PPAPI broker. The delegate must either
576 // call the passed in |callback| with the result, or call it with false
577 // to indicate that it does not support asking for permission.
578 virtual void RequestPpapiBrokerPermission(
579 WebContents* web_contents,
581 const base::FilePath& plugin_path,
582 base::OnceCallback<void(bool)> callback);
584 // Returns the size for the new render view created for the pending entry in
585 // |web_contents|; if there's no size, returns an empty size.
586 // This is optional for implementations of WebContentsDelegate; if the
587 // delegate doesn't provide a size, the current WebContentsView's size will be
589 virtual gfx::Size GetSizeForNewRenderView(WebContents* web_contents);
591 // Returns true if the WebContents is never user-visible, thus the renderer
592 // never needs to produce pixels for display.
593 virtual bool IsNeverComposited(WebContents* web_contents);
595 // Askss |guest_web_contents| to perform the same. If this returns true, the
596 // default behavior is suppressed.
597 virtual bool GuestSaveFrame(WebContents* guest_web_contents);
599 // Called in response to a request to save a frame. If this returns true, the
600 // default behavior is suppressed.
601 virtual bool SaveFrame(const GURL& url, const Referrer& referrer);
603 // Can be overridden by a delegate to return the security style of the
604 // given |web_contents|, populating |security_style_explanations| to
605 // explain why the SecurityStyle was downgraded. Returns
606 // SecurityStyleUnknown if not overriden.
607 virtual blink::SecurityStyle GetSecurityStyle(
608 WebContents* web_contents,
609 SecurityStyleExplanations* security_style_explanations);
611 // Called when a suspicious navigation of the main frame has been blocked.
612 // Allows the delegate to provide some UI to let the user know about the
613 // blocked navigation and give them the option to recover from it.
614 // |blocked_url| is the blocked navigation target, |initiator_url| is the URL
615 // of the frame initiating the navigation, |reason| specifies why the
616 // navigation was blocked.
617 virtual void OnDidBlockNavigation(
618 WebContents* web_contents,
619 const GURL& blocked_url,
620 const GURL& initiator_url,
621 blink::mojom::NavigationBlockedReason reason) {}
623 // Reports that passive mixed content was found at the specified url.
624 virtual void PassiveInsecureContentFound(const GURL& resource_url) {}
626 // Checks if running of active mixed content is allowed for the specified
628 virtual bool ShouldAllowRunningInsecureContent(WebContents* web_contents,
629 bool allowed_per_prefs,
630 const url::Origin& origin,
631 const GURL& resource_url);
633 virtual void SetTopControlsShownRatio(WebContents* web_contents,
636 // Requests to get browser controls info such as the height/min height of the
637 // top/bottom controls, and whether to animate these changes to height or
638 // whether they will shrink the Blink's view size. Note that they are not
639 // complete in the sense that there is no API to tell content to poll these
640 // values again, except part of resize. But this is not needed by embedder
641 // because it's always accompanied by view size change.
642 virtual int GetTopControlsHeight();
643 virtual int GetTopControlsMinHeight();
644 virtual int GetBottomControlsHeight();
645 virtual int GetBottomControlsMinHeight();
646 virtual bool ShouldAnimateBrowserControlsHeightChanges();
647 virtual bool DoBrowserControlsShrinkRendererSize(
648 const WebContents* web_contents);
650 // Propagates to the browser that gesture scrolling has changed state. This is
651 // used by the browser to assist in controlling the behavior of sliding the
652 // top controls as a result of page gesture scrolling while in tablet mode.
653 virtual void SetTopControlsGestureScrollInProgress(bool in_progress) {}
655 // Give WebContentsDelegates the opportunity to adjust the previews state.
656 virtual void AdjustPreviewsStateForNavigation(WebContents* web_contents,
657 PreviewsState* previews_state) {
660 // Requests to print an out-of-process subframe for the specified WebContents.
661 // |rect| is the rectangular area where its content resides in its parent
662 // frame. |document_cookie| is a unique id for a printed document associated
665 // |subframe_host| is the render frame host of the subframe to be printed.
666 virtual void PrintCrossProcessSubframe(WebContents* web_contents,
667 const gfx::Rect& rect,
669 RenderFrameHost* subframe_host) const {
672 // Requests to capture a paint preview of an out-of-process subframe for the
673 // specified WebContents. |rect| is the rectangular area where its content
674 // resides in its parent frame. |guid| is a globally unique identitier for an
675 // entire paint preview. |render_frame_host| is the render frame host of the
676 // subframe to be captured.
677 virtual void CapturePaintPreviewOfCrossProcessSubframe(
678 WebContents* web_contents,
679 const gfx::Rect& rect,
680 const base::UnguessableToken& guid,
681 RenderFrameHost* render_frame_host) {}
683 // Notifies the Picture-in-Picture controller that there is a new player
684 // entering Picture-in-Picture.
685 // Returns the result of the enter request.
686 virtual PictureInPictureResult EnterPictureInPicture(
687 WebContents* web_contents,
688 const viz::SurfaceId&,
689 const gfx::Size& natural_size);
691 // Updates the Picture-in-Picture controller with a signal that
692 // Picture-in-Picture mode has ended.
693 virtual void ExitPictureInPicture() {}
695 #if defined(OS_ANDROID)
696 // Updates information to determine whether a user gesture should carryover to
697 // future navigations. This is needed so navigations within a certain
698 // timeframe of a request initiated by a gesture will be treated as if they
699 // were initiated by a gesture too, otherwise the navigation may be blocked.
700 virtual void UpdateUserGestureCarryoverInfo(WebContents* web_contents) {}
703 // Returns true if lazy loading of images and frames should be enabled.
704 virtual bool ShouldAllowLazyLoad();
706 // Requests the delegate to replace |predecessor_contents| with
707 // |portal_contents| in the container that holds |predecessor_contents|. If
708 // the delegate successfully replaces |predecessor_contents|, the return
709 // parameter passes ownership of |predecessor_contents|. Otherwise,
710 // |portal_contents| is returned.
711 virtual std::unique_ptr<WebContents> ActivatePortalWebContents(
712 WebContents* predecessor_contents,
713 std::unique_ptr<WebContents> portal_contents);
715 // Returns true if the widget's frame content needs to be stored before
716 // eviction and displayed until a new frame is generated. If false, a white
717 // solid color is displayed instead.
718 virtual bool ShouldShowStaleContentOnEviction(WebContents* source);
720 // Determine if the frame is of a low priority.
721 virtual bool IsFrameLowPriority(const WebContents* web_contents,
722 const RenderFrameHost* render_frame_host);
724 // Returns the user-visible WebContents that is responsible for the activity
725 // in the provided WebContents. For example, this delegate may be aware that
726 // the contents is embedded in some other contents, or hosts background
727 // activity on behalf of a user-visible tab which should be used to display
728 // dialogs and similar affordances to the user.
730 // This may be distinct from the outer web contents (for example, the
731 // responsible contents may logically "own" a contents but not currently embed
732 // it for rendering).
734 // For most delegates (where the WebContents is a tab, window or other
735 // directly user-visible feature), simply returning the contents is
737 virtual WebContents* GetResponsibleWebContents(WebContents* web_contents);
739 // Invoked when media playback is interrupted or completed.
740 virtual void MediaWatchTimeChanged(const MediaPlayerWatchTime& watch_time) {}
742 // Returns a InstalledWebappGeolocationContext if this web content is running
743 // in a installed webapp and geolocation should be deleagted from the
744 // installed webapp; otherwise returns nullptr.
745 virtual device::mojom::GeolocationContext*
746 GetInstalledWebappGeolocationContext();
748 // Returns a weak ptr to the web contents delegate.
749 virtual base::WeakPtr<WebContentsDelegate> GetDelegateWeakPtr();
752 virtual ~WebContentsDelegate();
755 friend class WebContentsImpl;
757 // Called when |this| becomes the WebContentsDelegate for |source|.
758 void Attach(WebContents* source);
760 // Called when |this| is no longer the WebContentsDelegate for |source|.
761 void Detach(WebContents* source);
763 // The WebContents that this is currently a delegate for.
764 std::set<WebContents*> attached_contents_;
767 } // namespace content
769 #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_