1 // Copyright 2013 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_BROWSER_RENDERER_HOST_RENDER_FRAME_HOST_DELEGATE_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_FRAME_HOST_DELEGATE_H_
7 
8 #include <stdint.h>
9 
10 #include <string>
11 #include <vector>
12 
13 #include "base/callback_forward.h"
14 #include "base/i18n/rtl.h"
15 #include "base/optional.h"
16 #include "build/build_config.h"
17 #include "components/viz/common/surfaces/surface_id.h"
18 #include "content/browser/renderer_host/render_frame_host_impl.h"
19 #include "content/browser/webui/web_ui_impl.h"
20 #include "content/common/content_export.h"
21 #include "content/public/browser/javascript_dialog_manager.h"
22 #include "content/public/browser/media_player_watch_time.h"
23 #include "content/public/browser/media_stream_request.h"
24 #include "content/public/browser/site_instance.h"
25 #include "content/public/browser/visibility.h"
26 #include "content/public/common/javascript_dialog_type.h"
27 #include "media/mojo/services/media_metrics_provider.h"
28 #include "mojo/public/cpp/bindings/pending_receiver.h"
29 #include "mojo/public/cpp/bindings/pending_remote.h"
30 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
31 #include "net/cert/cert_status_flags.h"
32 #include "net/http/http_response_headers.h"
33 #include "services/device/public/mojom/geolocation_context.mojom.h"
34 #include "services/device/public/mojom/wake_lock.mojom.h"
35 #include "services/metrics/public/cpp/ukm_source_id.h"
36 #include "third_party/blink/public/common/mediastream/media_stream_request.h"
37 #include "third_party/blink/public/mojom/choosers/popup_menu.mojom.h"
38 #include "third_party/blink/public/mojom/devtools/console_message.mojom.h"
39 #include "third_party/blink/public/mojom/favicon/favicon_url.mojom.h"
40 #include "third_party/blink/public/mojom/frame/blocked_navigation_types.mojom.h"
41 #include "third_party/blink/public/mojom/frame/frame.mojom-forward.h"
42 #include "third_party/blink/public/mojom/loader/resource_load_info.mojom.h"
43 #include "third_party/skia/include/core/SkColor.h"
44 #include "ui/accessibility/ax_mode.h"
45 #include "ui/base/window_open_disposition.h"
46 
47 #if defined(OS_WIN)
48 #include "ui/gfx/native_widget_types.h"
49 #endif
50 
51 #if defined(OS_ANDROID)
52 #include "base/android/scoped_java_ref.h"
53 #include "services/device/public/mojom/nfc.mojom.h"
54 #endif
55 
56 class GURL;
57 
58 namespace IPC {
59 class Message;
60 }
61 
62 namespace gfx {
63 class Rect;
64 class Size;
65 }  // namespace gfx
66 
67 namespace url {
68 class Origin;
69 }
70 
71 namespace blink {
72 namespace mojom {
73 class FullscreenOptions;
74 }
75 class PageState;
76 namespace web_pref {
77 struct WebPreferences;
78 }
79 }  // namespace blink
80 
81 namespace ui {
82 class ClipboardFormatType;
83 }
84 
85 namespace content {
86 class AgentSchedulingGroupHost;
87 class FrameTreeNode;
88 class RenderFrameHostImpl;
89 class RenderWidgetHostImpl;
90 class SessionStorageNamespace;
91 class WebContents;
92 struct AXEventNotificationDetails;
93 struct AXLocationChangeNotificationDetails;
94 struct ContextMenuParams;
95 struct GlobalRequestID;
96 
97 namespace mojom {
98 class CreateNewWindowParams;
99 }
100 
101 // An interface implemented by an object interested in knowing about the state
102 // of the RenderFrameHost.
103 class CONTENT_EXPORT RenderFrameHostDelegate {
104  public:
105   // Callback used with HandleClipboardPaste() method.  If the clipboard paste
106   // is allowed to proceed, the callback is called with true.  Otherwise the
107   // callback is called with false.
108   using ClipboardPasteAllowed = RenderFrameHostImpl::ClipboardPasteAllowed;
109   using IsClipboardPasteAllowedCallback =
110       RenderFrameHostImpl::IsClipboardPasteAllowedCallback;
111 
112   using JavaScriptDialogCallback =
113       content::JavaScriptDialogManager::DialogClosedCallback;
114 
115   // This is used to give the delegate a chance to filter IPC messages.
116   virtual bool OnMessageReceived(RenderFrameHostImpl* render_frame_host,
117                                  const IPC::Message& message);
118 
119   // Allows the delegate to filter incoming associated interface requests.
OnAssociatedInterfaceRequest(RenderFrameHost * render_frame_host,const std::string & interface_name,mojo::ScopedInterfaceEndpointHandle handle)120   virtual void OnAssociatedInterfaceRequest(
121       RenderFrameHost* render_frame_host,
122       const std::string& interface_name,
123       mojo::ScopedInterfaceEndpointHandle handle) {}
124 
125   // Allows the delegate to filter incoming interface requests.
OnInterfaceRequest(RenderFrameHost * render_frame_host,const std::string & interface_name,mojo::ScopedMessagePipeHandle * interface_pipe)126   virtual void OnInterfaceRequest(
127       RenderFrameHost* render_frame_host,
128       const std::string& interface_name,
129       mojo::ScopedMessagePipeHandle* interface_pipe) {}
130 
131   // Notification from the renderer host that a suspicious navigation of the
132   // main frame has been blocked. Allows the delegate to provide some UI to let
133   // the user know about the blocked navigation and give them the option to
134   // recover from it.
135   // |blocked_url| is the blocked navigation target, |initiator_url| is the URL
136   // of the frame initiating the navigation, |reason| specifies why the
137   // navigation was blocked.
OnDidBlockNavigation(const GURL & blocked_url,const GURL & initiator_url,blink::mojom::NavigationBlockedReason reason)138   virtual void OnDidBlockNavigation(
139       const GURL& blocked_url,
140       const GURL& initiator_url,
141       blink::mojom::NavigationBlockedReason reason) {}
142 
143   // Notifies the browser that a frame finished loading.
OnDidFinishLoad(RenderFrameHost * render_frame_host,const GURL & url)144   virtual void OnDidFinishLoad(RenderFrameHost* render_frame_host,
145                                const GURL& url) {}
146 
147   // Gets the last committed URL. See WebContents::GetLastCommittedURL for a
148   // description of the semantics.
149   virtual const GURL& GetMainFrameLastCommittedURL();
150 
151   // A message was added to to the console.
152   virtual bool DidAddMessageToConsole(
153       RenderFrameHost* source_frame,
154       blink::mojom::ConsoleMessageLevel log_level,
155       const base::string16& message,
156       int32_t line_no,
157       const base::string16& source_id);
158 
159   // Called when a RenderFrame for |render_frame_host| is created in the
160   // renderer process. Use |RenderFrameDeleted| to listen for when this
161   // RenderFrame goes away.
RenderFrameCreated(RenderFrameHost * render_frame_host)162   virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
163 
164   // Called when a RenderFrame for |render_frame_host| is deleted or the
165   // renderer process in which it runs it has died. Use |RenderFrameCreated| to
166   // listen for when RenderFrame objects are created.
RenderFrameDeleted(RenderFrameHost * render_frame_host)167   virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
168 
169   // A context menu should be shown, to be built using the context information
170   // provided in the supplied params.
ShowContextMenu(RenderFrameHost * render_frame_host,const ContextMenuParams & params)171   virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
172                                const ContextMenuParams& params) {}
173 
174   // A JavaScript alert, confirmation or prompt dialog should be shown.
RunJavaScriptDialog(RenderFrameHost * render_frame_host,const base::string16 & message,const base::string16 & default_prompt,JavaScriptDialogType type,JavaScriptDialogCallback callback)175   virtual void RunJavaScriptDialog(RenderFrameHost* render_frame_host,
176                                    const base::string16& message,
177                                    const base::string16& default_prompt,
178                                    JavaScriptDialogType type,
179                                    JavaScriptDialogCallback callback) {}
180 
RunBeforeUnloadConfirm(RenderFrameHost * render_frame_host,bool is_reload,JavaScriptDialogCallback callback)181   virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host,
182                                       bool is_reload,
183                                       JavaScriptDialogCallback callback) {}
184 
185   // Notifies when new blink::mojom::FaviconURLPtr candidates are received from
186   // the renderer process.
UpdateFaviconURL(RenderFrameHost * source,std::vector<blink::mojom::FaviconURLPtr> candidates)187   virtual void UpdateFaviconURL(
188       RenderFrameHost* source,
189       std::vector<blink::mojom::FaviconURLPtr> candidates) {}
190 
191   // The pending page load was canceled, so the address bar should be updated.
DidCancelLoading()192   virtual void DidCancelLoading() {}
193 
194   // Another page accessed the top-level initial empty document, which means it
195   // is no longer safe to display a pending URL without risking a URL spoof.
DidAccessInitialDocument()196   virtual void DidAccessInitialDocument() {}
197 
198   // The frame changed its window.name property.
DidChangeName(RenderFrameHost * render_frame_host,const std::string & name)199   virtual void DidChangeName(RenderFrameHost* render_frame_host,
200                              const std::string& name) {}
201 
202   // The sticky user activation bit has been set on the frame. This will not be
203   // called for new RenderFrameHosts whose underlying FrameTreeNode was already
204   // activated.
DidReceiveFirstUserActivation(RenderFrameHost * render_frame_host)205   virtual void DidReceiveFirstUserActivation(
206       RenderFrameHost* render_frame_host) {}
207 
208   // The display style of the frame has changed.
DidChangeDisplayState(RenderFrameHost * render_frame_host,bool is_display_none)209   virtual void DidChangeDisplayState(RenderFrameHost* render_frame_host,
210                                      bool is_display_none) {}
211 
212   // The size of the frame has changed.
FrameSizeChanged(RenderFrameHost * render_frame_host,const gfx::Size & frame_size)213   virtual void FrameSizeChanged(RenderFrameHost* render_frame_host,
214                                 const gfx::Size& frame_size) {}
215 
216   // The DOMContentLoaded handler in the frame has completed.
DOMContentLoaded(RenderFrameHost * render_frame_host)217   virtual void DOMContentLoaded(RenderFrameHost* render_frame_host) {}
218 
219   // The onload handler in the frame has completed. Only called for the top-
220   // level frame.
DocumentOnLoadCompleted(RenderFrameHost * render_frame_host)221   virtual void DocumentOnLoadCompleted(RenderFrameHost* render_frame_host) {}
222 
223   // The state for the page changed and should be updated in session history.
UpdateStateForFrame(RenderFrameHost * render_frame_host,const blink::PageState & page_state)224   virtual void UpdateStateForFrame(RenderFrameHost* render_frame_host,
225                                    const blink::PageState& page_state) {}
226 
227   // The page's title was changed and should be updated. Only called for the
228   // top-level frame.
UpdateTitle(RenderFrameHost * render_frame_host,const base::string16 & title,base::i18n::TextDirection title_direction)229   virtual void UpdateTitle(RenderFrameHost* render_frame_host,
230                            const base::string16& title,
231                            base::i18n::TextDirection title_direction) {}
232 
233   // The destination URL has changed and should be updated.
UpdateTargetURL(RenderFrameHost * render_frame_host,const GURL & url)234   virtual void UpdateTargetURL(RenderFrameHost* render_frame_host,
235                                const GURL& url) {}
236 
237   // Return this object cast to a WebContents, if it is one. If the object is
238   // not a WebContents, returns null.
239   virtual WebContents* GetAsWebContents();
240 
241   // The render frame has requested access to media devices listed in
242   // |request|, and the client should grant or deny that permission by
243   // calling |callback|.
244   virtual void RequestMediaAccessPermission(const MediaStreamRequest& request,
245                                             MediaResponseCallback callback);
246 
247   // Checks if we have permission to access the microphone or camera. Note that
248   // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
249   // or MEDIA_DEVICE_VIDEO_CAPTURE.
250   virtual bool CheckMediaAccessPermission(RenderFrameHost* render_frame_host,
251                                           const url::Origin& security_origin,
252                                           blink::mojom::MediaStreamType type);
253 
254   // Returns the ID of the default device for the given media device |type|.
255   // If the returned value is an empty string, it means that there is no
256   // default device for the given |type|.
257   virtual std::string GetDefaultMediaDeviceID(
258       blink::mojom::MediaStreamType type);
259 
260   // Get the accessibility mode for the WebContents that owns this frame.
261   virtual ui::AXMode GetAccessibilityMode();
262 
263   // Called whenever the AXTreeID for the topmost RenderFrameHost has changed.
AXTreeIDForMainFrameHasChanged()264   virtual void AXTreeIDForMainFrameHasChanged() {}
265 
266   // Called when accessibility events or location changes are received
267   // from a render frame, when the accessibility mode has the
268   // ui::AXMode::kWebContents flag set.
AccessibilityEventReceived(const AXEventNotificationDetails & details)269   virtual void AccessibilityEventReceived(
270       const AXEventNotificationDetails& details) {}
AccessibilityLocationChangesReceived(const std::vector<AXLocationChangeNotificationDetails> & details)271   virtual void AccessibilityLocationChangesReceived(
272       const std::vector<AXLocationChangeNotificationDetails>& details) {}
273 
274   // Gets the GeolocationContext associated with this delegate.
275   virtual device::mojom::GeolocationContext* GetGeolocationContext();
276 
277 #if defined(OS_ANDROID)
278   // Gets an NFC implementation within the context of this delegate.
279   virtual void GetNFC(RenderFrameHost* render_frame_host,
280                       mojo::PendingReceiver<device::mojom::NFC> receiver);
281 #endif
282 
283   // Returns whether entering fullscreen with EnterFullscreenMode() is allowed.
284   virtual bool CanEnterFullscreenMode();
285 
286   // Notification that the frame with the given host wants to enter fullscreen
287   // mode. Must only be called if CanEnterFullscreenMode returns true.
EnterFullscreenMode(RenderFrameHost * requesting_frame,const blink::mojom::FullscreenOptions & options)288   virtual void EnterFullscreenMode(
289       RenderFrameHost* requesting_frame,
290       const blink::mojom::FullscreenOptions& options) {}
291 
292   // Notification that the frame wants to go out of fullscreen mode.
293   // |will_cause_resize| indicates whether the fullscreen change causes a
294   // view resize. e.g. This will be false when going from tab fullscreen to
295   // browser fullscreen.
ExitFullscreenMode(bool will_cause_resize)296   virtual void ExitFullscreenMode(bool will_cause_resize) {}
297 
298   // Notification that this frame has changed fullscreen state.
FullscreenStateChanged(RenderFrameHost * rfh,bool is_fullscreen)299   virtual void FullscreenStateChanged(RenderFrameHost* rfh,
300                                       bool is_fullscreen) {}
301 
302 #if defined(OS_ANDROID)
303   // Updates information to determine whether a user gesture should carryover to
304   // future navigations. This is needed so navigations within a certain
305   // timeframe of a request initiated by a gesture will be treated as if they
306   // were initiated by a gesture too, otherwise the navigation may be blocked.
UpdateUserGestureCarryoverInfo()307   virtual void UpdateUserGestureCarryoverInfo() {}
308 #endif
309 
310   // Let the delegate decide whether postMessage should be delivered to
311   // |target_rfh| from a source frame in the given SiteInstance.  This defaults
312   // to false and overrides the RenderFrameHost's decision if true.
313   virtual bool ShouldRouteMessageEvent(
314       RenderFrameHost* target_rfh,
315       SiteInstance* source_site_instance) const;
316 
317   // Ensure that |source_rfh| has swapped-out RenderViews and
318   // RenderFrameProxies for itself and for all frames on its opener chain in
319   // the current frame's SiteInstance.
320   //
321   // TODO(alexmos): This method currently supports cross-process postMessage,
322   // where we may need to create any missing proxies for the message's source
323   // frame and its opener chain. It currently exists in WebContents due to a
324   // special case for <webview> guests, but this logic should eventually be
325   // moved down into RenderFrameProxyHost::RouteMessageEvent when <webview>
326   // refactoring for --site-per-process mode is further along.  See
327   // https://crbug.com/330264.
EnsureOpenerProxiesExist(RenderFrameHost * source_rfh)328   virtual void EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) {}
329 
330   // Set the |node| frame as focused in the current FrameTree as well as
331   // possibly changing focus in distinct but related inner/outer WebContents.
SetFocusedFrame(FrameTreeNode * node,SiteInstance * source)332   virtual void SetFocusedFrame(FrameTreeNode* node, SiteInstance* source) {}
333 
334   // The frame called |window.focus()|.
DidCallFocus()335   virtual void DidCallFocus() {}
336 
337   // Searches the WebContents for a focused frame, potentially in an inner
338   // WebContents. If this WebContents has no focused frame, returns |nullptr|.
339   // If there is no inner WebContents at the focused tree node, returns its
340   // RenderFrameHost. If there is an inner WebContents, search it for focused
341   // frames and inner contents. If an inner WebContents does not have a focused
342   // frame, return its main frame, since the attachment frame in its outer
343   // WebContents is not live.
344   virtual RenderFrameHost* GetFocusedFrameIncludingInnerWebContents();
345 
346   // Returns the main frame for the delegate.
347   virtual RenderFrameHostImpl* GetMainFrame();
348 
349   // Called by when |source_rfh| advances focus to a RenderFrameProxyHost.
OnAdvanceFocus(RenderFrameHostImpl * source_rfh)350   virtual void OnAdvanceFocus(RenderFrameHostImpl* source_rfh) {}
351 
352   // Creates a WebUI object for a frame navigating to |url|. If no WebUI
353   // applies, returns null.
354   virtual std::unique_ptr<WebUIImpl> CreateWebUIForRenderFrameHost(
355       RenderFrameHost* frame_host,
356       const GURL& url);
357 
358   // Called by |frame| to notify that it has received an update on focused
359   // element. |bounds_in_root_view| is the rectangle containing the element that
360   // is focused and is with respect to root frame's RenderWidgetHost's
361   // coordinate space.
OnFocusedElementChangedInFrame(RenderFrameHostImpl * frame,const gfx::Rect & bounds_in_root_view,blink::mojom::FocusType focus_type)362   virtual void OnFocusedElementChangedInFrame(
363       RenderFrameHostImpl* frame,
364       const gfx::Rect& bounds_in_root_view,
365       blink::mojom::FocusType focus_type) {}
366 
367   // The page is trying to open a new page (e.g. a popup window). The window
368   // should be created associated the process of |opener|, but it should not
369   // be shown yet. That should happen in response to ShowCreatedWindow.
370   // |params.window_container_type| describes the type of RenderViewHost
371   // container that is requested -- in particular, the window.open call may
372   // have specified 'background' and 'persistent' in the feature string.
373   //
374   // The passed |opener| is the RenderFrameHost initiating the window creation.
375   // It will never be null, even if the opener is suppressed via |params|.
376   //
377   // The passed |params.frame_name| parameter is the name parameter that was
378   // passed to window.open(), and will be empty if none was passed.
379   //
380   // Note: this is not called "CreateWindow" because that will clash with
381   // the Windows function which is actually a #define.
382   //
383   // On success, a non-owning pointer to the new RenderFrameHostDelegate is
384   // returned.
385   //
386   // The caller is expected to handle cleanup if this operation fails or is
387   // suppressed by checking if the return value is null.
388   virtual RenderFrameHostDelegate* CreateNewWindow(
389       RenderFrameHost* opener,
390       const mojom::CreateNewWindowParams& params,
391       bool is_new_browsing_instance,
392       bool has_user_gesture,
393       SessionStorageNamespace* session_storage_namespace);
394 
395   // Show a previously created page with the specified disposition and bounds.
396   // The window is identified by the |main_frame_widget_route_id| passed to
397   // CreateNewWindow.
398   //
399   // The passed |opener| is the RenderFrameHost initiating the window creation.
400   // It will never be null, even if the opener is suppressed via |params|.
401   //
402   // Note: this is not called "ShowWindow" because that will clash with
403   // the Windows function which is actually a #define.
ShowCreatedWindow(RenderFrameHost * opener,int main_frame_widget_route_id,WindowOpenDisposition disposition,const gfx::Rect & initial_rect,bool user_gesture)404   virtual void ShowCreatedWindow(RenderFrameHost* opener,
405                                  int main_frame_widget_route_id,
406                                  WindowOpenDisposition disposition,
407                                  const gfx::Rect& initial_rect,
408                                  bool user_gesture) {}
409 
410   // Notified that mixed content was displayed or ran.
DidDisplayInsecureContent()411   virtual void DidDisplayInsecureContent() {}
DidContainInsecureFormAction()412   virtual void DidContainInsecureFormAction() {}
413   // The main frame document element is ready. This happens when the document
414   // has finished parsing.
DocumentAvailableInMainFrame()415   virtual void DocumentAvailableInMainFrame() {}
DidRunInsecureContent(const GURL & security_origin,const GURL & target_url)416   virtual void DidRunInsecureContent(const GURL& security_origin,
417                                      const GURL& target_url) {}
418 
419   // Reports that passive mixed content was found at the specified url.
PassiveInsecureContentFound(const GURL & resource_url)420   virtual void PassiveInsecureContentFound(const GURL& resource_url) {}
421 
422   // Checks if running of active mixed content is allowed in the current tab.
423   virtual bool ShouldAllowRunningInsecureContent(bool allowed_per_prefs,
424                                                  const url::Origin& origin,
425                                                  const GURL& resource_url);
426 
427   // Opens a new view-source tab for the last committed document in |frame|.
ViewSource(RenderFrameHostImpl * frame)428   virtual void ViewSource(RenderFrameHostImpl* frame) {}
429 
430 #if defined(OS_ANDROID)
431   virtual base::android::ScopedJavaLocalRef<jobject>
432   GetJavaRenderFrameHostDelegate();
433 #endif
434 
435   // Whether the delegate is being destroyed, in which case the RenderFrameHost
436   // should not be asked to create a RenderFrame.
437   virtual bool IsBeingDestroyed();
438 
439   // Notified that the render frame started loading a subresource.
SubresourceResponseStarted(const GURL & url,net::CertStatus cert_status)440   virtual void SubresourceResponseStarted(const GURL& url,
441                                           net::CertStatus cert_status) {}
442 
443   // Notified that the render finished loading a subresource for the frame
444   // associated with |render_frame_host|.
ResourceLoadComplete(RenderFrameHost * render_frame_host,const GlobalRequestID & request_id,blink::mojom::ResourceLoadInfoPtr resource_load_info)445   virtual void ResourceLoadComplete(
446       RenderFrameHost* render_frame_host,
447       const GlobalRequestID& request_id,
448       blink::mojom::ResourceLoadInfoPtr resource_load_info) {}
449 
450   // Request to print a frame that is in a different process than its parent.
PrintCrossProcessSubframe(const gfx::Rect & rect,int document_cookie,RenderFrameHost * render_frame_host)451   virtual void PrintCrossProcessSubframe(const gfx::Rect& rect,
452                                          int document_cookie,
453                                          RenderFrameHost* render_frame_host) {}
454 
455   // Request to paint preview a frame that is in a different process that its
456   // parent.
CapturePaintPreviewOfCrossProcessSubframe(const gfx::Rect & rect,const base::UnguessableToken & guid,RenderFrameHost * render_frame_host)457   virtual void CapturePaintPreviewOfCrossProcessSubframe(
458       const gfx::Rect& rect,
459       const base::UnguessableToken& guid,
460       RenderFrameHost* render_frame_host) {}
461 
462   // Updates the Picture-in-Picture controller with the relevant viz::SurfaceId
463   // of the video to be in Picture-in-Picture mode.
UpdatePictureInPictureSurfaceId(const viz::SurfaceId & surface_id,const gfx::Size & natural_size)464   virtual void UpdatePictureInPictureSurfaceId(const viz::SurfaceId& surface_id,
465                                                const gfx::Size& natural_size) {}
466 
467   // Returns a copy of the current WebPreferences associated with this
468   // RenderFrameHost's WebContents. If it does not exist, this will create one
469   // and send the newly computed value to all renderers.
470   // Note that this will not trigger a recomputation of WebPreferences if it
471   // already exists - this will return the last computed/set value of
472   // WebPreferences. If we want to guarantee that the value reflects the current
473   // state of the WebContents, NotifyPreferencesChanged() should be called
474   // before calling this.
475   virtual const blink::web_pref::WebPreferences&
476   GetOrCreateWebPreferences() = 0;
477 
478   // Returns the visibility of the delegate.
479   virtual Visibility GetVisibility();
480 
481   // Get the UKM source ID for current content from the last committed
482   // navigation, either a cross-document or same-document navigation. This is
483   // for providing data about the content to the URL-keyed metrics service.
484   // Use this method if UKM events should be attributed to the latest
485   // navigation, that is, attribute events to the new source after each
486   // same-document navigation, if any.
487   virtual ukm::SourceId
488   GetUkmSourceIdForLastCommittedSourceIncludingSameDocument() const;
489 
490   // Notify observers if WebAudio AudioContext has started (or stopped) playing
491   // audible sounds.
AudioContextPlaybackStarted(RenderFrameHost * host,int context_id)492   virtual void AudioContextPlaybackStarted(RenderFrameHost* host,
493                                            int context_id) {}
AudioContextPlaybackStopped(RenderFrameHost * host,int context_id)494   virtual void AudioContextPlaybackStopped(RenderFrameHost* host,
495                                            int context_id) {}
496 
497   // Notifies observers if the frame has changed audible state.
OnFrameAudioStateChanged(RenderFrameHost * host,bool is_audible)498   virtual void OnFrameAudioStateChanged(RenderFrameHost* host,
499                                         bool is_audible) {}
500 
501   // Returns the main frame of the inner delegate that is attached to this
502   // delegate using |frame_tree_node|. Returns nullptr if no such inner delegate
503   // exists.
504   virtual RenderFrameHostImpl* GetMainFrameForInnerDelegate(
505       FrameTreeNode* frame_tree_node);
506 
507   // Determine if the frame is of a low priority.
508   virtual bool IsFrameLowPriority(const RenderFrameHost* render_frame_host);
509 
510   // Registers a new URL handler for the given protocol.
RegisterProtocolHandler(RenderFrameHostImpl * host,const std::string & scheme,const GURL & url,bool user_gesture)511   virtual void RegisterProtocolHandler(RenderFrameHostImpl* host,
512                                        const std::string& scheme,
513                                        const GURL& url,
514                                        bool user_gesture) {}
515 
516   // Unregisters a given URL handler for the given protocol.
UnregisterProtocolHandler(RenderFrameHostImpl * host,const std::string & scheme,const GURL & url,bool user_gesture)517   virtual void UnregisterProtocolHandler(RenderFrameHostImpl* host,
518                                          const std::string& scheme,
519                                          const GURL& url,
520                                          bool user_gesture) {}
521 
522   // Go to the session history entry at the given offset (ie, -1 will return the
523   // "back" item).
OnGoToEntryAtOffset(RenderFrameHostImpl * source,int32_t offset,bool has_user_gesture)524   virtual void OnGoToEntryAtOffset(RenderFrameHostImpl* source,
525                                    int32_t offset,
526                                    bool has_user_gesture) {}
527 
528   virtual media::MediaMetricsProvider::RecordAggregateWatchTimeCallback
529   GetRecordAggregateWatchTimeCallback();
530 
531   // Determines if a clipboard paste using |data| of type |data_type| is allowed
532   // in this renderer frame.  Possible data types supported for paste can be
533   // seen in the ClipboardHostImpl class.  Text based formats will use the
534   // data_type ui::ClipboardFormatType::GetPlainTextType() unless it is known
535   // to be of a more specific type, like RTF or HTML, in which case a type
536   // such as ui::ClipboardFormatType::GetRtfType() or
537   // ui::ClipboardFormatType::GetHtmlType() is used.
538   //
539   // It is also possible for the data type to be
540   // ui::ClipboardFormatType::GetWebCustomDataType() indicating that the paste
541   // uses a custom data format.  It is up to the implementation to attempt to
542   // understand the type if possible.  It is acceptable to deny pastes of
543   // unknown data types.
544   //
545   // The implementation is expected to show UX to the user if needed.  If
546   // shown, the UX should be associated with the specific render frame host.
547   //
548   // The callback is called, possibly asynchronously, with a status indicating
549   // whether the operation is allowed or not.
550   virtual void IsClipboardPasteAllowed(
551       const GURL& url,
552       const ui::ClipboardFormatType& data_type,
553       const std::string& data,
554       IsClipboardPasteAllowedCallback callback);
555 
556   // Notified when the main frame adjusts the page scale.
OnPageScaleFactorChanged(RenderFrameHostImpl * source,float page_scale_factor)557   virtual void OnPageScaleFactorChanged(RenderFrameHostImpl* source,
558                                         float page_scale_factor) {}
559 
OnTextAutosizerPageInfoChanged(RenderFrameHostImpl * source,blink::mojom::TextAutosizerPageInfoPtr page_info)560   virtual void OnTextAutosizerPageInfoChanged(
561       RenderFrameHostImpl* source,
562       blink::mojom::TextAutosizerPageInfoPtr page_info) {}
563 
564   // Return true if we have seen a recent orientation change, which is used to
565   // decide if we should consume user activation when entering fullscreen.
566   virtual bool HasSeenRecentScreenOrientationChange();
567 
568   // Return true if the page has a transient affordance to enter fullscreen
569   // without consuming user activation.
570   virtual bool IsTransientAllowFullscreenActive() const;
571 
572   // The page is trying to open a new widget (e.g. a select popup). The
573   // widget should be created associated with the given
574   // |agent_scheduling_group|, but it should not be shown yet. That should
575   // happen in response to ShowCreatedWidget.
576   virtual RenderWidgetHostImpl* CreateNewPopupWidget(
577       AgentSchedulingGroupHost& agent_scheduling_group,
578       int32_t route_id,
579       mojo::PendingAssociatedReceiver<blink::mojom::PopupWidgetHost>
580           blink_popup_widget_host,
581       mojo::PendingAssociatedReceiver<blink::mojom::WidgetHost>
582           blink_widget_host,
583       mojo::PendingAssociatedRemote<blink::mojom::Widget> blink_widget);
584 
585   // Return true if the popup is shown through WebContentsObserver.
586   // BrowserPluginGuest for the guest WebContents will show the popup on Mac,
587   // then, we should skip to show the popup at RenderViewHostDelegateView.
588   virtual bool ShowPopupMenu(
589       RenderFrameHostImpl* render_frame_host,
590       mojo::PendingRemote<blink::mojom::PopupMenuClient>* popup_client,
591       const gfx::Rect& bounds,
592       int32_t item_height,
593       double font_size,
594       int32_t selected_item,
595       std::vector<blink::mojom::MenuItemPtr>* menu_items,
596       bool right_aligned,
597       bool allow_multiple_selection);
598 
DidLoadResourceFromMemoryCache(RenderFrameHostImpl * source,const GURL & url,const std::string & http_request,const std::string & mime_type,network::mojom::RequestDestination request_destination)599   virtual void DidLoadResourceFromMemoryCache(
600       RenderFrameHostImpl* source,
601       const GURL& url,
602       const std::string& http_request,
603       const std::string& mime_type,
604       network::mojom::RequestDestination request_destination) {}
605 
606   // Called when the renderer sends a response via DomAutomationController.
607   // For example, `window.domAutomationController.send(foo())` sends the result
608   // of foo() here.
DomOperationResponse(const std::string & json_string)609   virtual void DomOperationResponse(const std::string& json_string) {}
610 
OnCookiesAccessed(RenderFrameHostImpl * render_frame_host,const CookieAccessDetails & details)611   virtual void OnCookiesAccessed(RenderFrameHostImpl* render_frame_host,
612                                  const CookieAccessDetails& details) {}
613 
614   // Notified that the renderer responded after calling GetSavableResourceLinks.
SavableResourceLinksResponse(RenderFrameHostImpl * source,const std::vector<GURL> & resources_list,blink::mojom::ReferrerPtr referrer,const std::vector<blink::mojom::SavableSubframePtr> & subframes)615   virtual void SavableResourceLinksResponse(
616       RenderFrameHostImpl* source,
617       const std::vector<GURL>& resources_list,
618       blink::mojom::ReferrerPtr referrer,
619       const std::vector<blink::mojom::SavableSubframePtr>& subframes) {}
620 
621   // Notified that the renderer returned an error after calling
622   // GetSavableResourceLinks in case the frame contains non-savable content
623   // (i.e. from a non-savable scheme) or if there were errors gathering the
624   // links.
SavableResourceLinksError(RenderFrameHostImpl * source)625   virtual void SavableResourceLinksError(RenderFrameHostImpl* source) {}
626 
627   // Called when |RenderFrameHostImpl::lifecycle_state()| changes i.e., when
628   // RenderFrameHost LifecycleState changes from old_state to new_state.
RenderFrameHostStateChanged(RenderFrameHost * host,RenderFrameHostImpl::LifecycleState old_state,RenderFrameHostImpl::LifecycleState new_state)629   virtual void RenderFrameHostStateChanged(
630       RenderFrameHost* host,
631       RenderFrameHostImpl::LifecycleState old_state,
632       RenderFrameHostImpl::LifecycleState new_state) {}
633 
634   // The page is trying to move the main frame's representation in the client.
SetWindowRect(const gfx::Rect & new_bounds)635   virtual void SetWindowRect(const gfx::Rect& new_bounds) {}
636 
637  protected:
638   virtual ~RenderFrameHostDelegate() = default;
639 };
640 
641 }  // namespace content
642 
643 #endif  // CONTENT_BROWSER_RENDERER_HOST_RENDER_FRAME_HOST_DELEGATE_H_
644