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 a worker process has crashed.
65 virtual void WorkerCrashed(RenderFrameHost
* render_frame_host
) {}
67 // A context menu should be shown, to be built using the context information
68 // provided in the supplied params.
69 virtual void ShowContextMenu(RenderFrameHost
* render_frame_host
,
70 const ContextMenuParams
& params
) {}
72 // A JavaScript message, confirmation or prompt should be shown.
73 virtual void RunJavaScriptMessage(RenderFrameHost
* render_frame_host
,
74 const base::string16
& message
,
75 const base::string16
& default_prompt
,
76 const GURL
& frame_url
,
77 JavaScriptMessageType type
,
78 IPC::Message
* reply_msg
) {}
80 virtual void RunBeforeUnloadConfirm(RenderFrameHost
* render_frame_host
,
81 const base::string16
& message
,
83 IPC::Message
* reply_msg
) {}
85 // Another page accessed the top-level initial empty document, which means it
86 // is no longer safe to display a pending URL without risking a URL spoof.
87 virtual void DidAccessInitialDocument() {}
89 // The frame changed its window.name property.
90 virtual void DidChangeName(RenderFrameHost
* render_frame_host
,
91 const std::string
& name
) {}
93 // The onload handler in the frame has completed. Only called for the top-
95 virtual void DocumentOnLoadCompleted(RenderFrameHost
* render_frame_host
) {}
97 // The page's title was changed and should be updated. Only called for the
99 virtual void UpdateTitle(RenderFrameHost
* render_frame_host
,
101 const base::string16
& title
,
102 base::i18n::TextDirection title_direction
) {}
104 // The page's encoding was changed and should be updated. Only called for the
106 virtual void UpdateEncoding(RenderFrameHost
* render_frame_host
,
107 const std::string
& encoding
) {}
109 // Return this object cast to a WebContents, if it is one. If the object is
110 // not a WebContents, returns NULL.
111 virtual WebContents
* GetAsWebContents();
113 // The render frame has requested access to media devices listed in
114 // |request|, and the client should grant or deny that permission by
115 // calling |callback|.
116 virtual void RequestMediaAccessPermission(
117 const MediaStreamRequest
& request
,
118 const MediaResponseCallback
& callback
);
120 // Checks if we have permission to access the microphone or camera. Note that
121 // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
122 // or MEDIA_DEVICE_VIDEO_CAPTURE.
123 virtual bool CheckMediaAccessPermission(const GURL
& security_origin
,
124 MediaStreamType type
);
126 // Get the accessibility mode for the WebContents that owns this frame.
127 virtual AccessibilityMode
GetAccessibilityMode() const;
129 // Invoked when an accessibility event is received from the renderer.
130 virtual void AccessibilityEventReceived(
131 const std::vector
<AXEventNotificationDetails
>& details
) {}
133 // Find a guest RenderFrameHost by its parent |render_frame_host| and
134 // |browser_plugin_instance_id|.
135 virtual RenderFrameHost
* GetGuestByInstanceID(
136 RenderFrameHost
* render_frame_host
,
137 int browser_plugin_instance_id
);
139 // Gets the GeolocationServiceContext associated with this delegate.
140 virtual GeolocationServiceContext
* GetGeolocationServiceContext();
142 // Notification that the frame wants to go into fullscreen mode.
143 // |origin| represents the origin of the frame that requests fullscreen.
144 virtual void EnterFullscreenMode(const GURL
& origin
) {}
146 // Notification that the frame wants to go out of fullscreen mode.
147 virtual void ExitFullscreenMode() {}
149 // Let the delegate decide whether postMessage should be delivered to
150 // |target_rfh| from a source frame in the given SiteInstance. This defaults
151 // to false and overrides the RenderFrameHost's decision if true.
152 virtual bool ShouldRouteMessageEvent(
153 RenderFrameHost
* target_rfh
,
154 SiteInstance
* source_site_instance
) const;
156 // Ensure that |source_rfh| has swapped-out RenderViews and proxies for
157 // itself and for each frame on its opener chain in the current frame's
158 // SiteInstance. Returns the routing ID of the swapped-out RenderView
159 // corresponding to |source_rfh|.
161 // TODO(alexmos): This method will be removed once opener tracking and
162 // CreateOpenerRenderViews moves out of WebContents and into lower layers, as
163 // part of https://crbug.com/225940. Currently, this method temporarily
164 // supports cross-process postMessage in non-site-per-process mode, where we
165 // need to create any missing proxies for the message's source frame and its
166 // opener chain on demand.
167 virtual int EnsureOpenerRenderViewsExist(RenderFrameHost
* source_rfh
);
170 // Returns the frame's parent's NativeViewAccessible.
171 virtual gfx::NativeViewAccessible
GetParentNativeViewAccessible();
175 virtual ~RenderFrameHostDelegate() {}
178 } // namespace content
180 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_