Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / public / renderer / content_renderer_client.h
blob031fc8101e7054b4937d5f6d0bb8091e178b1380
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.
5 #ifndef CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
6 #define CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_
8 #include <map>
9 #include <string>
10 #include <vector>
12 #include "base/bind.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/memory/weak_ptr.h"
16 #include "base/strings/string16.h"
17 #include "content/public/common/content_client.h"
18 #include "third_party/WebKit/public/platform/WebPageVisibilityState.h"
19 #include "ui/base/page_transition_types.h"
20 #include "v8/include/v8.h"
22 class GURL;
23 class SkBitmap;
25 namespace base {
26 class FilePath;
27 class SingleThreadTaskRunner;
30 namespace blink {
31 class WebAppBannerClient;
32 class WebAudioDevice;
33 class WebClipboard;
34 class WebFrame;
35 class WebLocalFrame;
36 class WebMIDIAccessor;
37 class WebMIDIAccessorClient;
38 class WebMediaStreamCenter;
39 class WebMediaStreamCenterClient;
40 class WebPlugin;
41 class WebPluginContainer;
42 class WebPrescientNetworking;
43 class WebRTCPeerConnectionHandler;
44 class WebRTCPeerConnectionHandlerClient;
45 class WebSpeechSynthesizer;
46 class WebSpeechSynthesizerClient;
47 class WebThemeEngine;
48 class WebURLResponse;
49 class WebURLRequest;
50 class WebWorkerContentSettingsClientProxy;
51 struct WebPluginParams;
52 struct WebURLError;
55 namespace media {
56 class GpuVideoAcceleratorFactories;
57 class MediaLog;
58 class RendererFactory;
59 struct KeySystemInfo;
62 namespace content {
63 class BrowserPluginDelegate;
64 class DocumentState;
65 class MediaStreamRendererFactory;
66 class RenderFrame;
67 class RenderView;
68 class SynchronousCompositor;
69 struct WebPluginInfo;
71 // Embedder API for participating in renderer logic.
72 class CONTENT_EXPORT ContentRendererClient {
73 public:
74 virtual ~ContentRendererClient() {}
76 // Notifies us that the RenderThread has been created.
77 virtual void RenderThreadStarted() {}
79 // Notifies that a new RenderFrame has been created. Note that at this point,
80 // render_frame->GetWebFrame()->parent() is always NULL. This will change once
81 // the frame tree moves from Blink to content.
82 virtual void RenderFrameCreated(RenderFrame* render_frame) {}
84 // Notifies that a new RenderView has been created.
85 virtual void RenderViewCreated(RenderView* render_view) {}
87 // Returns the bitmap to show when a plugin crashed, or NULL for none.
88 virtual SkBitmap* GetSadPluginBitmap();
90 // Returns the bitmap to show when a <webview> guest has crashed, or NULL for
91 // none.
92 virtual SkBitmap* GetSadWebViewBitmap();
94 // Allows the embedder to override creating a plugin. If it returns true, then
95 // |plugin| will contain the created plugin, although it could be NULL. If it
96 // returns false, the content layer will create the plugin.
97 virtual bool OverrideCreatePlugin(
98 RenderFrame* render_frame,
99 blink::WebLocalFrame* frame,
100 const blink::WebPluginParams& params,
101 blink::WebPlugin** plugin);
103 // Creates a replacement plugin that is shown when the plugin at |file_path|
104 // couldn't be loaded. This allows the embedder to show a custom placeholder.
105 virtual blink::WebPlugin* CreatePluginReplacement(
106 RenderFrame* render_frame,
107 const base::FilePath& plugin_path);
109 // Creates a delegate for browser plugin.
110 virtual BrowserPluginDelegate* CreateBrowserPluginDelegate(
111 RenderFrame* render_frame,
112 const std::string& mime_type,
113 const GURL& original_url);
115 // Returns true if the embedder has an error page to show for the given http
116 // status code. If so |error_domain| should be set to according to WebURLError
117 // and the embedder's GetNavigationErrorHtml will be called afterwards to get
118 // the error html.
119 virtual bool HasErrorPage(int http_status_code,
120 std::string* error_domain);
122 // Returns true if the embedder prefers not to show an error page for a failed
123 // navigation to |url| in |render_frame|.
124 virtual bool ShouldSuppressErrorPage(RenderFrame* render_frame,
125 const GURL& url);
127 // Returns the information to display when a navigation error occurs.
128 // If |error_html| is not null then it may be set to a HTML page containing
129 // the details of the error and maybe links to more info.
130 // If |error_description| is not null it may be set to contain a brief
131 // message describing the error that has occurred.
132 // Either of the out parameters may be not written to in certain cases
133 // (lack of information on the error code) so the caller should take care to
134 // initialize the string values with safe defaults before the call.
135 virtual void GetNavigationErrorStrings(
136 content::RenderView* render_view,
137 blink::WebFrame* frame,
138 const blink::WebURLRequest& failed_request,
139 const blink::WebURLError& error,
140 std::string* error_html,
141 base::string16* error_description) {}
143 // Allows the embedder to control when media resources are loaded. Embedders
144 // can run |closure| immediately if they don't wish to defer media resource
145 // loading. If |has_played_media_before| is true, the render frame has
146 // previously started media playback (i.e. played audio and video).
147 virtual void DeferMediaLoad(RenderFrame* render_frame,
148 bool has_played_media_before,
149 const base::Closure& closure);
151 // Allows the embedder to override creating a WebMediaStreamCenter. If it
152 // returns NULL the content layer will create the stream center.
153 virtual blink::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter(
154 blink::WebMediaStreamCenterClient* client);
156 // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If
157 // it returns NULL the content layer will create the connection handler.
158 virtual blink::WebRTCPeerConnectionHandler*
159 OverrideCreateWebRTCPeerConnectionHandler(
160 blink::WebRTCPeerConnectionHandlerClient* client);
162 // Allows the embedder to override creating a WebMIDIAccessor. If it
163 // returns NULL the content layer will create the MIDI accessor.
164 virtual blink::WebMIDIAccessor* OverrideCreateMIDIAccessor(
165 blink::WebMIDIAccessorClient* client);
167 // Allows the embedder to override creating a WebAudioDevice. If it
168 // returns NULL the content layer will create the audio device.
169 virtual blink::WebAudioDevice* OverrideCreateAudioDevice(
170 double sample_rate);
172 // Allows the embedder to override the blink::WebClipboard used. If it
173 // returns NULL the content layer will handle clipboard interactions.
174 virtual blink::WebClipboard* OverrideWebClipboard();
176 // Allows the embedder to override the WebThemeEngine used. If it returns NULL
177 // the content layer will provide an engine.
178 virtual blink::WebThemeEngine* OverrideThemeEngine();
180 // Allows the embedder to override the WebSpeechSynthesizer used.
181 // If it returns NULL the content layer will provide an engine.
182 virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
183 blink::WebSpeechSynthesizerClient* client);
185 // Returns true if the renderer process should schedule the idle handler when
186 // all widgets are hidden.
187 virtual bool RunIdleHandlerWhenWidgetsHidden();
189 // Returns true if the renderer process should allow shared timer suspension
190 // after the process has been backgrounded. Defaults to false.
191 virtual bool AllowTimerSuspensionWhenProcessBackgrounded();
193 // Returns true if a popup window should be allowed.
194 virtual bool AllowPopup();
196 // Returns true if we should fork a new process for the given navigation.
197 // If |send_referrer| is set to false (which is the default), no referrer
198 // header will be send for the navigation. Otherwise, the referrer header is
199 // set according to the frame's referrer policy.
200 virtual bool ShouldFork(blink::WebLocalFrame* frame,
201 const GURL& url,
202 const std::string& http_method,
203 bool is_initial_navigation,
204 bool is_server_redirect,
205 bool* send_referrer);
207 // Notifies the embedder that the given frame is requesting the resource at
208 // |url|. If the function returns true, the url is changed to |new_url|.
209 virtual bool WillSendRequest(blink::WebFrame* frame,
210 ui::PageTransition transition_type,
211 const GURL& url,
212 const GURL& first_party_for_cookies,
213 GURL* new_url);
215 // See blink::Platform.
216 virtual unsigned long long VisitedLinkHash(const char* canonical_url,
217 size_t length);
218 virtual bool IsLinkVisited(unsigned long long link_hash);
219 virtual blink::WebPrescientNetworking* GetPrescientNetworking();
220 virtual bool ShouldOverridePageVisibilityState(
221 const RenderFrame* render_frame,
222 blink::WebPageVisibilityState* override_state);
224 // Allows an embedder to return custom PPAPI interfaces.
225 virtual const void* CreatePPAPIInterface(
226 const std::string& interface_name);
228 // Returns true if the given Pepper plugin is external (requiring special
229 // startup steps).
230 virtual bool IsExternalPepperPlugin(const std::string& module_name);
232 // Returns true if the page at |url| can use Pepper MediaStream APIs.
233 virtual bool AllowPepperMediaStreamAPI(const GURL& url);
235 // Allows an embedder to provide a media::RendererFactory.
236 virtual scoped_ptr<media::RendererFactory> CreateMediaRendererFactory(
237 RenderFrame* render_frame,
238 const scoped_refptr<media::GpuVideoAcceleratorFactories>& gpu_factories,
239 const scoped_refptr<media::MediaLog>& media_log);
241 // Allows an embedder to provide a MediaStreamRendererFactory.
242 virtual scoped_ptr<MediaStreamRendererFactory>
243 CreateMediaStreamRendererFactory();
245 // Gives the embedder a chance to register the key system(s) it supports by
246 // populating |key_systems|.
247 virtual void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems);
249 // Returns true if we should report a detailed message (including a stack
250 // trace) for console [logs|errors|exceptions]. |source| is the WebKit-
251 // reported source for the error; this can point to a page or a script,
252 // and can be external or internal.
253 virtual bool ShouldReportDetailedMessageForSource(
254 const base::string16& source) const;
256 // Returns true if we should gather stats during resource loads as if the
257 // cross-site document blocking policy were enabled. Does not actually block
258 // any pages.
259 virtual bool ShouldGatherSiteIsolationStats() const;
261 // Creates a permission client proxy for in-renderer worker.
262 virtual blink::WebWorkerContentSettingsClientProxy*
263 CreateWorkerContentSettingsClientProxy(RenderFrame* render_frame,
264 blink::WebFrame* frame);
266 // Returns true if the page at |url| can use Pepper CameraDevice APIs.
267 virtual bool IsPluginAllowedToUseCameraDeviceAPI(const GURL& url);
269 // Returns true if the page at |url| can use Pepper Compositor APIs.
270 virtual bool IsPluginAllowedToUseCompositorAPI(const GURL& url);
272 // Returns true if dev channel APIs are available for plugins.
273 virtual bool IsPluginAllowedToUseDevChannelAPIs();
275 // Returns a user agent override specific for |url|, or empty string if
276 // default user agent should be used.
277 virtual std::string GetUserAgentOverrideForURL(const GURL& url);
279 // Records a sample string to a Rappor privacy-preserving metric.
280 // See: https://www.chromium.org/developers/design-documents/rappor
281 virtual void RecordRappor(const std::string& metric,
282 const std::string& sample) {}
284 // Records a domain and registry of a url to a Rappor privacy-preserving
285 // metric. See: https://www.chromium.org/developers/design-documents/rappor
286 virtual void RecordRapporURL(const std::string& metric, const GURL& url) {}
288 // Allows an embedder to provide a blink::WebAppBannerClient.
289 virtual scoped_ptr<blink::WebAppBannerClient> CreateAppBannerClient(
290 RenderFrame* render_frame);
292 // Gives the embedder a chance to add properties to the context menu.
293 // Currently only called when the context menu is for an image.
294 virtual void AddImageContextMenuProperties(
295 const blink::WebURLResponse& response,
296 std::map<std::string, std::string>* properties) {}
298 // Notifies that a service worker context has been created. This function
299 // is called from the worker thread.
300 virtual void DidInitializeServiceWorkerContextOnWorkerThread(
301 v8::Local<v8::Context> context,
302 const GURL& url) {}
304 // Notifies that a service worker context will be destroyed. This function
305 // is called from the worker thread.
306 virtual void WillDestroyServiceWorkerContextOnWorkerThread(const GURL& url) {}
309 } // namespace content
311 #endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_