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_
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/strings/string16.h"
15 #include "content/public/renderer/content_renderer_client.h"
16 #include "ipc/ipc_channel_proxy.h"
18 class ChromeExtensionsDispatcherDelegate
;
19 class ChromeRenderProcessObserver
;
20 #if defined(ENABLE_PRINT_PREVIEW)
21 class ChromePDFPrintClient
;
23 class PrescientNetworkingDispatcher
;
25 #if defined(ENABLE_SPELLCHECK)
27 class SpellCheckProvider
;
30 struct ChromeViewHostMsg_GetPluginInfo_Output
;
33 class BrowserPluginDelegate
;
37 namespace network_hints
{
38 class PrescientNetworkingDispatcher
;
41 namespace extensions
{
45 class RendererPermissionsPolicyDelegate
;
49 class PrerenderDispatcher
;
52 namespace safe_browsing
{
53 class PhishingClassifierFilter
;
56 namespace visitedlink
{
57 class VisitedLinkSlave
;
61 class WebCacheRenderProcessObserver
;
65 class WebSecurityOrigin
;
68 namespace password_manager
{
69 class CredentialManagerClient
;
72 #if defined(ENABLE_WEBRTC)
73 class WebRtcLoggingMessageFilter
;
76 class ChromeContentRendererClient
: public content::ContentRendererClient
{
78 ChromeContentRendererClient();
79 ~ChromeContentRendererClient() override
;
81 void RenderThreadStarted() override
;
82 void RenderFrameCreated(content::RenderFrame
* render_frame
) override
;
83 void RenderViewCreated(content::RenderView
* render_view
) override
;
84 SkBitmap
* GetSadPluginBitmap() override
;
85 SkBitmap
* GetSadWebViewBitmap() override
;
86 bool OverrideCreatePlugin(content::RenderFrame
* render_frame
,
87 blink::WebLocalFrame
* frame
,
88 const blink::WebPluginParams
& params
,
89 blink::WebPlugin
** plugin
) override
;
90 scoped_ptr
<blink::WebPluginPlaceholder
> CreatePluginPlaceholder(
91 content::RenderFrame
* render_frame
,
92 blink::WebLocalFrame
* frame
,
93 const blink::WebPluginParams
& params
) override
;
94 blink::WebPlugin
* CreatePluginReplacement(
95 content::RenderFrame
* render_frame
,
96 const base::FilePath
& plugin_path
) override
;
97 bool HasErrorPage(int http_status_code
, std::string
* error_domain
) override
;
98 bool ShouldSuppressErrorPage(content::RenderFrame
* render_frame
,
99 const GURL
& url
) override
;
100 void GetNavigationErrorStrings(content::RenderView
* render_view
,
101 blink::WebFrame
* frame
,
102 const blink::WebURLRequest
& failed_request
,
103 const blink::WebURLError
& error
,
104 std::string
* error_html
,
105 base::string16
* error_description
) override
;
106 void DeferMediaLoad(content::RenderFrame
* render_frame
,
107 const base::Closure
& closure
) override
;
108 bool RunIdleHandlerWhenWidgetsHidden() override
;
109 bool AllowPopup() override
;
110 bool ShouldFork(blink::WebFrame
* frame
,
112 const std::string
& http_method
,
113 bool is_initial_navigation
,
114 bool is_server_redirect
,
115 bool* send_referrer
) override
;
116 #if defined(ENABLE_EXTENSIONS)
117 bool ShouldForwardToGuestContainer(const IPC::Message
& msg
) override
;
119 bool WillSendRequest(blink::WebFrame
* frame
,
120 ui::PageTransition transition_type
,
122 const GURL
& first_party_for_cookies
,
123 GURL
* new_url
) override
;
124 unsigned long long VisitedLinkHash(const char* canonical_url
,
125 size_t length
) override
;
126 bool IsLinkVisited(unsigned long long link_hash
) override
;
127 blink::WebPrescientNetworking
* GetPrescientNetworking() override
;
128 bool ShouldOverridePageVisibilityState(
129 const content::RenderFrame
* render_frame
,
130 blink::WebPageVisibilityState
* override_state
) override
;
131 const void* CreatePPAPIInterface(const std::string
& interface_name
) override
;
132 bool IsExternalPepperPlugin(const std::string
& module_name
) override
;
133 blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
134 blink::WebSpeechSynthesizerClient
* client
) override
;
135 bool ShouldReportDetailedMessageForSource(
136 const base::string16
& source
) const override
;
137 bool ShouldEnableSiteIsolationPolicy() const override
;
138 blink::WebWorkerContentSettingsClientProxy
*
139 CreateWorkerContentSettingsClientProxy(content::RenderFrame
* render_frame
,
140 blink::WebFrame
* frame
) override
;
141 bool AllowPepperMediaStreamAPI(const GURL
& url
) override
;
142 void AddKeySystems(std::vector
<media::KeySystemInfo
>* key_systems
) override
;
143 bool IsPluginAllowedToUseDevChannelAPIs() override
;
144 bool IsPluginAllowedToUseCameraDeviceAPI(const GURL
& url
) override
;
145 bool IsPluginAllowedToUseCompositorAPI(const GURL
& url
) override
;
146 content::BrowserPluginDelegate
* CreateBrowserPluginDelegate(
147 content::RenderFrame
* render_frame
,
148 const std::string
& mime_type
,
149 const GURL
& original_url
) override
;
151 #if defined(ENABLE_EXTENSIONS)
153 void SetExtensionDispatcherForTest(
154 extensions::Dispatcher
* extension_dispatcher
);
155 extensions::Dispatcher
* GetExtensionDispatcherForTest();
158 #if defined(ENABLE_SPELLCHECK)
159 // Sets a new |spellcheck|. Used for testing only.
160 // Takes ownership of |spellcheck|.
161 void SetSpellcheck(SpellCheck
* spellcheck
);
164 static blink::WebPlugin
* CreatePlugin(
165 content::RenderFrame
* render_frame
,
166 blink::WebLocalFrame
* frame
,
167 const blink::WebPluginParams
& params
,
168 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
170 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
171 static bool IsExtensionOrSharedModuleWhitelisted(
172 const GURL
& url
, const std::set
<std::string
>& whitelist
);
175 static bool WasWebRequestUsedBySomeExtensions();
178 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
179 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
,
180 ShouldSuppressErrorPage
);
182 #if defined(ENABLE_EXTENSIONS)
183 // Gets extension by the given origin, regardless of whether the extension
184 // is active in the current process.
185 const extensions::Extension
* GetExtensionByOrigin(
186 const blink::WebSecurityOrigin
& origin
) const;
188 // Returns true if the frame is navigating to an URL either into or out of an
189 // extension app's extent.
190 bool CrossesExtensionExtents(blink::WebFrame
* frame
,
192 const extensions::ExtensionSet
& extensions
,
193 bool is_extension_url
,
194 bool is_initial_navigation
);
197 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
198 const content::WebPluginInfo
& plugin
);
200 #if !defined(DISABLE_NACL)
201 // Determines if a NaCl app is allowed, and modifies params to pass the app's
202 // permissions to the trusted NaCl plugin.
203 static bool IsNaClAllowed(const GURL
& manifest_url
,
205 bool is_nacl_unrestricted
,
206 const extensions::Extension
* extension
,
207 blink::WebPluginParams
* params
);
210 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
211 scoped_ptr
<web_cache::WebCacheRenderProcessObserver
> web_cache_observer_
;
213 // TODO(thestig): Extract into a separate file if possible. Cleanup
214 // ENABLE_EXTENSIONS ifdefs in the .cc file as well.
215 #if defined(ENABLE_EXTENSIONS)
216 scoped_ptr
<ChromeExtensionsDispatcherDelegate
> extension_dispatcher_delegate_
;
217 scoped_ptr
<extensions::Dispatcher
> extension_dispatcher_
;
218 scoped_ptr
<extensions::RendererPermissionsPolicyDelegate
>
219 permissions_policy_delegate_
;
222 scoped_ptr
<network_hints::PrescientNetworkingDispatcher
>
223 prescient_networking_dispatcher_
;
224 scoped_ptr
<password_manager::CredentialManagerClient
>
225 credential_manager_client_
;
226 #if defined(ENABLE_SPELLCHECK)
227 scoped_ptr
<SpellCheck
> spellcheck_
;
229 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
230 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
231 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
232 #if defined(ENABLE_WEBRTC)
233 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
235 scoped_ptr
<SearchBouncer
> search_bouncer_
;
236 #if defined(ENABLE_PRINT_PREVIEW)
237 scoped_ptr
<ChromePDFPrintClient
> pdf_print_client_
;
239 #if defined(ENABLE_PLUGINS)
240 std::set
<std::string
> allowed_camera_device_origins_
;
241 std::set
<std::string
> allowed_compositor_origins_
;
245 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_