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