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_
11 #include "base/memory/weak_ptr.h"
12 #include "base/strings/string16.h"
13 #include "content/public/common/content_client.h"
14 #include "ipc/ipc_message.h"
15 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
16 #include "third_party/WebKit/public/web/WebNavigationType.h"
17 #include "third_party/WebKit/public/web/WebPageVisibilityState.h"
18 #include "ui/base/page_transition_types.h"
19 #include "v8/include/v8.h"
34 class WebMIDIAccessor
;
35 class WebMIDIAccessorClient
;
36 class WebMediaStreamCenter
;
37 class WebMediaStreamCenterClient
;
39 class WebPluginContainer
;
40 class WebPrescientNetworking
;
41 class WebRTCPeerConnectionHandler
;
42 class WebRTCPeerConnectionHandlerClient
;
43 class WebSpeechSynthesizer
;
44 class WebSpeechSynthesizerClient
;
47 class WebWorkerPermissionClientProxy
;
48 struct WebPluginParams
;
53 class BrowserPluginDelegate
;
57 class SynchronousCompositor
;
61 // Embedder API for participating in renderer logic.
62 class CONTENT_EXPORT ContentRendererClient
{
64 virtual ~ContentRendererClient() {}
66 // Notifies us that the RenderThread has been created.
67 virtual void RenderThreadStarted() {}
69 // Notifies that a new RenderFrame has been created. Note that at this point,
70 // render_frame->GetWebFrame()->parent() is always NULL. This will change once
71 // the frame tree moves from Blink to content.
72 virtual void RenderFrameCreated(RenderFrame
* render_frame
) {}
74 // Notifies that a new RenderView has been created.
75 virtual void RenderViewCreated(RenderView
* render_view
) {}
77 // Sets a number of views/tabs opened in this process.
78 virtual void SetNumberOfViews(int number_of_views
) {}
80 // Returns the bitmap to show when a plugin crashed, or NULL for none.
81 virtual SkBitmap
* GetSadPluginBitmap();
83 // Returns the bitmap to show when a <webview> guest has crashed, or NULL for
85 virtual SkBitmap
* GetSadWebViewBitmap();
87 // Returns the default text encoding.
88 virtual std::string
GetDefaultEncoding();
90 // Allows the embedder to override creating a plugin. If it returns true, then
91 // |plugin| will contain the created plugin, although it could be NULL. If it
92 // returns false, the content layer will create the plugin.
93 virtual bool OverrideCreatePlugin(
94 RenderFrame
* render_frame
,
95 blink::WebLocalFrame
* frame
,
96 const blink::WebPluginParams
& params
,
97 blink::WebPlugin
** plugin
);
99 // Creates a replacement plug-in that is shown when the plug-in at |file_path|
100 // couldn't be loaded. This allows the embedder to show a custom placeholder.
101 virtual blink::WebPlugin
* CreatePluginReplacement(
102 RenderFrame
* render_frame
,
103 const base::FilePath
& plugin_path
);
105 // Creates a delegate for browser plugin.
106 virtual BrowserPluginDelegate
* CreateBrowserPluginDelegate(
107 RenderFrame
* render_frame
,
108 const std::string
& mime_type
);
110 // Returns true if the embedder has an error page to show for the given http
111 // status code. If so |error_domain| should be set to according to WebURLError
112 // and the embedder's GetNavigationErrorHtml will be called afterwards to get
114 virtual bool HasErrorPage(int http_status_code
,
115 std::string
* error_domain
);
117 // Returns true if the embedder prefers not to show an error page for a failed
118 // navigation to |url| in |render_frame|.
119 virtual bool ShouldSuppressErrorPage(RenderFrame
* render_frame
,
122 // Returns the information to display when a navigation error occurs.
123 // If |error_html| is not null then it may be set to a HTML page containing
124 // the details of the error and maybe links to more info.
125 // If |error_description| is not null it may be set to contain a brief
126 // message describing the error that has occurred.
127 // Either of the out parameters may be not written to in certain cases
128 // (lack of information on the error code) so the caller should take care to
129 // initialize the string values with safe defaults before the call.
130 virtual void GetNavigationErrorStrings(
131 content::RenderView
* render_view
,
132 blink::WebFrame
* frame
,
133 const blink::WebURLRequest
& failed_request
,
134 const blink::WebURLError
& error
,
135 std::string
* error_html
,
136 base::string16
* error_description
) {}
138 // Allows the embedder to control when media resources are loaded. Embedders
139 // can run |closure| immediately if they don't wish to defer media resource
141 virtual void DeferMediaLoad(RenderFrame
* render_frame
,
142 const base::Closure
& closure
);
144 // Allows the embedder to override creating a WebMediaStreamCenter. If it
145 // returns NULL the content layer will create the stream center.
146 virtual blink::WebMediaStreamCenter
* OverrideCreateWebMediaStreamCenter(
147 blink::WebMediaStreamCenterClient
* client
);
149 // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If
150 // it returns NULL the content layer will create the connection handler.
151 virtual blink::WebRTCPeerConnectionHandler
*
152 OverrideCreateWebRTCPeerConnectionHandler(
153 blink::WebRTCPeerConnectionHandlerClient
* client
);
155 // Allows the embedder to override creating a WebMIDIAccessor. If it
156 // returns NULL the content layer will create the MIDI accessor.
157 virtual blink::WebMIDIAccessor
* OverrideCreateMIDIAccessor(
158 blink::WebMIDIAccessorClient
* client
);
160 // Allows the embedder to override creating a WebAudioDevice. If it
161 // returns NULL the content layer will create the audio device.
162 virtual blink::WebAudioDevice
* OverrideCreateAudioDevice(
165 // Allows the embedder to override the blink::WebClipboard used. If it
166 // returns NULL the content layer will handle clipboard interactions.
167 virtual blink::WebClipboard
* OverrideWebClipboard();
169 // Allows the embedder to override the WebThemeEngine used. If it returns NULL
170 // the content layer will provide an engine.
171 virtual blink::WebThemeEngine
* OverrideThemeEngine();
173 // Allows the embedder to override the WebSpeechSynthesizer used.
174 // If it returns NULL the content layer will provide an engine.
175 virtual blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
176 blink::WebSpeechSynthesizerClient
* client
);
178 // Returns true if the renderer process should schedule the idle handler when
179 // all widgets are hidden.
180 virtual bool RunIdleHandlerWhenWidgetsHidden();
182 // Returns true if a popup window should be allowed.
183 virtual bool AllowPopup();
186 // TODO(sgurun) This callback is deprecated and will be removed as soon
187 // as android webview completes implementation of a resource throttle based
188 // shouldoverrideurl implementation. See crbug.com/325351
190 // Returns true if the navigation was handled by the embedder and should be
191 // ignored by WebKit. This method is used by CEF and android_webview.
192 virtual bool HandleNavigation(RenderFrame
* render_frame
,
193 DocumentState
* document_state
,
195 blink::WebFrame
* frame
,
196 const blink::WebURLRequest
& request
,
197 blink::WebNavigationType type
,
198 blink::WebNavigationPolicy default_policy
,
202 // Returns true if we should fork a new process for the given navigation.
203 // If |send_referrer| is set to false (which is the default), no referrer
204 // header will be send for the navigation. Otherwise, the referrer header is
205 // set according to the frame's referrer policy.
206 virtual bool ShouldFork(blink::WebFrame
* frame
,
208 const std::string
& http_method
,
209 bool is_initial_navigation
,
210 bool is_server_redirect
,
211 bool* send_referrer
);
213 // Notifies the embedder that the given frame is requesting the resource at
214 // |url|. If the function returns true, the url is changed to |new_url|.
215 virtual bool WillSendRequest(blink::WebFrame
* frame
,
216 ui::PageTransition transition_type
,
218 const GURL
& first_party_for_cookies
,
221 // See the corresponding functions in blink::WebFrameClient.
222 virtual void DidCreateScriptContext(blink::WebFrame
* frame
,
223 v8::Handle
<v8::Context
> context
,
227 // See blink::Platform.
228 virtual unsigned long long VisitedLinkHash(const char* canonical_url
,
230 virtual bool IsLinkVisited(unsigned long long link_hash
);
231 virtual blink::WebPrescientNetworking
* GetPrescientNetworking();
232 virtual bool ShouldOverridePageVisibilityState(
233 const RenderFrame
* render_frame
,
234 blink::WebPageVisibilityState
* override_state
);
236 // Allows an embedder to return custom PPAPI interfaces.
237 virtual const void* CreatePPAPIInterface(
238 const std::string
& interface_name
);
240 // Returns true if the given Pepper plugin is external (requiring special
242 virtual bool IsExternalPepperPlugin(const std::string
& module_name
);
244 // Returns true if the page at |url| can use Pepper MediaStream APIs.
245 virtual bool AllowPepperMediaStreamAPI(const GURL
& url
);
247 // Gives the embedder a chance to register the key system(s) it supports by
248 // populating |key_systems|.
249 virtual void AddKeySystems(std::vector
<KeySystemInfo
>* key_systems
);
251 // Returns true if we should report a detailed message (including a stack
252 // trace) for console [logs|errors|exceptions]. |source| is the WebKit-
253 // reported source for the error; this can point to a page or a script,
254 // and can be external or internal.
255 virtual bool ShouldReportDetailedMessageForSource(
256 const base::string16
& source
) const;
258 // Returns true if we should apply the cross-site document blocking policy to
259 // this renderer process. Currently, we apply the policy only to a renderer
260 // process running on a normal page from the web.
261 virtual bool ShouldEnableSiteIsolationPolicy() const;
263 // Creates a permission client proxy for in-renderer worker.
264 virtual blink::WebWorkerPermissionClientProxy
*
265 CreateWorkerPermissionClientProxy(RenderFrame
* render_frame
,
266 blink::WebFrame
* frame
);
268 // Returns true if the page at |url| can use Pepper Compositor APIs.
269 virtual bool IsPluginAllowedToUseCompositorAPI(const GURL
& url
);
271 // Returns true if the page at |url| can use Pepper VideoDecoder APIs.
272 virtual bool IsPluginAllowedToUseVideoDecodeAPI(const GURL
& url
);
274 // Returns true if dev channel APIs are available for plugins.
275 virtual bool IsPluginAllowedToUseDevChannelAPIs();
278 } // namespace content
280 #endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_