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 scoped_ptr
<blink::WebPluginPlaceholder
> CreatePluginPlaceholder(
93 content::RenderFrame
* render_frame
,
94 blink::WebLocalFrame
* frame
,
95 const blink::WebPluginParams
& params
) override
;
96 blink::WebPlugin
* CreatePluginReplacement(
97 content::RenderFrame
* render_frame
,
98 const base::FilePath
& plugin_path
) override
;
99 bool HasErrorPage(int http_status_code
, std::string
* error_domain
) override
;
100 bool ShouldSuppressErrorPage(content::RenderFrame
* render_frame
,
101 const GURL
& url
) override
;
102 void GetNavigationErrorStrings(content::RenderView
* render_view
,
103 blink::WebFrame
* frame
,
104 const blink::WebURLRequest
& failed_request
,
105 const blink::WebURLError
& error
,
106 std::string
* error_html
,
107 base::string16
* error_description
) override
;
108 void DeferMediaLoad(content::RenderFrame
* render_frame
,
109 bool has_played_media_before
,
110 const base::Closure
& closure
) override
;
111 bool RunIdleHandlerWhenWidgetsHidden() override
;
112 bool AllowPopup() override
;
113 bool ShouldFork(blink::WebLocalFrame
* frame
,
115 const std::string
& http_method
,
116 bool is_initial_navigation
,
117 bool is_server_redirect
,
118 bool* send_referrer
) 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 ShouldGatherSiteIsolationStats() 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
;
150 void RecordRappor(const std::string
& metric
,
151 const std::string
& sample
) override
;
152 void RecordRapporURL(const std::string
& metric
, const GURL
& url
) override
;
153 scoped_ptr
<blink::WebAppBannerClient
> CreateAppBannerClient(
154 content::RenderFrame
* render_frame
) override
;
155 void AddImageContextMenuProperties(
156 const blink::WebURLResponse
& response
,
157 std::map
<std::string
, std::string
>* properties
) override
;
158 void DidInitializeServiceWorkerContextOnWorkerThread(
159 v8::Local
<v8::Context
> context
,
160 const GURL
& url
) override
;
161 #if defined(ENABLE_EXTENSIONS)
163 void SetExtensionDispatcherForTest(
164 extensions::Dispatcher
* extension_dispatcher
);
165 extensions::Dispatcher
* GetExtensionDispatcherForTest();
168 #if defined(ENABLE_SPELLCHECK)
169 // Sets a new |spellcheck|. Used for testing only.
170 // Takes ownership of |spellcheck|.
171 void SetSpellcheck(SpellCheck
* spellcheck
);
174 #if defined(ENABLE_PLUGINS)
175 static blink::WebPlugin
* CreatePlugin(
176 content::RenderFrame
* render_frame
,
177 blink::WebLocalFrame
* frame
,
178 const blink::WebPluginParams
& params
,
179 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
182 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
183 static bool IsExtensionOrSharedModuleWhitelisted(
184 const GURL
& url
, const std::set
<std::string
>& whitelist
);
187 static bool WasWebRequestUsedBySomeExtensions();
190 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
191 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
,
192 ShouldSuppressErrorPage
);
194 #if defined(ENABLE_EXTENSIONS)
195 // Gets extension by the given origin, regardless of whether the extension
196 // is active in the current process.
197 const extensions::Extension
* GetExtensionByOrigin(
198 const blink::WebSecurityOrigin
& origin
) const;
200 // Returns true if the frame is navigating to an URL either into or out of an
201 // extension app's extent.
202 bool CrossesExtensionExtents(blink::WebLocalFrame
* frame
,
204 bool is_extension_url
,
205 bool is_initial_navigation
);
208 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
209 const content::WebPluginInfo
& plugin
);
211 #if !defined(DISABLE_NACL)
212 // Determines if a NaCl app is allowed, and modifies params to pass the app's
213 // permissions to the trusted NaCl plugin.
214 static bool IsNaClAllowed(const GURL
& manifest_url
,
216 bool is_nacl_unrestricted
,
217 const extensions::Extension
* extension
,
218 blink::WebPluginParams
* params
);
221 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
222 scoped_ptr
<web_cache::WebCacheRenderProcessObserver
> web_cache_observer_
;
224 // TODO(thestig): Extract into a separate file if possible. Cleanup
225 // ENABLE_EXTENSIONS ifdefs in the .cc file as well.
226 #if defined(ENABLE_EXTENSIONS)
227 scoped_ptr
<ChromeExtensionsDispatcherDelegate
> extension_dispatcher_delegate_
;
228 scoped_ptr
<extensions::Dispatcher
> extension_dispatcher_
;
229 scoped_ptr
<extensions::RendererPermissionsPolicyDelegate
>
230 permissions_policy_delegate_
;
231 scoped_ptr
<extensions::ExtensionsGuestViewContainerDispatcher
>
232 guest_view_container_dispatcher_
;
235 scoped_ptr
<network_hints::PrescientNetworkingDispatcher
>
236 prescient_networking_dispatcher_
;
237 scoped_ptr
<password_manager::CredentialManagerClient
>
238 credential_manager_client_
;
239 #if defined(ENABLE_SPELLCHECK)
240 scoped_ptr
<SpellCheck
> spellcheck_
;
242 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
243 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
244 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
245 #if defined(ENABLE_WEBRTC)
246 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
248 #if defined(ENABLE_PRINT_PREVIEW)
249 scoped_ptr
<ChromePDFPrintClient
> pdf_print_client_
;
251 #if defined(ENABLE_PLUGINS)
252 std::set
<std::string
> allowed_camera_device_origins_
;
253 std::set
<std::string
> allowed_compositor_origins_
;
257 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_