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