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