• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 class ChromeExtensionsDispatcherDelegate;
19 class ChromeRenderProcessObserver;
20 class PrescientNetworkingDispatcher;
21 class RendererNetPredictor;
22 class SearchBouncer;
23 #if defined(ENABLE_SPELLCHECK)
24 class SpellCheck;
25 class SpellCheckProvider;
26 #endif
27 
28 struct ChromeViewHostMsg_GetPluginInfo_Output;
29 
30 namespace content {
31 struct WebPluginInfo;
32 }
33 
34 namespace extensions {
35 class Dispatcher;
36 class Extension;
37 class ExtensionSet;
38 class RendererPermissionsPolicyDelegate;
39 }
40 
41 namespace prerender {
42 class PrerenderDispatcher;
43 }
44 
45 namespace safe_browsing {
46 class PhishingClassifierFilter;
47 }
48 
49 namespace visitedlink {
50 class VisitedLinkSlave;
51 }
52 
53 namespace blink {
54 class WebSecurityOrigin;
55 }
56 
57 #if defined(ENABLE_WEBRTC)
58 class WebRtcLoggingMessageFilter;
59 #endif
60 
61 class ChromeContentRendererClient : public content::ContentRendererClient {
62  public:
63   ChromeContentRendererClient();
64   virtual ~ChromeContentRendererClient();
65 
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,
97                           const GURL& url,
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,
104                                const GURL& url,
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,
109                                       int extension_group,
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 
133   // Takes ownership.
134   void SetExtensionDispatcherForTest(
135       extensions::Dispatcher* extension_dispatcher);
136   extensions::Dispatcher* GetExtensionDispatcherForTest();
137 
138 #if defined(ENABLE_SPELLCHECK)
139   // Sets a new |spellcheck|. Used for testing only.
140   // Takes ownership of |spellcheck|.
141   void SetSpellcheck(SpellCheck* spellcheck);
142 #endif
143 
144   static blink::WebPlugin* CreatePlugin(
145       content::RenderFrame* render_frame,
146       blink::WebLocalFrame* frame,
147       const blink::WebPluginParams& params,
148       const ChromeViewHostMsg_GetPluginInfo_Output& output);
149 
150   static bool IsExtensionOrSharedModuleWhitelisted(
151       const GURL& url, const std::set<std::string>& whitelist);
152 
153   static bool WasWebRequestUsedBySomeExtensions();
154 
155  private:
156   FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, NaClRestriction);
157   FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest,
158                            ShouldSuppressErrorPage);
159 
160   // Gets extension by the given origin, regardless of whether the extension
161   // is active in the current process.
162   const extensions::Extension* GetExtensionByOrigin(
163       const blink::WebSecurityOrigin& origin) const;
164 
165   // Returns true if the frame is navigating to an URL either into or out of an
166   // extension app's extent.
167   bool CrossesExtensionExtents(blink::WebFrame* frame,
168                                const GURL& new_url,
169                                const extensions::ExtensionSet& extensions,
170                                bool is_extension_url,
171                                bool is_initial_navigation);
172 
173   static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type,
174                                        const content::WebPluginInfo& plugin);
175 
176   // Determines if a NaCl app is allowed, and modifies params to pass the app's
177   // permissions to the trusted NaCl plugin.
178   static bool IsNaClAllowed(const GURL& manifest_url,
179                             const GURL& app_url,
180                             bool is_nacl_unrestricted,
181                             const extensions::Extension* extension,
182                             blink::WebPluginParams* params);
183 
184   scoped_ptr<ChromeRenderProcessObserver> chrome_observer_;
185   scoped_ptr<ChromeExtensionsDispatcherDelegate> extension_dispatcher_delegate_;
186   scoped_ptr<extensions::Dispatcher> extension_dispatcher_;
187   scoped_ptr<extensions::RendererPermissionsPolicyDelegate>
188       permissions_policy_delegate_;
189   scoped_ptr<PrescientNetworkingDispatcher> prescient_networking_dispatcher_;
190   scoped_ptr<RendererNetPredictor> net_predictor_;
191 #if defined(ENABLE_SPELLCHECK)
192   scoped_ptr<SpellCheck> spellcheck_;
193 #endif
194   scoped_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_;
195   scoped_ptr<safe_browsing::PhishingClassifierFilter> phishing_classifier_;
196   scoped_ptr<prerender::PrerenderDispatcher> prerender_dispatcher_;
197 #if defined(ENABLE_WEBRTC)
198   scoped_refptr<WebRtcLoggingMessageFilter> webrtc_logging_message_filter_;
199 #endif
200   scoped_ptr<SearchBouncer> search_bouncer_;
201 };
202 
203 #endif  // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_
204