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"
17 class ChromeRenderProcessObserver
;
18 class PrescientNetworkingDispatcher
;
19 class RendererNetPredictor
;
21 #if defined(ENABLE_SPELLCHECK)
23 class SpellCheckProvider
;
26 struct ChromeViewHostMsg_GetPluginInfo_Output
;
32 namespace extensions
{
36 class RendererPermissionsPolicyDelegate
;
40 class PrerenderDispatcher
;
43 namespace safe_browsing
{
44 class PhishingClassifierFilter
;
47 namespace visitedlink
{
48 class VisitedLinkSlave
;
52 class WebSecurityOrigin
;
55 #if defined(ENABLE_WEBRTC)
56 class WebRtcLoggingMessageFilter
;
59 class ChromeContentRendererClient
: public content::ContentRendererClient
{
61 ChromeContentRendererClient();
62 virtual ~ChromeContentRendererClient();
64 virtual void RenderThreadStarted() OVERRIDE
;
65 virtual void RenderFrameCreated(content::RenderFrame
* render_frame
) OVERRIDE
;
66 virtual void RenderViewCreated(content::RenderView
* render_view
) OVERRIDE
;
67 virtual void SetNumberOfViews(int number_of_views
) OVERRIDE
;
68 virtual SkBitmap
* GetSadPluginBitmap() OVERRIDE
;
69 virtual SkBitmap
* GetSadWebViewBitmap() OVERRIDE
;
70 virtual std::string
GetDefaultEncoding() OVERRIDE
;
71 virtual bool OverrideCreatePlugin(
72 content::RenderFrame
* render_frame
,
73 blink::WebFrame
* frame
,
74 const blink::WebPluginParams
& params
,
75 blink::WebPlugin
** plugin
) OVERRIDE
;
76 virtual blink::WebPlugin
* CreatePluginReplacement(
77 content::RenderFrame
* render_frame
,
78 const base::FilePath
& plugin_path
) OVERRIDE
;
79 virtual bool HasErrorPage(int http_status_code
,
80 std::string
* error_domain
) OVERRIDE
;
81 virtual bool ShouldSuppressErrorPage(content::RenderFrame
* render_frame
,
82 const GURL
& url
) OVERRIDE
;
83 virtual void GetNavigationErrorStrings(
84 content::RenderView
* render_view
,
85 blink::WebFrame
* frame
,
86 const blink::WebURLRequest
& failed_request
,
87 const blink::WebURLError
& error
,
88 std::string
* error_html
,
89 base::string16
* error_description
) OVERRIDE
;
90 virtual void DeferMediaLoad(content::RenderFrame
* render_frame
,
91 const base::Closure
& closure
) OVERRIDE
;
92 virtual bool RunIdleHandlerWhenWidgetsHidden() OVERRIDE
;
93 virtual bool AllowPopup() OVERRIDE
;
94 virtual bool ShouldFork(blink::WebFrame
* frame
,
96 const std::string
& http_method
,
97 bool is_initial_navigation
,
98 bool is_server_redirect
,
99 bool* send_referrer
) OVERRIDE
;
100 virtual bool WillSendRequest(blink::WebFrame
* frame
,
101 content::PageTransition transition_type
,
103 const GURL
& first_party_for_cookies
,
104 GURL
* new_url
) OVERRIDE
;
105 virtual void DidCreateScriptContext(blink::WebFrame
* frame
,
106 v8::Handle
<v8::Context
> context
,
108 int world_id
) OVERRIDE
;
109 virtual void WillReleaseScriptContext(blink::WebFrame
* frame
,
110 v8::Handle
<v8::Context
> context
,
111 int world_id
) OVERRIDE
;
112 virtual unsigned long long VisitedLinkHash(const char* canonical_url
,
113 size_t length
) OVERRIDE
;
114 virtual bool IsLinkVisited(unsigned long long link_hash
) OVERRIDE
;
115 virtual blink::WebPrescientNetworking
* GetPrescientNetworking() OVERRIDE
;
116 virtual bool ShouldOverridePageVisibilityState(
117 const content::RenderFrame
* render_frame
,
118 blink::WebPageVisibilityState
* override_state
) OVERRIDE
;
119 virtual bool AllowBrowserPlugin(
120 blink::WebPluginContainer
* container
) OVERRIDE
;
121 virtual const void* CreatePPAPIInterface(
122 const std::string
& interface_name
) OVERRIDE
;
123 virtual bool IsExternalPepperPlugin(const std::string
& module_name
) OVERRIDE
;
124 virtual blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
125 blink::WebSpeechSynthesizerClient
* client
) OVERRIDE
;
126 virtual bool ShouldReportDetailedMessageForSource(
127 const base::string16
& source
) const OVERRIDE
;
128 virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE
;
129 virtual blink::WebWorkerPermissionClientProxy
*
130 CreateWorkerPermissionClientProxy(content::RenderFrame
* render_frame
,
131 blink::WebFrame
* frame
) OVERRIDE
;
132 virtual bool AllowPepperMediaStreamAPI(const GURL
& url
) OVERRIDE
;
133 virtual void AddKeySystems(
134 std::vector
<content::KeySystemInfo
>* key_systems
) OVERRIDE
;
137 void SetExtensionDispatcher(extensions::Dispatcher
* extension_dispatcher
);
139 #if defined(ENABLE_SPELLCHECK)
140 // Sets a new |spellcheck|. Used for low-mem restart and testing only.
141 // Takes ownership of |spellcheck|.
142 void SetSpellcheck(SpellCheck
* spellcheck
);
145 // Called in low-memory conditions to dump the memory used by the spellchecker
147 void OnPurgeMemory();
149 static blink::WebPlugin
* CreatePlugin(
150 content::RenderFrame
* render_frame
,
151 blink::WebFrame
* frame
,
152 const blink::WebPluginParams
& params
,
153 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
155 static bool IsExtensionOrSharedModuleWhitelisted(
156 const GURL
& url
, const std::set
<std::string
>& whitelist
);
158 // TODO(mpcomplete): remove after we collect histogram data.
159 // http://crbug.com/100411
160 static bool IsAdblockInstalled();
161 static bool IsAdblockPlusInstalled();
162 static bool IsAdblockWithWebRequestInstalled();
163 static bool IsAdblockPlusWithWebRequestInstalled();
164 static bool IsOtherExtensionWithWebRequestInstalled();
167 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
168 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
,
169 ShouldSuppressErrorPage
);
171 // Gets extension by the given origin, regardless of whether the extension
172 // is active in the current process.
173 const extensions::Extension
* GetExtensionByOrigin(
174 const blink::WebSecurityOrigin
& origin
) const;
176 // Returns true if the frame is navigating to an URL either into or out of an
177 // extension app's extent.
178 bool CrossesExtensionExtents(blink::WebFrame
* frame
,
180 const extensions::ExtensionSet
& extensions
,
181 bool is_extension_url
,
182 bool is_initial_navigation
);
184 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
185 const content::WebPluginInfo
& plugin
);
187 // Determines if a NaCl app is allowed, and modifies params to pass the app's
188 // permissions to the trusted NaCl plugin.
189 static bool IsNaClAllowed(const GURL
& manifest_url
,
191 bool is_nacl_unrestricted
,
192 const extensions::Extension
* extension
,
193 blink::WebPluginParams
* params
);
195 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
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 #if defined(ENABLE_SPELLCHECK)
202 scoped_ptr
<SpellCheck
> spellcheck_
;
204 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
205 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
206 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
207 #if defined(ENABLE_WEBRTC)
208 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
210 scoped_ptr
<SearchBouncer
> search_bouncer_
;
213 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_