Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / frame_host / render_frame_host_delegate.h
blob56b563474e07c071f2f250fbf98e4b150b82258f
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_
8 #include <vector>
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/common/javascript_message_type.h"
15 #include "content/public/common/media_stream_request.h"
16 #include "net/http/http_response_headers.h"
18 #if defined(OS_WIN)
19 #include "ui/gfx/native_widget_types.h"
20 #endif
22 class GURL;
24 namespace IPC {
25 class Message;
28 namespace content {
29 class GeolocationServiceContext;
30 class RenderFrameHost;
31 class WebContents;
32 struct AXEventNotificationDetails;
33 struct ContextMenuParams;
34 struct TransitionLayerData;
36 // An interface implemented by an object interested in knowing about the state
37 // of the RenderFrameHost.
38 class CONTENT_EXPORT RenderFrameHostDelegate {
39 public:
40 // This is used to give the delegate a chance to filter IPC messages.
41 virtual bool OnMessageReceived(RenderFrameHost* render_frame_host,
42 const IPC::Message& message);
44 // Gets the last committed URL. See WebContents::GetLastCommittedURL for a
45 // description of the semantics.
46 virtual const GURL& GetMainFrameLastCommittedURL() const;
48 // A message was added to to the console.
49 virtual bool AddMessageToConsole(int32 level,
50 const base::string16& message,
51 int32 line_no,
52 const base::string16& source_id);
54 // Informs the delegate whenever a RenderFrameHost is created.
55 virtual void RenderFrameCreated(RenderFrameHost* render_frame_host) {}
57 // Informs the delegate whenever a RenderFrameHost is deleted.
58 virtual void RenderFrameDeleted(RenderFrameHost* render_frame_host) {}
60 // The specified RenderFrame began loading a new page. This corresponds to
61 // Blink's notion of the throbber starting.
62 // |to_different_document| will be true unless the load is a fragment
63 // navigation, or triggered by history.pushState/replaceState.
64 virtual void DidStartLoading(RenderFrameHost* render_frame_host,
65 bool to_different_document) {}
67 // The specified RenderFrame stopped loading a page. This corresponds to
68 // Blink's notion of the throbber stopping.
69 virtual void DidStopLoading() {}
71 // The RenderFrameHost has been swapped out.
72 virtual void SwappedOut(RenderFrameHost* render_frame_host) {}
74 // Notification that the navigation on the main frame is blocked waiting
75 // for transition to occur.
76 virtual void DidDeferAfterResponseStarted(
77 const TransitionLayerData& transition_data) {}
79 // Used to query whether the navigation transition will be handled.
80 virtual bool WillHandleDeferAfterResponseStarted();
82 // Notification that a worker process has crashed.
83 virtual void WorkerCrashed(RenderFrameHost* render_frame_host) {}
85 // A context menu should be shown, to be built using the context information
86 // provided in the supplied params.
87 virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
88 const ContextMenuParams& params) {}
90 // A JavaScript message, confirmation or prompt should be shown.
91 virtual void RunJavaScriptMessage(RenderFrameHost* render_frame_host,
92 const base::string16& message,
93 const base::string16& default_prompt,
94 const GURL& frame_url,
95 JavaScriptMessageType type,
96 IPC::Message* reply_msg) {}
98 virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host,
99 const base::string16& message,
100 bool is_reload,
101 IPC::Message* reply_msg) {}
103 // Another page accessed the top-level initial empty document, which means it
104 // is no longer safe to display a pending URL without risking a URL spoof.
105 virtual void DidAccessInitialDocument() {}
107 // The frame changed its window.name property.
108 virtual void DidChangeName(RenderFrameHost* render_frame_host,
109 const std::string& name) {}
111 // The frame set its opener to null, disowning it for the lifetime of the
112 // window. Only called for the top-level frame.
113 virtual void DidDisownOpener(RenderFrameHost* render_frame_host) {}
115 // The onload handler in the frame has completed. Only called for the top-
116 // level frame.
117 virtual void DocumentOnLoadCompleted(RenderFrameHost* render_frame_host) {}
119 // The page's title was changed and should be updated. Only called for the
120 // top-level frame.
121 virtual void UpdateTitle(RenderFrameHost* render_frame_host,
122 int32 page_id,
123 const base::string16& title,
124 base::i18n::TextDirection title_direction) {}
126 // The page's encoding was changed and should be updated. Only called for the
127 // top-level frame.
128 virtual void UpdateEncoding(RenderFrameHost* render_frame_host,
129 const std::string& encoding) {}
131 // Return this object cast to a WebContents, if it is one. If the object is
132 // not a WebContents, returns NULL.
133 virtual WebContents* GetAsWebContents();
135 // The render frame has requested access to media devices listed in
136 // |request|, and the client should grant or deny that permission by
137 // calling |callback|.
138 virtual void RequestMediaAccessPermission(
139 const MediaStreamRequest& request,
140 const MediaResponseCallback& callback);
142 // Checks if we have permission to access the microphone or camera. Note that
143 // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
144 // or MEDIA_DEVICE_VIDEO_CAPTURE.
145 virtual bool CheckMediaAccessPermission(const GURL& security_origin,
146 MediaStreamType type);
148 // Get the accessibility mode for the WebContents that owns this frame.
149 virtual AccessibilityMode GetAccessibilityMode() const;
151 // Invoked when an accessibility event is received from the renderer.
152 virtual void AccessibilityEventReceived(
153 const std::vector<AXEventNotificationDetails>& details) {}
155 // Find a guest RenderFrameHost by its parent |render_frame_host| and
156 // |browser_plugin_instance_id|.
157 virtual RenderFrameHost* GetGuestByInstanceID(
158 RenderFrameHost* render_frame_host,
159 int browser_plugin_instance_id);
161 // Gets the GeolocationServiceContext associated with this delegate.
162 virtual GeolocationServiceContext* GetGeolocationServiceContext();
164 // Notification that the frame wants to go into fullscreen mode.
165 // |origin| represents the origin of the frame that requests fullscreen.
166 virtual void EnterFullscreenMode(const GURL& origin) {}
168 // Notification that the frame wants to go out of fullscreen mode.
169 virtual void ExitFullscreenMode() {}
171 #if defined(OS_WIN)
172 // Returns the frame's parent's NativeViewAccessible.
173 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible();
174 #endif
176 protected:
177 virtual ~RenderFrameHostDelegate() {}
180 } // namespace content
182 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_