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 CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_ 6 #define CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_ 7 8 #include <string> 9 10 #include "base/memory/weak_ptr.h" 11 #include "base/strings/string16.h" 12 #include "content/public/common/content_client.h" 13 #include "content/public/common/page_transition_types.h" 14 #include "ipc/ipc_message.h" 15 #include "third_party/WebKit/public/web/WebNavigationPolicy.h" 16 #include "third_party/WebKit/public/web/WebNavigationType.h" 17 #include "third_party/WebKit/public/web/WebPageVisibilityState.h" 18 #include "v8/include/v8.h" 19 20 class GURL; 21 class SkBitmap; 22 23 namespace base { 24 class FilePath; 25 class MessageLoop; 26 } 27 28 namespace WebKit { 29 class WebAudioDevice; 30 class WebClipboard; 31 class WebCrypto; 32 class WebFrame; 33 class WebMIDIAccessor; 34 class WebMIDIAccessorClient; 35 class WebMediaStreamCenter; 36 class WebMediaStreamCenterClient; 37 class WebPlugin; 38 class WebPluginContainer; 39 class WebPrescientNetworking; 40 class WebRTCPeerConnectionHandler; 41 class WebRTCPeerConnectionHandlerClient; 42 class WebSpeechSynthesizer; 43 class WebSpeechSynthesizerClient; 44 class WebThemeEngine; 45 class WebURLRequest; 46 struct WebPluginParams; 47 struct WebURLError; 48 } 49 50 namespace content { 51 52 class DocumentState; 53 class RenderView; 54 class SynchronousCompositor; 55 struct WebPluginInfo; 56 57 // Embedder API for participating in renderer logic. 58 class CONTENT_EXPORT ContentRendererClient { 59 public: 60 virtual ~ContentRendererClient() {} 61 62 // Notifies us that the RenderThread has been created. 63 virtual void RenderThreadStarted() {} 64 65 // Notifies that a new RenderView has been created. 66 virtual void RenderViewCreated(RenderView* render_view) {} 67 68 // Sets a number of views/tabs opened in this process. 69 virtual void SetNumberOfViews(int number_of_views) {} 70 71 // Returns the bitmap to show when a plugin crashed, or NULL for none. 72 virtual SkBitmap* GetSadPluginBitmap(); 73 74 // Returns the bitmap to show when a <webview> guest has crashed, or NULL for 75 // none. 76 virtual SkBitmap* GetSadWebViewBitmap(); 77 78 // Returns the default text encoding. 79 virtual std::string GetDefaultEncoding(); 80 81 // Allows the embedder to override creating a plugin. If it returns true, then 82 // |plugin| will contain the created plugin, although it could be NULL. If it 83 // returns false, the content layer will create the plugin. 84 virtual bool OverrideCreatePlugin( 85 RenderView* render_view, 86 WebKit::WebFrame* frame, 87 const WebKit::WebPluginParams& params, 88 WebKit::WebPlugin** plugin); 89 90 // Creates a replacement plug-in that is shown when the plug-in at |file_path| 91 // couldn't be loaded. This allows the embedder to show a custom placeholder. 92 virtual WebKit::WebPlugin* CreatePluginReplacement( 93 RenderView* render_view, 94 const base::FilePath& plugin_path); 95 96 // Returns true if the embedder has an error page to show for the given http 97 // status code. If so |error_domain| should be set to according to WebURLError 98 // and the embedder's GetNavigationErrorHtml will be called afterwards to get 99 // the error html. 100 virtual bool HasErrorPage(int http_status_code, 101 std::string* error_domain); 102 103 // Returns the information to display when a navigation error occurs. 104 // If |error_html| is not null then it may be set to a HTML page containing 105 // the details of the error and maybe links to more info. 106 // If |error_description| is not null it may be set to contain a brief 107 // message describing the error that has occurred. 108 // Either of the out parameters may be not written to in certain cases 109 // (lack of information on the error code) so the caller should take care to 110 // initialize the string values with safe defaults before the call. 111 virtual void GetNavigationErrorStrings( 112 WebKit::WebFrame* frame, 113 const WebKit::WebURLRequest& failed_request, 114 const WebKit::WebURLError& error, 115 std::string* error_html, 116 string16* error_description) {} 117 118 // Allows the embedder to control when media resources are loaded. Embedders 119 // can run |closure| immediately if they don't wish to defer media resource 120 // loading. 121 virtual void DeferMediaLoad(RenderView* render_view, 122 const base::Closure& closure); 123 124 // Allows the embedder to override creating a WebMediaStreamCenter. If it 125 // returns NULL the content layer will create the stream center. 126 virtual WebKit::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter( 127 WebKit::WebMediaStreamCenterClient* client); 128 129 // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If 130 // it returns NULL the content layer will create the connection handler. 131 virtual WebKit::WebRTCPeerConnectionHandler* 132 OverrideCreateWebRTCPeerConnectionHandler( 133 WebKit::WebRTCPeerConnectionHandlerClient* client); 134 135 // Allows the embedder to override creating a WebMIDIAccessor. If it 136 // returns NULL the content layer will create the MIDI accessor. 137 virtual WebKit::WebMIDIAccessor* OverrideCreateMIDIAccessor( 138 WebKit::WebMIDIAccessorClient* client); 139 140 // Allows the embedder to override creating a WebAudioDevice. If it 141 // returns NULL the content layer will create the audio device. 142 virtual WebKit::WebAudioDevice* OverrideCreateAudioDevice( 143 double sample_rate); 144 145 // Allows the embedder to override the WebKit::WebClipboard used. If it 146 // returns NULL the content layer will handle clipboard interactions. 147 virtual WebKit::WebClipboard* OverrideWebClipboard(); 148 149 // Allows the embedder to override the WebThemeEngine used. If it returns NULL 150 // the content layer will provide an engine. 151 virtual WebKit::WebThemeEngine* OverrideThemeEngine(); 152 153 // Allows the embedder to override the WebSpeechSynthesizer used. 154 // If it returns NULL the content layer will provide an engine. 155 virtual WebKit::WebSpeechSynthesizer* OverrideSpeechSynthesizer( 156 WebKit::WebSpeechSynthesizerClient* client); 157 158 // Allows the embedder to override the WebCrypto used. 159 // If it returns NULL the content layer will handle crypto. 160 virtual WebKit::WebCrypto* OverrideWebCrypto(); 161 162 // Returns true if the renderer process should schedule the idle handler when 163 // all widgets are hidden. 164 virtual bool RunIdleHandlerWhenWidgetsHidden(); 165 166 // Returns true if a popup window should be allowed. 167 virtual bool AllowPopup(); 168 169 // Returns true if the navigation was handled by the embedder and should be 170 // ignored by WebKit. This method is used by CEF. 171 virtual bool HandleNavigation(RenderView* view, 172 DocumentState* document_state, 173 int opener_id, 174 WebKit::WebFrame* frame, 175 const WebKit::WebURLRequest& request, 176 WebKit::WebNavigationType type, 177 WebKit::WebNavigationPolicy default_policy, 178 bool is_redirect); 179 180 virtual bool ShouldAbortNavigationAfterUrlResolve(content::RenderView* view, 181 const GURL& base, 182 const base::string16& fragment, 183 const GURL& result); 184 185 // Returns true if we should fork a new process for the given navigation. 186 virtual bool ShouldFork(WebKit::WebFrame* frame, 187 const GURL& url, 188 const std::string& http_method, 189 bool is_initial_navigation, 190 bool is_server_redirect, 191 bool* send_referrer); 192 193 // Notifies the embedder that the given frame is requesting the resource at 194 // |url|. If the function returns true, the url is changed to |new_url|. 195 virtual bool WillSendRequest(WebKit::WebFrame* frame, 196 PageTransition transition_type, 197 const GURL& url, 198 const GURL& first_party_for_cookies, 199 GURL* new_url); 200 201 // Whether to pump events when sending sync cookie messages. Needed if the 202 // embedder can potentiall put up a modal dialog on the UI thread as a result. 203 virtual bool ShouldPumpEventsDuringCookieMessage(); 204 205 // See the corresponding functions in WebKit::WebFrameClient. 206 virtual void DidCreateScriptContext(WebKit::WebFrame* frame, 207 v8::Handle<v8::Context> context, 208 int extension_group, 209 int world_id) {} 210 virtual void WillReleaseScriptContext(WebKit::WebFrame* frame, 211 v8::Handle<v8::Context>, 212 int world_id) {} 213 214 // See WebKit::Platform. 215 virtual unsigned long long VisitedLinkHash(const char* canonical_url, 216 size_t length); 217 virtual bool IsLinkVisited(unsigned long long link_hash); 218 virtual WebKit::WebPrescientNetworking* GetPrescientNetworking(); 219 virtual bool ShouldOverridePageVisibilityState( 220 const RenderView* render_view, 221 WebKit::WebPageVisibilityState* override_state); 222 223 // Return true if the GetCookie request will be handled by the embedder. 224 // Cookies are returned in the cookie parameter. 225 virtual bool HandleGetCookieRequest(RenderView* sender, 226 const GURL& url, 227 const GURL& first_party_for_cookies, 228 std::string* cookies); 229 230 // Return true if the SetCookie request will be handled by the embedder. 231 // Cookies to be set are passed in the value parameter. 232 virtual bool HandleSetCookieRequest(RenderView* sender, 233 const GURL& url, 234 const GURL& first_party_for_cookies, 235 const std::string& value); 236 237 // Allows an embedder to return custom PPAPI interfaces. 238 virtual const void* CreatePPAPIInterface( 239 const std::string& interface_name); 240 241 // Returns true if the given Pepper plugin is external (requiring special 242 // startup steps). 243 virtual bool IsExternalPepperPlugin(const std::string& module_name); 244 245 // Returns true if plugin living in the container can use 246 // pp::FileIO::RequestOSFileHandle. 247 virtual bool IsPluginAllowedToCallRequestOSFileHandle( 248 WebKit::WebPluginContainer* container); 249 250 // Returns whether BrowserPlugin should be allowed within the |container|. 251 virtual bool AllowBrowserPlugin(WebKit::WebPluginContainer* container); 252 253 // Returns true if the page at |url| can use Pepper MediaStream APIs. 254 virtual bool AllowPepperMediaStreamAPI(const GURL& url); 255 }; 256 257 } // namespace content 258 259 #endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_ 260