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