content_renderer_client.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
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 "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 "ui/base/page_transition_types.h" 19#include "v8/include/v8.h" 20 21class GURL; 22class SkBitmap; 23 24namespace base { 25class FilePath; 26class MessageLoop; 27} 28 29namespace blink { 30class WebAudioDevice; 31class WebClipboard; 32class WebFrame; 33class WebLocalFrame; 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; 47class WebWorkerPermissionClientProxy; 48struct WebPluginParams; 49struct WebURLError; 50} 51 52namespace content { 53class BrowserPluginDelegate; 54class DocumentState; 55class RenderFrame; 56class RenderView; 57class SynchronousCompositor; 58struct KeySystemInfo; 59struct WebPluginInfo; 60 61// Embedder API for participating in renderer logic. 62class CONTENT_EXPORT ContentRendererClient { 63 public: 64 virtual ~ContentRendererClient() {} 65 66 // Notifies us that the RenderThread has been created. 67 virtual void RenderThreadStarted() {} 68 69 // Notifies that a new RenderFrame has been created. Note that at this point, 70 // render_frame->GetWebFrame()->parent() is always NULL. This will change once 71 // the frame tree moves from Blink to content. 72 virtual void RenderFrameCreated(RenderFrame* render_frame) {} 73 74 // Notifies that a new RenderView has been created. 75 virtual void RenderViewCreated(RenderView* render_view) {} 76 77 // Sets a number of views/tabs opened in this process. 78 virtual void SetNumberOfViews(int number_of_views) {} 79 80 // Returns the bitmap to show when a plugin crashed, or NULL for none. 81 virtual SkBitmap* GetSadPluginBitmap(); 82 83 // Returns the bitmap to show when a <webview> guest has crashed, or NULL for 84 // none. 85 virtual SkBitmap* GetSadWebViewBitmap(); 86 87 // Returns the default text encoding. 88 virtual std::string GetDefaultEncoding(); 89 90 // Allows the embedder to override creating a plugin. If it returns true, then 91 // |plugin| will contain the created plugin, although it could be NULL. If it 92 // returns false, the content layer will create the plugin. 93 virtual bool OverrideCreatePlugin( 94 RenderFrame* render_frame, 95 blink::WebLocalFrame* frame, 96 const blink::WebPluginParams& params, 97 blink::WebPlugin** plugin); 98 99 // Creates a replacement plug-in that is shown when the plug-in at |file_path| 100 // couldn't be loaded. This allows the embedder to show a custom placeholder. 101 virtual blink::WebPlugin* CreatePluginReplacement( 102 RenderFrame* render_frame, 103 const base::FilePath& plugin_path); 104 105 // Creates a delegate for browser plugin. 106 virtual BrowserPluginDelegate* CreateBrowserPluginDelegate( 107 RenderFrame* render_frame, 108 const std::string& mime_type); 109 110 // Returns true if the embedder has an error page to show for the given http 111 // status code. If so |error_domain| should be set to according to WebURLError 112 // and the embedder's GetNavigationErrorHtml will be called afterwards to get 113 // the error html. 114 virtual bool HasErrorPage(int http_status_code, 115 std::string* error_domain); 116 117 // Returns true if the embedder prefers not to show an error page for a failed 118 // navigation to |url| in |render_frame|. 119 virtual bool ShouldSuppressErrorPage(RenderFrame* render_frame, 120 const GURL& url); 121 122 // Returns the information to display when a navigation error occurs. 123 // If |error_html| is not null then it may be set to a HTML page containing 124 // the details of the error and maybe links to more info. 125 // If |error_description| is not null it may be set to contain a brief 126 // message describing the error that has occurred. 127 // Either of the out parameters may be not written to in certain cases 128 // (lack of information on the error code) so the caller should take care to 129 // initialize the string values with safe defaults before the call. 130 virtual void GetNavigationErrorStrings( 131 content::RenderView* render_view, 132 blink::WebFrame* frame, 133 const blink::WebURLRequest& failed_request, 134 const blink::WebURLError& error, 135 std::string* error_html, 136 base::string16* error_description) {} 137 138 // Allows the embedder to control when media resources are loaded. Embedders 139 // can run |closure| immediately if they don't wish to defer media resource 140 // loading. 141 virtual void DeferMediaLoad(RenderFrame* render_frame, 142 const base::Closure& closure); 143 144 // Allows the embedder to override creating a WebMediaStreamCenter. If it 145 // returns NULL the content layer will create the stream center. 146 virtual blink::WebMediaStreamCenter* OverrideCreateWebMediaStreamCenter( 147 blink::WebMediaStreamCenterClient* client); 148 149 // Allows the embedder to override creating a WebRTCPeerConnectionHandler. If 150 // it returns NULL the content layer will create the connection handler. 151 virtual blink::WebRTCPeerConnectionHandler* 152 OverrideCreateWebRTCPeerConnectionHandler( 153 blink::WebRTCPeerConnectionHandlerClient* client); 154 155 // Allows the embedder to override creating a WebMIDIAccessor. If it 156 // returns NULL the content layer will create the MIDI accessor. 157 virtual blink::WebMIDIAccessor* OverrideCreateMIDIAccessor( 158 blink::WebMIDIAccessorClient* client); 159 160 // Allows the embedder to override creating a WebAudioDevice. If it 161 // returns NULL the content layer will create the audio device. 162 virtual blink::WebAudioDevice* OverrideCreateAudioDevice( 163 double sample_rate); 164 165 // Allows the embedder to override the blink::WebClipboard used. If it 166 // returns NULL the content layer will handle clipboard interactions. 167 virtual blink::WebClipboard* OverrideWebClipboard(); 168 169 // Allows the embedder to override the WebThemeEngine used. If it returns NULL 170 // the content layer will provide an engine. 171 virtual blink::WebThemeEngine* OverrideThemeEngine(); 172 173 // Allows the embedder to override the WebSpeechSynthesizer used. 174 // If it returns NULL the content layer will provide an engine. 175 virtual blink::WebSpeechSynthesizer* OverrideSpeechSynthesizer( 176 blink::WebSpeechSynthesizerClient* client); 177 178 // Returns true if the renderer process should schedule the idle handler when 179 // all widgets are hidden. 180 virtual bool RunIdleHandlerWhenWidgetsHidden(); 181 182 // Returns true if a popup window should be allowed. 183 virtual bool AllowPopup(); 184 185#ifdef OS_ANDROID 186 // TODO(sgurun) This callback is deprecated and will be removed as soon 187 // as android webview completes implementation of a resource throttle based 188 // shouldoverrideurl implementation. See crbug.com/325351 189 // 190 // Returns true if the navigation was handled by the embedder and should be 191 // ignored by WebKit. This method is used by CEF and android_webview. 192 virtual bool HandleNavigation(RenderFrame* render_frame, 193 DocumentState* document_state, 194 int opener_id, 195 blink::WebFrame* frame, 196 const blink::WebURLRequest& request, 197 blink::WebNavigationType type, 198 blink::WebNavigationPolicy default_policy, 199 bool is_redirect); 200#endif 201 202 // Returns true if we should fork a new process for the given navigation. 203 // If |send_referrer| is set to false (which is the default), no referrer 204 // header will be send for the navigation. Otherwise, the referrer header is 205 // set according to the frame's referrer policy. 206 virtual bool ShouldFork(blink::WebFrame* frame, 207 const GURL& url, 208 const std::string& http_method, 209 bool is_initial_navigation, 210 bool is_server_redirect, 211 bool* send_referrer); 212 213 // Notifies the embedder that the given frame is requesting the resource at 214 // |url|. If the function returns true, the url is changed to |new_url|. 215 virtual bool WillSendRequest(blink::WebFrame* frame, 216 ui::PageTransition transition_type, 217 const GURL& url, 218 const GURL& first_party_for_cookies, 219 GURL* new_url); 220 221 // See the corresponding functions in blink::WebFrameClient. 222 virtual void DidCreateScriptContext(blink::WebFrame* frame, 223 v8::Handle<v8::Context> context, 224 int extension_group, 225 int world_id) {} 226 227 // See blink::Platform. 228 virtual unsigned long long VisitedLinkHash(const char* canonical_url, 229 size_t length); 230 virtual bool IsLinkVisited(unsigned long long link_hash); 231 virtual blink::WebPrescientNetworking* GetPrescientNetworking(); 232 virtual bool ShouldOverridePageVisibilityState( 233 const RenderFrame* render_frame, 234 blink::WebPageVisibilityState* override_state); 235 236 // Allows an embedder to return custom PPAPI interfaces. 237 virtual const void* CreatePPAPIInterface( 238 const std::string& interface_name); 239 240 // Returns true if the given Pepper plugin is external (requiring special 241 // startup steps). 242 virtual bool IsExternalPepperPlugin(const std::string& module_name); 243 244 // Returns true if the page at |url| can use Pepper MediaStream APIs. 245 virtual bool AllowPepperMediaStreamAPI(const GURL& url); 246 247 // Gives the embedder a chance to register the key system(s) it supports by 248 // populating |key_systems|. 249 virtual void AddKeySystems(std::vector<KeySystemInfo>* key_systems); 250 251 // Returns true if we should report a detailed message (including a stack 252 // trace) for console [logs|errors|exceptions]. |source| is the WebKit- 253 // reported source for the error; this can point to a page or a script, 254 // and can be external or internal. 255 virtual bool ShouldReportDetailedMessageForSource( 256 const base::string16& source) const; 257 258 // Returns true if we should apply the cross-site document blocking policy to 259 // this renderer process. Currently, we apply the policy only to a renderer 260 // process running on a normal page from the web. 261 virtual bool ShouldEnableSiteIsolationPolicy() const; 262 263 // Creates a permission client proxy for in-renderer worker. 264 virtual blink::WebWorkerPermissionClientProxy* 265 CreateWorkerPermissionClientProxy(RenderFrame* render_frame, 266 blink::WebFrame* frame); 267 268 // Returns true if the page at |url| can use Pepper Compositor APIs. 269 virtual bool IsPluginAllowedToUseCompositorAPI(const GURL& url); 270 271 // Returns true if the page at |url| can use Pepper VideoDecoder APIs. 272 virtual bool IsPluginAllowedToUseVideoDecodeAPI(const GURL& url); 273 274 // Returns true if dev channel APIs are available for plugins. 275 virtual bool IsPluginAllowedToUseDevChannelAPIs(); 276}; 277 278} // namespace content 279 280#endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_ 281