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/common/javascript_message_type.h"
15 #include "content/public/common/media_stream_request.h"
16 #include "net/http/http_response_headers.h"
19 #include "ui/gfx/native_widget_types.h"
29 class GeolocationServiceContext;
30 class RenderFrameHost;
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 {
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,
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 top-level 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 RenderFrameHost has been swapped out.
68 virtual void SwappedOut(RenderFrameHost* render_frame_host) {}
70 // Notification that the navigation on the main frame is blocked waiting
71 // for transition to occur.
72 virtual void DidDeferAfterResponseStarted(
73 const TransitionLayerData& transition_data) {}
75 // Used to query whether the navigation transition will be handled.
76 virtual bool WillHandleDeferAfterResponseStarted();
78 // Notification that a worker process has crashed.
79 virtual void WorkerCrashed(RenderFrameHost* render_frame_host) {}
81 // A context menu should be shown, to be built using the context information
82 // provided in the supplied params.
83 virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
84 const ContextMenuParams& params) {}
86 // A JavaScript message, confirmation or prompt should be shown.
87 virtual void RunJavaScriptMessage(RenderFrameHost* render_frame_host,
88 const base::string16& message,
89 const base::string16& default_prompt,
90 const GURL& frame_url,
91 JavaScriptMessageType type,
92 IPC::Message* reply_msg) {}
94 virtual void RunBeforeUnloadConfirm(RenderFrameHost* render_frame_host,
95 const base::string16& message,
97 IPC::Message* reply_msg) {}
99 // Another page accessed the top-level initial empty document, which means it
100 // is no longer safe to display a pending URL without risking a URL spoof.
101 virtual void DidAccessInitialDocument() {}
103 // The frame set its opener to null, disowning it for the lifetime of the
104 // window. Only called for the top-level frame.
105 virtual void DidDisownOpener(RenderFrameHost* render_frame_host) {}
107 // The onload handler in the frame has completed. Only called for the top-
109 virtual void DocumentOnLoadCompleted(RenderFrameHost* render_frame_host) {}
111 // The page's title was changed and should be updated. Only called for the
113 virtual void UpdateTitle(RenderFrameHost* render_frame_host,
115 const base::string16& title,
116 base::i18n::TextDirection title_direction) {}
118 // The page's encoding was changed and should be updated. Only called for the
120 virtual void UpdateEncoding(RenderFrameHost* render_frame_host,
121 const std::string& encoding) {}
123 // Return this object cast to a WebContents, if it is one. If the object is
124 // not a WebContents, returns NULL.
125 virtual WebContents* GetAsWebContents();
127 // The render frame has requested access to media devices listed in
128 // |request|, and the client should grant or deny that permission by
129 // calling |callback|.
130 virtual void RequestMediaAccessPermission(
131 const MediaStreamRequest& request,
132 const MediaResponseCallback& callback);
134 // Checks if we have permission to access the microphone or camera. Note that
135 // this does not query the user. |type| must be MEDIA_DEVICE_AUDIO_CAPTURE
136 // or MEDIA_DEVICE_VIDEO_CAPTURE.
137 virtual bool CheckMediaAccessPermission(const GURL& security_origin,
138 MediaStreamType type);
140 // Get the accessibility mode for the WebContents that owns this frame.
141 virtual AccessibilityMode GetAccessibilityMode() const;
143 // Invoked when an accessibility event is received from the renderer.
144 virtual void AccessibilityEventReceived(
145 const std::vector<AXEventNotificationDetails>& details) {}
147 // Find a guest RenderFrameHost by its browser plugin instance id.
148 virtual RenderFrameHost* GetGuestByInstanceID(
149 int browser_plugin_instance_id);
151 // Gets the GeolocationServiceContext associated with this delegate.
152 virtual GeolocationServiceContext* GetGeolocationServiceContext();
155 // Returns the frame's parent's NativeViewAccessible.
156 virtual gfx::NativeViewAccessible GetParentNativeViewAccessible();
160 virtual ~RenderFrameHostDelegate() {}
163 } // namespace content
165 #endif // CONTENT_BROWSER_FRAME_HOST_RENDER_FRAME_HOST_DELEGATE_H_