content_renderer_client.h revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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 20class GURL; 21class SkBitmap; 22 23namespace base { 24class FilePath; 25class MessageLoop; 26} 27 28namespace WebKit { 29class WebAudioDevice; 30class WebClipboard; 31class WebFrame; 32class WebHyphenator; 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 webkit { 51namespace ppapi { 52class PpapiInterfaceFactoryManager; 53} 54} 55 56namespace content { 57 58class RenderView; 59class SynchronousCompositor; 60struct WebPluginInfo; 61 62// Embedder API for participating in renderer logic. 63class CONTENT_EXPORT ContentRendererClient { 64 public: 65 virtual ~ContentRendererClient() {} 66 67 // Notifies us that the RenderThread has been created. 68 virtual void RenderThreadStarted() {} 69 70 // Notifies that a new RenderView has been created. 71 virtual void RenderViewCreated(RenderView* render_view) {} 72 73 // Sets a number of views/tabs opened in this process. 74 virtual void SetNumberOfViews(int number_of_views) {} 75 76 // Returns the bitmap to show when a plugin crashed, or NULL for none. 77 virtual SkBitmap* GetSadPluginBitmap(); 78 79 // Returns the bitmap to show when a <webview> guest has crashed, or NULL for 80 // none. 81 virtual SkBitmap* GetSadWebViewBitmap(); 82 83 // Returns the default text encoding. 84 virtual std::string GetDefaultEncoding(); 85 86 // Allows the embedder to override creating a plugin. If it returns true, then 87 // |plugin| will contain the created plugin, although it could be NULL. If it 88 // returns false, the content layer will create the plugin. 89 virtual bool OverrideCreatePlugin( 90 RenderView* render_view, 91 WebKit::WebFrame* frame, 92 const WebKit::WebPluginParams& params, 93 WebKit::WebPlugin** plugin); 94 95 // Creates a replacement plug-in that is shown when the plug-in at |file_path| 96 // couldn't be loaded. This allows the embedder to show a custom placeholder. 97 virtual WebKit::WebPlugin* CreatePluginReplacement( 98 RenderView* render_view, 99 const base::FilePath& plugin_path); 100 101 // Returns true if the embedder has an error page to show for the given http 102 // status code. If so |error_domain| should be set to according to WebURLError 103 // and the embedder's GetNavigationErrorHtml will be called afterwards to get 104 // the error html. 105 virtual bool HasErrorPage(int http_status_code, 106 std::string* error_domain); 107 108 // Returns the information to display when a navigation error occurs. 109 // If |error_html| is not null then it may be set to a HTML page containing 110 // the details of the error and maybe links to more info. 111 // If |error_description| is not null it may be set to contain a brief 112 // message describing the error that has occurred. 113 // Either of the out parameters may be not written to in certain cases 114 // (lack of information on the error code) so the caller should take care to 115 // initialize the string values with safe defaults before the call. 116 virtual void GetNavigationErrorStrings( 117 WebKit::WebFrame* frame, 118 const WebKit::WebURLRequest& failed_request, 119 const WebKit::WebURLError& error, 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 WebKit::WebHyphenator used. If it 155 // returns NULL the content layer will handle hyphenation. 156 virtual WebKit::WebHyphenator* OverrideWebHyphenator(); 157 158 // Allows the embedder to override the WebThemeEngine used. If it returns NULL 159 // the content layer will provide an engine. 160 virtual WebKit::WebThemeEngine* OverrideThemeEngine(); 161 162 // Allows the embedder to override the WebSpeechSynthesizer used. 163 // If it returns NULL the content layer will provide an engine. 164 virtual WebKit::WebSpeechSynthesizer* OverrideSpeechSynthesizer( 165 WebKit::WebSpeechSynthesizerClient* client); 166 167 // Returns true if the renderer process should schedule the idle handler when 168 // all widgets are hidden. 169 virtual bool RunIdleHandlerWhenWidgetsHidden(); 170 171 // Returns true if a popup window should be allowed. 172 virtual bool AllowPopup(); 173 174 // Returns true if the navigation was handled by the embedder and should be 175 // ignored by WebKit. This method is used by CEF. 176 virtual bool HandleNavigation(WebKit::WebFrame* frame, 177 const WebKit::WebURLRequest& request, 178 WebKit::WebNavigationType type, 179 WebKit::WebNavigationPolicy default_policy, 180 bool is_redirect); 181 182 // Returns true if we should fork a new process for the given navigation. 183 virtual bool ShouldFork(WebKit::WebFrame* frame, 184 const GURL& url, 185 const std::string& http_method, 186 bool is_initial_navigation, 187 bool is_server_redirect, 188 bool* send_referrer); 189 190 // Notifies the embedder that the given frame is requesting the resource at 191 // |url|. If the function returns true, the url is changed to |new_url|. 192 virtual bool WillSendRequest(WebKit::WebFrame* frame, 193 PageTransition transition_type, 194 const GURL& url, 195 const GURL& first_party_for_cookies, 196 GURL* new_url); 197 198 // Whether to pump events when sending sync cookie messages. Needed if the 199 // embedder can potentiall put up a modal dialog on the UI thread as a result. 200 virtual bool ShouldPumpEventsDuringCookieMessage(); 201 202 // See the corresponding functions in WebKit::WebFrameClient. 203 virtual void DidCreateScriptContext(WebKit::WebFrame* frame, 204 v8::Handle<v8::Context> context, 205 int extension_group, 206 int world_id) {} 207 virtual void WillReleaseScriptContext(WebKit::WebFrame* frame, 208 v8::Handle<v8::Context>, 209 int world_id) {} 210 211 // See WebKit::Platform. 212 virtual unsigned long long VisitedLinkHash(const char* canonical_url, 213 size_t length); 214 virtual bool IsLinkVisited(unsigned long long link_hash); 215 virtual void PrefetchHostName(const char* hostname, size_t length) {} 216 virtual WebKit::WebPrescientNetworking* GetPrescientNetworking(); 217 virtual bool ShouldOverridePageVisibilityState( 218 const RenderView* render_view, 219 WebKit::WebPageVisibilityState* override_state) const; 220 221 // Return true if the GetCookie request will be handled by the embedder. 222 // Cookies are returned in the cookie parameter. 223 virtual bool HandleGetCookieRequest(RenderView* sender, 224 const GURL& url, 225 const GURL& first_party_for_cookies, 226 std::string* cookies); 227 228 // Return true if the SetCookie request will be handled by the embedder. 229 // Cookies to be set are passed in the value parameter. 230 virtual bool HandleSetCookieRequest(RenderView* sender, 231 const GURL& url, 232 const GURL& first_party_for_cookies, 233 const std::string& value); 234 235 virtual void RegisterPPAPIInterfaceFactories( 236 webkit::ppapi::PpapiInterfaceFactoryManager* factory_manager) {} 237 238 // Returns true if plugin living in the container can use 239 // pp::FileIO::RequestOSFileHandle. 240 virtual bool IsPluginAllowedToCallRequestOSFileHandle( 241 WebKit::WebPluginContainer* container) const; 242 243 // Returns whether BrowserPlugin should be allowed within the |container|. 244 virtual bool AllowBrowserPlugin(WebKit::WebPluginContainer* container) const; 245 246 // Returns true if the page at |url| can use Pepper MediaStream APIs. 247 virtual bool AllowPepperMediaStreamAPI(const GURL& url) const; 248}; 249 250} // namespace content 251 252#endif // CONTENT_PUBLIC_RENDERER_CONTENT_RENDERER_CLIENT_H_ 253