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