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_PRINT_PREVIEW)
21 class ChromePDFPrintClient
;
23 class PrescientNetworkingDispatcher
;
25 #if defined(ENABLE_SPELLCHECK)
27 class SpellCheckProvider
;
30 struct ChromeViewHostMsg_GetPluginInfo_Output
;
33 class BrowserPluginDelegate
;
37 namespace network_hints
{
38 class PrescientNetworkingDispatcher
;
41 namespace extensions
{
45 class RendererPermissionsPolicyDelegate
;
49 class PrerenderDispatcher
;
52 namespace safe_browsing
{
53 class PhishingClassifierFilter
;
56 namespace visitedlink
{
57 class VisitedLinkSlave
;
61 class WebCacheRenderProcessObserver
;
65 class WebSecurityOrigin
;
68 namespace password_manager
{
69 class CredentialManagerClient
;
72 #if defined(ENABLE_WEBRTC)
73 class WebRtcLoggingMessageFilter
;
76 class ChromeContentRendererClient
: public content::ContentRendererClient
{
78 ChromeContentRendererClient();
79 ~ChromeContentRendererClient() override
;
81 void RenderThreadStarted() override
;
82 void RenderFrameCreated(content::RenderFrame
* render_frame
) override
;
83 void RenderViewCreated(content::RenderView
* render_view
) override
;
84 SkBitmap
* GetSadPluginBitmap() override
;
85 SkBitmap
* GetSadWebViewBitmap() override
;
86 bool OverrideCreatePlugin(content::RenderFrame
* render_frame
,
87 blink::WebLocalFrame
* frame
,
88 const blink::WebPluginParams
& params
,
89 blink::WebPlugin
** plugin
) override
;
90 scoped_ptr
<blink::WebPluginPlaceholder
> CreatePluginPlaceholder(
91 content::RenderFrame
* render_frame
,
92 blink::WebLocalFrame
* frame
,
93 const blink::WebPluginParams
& params
) override
;
94 blink::WebPlugin
* CreatePluginReplacement(
95 content::RenderFrame
* render_frame
,
96 const base::FilePath
& plugin_path
) override
;
97 bool HasErrorPage(int http_status_code
, std::string
* error_domain
) override
;
98 bool ShouldSuppressErrorPage(content::RenderFrame
* render_frame
,
99 const GURL
& url
) override
;
100 void GetNavigationErrorStrings(content::RenderView
* render_view
,
101 blink::WebFrame
* frame
,
102 const blink::WebURLRequest
& failed_request
,
103 const blink::WebURLError
& error
,
104 std::string
* error_html
,
105 base::string16
* error_description
) override
;
106 void DeferMediaLoad(content::RenderFrame
* render_frame
,
107 const base::Closure
& closure
) override
;
108 bool RunIdleHandlerWhenWidgetsHidden() override
;
109 bool AllowPopup() override
;
110 bool ShouldFork(blink::WebFrame
* frame
,
112 const std::string
& http_method
,
113 bool is_initial_navigation
,
114 bool is_server_redirect
,
115 bool* send_referrer
) override
;
116 #if defined(ENABLE_EXTENSIONS)
117 bool ShouldForwardToGuestContainer(const IPC::Message
& msg
) override
;
119 bool WillSendRequest(blink::WebFrame
* frame
,
120 ui::PageTransition transition_type
,
122 const GURL
& first_party_for_cookies
,
123 GURL
* new_url
) override
;
124 void DidCreateScriptContext(blink::WebLocalFrame
* frame
,
125 v8::Handle
<v8::Context
> context
,
127 int world_id
) override
;
128 unsigned long long VisitedLinkHash(const char* canonical_url
,
129 size_t length
) override
;
130 bool IsLinkVisited(unsigned long long link_hash
) override
;
131 blink::WebPrescientNetworking
* GetPrescientNetworking() override
;
132 bool ShouldOverridePageVisibilityState(
133 const content::RenderFrame
* render_frame
,
134 blink::WebPageVisibilityState
* override_state
) override
;
135 const void* CreatePPAPIInterface(const std::string
& interface_name
) override
;
136 bool IsExternalPepperPlugin(const std::string
& module_name
) override
;
137 blink::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
138 blink::WebSpeechSynthesizerClient
* client
) override
;
139 bool ShouldReportDetailedMessageForSource(
140 const base::string16
& source
) const override
;
141 bool ShouldEnableSiteIsolationPolicy() const override
;
142 blink::WebWorkerContentSettingsClientProxy
*
143 CreateWorkerContentSettingsClientProxy(content::RenderFrame
* render_frame
,
144 blink::WebFrame
* frame
) override
;
145 bool AllowPepperMediaStreamAPI(const GURL
& url
) override
;
146 void AddKeySystems(std::vector
<media::KeySystemInfo
>* key_systems
) override
;
147 bool IsPluginAllowedToUseDevChannelAPIs() override
;
148 bool IsPluginAllowedToUseCameraDeviceAPI(const GURL
& url
) override
;
149 bool IsPluginAllowedToUseCompositorAPI(const GURL
& url
) override
;
150 content::BrowserPluginDelegate
* CreateBrowserPluginDelegate(
151 content::RenderFrame
* render_frame
,
152 const std::string
& mime_type
,
153 const GURL
& original_url
) override
;
155 #if defined(ENABLE_EXTENSIONS)
157 void SetExtensionDispatcherForTest(
158 extensions::Dispatcher
* extension_dispatcher
);
159 extensions::Dispatcher
* GetExtensionDispatcherForTest();
162 #if defined(ENABLE_SPELLCHECK)
163 // Sets a new |spellcheck|. Used for testing only.
164 // Takes ownership of |spellcheck|.
165 void SetSpellcheck(SpellCheck
* spellcheck
);
168 static blink::WebPlugin
* CreatePlugin(
169 content::RenderFrame
* render_frame
,
170 blink::WebLocalFrame
* frame
,
171 const blink::WebPluginParams
& params
,
172 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
174 #if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
175 static bool IsExtensionOrSharedModuleWhitelisted(
176 const GURL
& url
, const std::set
<std::string
>& whitelist
);
179 static bool WasWebRequestUsedBySomeExtensions();
182 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
183 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
,
184 ShouldSuppressErrorPage
);
186 #if defined(ENABLE_EXTENSIONS)
187 // Gets extension by the given origin, regardless of whether the extension
188 // is active in the current process.
189 const extensions::Extension
* GetExtensionByOrigin(
190 const blink::WebSecurityOrigin
& origin
) const;
192 // Returns true if the frame is navigating to an URL either into or out of an
193 // extension app's extent.
194 bool CrossesExtensionExtents(blink::WebFrame
* frame
,
196 const extensions::ExtensionSet
& extensions
,
197 bool is_extension_url
,
198 bool is_initial_navigation
);
201 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
202 const content::WebPluginInfo
& plugin
);
204 #if !defined(DISABLE_NACL)
205 // Determines if a NaCl app is allowed, and modifies params to pass the app's
206 // permissions to the trusted NaCl plugin.
207 static bool IsNaClAllowed(const GURL
& manifest_url
,
209 bool is_nacl_unrestricted
,
210 const extensions::Extension
* extension
,
211 blink::WebPluginParams
* params
);
214 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
215 scoped_ptr
<web_cache::WebCacheRenderProcessObserver
> web_cache_observer_
;
217 // TODO(thestig): Extract into a separate file if possible. Cleanup
218 // ENABLE_EXTENSIONS ifdefs in the .cc file as well.
219 #if defined(ENABLE_EXTENSIONS)
220 scoped_ptr
<ChromeExtensionsDispatcherDelegate
> extension_dispatcher_delegate_
;
221 scoped_ptr
<extensions::Dispatcher
> extension_dispatcher_
;
222 scoped_ptr
<extensions::RendererPermissionsPolicyDelegate
>
223 permissions_policy_delegate_
;
226 scoped_ptr
<network_hints::PrescientNetworkingDispatcher
>
227 prescient_networking_dispatcher_
;
228 scoped_ptr
<password_manager::CredentialManagerClient
>
229 credential_manager_client_
;
230 #if defined(ENABLE_SPELLCHECK)
231 scoped_ptr
<SpellCheck
> spellcheck_
;
233 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
234 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
235 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
236 #if defined(ENABLE_WEBRTC)
237 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
239 scoped_ptr
<SearchBouncer
> search_bouncer_
;
240 #if defined(ENABLE_PRINT_PREVIEW)
241 scoped_ptr
<ChromePDFPrintClient
> pdf_print_client_
;
243 #if defined(ENABLE_PLUGINS)
244 std::set
<std::string
> allowed_camera_device_origins_
;
245 std::set
<std::string
> allowed_compositor_origins_
;
249 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_