content_renderer_client.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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.
4
5#ifndef CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
6#define CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
7
8#include <string>
9#include <vector>
10
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"
20
21class GURL;
22class SkBitmap;
23
24namespace base {
25class FilePath;
26class MessageLoop;
27}
28
29namespace blink {
30class WebAudioDevice;
31class WebClipboard;
32class WebFrame;
33class WebMIDIAccessor;
34class WebMIDIAccessorClient;
35class WebMediaStreamCenter;
36class WebMediaStreamCenterClient;
37class WebPlugin;
38class WebPluginContainer;
39class WebPrescientNetworking;
40class WebRTCPeerConnectionHandler;
41class WebRTCPeerConnectionHandlerClient;
42class WebSpeechSynthesizer;
43class WebSpeechSynthesizerClient;
44class WebThemeEngine;
45class WebURLRequest;
46class WebWorkerPermissionClientProxy;
47struct WebPluginParams;
48struct WebURLError;
49}
50
51namespace content {
52class DocumentState;
53class RenderFrame;
54class RenderView;
55class SynchronousCompositor;
56struct KeySystemInfo;
57struct WebPluginInfo;
58
59// Embedder API for participating in renderer logic.
60class CONTENT_EXPORT ContentRendererClient {
61 public:
62  virtual ~ContentRendererClient() {}
63
64  // Notifies us that the RenderThread has been created.
65  virtual void RenderThreadStarted() {}
66
67  // Notifies that a new RenderFrame has been created.
68  virtual void RenderFrameCreated(RenderFrame* render_frame) {}
69
70  // Notifies that a new RenderView has been created.
71  virtual void RenderViewCreated(RenderView* render_view) {}
72
73  // Sets a number of views/tabs opened in this process.
74  virtual void SetNumberOfViews(int number_of_views) {}
75
76  // Returns the bitmap to show when a plugin crashed, or NULL for none.
77  virtual SkBitmap* GetSadPluginBitmap();
78
79  // Returns the bitmap to show when a <webview> guest has crashed, or NULL for
80  // none.
81  virtual SkBitmap* GetSadWebViewBitmap();
82
83  // Returns the default text encoding.
84  virtual std::string GetDefaultEncoding();
85
86  // Allows the embedder to override creating a plugin. If it returns true, then
87  // |plugin| will contain the created plugin, although it could be NULL. If it
88  // returns false, the content layer will create the plugin.
89  virtual bool OverrideCreatePlugin(
90      RenderFrame* render_frame,
91      blink::WebFrame* frame,
92      const blink::WebPluginParams& params,
93      blink::WebPlugin** plugin);
94
95  // Creates a replacement plug-in that is shown when the plug-in at |file_path|
96  // couldn't be loaded. This allows the embedder to show a custom placeholder.
97  virtual blink::WebPlugin* CreatePluginReplacement(
98      RenderFrame* render_frame,
99      const base::FilePath& plugin_path);
100
101  // Returns true if the embedder has an error page to show for the given http
102  // status code. If so |error_domain| should be set to according to WebURLError
103  // and the embedder's GetNavigationErrorHtml will be called afterwards to get
104  // the error html.
105  virtual bool HasErrorPage(int http_status_code,
106                            std::string* error_domain);
107
108  // Returns true if the embedder prefers not to show an error page for a failed
109  // navigation to |url|.
110  virtual bool ShouldSuppressErrorPage(const GURL& url);
111
112  // Returns the information to display when a navigation error occurs.
113  // If |error_html| is not null then it may be set to a HTML page containing
114  // the details of the error and maybe links to more info.
115  // If |error_description| is not null it may be set to contain a brief
116  // message describing the error that has occurred.
117  // Either of the out parameters may be not written to in certain cases
118  // (lack of information on the error code) so the caller should take care to
119  // initialize the string values with safe defaults before the call.
120  virtual void GetNavigationErrorStrings(
121      blink::WebFrame* frame,
122      const blink::WebURLRequest& failed_request,
123      const blink::WebURLError& error,
124      const std::string& accept_languages,
125      std::string* error_html,
126      base::string16* error_description) {}
127
128  // Allows the embedder to control when media resources are loaded. Embedders
129  // can run |closure| immediately if they don't wish to defer media resource
130  // loading.
131  virtual void DeferMediaLoad(RenderFrame* render_frame,
132                              const base::Closure& closure);
133
134  // Allows the embedder to override creating a WebMediaStreamCenter. If it
135  // returns NULL the content layer will create the stream center.
136  virtual blink::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter(
137      blink::WebMediaStreamCenterClient* client);
138
139  // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If
140  // it returns NULL the content layer will create the connection handler.
141  virtual blink::WebRTCPeerConnectionHandler*
142  OverrideCreateWebRTCPeerConnectionHandler(
143      blink::WebRTCPeerConnectionHandlerClient* client);
144
145  // Allows the embedder to override creating a WebMIDIAccessor.  If it
146  // returns NULL the content layer will create the MIDI accessor.
147  virtual blink::WebMIDIAccessor* OverrideCreateMIDIAccessor(
148      blink::WebMIDIAccessorClient* client);
149
150  // Allows the embedder to override creating a WebAudioDevice.  If it
151  // returns NULL the content layer will create the audio device.
152  virtual blink::WebAudioDevice* OverrideCreateAudioDevice(
153      double sample_rate);
154
155  // Allows the embedder to override the blink::WebClipboard used. If it
156  // returns NULL the content layer will handle clipboard interactions.
157  virtual blink::WebClipboard* OverrideWebClipboard();
158
159  // Allows the embedder to override the WebThemeEngine used. If it returns NULL
160  // the content layer will provide an engine.
161  virtual blink::WebThemeEngine* OverrideThemeEngine();
162
163  // Allows the embedder to override the WebSpeechSynthesizer used.
164  // If it returns NULL the content layer will provide an engine.
165  virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
166      blink::WebSpeechSynthesizerClient* client);
167
168  // Returns true if the renderer process should schedule the idle handler when
169  // all widgets are hidden.
170  virtual bool RunIdleHandlerWhenWidgetsHidden();
171
172  // Returns true if a popup window should be allowed.
173  virtual bool AllowPopup();
174
175#ifdef OS_ANDROID
176  // TODO(sgurun) This callback is deprecated and will be removed as soon
177  // as android webview completes implementation of a resource throttle based
178  // shouldoverrideurl implementation. See crbug.com/325351
179  //
180  // Returns true if the navigation was handled by the embedder and should be
181  // ignored by WebKit. This method is used by CEF and android_webview.
182  virtual bool HandleNavigation(RenderView* view,
183                                DocumentState* document_state,
184                                int opener_id,
185                                blink::WebFrame* frame,
186                                const blink::WebURLRequest& request,
187                                blink::WebNavigationType type,
188                                blink::WebNavigationPolicy default_policy,
189                                bool is_redirect);
190#endif
191
192  // Returns true if we should fork a new process for the given navigation.
193  // If |send_referrer| is set to false (which is the default), no referrer
194  // header will be send for the navigation. Otherwise, the referrer header is
195  // set according to the frame's referrer policy.
196  virtual bool ShouldFork(blink::WebFrame* frame,
197                          const GURL& url,
198                          const std::string& http_method,
199                          bool is_initial_navigation,
200                          bool is_server_redirect,
201                          bool* send_referrer);
202
203  // Notifies the embedder that the given frame is requesting the resource at
204  // |url|.  If the function returns true, the url is changed to |new_url|.
205  virtual bool WillSendRequest(blink::WebFrame* frame,
206                               PageTransition transition_type,
207                               const GURL& url,
208                               const GURL& first_party_for_cookies,
209                               GURL* new_url);
210
211  // Whether to pump events when sending sync cookie messages.  Needed if the
212  // embedder can potentiall put up a modal dialog on the UI thread as a result.
213  virtual bool ShouldPumpEventsDuringCookieMessage();
214
215  // See the corresponding functions in blink::WebFrameClient.
216  virtual void DidCreateScriptContext(blink::WebFrame* frame,
217                                      v8::Handle<v8::Context> context,
218                                      int extension_group,
219                                      int world_id) {}
220  virtual void WillReleaseScriptContext(blink::WebFrame* frame,
221                                        v8::Handle<v8::Context>,
222                                        int world_id) {}
223
224  // See blink::Platform.
225  virtual unsigned long long VisitedLinkHash(const char* canonical_url,
226                                             size_t length);
227  virtual bool IsLinkVisited(unsigned long long link_hash);
228  virtual blink::WebPrescientNetworking* GetPrescientNetworking();
229  virtual bool ShouldOverridePageVisibilityState(
230      const RenderFrame* render_frame,
231      blink::WebPageVisibilityState* override_state);
232
233  // Return true if the GetCookie request will be handled by the embedder.
234  // Cookies are returned in the cookie parameter.
235  virtual bool HandleGetCookieRequest(RenderView* sender,
236                                      const GURL& url,
237                                      const GURL& first_party_for_cookies,
238                                      std::string* cookies);
239
240  // Return true if the SetCookie request will be handled by the embedder.
241  // Cookies to be set are passed in the value parameter.
242  virtual bool HandleSetCookieRequest(RenderView* sender,
243                                      const GURL& url,
244                                      const GURL& first_party_for_cookies,
245                                      const std::string& value);
246
247  // Allows an embedder to return custom PPAPI interfaces.
248  virtual const void* CreatePPAPIInterface(
249      const std::string& interface_name);
250
251  // Returns true if the given Pepper plugin is external (requiring special
252  // startup steps).
253  virtual bool IsExternalPepperPlugin(const std::string& module_name);
254
255  // Returns whether BrowserPlugin should be allowed within the |container|.
256  virtual bool AllowBrowserPlugin(blink::WebPluginContainer* container);
257
258  // Returns true if the page at |url| can use Pepper MediaStream APIs.
259  virtual bool AllowPepperMediaStreamAPI(const GURL& url);
260
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<KeySystemInfo>* key_systems);
264
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;
271
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;
276
277  // Creates a permission client proxy for in-renderer worker.
278  virtual blink::WebWorkerPermissionClientProxy*
279      CreateWorkerPermissionClientProxy(RenderView* render_view,
280                                        blink::WebFrame* frame);
281};
282
283}  // namespace content
284
285#endif  // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
286