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