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