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