[M120 Migration] Support Downloadable font info feature
[platform/framework/web/chromium-efl.git] / content / public / browser / web_contents_delegate.h
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.
4
5 #ifndef CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_
6 #define CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11 #include <set>
12 #include <string>
13 #include <vector>
14
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"
36
37 #if BUILDFLAG(IS_ANDROID)
38 #include "base/android/scoped_java_ref.h"
39 #endif
40
41 class GURL;
42
43 namespace base {
44 class FilePath;
45 template <typename T>
46 class WeakPtr;
47 }
48
49 namespace blink {
50 namespace mojom {
51 class FileChooserParams;
52 class WindowFeatures;
53 }
54 }  // namespace blink
55
56 namespace content {
57 class ColorChooser;
58 class EyeDropperListener;
59 class FileSelectListener;
60 class JavaScriptDialogManager;
61 class RenderFrameHost;
62 class RenderWidgetHost;
63 class SessionStorageNamespace;
64 class SiteInstance;
65 struct ContextMenuParams;
66 struct DropData;
67 struct MediaPlayerWatchTime;
68 struct NativeWebKeyboardEvent;
69 struct Referrer;
70 }  // namespace content
71
72 namespace device {
73 namespace mojom {
74 class GeolocationContext;
75 }
76 }  // namespace device
77
78 namespace gfx {
79 class Rect;
80 class Size;
81 }
82
83 namespace url {
84 class Origin;
85 }
86
87 namespace blink {
88 class WebGestureEvent;
89 enum class ProtocolHandlerSecurityLevel;
90 }
91
92 namespace content {
93
94 class AudioStreamBrokerFactory;
95 struct OpenURLParams;
96
97 enum class KeyboardEventProcessingResult;
98
99 // Result of an EnterPictureInPicture request.
100 enum class PictureInPictureResult {
101   // The request was successful.
102   kSuccess,
103
104   // Picture-in-Picture is not supported by the embedder.
105   kNotSupported,
106 };
107
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 {
115  public:
116   WebContentsDelegate();
117
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.
121   //
122   // A nullptr source indicates the current tab (callers should probably use
123   // OpenURL() for these cases which does it for you).
124
125   // Returns the WebContents the URL is opened in, or nullptr if the URL wasn't
126   // opened immediately. Note that the URL might be opened in another context
127   // when a nullptr is returned.
128   virtual WebContents* OpenURLFromTab(WebContents* source,
129                                       const OpenURLParams& params);
130
131   // Allows the delegate to optionally cancel navigations that attempt to
132   // transfer to a different process between the start of the network load and
133   // commit.  Defaults to true.
134   virtual bool ShouldAllowRendererInitiatedCrossProcessNavigation(
135       bool is_outermost_main_frame_navigation);
136
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) {}
142
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) {}
146
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,
151   // `window_features` should hold the initial position, size and other
152   // properties of the window. If `was_blocked` is non-nullptr, then
153   // `*was_blocked` will be set to true if the popup gets blocked, and left
154   // unchanged otherwise.
155   virtual void AddNewContents(
156       WebContents* source,
157       std::unique_ptr<WebContents> new_contents,
158       const GURL& target_url,
159       WindowOpenDisposition disposition,
160       const blink::mojom::WindowFeatures& window_features,
161       bool user_gesture,
162       bool* was_blocked) {}
163
164   // Selects the specified contents, bringing its container to the front.
165   virtual void ActivateContents(WebContents* contents) {}
166
167   // Notifies the delegate that this contents is starting or is done loading
168   // some resource. The delegate should use this notification to represent
169   // loading feedback. See WebContents::IsLoading()
170   // |should_show_loading_ui| indicates whether a load start should be visible
171   // in UI elements. It is generally true for different-document navigations and
172   // false for most same-document navigations (because same-documents are
173   // typically instantaneous so there's no point in flickering the UI). The
174   // exception is the navigation API's intercept(), which is the sole type
175   // of same-document navigation that is asynchronous, and therefore a UI change
176   // is sensible.
177   virtual void LoadingStateChanged(WebContents* source,
178                                    bool should_show_loading_ui) {}
179
180   // Request the delegate to close this web contents, and do whatever cleanup
181   // it needs to do.
182   virtual void CloseContents(WebContents* source) {}
183
184   // Request the delegate to resize this WebContents to the specified size in
185   // screen coordinates. The embedder is free to ignore the request.
186   virtual void SetContentsBounds(WebContents* source, const gfx::Rect& bounds) {
187   }
188
189   // Notification that the target URL has changed.
190   virtual void UpdateTargetURL(WebContents* source,
191                                const GURL& url) {}
192
193   // Notification that there was a mouse event, along with the type of event.
194   // If |motion| is true, this is a normal motion event. If |exited| is true,
195   // the pointer left the contents area.
196   virtual void ContentsMouseEvent(WebContents* source,
197                                   bool motion,
198                                   bool exited) {}
199
200   // Request the delegate to change the zoom level of the current tab.
201   virtual void ContentsZoomChange(bool zoom_in) {}
202
203   // Called to determine if the WebContents can be overscrolled with touch/wheel
204   // gestures.
205   virtual bool CanOverscrollContent();
206
207   // Returns true if javascript dialogs and unload alerts are suppressed.
208   // Default is false.
209   virtual bool ShouldSuppressDialogs(WebContents* source);
210
211   // Returns whether pending NavigationEntries for aborted browser-initiated
212   // navigations should be preserved (and thus returned from GetVisibleURL).
213   // Defaults to false.
214   virtual bool ShouldPreserveAbortedURLs(WebContents* source);
215
216   // A message was added to the console of a frame of the page. Returning true
217   // indicates that the delegate handled the message. If false is returned the
218   // default logging mechanism will be used for the message.
219   // NOTE: If you only need to monitor messages added to the console, rather
220   // than change the behavior when they are added, prefer using
221   // WebContentsObserver::OnDidAddMessageToConsole().
222   virtual bool DidAddMessageToConsole(
223       WebContents* source,
224       blink::mojom::ConsoleMessageLevel log_level,
225       const std::u16string& message,
226       int32_t line_no,
227       const std::u16string& source_id);
228
229   // Tells us that we've finished firing this tab's beforeunload event.
230   // The proceed bool tells us whether the user chose to proceed closing the
231   // tab. Returns true if the tab can continue on firing its unload event.
232   // If we're closing the entire browser, then we'll want to delay firing
233   // unload events until all the beforeunload events have fired.
234   virtual void BeforeUnloadFired(WebContents* tab,
235                                  bool proceed,
236                                  bool* proceed_to_fire_unload);
237
238   // Returns true if the location bar should be focused by default rather than
239   // the page contents. NOTE: this is only used if WebContents can't determine
240   // for itself whether the location bar should be focused by default. For a
241   // complete check, you should use WebContents::FocusLocationBarByDefault().
242   virtual bool ShouldFocusLocationBarByDefault(WebContents* source);
243
244   // Sets focus to the location bar or some other place that is appropriate.
245   // This is called when the tab wants to encourage user input, like for the
246   // new tab page.
247   virtual void SetFocusToLocationBar() {}
248
249   // Returns whether the page should be focused when transitioning from crashed
250   // to live. Default is true.
251   virtual bool ShouldFocusPageAfterCrash();
252
253   // Returns whether the page should resume accepting requests for the new
254   // window. This is used when window creation is asynchronous
255   // and the navigations need to be delayed. Default is true.
256   virtual bool ShouldResumeRequestsForCreatedWindow();
257
258   // This is called when WebKit tells us that it is done tabbing through
259   // controls on the page. Provides a way for WebContentsDelegates to handle
260   // this. Returns true if the delegate successfully handled it.
261   virtual bool TakeFocus(WebContents* source,
262                          bool reverse);
263
264   // Asks the delegate if the given tab can download.
265   // Invoking the |callback| synchronously is OK.
266   virtual void CanDownload(const GURL& url,
267                            const std::string& request_method,
268                            base::OnceCallback<void(bool)> callback);
269
270   // Asks the delegate to open/show the context menu based on `params`.
271   //
272   // The `render_frame_host` represents the frame that requests the context menu
273   // (typically this frame is focused, but this is not necessarily the case -
274   // see https://crbug.com/1257907#c14).
275   //
276   // Returns true if the context menu operation was handled by the delegate.
277   virtual bool HandleContextMenu(RenderFrameHost& render_frame_host,
278                                  const ContextMenuParams& params);
279
280   // Allows delegates to handle keyboard events before sending to the renderer.
281   // See enum for description of return values.
282   virtual KeyboardEventProcessingResult PreHandleKeyboardEvent(
283       WebContents* source,
284       const NativeWebKeyboardEvent& event);
285
286   // Allows delegates to handle unhandled keyboard messages coming back from
287   // the renderer. Returns true if the event was handled, false otherwise. A
288   // true value means no more processing should happen on the event. The default
289   // return value is false
290   virtual bool HandleKeyboardEvent(WebContents* source,
291                                    const NativeWebKeyboardEvent& event);
292
293   // Allows delegates to handle gesture events before sending to the renderer.
294   // Returns true if the |event| was handled and thus shouldn't be processed
295   // by the renderer's event handler. Note that the touch events that create
296   // the gesture are always passed to the renderer since the gesture is created
297   // and dispatched after the touches return without being "preventDefault()"ed.
298   virtual bool PreHandleGestureEvent(
299       WebContents* source,
300       const blink::WebGestureEvent& event);
301
302   // Called when an external drag event enters the web contents window. Return
303   // true to allow dragging and dropping on the web contents window or false to
304   // cancel the operation. This method is used by Chromium Embedded Framework.
305   virtual bool CanDragEnter(WebContents* source,
306                             const DropData& data,
307                             blink::DragOperationsMask operations_allowed);
308
309   // Shows the repost form confirmation dialog box.
310   virtual void ShowRepostFormWarningDialog(WebContents* source) {}
311
312   // Allows delegate to override navigation to the history entries.
313   // Returns true to allow WebContents to continue with the default processing.
314   virtual bool OnGoToEntryOffset(int offset);
315
316   // Allows delegate to control whether a new WebContents can be created by
317   // the WebContents itself.
318   //
319   // If an delegate returns true, it can optionally also override
320   // CreateCustomWebContents() below to provide their own WebContents.
321   virtual bool IsWebContentsCreationOverridden(
322       SiteInstance* source_site_instance,
323       mojom::WindowContainerType window_container_type,
324       const GURL& opener_url,
325       const std::string& frame_name,
326       const GURL& target_url);
327
328   // Allow delegate to creates a custom WebContents when
329   // WebContents::CreateNewWindow() is called. This function is only called
330   // when IsWebContentsCreationOverridden() returns true.
331   //
332   // In general, a delegate should return a pointer to a created WebContents
333   // so that the opener can be given a references to it as appropriate.
334   // Returning nullptr also makes sense if the delegate wishes to suppress
335   // all window creation, or if the delegate wants to ensure the opener
336   // cannot get a reference effectively creating a new browsing instance.
337   virtual WebContents* CreateCustomWebContents(
338       RenderFrameHost* opener,
339       SiteInstance* source_site_instance,
340       bool is_new_browsing_instance,
341       const GURL& opener_url,
342       const std::string& frame_name,
343       const GURL& target_url,
344       const StoragePartitionConfig& partition_config,
345       SessionStorageNamespace* session_storage_namespace);
346
347   // Notifies the delegate about the creation of a new WebContents. This
348   // typically happens when popups are created.
349   virtual void WebContentsCreated(WebContents* source_contents,
350                                   int opener_render_process_id,
351                                   int opener_render_frame_id,
352                                   const std::string& frame_name,
353                                   const GURL& target_url,
354                                   WebContents* new_contents) {}
355
356   // Notifies the embedder that a new WebContents dedicated for hosting a
357   // prerendered page has been created. `prerender_web_contents` will host an
358   // initial empty primary page and a prerendered page. The prerendered page
359   // will be activated as a primary page on prerender activation.
360   // `prerender_web_contents` is not visible until the activation.
361   //
362   // This function is called only when this delegate is
363   // PrerenderWebContentsDelegate. This delegate and `prerender_web_contents`
364   // are owned by a prerender handle. `prerender_web_contents` outlives this
365   // delegate.
366   virtual void PrerenderWebContentsCreated(
367       WebContents* prerender_web_contents) {}
368
369   // Notifies the embedder that a new WebContents has been created to contain
370   // the contents of a portal.
371   virtual void PortalWebContentsCreated(WebContents* portal_web_contents) {}
372
373   // Notifies the embedder that an existing WebContents that it manages (e.g., a
374   // browser tab) has become the contents of a portal.
375   //
376   // During portal activation, WebContentsDelegate::ActivatePortalWebContents
377   // will be called to release the delegate's management of a WebContents.
378   // Shortly afterward, the portal will assume ownership of the contents and
379   // call this function to indicate that this is complete, passing the
380   // swapped-out contents as |portal_web_contents|.
381   //
382   // Implementations will likely want to apply changes analogous to those they
383   // would apply to a new WebContents in PortalWebContentsCreated.
384   virtual void WebContentsBecamePortal(WebContents* portal_web_contents) {}
385
386   // Notification that one of the frames in the WebContents is hung. |source| is
387   // the WebContents that is hung, and |render_widget_host| is the
388   // RenderWidgetHost that, while routing events to it, discovered the hang.
389   //
390   // |hang_monitor_restarter| can be used to restart the timer used to
391   // detect the hang.  The timer is typically restarted when the renderer has
392   // become active, the tab got hidden, or the user has chosen to wait some
393   // more.
394   //
395   // Useful member functions on |render_widget_host|:
396   // - Getting the hung render process: GetProcess()
397   // - Querying whether the process is still hung: IsCurrentlyUnresponsive()
398   virtual void RendererUnresponsive(
399       WebContents* source,
400       RenderWidgetHost* render_widget_host,
401       base::RepeatingClosure hang_monitor_restarter) {}
402
403   // Notification that a process in the WebContents is no longer hung. |source|
404   // is the WebContents that was hung, and |render_widget_host| is the
405   // RenderWidgetHost that was passed in an earlier call to
406   // RendererUnresponsive().
407   virtual void RendererResponsive(WebContents* source,
408                                   RenderWidgetHost* render_widget_host) {}
409
410 #if BUILDFLAG(IS_TIZEN_TV)
411   virtual void DidEdgeScrollBy(const gfx::Point& offset, bool handled) {}
412   virtual void ShowMicOpenedNotification(bool show) {}
413 #endif
414
415   // Returns a pointer to a service to manage JavaScript dialogs. May return
416   // nullptr in which case dialogs aren't shown.
417   virtual JavaScriptDialogManager* GetJavaScriptDialogManager(
418       WebContents* source);
419
420 #if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_APPLE) || BUILDFLAG(IS_EFL)
421   // Called when color chooser should open. Returns the opened color chooser.
422   // Returns nullptr if we failed to open the color chooser. The color chooser
423   // is supported/required for Android or iOS.
424   virtual std::unique_ptr<ColorChooser> OpenColorChooser(
425       WebContents* web_contents,
426       SkColor color,
427       const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions);
428 #endif
429
430   // Called when an eye dropper should open. Returns the eye dropper window.
431   // The eye dropper is responsible for calling listener->ColorSelected() or
432   // listener->ColorSelectionCanceled().
433   // The ownership of the returned pointer is transferred to the caller.
434   virtual std::unique_ptr<EyeDropper> OpenEyeDropper(
435       RenderFrameHost* frame,
436       EyeDropperListener* listener);
437
438   // Called when a file selection is to be done.
439   // This function is responsible for calling listener->FileSelected() or
440   // listener->FileSelectionCanceled().
441   virtual void RunFileChooser(RenderFrameHost* render_frame_host,
442                               scoped_refptr<FileSelectListener> listener,
443                               const blink::mojom::FileChooserParams& params);
444
445   // Request to enumerate a directory.  This is equivalent to running the file
446   // chooser in directory-enumeration mode and having the user select the given
447   // directory.
448   // This function is responsible for calling listener->FileSelected() or
449   // listener->FileSelectionCanceled().
450   virtual void EnumerateDirectory(WebContents* web_contents,
451                                   scoped_refptr<FileSelectListener> listener,
452                                   const base::FilePath& path);
453
454   // Creates an info bar for the user to control the receiving of the SMS.
455   virtual void CreateSmsPrompt(RenderFrameHost*,
456                                const std::vector<url::Origin>&,
457                                const std::string& one_time_code,
458                                base::OnceCallback<void()> on_confirm,
459                                base::OnceCallback<void()> on_cancel);
460
461   // Returns whether the RFH can use Additional Windowing Controls APIs.
462   // https://github.com/ivansandrk/additional-windowing-controls/blob/main/awc-explainer.md
463   virtual bool CanUseWindowingControls(RenderFrameHost* requesting_frame);
464
465   // Sends the resizable boolean set via `window.setResizable(bool)` API to
466   // `BrowserView`. Passing std::nullopt will reset the resizable state to the
467   // default.
468   virtual void SetCanResizeFromWebAPI(absl::optional<bool> can_resize) {}
469   virtual bool GetCanResize();
470   virtual void MinimizeFromWebAPI() {}
471   virtual void MaximizeFromWebAPI() {}
472   virtual void RestoreFromWebAPI() {}
473
474   // Returns whether entering fullscreen with |EnterFullscreenModeForTab()| is
475   // allowed.
476   virtual bool CanEnterFullscreenModeForTab(
477       RenderFrameHost* requesting_frame,
478       const blink::mojom::FullscreenOptions& options);
479
480   // Called when the renderer puts a tab into fullscreen mode.
481   // |requesting_frame| is the specific content frame requesting fullscreen.
482   // |CanEnterFullscreenModeForTab()| must return true on entry.
483   virtual void EnterFullscreenModeForTab(
484       RenderFrameHost* requesting_frame,
485       const blink::mojom::FullscreenOptions& options) {}
486
487   virtual void FullscreenStateChangedForTab(
488       RenderFrameHost* requesting_frame,
489       const blink::mojom::FullscreenOptions& options) {}
490
491   // Called when the renderer puts a tab out of fullscreen mode.
492   virtual void ExitFullscreenModeForTab(WebContents*) {}
493
494   // Returns true if `web_contents` is, or is transitioning to, tab-fullscreen.
495   virtual bool IsFullscreenForTabOrPending(const WebContents* web_contents);
496
497   // Returns fullscreen state information about the given `web_contents`.
498   virtual FullscreenState GetFullscreenState(
499       const WebContents* web_contents) const;
500
501   // Returns the actual display mode of the top-level browsing context.
502   // For example, it should return 'blink::mojom::DisplayModeFullscreen'
503   // whenever the browser window is put to fullscreen mode (either by the end
504   // user, or HTML API or from a web manifest setting). See
505   // http://w3c.github.io/manifest/#dfn-display-mode
506   virtual blink::mojom::DisplayMode GetDisplayMode(
507       const WebContents* web_contents);
508
509   // Returns the security level to use for Navigator.RegisterProtocolHandler().
510   virtual blink::ProtocolHandlerSecurityLevel GetProtocolHandlerSecurityLevel(
511       RenderFrameHost* requesting_frame);
512
513   // Register a new handler for URL requests with the given scheme.
514   // |user_gesture| is true if the registration is made in the context of a user
515   // gesture.
516   virtual void RegisterProtocolHandler(RenderFrameHost* requesting_frame,
517                                        const std::string& protocol,
518                                        const GURL& url,
519                                        bool user_gesture) {}
520
521   // Unregister the registered handler for URL requests with the given scheme.
522   // |user_gesture| is true if the registration is made in the context of a user
523   // gesture.
524   virtual void UnregisterProtocolHandler(RenderFrameHost* requesting_frame,
525                                          const std::string& protocol,
526                                          const GURL& url,
527                                          bool user_gesture) {}
528
529   // Result of string search in the page. This includes the number of matches
530   // found and the selection rect (in screen coordinates) for the string found.
531   // If |final_update| is false, it indicates that more results follow.
532   virtual void FindReply(WebContents* web_contents,
533                          int request_id,
534                          int number_of_matches,
535                          const gfx::Rect& selection_rect,
536                          int active_match_ordinal,
537                          bool final_update) {}
538
539 #if defined(TIZEN_TBM_SUPPORT)
540   virtual void DidRenderOffscreenFrame(void* buffer) {}
541 #endif
542
543 #if BUILDFLAG(IS_EFL)
544   virtual void DidChangeInputType(bool is_password_field) {}
545   virtual void DidReceiveNonEmtpyLayoutFrame() {}
546   virtual void DidRenderFrame() {}
547   virtual void BackgroundColorReceived(int callback_id, SkColor bg_color) {}
548   virtual void OnDidChangeFocusedNodeBounds(
549       const gfx::RectF& focused_node_bounds) {}
550   virtual void OnGetMainFrameScrollbarVisible(int callback_id, bool visible) {}
551   virtual void WillDraw(int rotation, gfx::Size frame_data_output_size) {}
552 #endif
553
554 #if BUILDFLAG(IS_ANDROID)
555   // Provides the rects of the current find-in-page matches.
556   // Sent as a reply to RequestFindMatchRects.
557   virtual void FindMatchRectsReply(WebContents* web_contents,
558                                    int version,
559                                    const std::vector<gfx::RectF>& rects,
560                                    const gfx::RectF& active_rect) {}
561 #endif
562
563   // Invoked when the preferred size of the contents has been changed.
564   virtual void UpdatePreferredSize(WebContents* web_contents,
565                                    const gfx::Size& pref_size) {}
566
567   // Invoked when the contents auto-resized and the container should match it.
568   virtual void ResizeDueToAutoResize(WebContents* web_contents,
569                                      const gfx::Size& new_size) {}
570
571   // Requests to lock the mouse. Once the request is approved or rejected,
572   // GotResponseToLockMouseRequest() will be called on the requesting tab
573   // contents.
574   virtual void RequestToLockMouse(WebContents* web_contents,
575                                   bool user_gesture,
576                                   bool last_unlocked_by_target);
577
578   // Notification that the page has lost the mouse lock.
579   virtual void LostMouseLock() {}
580
581   // Requests keyboard lock. Once the request is approved or rejected,
582   // GotResponseToKeyboardLockRequest() will be called on |web_contents|.
583   virtual void RequestKeyboardLock(WebContents* web_contents,
584                                    bool esc_key_locked);
585
586   // Notification that the keyboard lock request has been canceled.
587   virtual void CancelKeyboardLockRequest(WebContents* web_contents) {}
588
589   // Asks permission to use the camera and/or microphone. If permission is
590   // granted, a call should be made to |callback| with the devices. If the
591   // request is denied, a call should be made to |callback| with an empty list
592   // of devices. |request| has the details of the request (e.g. which of audio
593   // and/or video devices are requested, and lists of available devices).
594   virtual void RequestMediaAccessPermission(WebContents* web_contents,
595                                             const MediaStreamRequest& request,
596                                             MediaResponseCallback callback);
597
598   // Checks if we have permission to access the microphone or camera. Note that
599   // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
600   // or MEDIA_DEVICE_VIDEO_CAPTURE.
601   virtual bool CheckMediaAccessPermission(RenderFrameHost* render_frame_host,
602                                           const GURL& security_origin,
603                                           blink::mojom::MediaStreamType type);
604
605   // Returns the ID of the default device for the given media device |type|.
606   // If the returned value is an empty string, it means that there is no
607   // default device for the given |type|.
608   virtual std::string GetDefaultMediaDeviceID(
609       WebContents* web_contents,
610       blink::mojom::MediaStreamType type);
611
612   // Returns the human-readable name for title in Media Controls.
613   // If the returned value is an empty string, it means that there is no
614   // human-readable name.
615   // For example, this returns an extension name for title instead of extension
616   // url.
617   virtual std::string GetTitleForMediaControls(WebContents* web_contents);
618
619   // Returns AudioStreamBrokerFactory to use to create AudioStreamBroker when
620   // creating audio I/O streams. Returned `AudioStreamBrokerFactory` is used and
621   // deleted on the IO thread.
622   virtual std::unique_ptr<AudioStreamBrokerFactory>
623   CreateAudioStreamBrokerFactory(WebContents* web_contents);
624
625 #if BUILDFLAG(IS_ANDROID)
626   // Returns true if the given media should be blocked to load.
627   virtual bool ShouldBlockMediaRequest(const GURL& url);
628
629   // Tells the delegate to enter overlay mode.
630   // Overlay mode means that we are currently using AndroidOverlays to display
631   // video, and that the compositor's surface should support alpha and not be
632   // marked as opaque. See media/base/android/android_overlay.h.
633   virtual void SetOverlayMode(bool use_overlay_mode) {}
634 #endif
635
636   // Returns the size for the new render view created for the pending entry in
637   // |web_contents|; if there's no size, returns an empty size.
638   // This is optional for implementations of WebContentsDelegate; if the
639   // delegate doesn't provide a size, the current WebContentsView's size will be
640   // used.
641   virtual gfx::Size GetSizeForNewRenderView(WebContents* web_contents);
642
643   // Returns true if the WebContents is never user-visible, thus the renderer
644   // never needs to produce pixels for display.
645   virtual bool IsNeverComposited(WebContents* web_contents);
646
647   // Askss |guest_web_contents| to perform the same. If this returns true, the
648   // default behavior is suppressed.
649   virtual bool GuestSaveFrame(WebContents* guest_web_contents);
650
651   // Called in response to a request to save a frame. If this returns true, the
652   // default behavior is suppressed.
653   virtual bool SaveFrame(const GURL& url,
654                          const Referrer& referrer,
655                          RenderFrameHost* rfh);
656
657   // Called when a suspicious navigation of the main frame has been blocked.
658   // Allows the delegate to provide some UI to let the user know about the
659   // blocked navigation and give them the option to recover from it.
660   // |blocked_url| is the blocked navigation target, |initiator_url| is the URL
661   // of the frame initiating the navigation, |reason| specifies why the
662   // navigation was blocked.
663   virtual void OnDidBlockNavigation(
664       WebContents* web_contents,
665       const GURL& blocked_url,
666       const GURL& initiator_url,
667       blink::mojom::NavigationBlockedReason reason) {}
668
669   // Reports that passive mixed content was found at the specified url.
670   virtual void PassiveInsecureContentFound(const GURL& resource_url) {}
671
672   // Checks if running of active mixed content is allowed for the specified
673   // WebContents/tab.
674   virtual bool ShouldAllowRunningInsecureContent(WebContents* web_contents,
675                                                  bool allowed_per_prefs,
676                                                  const url::Origin& origin,
677                                                  const GURL& resource_url);
678
679   virtual void SetTopControlsShownRatio(WebContents* web_contents,
680                                         float ratio) {}
681
682   // Requests to get browser controls info such as the height/min height of the
683   // top/bottom controls, and whether to animate these changes to height or
684   // whether they will shrink the Blink's view size. Note that they are not
685   // complete in the sense that there is no API to tell content to poll these
686   // values again, except part of resize. But this is not needed by embedder
687   // because it's always accompanied by view size change. The values returned
688   // by these APIs are in physical pixels (not DIPs).
689   virtual int GetTopControlsHeight();
690   virtual int GetTopControlsMinHeight();
691   virtual int GetBottomControlsHeight();
692   virtual int GetBottomControlsMinHeight();
693   virtual bool ShouldAnimateBrowserControlsHeightChanges();
694   virtual bool DoBrowserControlsShrinkRendererSize(WebContents* web_contents);
695   virtual int GetVirtualKeyboardHeight(WebContents* web_contents);
696   // Returns true if the top controls should only expand at the top of the page,
697   // so they'll only be visible if the page is scrolled to the top.
698   virtual bool OnlyExpandTopControlsAtPageTop();
699
700   // Propagates to the browser that gesture scrolling has changed state. This is
701   // used by the browser to assist in controlling the behavior of sliding the
702   // top controls as a result of page gesture scrolling while in tablet mode.
703   virtual void SetTopControlsGestureScrollInProgress(bool in_progress) {}
704
705   // Requests to print an out-of-process subframe for the specified WebContents.
706   // |rect| is the rectangular area where its content resides in its parent
707   // frame. |document_cookie| is a unique id for a printed document associated
708   // with a print job. |subframe_host| is the RenderFrameHost of the subframe
709   // to be printed.
710   virtual void PrintCrossProcessSubframe(WebContents* web_contents,
711                                          const gfx::Rect& rect,
712                                          int document_cookie,
713                                          RenderFrameHost* subframe_host) const {
714   }
715
716   // Requests to capture a paint preview of a subframe for the specified
717   // WebContents. |rect| is the rectangular area where its content resides in
718   // its parent frame. |guid| is a globally unique identitier for an entire
719   // paint preview. |render_frame_host| is the RenderFrameHost of the subframe
720   // to be captured.
721   virtual void CapturePaintPreviewOfSubframe(
722       WebContents* web_contents,
723       const gfx::Rect& rect,
724       const base::UnguessableToken& guid,
725       RenderFrameHost* render_frame_host) {}
726
727   // Notifies the Picture-in-Picture controller that there is a new player
728   // entering Picture-in-Picture.
729   // Returns the result of the enter request.
730   virtual PictureInPictureResult EnterPictureInPicture(
731       WebContents* web_contents);
732
733   // Updates the Picture-in-Picture controller with a signal that
734   // Picture-in-Picture mode has ended.
735   virtual void ExitPictureInPicture() {}
736
737 #if BUILDFLAG(IS_TIZEN_TV)
738   // Notify Media State to Web browser
739   virtual void NotifyMediaStateChanged(uint32_t type,
740                                        uint32_t previous,
741                                        uint32_t current) {};
742   virtual bool IsHighBitRate() const { return false; }
743   virtual void NotifyDownloadableFontInfo(const std::string& scheme_id_uri,
744                                           const std::string& value,
745                                           const std::string& data,
746                                           int type) {}
747 #endif
748
749 #if BUILDFLAG(IS_ANDROID)
750   // Updates information to determine whether a user gesture should carryover to
751   // future navigations. This is needed so navigations within a certain
752   // timeframe of a request initiated by a gesture will be treated as if they
753   // were initiated by a gesture too, otherwise the navigation may be blocked.
754   virtual void UpdateUserGestureCarryoverInfo(WebContents* web_contents) {}
755 #endif
756
757   // Returns true if lazy loading of images and frames should be enabled.
758   virtual bool ShouldAllowLazyLoad();
759
760   // Return true if the back forward cache is supported. This is not an
761   // indication that the cache will be used.
762   virtual bool IsBackForwardCacheSupported();
763
764   // Returns PreloadingEligibility::kEligible if Prerender2 (see
765   // content/browser/preloading/prerender/README.md for details) is supported.
766   // If it is not supported, returns the reason.
767   virtual PreloadingEligibility IsPrerender2Supported(
768       WebContents& web_contents);
769
770   // Requests the delegate to replace |predecessor_contents| with
771   // |portal_contents| in the container that holds |predecessor_contents|. If
772   // the delegate successfully replaces |predecessor_contents|, the return
773   // parameter passes ownership of |predecessor_contents|. Otherwise,
774   // |portal_contents| is returned.
775   virtual std::unique_ptr<WebContents> ActivatePortalWebContents(
776       WebContents* predecessor_contents,
777       std::unique_ptr<WebContents> portal_contents);
778
779   // If |old_contents| is being inspected by a DevTools window, it updates the
780   // window to inspect |new_contents| instead and calls |callback| after it
781   // finishes asynchronously. If no window is present, or no update is
782   // necessary, |callback| is run synchronously (immediately on the same stack).
783   virtual void UpdateInspectedWebContentsIfNecessary(
784       WebContents* old_contents,
785       WebContents* new_contents,
786       base::OnceCallback<void()> callback);
787
788   // Returns true if the widget's frame content needs to be stored before
789   // eviction and displayed until a new frame is generated. If false, a white
790   // solid color is displayed instead.
791   virtual bool ShouldShowStaleContentOnEviction(WebContents* source);
792
793   // Invoked when media playback is interrupted or completed.
794   virtual void MediaWatchTimeChanged(const MediaPlayerWatchTime& watch_time) {}
795
796   // Returns a  InstalledWebappGeolocationContext if this web content is running
797   // in a installed webapp and geolocation should be deleagted from the
798   // installed webapp; otherwise returns nullptr.
799   virtual device::mojom::GeolocationContext*
800   GetInstalledWebappGeolocationContext();
801
802   // Returns a weak ptr to the web contents delegate.
803   virtual base::WeakPtr<WebContentsDelegate> GetDelegateWeakPtr();
804
805   // Whether the WebContents is privileged.
806   // It's used to prevent drag and drop between privileged and non-privileged
807   // WebContents.
808   virtual bool IsPrivileged();
809
810   // Initiates previewing the given `url` within the given `web_contents`.
811   virtual void InitiatePreview(WebContents& web_contents, const GURL& url) {}
812
813   // CloseWatcher web API support. If the currently focused frame has a
814   // CloseWatcher registered in JavaScript, the CloseWatcher should receive the
815   // next "close" operation, based on what the OS convention for closing is.
816   // This function is called when the focused frame changes or a CloseWatcher
817   // is registered/unregistered to update whether the CloseWatcher should
818   // intercept.
819   virtual void DidChangeCloseSignalInterceptStatus() {}
820
821   // Whether the WebContents is running in preview mode.
822   virtual bool IsInPreviewMode() const;
823
824   // Notify the page uses a forbidden powerful API and cannot be shown in
825   // preview mode.
826   virtual void CancelPreviewByMojoBinderPolicy(
827       const std::string& interface_name) {}
828
829 #if !BUILDFLAG(IS_ANDROID)
830   // Whether the WebContents should use per PWA instanced
831   // system media controls.
832   virtual bool ShouldUseInstancedSystemMediaControls() const;
833 #endif  // !BUILDFLAG(IS_ANDROID)
834
835  protected:
836   virtual ~WebContentsDelegate();
837
838  private:
839   friend class WebContentsImpl;
840
841   // Called when |this| becomes the WebContentsDelegate for |source|.
842   void Attach(WebContents* source);
843
844   // Called when |this| is no longer the WebContentsDelegate for |source|.
845   void Detach(WebContents* source);
846
847   // The WebContents that this is currently a delegate for.
848   std::set<WebContents*> attached_contents_;
849 };
850
851 }  // namespace content
852
853 #endif  // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_