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 class PrescientNetworkingDispatcher
;
21 class RendererNetPredictor
;
23 #if defined(ENABLE_SPELLCHECK)
25 class SpellCheckProvider
;
28 struct ChromeViewHostMsg_GetPluginInfo_Output
;
34 namespace extensions
{
38 class RendererPermissionsPolicyDelegate
;
42 class PrerenderDispatcher
;
45 namespace safe_browsing
{
46 class PhishingClassifierFilter
;
49 namespace visitedlink
{
50 class VisitedLinkSlave
;
54 class WebSecurityOrigin
;
57 #if defined(ENABLE_WEBRTC)
58 class WebRtcLoggingMessageFilter
;
61 class ChromeContentRendererClient
: public content::ContentRendererClient
{
63 ChromeContentRendererClient();
64 virtual ~ChromeContentRendererClient();
66 virtual void RenderThreadStarted() OVERRIDE
;
67 virtual void RenderFrameCreated(content::RenderFrame
* render_frame
) OVERRIDE
;
68 virtual void RenderViewCreated(content::RenderView
* render_view
) OVERRIDE
;
69 virtual void SetNumberOfViews(int number_of_views
) OVERRIDE
;
70 virtual SkBitmap
* GetSadPluginBitmap() OVERRIDE
;
71 virtual SkBitmap
* GetSadWebViewBitmap() OVERRIDE
;
72 virtual std::string
GetDefaultEncoding() OVERRIDE
;
73 virtual bool OverrideCreatePlugin(
74 content::RenderFrame
* render_frame
,
75 blink::WebLocalFrame
* frame
,
76 const blink::WebPluginParams
& params
,
77 blink::WebPlugin
** plugin
) OVERRIDE
;
78 virtual blink::WebPlugin
* CreatePluginReplacement(
79 content::RenderFrame
* render_frame
,
80 const base::FilePath
& plugin_path
) OVERRIDE
;
81 virtual bool HasErrorPage(int http_status_code
,
82 std::string
* error_domain
) OVERRIDE
;
83 virtual bool ShouldSuppressErrorPage(content::RenderFrame
* render_frame
,
84 const GURL
& url
) OVERRIDE
;
85 virtual void GetNavigationErrorStrings(
86 content::RenderView
* render_view
,
87 blink::WebFrame
* frame
,
88 const blink::WebURLRequest
& failed_request
,
89 const blink::WebURLError
& error
,
90 std::string
* error_html
,
91 base::string16
* error_description
) OVERRIDE
;
92 virtual void DeferMediaLoad(content::RenderFrame
* render_frame
,
93 const base::Closure
& closure
) OVERRIDE
;
94 virtual bool RunIdleHandlerWhenWidgetsHidden() OVERRIDE
;
95 virtual bool AllowPopup() OVERRIDE
;
96 virtual bool ShouldFork(blink::WebFrame
* frame
,
98 const std::string
& http_method
,
99 bool is_initial_navigation
,
100 bool is_server_redirect
,
101 bool* send_referrer
) OVERRIDE
;
102 virtual bool WillSendRequest(blink::WebFrame
* frame
,
103 content::PageTransition transition_type
,
105 const GURL
& first_party_for_cookies
,
106 GURL
* new_url
) OVERRIDE
;
107 virtual void DidCreateScriptContext(blink::WebFrame
* frame
,
108 v8::Handle
<v8::Context
> context
,
110 int world_id
) OVERRIDE
;
111 virtual unsigned long long VisitedLinkHash(const char* canonical_url
,
112 size_t length
) OVERRIDE
;
113 virtual bool IsLinkVisited(unsigned long long link_hash
) OVERRIDE
;
114 virtual blink::WebPrescientNetworking
* GetPrescientNetworking() OVERRIDE
;
115 virtual bool ShouldOverridePageVisibilityState(
116 const content::RenderFrame
* render_frame
,
117 blink::WebPageVisibilityState
* override_state
) OVERRIDE
;
118 virtual bool AllowBrowserPlugin(
119 blink::WebPluginContainer
* container
) OVERRIDE
;
120 virtual const void* CreatePPAPIInterface(
121 const std::string
& interface_name
) OVERRIDE
;
122 virtual bool IsExternalPepperPlugin(const std::string
& module_name
) OVERRIDE
;
123 virtual blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
124 blink::WebSpeechSynthesizerClient
* client
) OVERRIDE
;
125 virtual bool ShouldReportDetailedMessageForSource(
126 const base::string16
& source
) const OVERRIDE
;
127 virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE
;
128 virtual blink::WebWorkerPermissionClientProxy
*
129 CreateWorkerPermissionClientProxy(content::RenderFrame
* render_frame
,
130 blink::WebFrame
* frame
) OVERRIDE
;
131 virtual bool AllowPepperMediaStreamAPI(const GURL
& url
) OVERRIDE
;
132 virtual void AddKeySystems(
133 std::vector
<content::KeySystemInfo
>* key_systems
) OVERRIDE
;
136 void SetExtensionDispatcherForTest(
137 extensions::Dispatcher
* extension_dispatcher
);
138 extensions::Dispatcher
* GetExtensionDispatcherForTest();
140 #if defined(ENABLE_SPELLCHECK)
141 // Sets a new |spellcheck|. Used for testing only.
142 // Takes ownership of |spellcheck|.
143 void SetSpellcheck(SpellCheck
* spellcheck
);
146 static blink::WebPlugin
* CreatePlugin(
147 content::RenderFrame
* render_frame
,
148 blink::WebLocalFrame
* frame
,
149 const blink::WebPluginParams
& params
,
150 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
152 static bool IsExtensionOrSharedModuleWhitelisted(
153 const GURL
& url
, const std::set
<std::string
>& whitelist
);
155 // TODO(mpcomplete): remove after we collect histogram data.
156 // http://crbug.com/100411
157 static bool IsAdblockInstalled();
158 static bool IsAdblockPlusInstalled();
159 static bool IsAdblockWithWebRequestInstalled();
160 static bool IsAdblockPlusWithWebRequestInstalled();
161 static bool IsOtherExtensionWithWebRequestInstalled();
164 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
165 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
,
166 ShouldSuppressErrorPage
);
168 // Gets extension by the given origin, regardless of whether the extension
169 // is active in the current process.
170 const extensions::Extension
* GetExtensionByOrigin(
171 const blink::WebSecurityOrigin
& origin
) const;
173 // Returns true if the frame is navigating to an URL either into or out of an
174 // extension app's extent.
175 bool CrossesExtensionExtents(blink::WebFrame
* frame
,
177 const extensions::ExtensionSet
& extensions
,
178 bool is_extension_url
,
179 bool is_initial_navigation
);
181 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
182 const content::WebPluginInfo
& plugin
);
184 // Determines if a NaCl app is allowed, and modifies params to pass the app's
185 // permissions to the trusted NaCl plugin.
186 static bool IsNaClAllowed(const GURL
& manifest_url
,
188 bool is_nacl_unrestricted
,
189 const extensions::Extension
* extension
,
190 blink::WebPluginParams
* params
);
192 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
193 scoped_ptr
<ChromeExtensionsDispatcherDelegate
> extension_dispatcher_delegate_
;
194 scoped_ptr
<extensions::Dispatcher
> extension_dispatcher_
;
195 scoped_ptr
<extensions::RendererPermissionsPolicyDelegate
>
196 permissions_policy_delegate_
;
197 scoped_ptr
<PrescientNetworkingDispatcher
> prescient_networking_dispatcher_
;
198 scoped_ptr
<RendererNetPredictor
> net_predictor_
;
199 #if defined(ENABLE_SPELLCHECK)
200 scoped_ptr
<SpellCheck
> spellcheck_
;
202 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
203 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
204 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
205 #if defined(ENABLE_WEBRTC)
206 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
208 scoped_ptr
<SearchBouncer
> search_bouncer_
;
211 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_