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 <set>
9#include <string>
10#include <vector>
11
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"
17
18class ChromeExtensionsDispatcherDelegate;
19class ChromeRenderProcessObserver;
20#if defined(ENABLE_FULL_PRINTING)
21class ChromePDFPrintClient;
22#endif
23class PrescientNetworkingDispatcher;
24class RendererNetPredictor;
25class SearchBouncer;
26#if defined(ENABLE_SPELLCHECK)
27class SpellCheck;
28class SpellCheckProvider;
29#endif
30
31struct ChromeViewHostMsg_GetPluginInfo_Output;
32
33namespace content {
34class BrowserPluginDelegate;
35struct WebPluginInfo;
36}
37
38namespace extensions {
39class Dispatcher;
40class Extension;
41class ExtensionSet;
42class RendererPermissionsPolicyDelegate;
43}
44
45namespace prerender {
46class PrerenderDispatcher;
47}
48
49namespace safe_browsing {
50class PhishingClassifierFilter;
51}
52
53namespace visitedlink {
54class VisitedLinkSlave;
55}
56
57namespace web_cache {
58class WebCacheRenderProcessObserver;
59}
60
61namespace blink {
62class WebSecurityOrigin;
63}
64
65namespace password_manager {
66class CredentialManagerClient;
67}
68
69#if defined(ENABLE_WEBRTC)
70class WebRtcLoggingMessageFilter;
71#endif
72
73class ChromeContentRendererClient : public content::ContentRendererClient {
74 public:
75  ChromeContentRendererClient();
76  virtual ~ChromeContentRendererClient();
77
78  virtual void RenderThreadStarted() OVERRIDE;
79  virtual void RenderFrameCreated(content::RenderFrame* render_frame) OVERRIDE;
80  virtual void RenderViewCreated(content::RenderView* render_view) OVERRIDE;
81  virtual void SetNumberOfViews(int number_of_views) OVERRIDE;
82  virtual SkBitmap* GetSadPluginBitmap() OVERRIDE;
83  virtual SkBitmap* GetSadWebViewBitmap() OVERRIDE;
84  virtual bool OverrideCreatePlugin(
85      content::RenderFrame* render_frame,
86      blink::WebLocalFrame* frame,
87      const blink::WebPluginParams& params,
88      blink::WebPlugin** plugin) OVERRIDE;
89  virtual blink::WebPlugin* CreatePluginReplacement(
90      content::RenderFrame* render_frame,
91      const base::FilePath& plugin_path) OVERRIDE;
92  virtual bool HasErrorPage(int http_status_code,
93                            std::string* error_domain) OVERRIDE;
94  virtual bool ShouldSuppressErrorPage(content::RenderFrame* render_frame,
95                                       const GURL& url) OVERRIDE;
96  virtual void GetNavigationErrorStrings(
97      content::RenderView* render_view,
98      blink::WebFrame* frame,
99      const blink::WebURLRequest& failed_request,
100      const blink::WebURLError& error,
101      std::string* error_html,
102      base::string16* error_description) OVERRIDE;
103  virtual void DeferMediaLoad(content::RenderFrame* render_frame,
104                              const base::Closure& closure) OVERRIDE;
105  virtual bool RunIdleHandlerWhenWidgetsHidden() OVERRIDE;
106  virtual bool AllowPopup() OVERRIDE;
107  virtual bool ShouldFork(blink::WebFrame* frame,
108                          const GURL& url,
109                          const std::string& http_method,
110                          bool is_initial_navigation,
111                          bool is_server_redirect,
112                          bool* send_referrer) OVERRIDE;
113  virtual bool WillSendRequest(blink::WebFrame* frame,
114                               ui::PageTransition transition_type,
115                               const GURL& url,
116                               const GURL& first_party_for_cookies,
117                               GURL* new_url) OVERRIDE;
118  virtual void DidCreateScriptContext(blink::WebFrame* frame,
119                                      v8::Handle<v8::Context> context,
120                                      int extension_group,
121                                      int world_id) OVERRIDE;
122  virtual unsigned long long VisitedLinkHash(const char* canonical_url,
123                                             size_t length) OVERRIDE;
124  virtual bool IsLinkVisited(unsigned long long link_hash) OVERRIDE;
125  virtual blink::WebPrescientNetworking* GetPrescientNetworking() OVERRIDE;
126  virtual bool ShouldOverridePageVisibilityState(
127      const content::RenderFrame* render_frame,
128      blink::WebPageVisibilityState* override_state) OVERRIDE;
129  virtual const void* CreatePPAPIInterface(
130      const std::string& interface_name) OVERRIDE;
131  virtual bool IsExternalPepperPlugin(const std::string& module_name) OVERRIDE;
132  virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer(
133      blink::WebSpeechSynthesizerClient* client) OVERRIDE;
134  virtual bool ShouldReportDetailedMessageForSource(
135      const base::string16& source) const OVERRIDE;
136  virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE;
137  virtual blink::WebWorkerPermissionClientProxy*
138      CreateWorkerPermissionClientProxy(content::RenderFrame* render_frame,
139                                        blink::WebFrame* frame) OVERRIDE;
140  virtual bool AllowPepperMediaStreamAPI(const GURL& url) OVERRIDE;
141  virtual void AddKeySystems(
142      std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
143  virtual bool IsPluginAllowedToUseDevChannelAPIs() OVERRIDE;
144  virtual bool IsPluginAllowedToUseCompositorAPI(const GURL& url) OVERRIDE;
145  virtual bool IsPluginAllowedToUseVideoDecodeAPI(const GURL& url) OVERRIDE;
146  virtual content::BrowserPluginDelegate* CreateBrowserPluginDelegate(
147      content::RenderFrame* render_frame,
148      const std::string& mime_type) OVERRIDE;
149
150#if defined(ENABLE_EXTENSIONS)
151  // Takes ownership.
152  void SetExtensionDispatcherForTest(
153      extensions::Dispatcher* extension_dispatcher);
154  extensions::Dispatcher* GetExtensionDispatcherForTest();
155#endif
156
157#if defined(ENABLE_SPELLCHECK)
158  // Sets a new |spellcheck|. Used for testing only.
159  // Takes ownership of |spellcheck|.
160  void SetSpellcheck(SpellCheck* spellcheck);
161#endif
162
163  static blink::WebPlugin* CreatePlugin(
164      content::RenderFrame* render_frame,
165      blink::WebLocalFrame* frame,
166      const blink::WebPluginParams& params,
167      const ChromeViewHostMsg_GetPluginInfo_Output& output);
168
169#if defined(ENABLE_PLUGINS) && defined(ENABLE_EXTENSIONS)
170  static bool IsExtensionOrSharedModuleWhitelisted(
171      const GURL& url, const std::set<std::string>& whitelist);
172#endif
173
174  static bool WasWebRequestUsedBySomeExtensions();
175
176 private:
177  FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, NaClRestriction);
178  FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest,
179                           ShouldSuppressErrorPage);
180
181#if defined(ENABLE_EXTENSIONS)
182  // Gets extension by the given origin, regardless of whether the extension
183  // is active in the current process.
184  const extensions::Extension* GetExtensionByOrigin(
185      const blink::WebSecurityOrigin& origin) const;
186
187  // Returns true if the frame is navigating to an URL either into or out of an
188  // extension app's extent.
189  bool CrossesExtensionExtents(blink::WebFrame* frame,
190                               const GURL& new_url,
191                               const extensions::ExtensionSet& extensions,
192                               bool is_extension_url,
193                               bool is_initial_navigation);
194#endif
195
196  static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type,
197                                       const content::WebPluginInfo& plugin);
198
199  // Determines if a NaCl app is allowed, and modifies params to pass the app's
200  // permissions to the trusted NaCl plugin.
201  static bool IsNaClAllowed(const GURL& manifest_url,
202                            const GURL& app_url,
203                            bool is_nacl_unrestricted,
204                            const extensions::Extension* extension,
205                            blink::WebPluginParams* params);
206
207  scoped_ptr<ChromeRenderProcessObserver> chrome_observer_;
208  scoped_ptr<web_cache::WebCacheRenderProcessObserver> web_cache_observer_;
209
210// TODO(thestig): Extract into a separate file if possible. Cleanup
211// ENABLE_EXTENSIONS ifdefs in the .cc file as well.
212#if defined(ENABLE_EXTENSIONS)
213  scoped_ptr<ChromeExtensionsDispatcherDelegate> extension_dispatcher_delegate_;
214  scoped_ptr<extensions::Dispatcher> extension_dispatcher_;
215  scoped_ptr<extensions::RendererPermissionsPolicyDelegate>
216      permissions_policy_delegate_;
217#endif
218
219  scoped_ptr<PrescientNetworkingDispatcher> prescient_networking_dispatcher_;
220  scoped_ptr<RendererNetPredictor> net_predictor_;
221  scoped_ptr<password_manager::CredentialManagerClient>
222      credential_manager_client_;
223#if defined(ENABLE_SPELLCHECK)
224  scoped_ptr<SpellCheck> spellcheck_;
225#endif
226  scoped_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
227  scoped_ptr<safe_browsing::PhishingClassifierFilter> phishing_classifier_;
228  scoped_ptr<prerender::PrerenderDispatcher> prerender_dispatcher_;
229#if defined(ENABLE_WEBRTC)
230  scoped_refptr<WebRtcLoggingMessageFilter> webrtc_logging_message_filter_;
231#endif
232  scoped_ptr<SearchBouncer> search_bouncer_;
233#if defined(ENABLE_FULL_PRINTING)
234  scoped_ptr<ChromePDFPrintClient> pdf_print_client_;
235#endif
236#if defined(ENABLE_PLUGINS)
237  std::set<std::string> allowed_compositor_origins_;
238  std::set<std::string> allowed_video_decode_origins_;
239#endif
240};
241
242#endif  // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
243