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_
12 #include "base/bind.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/strings/string16.h"
17 #include "content/public/common/content_client.h"
18 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h"
19 #include "ui/base/page_transition_types.h"
20 #include "v8/include/v8.h"
27 class SingleThreadTaskRunner
;
31 class WebAppBannerClient
;
36 class WebMIDIAccessor
;
37 class WebMIDIAccessorClient
;
38 class WebMediaStreamCenter
;
39 class WebMediaStreamCenterClient
;
41 class WebPluginContainer
;
42 class WebPluginPlaceholder
;
43 class WebPrescientNetworking
;
44 class WebRTCPeerConnectionHandler
;
45 class WebRTCPeerConnectionHandlerClient
;
46 class WebSpeechSynthesizer
;
47 class WebSpeechSynthesizerClient
;
51 class WebWorkerContentSettingsClientProxy
;
52 struct WebPluginParams
;
57 class GpuVideoAcceleratorFactories
;
59 class RendererFactory
;
64 class BrowserPluginDelegate
;
66 class MediaStreamRendererFactory
;
69 class SynchronousCompositor
;
72 // Embedder API for participating in renderer logic.
73 class CONTENT_EXPORT ContentRendererClient
{
75 virtual ~ContentRendererClient() {}
77 // Notifies us that the RenderThread has been created.
78 virtual void RenderThreadStarted() {}
80 // Notifies that a new RenderFrame has been created. Note that at this point,
81 // render_frame->GetWebFrame()->parent() is always NULL. This will change once
82 // the frame tree moves from Blink to content.
83 virtual void RenderFrameCreated(RenderFrame
* render_frame
) {}
85 // Notifies that a new RenderView has been created.
86 virtual void RenderViewCreated(RenderView
* render_view
) {}
88 // Returns the bitmap to show when a plugin crashed, or NULL for none.
89 virtual SkBitmap
* GetSadPluginBitmap();
91 // Returns the bitmap to show when a <webview> guest has crashed, or NULL for
93 virtual SkBitmap
* GetSadWebViewBitmap();
95 // Allows the embedder to create a plugin placeholder instead of a plugin.
96 // Called before OverrideCreatePlugin. May return null to decline to provide
97 // a plugin placeholder.
98 virtual scoped_ptr
<blink::WebPluginPlaceholder
> CreatePluginPlaceholder(
99 RenderFrame
* render_frame
,
100 blink::WebLocalFrame
* frame
,
101 const blink::WebPluginParams
& params
);
103 // Allows the embedder to override creating a plugin. If it returns true, then
104 // |plugin| will contain the created plugin, although it could be NULL. If it
105 // returns false, the content layer will create the plugin.
106 virtual bool OverrideCreatePlugin(
107 RenderFrame
* render_frame
,
108 blink::WebLocalFrame
* frame
,
109 const blink::WebPluginParams
& params
,
110 blink::WebPlugin
** plugin
);
112 // Creates a replacement plugin that is shown when the plugin at |file_path|
113 // couldn't be loaded. This allows the embedder to show a custom placeholder.
114 virtual blink::WebPlugin
* CreatePluginReplacement(
115 RenderFrame
* render_frame
,
116 const base::FilePath
& plugin_path
);
118 // Creates a delegate for browser plugin.
119 virtual BrowserPluginDelegate
* CreateBrowserPluginDelegate(
120 RenderFrame
* render_frame
,
121 const std::string
& mime_type
,
122 const GURL
& original_url
);
124 // Returns true if the embedder has an error page to show for the given http
125 // status code. If so |error_domain| should be set to according to WebURLError
126 // and the embedder's GetNavigationErrorHtml will be called afterwards to get
128 virtual bool HasErrorPage(int http_status_code
,
129 std::string
* error_domain
);
131 // Returns true if the embedder prefers not to show an error page for a failed
132 // navigation to |url| in |render_frame|.
133 virtual bool ShouldSuppressErrorPage(RenderFrame
* render_frame
,
136 // Returns the information to display when a navigation error occurs.
137 // If |error_html| is not null then it may be set to a HTML page containing
138 // the details of the error and maybe links to more info.
139 // If |error_description| is not null it may be set to contain a brief
140 // message describing the error that has occurred.
141 // Either of the out parameters may be not written to in certain cases
142 // (lack of information on the error code) so the caller should take care to
143 // initialize the string values with safe defaults before the call.
144 virtual void GetNavigationErrorStrings(
145 content::RenderView
* render_view
,
146 blink::WebFrame
* frame
,
147 const blink::WebURLRequest
& failed_request
,
148 const blink::WebURLError
& error
,
149 std::string
* error_html
,
150 base::string16
* error_description
) {}
152 // Allows the embedder to control when media resources are loaded. Embedders
153 // can run |closure| immediately if they don't wish to defer media resource
155 virtual void DeferMediaLoad(RenderFrame
* render_frame
,
156 const base::Closure
& closure
);
158 // Allows the embedder to override creating a WebMediaStreamCenter. If it
159 // returns NULL the content layer will create the stream center.
160 virtual blink::WebMediaStreamCenter
* OverrideCreateWebMediaStreamCenter(
161 blink::WebMediaStreamCenterClient
* client
);
163 // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If
164 // it returns NULL the content layer will create the connection handler.
165 virtual blink::WebRTCPeerConnectionHandler
*
166 OverrideCreateWebRTCPeerConnectionHandler(
167 blink::WebRTCPeerConnectionHandlerClient
* client
);
169 // Allows the embedder to override creating a WebMIDIAccessor. If it
170 // returns NULL the content layer will create the MIDI accessor.
171 virtual blink::WebMIDIAccessor
* OverrideCreateMIDIAccessor(
172 blink::WebMIDIAccessorClient
* client
);
174 // Allows the embedder to override creating a WebAudioDevice. If it
175 // returns NULL the content layer will create the audio device.
176 virtual blink::WebAudioDevice
* OverrideCreateAudioDevice(
179 // Allows the embedder to override the blink::WebClipboard used. If it
180 // returns NULL the content layer will handle clipboard interactions.
181 virtual blink::WebClipboard
* OverrideWebClipboard();
183 // Allows the embedder to override the WebThemeEngine used. If it returns NULL
184 // the content layer will provide an engine.
185 virtual blink::WebThemeEngine
* OverrideThemeEngine();
187 // Allows the embedder to override the WebSpeechSynthesizer used.
188 // If it returns NULL the content layer will provide an engine.
189 virtual blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
190 blink::WebSpeechSynthesizerClient
* client
);
192 // Returns true if the renderer process should schedule the idle handler when
193 // all widgets are hidden.
194 virtual bool RunIdleHandlerWhenWidgetsHidden();
196 // Returns true if a popup window should be allowed.
197 virtual bool AllowPopup();
199 // Returns true if we should fork a new process for the given navigation.
200 // If |send_referrer| is set to false (which is the default), no referrer
201 // header will be send for the navigation. Otherwise, the referrer header is
202 // set according to the frame's referrer policy.
203 virtual bool ShouldFork(blink::WebLocalFrame
* frame
,
205 const std::string
& http_method
,
206 bool is_initial_navigation
,
207 bool is_server_redirect
,
208 bool* send_referrer
);
210 // Notifies the embedder that the given frame is requesting the resource at
211 // |url|. If the function returns true, the url is changed to |new_url|.
212 virtual bool WillSendRequest(blink::WebFrame
* frame
,
213 ui::PageTransition transition_type
,
215 const GURL
& first_party_for_cookies
,
218 // See blink::Platform.
219 virtual unsigned long long VisitedLinkHash(const char* canonical_url
,
221 virtual bool IsLinkVisited(unsigned long long link_hash
);
222 virtual blink::WebPrescientNetworking
* GetPrescientNetworking();
223 virtual bool ShouldOverridePageVisibilityState(
224 const RenderFrame
* render_frame
,
225 blink::WebPageVisibilityState
* override_state
);
227 // Allows an embedder to return custom PPAPI interfaces.
228 virtual const void* CreatePPAPIInterface(
229 const std::string
& interface_name
);
231 // Returns true if the given Pepper plugin is external (requiring special
233 virtual bool IsExternalPepperPlugin(const std::string
& module_name
);
235 // Returns true if the page at |url| can use Pepper MediaStream APIs.
236 virtual bool AllowPepperMediaStreamAPI(const GURL
& url
);
238 // Allows an embedder to provide a media::RendererFactory.
239 virtual scoped_ptr
<media::RendererFactory
> CreateMediaRendererFactory(
240 RenderFrame
* render_frame
,
241 const scoped_refptr
<media::GpuVideoAcceleratorFactories
>& gpu_factories
,
242 const scoped_refptr
<media::MediaLog
>& media_log
);
244 // Allows an embedder to provide a MediaStreamRendererFactory.
245 virtual scoped_ptr
<MediaStreamRendererFactory
>
246 CreateMediaStreamRendererFactory();
248 // Gives the embedder a chance to register the key system(s) it supports by
249 // populating |key_systems|.
250 virtual void AddKeySystems(std::vector
<media::KeySystemInfo
>* key_systems
);
252 // Returns true if we should report a detailed message (including a stack
253 // trace) for console [logs|errors|exceptions]. |source| is the WebKit-
254 // reported source for the error; this can point to a page or a script,
255 // and can be external or internal.
256 virtual bool ShouldReportDetailedMessageForSource(
257 const base::string16
& source
) const;
259 // Returns true if we should gather stats during resource loads as if the
260 // cross-site document blocking policy were enabled. Does not actually block
262 virtual bool ShouldGatherSiteIsolationStats() const;
264 // Creates a permission client proxy for in-renderer worker.
265 virtual blink::WebWorkerContentSettingsClientProxy
*
266 CreateWorkerContentSettingsClientProxy(RenderFrame
* render_frame
,
267 blink::WebFrame
* frame
);
269 // Returns true if the page at |url| can use Pepper CameraDevice APIs.
270 virtual bool IsPluginAllowedToUseCameraDeviceAPI(const GURL
& url
);
272 // Returns true if the page at |url| can use Pepper Compositor APIs.
273 virtual bool IsPluginAllowedToUseCompositorAPI(const GURL
& url
);
275 // Returns true if dev channel APIs are available for plugins.
276 virtual bool IsPluginAllowedToUseDevChannelAPIs();
278 // Returns a user agent override specific for |url|, or empty string if
279 // default user agent should be used.
280 virtual std::string
GetUserAgentOverrideForURL(const GURL
& url
);
282 // Records a sample string to a Rappor privacy-preserving metric.
283 // See: https://www.chromium.org/developers/design-documents/rappor
284 virtual void RecordRappor(const std::string
& metric
,
285 const std::string
& sample
) {}
287 // Records a domain and registry of a url to a Rappor privacy-preserving
288 // metric. See: https://www.chromium.org/developers/design-documents/rappor
289 virtual void RecordRapporURL(const std::string
& metric
, const GURL
& url
) {}
291 // Allows an embedder to provide a blink::WebAppBannerClient.
292 virtual scoped_ptr
<blink::WebAppBannerClient
> CreateAppBannerClient(
293 RenderFrame
* render_frame
);
295 // Gives the embedder a chance to add properties to the context menu.
296 // Currently only called when the context menu is for an image.
297 virtual void AddImageContextMenuProperties(
298 const blink::WebURLResponse
& response
,
299 std::map
<std::string
, std::string
>* properties
) {}
301 // Notifies that a service worker context has been created. This function
302 // is called from the worker thread.
303 virtual void DidInitializeServiceWorkerContextOnWorkerThread(
304 v8::Local
<v8::Context
> context
,
308 } // namespace content
310 #endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_