content_renderer_client.h revision 868fa2fe829687343ffae624259930155e16dbd8
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/string16.h"
11#include "base/memory/weak_ptr.h"
12#include "ipc/ipc_message.h"
13#include "content/public/common/content_client.h"
14#include "content/public/common/page_transition_types.h"
15#include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h"
16#include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationType.h"
17#include "third_party/WebKit/Source/WebKit/chromium/public/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 WebMediaPlayerClient;
33class WebMediaStreamCenter;
34class WebMediaStreamCenterClient;
35class WebMimeRegistry;
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 WebMediaPlayerDelegate;
58class WebMediaPlayerImpl;
59class WebMediaPlayerParams;
60}
61
62namespace content {
63
64class RenderView;
65class SynchronousCompositor;
66
67// Embedder API for participating in renderer logic.
68class CONTENT_EXPORT ContentRendererClient {
69 public:
70  virtual ~ContentRendererClient() {}
71
72  // Notifies us that the RenderThread has been created.
73  virtual void RenderThreadStarted() {}
74
75  // Notifies that a new RenderView has been created.
76  virtual void RenderViewCreated(RenderView* render_view) {}
77
78  // Sets a number of views/tabs opened in this process.
79  virtual void SetNumberOfViews(int number_of_views) {}
80
81  // Returns the bitmap to show when a plugin crashed, or NULL for none.
82  virtual SkBitmap* GetSadPluginBitmap();
83
84  // Returns the bitmap to show when a <webview> guest has crashed, or NULL for
85  // none.
86  virtual SkBitmap* GetSadWebViewBitmap();
87
88  // Returns the default text encoding.
89  virtual std::string GetDefaultEncoding();
90
91  // Allows the embedder to override creating a plugin. If it returns true, then
92  // |plugin| will contain the created plugin, although it could be NULL. If it
93  // returns false, the content layer will create the plugin.
94  virtual bool OverrideCreatePlugin(
95      RenderView* render_view,
96      WebKit::WebFrame* frame,
97      const WebKit::WebPluginParams& params,
98      WebKit::WebPlugin** plugin);
99
100  // Creates a replacement plug-in that is shown when the plug-in at |file_path|
101  // couldn't be loaded. This allows the embedder to show a custom placeholder.
102  virtual WebKit::WebPlugin* CreatePluginReplacement(
103      RenderView* render_view,
104      const base::FilePath& plugin_path);
105
106  // Returns true if the embedder has an error page to show for the given http
107  // status code. If so |error_domain| should be set to according to WebURLError
108  // and the embedder's GetNavigationErrorHtml will be called afterwards to get
109  // the error html.
110  virtual bool HasErrorPage(int http_status_code,
111                            std::string* error_domain);
112
113  // Returns the information to display when a navigation error occurs.
114  // If |error_html| is not null then it may be set to a HTML page containing
115  // the details of the error and maybe links to more info.
116  // If |error_description| is not null it may be set to contain a brief
117  // message describing the error that has occurred.
118  // Either of the out parameters may be not written to in certain cases
119  // (lack of information on the error code) so the caller should take care to
120  // initialize the string values with safe defaults before the call.
121  virtual void GetNavigationErrorStrings(
122      WebKit::WebFrame* frame,
123      const WebKit::WebURLRequest& failed_request,
124      const WebKit::WebURLError& error,
125      std::string* error_html,
126      string16* error_description) {}
127
128  // Allows embedder to override creating a WebMediaPlayerImpl. If it returns
129  // NULL the content layer will create the media player.
130  virtual webkit_media::WebMediaPlayerImpl* OverrideCreateWebMediaPlayer(
131      RenderView* render_view,
132      WebKit::WebFrame* frame,
133      WebKit::WebMediaPlayerClient* client,
134      base::WeakPtr<webkit_media::WebMediaPlayerDelegate> delegate,
135      const webkit_media::WebMediaPlayerParams& params);
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 WebKit::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter(
140      WebKit::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 WebKit::WebRTCPeerConnectionHandler*
145  OverrideCreateWebRTCPeerConnectionHandler(
146      WebKit::WebRTCPeerConnectionHandlerClient* client);
147
148  // Allows the embedder to override the WebKit::WebClipboard used. If it
149  // returns NULL the content layer will handle clipboard interactions.
150  virtual WebKit::WebClipboard* OverrideWebClipboard();
151
152  // Allows the embedder to override the WebKit::WebMimeRegistry used. If it
153  // returns NULL the content layer will provide its own mime registry.
154  virtual WebKit::WebMimeRegistry* OverrideWebMimeRegistry();
155
156  // Allows the embedder to override the WebKit::WebHyphenator used. If it
157  // returns NULL the content layer will handle hyphenation.
158  virtual WebKit::WebHyphenator* OverrideWebHyphenator();
159
160  // Allows the embedder to override the WebThemeEngine used. If it returns NULL
161  // the content layer will provide an engine.
162  virtual WebKit::WebThemeEngine* OverrideThemeEngine();
163
164  // Allows the embedder to override the WebSpeechSynthesizer used.
165  // If it returns NULL the content layer will provide an engine.
166  virtual WebKit::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
167      WebKit::WebSpeechSynthesizerClient* client);
168
169  // Returns true if the renderer process should schedule the idle handler when
170  // all widgets are hidden.
171  virtual bool RunIdleHandlerWhenWidgetsHidden();
172
173  // Returns true if a popup window should be allowed.
174  virtual bool AllowPopup();
175
176  // Returns true if the navigation was handled by the embedder and should be
177  // ignored by WebKit. This method is used by CEF.
178  virtual bool HandleNavigation(WebKit::WebFrame* frame,
179                                const WebKit::WebURLRequest& request,
180                                WebKit::WebNavigationType type,
181                                WebKit::WebNavigationPolicy default_policy,
182                                bool is_redirect);
183
184  // Returns true if we should fork a new process for the given navigation.
185  virtual bool ShouldFork(WebKit::WebFrame* frame,
186                          const GURL& url,
187                          const std::string& http_method,
188                          bool is_initial_navigation,
189                          bool is_server_redirect,
190                          bool* send_referrer);
191
192  // Notifies the embedder that the given frame is requesting the resource at
193  // |url|.  If the function returns true, the url is changed to |new_url|.
194  virtual bool WillSendRequest(WebKit::WebFrame* frame,
195                               PageTransition transition_type,
196                               const GURL& url,
197                               const GURL& first_party_for_cookies,
198                               GURL* new_url);
199
200  // Whether to pump events when sending sync cookie messages.  Needed if the
201  // embedder can potentiall put up a modal dialog on the UI thread as a result.
202  virtual bool ShouldPumpEventsDuringCookieMessage();
203
204  // See the corresponding functions in WebKit::WebFrameClient.
205  virtual void DidCreateScriptContext(WebKit::WebFrame* frame,
206                                      v8::Handle<v8::Context> context,
207                                      int extension_group,
208                                      int world_id) {}
209  virtual void WillReleaseScriptContext(WebKit::WebFrame* frame,
210                                        v8::Handle<v8::Context>,
211                                        int world_id) {}
212
213  // See WebKit::Platform.
214  virtual unsigned long long VisitedLinkHash(const char* canonical_url,
215                                             size_t length);
216  virtual bool IsLinkVisited(unsigned long long link_hash);
217  virtual void PrefetchHostName(const char* hostname, size_t length) {}
218  virtual WebKit::WebPrescientNetworking* GetPrescientNetworking();
219  virtual bool ShouldOverridePageVisibilityState(
220      const RenderView* render_view,
221      WebKit::WebPageVisibilityState* override_state) const;
222
223  // Return true if the GetCookie request will be handled by the embedder.
224  // Cookies are returned in the cookie parameter.
225  virtual bool HandleGetCookieRequest(RenderView* sender,
226                                      const GURL& url,
227                                      const GURL& first_party_for_cookies,
228                                      std::string* cookies);
229
230  // Return true if the SetCookie request will be handled by the embedder.
231  // Cookies to be set are passed in the value parameter.
232  virtual bool HandleSetCookieRequest(RenderView* sender,
233                                      const GURL& url,
234                                      const GURL& first_party_for_cookies,
235                                      const std::string& value);
236
237  virtual void RegisterPPAPIInterfaceFactories(
238      webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) {}
239
240  // Returns whether BrowserPlugin should be allowed within the |container|.
241  virtual bool AllowBrowserPlugin(WebKit::WebPluginContainer* container) const;
242
243};
244
245}  // namespace content
246
247#endif  // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
248