Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / renderer / chrome_content_renderer_client.h
blob9c69bce752eb8d32d27e056971f6dde50ee396fb
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 CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
6 #define CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
13 #include "base/compiler_specific.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "content/public/renderer/content_renderer_client.h"
17 #include "ipc/ipc_channel_proxy.h"
18 #include "v8/include/v8.h"
20 class ChromeExtensionsDispatcherDelegate;
21 class ChromeRenderProcessObserver;
22 #if defined(ENABLE_PRINT_PREVIEW)
23 class ChromePDFPrintClient;
24 #endif
25 class PrescientNetworkingDispatcher;
26 #if defined(ENABLE_SPELLCHECK)
27 class SpellCheck;
28 class SpellCheckProvider;
29 #endif
31 struct ChromeViewHostMsg_GetPluginInfo_Output;
33 namespace content {
34 class BrowserPluginDelegate;
35 struct WebPluginInfo;
38 namespace network_hints {
39 class PrescientNetworkingDispatcher;
42 namespace extensions {
43 class Dispatcher;
44 class Extension;
45 class ExtensionSet;
46 class ExtensionsGuestViewContainerDispatcher;
47 class RendererPermissionsPolicyDelegate;
50 namespace prerender {
51 class PrerenderDispatcher;
54 namespace safe_browsing {
55 class PhishingClassifierFilter;
58 namespace visitedlink {
59 class VisitedLinkSlave;
62 namespace web_cache {
63 class WebCacheRenderProcessObserver;
66 namespace blink {
67 class WebSecurityOrigin;
70 namespace password_manager {
71 class CredentialManagerClient;
74 #if defined(ENABLE_WEBRTC)
75 class WebRtcLoggingMessageFilter;
76 #endif
78 class ChromeContentRendererClient : public content::ContentRendererClient {
79 public:
80 ChromeContentRendererClient();
81 ~ChromeContentRendererClient() override;
83 void RenderThreadStarted() override;
84 void RenderFrameCreated(content::RenderFrame* render_frame) override;
85 void RenderViewCreated(content::RenderView* render_view) override;
86 SkBitmap* GetSadPluginBitmap() override;
87 SkBitmap* GetSadWebViewBitmap() override;
88 bool OverrideCreatePlugin(content::RenderFrame* render_frame,
89 blink::WebLocalFrame* frame,
90 const blink::WebPluginParams& params,
91 blink::WebPlugin** plugin) override;
92 blink::WebPlugin* CreatePluginReplacement(
93 content::RenderFrame* render_frame,
94 const base::FilePath& plugin_path) override;
95 bool HasErrorPage(int http_status_code, std::string* error_domain) override;
96 bool ShouldSuppressErrorPage(content::RenderFrame* render_frame,
97 const GURL& url) override;
98 void GetNavigationErrorStrings(content::RenderView* render_view,
99 blink::WebFrame* frame,
100 const blink::WebURLRequest& failed_request,
101 const blink::WebURLError& error,
102 std::string* error_html,
103 base::string16* error_description) override;
104 void DeferMediaLoad(content::RenderFrame* render_frame,
105 bool has_played_media_before,
106 const base::Closure& closure) override;
107 bool RunIdleHandlerWhenWidgetsHidden() override;
108 bool AllowTimerSuspensionWhenProcessBackgrounded() override;
109 bool AllowPopup() override;
110 bool ShouldFork(blink::WebLocalFrame* frame,
111 const GURL& url,
112 const std::string& http_method,
113 bool is_initial_navigation,
114 bool is_server_redirect,
115 bool* send_referrer) override;
116 bool WillSendRequest(blink::WebFrame* frame,
117 ui::PageTransition transition_type,
118 const GURL& url,
119 const GURL& first_party_for_cookies,
120 GURL* new_url) override;
121 unsigned long long VisitedLinkHash(const char* canonical_url,
122 size_t length) override;
123 bool IsLinkVisited(unsigned long long link_hash) override;
124 blink::WebPrescientNetworking* GetPrescientNetworking() override;
125 bool ShouldOverridePageVisibilityState(
126 const content::RenderFrame* render_frame,
127 blink::WebPageVisibilityState* override_state) override;
128 const void* CreatePPAPIInterface(const std::string& interface_name) override;
129 bool IsExternalPepperPlugin(const std::string& module_name) override;
130 blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
131 blink::WebSpeechSynthesizerClient* client) override;
132 bool ShouldReportDetailedMessageForSource(
133 const base::string16& source) const override;
134 bool ShouldGatherSiteIsolationStats() const override;
135 blink::WebWorkerContentSettingsClientProxy*
136 CreateWorkerContentSettingsClientProxy(content::RenderFrame* render_frame,
137 blink::WebFrame* frame) override;
138 bool AllowPepperMediaStreamAPI(const GURL& url) override;
139 void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems) override;
140 bool IsPluginAllowedToUseDevChannelAPIs() override;
141 bool IsPluginAllowedToUseCameraDeviceAPI(const GURL& url) override;
142 bool IsPluginAllowedToUseCompositorAPI(const GURL& url) override;
143 content::BrowserPluginDelegate* CreateBrowserPluginDelegate(
144 content::RenderFrame* render_frame,
145 const std::string& mime_type,
146 const GURL& original_url) override;
147 void RecordRappor(const std::string& metric,
148 const std::string& sample) override;
149 void RecordRapporURL(const std::string& metric, const GURL& url) override;
150 scoped_ptr<blink::WebAppBannerClient> CreateAppBannerClient(
151 content::RenderFrame* render_frame) override;
152 void AddImageContextMenuProperties(
153 const blink::WebURLResponse& response,
154 std::map<std::string, std::string>* properties) override;
155 void DidInitializeServiceWorkerContextOnWorkerThread(
156 v8::Local<v8::Context> context,
157 const GURL& url) override;
158 void WillDestroyServiceWorkerContextOnWorkerThread(const GURL& url) override;
159 #if defined(ENABLE_EXTENSIONS)
160 // Takes ownership.
161 void SetExtensionDispatcherForTest(
162 extensions::Dispatcher* extension_dispatcher);
163 extensions::Dispatcher* GetExtensionDispatcherForTest();
164 #endif
166 #if defined(ENABLE_SPELLCHECK)
167 // Sets a new |spellcheck|. Used for testing only.
168 // Takes ownership of |spellcheck|.
169 void SetSpellcheck(SpellCheck* spellcheck);
170 #endif
172 #if defined(ENABLE_PLUGINS)
173 static blink::WebPlugin* CreatePlugin(
174 content::RenderFrame* render_frame,
175 blink::WebLocalFrame* frame,
176 const blink::WebPluginParams& params,
177 const ChromeViewHostMsg_GetPluginInfo_Output& output);
178 #endif
180 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
181 static bool IsExtensionOrSharedModuleWhitelisted(
182 const GURL& url, const std::set<std::string>& whitelist);
183 #endif
185 static bool WasWebRequestUsedBySomeExtensions();
187 private:
188 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, NaClRestriction);
189 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest,
190 ShouldSuppressErrorPage);
192 #if defined(ENABLE_EXTENSIONS)
193 // Gets extension by the given origin, regardless of whether the extension
194 // is active in the current process.
195 const extensions::Extension* GetExtensionByOrigin(
196 const blink::WebSecurityOrigin& origin) const;
198 // Returns true if the frame is navigating to an URL either into or out of an
199 // extension app's extent.
200 bool CrossesExtensionExtents(blink::WebLocalFrame* frame,
201 const GURL& new_url,
202 bool is_extension_url,
203 bool is_initial_navigation);
204 #endif
206 static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type,
207 const content::WebPluginInfo& plugin);
209 #if !defined(DISABLE_NACL)
210 // Determines if a NaCl app is allowed, and modifies params to pass the app's
211 // permissions to the trusted NaCl plugin.
212 static bool IsNaClAllowed(const GURL& manifest_url,
213 const GURL& app_url,
214 bool is_nacl_unrestricted,
215 const extensions::Extension* extension,
216 blink::WebPluginParams* params);
217 #endif
219 scoped_ptr<ChromeRenderProcessObserver> chrome_observer_;
220 scoped_ptr<web_cache::WebCacheRenderProcessObserver> web_cache_observer_;
222 // TODO(thestig): Extract into a separate file if possible. Cleanup
223 // ENABLE_EXTENSIONS ifdefs in the .cc file as well.
224 #if defined(ENABLE_EXTENSIONS)
225 scoped_ptr<ChromeExtensionsDispatcherDelegate> extension_dispatcher_delegate_;
226 scoped_ptr<extensions::Dispatcher> extension_dispatcher_;
227 scoped_ptr<extensions::RendererPermissionsPolicyDelegate>
228 permissions_policy_delegate_;
229 scoped_ptr<extensions::ExtensionsGuestViewContainerDispatcher>
230 guest_view_container_dispatcher_;
231 #endif
233 scoped_ptr<network_hints::PrescientNetworkingDispatcher>
234 prescient_networking_dispatcher_;
235 scoped_ptr<password_manager::CredentialManagerClient>
236 credential_manager_client_;
237 #if defined(ENABLE_SPELLCHECK)
238 scoped_ptr<SpellCheck> spellcheck_;
239 #endif
240 scoped_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
241 scoped_ptr<safe_browsing::PhishingClassifierFilter> phishing_classifier_;
242 scoped_ptr<prerender::PrerenderDispatcher> prerender_dispatcher_;
243 #if defined(ENABLE_WEBRTC)
244 scoped_refptr<WebRtcLoggingMessageFilter> webrtc_logging_message_filter_;
245 #endif
246 #if defined(ENABLE_PRINT_PREVIEW)
247 scoped_ptr<ChromePDFPrintClient> pdf_print_client_;
248 #endif
249 #if defined(ENABLE_PLUGINS)
250 std::set<std::string> allowed_camera_device_origins_;
251 std::set<std::string> allowed_compositor_origins_;
252 #endif
255 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_