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 #if defined(ENABLE_SPELLCHECK) 25 class SpellCheck; 26 class SpellCheckProvider; 27 #endif 28 29 struct ChromeViewHostMsg_GetPluginInfo_Output; 30 31 namespace content { 32 struct WebPluginInfo; 33 } 34 35 namespace extensions { 36 class Dispatcher; 37 class Extension; 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 WebKit { 54 class WebSecurityOrigin; 55 } 56 57 #if defined(ENABLE_WEBRTC) 58 class WebRtcLoggingMessageFilter; 59 #endif 60 61 namespace chrome { 62 63 class 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 AllowPepperMediaStreamAPI(const GURL& url) OVERRIDE; 140 141 // For testing. 142 void SetExtensionDispatcher(extensions::Dispatcher* extension_dispatcher); 143 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); 148 #endif 149 150 // Called in low-memory conditions to dump the memory used by the spellchecker 151 // and start over. 152 void OnPurgeMemory(); 153 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); 159 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(); 167 168 private: 169 FRIEND_TEST_ALL_PREFIXES(ChromeContentRendererClientTest, NaClRestriction); 170 171 const extensions::Extension* GetExtension( 172 const WebKit::WebSecurityOrigin& origin) const; 173 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, 177 const GURL& new_url, 178 const ExtensionSet& extensions, 179 bool is_extension_url, 180 bool is_initial_navigation); 181 182 static GURL GetNaClContentHandlerURL(const std::string& actual_mime_type, 183 const content::WebPluginInfo& plugin); 184 static bool IsNaClAllowed(const GURL& manifest_url, 185 const GURL& app_url, 186 bool is_nacl_unrestricted, 187 const extensions::Extension* extension, 188 WebKit::WebPluginParams* params); 189 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_; 198 #endif 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_; 204 #endif 205 206 #if defined(ENABLE_PLUGINS) 207 std::set<std::string> allowed_file_handle_origins_; 208 #endif 209 }; 210 211 } // namespace chrome 212 213 #endif // CHROME_RENDERER_CHROME_CONTENT_RENDERER_CLIENT_H_ 214