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.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_
6 #define CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_
10 #include "base/basictypes.h"
11 #include "base/i18n/rtl.h"
12 #include "content/common/content_export.h"
13 #include "content/common/frame_message_enums.h"
14 #include "content/public/browser/site_instance.h"
15 #include "content/public/common/javascript_message_type.h"
16 #include "content/public/common/media_stream_request.h"
17 #include "net/http/http_response_headers.h"
20 #include "ui/gfx/native_widget_types.h"
30 class GeolocationServiceContext
;
31 class RenderFrameHost
;
33 struct AXEventNotificationDetails
;
34 struct ContextMenuParams
;
35 struct TransitionLayerData
;
37 // An interface implemented by an object interested in knowing about the state
38 // of the RenderFrameHost.
39 class CONTENT_EXPORT RenderFrameHostDelegate
{
41 // This is used to give the delegate a chance to filter IPC messages.
42 virtual bool OnMessageReceived(RenderFrameHost
* render_frame_host
,
43 const IPC::Message
& message
);
45 // Gets the last committed URL. See WebContents::GetLastCommittedURL for a
46 // description of the semantics.
47 virtual const GURL
& GetMainFrameLastCommittedURL() const;
49 // A message was added to to the console.
50 virtual bool AddMessageToConsole(int32 level
,
51 const base::string16
& message
,
53 const base::string16
& source_id
);
55 // Informs the delegate whenever a RenderFrameHost is created.
56 virtual void RenderFrameCreated(RenderFrameHost
* render_frame_host
) {}
58 // Informs the delegate whenever a RenderFrameHost is deleted.
59 virtual void RenderFrameDeleted(RenderFrameHost
* render_frame_host
) {}
61 // The RenderFrameHost has been swapped out.
62 virtual void SwappedOut(RenderFrameHost
* render_frame_host
) {}
64 // Notification that the navigation on the main frame is blocked waiting
65 // for transition to occur.
66 virtual void DidDeferAfterResponseStarted(
67 const TransitionLayerData
& transition_data
) {}
69 // Used to query whether the navigation transition will be handled.
70 virtual bool WillHandleDeferAfterResponseStarted();
72 // Notification that a worker process has crashed.
73 virtual void WorkerCrashed(RenderFrameHost
* render_frame_host
) {}
75 // A context menu should be shown, to be built using the context information
76 // provided in the supplied params.
77 virtual void ShowContextMenu(RenderFrameHost
* render_frame_host
,
78 const ContextMenuParams
& params
) {}
80 // A JavaScript message, confirmation or prompt should be shown.
81 virtual void RunJavaScriptMessage(RenderFrameHost
* render_frame_host
,
82 const base::string16
& message
,
83 const base::string16
& default_prompt
,
84 const GURL
& frame_url
,
85 JavaScriptMessageType type
,
86 IPC::Message
* reply_msg
) {}
88 virtual void RunBeforeUnloadConfirm(RenderFrameHost
* render_frame_host
,
89 const base::string16
& message
,
91 IPC::Message
* reply_msg
) {}
93 // Another page accessed the top-level initial empty document, which means it
94 // is no longer safe to display a pending URL without risking a URL spoof.
95 virtual void DidAccessInitialDocument() {}
97 // The frame changed its window.name property.
98 virtual void DidChangeName(RenderFrameHost
* render_frame_host
,
99 const std::string
& name
) {}
101 // The frame set its opener to null, disowning it for the lifetime of the
102 // window. Only called for the top-level frame.
103 virtual void DidDisownOpener(RenderFrameHost
* render_frame_host
) {}
105 // The onload handler in the frame has completed. Only called for the top-
107 virtual void DocumentOnLoadCompleted(RenderFrameHost
* render_frame_host
) {}
109 // The page's title was changed and should be updated. Only called for the
111 virtual void UpdateTitle(RenderFrameHost
* render_frame_host
,
113 const base::string16
& title
,
114 base::i18n::TextDirection title_direction
) {}
116 // The page's encoding was changed and should be updated. Only called for the
118 virtual void UpdateEncoding(RenderFrameHost
* render_frame_host
,
119 const std::string
& encoding
) {}
121 // Return this object cast to a WebContents, if it is one. If the object is
122 // not a WebContents, returns NULL.
123 virtual WebContents
* GetAsWebContents();
125 // The render frame has requested access to media devices listed in
126 // |request|, and the client should grant or deny that permission by
127 // calling |callback|.
128 virtual void RequestMediaAccessPermission(
129 const MediaStreamRequest
& request
,
130 const MediaResponseCallback
& callback
);
132 // Checks if we have permission to access the microphone or camera. Note that
133 // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
134 // or MEDIA_DEVICE_VIDEO_CAPTURE.
135 virtual bool CheckMediaAccessPermission(const GURL
& security_origin
,
136 MediaStreamType type
);
138 // Get the accessibility mode for the WebContents that owns this frame.
139 virtual AccessibilityMode
GetAccessibilityMode() const;
141 // Invoked when an accessibility event is received from the renderer.
142 virtual void AccessibilityEventReceived(
143 const std::vector
<AXEventNotificationDetails
>& details
) {}
145 // Find a guest RenderFrameHost by its parent |render_frame_host| and
146 // |browser_plugin_instance_id|.
147 virtual RenderFrameHost
* GetGuestByInstanceID(
148 RenderFrameHost
* render_frame_host
,
149 int browser_plugin_instance_id
);
151 // Gets the GeolocationServiceContext associated with this delegate.
152 virtual GeolocationServiceContext
* GetGeolocationServiceContext();
154 // Notification that the frame wants to go into fullscreen mode.
155 // |origin| represents the origin of the frame that requests fullscreen.
156 virtual void EnterFullscreenMode(const GURL
& origin
) {}
158 // Notification that the frame wants to go out of fullscreen mode.
159 virtual void ExitFullscreenMode() {}
161 // Let the delegate decide whether postMessage should be delivered to
162 // |target_rfh| from a source frame in the given SiteInstance. This defaults
163 // to false and overrides the RenderFrameHost's decision if true.
164 virtual bool ShouldRouteMessageEvent(
165 RenderFrameHost
* target_rfh
,
166 SiteInstance
* source_site_instance
) const;
168 // Ensure that |source_rfh| has swapped-out RenderViews and proxies for
169 // itself and for each frame on its opener chain in the current frame's
170 // SiteInstance. Returns the routing ID of the swapped-out RenderView
171 // corresponding to |source_rfh|.
173 // TODO(alexmos): This method will be removed once opener tracking and
174 // CreateOpenerRenderViews moves out of WebContents and into lower layers, as
175 // part of https://crbug.com/225940. Currently, this method temporarily
176 // supports cross-process postMessage in non-site-per-process mode, where we
177 // need to create any missing proxies for the message's source frame and its
178 // opener chain on demand.
179 virtual int EnsureOpenerRenderViewsExist(RenderFrameHost
* source_rfh
);
182 // Returns the frame's parent's NativeViewAccessible.
183 virtual gfx::NativeViewAccessible
GetParentNativeViewAccessible();
187 virtual ~RenderFrameHostDelegate() {}
190 } // namespace content
192 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_