Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / public / renderer / content_renderer_client.h
blobca4d51db881f8d8310f9e2fac5d4ce8c79d77974
1 // Copyright (c) 2012 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_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
6 #define CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
8 #include <string>
9 #include <vector>
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "content/public/common/content_client.h"
16 #include "ipc/ipc_message.h"
17 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h"
18 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
19 #include "third_party/WebKit/public/web/WebNavigationType.h"
20 #include "ui/base/page_transition_types.h"
21 #include "v8/include/v8.h"
23 class GURL;
24 class SkBitmap;
26 namespace base {
27 class FilePath;
28 class SingleThreadTaskRunner;
31 namespace blink {
32 class WebAudioDevice;
33 class WebClipboard;
34 class WebFrame;
35 class WebLocalFrame;
36 class WebMIDIAccessor;
37 class WebMIDIAccessorClient;
38 class WebMediaStreamCenter;
39 class WebMediaStreamCenterClient;
40 class WebPlugin;
41 class WebPluginContainer;
42 class WebPluginPlaceholder;
43 class WebPrescientNetworking;
44 class WebRTCPeerConnectionHandler;
45 class WebRTCPeerConnectionHandlerClient;
46 class WebSpeechSynthesizer;
47 class WebSpeechSynthesizerClient;
48 class WebThemeEngine;
49 class WebURLRequest;
50 class WebWorkerContentSettingsClientProxy;
51 struct WebPluginParams;
52 struct WebURLError;
55 namespace media {
56 class MediaLog;
57 class RendererFactory;
58 struct KeySystemInfo;
61 namespace content {
62 class BrowserPluginDelegate;
63 class DocumentState;
64 class RenderFrame;
65 class RenderView;
66 class SynchronousCompositor;
67 struct WebPluginInfo;
69 // Embedder API for participating in renderer logic.
70 class CONTENT_EXPORT ContentRendererClient {
71 public:
72 virtual ~ContentRendererClient() {}
74 // Notifies us that the RenderThread has been created.
75 virtual void RenderThreadStarted() {}
77 // Notifies that a new RenderFrame has been created. Note that at this point,
78 // render_frame->GetWebFrame()->parent() is always NULL. This will change once
79 // the frame tree moves from Blink to content.
80 virtual void RenderFrameCreated(RenderFrame* render_frame) {}
82 // Notifies that a new RenderView has been created.
83 virtual void RenderViewCreated(RenderView* render_view) {}
85 // Returns the bitmap to show when a plugin crashed, or NULL for none.
86 virtual SkBitmap* GetSadPluginBitmap();
88 // Returns the bitmap to show when a <webview> guest has crashed, or NULL for
89 // none.
90 virtual SkBitmap* GetSadWebViewBitmap();
92 // Allows the embedder to create a plugin placeholder instead of a plugin.
93 // Called before OverrideCreatePlugin. May return null to decline to provide
94 // a plugin placeholder.
95 virtual scoped_ptr<blink::WebPluginPlaceholder> CreatePluginPlaceholder(
96 RenderFrame* render_frame,
97 blink::WebLocalFrame* frame,
98 const blink::WebPluginParams& params);
100 // Allows the embedder to override creating a plugin. If it returns true, then
101 // |plugin| will contain the created plugin, although it could be NULL. If it
102 // returns false, the content layer will create the plugin.
103 virtual bool OverrideCreatePlugin(
104 RenderFrame* render_frame,
105 blink::WebLocalFrame* frame,
106 const blink::WebPluginParams& params,
107 blink::WebPlugin** plugin);
109 // Creates a replacement plugin that is shown when the plugin at |file_path|
110 // couldn't be loaded. This allows the embedder to show a custom placeholder.
111 virtual blink::WebPlugin* CreatePluginReplacement(
112 RenderFrame* render_frame,
113 const base::FilePath& plugin_path);
115 // Creates a delegate for browser plugin.
116 virtual BrowserPluginDelegate* CreateBrowserPluginDelegate(
117 RenderFrame* render_frame,
118 const std::string& mime_type,
119 const GURL& original_url);
121 // Returns true if the embedder has an error page to show for the given http
122 // status code. If so |error_domain| should be set to according to WebURLError
123 // and the embedder's GetNavigationErrorHtml will be called afterwards to get
124 // the error html.
125 virtual bool HasErrorPage(int http_status_code,
126 std::string* error_domain);
128 // Returns true if the embedder prefers not to show an error page for a failed
129 // navigation to |url| in |render_frame|.
130 virtual bool ShouldSuppressErrorPage(RenderFrame* render_frame,
131 const GURL& url);
133 // Returns the information to display when a navigation error occurs.
134 // If |error_html| is not null then it may be set to a HTML page containing
135 // the details of the error and maybe links to more info.
136 // If |error_description| is not null it may be set to contain a brief
137 // message describing the error that has occurred.
138 // Either of the out parameters may be not written to in certain cases
139 // (lack of information on the error code) so the caller should take care to
140 // initialize the string values with safe defaults before the call.
141 virtual void GetNavigationErrorStrings(
142 content::RenderView* render_view,
143 blink::WebFrame* frame,
144 const blink::WebURLRequest& failed_request,
145 const blink::WebURLError& error,
146 std::string* error_html,
147 base::string16* error_description) {}
149 // Allows the embedder to control when media resources are loaded. Embedders
150 // can run |closure| immediately if they don't wish to defer media resource
151 // loading.
152 virtual void DeferMediaLoad(RenderFrame* render_frame,
153 const base::Closure& closure);
155 // Allows the embedder to override creating a WebMediaStreamCenter. If it
156 // returns NULL the content layer will create the stream center.
157 virtual blink::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter(
158 blink::WebMediaStreamCenterClient* client);
160 // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If
161 // it returns NULL the content layer will create the connection handler.
162 virtual blink::WebRTCPeerConnectionHandler*
163 OverrideCreateWebRTCPeerConnectionHandler(
164 blink::WebRTCPeerConnectionHandlerClient* client);
166 // Allows the embedder to override creating a WebMIDIAccessor. If it
167 // returns NULL the content layer will create the MIDI accessor.
168 virtual blink::WebMIDIAccessor* OverrideCreateMIDIAccessor(
169 blink::WebMIDIAccessorClient* client);
171 // Allows the embedder to override creating a WebAudioDevice. If it
172 // returns NULL the content layer will create the audio device.
173 virtual blink::WebAudioDevice* OverrideCreateAudioDevice(
174 double sample_rate);
176 // Allows the embedder to override the blink::WebClipboard used. If it
177 // returns NULL the content layer will handle clipboard interactions.
178 virtual blink::WebClipboard* OverrideWebClipboard();
180 // Allows the embedder to override the WebThemeEngine used. If it returns NULL
181 // the content layer will provide an engine.
182 virtual blink::WebThemeEngine* OverrideThemeEngine();
184 // Allows the embedder to override the WebSpeechSynthesizer used.
185 // If it returns NULL the content layer will provide an engine.
186 virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
187 blink::WebSpeechSynthesizerClient* client);
189 // Returns true if the renderer process should schedule the idle handler when
190 // all widgets are hidden.
191 virtual bool RunIdleHandlerWhenWidgetsHidden();
193 // Returns true if a popup window should be allowed.
194 virtual bool AllowPopup();
196 #ifdef OS_ANDROID
197 // TODO(sgurun) This callback is deprecated and will be removed as soon
198 // as android webview completes implementation of a resource throttle based
199 // shouldoverrideurl implementation. See crbug.com/325351
201 // Returns true if the navigation was handled by the embedder and should be
202 // ignored by WebKit. This method is used by CEF and android_webview.
203 virtual bool HandleNavigation(RenderFrame* render_frame,
204 DocumentState* document_state,
205 int opener_id,
206 blink::WebFrame* frame,
207 const blink::WebURLRequest& request,
208 blink::WebNavigationType type,
209 blink::WebNavigationPolicy default_policy,
210 bool is_redirect);
211 #endif
213 // Returns true if we should fork a new process for the given navigation.
214 // If |send_referrer| is set to false (which is the default), no referrer
215 // header will be send for the navigation. Otherwise, the referrer header is
216 // set according to the frame's referrer policy.
217 virtual bool ShouldFork(blink::WebFrame* frame,
218 const GURL& url,
219 const std::string& http_method,
220 bool is_initial_navigation,
221 bool is_server_redirect,
222 bool* send_referrer);
224 // Returns true if this IPC message belongs to a guest container. Currently,
225 // BrowserPlugin is a guest container.
226 virtual bool ShouldForwardToGuestContainer(const IPC::Message& msg);
228 // Notifies the embedder that the given frame is requesting the resource at
229 // |url|. If the function returns true, the url is changed to |new_url|.
230 virtual bool WillSendRequest(blink::WebFrame* frame,
231 ui::PageTransition transition_type,
232 const GURL& url,
233 const GURL& first_party_for_cookies,
234 GURL* new_url);
236 // See blink::Platform.
237 virtual unsigned long long VisitedLinkHash(const char* canonical_url,
238 size_t length);
239 virtual bool IsLinkVisited(unsigned long long link_hash);
240 virtual blink::WebPrescientNetworking* GetPrescientNetworking();
241 virtual bool ShouldOverridePageVisibilityState(
242 const RenderFrame* render_frame,
243 blink::WebPageVisibilityState* override_state);
245 // Allows an embedder to return custom PPAPI interfaces.
246 virtual const void* CreatePPAPIInterface(
247 const std::string& interface_name);
249 // Returns true if the given Pepper plugin is external (requiring special
250 // startup steps).
251 virtual bool IsExternalPepperPlugin(const std::string& module_name);
253 // Returns true if the page at |url| can use Pepper MediaStream APIs.
254 virtual bool AllowPepperMediaStreamAPI(const GURL& url);
256 // Allows an embedder to provide a media::RendererFactory.
257 virtual scoped_ptr<media::RendererFactory> CreateMediaRendererFactory(
258 RenderFrame* render_frame,
259 const scoped_refptr<media::MediaLog>& media_log);
261 // Gives the embedder a chance to register the key system(s) it supports by
262 // populating |key_systems|.
263 virtual void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems);
265 // Returns true if we should report a detailed message (including a stack
266 // trace) for console [logs|errors|exceptions]. |source| is the WebKit-
267 // reported source for the error; this can point to a page or a script,
268 // and can be external or internal.
269 virtual bool ShouldReportDetailedMessageForSource(
270 const base::string16& source) const;
272 // Returns true if we should apply the cross-site document blocking policy to
273 // this renderer process. Currently, we apply the policy only to a renderer
274 // process running on a normal page from the web.
275 virtual bool ShouldEnableSiteIsolationPolicy() const;
277 // Creates a permission client proxy for in-renderer worker.
278 virtual blink::WebWorkerContentSettingsClientProxy*
279 CreateWorkerContentSettingsClientProxy(RenderFrame* render_frame,
280 blink::WebFrame* frame);
282 // Returns true if the page at |url| can use Pepper CameraDevice APIs.
283 virtual bool IsPluginAllowedToUseCameraDeviceAPI(const GURL& url);
285 // Returns true if the page at |url| can use Pepper Compositor APIs.
286 virtual bool IsPluginAllowedToUseCompositorAPI(const GURL& url);
288 // Returns true if dev channel APIs are available for plugins.
289 virtual bool IsPluginAllowedToUseDevChannelAPIs();
291 // Returns a user agent override specific for |url|, or empty string if
292 // default user agent should be used.
293 virtual std::string GetUserAgentOverrideForURL(const GURL& url);
296 } // namespace content
298 #endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_