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_FULL_PRINTING)
21 class ChromePDFPrintClient
;
23 class PrescientNetworkingDispatcher
;
24 class RendererNetPredictor
;
26 #if defined(ENABLE_SPELLCHECK)
28 class SpellCheckProvider
;
31 struct ChromeViewHostMsg_GetPluginInfo_Output
;
37 namespace extensions
{
41 class RendererPermissionsPolicyDelegate
;
45 class PrerenderDispatcher
;
48 namespace safe_browsing
{
49 class PhishingClassifierFilter
;
52 namespace visitedlink
{
53 class VisitedLinkSlave
;
57 class WebSecurityOrigin
;
60 namespace password_manager
{
61 class CredentialManagerClient
;
64 #if defined(ENABLE_WEBRTC)
65 class WebRtcLoggingMessageFilter
;
68 class ChromeContentRendererClient
: public content::ContentRendererClient
{
70 ChromeContentRendererClient();
71 virtual ~ChromeContentRendererClient();
73 virtual void RenderThreadStarted() OVERRIDE
;
74 virtual void RenderFrameCreated(content::RenderFrame
* render_frame
) OVERRIDE
;
75 virtual void RenderViewCreated(content::RenderView
* render_view
) OVERRIDE
;
76 virtual void SetNumberOfViews(int number_of_views
) OVERRIDE
;
77 virtual SkBitmap
* GetSadPluginBitmap() OVERRIDE
;
78 virtual SkBitmap
* GetSadWebViewBitmap() OVERRIDE
;
79 virtual std::string
GetDefaultEncoding() OVERRIDE
;
80 virtual bool OverrideCreatePlugin(
81 content::RenderFrame
* render_frame
,
82 blink::WebLocalFrame
* frame
,
83 const blink::WebPluginParams
& params
,
84 blink::WebPlugin
** plugin
) OVERRIDE
;
85 virtual blink::WebPlugin
* CreatePluginReplacement(
86 content::RenderFrame
* render_frame
,
87 const base::FilePath
& plugin_path
) OVERRIDE
;
88 virtual bool HasErrorPage(int http_status_code
,
89 std::string
* error_domain
) OVERRIDE
;
90 virtual bool ShouldSuppressErrorPage(content::RenderFrame
* render_frame
,
91 const GURL
& url
) OVERRIDE
;
92 virtual void GetNavigationErrorStrings(
93 content::RenderView
* render_view
,
94 blink::WebFrame
* frame
,
95 const blink::WebURLRequest
& failed_request
,
96 const blink::WebURLError
& error
,
97 std::string
* error_html
,
98 base::string16
* error_description
) OVERRIDE
;
99 virtual void DeferMediaLoad(content::RenderFrame
* render_frame
,
100 const base::Closure
& closure
) OVERRIDE
;
101 virtual bool RunIdleHandlerWhenWidgetsHidden() OVERRIDE
;
102 virtual bool AllowPopup() OVERRIDE
;
103 virtual bool ShouldFork(blink::WebFrame
* frame
,
105 const std::string
& http_method
,
106 bool is_initial_navigation
,
107 bool is_server_redirect
,
108 bool* send_referrer
) OVERRIDE
;
109 virtual bool WillSendRequest(blink::WebFrame
* frame
,
110 content::PageTransition transition_type
,
112 const GURL
& first_party_for_cookies
,
113 GURL
* new_url
) OVERRIDE
;
114 virtual void DidCreateScriptContext(blink::WebFrame
* frame
,
115 v8::Handle
<v8::Context
> context
,
117 int world_id
) OVERRIDE
;
118 virtual unsigned long long VisitedLinkHash(const char* canonical_url
,
119 size_t length
) OVERRIDE
;
120 virtual bool IsLinkVisited(unsigned long long link_hash
) OVERRIDE
;
121 virtual blink::WebPrescientNetworking
* GetPrescientNetworking() OVERRIDE
;
122 virtual bool ShouldOverridePageVisibilityState(
123 const content::RenderFrame
* render_frame
,
124 blink::WebPageVisibilityState
* override_state
) OVERRIDE
;
125 virtual const void* CreatePPAPIInterface(
126 const std::string
& interface_name
) OVERRIDE
;
127 virtual bool IsExternalPepperPlugin(const std::string
& module_name
) OVERRIDE
;
128 virtual blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
129 blink::WebSpeechSynthesizerClient
* client
) OVERRIDE
;
130 virtual bool ShouldReportDetailedMessageForSource(
131 const base::string16
& source
) const OVERRIDE
;
132 virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE
;
133 virtual blink::WebWorkerPermissionClientProxy
*
134 CreateWorkerPermissionClientProxy(content::RenderFrame
* render_frame
,
135 blink::WebFrame
* frame
) OVERRIDE
;
136 virtual bool AllowPepperMediaStreamAPI(const GURL
& url
) OVERRIDE
;
137 virtual void AddKeySystems(
138 std::vector
<content::KeySystemInfo
>* key_systems
) OVERRIDE
;
139 virtual bool IsPluginAllowedToUseDevChannelAPIs() OVERRIDE
;
140 virtual bool IsPluginAllowedToUseCompositorAPI(const GURL
& url
) OVERRIDE
;
141 virtual bool IsPluginAllowedToUseVideoDecodeAPI(const GURL
& url
) OVERRIDE
;
144 void SetExtensionDispatcherForTest(
145 extensions::Dispatcher
* extension_dispatcher
);
146 extensions::Dispatcher
* GetExtensionDispatcherForTest();
148 #if defined(ENABLE_SPELLCHECK)
149 // Sets a new |spellcheck|. Used for testing only.
150 // Takes ownership of |spellcheck|.
151 void SetSpellcheck(SpellCheck
* spellcheck
);
154 static blink::WebPlugin
* CreatePlugin(
155 content::RenderFrame
* render_frame
,
156 blink::WebLocalFrame
* frame
,
157 const blink::WebPluginParams
& params
,
158 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
160 static bool IsExtensionOrSharedModuleWhitelisted(
161 const GURL
& url
, const std::set
<std::string
>& whitelist
);
163 static bool WasWebRequestUsedBySomeExtensions();
166 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
167 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
,
168 ShouldSuppressErrorPage
);
170 // Gets extension by the given origin, regardless of whether the extension
171 // is active in the current process.
172 const extensions::Extension
* GetExtensionByOrigin(
173 const blink::WebSecurityOrigin
& origin
) const;
175 // Returns true if the frame is navigating to an URL either into or out of an
176 // extension app's extent.
177 bool CrossesExtensionExtents(blink::WebFrame
* frame
,
179 const extensions::ExtensionSet
& extensions
,
180 bool is_extension_url
,
181 bool is_initial_navigation
);
183 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
184 const content::WebPluginInfo
& plugin
);
186 // Determines if a NaCl app is allowed, and modifies params to pass the app's
187 // permissions to the trusted NaCl plugin.
188 static bool IsNaClAllowed(const GURL
& manifest_url
,
190 bool is_nacl_unrestricted
,
191 const extensions::Extension
* extension
,
192 blink::WebPluginParams
* params
);
194 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
195 scoped_ptr
<ChromeExtensionsDispatcherDelegate
> extension_dispatcher_delegate_
;
196 scoped_ptr
<extensions::Dispatcher
> extension_dispatcher_
;
197 scoped_ptr
<extensions::RendererPermissionsPolicyDelegate
>
198 permissions_policy_delegate_
;
199 scoped_ptr
<PrescientNetworkingDispatcher
> prescient_networking_dispatcher_
;
200 scoped_ptr
<RendererNetPredictor
> net_predictor_
;
201 scoped_ptr
<password_manager::CredentialManagerClient
>
202 credential_manager_client_
;
203 #if defined(ENABLE_SPELLCHECK)
204 scoped_ptr
<SpellCheck
> spellcheck_
;
206 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
207 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
208 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
209 #if defined(ENABLE_WEBRTC)
210 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
212 scoped_ptr
<SearchBouncer
> search_bouncer_
;
213 #if defined(ENABLE_FULL_PRINTING)
214 scoped_ptr
<ChromePDFPrintClient
> pdf_print_client_
;
216 #if defined(ENABLE_PLUGINS)
217 std::set
<std::string
> allowed_compositor_origins_
;
218 std::set
<std::string
> allowed_video_decode_origins_
;
222 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_