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 "content/public/common/page_transition_types.h"
15 #include "ipc/ipc_message.h"
16 #include "third_party/WebKit/public/web/WebNavigationPolicy.h"
17 #include "third_party/WebKit/public/web/WebNavigationType.h"
18 #include "third_party/WebKit/public/web/WebPageVisibilityState.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;
56 class SynchronousCompositor;
60 // Embedder API for participating in renderer logic.
61 class CONTENT_EXPORT ContentRendererClient {
63 virtual ~ContentRendererClient() {}
65 // Notifies us that the RenderThread has been created.
66 virtual void RenderThreadStarted() {}
68 // Notifies that a new RenderFrame has been created. Note that at this point,
69 // render_frame->GetWebFrame()->parent() is always NULL. This will change once
70 // the frame tree moves from Blink to content.
71 virtual void RenderFrameCreated(RenderFrame* render_frame) {}
73 // Notifies that a new RenderView has been created.
74 virtual void RenderViewCreated(RenderView* render_view) {}
76 // Sets a number of views/tabs opened in this process.
77 virtual void SetNumberOfViews(int number_of_views) {}
79 // Returns the bitmap to show when a plugin crashed, or NULL for none.
80 virtual SkBitmap* GetSadPluginBitmap();
82 // Returns the bitmap to show when a <webview> guest has crashed, or NULL for
84 virtual SkBitmap* GetSadWebViewBitmap();
86 // Returns the default text encoding.
87 virtual std::string GetDefaultEncoding();
89 // Allows the embedder to override creating a plugin. If it returns true, then
90 // |plugin| will contain the created plugin, although it could be NULL. If it
91 // returns false, the content layer will create the plugin.
92 virtual bool OverrideCreatePlugin(
93 RenderFrame* render_frame,
94 blink::WebLocalFrame* frame,
95 const blink::WebPluginParams& params,
96 blink::WebPlugin** plugin);
98 // Creates a replacement plug-in that is shown when the plug-in at |file_path|
99 // couldn't be loaded. This allows the embedder to show a custom placeholder.
100 virtual blink::WebPlugin* CreatePluginReplacement(
101 RenderFrame* render_frame,
102 const base::FilePath& plugin_path);
104 // Returns true if the embedder has an error page to show for the given http
105 // status code. If so |error_domain| should be set to according to WebURLError
106 // and the embedder's GetNavigationErrorHtml will be called afterwards to get
108 virtual bool HasErrorPage(int http_status_code,
109 std::string* error_domain);
111 // Returns true if the embedder prefers not to show an error page for a failed
112 // navigation to |url| in |render_frame|.
113 virtual bool ShouldSuppressErrorPage(RenderFrame* render_frame,
116 // Returns the information to display when a navigation error occurs.
117 // If |error_html| is not null then it may be set to a HTML page containing
118 // the details of the error and maybe links to more info.
119 // If |error_description| is not null it may be set to contain a brief
120 // message describing the error that has occurred.
121 // Either of the out parameters may be not written to in certain cases
122 // (lack of information on the error code) so the caller should take care to
123 // initialize the string values with safe defaults before the call.
124 virtual void GetNavigationErrorStrings(
125 content::RenderView* render_view,
126 blink::WebFrame* frame,
127 const blink::WebURLRequest& failed_request,
128 const blink::WebURLError& error,
129 std::string* error_html,
130 base::string16* error_description) {}
132 // Allows the embedder to control when media resources are loaded. Embedders
133 // can run |closure| immediately if they don't wish to defer media resource
135 virtual void DeferMediaLoad(RenderFrame* render_frame,
136 const base::Closure& closure);
138 // Allows the embedder to override creating a WebMediaStreamCenter. If it
139 // returns NULL the content layer will create the stream center.
140 virtual blink::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter(
141 blink::WebMediaStreamCenterClient* client);
143 // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If
144 // it returns NULL the content layer will create the connection handler.
145 virtual blink::WebRTCPeerConnectionHandler*
146 OverrideCreateWebRTCPeerConnectionHandler(
147 blink::WebRTCPeerConnectionHandlerClient* client);
149 // Allows the embedder to override creating a WebMIDIAccessor. If it
150 // returns NULL the content layer will create the MIDI accessor.
151 virtual blink::WebMIDIAccessor* OverrideCreateMIDIAccessor(
152 blink::WebMIDIAccessorClient* client);
154 // Allows the embedder to override creating a WebAudioDevice. If it
155 // returns NULL the content layer will create the audio device.
156 virtual blink::WebAudioDevice* OverrideCreateAudioDevice(
159 // Allows the embedder to override the blink::WebClipboard used. If it
160 // returns NULL the content layer will handle clipboard interactions.
161 virtual blink::WebClipboard* OverrideWebClipboard();
163 // Allows the embedder to override the WebThemeEngine used. If it returns NULL
164 // the content layer will provide an engine.
165 virtual blink::WebThemeEngine* OverrideThemeEngine();
167 // Allows the embedder to override the WebSpeechSynthesizer used.
168 // If it returns NULL the content layer will provide an engine.
169 virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
170 blink::WebSpeechSynthesizerClient* client);
172 // Returns true if the renderer process should schedule the idle handler when
173 // all widgets are hidden.
174 virtual bool RunIdleHandlerWhenWidgetsHidden();
176 // Returns true if a popup window should be allowed.
177 virtual bool AllowPopup();
180 // TODO(sgurun) This callback is deprecated and will be removed as soon
181 // as android webview completes implementation of a resource throttle based
182 // shouldoverrideurl implementation. See crbug.com/325351
184 // Returns true if the navigation was handled by the embedder and should be
185 // ignored by WebKit. This method is used by CEF and android_webview.
186 virtual bool HandleNavigation(RenderFrame* render_frame,
187 DocumentState* document_state,
189 blink::WebFrame* frame,
190 const blink::WebURLRequest& request,
191 blink::WebNavigationType type,
192 blink::WebNavigationPolicy default_policy,
196 // Returns true if we should fork a new process for the given navigation.
197 // If |send_referrer| is set to false (which is the default), no referrer
198 // header will be send for the navigation. Otherwise, the referrer header is
199 // set according to the frame's referrer policy.
200 virtual bool ShouldFork(blink::WebFrame* frame,
202 const std::string& http_method,
203 bool is_initial_navigation,
204 bool is_server_redirect,
205 bool* send_referrer);
207 // Notifies the embedder that the given frame is requesting the resource at
208 // |url|. If the function returns true, the url is changed to |new_url|.
209 virtual bool WillSendRequest(blink::WebFrame* frame,
210 PageTransition transition_type,
212 const GURL& first_party_for_cookies,
215 // See the corresponding functions in blink::WebFrameClient.
216 virtual void DidCreateScriptContext(blink::WebFrame* frame,
217 v8::Handle<v8::Context> context,
221 // See blink::Platform.
222 virtual unsigned long long VisitedLinkHash(const char* canonical_url,
224 virtual bool IsLinkVisited(unsigned long long link_hash);
225 virtual blink::WebPrescientNetworking* GetPrescientNetworking();
226 virtual bool ShouldOverridePageVisibilityState(
227 const RenderFrame* render_frame,
228 blink::WebPageVisibilityState* override_state);
230 // Allows an embedder to return custom PPAPI interfaces.
231 virtual const void* CreatePPAPIInterface(
232 const std::string& interface_name);
234 // Returns true if the given Pepper plugin is external (requiring special
236 virtual bool IsExternalPepperPlugin(const std::string& module_name);
238 // Returns whether BrowserPlugin should be allowed within the |container|.
239 virtual bool AllowBrowserPlugin(blink::WebPluginContainer* container);
241 // Returns true if the page at |url| can use Pepper MediaStream APIs.
242 virtual bool AllowPepperMediaStreamAPI(const GURL& url);
244 // Gives the embedder a chance to register the key system(s) it supports by
245 // populating |key_systems|.
246 virtual void AddKeySystems(std::vector<KeySystemInfo>* key_systems);
248 // Returns true if we should report a detailed message (including a stack
249 // trace) for console [logs|errors|exceptions]. |source| is the WebKit-
250 // reported source for the error; this can point to a page or a script,
251 // and can be external or internal.
252 virtual bool ShouldReportDetailedMessageForSource(
253 const base::string16& source) const;
255 // Returns true if we should apply the cross-site document blocking policy to
256 // this renderer process. Currently, we apply the policy only to a renderer
257 // process running on a normal page from the web.
258 virtual bool ShouldEnableSiteIsolationPolicy() const;
260 // Creates a permission client proxy for in-renderer worker.
261 virtual blink::WebWorkerPermissionClientProxy*
262 CreateWorkerPermissionClientProxy(RenderFrame* render_frame,
263 blink::WebFrame* frame);
266 } // namespace content
268 #endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_