content_renderer_client.h revision 4ccfafb49a467adf7819cc5933ef036c1ee41c10
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 "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"
20
21class GURL;
22class SkBitmap;
23
24namespace base {
25class FilePath;
26class MessageLoop;
27}
28
29namespace blink {
30class WebAudioDevice;
31class WebClipboard;
32class WebFrame;
33class WebLocalFrame;
34class WebMIDIAccessor;
35class WebMIDIAccessorClient;
36class WebMediaStreamCenter;
37class WebMediaStreamCenterClient;
38class WebPlugin;
39class WebPluginContainer;
40class WebPrescientNetworking;
41class WebRTCPeerConnectionHandler;
42class WebRTCPeerConnectionHandlerClient;
43class WebSpeechSynthesizer;
44class WebSpeechSynthesizerClient;
45class WebThemeEngine;
46class WebURLRequest;
47class WebWorkerPermissionClientProxy;
48struct WebPluginParams;
49struct WebURLError;
50}
51
52namespace content {
53class BrowserPluginDelegate;
54class DocumentState;
55class RenderFrame;
56class RenderView;
57class SynchronousCompositor;
58struct KeySystemInfo;
59struct WebPluginInfo;
60
61// Embedder API for participating in renderer logic.
62class CONTENT_EXPORT ContentRendererClient {
63 public:
64  virtual ~ContentRendererClient() {}
65
66  // Notifies us that the RenderThread has been created.
67  virtual void RenderThreadStarted() {}
68
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) {}
73
74  // Notifies that a new RenderView has been created.
75  virtual void RenderViewCreated(RenderView* render_view) {}
76
77  // Sets a number of views/tabs opened in this process.
78  virtual void SetNumberOfViews(int number_of_views) {}
79
80  // Returns the bitmap to show when a plugin crashed, or NULL for none.
81  virtual SkBitmap* GetSadPluginBitmap();
82
83  // Returns the bitmap to show when a <webview> guest has crashed, or NULL for
84  // none.
85  virtual SkBitmap* GetSadWebViewBitmap();
86
87  // Allows the embedder to override creating a plugin. If it returns true, then
88  // |plugin| will contain the created plugin, although it could be NULL. If it
89  // returns false, the content layer will create the plugin.
90  virtual bool OverrideCreatePlugin(
91      RenderFrame* render_frame,
92      blink::WebLocalFrame* frame,
93      const blink::WebPluginParams& params,
94      blink::WebPlugin** plugin);
95
96  // Creates a replacement plug-in that is shown when the plug-in at |file_path|
97  // couldn't be loaded. This allows the embedder to show a custom placeholder.
98  virtual blink::WebPlugin* CreatePluginReplacement(
99      RenderFrame* render_frame,
100      const base::FilePath& plugin_path);
101
102  // Creates a delegate for browser plugin.
103  virtual BrowserPluginDelegate* CreateBrowserPluginDelegate(
104      RenderFrame* render_frame,
105      const std::string& mime_type);
106
107  // Returns true if the embedder has an error page to show for the given http
108  // status code. If so |error_domain| should be set to according to WebURLError
109  // and the embedder's GetNavigationErrorHtml will be called afterwards to get
110  // the error html.
111  virtual bool HasErrorPage(int http_status_code,
112                            std::string* error_domain);
113
114  // Returns true if the embedder prefers not to show an error page for a failed
115  // navigation to |url| in |render_frame|.
116  virtual bool ShouldSuppressErrorPage(RenderFrame* render_frame,
117                                       const GURL& url);
118
119  // Returns the information to display when a navigation error occurs.
120  // If |error_html| is not null then it may be set to a HTML page containing
121  // the details of the error and maybe links to more info.
122  // If |error_description| is not null it may be set to contain a brief
123  // message describing the error that has occurred.
124  // Either of the out parameters may be not written to in certain cases
125  // (lack of information on the error code) so the caller should take care to
126  // initialize the string values with safe defaults before the call.
127  virtual void GetNavigationErrorStrings(
128      content::RenderView* render_view,
129      blink::WebFrame* frame,
130      const blink::WebURLRequest& failed_request,
131      const blink::WebURLError& error,
132      std::string* error_html,
133      base::string16* error_description) {}
134
135  // Allows the embedder to control when media resources are loaded. Embedders
136  // can run |closure| immediately if they don't wish to defer media resource
137  // loading.
138  virtual void DeferMediaLoad(RenderFrame* render_frame,
139                              const base::Closure& closure);
140
141  // Allows the embedder to override creating a WebMediaStreamCenter. If it
142  // returns NULL the content layer will create the stream center.
143  virtual blink::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter(
144      blink::WebMediaStreamCenterClient* client);
145
146  // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If
147  // it returns NULL the content layer will create the connection handler.
148  virtual blink::WebRTCPeerConnectionHandler*
149  OverrideCreateWebRTCPeerConnectionHandler(
150      blink::WebRTCPeerConnectionHandlerClient* client);
151
152  // Allows the embedder to override creating a WebMIDIAccessor.  If it
153  // returns NULL the content layer will create the MIDI accessor.
154  virtual blink::WebMIDIAccessor* OverrideCreateMIDIAccessor(
155      blink::WebMIDIAccessorClient* client);
156
157  // Allows the embedder to override creating a WebAudioDevice.  If it
158  // returns NULL the content layer will create the audio device.
159  virtual blink::WebAudioDevice* OverrideCreateAudioDevice(
160      double sample_rate);
161
162  // Allows the embedder to override the blink::WebClipboard used. If it
163  // returns NULL the content layer will handle clipboard interactions.
164  virtual blink::WebClipboard* OverrideWebClipboard();
165
166  // Allows the embedder to override the WebThemeEngine used. If it returns NULL
167  // the content layer will provide an engine.
168  virtual blink::WebThemeEngine* OverrideThemeEngine();
169
170  // Allows the embedder to override the WebSpeechSynthesizer used.
171  // If it returns NULL the content layer will provide an engine.
172  virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
173      blink::WebSpeechSynthesizerClient* client);
174
175  // Returns true if the renderer process should schedule the idle handler when
176  // all widgets are hidden.
177  virtual bool RunIdleHandlerWhenWidgetsHidden();
178
179  // Returns true if a popup window should be allowed.
180  virtual bool AllowPopup();
181
182#ifdef OS_ANDROID
183  // TODO(sgurun) This callback is deprecated and will be removed as soon
184  // as android webview completes implementation of a resource throttle based
185  // shouldoverrideurl implementation. See crbug.com/325351
186  //
187  // Returns true if the navigation was handled by the embedder and should be
188  // ignored by WebKit. This method is used by CEF and android_webview.
189  virtual bool HandleNavigation(RenderFrame* render_frame,
190                                DocumentState* document_state,
191                                int opener_id,
192                                blink::WebFrame* frame,
193                                const blink::WebURLRequest& request,
194                                blink::WebNavigationType type,
195                                blink::WebNavigationPolicy default_policy,
196                                bool is_redirect);
197#endif
198
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::WebFrame* frame,
204                          const GURL& url,
205                          const std::string& http_method,
206                          bool is_initial_navigation,
207                          bool is_server_redirect,
208                          bool* send_referrer);
209
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,
214                               const GURL& url,
215                               const GURL& first_party_for_cookies,
216                               GURL* new_url);
217
218  // See the corresponding functions in blink::WebFrameClient.
219  virtual void DidCreateScriptContext(blink::WebFrame* frame,
220                                      v8::Handle<v8::Context> context,
221                                      int extension_group,
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  // Allows an embedder to return custom PPAPI interfaces.
234  virtual const void* CreatePPAPIInterface(
235      const std::string& interface_name);
236
237  // Returns true if the given Pepper plugin is external (requiring special
238  // startup steps).
239  virtual bool IsExternalPepperPlugin(const std::string& module_name);
240
241  // Returns true if the page at |url| can use Pepper MediaStream APIs.
242  virtual bool AllowPepperMediaStreamAPI(const GURL& url);
243
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);
247
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;
254
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;
259
260  // Creates a permission client proxy for in-renderer worker.
261  virtual blink::WebWorkerPermissionClientProxy*
262      CreateWorkerPermissionClientProxy(RenderFrame* render_frame,
263                                        blink::WebFrame* frame);
264
265  // Returns true if the page at |url| can use Pepper Compositor APIs.
266  virtual bool IsPluginAllowedToUseCompositorAPI(const GURL& url);
267
268  // Returns true if the page at |url| can use Pepper VideoDecoder APIs.
269  virtual bool IsPluginAllowedToUseVideoDecodeAPI(const GURL& url);
270
271  // Returns true if dev channel APIs are available for plugins.
272  virtual bool IsPluginAllowedToUseDevChannelAPIs();
273};
274
275}  // namespace content
276
277#endif  // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
278