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