chrome_content_renderer_client.h revision d0247b1b59f9c528cb6df88b4f2b9afaf80d181e
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.
4
5#ifndef CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
6#define CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
7
8#include <string>
9#include <vector>
10
11#if defined(ENABLE_PLUGINS)
12#include <set>
13#endif
14
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"
19
20class ChromeRenderProcessObserver;
21class ExtensionSet;
22class PrescientNetworkingDispatcher;
23class RendererNetPredictor;
24#if defined(ENABLE_SPELLCHECK)
25class SpellCheck;
26class SpellCheckProvider;
27#endif
28
29struct ChromeViewHostMsg_GetPluginInfo_Output;
30
31namespace content {
32struct WebPluginInfo;
33}
34
35namespace extensions {
36class Dispatcher;
37class Extension;
38class RendererPermissionsPolicyDelegate;
39}
40
41namespace prerender {
42class PrerenderDispatcher;
43}
44
45namespace safe_browsing {
46class PhishingClassifierFilter;
47}
48
49namespace visitedlink {
50class VisitedLinkSlave;
51}
52
53namespace WebKit {
54class WebSecurityOrigin;
55}
56
57#if defined(ENABLE_WEBRTC)
58class WebRtcLoggingMessageFilter;
59#endif
60
61namespace chrome {
62
63class ChromeContentRendererClient : public content::ContentRendererClient {
64 public:
65  ChromeContentRendererClient();
66  virtual ~ChromeContentRendererClient();
67
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,
95                          const GURL& url,
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,
102                               const GURL& url,
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,
108                                      int extension_group,
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,
121                                      const GURL& url,
122                                      const GURL& first_party_for_cookies,
123                                      std::string* cookies) OVERRIDE;
124  virtual bool HandleSetCookieRequest(content::RenderView* sender,
125                                      const GURL& url,
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 ShouldReportDetailedMessageForSource(
140      const base::string16& source) const OVERRIDE;
141  virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE;
142  virtual bool AllowPepperMediaStreamAPI(const GURL& url) OVERRIDE;
143  virtual void AddKeySystems(
144      std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
145
146  // For testing.
147  void SetExtensionDispatcher(extensions::Dispatcher* extension_dispatcher);
148
149#if defined(ENABLE_SPELLCHECK)
150  // Sets a new |spellcheck|. Used for low-mem restart and testing only.
151  // Takes ownership of |spellcheck|.
152  void SetSpellcheck(SpellCheck* spellcheck);
153#endif
154
155  // Called in low-memory conditions to dump the memory used by the spellchecker
156  // and start over.
157  void OnPurgeMemory();
158
159  static WebKit::WebPlugin* CreatePlugin(
160      content::RenderView* render_view,
161      WebKit::WebFrame* frame,
162      const WebKit::WebPluginParams& params,
163      const ChromeViewHostMsg_GetPluginInfo_Output& output);
164
165  // TODO(mpcomplete): remove after we collect histogram data.
166  // http://crbug.com/100411
167  static bool IsAdblockInstalled();
168  static bool IsAdblockPlusInstalled();
169  static bool IsAdblockWithWebRequestInstalled();
170  static bool IsAdblockPlusWithWebRequestInstalled();
171  static bool IsOtherExtensionWithWebRequestInstalled();
172
173 private:
174  FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, NaClRestriction);
175
176  const extensions::Extension* GetExtension(
177      const WebKit::WebSecurityOrigin& origin) const;
178
179  // Returns true if the frame is navigating to an URL either into or out of an
180  // extension app's extent.
181  bool CrossesExtensionExtents(WebKit::WebFrame* frame,
182                               const GURL& new_url,
183                               const ExtensionSet& extensions,
184                               bool is_extension_url,
185                               bool is_initial_navigation);
186
187  static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type,
188                                       const content::WebPluginInfo& plugin);
189  static bool IsNaClAllowed(const GURL& manifest_url,
190                            const GURL& app_url,
191                            bool is_nacl_unrestricted,
192                            const extensions::Extension* extension,
193                            WebKit::WebPluginParams* params);
194
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_;
203#endif
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_;
209#endif
210
211#if defined(ENABLE_PLUGINS)
212  std::set<std::string> allowed_file_handle_origins_;
213#endif
214};
215
216}  // namespace chrome
217
218#endif  // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
219