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_
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
;
25 class PrescientNetworkingDispatcher
;
26 #if defined(ENABLE_SPELLCHECK)
28 class SpellCheckProvider
;
31 struct ChromeViewHostMsg_GetPluginInfo_Output
;
34 class BrowserPluginDelegate
;
38 namespace network_hints
{
39 class PrescientNetworkingDispatcher
;
42 namespace extensions
{
46 class ExtensionsGuestViewContainerDispatcher
;
47 class RendererPermissionsPolicyDelegate
;
51 class PrerenderDispatcher
;
54 namespace safe_browsing
{
55 class PhishingClassifierFilter
;
58 namespace visitedlink
{
59 class VisitedLinkSlave
;
63 class WebCacheRenderProcessObserver
;
67 class WebSecurityOrigin
;
70 namespace password_manager
{
71 class CredentialManagerClient
;
74 #if defined(ENABLE_WEBRTC)
75 class WebRtcLoggingMessageFilter
;
78 class ChromeContentRendererClient
: public content::ContentRendererClient
{
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 AllowPopup() override
;
109 bool ShouldFork(blink::WebLocalFrame
* frame
,
111 const std::string
& http_method
,
112 bool is_initial_navigation
,
113 bool is_server_redirect
,
114 bool* send_referrer
) override
;
115 bool WillSendRequest(blink::WebFrame
* frame
,
116 ui::PageTransition transition_type
,
118 const GURL
& first_party_for_cookies
,
119 GURL
* new_url
) override
;
120 unsigned long long VisitedLinkHash(const char* canonical_url
,
121 size_t length
) override
;
122 bool IsLinkVisited(unsigned long long link_hash
) override
;
123 blink::WebPrescientNetworking
* GetPrescientNetworking() override
;
124 bool ShouldOverridePageVisibilityState(
125 const content::RenderFrame
* render_frame
,
126 blink::WebPageVisibilityState
* override_state
) override
;
127 const void* CreatePPAPIInterface(const std::string
& interface_name
) override
;
128 bool IsExternalPepperPlugin(const std::string
& module_name
) override
;
129 blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
130 blink::WebSpeechSynthesizerClient
* client
) override
;
131 bool ShouldReportDetailedMessageForSource(
132 const base::string16
& source
) const override
;
133 bool ShouldGatherSiteIsolationStats() const override
;
134 blink::WebWorkerContentSettingsClientProxy
*
135 CreateWorkerContentSettingsClientProxy(content::RenderFrame
* render_frame
,
136 blink::WebFrame
* frame
) override
;
137 bool AllowPepperMediaStreamAPI(const GURL
& url
) override
;
138 void AddKeySystems(std::vector
<media::KeySystemInfo
>* key_systems
) override
;
139 bool IsPluginAllowedToUseDevChannelAPIs() override
;
140 bool IsPluginAllowedToUseCameraDeviceAPI(const GURL
& url
) override
;
141 bool IsPluginAllowedToUseCompositorAPI(const GURL
& url
) override
;
142 content::BrowserPluginDelegate
* CreateBrowserPluginDelegate(
143 content::RenderFrame
* render_frame
,
144 const std::string
& mime_type
,
145 const GURL
& original_url
) override
;
146 void RecordRappor(const std::string
& metric
,
147 const std::string
& sample
) override
;
148 void RecordRapporURL(const std::string
& metric
, const GURL
& url
) override
;
149 scoped_ptr
<blink::WebAppBannerClient
> CreateAppBannerClient(
150 content::RenderFrame
* render_frame
) override
;
151 void AddImageContextMenuProperties(
152 const blink::WebURLResponse
& response
,
153 std::map
<std::string
, std::string
>* properties
) override
;
154 void DidInitializeServiceWorkerContextOnWorkerThread(
155 v8::Local
<v8::Context
> context
,
156 const GURL
& url
) override
;
157 void WillDestroyServiceWorkerContextOnWorkerThread(const GURL
& url
) override
;
158 #if defined(ENABLE_EXTENSIONS)
160 void SetExtensionDispatcherForTest(
161 extensions::Dispatcher
* extension_dispatcher
);
162 extensions::Dispatcher
* GetExtensionDispatcherForTest();
165 #if defined(ENABLE_SPELLCHECK)
166 // Sets a new |spellcheck|. Used for testing only.
167 // Takes ownership of |spellcheck|.
168 void SetSpellcheck(SpellCheck
* spellcheck
);
171 #if defined(ENABLE_PLUGINS)
172 static blink::WebPlugin
* CreatePlugin(
173 content::RenderFrame
* render_frame
,
174 blink::WebLocalFrame
* frame
,
175 const blink::WebPluginParams
& params
,
176 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
179 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
180 static bool IsExtensionOrSharedModuleWhitelisted(
181 const GURL
& url
, const std::set
<std::string
>& whitelist
);
184 static bool WasWebRequestUsedBySomeExtensions();
187 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
188 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
,
189 ShouldSuppressErrorPage
);
191 #if defined(ENABLE_EXTENSIONS)
192 // Gets extension by the given origin, regardless of whether the extension
193 // is active in the current process.
194 const extensions::Extension
* GetExtensionByOrigin(
195 const blink::WebSecurityOrigin
& origin
) const;
197 // Returns true if the frame is navigating to an URL either into or out of an
198 // extension app's extent.
199 bool CrossesExtensionExtents(blink::WebLocalFrame
* frame
,
201 bool is_extension_url
,
202 bool is_initial_navigation
);
205 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
206 const content::WebPluginInfo
& plugin
);
208 #if !defined(DISABLE_NACL)
209 // Determines if a NaCl app is allowed, and modifies params to pass the app's
210 // permissions to the trusted NaCl plugin.
211 static bool IsNaClAllowed(const GURL
& manifest_url
,
213 bool is_nacl_unrestricted
,
214 const extensions::Extension
* extension
,
215 blink::WebPluginParams
* params
);
218 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
219 scoped_ptr
<web_cache::WebCacheRenderProcessObserver
> web_cache_observer_
;
221 // TODO(thestig): Extract into a separate file if possible. Cleanup
222 // ENABLE_EXTENSIONS ifdefs in the .cc file as well.
223 #if defined(ENABLE_EXTENSIONS)
224 scoped_ptr
<ChromeExtensionsDispatcherDelegate
> extension_dispatcher_delegate_
;
225 scoped_ptr
<extensions::Dispatcher
> extension_dispatcher_
;
226 scoped_ptr
<extensions::RendererPermissionsPolicyDelegate
>
227 permissions_policy_delegate_
;
228 scoped_ptr
<extensions::ExtensionsGuestViewContainerDispatcher
>
229 guest_view_container_dispatcher_
;
232 scoped_ptr
<network_hints::PrescientNetworkingDispatcher
>
233 prescient_networking_dispatcher_
;
234 scoped_ptr
<password_manager::CredentialManagerClient
>
235 credential_manager_client_
;
236 #if defined(ENABLE_SPELLCHECK)
237 scoped_ptr
<SpellCheck
> spellcheck_
;
239 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
240 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
241 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
242 #if defined(ENABLE_WEBRTC)
243 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
245 #if defined(ENABLE_PRINT_PREVIEW)
246 scoped_ptr
<ChromePDFPrintClient
> pdf_print_client_
;
248 #if defined(ENABLE_PLUGINS)
249 std::set
<std::string
> allowed_camera_device_origins_
;
250 std::set
<std::string
> allowed_compositor_origins_
;
254 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_