Upload upstream chromium 85.0.4183.84
[platform/framework/web/chromium-efl.git] / content / public / browser / web_contents_delegate.h
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.
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/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"
39
40 #if defined(OS_ANDROID)
41 #include "base/android/scoped_java_ref.h"
42 #endif
43
44 class GURL;
45
46 namespace base {
47 class FilePath;
48 template <typename T>
49 class WeakPtr;
50 }
51
52 namespace blink {
53 namespace mojom {
54 class FileChooserParams;
55 }
56 }  // namespace blink
57
58 namespace content {
59 class ColorChooser;
60 class EyeDropperListener;
61 class FileSelectListener;
62 class JavaScriptDialogManager;
63 class RenderFrameHost;
64 class RenderWidgetHost;
65 class SessionStorageNamespace;
66 class SiteInstance;
67 class WebContentsImpl;
68 struct ContextMenuParams;
69 struct DropData;
70 struct MediaPlayerWatchTime;
71 struct NativeWebKeyboardEvent;
72 struct Referrer;
73 struct SecurityStyleExplanations;
74 }  // namespace content
75
76 namespace device {
77 namespace mojom {
78 class GeolocationContext;
79 }
80 }  // namespace device
81
82 namespace gfx {
83 class Rect;
84 class Size;
85 }
86
87 namespace url {
88 class Origin;
89 }
90
91 namespace viz {
92 class SurfaceId;
93 }  // namespace viz
94
95 namespace blink {
96 class WebGestureEvent;
97 }
98
99 namespace content {
100
101 struct OpenURLParams;
102
103 enum class KeyboardEventProcessingResult;
104
105 // Result of an EnterPictureInPicture request.
106 enum class PictureInPictureResult {
107   // The request was successful.
108   kSuccess,
109
110   // Picture-in-Picture is not supported by the embedder.
111   kNotSupported,
112 };
113
114 // Objects implement this interface to get notified about changes in the
115 // WebContents and to provide necessary functionality.
116 class CONTENT_EXPORT WebContentsDelegate {
117  public:
118   WebContentsDelegate();
119
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.
123   //
124   // A nullptr source indicates the current tab (callers should probably use
125   // OpenURL() for these cases which does it for you).
126
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);
131
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);
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, |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,
159                               bool user_gesture,
160                               bool* was_blocked) {}
161
162   // Selects the specified contents, bringing its container to the front.
163   virtual void ActivateContents(WebContents* contents) {}
164
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) {}
172
173   // Request the delegate to close this web contents, and do whatever cleanup
174   // it needs to do.
175   virtual void CloseContents(WebContents* source) {}
176
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) {
180   }
181
182   // Notification that the target URL has changed.
183   virtual void UpdateTargetURL(WebContents* source,
184                                const GURL& url) {}
185
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,
190                                   bool motion,
191                                   bool exited) {}
192
193   // Request the delegate to change the zoom level of the current tab.
194   virtual void ContentsZoomChange(bool zoom_in) {}
195
196   // Called to determine if the WebContents can be overscrolled with touch/wheel
197   // gestures.
198   virtual bool CanOverscrollContent();
199
200   // Invoked prior to showing before unload handler confirmation dialog.
201   virtual void WillRunBeforeUnloadConfirm() {}
202
203   // Returns true if javascript dialogs and unload alerts are suppressed.
204   // Default is false.
205   virtual bool ShouldSuppressDialogs(WebContents* source);
206
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);
211
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(
219       WebContents* source,
220       blink::mojom::ConsoleMessageLevel log_level,
221       const base::string16& message,
222       int32_t line_no,
223       const base::string16& source_id);
224
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,
231                                  bool proceed,
232                                  bool* proceed_to_fire_unload);
233
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);
239
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
242   // new tab page.
243   virtual void SetFocusToLocationBar() {}
244
245   // Returns whether the page should be focused when transitioning from crashed
246   // to live. Default is true.
247   virtual bool ShouldFocusPageAfterCrash();
248
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();
253
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,
258                          bool reverse);
259
260   // Invoked when the page loses mouse capture.
261   virtual void LostCapture() {}
262
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);
268
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);
272
273   // Allows delegates to handle keyboard events before sending to the renderer.
274   // See enum for description of return values.
275   virtual KeyboardEventProcessingResult PreHandleKeyboardEvent(
276       WebContents* source,
277       const NativeWebKeyboardEvent& event);
278
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);
285
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(
292       WebContents* source,
293       const blink::WebGestureEvent& event);
294
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);
301
302   // Shows the repost form confirmation dialog box.
303   virtual void ShowRepostFormWarningDialog(WebContents* source) {}
304
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);
308
309   // Allows delegate to control whether a new WebContents can be created by
310   // the WebContents itself.
311   //
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);
320
321   // Allow delegate to creates a custom WebContents when
322   // WebContents::CreateNewWindow() is called. This function is only called
323   // when IsWebContentsCreationOverridden() returns true.
324   //
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);
339
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) {}
348
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) {}
352
353   // Notifies the embedder that an existing WebContents that it manages (e.g., a
354   // browser tab) has become the contents of a portal.
355   //
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|.
361   //
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) {}
365
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.
369   //
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
373   // more.
374   //
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(
379       WebContents* source,
380       RenderWidgetHost* render_widget_host,
381       base::RepeatingClosure hang_monitor_restarter) {}
382
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) {}
389
390   // Invoked when a main fram navigation occurs.
391   virtual void DidNavigateMainFramePostCommit(WebContents* source) {}
392
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);
397
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,
404       SkColor color,
405       const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions);
406
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);
414
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);
421
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
424   // directory.
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);
430
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);
436
437   // Creates an info bar for the user to control the receiving of the SMS.
438   virtual void CreateSmsPrompt(RenderFrameHost*,
439                                const url::Origin&,
440                                const std::string& one_time_code,
441                                base::OnceCallback<void()> on_confirm,
442                                base::OnceCallback<void()> on_cancel);
443
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);
449
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();
455
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) {}
461
462   // Called when the renderer puts a tab out of fullscreen mode.
463   virtual void ExitFullscreenModeForTab(WebContents*) {}
464
465   virtual bool IsFullscreenForTabOrPending(const WebContents* web_contents);
466
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);
474
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
477   // gesture.
478   virtual void RegisterProtocolHandler(WebContents* web_contents,
479                                        const std::string& protocol,
480                                        const GURL& url,
481                                        bool user_gesture) {}
482
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
485   // gesture.
486   virtual void UnregisterProtocolHandler(WebContents* web_contents,
487                                          const std::string& protocol,
488                                          const GURL& url,
489                                          bool user_gesture) {}
490
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,
495                          int request_id,
496                          int number_of_matches,
497                          const gfx::Rect& selection_rect,
498                          int active_match_ordinal,
499                          bool final_update) {}
500
501 #if defined(USE_EFL)
502   virtual void DidRenderFrame() {}
503 #endif
504
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,
509                                    int version,
510                                    const std::vector<gfx::RectF>& rects,
511                                    const gfx::RectF& active_rect) {}
512 #endif
513
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) {}
517
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) {}
521
522   // Requests to lock the mouse. Once the request is approved or rejected,
523   // GotResponseToLockMouseRequest() will be called on the requesting tab
524   // contents.
525   virtual void RequestToLockMouse(WebContents* web_contents,
526                                   bool user_gesture,
527                                   bool last_unlocked_by_target) {}
528
529   // Notification that the page has lost the mouse lock.
530   virtual void LostMouseLock() {}
531
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) {}
536
537   // Notification that the keyboard lock request has been canceled.
538   virtual void CancelKeyboardLockRequest(WebContents* web_contents) {}
539
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);
549
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);
556
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);
563
564 #if defined(OS_ANDROID)
565   // Returns true if the given media should be blocked to load.
566   virtual bool ShouldBlockMediaRequest(const GURL& url);
567
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) {}
573 #endif
574
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,
580       const GURL& url,
581       const base::FilePath& plugin_path,
582       base::OnceCallback<void(bool)> callback);
583
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
588   // used.
589   virtual gfx::Size GetSizeForNewRenderView(WebContents* web_contents);
590
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);
594
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);
598
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);
602
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);
610
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) {}
622
623   // Reports that passive mixed content was found at the specified url.
624   virtual void PassiveInsecureContentFound(const GURL& resource_url) {}
625
626   // Checks if running of active mixed content is allowed for the specified
627   // WebContents/tab.
628   virtual bool ShouldAllowRunningInsecureContent(WebContents* web_contents,
629                                                  bool allowed_per_prefs,
630                                                  const url::Origin& origin,
631                                                  const GURL& resource_url);
632
633   virtual void SetTopControlsShownRatio(WebContents* web_contents,
634                                         float ratio) {}
635
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);
649
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) {}
654
655   // Give WebContentsDelegates the opportunity to adjust the previews state.
656   virtual void AdjustPreviewsStateForNavigation(WebContents* web_contents,
657                                                 PreviewsState* previews_state) {
658   }
659
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
663   // with
664   //                   a print job.
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,
668                                          int document_cookie,
669                                          RenderFrameHost* subframe_host) const {
670   }
671
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) {}
682
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);
690
691   // Updates the Picture-in-Picture controller with a signal that
692   // Picture-in-Picture mode has ended.
693   virtual void ExitPictureInPicture() {}
694
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) {}
701 #endif
702
703   // Returns true if lazy loading of images and frames should be enabled.
704   virtual bool ShouldAllowLazyLoad();
705
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);
714
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);
719
720   // Determine if the frame is of a low priority.
721   virtual bool IsFrameLowPriority(const WebContents* web_contents,
722                                   const RenderFrameHost* render_frame_host);
723
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.
729   //
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).
733   //
734   // For most delegates (where the WebContents is a tab, window or other
735   // directly user-visible feature), simply returning the contents is
736   // appropriate.
737   virtual WebContents* GetResponsibleWebContents(WebContents* web_contents);
738
739   // Invoked when media playback is interrupted or completed.
740   virtual void MediaWatchTimeChanged(const MediaPlayerWatchTime& watch_time) {}
741
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();
747
748   // Returns a weak ptr to the web contents delegate.
749   virtual base::WeakPtr<WebContentsDelegate> GetDelegateWeakPtr();
750
751  protected:
752   virtual ~WebContentsDelegate();
753
754  private:
755   friend class WebContentsImpl;
756
757   // Called when |this| becomes the WebContentsDelegate for |source|.
758   void Attach(WebContents* source);
759
760   // Called when |this| is no longer the WebContentsDelegate for |source|.
761   void Detach(WebContents* source);
762
763   // The WebContents that this is currently a delegate for.
764   std::set<WebContents*> attached_contents_;
765 };
766
767 }  // namespace content
768
769 #endif  // CONTENT_PUBLIC_BROWSER_WEB_CONTENTS_DELEGATE_H_