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 20 class ChromeRenderProcessObserver; 21 class ExtensionSet; 22 class PrescientNetworkingDispatcher; 23 class RendererNetPredictor; 24 class SearchBouncer; 25 #if defined(ENABLE_SPELLCHECK) 26 class SpellCheck; 27 class SpellCheckProvider; 28 #endif 29 30 struct ChromeViewHostMsg_GetPluginInfo_Output; 31 32 namespace content { 33 struct WebPluginInfo; 34 } 35 36 namespace extensions { 37 class Dispatcher; 38 class Extension; 39 class RendererPermissionsPolicyDelegate; 40 } 41 42 namespace prerender { 43 class PrerenderDispatcher; 44 } 45 46 namespace safe_browsing { 47 class PhishingClassifierFilter; 48 } 49 50 namespace visitedlink { 51 class VisitedLinkSlave; 52 } 53 54 namespace blink { 55 class WebSecurityOrigin; 56 } 57 58 #if defined(ENABLE_WEBRTC) 59 class WebRtcLoggingMessageFilter; 60 #endif 61 62 class ChromeContentRendererClient : public content::ContentRendererClient { 63 public: 64 ChromeContentRendererClient(); 65 virtual ~ChromeContentRendererClient(); 66 67 virtual void RenderThreadStarted() OVERRIDE; 68 virtual void RenderFrameCreated(content::RenderFrame* render_frame) 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::RenderFrame* render_frame, 76 blink::WebFrame* frame, 77 const blink::WebPluginParams& params, 78 blink::WebPlugin** plugin) OVERRIDE; 79 virtual blink::WebPlugin* CreatePluginReplacement( 80 content::RenderFrame* render_frame, 81 const base::FilePath& plugin_path) OVERRIDE; 82 virtual bool HasErrorPage(int http_status_code, 83 std::string* error_domain) OVERRIDE; 84 virtual bool ShouldSuppressErrorPage(const GURL& url) OVERRIDE; 85 virtual void GetNavigationErrorStrings( 86 blink::WebFrame* frame, 87 const blink::WebURLRequest& failed_request, 88 const blink::WebURLError& error, 89 const std::string& accept_languages, 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 void WillReleaseScriptContext(blink::WebFrame* frame, 112 v8::Handle<v8::Context> context, 113 int world_id) OVERRIDE; 114 virtual unsigned long long VisitedLinkHash(const char* canonical_url, 115 size_t length) OVERRIDE; 116 virtual bool IsLinkVisited(unsigned long long link_hash) OVERRIDE; 117 virtual blink::WebPrescientNetworking* GetPrescientNetworking() OVERRIDE; 118 virtual bool ShouldOverridePageVisibilityState( 119 const content::RenderFrame* render_frame, 120 blink::WebPageVisibilityState* override_state) OVERRIDE; 121 virtual bool AllowBrowserPlugin( 122 blink::WebPluginContainer* container) OVERRIDE; 123 virtual const void* CreatePPAPIInterface( 124 const std::string& interface_name) OVERRIDE; 125 virtual bool IsExternalPepperPlugin(const std::string& module_name) OVERRIDE; 126 virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer( 127 blink::WebSpeechSynthesizerClient* client) OVERRIDE; 128 virtual bool ShouldReportDetailedMessageForSource( 129 const base::string16& source) const OVERRIDE; 130 virtual bool ShouldEnableSiteIsolationPolicy() const OVERRIDE; 131 virtual blink::WebWorkerPermissionClientProxy* 132 CreateWorkerPermissionClientProxy(content::RenderView* render_view, 133 blink::WebFrame* frame) OVERRIDE; 134 virtual bool AllowPepperMediaStreamAPI(const GURL& url) OVERRIDE; 135 virtual void AddKeySystems( 136 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE; 137 138 // For testing. 139 void SetExtensionDispatcher(extensions::Dispatcher* extension_dispatcher); 140 141 #if defined(ENABLE_SPELLCHECK) 142 // Sets a new |spellcheck|. Used for low-mem restart and testing only. 143 // Takes ownership of |spellcheck|. 144 void SetSpellcheck(SpellCheck* spellcheck); 145 #endif 146 147 // Called in low-memory conditions to dump the memory used by the spellchecker 148 // and start over. 149 void OnPurgeMemory(); 150 151 static blink::WebPlugin* CreatePlugin( 152 content::RenderFrame* render_frame, 153 blink::WebFrame* frame, 154 const blink::WebPluginParams& params, 155 const ChromeViewHostMsg_GetPluginInfo_Output& output); 156 157 // TODO(mpcomplete): remove after we collect histogram data. 158 // http://crbug.com/100411 159 static bool IsAdblockInstalled(); 160 static bool IsAdblockPlusInstalled(); 161 static bool IsAdblockWithWebRequestInstalled(); 162 static bool IsAdblockPlusWithWebRequestInstalled(); 163 static bool IsOtherExtensionWithWebRequestInstalled(); 164 165 private: 166 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, NaClRestriction); 167 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, 168 ShouldSuppressErrorPage); 169 170 // Gets extension by the given origin, regardless of whether the extension 171 // is active in the current process. 172 const extensions::Extension* GetExtensionByOrigin( 173 const blink::WebSecurityOrigin& origin) const; 174 175 // Returns true if the frame is navigating to an URL either into or out of an 176 // extension app's extent. 177 bool CrossesExtensionExtents(blink::WebFrame* frame, 178 const GURL& new_url, 179 const ExtensionSet& extensions, 180 bool is_extension_url, 181 bool is_initial_navigation); 182 183 static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type, 184 const content::WebPluginInfo& plugin); 185 186 // Determines if a NaCl app is allowed, and modifies params to pass the app's 187 // permissions to the trusted NaCl plugin. 188 static bool IsNaClAllowed(const GURL& manifest_url, 189 const GURL& app_url, 190 bool is_nacl_unrestricted, 191 const extensions::Extension* extension, 192 blink::WebPluginParams* params); 193 194 scoped_ptr<ChromeRenderProcessObserver> chrome_observer_; 195 scoped_ptr<extensions::Dispatcher> extension_dispatcher_; 196 scoped_ptr<extensions::RendererPermissionsPolicyDelegate> 197 permissions_policy_delegate_; 198 scoped_ptr<PrescientNetworkingDispatcher> prescient_networking_dispatcher_; 199 scoped_ptr<RendererNetPredictor> net_predictor_; 200 #if defined(ENABLE_SPELLCHECK) 201 scoped_ptr<SpellCheck> spellcheck_; 202 #endif 203 scoped_ptr<visitedlink::VisitedLinkSlave> visited_link_slave_; 204 scoped_ptr<safe_browsing::PhishingClassifierFilter> phishing_classifier_; 205 scoped_ptr<prerender::PrerenderDispatcher> prerender_dispatcher_; 206 #if defined(ENABLE_WEBRTC) 207 scoped_refptr<WebRtcLoggingMessageFilter> webrtc_logging_message_filter_; 208 #endif 209 scoped_ptr<SearchBouncer> search_bouncer_; 210 }; 211 212 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_ 213