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_
11 #if defined(ENABLE_PLUGINS)
15 #include "base/compiler_specific.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/strings/string16.h"
18 #include "content/public/renderer/content_renderer_client.h"
20 class ChromeRenderProcessObserver
;
22 class PrescientNetworkingDispatcher
;
23 class RendererNetPredictor
;
24 #if defined(ENABLE_SPELLCHECK)
26 class SpellCheckProvider
;
29 struct ChromeViewHostMsg_GetPluginInfo_Output
;
35 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
;
63 class ChromeContentRendererClient
: public content::ContentRendererClient
{
65 ChromeContentRendererClient();
66 virtual ~ChromeContentRendererClient();
68 virtual void RenderThreadStarted() OVERRIDE
;
69 virtual void RenderViewCreated(content::RenderView
* render_view
) OVERRIDE
;
70 virtual void SetNumberOfViews(int number_of_views
) OVERRIDE
;
71 virtual SkBitmap
* GetSadPluginBitmap() OVERRIDE
;
72 virtual SkBitmap
* GetSadWebViewBitmap() OVERRIDE
;
73 virtual std::string
GetDefaultEncoding() OVERRIDE
;
74 virtual bool OverrideCreatePlugin(
75 content::RenderView
* render_view
,
76 WebKit::WebFrame
* frame
,
77 const WebKit::WebPluginParams
& params
,
78 WebKit::WebPlugin
** plugin
) OVERRIDE
;
79 virtual WebKit::WebPlugin
* CreatePluginReplacement(
80 content::RenderView
* render_view
,
81 const base::FilePath
& plugin_path
) OVERRIDE
;
82 virtual bool HasErrorPage(int http_status_code
,
83 std::string
* error_domain
) OVERRIDE
;
84 virtual void GetNavigationErrorStrings(
85 WebKit::WebFrame
* frame
,
86 const WebKit::WebURLRequest
& failed_request
,
87 const WebKit::WebURLError
& error
,
88 std::string
* error_html
,
89 string16
* error_description
) OVERRIDE
;
90 virtual void DeferMediaLoad(content::RenderView
* render_view
,
91 const base::Closure
& closure
) OVERRIDE
;
92 virtual bool RunIdleHandlerWhenWidgetsHidden() OVERRIDE
;
93 virtual bool AllowPopup() OVERRIDE
;
94 virtual bool ShouldFork(WebKit::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(WebKit::WebFrame
* frame
,
101 content::PageTransition transition_type
,
103 const GURL
& first_party_for_cookies
,
104 GURL
* new_url
) OVERRIDE
;
105 virtual bool ShouldPumpEventsDuringCookieMessage() OVERRIDE
;
106 virtual void DidCreateScriptContext(WebKit::WebFrame
* frame
,
107 v8::Handle
<v8::Context
> context
,
109 int world_id
) OVERRIDE
;
110 virtual void WillReleaseScriptContext(WebKit::WebFrame
* frame
,
111 v8::Handle
<v8::Context
> context
,
112 int world_id
) OVERRIDE
;
113 virtual unsigned long long VisitedLinkHash(const char* canonical_url
,
114 size_t length
) OVERRIDE
;
115 virtual bool IsLinkVisited(unsigned long long link_hash
) OVERRIDE
;
116 virtual WebKit::WebPrescientNetworking
* GetPrescientNetworking() OVERRIDE
;
117 virtual bool ShouldOverridePageVisibilityState(
118 const content::RenderView
* render_view
,
119 WebKit::WebPageVisibilityState
* override_state
) OVERRIDE
;
120 virtual bool HandleGetCookieRequest(content::RenderView
* sender
,
122 const GURL
& first_party_for_cookies
,
123 std::string
* cookies
) OVERRIDE
;
124 virtual bool HandleSetCookieRequest(content::RenderView
* sender
,
126 const GURL
& first_party_for_cookies
,
127 const std::string
& value
) OVERRIDE
;
128 virtual bool AllowBrowserPlugin(
129 WebKit::WebPluginContainer
* container
) OVERRIDE
;
130 virtual const void* CreatePPAPIInterface(
131 const std::string
& interface_name
) OVERRIDE
;
132 virtual bool IsExternalPepperPlugin(const std::string
& module_name
) OVERRIDE
;
133 // TODO(victorhsieh): move to ChromeContentBrowserClient once we migrate
134 // PPAPI FileIO host to browser.
135 virtual bool IsPluginAllowedToCallRequestOSFileHandle(
136 WebKit::WebPluginContainer
* container
) OVERRIDE
;
137 virtual WebKit::WebSpeechSynthesizer
* OverrideSpeechSynthesizer(
138 WebKit::WebSpeechSynthesizerClient
* client
) OVERRIDE
;
139 virtual bool AllowPepperMediaStreamAPI(const GURL
& url
) OVERRIDE
;
142 void SetExtensionDispatcher(extensions::Dispatcher
* extension_dispatcher
);
144 #if defined(ENABLE_SPELLCHECK)
145 // Sets a new |spellcheck|. Used for low-mem restart and testing only.
146 // Takes ownership of |spellcheck|.
147 void SetSpellcheck(SpellCheck
* spellcheck
);
150 // Called in low-memory conditions to dump the memory used by the spellchecker
152 void OnPurgeMemory();
154 static WebKit::WebPlugin
* CreatePlugin(
155 content::RenderView
* render_view
,
156 WebKit::WebFrame
* frame
,
157 const WebKit::WebPluginParams
& params
,
158 const ChromeViewHostMsg_GetPluginInfo_Output
& output
);
160 // TODO(mpcomplete): remove after we collect histogram data.
161 // http://crbug.com/100411
162 static bool IsAdblockInstalled();
163 static bool IsAdblockPlusInstalled();
164 static bool IsAdblockWithWebRequestInstalled();
165 static bool IsAdblockPlusWithWebRequestInstalled();
166 static bool IsOtherExtensionWithWebRequestInstalled();
169 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest
, NaClRestriction
);
171 const extensions::Extension
* GetExtension(
172 const WebKit::WebSecurityOrigin
& origin
) const;
174 // Returns true if the frame is navigating to an URL either into or out of an
175 // extension app's extent.
176 bool CrossesExtensionExtents(WebKit::WebFrame
* frame
,
178 const ExtensionSet
& extensions
,
179 bool is_extension_url
,
180 bool is_initial_navigation
);
182 static GURL
GetNaClContentHandlerURL(const std::string
& actual_mime_type
,
183 const content::WebPluginInfo
& plugin
);
184 static bool IsNaClAllowed(const GURL
& manifest_url
,
186 bool is_nacl_unrestricted
,
187 const extensions::Extension
* extension
,
188 WebKit::WebPluginParams
* params
);
190 scoped_ptr
<ChromeRenderProcessObserver
> chrome_observer_
;
191 scoped_ptr
<extensions::Dispatcher
> extension_dispatcher_
;
192 scoped_ptr
<extensions::RendererPermissionsPolicyDelegate
>
193 permissions_policy_delegate_
;
194 scoped_ptr
<PrescientNetworkingDispatcher
> prescient_networking_dispatcher_
;
195 scoped_ptr
<RendererNetPredictor
> net_predictor_
;
196 #if defined(ENABLE_SPELLCHECK)
197 scoped_ptr
<SpellCheck
> spellcheck_
;
199 scoped_ptr
<visitedlink::VisitedLinkSlave
> visited_link_slave_
;
200 scoped_ptr
<safe_browsing::PhishingClassifierFilter
> phishing_classifier_
;
201 scoped_ptr
<prerender::PrerenderDispatcher
> prerender_dispatcher_
;
202 #if defined(ENABLE_WEBRTC)
203 scoped_refptr
<WebRtcLoggingMessageFilter
> webrtc_logging_message_filter_
;
206 #if defined(ENABLE_PLUGINS)
207 std::set
<std::string
> allowed_file_handle_origins_
;
211 } // namespace chrome
213 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_