content_renderer_client.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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 WebClipboard;
30class WebFrame;
31class WebHyphenator;
32class WebMIDIAccessor;
33class WebMIDIAccessorClient;
34class WebMediaStreamCenter;
35class WebMediaStreamCenterClient;
36class WebPlugin;
37class WebPluginContainer;
38class WebPrescientNetworking;
39class WebRTCPeerConnectionHandler;
40class WebRTCPeerConnectionHandlerClient;
41class WebSpeechSynthesizer;
42class WebSpeechSynthesizerClient;
43class WebThemeEngine;
44class WebURLRequest;
45struct WebPluginParams;
46struct WebURLError;
47}
48
49namespace webkit {
50namespace ppapi {
51class PpapiInterfaceFactoryManager;
52}
53struct WebPluginInfo;
54}
55
56namespace webkit_media {
57class MediaLoadDelegate;
58class MediaStreamClient;
59}
60
61namespace content {
62
63class RenderView;
64class SynchronousCompositor;
65
66// Embedder API for participating in renderer logic.
67class CONTENT_EXPORT ContentRendererClient {
68 public:
69  virtual ~ContentRendererClient() {}
70
71  // Notifies us that the RenderThread has been created.
72  virtual void RenderThreadStarted() {}
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  // Returns the default text encoding.
88  virtual std::string GetDefaultEncoding();
89
90  // Allows the embedder to override creating a plugin. If it returns true, then
91  // |plugin| will contain the created plugin, although it could be NULL. If it
92  // returns false, the content layer will create the plugin.
93  virtual bool OverrideCreatePlugin(
94      RenderView* render_view,
95      WebKit::WebFrame* frame,
96      const WebKit::WebPluginParams& params,
97      WebKit::WebPlugin** plugin);
98
99  // Creates a replacement plug-in that is shown when the plug-in at |file_path|
100  // couldn't be loaded. This allows the embedder to show a custom placeholder.
101  virtual WebKit::WebPlugin* CreatePluginReplacement(
102      RenderView* render_view,
103      const base::FilePath& plugin_path);
104
105  // Returns true if the embedder has an error page to show for the given http
106  // status code. If so |error_domain| should be set to according to WebURLError
107  // and the embedder's GetNavigationErrorHtml will be called afterwards to get
108  // the error html.
109  virtual bool HasErrorPage(int http_status_code,
110                            std::string* error_domain);
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      WebKit::WebFrame* frame,
122      const WebKit::WebURLRequest& failed_request,
123      const WebKit::WebURLError& error,
124      std::string* error_html,
125      string16* error_description) {}
126
127  // Allows the embedder to control when media resources are loaded. Embedders
128  // can run |closure| immediately if they don't wish to defer media resource
129  // loading.
130  virtual void DeferMediaLoad(RenderView* render_view,
131                              const base::Closure& closure);
132
133  // Allows the embedder to override creating a WebMediaStreamCenter. If it
134  // returns NULL the content layer will create the stream center.
135  virtual WebKit::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter(
136      WebKit::WebMediaStreamCenterClient* client);
137
138  // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If
139  // it returns NULL the content layer will create the connection handler.
140  virtual WebKit::WebRTCPeerConnectionHandler*
141  OverrideCreateWebRTCPeerConnectionHandler(
142      WebKit::WebRTCPeerConnectionHandlerClient* client);
143
144  // Allows the embedder to override creating a MediaStreamClient. If it returns
145  // NULL the content layer will create the media stream client.
146  virtual webkit_media::MediaStreamClient* OverrideCreateMediaStreamClient();
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 WebKit::WebMIDIAccessor* OverrideCreateMIDIAccessor(
151      WebKit::WebMIDIAccessorClient* client);
152
153  // Allows the embedder to override the WebKit::WebClipboard used. If it
154  // returns NULL the content layer will handle clipboard interactions.
155  virtual WebKit::WebClipboard* OverrideWebClipboard();
156
157  // Allows the embedder to override the WebKit::WebHyphenator used. If it
158  // returns NULL the content layer will handle hyphenation.
159  virtual WebKit::WebHyphenator* OverrideWebHyphenator();
160
161  // Allows the embedder to override the WebThemeEngine used. If it returns NULL
162  // the content layer will provide an engine.
163  virtual WebKit::WebThemeEngine* OverrideThemeEngine();
164
165  // Allows the embedder to override the WebSpeechSynthesizer used.
166  // If it returns NULL the content layer will provide an engine.
167  virtual WebKit::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
168      WebKit::WebSpeechSynthesizerClient* client);
169
170  // Returns true if the renderer process should schedule the idle handler when
171  // all widgets are hidden.
172  virtual bool RunIdleHandlerWhenWidgetsHidden();
173
174  // Returns true if a popup window should be allowed.
175  virtual bool AllowPopup();
176
177  // Returns true if the navigation was handled by the embedder and should be
178  // ignored by WebKit. This method is used by CEF.
179  virtual bool HandleNavigation(WebKit::WebFrame* frame,
180                                const WebKit::WebURLRequest& request,
181                                WebKit::WebNavigationType type,
182                                WebKit::WebNavigationPolicy default_policy,
183                                bool is_redirect);
184
185  // Returns true if we should fork a new process for the given navigation.
186  virtual bool ShouldFork(WebKit::WebFrame* frame,
187                          const GURL& url,
188                          const std::string& http_method,
189                          bool is_initial_navigation,
190                          bool is_server_redirect,
191                          bool* send_referrer);
192
193  // Notifies the embedder that the given frame is requesting the resource at
194  // |url|.  If the function returns true, the url is changed to |new_url|.
195  virtual bool WillSendRequest(WebKit::WebFrame* frame,
196                               PageTransition transition_type,
197                               const GURL& url,
198                               const GURL& first_party_for_cookies,
199                               GURL* new_url);
200
201  // Whether to pump events when sending sync cookie messages.  Needed if the
202  // embedder can potentiall put up a modal dialog on the UI thread as a result.
203  virtual bool ShouldPumpEventsDuringCookieMessage();
204
205  // See the corresponding functions in WebKit::WebFrameClient.
206  virtual void DidCreateScriptContext(WebKit::WebFrame* frame,
207                                      v8::Handle<v8::Context> context,
208                                      int extension_group,
209                                      int world_id) {}
210  virtual void WillReleaseScriptContext(WebKit::WebFrame* frame,
211                                        v8::Handle<v8::Context>,
212                                        int world_id) {}
213
214  // See WebKit::Platform.
215  virtual unsigned long long VisitedLinkHash(const char* canonical_url,
216                                             size_t length);
217  virtual bool IsLinkVisited(unsigned long long link_hash);
218  virtual void PrefetchHostName(const char* hostname, size_t length) {}
219  virtual WebKit::WebPrescientNetworking* GetPrescientNetworking();
220  virtual bool ShouldOverridePageVisibilityState(
221      const RenderView* render_view,
222      WebKit::WebPageVisibilityState* override_state) const;
223
224  // Return true if the GetCookie request will be handled by the embedder.
225  // Cookies are returned in the cookie parameter.
226  virtual bool HandleGetCookieRequest(RenderView* sender,
227                                      const GURL& url,
228                                      const GURL& first_party_for_cookies,
229                                      std::string* cookies);
230
231  // Return true if the SetCookie request will be handled by the embedder.
232  // Cookies to be set are passed in the value parameter.
233  virtual bool HandleSetCookieRequest(RenderView* sender,
234                                      const GURL& url,
235                                      const GURL& first_party_for_cookies,
236                                      const std::string& value);
237
238  virtual void RegisterPPAPIInterfaceFactories(
239      webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) {}
240
241  // Returns true if plugin living in the container can use
242  // pp::FileIO::RequestOSFileHandle.
243  virtual bool IsPluginAllowedToCallRequestOSFileHandle(
244      WebKit::WebPluginContainer* container) const;
245
246  // Returns whether BrowserPlugin should be allowed within the |container|.
247  virtual bool AllowBrowserPlugin(WebKit::WebPluginContainer* container) const;
248
249  // Returns true if the page at |url| can use Pepper MediaStream APIs.
250  virtual bool AllowPepperMediaStreamAPI(const GURL& url) const;
251};
252
253}  // namespace content
254
255#endif  // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
256