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 const void* CreatePPAPIInterface(
119 const std::string
& interface_name
) OVERRIDE
;
120 virtual bool IsExternalPepperPlugin(const std::string
& module_name
) OVERRIDE
;
121 virtual blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
122 blink::WebSpeechSynthesizerClient
* client
) OVERRIDE
;
123 virtual bool ShouldReportDetailedMessageForSource(
124 const base::string16
& source
) const OVERRIDE
;
125 virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE
;
126 virtual blink::WebWorkerPermissionClientProxy
*
127 CreateWorkerPermissionClientProxy(content::RenderFrame
* render_frame
,
128 blink::WebFrame
* frame
) OVERRIDE
;
129 virtual bool AllowPepperMediaStreamAPI(const GURL
& url
) OVERRIDE
;
130 virtual void AddKeySystems(
131 std::vector
<content::KeySystemInfo
>* key_systems
) OVERRIDE
;
132 virtual bool IsPluginAllowedToUseDevChannelAPIs() OVERRIDE
;
133 virtual bool IsPluginAllowedToUseCompositorAPI(const GURL
& url
) OVERRIDE
;
134 virtual bool IsPluginAllowedToUseVideoDecodeAPI(const GURL
& url
) OVERRIDE
;
137 void SetExtensionDispatcherForTest(
138 extensions::Dispatcher
* extension_dispatcher
);
139 extensions::Dispatcher
* GetExtensionDispatcherForTest();
141 #if defined(ENABLE_SPELLCHECK)
142 // Sets a new |spellcheck|. Used for testing only.
143 // Takes ownership of |spellcheck|.
144 void SetSpellcheck(SpellCheck
* spellcheck
);
147 static blink::WebPlugin
* CreatePlugin(
148 content::RenderFrame
* render_frame
,
149 blink::WebLocalFrame
* frame
,
150 const blink::WebPluginParams
& params
,
151 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
153 static bool IsExtensionOrSharedModuleWhitelisted(
154 const GURL
& url
, const std::set
<std::string
>& whitelist
);
156 static bool WasWebRequestUsedBySomeExtensions();
159 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
160 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
,
161 ShouldSuppressErrorPage
);
163 // Gets extension by the given origin, regardless of whether the extension
164 // is active in the current process.
165 const extensions::Extension
* GetExtensionByOrigin(
166 const blink::WebSecurityOrigin
& origin
) const;
168 // Returns true if the frame is navigating to an URL either into or out of an
169 // extension app's extent.
170 bool CrossesExtensionExtents(blink::WebFrame
* frame
,
172 const extensions::ExtensionSet
& extensions
,
173 bool is_extension_url
,
174 bool is_initial_navigation
);
176 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
177 const content::WebPluginInfo
& plugin
);
179 // Determines if a NaCl app is allowed, and modifies params to pass the app's
180 // permissions to the trusted NaCl plugin.
181 static bool IsNaClAllowed(const GURL
& manifest_url
,
183 bool is_nacl_unrestricted
,
184 const extensions::Extension
* extension
,
185 blink::WebPluginParams
* params
);
187 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
188 scoped_ptr
<ChromeExtensionsDispatcherDelegate
> extension_dispatcher_delegate_
;
189 scoped_ptr
<extensions::Dispatcher
> extension_dispatcher_
;
190 scoped_ptr
<extensions::RendererPermissionsPolicyDelegate
>
191 permissions_policy_delegate_
;
192 scoped_ptr
<PrescientNetworkingDispatcher
> prescient_networking_dispatcher_
;
193 scoped_ptr
<RendererNetPredictor
> net_predictor_
;
194 #if defined(ENABLE_SPELLCHECK)
195 scoped_ptr
<SpellCheck
> spellcheck_
;
197 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
198 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
199 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
200 #if defined(ENABLE_WEBRTC)
201 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
203 scoped_ptr
<SearchBouncer
> search_bouncer_
;
204 #if defined(ENABLE_PLUGINS)
205 std::set
<std::string
> allowed_compositor_origins_
;
206 std::set
<std::string
> allowed_video_decode_origins_
;
210 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_