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