content_renderer_client.h revision 4e180b6a0b4720a9b8e9e959a882386f690f08ff
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_ 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string> 95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector> 105e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles) 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/weak_ptr.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/strings/string16.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/content_client.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/common/page_transition_types.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ipc/ipc_message.h" 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/WebKit/public/web/WebNavigationPolicy.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/WebKit/public/web/WebNavigationType.h" 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "third_party/WebKit/public/web/WebPageVisibilityState.h" 19c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "v8/include/v8.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SkBitmap; 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 25class FilePath; 26class MessageLoop; 27} 28 29namespace WebKit { 30class WebAudioDevice; 31class WebClipboard; 32class WebFrame; 33class WebMIDIAccessor; 34class WebMIDIAccessorClient; 35class WebMediaStreamCenter; 36class WebMediaStreamCenterClient; 37class WebPlugin; 38class WebPluginContainer; 39class WebPrescientNetworking; 40class WebRTCPeerConnectionHandler; 41class WebRTCPeerConnectionHandlerClient; 42class WebSpeechSynthesizer; 43class WebSpeechSynthesizerClient; 44class WebThemeEngine; 45class WebURLRequest; 46struct WebPluginParams; 47struct WebURLError; 48} 49 50namespace content { 51 52class RenderView; 53class SynchronousCompositor; 54struct KeySystemInfo; 55struct WebPluginInfo; 56 57// Embedder API for participating in renderer logic. 58class 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 true if the embedder prefers not to show an error page for a failed 104 // navigation to |url|. 105 virtual bool ShouldSuppressErrorPage(const GURL& url); 106 107 // Returns the information to display when a navigation error occurs. 108 // If |error_html| is not null then it may be set to a HTML page containing 109 // the details of the error and maybe links to more info. 110 // If |error_description| is not null it may be set to contain a brief 111 // message describing the error that has occurred. 112 // Either of the out parameters may be not written to in certain cases 113 // (lack of information on the error code) so the caller should take care to 114 // initialize the string values with safe defaults before the call. 115 virtual void GetNavigationErrorStrings( 116 WebKit::WebFrame* frame, 117 const WebKit::WebURLRequest& failed_request, 118 const WebKit::WebURLError& error, 119 const std::string& accept_languages, 120 std::string* error_html, 121 string16* error_description) {} 122 123 // Allows the embedder to control when media resources are loaded. Embedders 124 // can run |closure| immediately if they don't wish to defer media resource 125 // loading. 126 virtual void DeferMediaLoad(RenderView* render_view, 127 const base::Closure& closure); 128 129 // Allows the embedder to override creating a WebMediaStreamCenter. If it 130 // returns NULL the content layer will create the stream center. 131 virtual WebKit::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter( 132 WebKit::WebMediaStreamCenterClient* client); 133 134 // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If 135 // it returns NULL the content layer will create the connection handler. 136 virtual WebKit::WebRTCPeerConnectionHandler* 137 OverrideCreateWebRTCPeerConnectionHandler( 138 WebKit::WebRTCPeerConnectionHandlerClient* client); 139 140 // Allows the embedder to override creating a WebMIDIAccessor. If it 141 // returns NULL the content layer will create the MIDI accessor. 142 virtual WebKit::WebMIDIAccessor* OverrideCreateMIDIAccessor( 143 WebKit::WebMIDIAccessorClient* client); 144 145 // Allows the embedder to override creating a WebAudioDevice. If it 146 // returns NULL the content layer will create the audio device. 147 virtual WebKit::WebAudioDevice* OverrideCreateAudioDevice( 148 double sample_rate); 149 150 // Allows the embedder to override the WebKit::WebClipboard used. If it 151 // returns NULL the content layer will handle clipboard interactions. 152 virtual WebKit::WebClipboard* OverrideWebClipboard(); 153 154 // Allows the embedder to override the WebThemeEngine used. If it returns NULL 155 // the content layer will provide an engine. 156 virtual WebKit::WebThemeEngine* OverrideThemeEngine(); 157 158 // Allows the embedder to override the WebSpeechSynthesizer used. 159 // If it returns NULL the content layer will provide an engine. 160 virtual WebKit::WebSpeechSynthesizer* OverrideSpeechSynthesizer( 161 WebKit::WebSpeechSynthesizerClient* client); 162 163 // Returns true if the renderer process should schedule the idle handler when 164 // all widgets are hidden. 165 virtual bool RunIdleHandlerWhenWidgetsHidden(); 166 167 // Returns true if a popup window should be allowed. 168 virtual bool AllowPopup(); 169 170 // Returns true if the navigation was handled by the embedder and should be 171 // ignored by WebKit. This method is used by CEF. 172 virtual bool HandleNavigation(WebKit::WebFrame* frame, 173 const WebKit::WebURLRequest& request, 174 WebKit::WebNavigationType type, 175 WebKit::WebNavigationPolicy default_policy, 176 bool is_redirect); 177 178 // Returns true if we should fork a new process for the given navigation. 179 // If |send_referrer| is set to false (which is the default), no referrer 180 // header will be send for the navigation. Otherwise, the referrer header is 181 // set according to the frame's referrer policy. 182 virtual bool ShouldFork(WebKit::WebFrame* frame, 183 const GURL& url, 184 const std::string& http_method, 185 bool is_initial_navigation, 186 bool is_server_redirect, 187 bool* send_referrer); 188 189 // Notifies the embedder that the given frame is requesting the resource at 190 // |url|. If the function returns true, the url is changed to |new_url|. 191 virtual bool WillSendRequest(WebKit::WebFrame* frame, 192 PageTransition transition_type, 193 const GURL& url, 194 const GURL& first_party_for_cookies, 195 GURL* new_url); 196 197 // Whether to pump events when sending sync cookie messages. Needed if the 198 // embedder can potentiall put up a modal dialog on the UI thread as a result. 199 virtual bool ShouldPumpEventsDuringCookieMessage(); 200 201 // See the corresponding functions in WebKit::WebFrameClient. 202 virtual void DidCreateScriptContext(WebKit::WebFrame* frame, 203 v8::Handle<v8::Context> context, 204 int extension_group, 205 int world_id) {} 206 virtual void WillReleaseScriptContext(WebKit::WebFrame* frame, 207 v8::Handle<v8::Context>, 208 int world_id) {} 209 210 // See WebKit::Platform. 211 virtual unsigned long long VisitedLinkHash(const char* canonical_url, 212 size_t length); 213 virtual bool IsLinkVisited(unsigned long long link_hash); 214 virtual WebKit::WebPrescientNetworking* GetPrescientNetworking(); 215 virtual bool ShouldOverridePageVisibilityState( 216 const RenderView* render_view, 217 WebKit::WebPageVisibilityState* override_state); 218 219 // Return true if the GetCookie request will be handled by the embedder. 220 // Cookies are returned in the cookie parameter. 221 virtual bool HandleGetCookieRequest(RenderView* sender, 222 const GURL& url, 223 const GURL& first_party_for_cookies, 224 std::string* cookies); 225 226 // Return true if the SetCookie request will be handled by the embedder. 227 // Cookies to be set are passed in the value parameter. 228 virtual bool HandleSetCookieRequest(RenderView* sender, 229 const GURL& url, 230 const GURL& first_party_for_cookies, 231 const std::string& value); 232 233 // Allows an embedder to return custom PPAPI interfaces. 234 virtual const void* CreatePPAPIInterface( 235 const std::string& interface_name); 236 237 // Returns true if the given Pepper plugin is external (requiring special 238 // startup steps). 239 virtual bool IsExternalPepperPlugin(const std::string& module_name); 240 241 // Returns true if plugin living in the container can use 242 // pp::FileIO::RequestOSFileHandle. 243 // TODO(teravest): Remove this when FileIO is moved to the browser. 244 virtual bool IsPluginAllowedToCallRequestOSFileHandle( 245 WebKit::WebPluginContainer* container); 246 247 // Returns whether BrowserPlugin should be allowed within the |container|. 248 virtual bool AllowBrowserPlugin(WebKit::WebPluginContainer* container); 249 250 // Returns true if the page at |url| can use Pepper MediaStream APIs. 251 virtual bool AllowPepperMediaStreamAPI(const GURL& url); 252 253 // Gives the embedder a chance to register the key system(s) it supports by 254 // populating |key_systems|. 255 virtual void AddKeySystems(std::vector<KeySystemInfo>* key_systems); 256 257 // Returns true if we should report a detailed message (including a stack 258 // trace) for console [logs|errors|exceptions]. |source| is the WebKit- 259 // reported source for the error; this can point to a page or a script, 260 // and can be external or internal. 261 virtual bool ShouldReportDetailedMessageForSource( 262 const base::string16& source) const; 263 264 // Returns true if we should apply the cross-site document blocking policy to 265 // this renderer process. Currently, we apply the policy only to a renderer 266 // process running on a normal page from the web. 267 virtual bool ShouldEnableSiteIsolationPolicy() const; 268}; 269 270} // namespace content 271 272#endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_ 273