1 // Copyright 2012 The Chromium Authors
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/functional/callback.h"
16 #include "base/memory/scoped_refptr.h"
17 #include "build/build_config.h"
18 #include "content/common/content_export.h"
19 #include "content/public/browser/eye_dropper.h"
20 #include "content/public/browser/fullscreen_types.h"
21 #include "content/public/browser/invalidate_type.h"
22 #include "content/public/browser/media_stream_request.h"
23 #include "content/public/browser/serial_chooser.h"
24 #include "content/public/browser/web_contents.h"
25 #include "content/public/common/window_container_type.mojom-forward.h"
26 #include "third_party/blink/public/common/mediastream/media_stream_request.h"
27 #include "third_party/blink/public/common/page/drag_operation.h"
28 #include "third_party/blink/public/mojom/choosers/color_chooser.mojom-forward.h"
29 #include "third_party/blink/public/mojom/frame/blocked_navigation_types.mojom.h"
30 #include "third_party/blink/public/mojom/frame/fullscreen.mojom-forward.h"
31 #include "third_party/blink/public/mojom/manifest/display_mode.mojom.h"
32 #include "third_party/skia/include/core/SkColor.h"
33 #include "ui/base/window_open_disposition.h"
34 #include "ui/gfx/geometry/rect_f.h"
35 #include "ui/gfx/native_widget_types.h"
37 #if BUILDFLAG(IS_ANDROID)
38 #include "base/android/scoped_java_ref.h"
51 class FileChooserParams;
58 class EyeDropperListener;
59 class FileSelectListener;
60 class JavaScriptDialogManager;
61 class RenderFrameHost;
62 class RenderWidgetHost;
63 class SessionStorageNamespace;
65 struct ContextMenuParams;
67 struct MediaPlayerWatchTime;
68 struct NativeWebKeyboardEvent;
70 } // namespace content
74 class GeolocationContext;
88 class WebGestureEvent;
89 enum class ProtocolHandlerSecurityLevel;
94 class AudioStreamBrokerFactory;
97 enum class KeyboardEventProcessingResult;
99 // Result of an EnterPictureInPicture request.
100 enum class PictureInPictureResult {
101 // The request was successful.
104 // Picture-in-Picture is not supported by the embedder.
108 // Objects implement this interface to get notified about changes in the
109 // WebContents and to provide necessary functionality. If a method doesn't
110 // change state, e.g. has no return value, then it can move to
111 // WebContentsObserver if many places want to observe the change. If the
112 // implementation of one of the methods below would be shared by many or all of
113 // WebContentsDelegate implementations then it can go on ContentBrowserClient.
114 class CONTENT_EXPORT WebContentsDelegate {
116 WebContentsDelegate();
118 // Opens a new URL inside the passed in WebContents (if source is 0 open
119 // in the current front-most tab), unless |disposition| indicates the url
120 // should be opened in a new tab or window.
122 // A nullptr source indicates the current tab (callers should probably use
123 // OpenURL() for these cases which does it for you).
125 // Returns the WebContents the URL is opened in, or nullptr if the URL wasn't
126 // opened immediately.
127 virtual WebContents* OpenURLFromTab(WebContents* source,
128 const OpenURLParams& params);
130 // Allows the delegate to optionally cancel navigations that attempt to
131 // transfer to a different process between the start of the network load and
132 // commit. Defaults to true.
133 virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation(
134 bool is_outermost_main_frame_navigation);
136 // Called to inform the delegate that the WebContents's navigation state
137 // changed. The |changed_flags| indicates the parts of the navigation state
138 // that have been updated.
139 virtual void NavigationStateChanged(WebContents* source,
140 InvalidateTypes changed_flags) {}
142 // Called to inform the delegate that the WebContent's visible
143 // security state changed and that security UI should be updated.
144 virtual void VisibleSecurityStateChanged(WebContents* source) {}
146 // Creates a new tab with the already-created WebContents `new_contents`.
147 // The window for the added contents should be reparented correctly when this
148 // method returns. `target_url` is set to the value provided when
149 // `new_contents` was created. If `disposition` is NEW_POPUP,
150 // `window_features` should hold the initial position, size and other
151 // properties of the window. If `was_blocked` is non-nullptr, then
152 // `*was_blocked` will be set to true if the popup gets blocked, and left
153 // unchanged otherwise.
154 virtual void AddNewContents(
156 std::unique_ptr<WebContents> new_contents,
157 const GURL& target_url,
158 WindowOpenDisposition disposition,
159 const blink::mojom::WindowFeatures& window_features,
161 bool* was_blocked) {}
163 // Selects the specified contents, bringing its container to the front.
164 virtual void ActivateContents(WebContents* contents) {}
166 // Notifies the delegate that this contents is starting or is done loading
167 // some resource. The delegate should use this notification to represent
168 // loading feedback. See WebContents::IsLoading()
169 // |should_show_loading_ui| indicates whether a load start should be visible
170 // in UI elements. It is generally true for different-document navigations and
171 // false for most same-document navigations (because same-documents are
172 // typically instantaneous so there's no point in flickering the UI). The
173 // exception is the navigation API's intercept(), which is the sole type
174 // of same-document navigation that is asynchronous, and therefore a UI change
176 virtual void LoadingStateChanged(WebContents* source,
177 bool should_show_loading_ui) {}
179 // Request the delegate to close this web contents, and do whatever cleanup
181 virtual void CloseContents(WebContents* source) {}
183 // Request the delegate to resize this WebContents to the specified size in
184 // screen coordinates. The embedder is free to ignore the request.
185 virtual void SetContentsBounds(WebContents* source, const gfx::Rect& bounds) {
188 // Notification that the target URL has changed.
189 virtual void UpdateTargetURL(WebContents* source,
192 // Notification that there was a mouse event, along with the type of event.
193 // If |motion| is true, this is a normal motion event. If |exited| is true,
194 // the pointer left the contents area.
195 virtual void ContentsMouseEvent(WebContents* source,
199 // Request the delegate to change the zoom level of the current tab.
200 virtual void ContentsZoomChange(bool zoom_in) {}
202 // Called to determine if the WebContents can be overscrolled with touch/wheel
204 virtual bool CanOverscrollContent();
206 // Returns true if javascript dialogs and unload alerts are suppressed.
208 virtual bool ShouldSuppressDialogs(WebContents* source);
210 // Returns whether pending NavigationEntries for aborted browser-initiated
211 // navigations should be preserved (and thus returned from GetVisibleURL).
212 // Defaults to false.
213 virtual bool ShouldPreserveAbortedURLs(WebContents* source);
215 // A message was added to the console of a frame of the page. Returning true
216 // indicates that the delegate handled the message. If false is returned the
217 // default logging mechanism will be used for the message.
218 // NOTE: If you only need to monitor messages added to the console, rather
219 // than change the behavior when they are added, prefer using
220 // WebContentsObserver::OnDidAddMessageToConsole().
221 virtual bool DidAddMessageToConsole(
223 blink::mojom::ConsoleMessageLevel log_level,
224 const std::u16string& message,
226 const std::u16string& source_id);
228 // Tells us that we've finished firing this tab's beforeunload event.
229 // The proceed bool tells us whether the user chose to proceed closing the
230 // tab. Returns true if the tab can continue on firing its unload event.
231 // If we're closing the entire browser, then we'll want to delay firing
232 // unload events until all the beforeunload events have fired.
233 virtual void BeforeUnloadFired(WebContents* tab,
235 bool* proceed_to_fire_unload);
237 // Returns true if the location bar should be focused by default rather than
238 // the page contents. NOTE: this is only used if WebContents can't determine
239 // for itself whether the location bar should be focused by default. For a
240 // complete check, you should use WebContents::FocusLocationBarByDefault().
241 virtual bool ShouldFocusLocationBarByDefault(WebContents* source);
243 // Sets focus to the location bar or some other place that is appropriate.
244 // This is called when the tab wants to encourage user input, like for the
246 virtual void SetFocusToLocationBar() {}
248 // Returns whether the page should be focused when transitioning from crashed
249 // to live. Default is true.
250 virtual bool ShouldFocusPageAfterCrash();
252 // Returns whether the page should resume accepting requests for the new
253 // window. This is used when window creation is asynchronous
254 // and the navigations need to be delayed. Default is true.
255 virtual bool ShouldResumeRequestsForCreatedWindow();
257 // This is called when WebKit tells us that it is done tabbing through
258 // controls on the page. Provides a way for WebContentsDelegates to handle
259 // this. Returns true if the delegate successfully handled it.
260 virtual bool TakeFocus(WebContents* source,
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 // Asks the delegate to open/show the context menu based on `params`.
271 // The `render_frame_host` represents the frame that requests the context menu
272 // (typically this frame is focused, but this is not necessarily the case -
273 // see https://crbug.com/1257907#c14).
275 // Returns true if the context menu operation was handled by the delegate.
276 virtual bool HandleContextMenu(RenderFrameHost& render_frame_host,
277 const ContextMenuParams& params);
279 // Allows delegates to handle keyboard events before sending to the renderer.
280 // See enum for description of return values.
281 virtual KeyboardEventProcessingResult PreHandleKeyboardEvent(
283 const NativeWebKeyboardEvent& event);
285 // Allows delegates to handle unhandled keyboard messages coming back from
286 // the renderer. Returns true if the event was handled, false otherwise. A
287 // true value means no more processing should happen on the event. The default
288 // return value is false
289 virtual bool HandleKeyboardEvent(WebContents* source,
290 const NativeWebKeyboardEvent& event);
292 // Allows delegates to handle gesture events before sending to the renderer.
293 // Returns true if the |event| was handled and thus shouldn't be processed
294 // by the renderer's event handler. Note that the touch events that create
295 // the gesture are always passed to the renderer since the gesture is created
296 // and dispatched after the touches return without being "preventDefault()"ed.
297 virtual bool PreHandleGestureEvent(
299 const blink::WebGestureEvent& event);
301 // Called when an external drag event enters the web contents window. Return
302 // true to allow dragging and dropping on the web contents window or false to
303 // cancel the operation. This method is used by Chromium Embedded Framework.
304 virtual bool CanDragEnter(WebContents* source,
305 const DropData& data,
306 blink::DragOperationsMask operations_allowed);
308 // Shows the repost form confirmation dialog box.
309 virtual void ShowRepostFormWarningDialog(WebContents* source) {}
311 // Allows delegate to override navigation to the history entries.
312 // Returns true to allow WebContents to continue with the default processing.
313 virtual bool OnGoToEntryOffset(int offset);
315 // Allows delegate to control whether a new WebContents can be created by
316 // the WebContents itself.
318 // If an delegate returns true, it can optionally also override
319 // CreateCustomWebContents() below to provide their own WebContents.
320 virtual bool IsWebContentsCreationOverridden(
321 SiteInstance* source_site_instance,
322 mojom::WindowContainerType window_container_type,
323 const GURL& opener_url,
324 const std::string& frame_name,
325 const GURL& target_url);
327 // Allow delegate to creates a custom WebContents when
328 // WebContents::CreateNewWindow() is called. This function is only called
329 // when IsWebContentsCreationOverridden() returns true.
331 // In general, a delegate should return a pointer to a created WebContents
332 // so that the opener can be given a references to it as appropriate.
333 // Returning nullptr also makes sense if the delegate wishes to suppress
334 // all window creation, or if the delegate wants to ensure the opener
335 // cannot get a reference effectively creating a new browsing instance.
336 virtual WebContents* CreateCustomWebContents(
337 RenderFrameHost* opener,
338 SiteInstance* source_site_instance,
339 bool is_new_browsing_instance,
340 const GURL& opener_url,
341 const std::string& frame_name,
342 const GURL& target_url,
343 const StoragePartitionConfig& partition_config,
344 SessionStorageNamespace* session_storage_namespace);
346 // Notifies the delegate about the creation of a new WebContents. This
347 // typically happens when popups are created.
348 virtual void WebContentsCreated(WebContents* source_contents,
349 int opener_render_process_id,
350 int opener_render_frame_id,
351 const std::string& frame_name,
352 const GURL& target_url,
353 WebContents* new_contents) {}
355 // Notifies the embedder that a new WebContents has been created to contain
356 // the contents of a portal.
357 virtual void PortalWebContentsCreated(WebContents* portal_web_contents) {}
359 // Notifies the embedder that an existing WebContents that it manages (e.g., a
360 // browser tab) has become the contents of a portal.
362 // During portal activation, WebContentsDelegate::ActivatePortalWebContents
363 // will be called to release the delegate's management of a WebContents.
364 // Shortly afterward, the portal will assume ownership of the contents and
365 // call this function to indicate that this is complete, passing the
366 // swapped-out contents as |portal_web_contents|.
368 // Implementations will likely want to apply changes analogous to those they
369 // would apply to a new WebContents in PortalWebContentsCreated.
370 virtual void WebContentsBecamePortal(WebContents* portal_web_contents) {}
372 // Notification that one of the frames in the WebContents is hung. |source| is
373 // the WebContents that is hung, and |render_widget_host| is the
374 // RenderWidgetHost that, while routing events to it, discovered the hang.
376 // |hang_monitor_restarter| can be used to restart the timer used to
377 // detect the hang. The timer is typically restarted when the renderer has
378 // become active, the tab got hidden, or the user has chosen to wait some
381 // Useful member functions on |render_widget_host|:
382 // - Getting the hung render process: GetProcess()
383 // - Querying whether the process is still hung: IsCurrentlyUnresponsive()
384 virtual void RendererUnresponsive(
386 RenderWidgetHost* render_widget_host,
387 base::RepeatingClosure hang_monitor_restarter) {}
389 // Notification that a process in the WebContents is no longer hung. |source|
390 // is the WebContents that was hung, and |render_widget_host| is the
391 // RenderWidgetHost that was passed in an earlier call to
392 // RendererUnresponsive().
393 virtual void RendererResponsive(WebContents* source,
394 RenderWidgetHost* render_widget_host) {}
396 #if BUILDFLAG(IS_TIZEN_TV)
397 //Browser edge scroll
398 virtual void DidEdgeScrollBy(const gfx::Point& offset, bool handled) {}
401 // Returns a pointer to a service to manage JavaScript dialogs. May return
402 // nullptr in which case dialogs aren't shown.
403 virtual JavaScriptDialogManager* GetJavaScriptDialogManager(
404 WebContents* source);
406 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC) || BUILDFLAG(IS_EFL)
407 // Called when color chooser should open. Returns the opened color chooser.
408 // Returns nullptr if we failed to open the color chooser. The color chooser
409 // is only supported/required for Android.
410 virtual std::unique_ptr<ColorChooser> OpenColorChooser(
411 WebContents* web_contents,
413 const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions);
414 #endif // BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_MAC)
416 // Called when an eye dropper should open. Returns the eye dropper window.
417 // The eye dropper is responsible for calling listener->ColorSelected() or
418 // listener->ColorSelectionCanceled().
419 // The ownership of the returned pointer is transferred to the caller.
420 virtual std::unique_ptr<EyeDropper> OpenEyeDropper(
421 RenderFrameHost* frame,
422 EyeDropperListener* listener);
424 // Called when a file selection is to be done.
425 // This function is responsible for calling listener->FileSelected() or
426 // listener->FileSelectionCanceled().
427 virtual void RunFileChooser(RenderFrameHost* render_frame_host,
428 scoped_refptr<FileSelectListener> listener,
429 const blink::mojom::FileChooserParams& params);
431 // Request to enumerate a directory. This is equivalent to running the file
432 // chooser in directory-enumeration mode and having the user select the given
434 // This function is responsible for calling listener->FileSelected() or
435 // listener->FileSelectionCanceled().
436 virtual void EnumerateDirectory(WebContents* web_contents,
437 scoped_refptr<FileSelectListener> listener,
438 const base::FilePath& path);
440 // Creates an info bar for the user to control the receiving of the SMS.
441 virtual void CreateSmsPrompt(RenderFrameHost*,
442 const std::vector<url::Origin>&,
443 const std::string& one_time_code,
444 base::OnceCallback<void()> on_confirm,
445 base::OnceCallback<void()> on_cancel);
447 // Returns whether entering fullscreen with |EnterFullscreenModeForTab()| is
449 virtual bool CanEnterFullscreenModeForTab(
450 RenderFrameHost* requesting_frame,
451 const blink::mojom::FullscreenOptions& options);
453 // Called when the renderer puts a tab into fullscreen mode.
454 // |requesting_frame| is the specific content frame requesting fullscreen.
455 // |CanEnterFullscreenModeForTab()| must return true on entry.
456 virtual void EnterFullscreenModeForTab(
457 RenderFrameHost* requesting_frame,
458 const blink::mojom::FullscreenOptions& options) {}
460 virtual void FullscreenStateChangedForTab(
461 RenderFrameHost* requesting_frame,
462 const blink::mojom::FullscreenOptions& options) {}
464 // Called when the renderer puts a tab out of fullscreen mode.
465 virtual void ExitFullscreenModeForTab(WebContents*) {}
467 // Returns true if `web_contents` is, or is transitioning to, tab-fullscreen.
468 virtual bool IsFullscreenForTabOrPending(const WebContents* web_contents);
470 // Returns fullscreen state information about the given `web_contents`.
471 virtual FullscreenState GetFullscreenState(
472 const WebContents* web_contents) const;
474 // Returns the actual display mode of the top-level browsing context.
475 // For example, it should return 'blink::mojom::DisplayModeFullscreen'
476 // whenever the browser window is put to fullscreen mode (either by the end
477 // user, or HTML API or from a web manifest setting). See
478 // http://w3c.github.io/manifest/#dfn-display-mode
479 virtual blink::mojom::DisplayMode GetDisplayMode(
480 const WebContents* web_contents);
482 // Returns the security level to use for Navigator.RegisterProtocolHandler().
483 virtual blink::ProtocolHandlerSecurityLevel GetProtocolHandlerSecurityLevel(
484 RenderFrameHost* requesting_frame);
486 // Register a new handler for URL requests with the given scheme.
487 // |user_gesture| is true if the registration is made in the context of a user
489 virtual void RegisterProtocolHandler(RenderFrameHost* requesting_frame,
490 const std::string& protocol,
492 bool user_gesture) {}
494 // Unregister the registered handler for URL requests with the given scheme.
495 // |user_gesture| is true if the registration is made in the context of a user
497 virtual void UnregisterProtocolHandler(RenderFrameHost* requesting_frame,
498 const std::string& protocol,
500 bool user_gesture) {}
502 // Result of string search in the page. This includes the number of matches
503 // found and the selection rect (in screen coordinates) for the string found.
504 // If |final_update| is false, it indicates that more results follow.
505 virtual void FindReply(WebContents* web_contents,
507 int number_of_matches,
508 const gfx::Rect& selection_rect,
509 int active_match_ordinal,
510 bool final_update) {}
512 #if defined(TIZEN_TBM_SUPPORT)
513 virtual void DidRenderOffscreenFrame(void* buffer) {}
516 #if BUILDFLAG(IS_EFL)
517 virtual void DidChangeInputType(bool is_password_field) {}
518 virtual void DidRenderFrame() {}
519 virtual void BackgroundColorReceived(int callback_id, SkColor bg_color) {}
520 virtual void OnDidChangeFocusedNodeBounds(
521 const gfx::RectF& focused_node_bounds) {}
522 virtual void OnGetMainFrameScrollbarVisible(int callback_id, bool visible) {}
525 #if BUILDFLAG(IS_ANDROID)
526 // Provides the rects of the current find-in-page matches.
527 // Sent as a reply to RequestFindMatchRects.
528 virtual void FindMatchRectsReply(WebContents* web_contents,
530 const std::vector<gfx::RectF>& rects,
531 const gfx::RectF& active_rect) {}
534 // Invoked when the preferred size of the contents has been changed.
535 virtual void UpdatePreferredSize(WebContents* web_contents,
536 const gfx::Size& pref_size) {}
538 // Invoked when the contents auto-resized and the container should match it.
539 virtual void ResizeDueToAutoResize(WebContents* web_contents,
540 const gfx::Size& new_size) {}
542 // Requests to lock the mouse. Once the request is approved or rejected,
543 // GotResponseToLockMouseRequest() will be called on the requesting tab
545 virtual void RequestToLockMouse(WebContents* web_contents,
547 bool last_unlocked_by_target);
549 // Notification that the page has lost the mouse lock.
550 virtual void LostMouseLock() {}
552 // Requests keyboard lock. Once the request is approved or rejected,
553 // GotResponseToKeyboardLockRequest() will be called on |web_contents|.
554 virtual void RequestKeyboardLock(WebContents* web_contents,
555 bool esc_key_locked);
557 // Notification that the keyboard lock request has been canceled.
558 virtual void CancelKeyboardLockRequest(WebContents* web_contents) {}
560 // Asks permission to use the camera and/or microphone. If permission is
561 // granted, a call should be made to |callback| with the devices. If the
562 // request is denied, a call should be made to |callback| with an empty list
563 // of devices. |request| has the details of the request (e.g. which of audio
564 // and/or video devices are requested, and lists of available devices).
565 virtual void RequestMediaAccessPermission(WebContents* web_contents,
566 const MediaStreamRequest& request,
567 MediaResponseCallback callback);
569 // Checks if we have permission to access the microphone or camera. Note that
570 // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
571 // or MEDIA_DEVICE_VIDEO_CAPTURE.
572 virtual bool CheckMediaAccessPermission(RenderFrameHost* render_frame_host,
573 const GURL& security_origin,
574 blink::mojom::MediaStreamType type);
576 // Returns the ID of the default device for the given media device |type|.
577 // If the returned value is an empty string, it means that there is no
578 // default device for the given |type|.
579 virtual std::string GetDefaultMediaDeviceID(
580 WebContents* web_contents,
581 blink::mojom::MediaStreamType type);
583 // Returns the human-readable name for title in Media Controls.
584 // If the returned value is an empty string, it means that there is no
585 // human-readable name.
586 // For example, this returns an extension name for title instead of extension
588 virtual std::string GetTitleForMediaControls(WebContents* web_contents);
590 // Returns AudioStreamBrokerFactory to use to create AudioStreamBroker when
591 // creating audio I/O streams. Returned `AudioStreamBrokerFactory` is used and
592 // deleted on the IO thread.
593 virtual std::unique_ptr<AudioStreamBrokerFactory>
594 CreateAudioStreamBrokerFactory(WebContents* web_contents);
596 #if BUILDFLAG(IS_ANDROID)
597 // Returns true if the given media should be blocked to load.
598 virtual bool ShouldBlockMediaRequest(const GURL& url);
600 // Tells the delegate to enter overlay mode.
601 // Overlay mode means that we are currently using AndroidOverlays to display
602 // video, and that the compositor's surface should support alpha and not be
603 // marked as opaque. See media/base/android/android_overlay.h.
604 virtual void SetOverlayMode(bool use_overlay_mode) {}
607 // Returns the size for the new render view created for the pending entry in
608 // |web_contents|; if there's no size, returns an empty size.
609 // This is optional for implementations of WebContentsDelegate; if the
610 // delegate doesn't provide a size, the current WebContentsView's size will be
612 virtual gfx::Size GetSizeForNewRenderView(WebContents* web_contents);
614 // Returns true if the WebContents is never user-visible, thus the renderer
615 // never needs to produce pixels for display.
616 virtual bool IsNeverComposited(WebContents* web_contents);
618 // Askss |guest_web_contents| to perform the same. If this returns true, the
619 // default behavior is suppressed.
620 virtual bool GuestSaveFrame(WebContents* guest_web_contents);
622 // Called in response to a request to save a frame. If this returns true, the
623 // default behavior is suppressed.
624 virtual bool SaveFrame(const GURL& url,
625 const Referrer& referrer,
626 RenderFrameHost* rfh);
628 // Called when a suspicious navigation of the main frame has been blocked.
629 // Allows the delegate to provide some UI to let the user know about the
630 // blocked navigation and give them the option to recover from it.
631 // |blocked_url| is the blocked navigation target, |initiator_url| is the URL
632 // of the frame initiating the navigation, |reason| specifies why the
633 // navigation was blocked.
634 virtual void OnDidBlockNavigation(
635 WebContents* web_contents,
636 const GURL& blocked_url,
637 const GURL& initiator_url,
638 blink::mojom::NavigationBlockedReason reason) {}
640 // Reports that passive mixed content was found at the specified url.
641 virtual void PassiveInsecureContentFound(const GURL& resource_url) {}
643 // Checks if running of active mixed content is allowed for the specified
645 virtual bool ShouldAllowRunningInsecureContent(WebContents* web_contents,
646 bool allowed_per_prefs,
647 const url::Origin& origin,
648 const GURL& resource_url);
650 virtual void SetTopControlsShownRatio(WebContents* web_contents,
653 // Requests to get browser controls info such as the height/min height of the
654 // top/bottom controls, and whether to animate these changes to height or
655 // whether they will shrink the Blink's view size. Note that they are not
656 // complete in the sense that there is no API to tell content to poll these
657 // values again, except part of resize. But this is not needed by embedder
658 // because it's always accompanied by view size change.
659 virtual int GetTopControlsHeight();
660 virtual int GetTopControlsMinHeight();
661 virtual int GetBottomControlsHeight();
662 virtual int GetBottomControlsMinHeight();
663 virtual bool ShouldAnimateBrowserControlsHeightChanges();
664 virtual bool DoBrowserControlsShrinkRendererSize(WebContents* web_contents);
665 virtual int GetVirtualKeyboardHeight(WebContents* web_contents);
666 // Returns true if the top controls should only expand at the top of the page,
667 // so they'll only be visible if the page is scrolled to the top.
668 virtual bool OnlyExpandTopControlsAtPageTop();
670 // Propagates to the browser that gesture scrolling has changed state. This is
671 // used by the browser to assist in controlling the behavior of sliding the
672 // top controls as a result of page gesture scrolling while in tablet mode.
673 virtual void SetTopControlsGestureScrollInProgress(bool in_progress) {}
675 // Requests to print an out-of-process subframe for the specified WebContents.
676 // |rect| is the rectangular area where its content resides in its parent
677 // frame. |document_cookie| is a unique id for a printed document associated
678 // with a print job. |subframe_host| is the RenderFrameHost of the subframe
680 virtual void PrintCrossProcessSubframe(WebContents* web_contents,
681 const gfx::Rect& rect,
683 RenderFrameHost* subframe_host) const {
686 // Requests to capture a paint preview of a subframe for the specified
687 // WebContents. |rect| is the rectangular area where its content resides in
688 // its parent frame. |guid| is a globally unique identitier for an entire
689 // paint preview. |render_frame_host| is the RenderFrameHost of the subframe
691 virtual void CapturePaintPreviewOfSubframe(
692 WebContents* web_contents,
693 const gfx::Rect& rect,
694 const base::UnguessableToken& guid,
695 RenderFrameHost* render_frame_host) {}
697 // Notifies the Picture-in-Picture controller that there is a new player
698 // entering Picture-in-Picture.
699 // Returns the result of the enter request.
700 virtual PictureInPictureResult EnterPictureInPicture(
701 WebContents* web_contents);
703 // Updates the Picture-in-Picture controller with a signal that
704 // Picture-in-Picture mode has ended.
705 virtual void ExitPictureInPicture() {}
707 #if BUILDFLAG(IS_ANDROID)
708 // Updates information to determine whether a user gesture should carryover to
709 // future navigations. This is needed so navigations within a certain
710 // timeframe of a request initiated by a gesture will be treated as if they
711 // were initiated by a gesture too, otherwise the navigation may be blocked.
712 virtual void UpdateUserGestureCarryoverInfo(WebContents* web_contents) {}
715 // Returns true if lazy loading of images and frames should be enabled.
716 virtual bool ShouldAllowLazyLoad();
718 // Return true if the back forward cache is supported. This is not an
719 // indication that the cache will be used.
720 virtual bool IsBackForwardCacheSupported();
722 // Returns PreloadingEligibility::kEligible if Prerender2 (see
723 // content/browser/preloading/prerender/README.md for details) is supported.
724 // If it is not supported, returns the reason.
725 virtual PreloadingEligibility IsPrerender2Supported(
726 WebContents& web_contents);
728 // Requests the delegate to replace |predecessor_contents| with
729 // |portal_contents| in the container that holds |predecessor_contents|. If
730 // the delegate successfully replaces |predecessor_contents|, the return
731 // parameter passes ownership of |predecessor_contents|. Otherwise,
732 // |portal_contents| is returned.
733 virtual std::unique_ptr<WebContents> ActivatePortalWebContents(
734 WebContents* predecessor_contents,
735 std::unique_ptr<WebContents> portal_contents);
737 // If |old_contents| is being inspected by a DevTools window, it updates the
738 // window to inspect |new_contents| instead and calls |callback| after it
739 // finishes asynchronously. If no window is present, or no update is
740 // necessary, |callback| is run synchronously (immediately on the same stack).
741 virtual void UpdateInspectedWebContentsIfNecessary(
742 WebContents* old_contents,
743 WebContents* new_contents,
744 base::OnceCallback<void()> callback);
746 // Returns true if the widget's frame content needs to be stored before
747 // eviction and displayed until a new frame is generated. If false, a white
748 // solid color is displayed instead.
749 virtual bool ShouldShowStaleContentOnEviction(WebContents* source);
751 // Invoked when media playback is interrupted or completed.
752 virtual void MediaWatchTimeChanged(const MediaPlayerWatchTime& watch_time) {}
754 // Returns a InstalledWebappGeolocationContext if this web content is running
755 // in a installed webapp and geolocation should be deleagted from the
756 // installed webapp; otherwise returns nullptr.
757 virtual device::mojom::GeolocationContext*
758 GetInstalledWebappGeolocationContext();
760 // Returns a weak ptr to the web contents delegate.
761 virtual base::WeakPtr<WebContentsDelegate> GetDelegateWeakPtr();
763 // Whether the WebContents is privileged.
764 // It's used to prevent drag and drop between privileged and non-privileged
766 virtual bool IsPrivileged();
769 virtual ~WebContentsDelegate();
772 friend class WebContentsImpl;
774 // Called when |this| becomes the WebContentsDelegate for |source|.
775 void Attach(WebContents* source);
777 // Called when |this| is no longer the WebContentsDelegate for |source|.
778 void Detach(WebContents* source);
780 // The WebContents that this is currently a delegate for.
781 std::set<WebContents*> attached_contents_;
784 } // namespace content
786 #endif // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_