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_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_
      6 #define CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_
      7 
      8 #include "base/compiler_specific.h"
      9 #include "base/memory/scoped_ptr.h"
     10 #include "base/platform_file.h"
     11 #include "content/child/webkitplatformsupport_impl.h"
     12 #include "content/common/content_export.h"
     13 #include "third_party/WebKit/public/web/WebSharedWorkerRepository.h"
     14 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
     15 #include "third_party/WebKit/public/platform/WebIDBFactory.h"
     16 #include "webkit/renderer/compositor_bindings/web_compositor_support_impl.h"
     17 
     18 namespace base {
     19 class MessageLoopProxy;
     20 }
     21 
     22 namespace cc {
     23 class ContextProvider;
     24 }
     25 
     26 namespace IPC {
     27 class SyncMessageFilter;
     28 }
     29 
     30 namespace WebKit {
     31 class WebDeviceMotionData;
     32 class WebGraphicsContext3DProvider;
     33 }
     34 
     35 namespace content {
     36 class DeviceMotionEventPump;
     37 class DeviceOrientationEventPump;
     38 class QuotaMessageFilter;
     39 class RendererClipboardClient;
     40 class ThreadSafeSender;
     41 class WebClipboardImpl;
     42 class WebCryptoImpl;
     43 class WebFileSystemImpl;
     44 class WebSharedWorkerRepositoryImpl;
     45 
     46 class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
     47     : public WebKitPlatformSupportImpl {
     48  public:
     49   RendererWebKitPlatformSupportImpl();
     50   virtual ~RendererWebKitPlatformSupportImpl();
     51 
     52   void set_plugin_refresh_allowed(bool plugin_refresh_allowed) {
     53     plugin_refresh_allowed_ = plugin_refresh_allowed;
     54   }
     55   // Platform methods:
     56   virtual WebKit::WebClipboard* clipboard();
     57   virtual WebKit::WebMimeRegistry* mimeRegistry();
     58   virtual WebKit::WebFileUtilities* fileUtilities();
     59   virtual WebKit::WebSandboxSupport* sandboxSupport();
     60   virtual WebKit::WebCookieJar* cookieJar();
     61   virtual WebKit::WebThemeEngine* themeEngine();
     62   virtual WebKit::WebSpeechSynthesizer* createSpeechSynthesizer(
     63       WebKit::WebSpeechSynthesizerClient* client);
     64   virtual bool sandboxEnabled();
     65   virtual unsigned long long visitedLinkHash(
     66       const char* canonicalURL, size_t length);
     67   virtual bool isLinkVisited(unsigned long long linkHash);
     68   virtual WebKit::WebMessagePortChannel* createMessagePortChannel();
     69   virtual WebKit::WebPrescientNetworking* prescientNetworking();
     70   virtual void cacheMetadata(
     71       const WebKit::WebURL&, double, const char*, size_t);
     72   virtual WebKit::WebString defaultLocale();
     73   virtual void suddenTerminationChanged(bool enabled);
     74   virtual WebKit::WebStorageNamespace* createLocalStorageNamespace();
     75   virtual WebKit::Platform::FileHandle databaseOpenFile(
     76       const WebKit::WebString& vfs_file_name, int desired_flags);
     77   virtual int databaseDeleteFile(const WebKit::WebString& vfs_file_name,
     78                                  bool sync_dir);
     79   virtual long databaseGetFileAttributes(
     80       const WebKit::WebString& vfs_file_name);
     81   virtual long long databaseGetFileSize(
     82       const WebKit::WebString& vfs_file_name);
     83   virtual long long databaseGetSpaceAvailableForOrigin(
     84       const WebKit::WebString& origin_identifier);
     85   virtual WebKit::WebString signedPublicKeyAndChallengeString(
     86       unsigned key_size_index,
     87       const WebKit::WebString& challenge,
     88       const WebKit::WebURL& url);
     89   virtual void getPluginList(bool refresh,
     90                              WebKit::WebPluginListBuilder* builder);
     91   virtual void screenColorProfile(WebKit::WebVector<char>* to_profile);
     92   virtual WebKit::WebIDBFactory* idbFactory();
     93   virtual WebKit::WebFileSystem* fileSystem();
     94   virtual WebKit::WebSharedWorkerRepository* sharedWorkerRepository();
     95   virtual bool canAccelerate2dCanvas();
     96   virtual bool isThreadedCompositingEnabled();
     97   virtual double audioHardwareSampleRate();
     98   virtual size_t audioHardwareBufferSize();
     99   virtual unsigned audioHardwareOutputChannels();
    100 
    101   // TODO(crogers): remove deprecated API as soon as WebKit calls new API.
    102   virtual WebKit::WebAudioDevice* createAudioDevice(
    103       size_t buffer_size, unsigned channels, double sample_rate,
    104       WebKit::WebAudioDevice::RenderCallback* callback);
    105   // TODO(crogers): remove deprecated API as soon as WebKit calls new API.
    106   virtual WebKit::WebAudioDevice* createAudioDevice(
    107       size_t buffer_size, unsigned input_channels, unsigned channels,
    108       double sample_rate, WebKit::WebAudioDevice::RenderCallback* callback);
    109 
    110   virtual WebKit::WebAudioDevice* createAudioDevice(
    111       size_t buffer_size, unsigned input_channels, unsigned channels,
    112       double sample_rate, WebKit::WebAudioDevice::RenderCallback* callback,
    113       const WebKit::WebString& input_device_id);
    114 
    115   virtual bool loadAudioResource(
    116       WebKit::WebAudioBus* destination_bus, const char* audio_file_data,
    117       size_t data_size, double sample_rate);
    118 
    119   virtual WebKit::WebContentDecryptionModule* createContentDecryptionModule(
    120       const WebKit::WebString& key_system);
    121   virtual WebKit::WebMIDIAccessor*
    122       createMIDIAccessor(WebKit::WebMIDIAccessorClient* client);
    123 
    124   virtual WebKit::WebBlobRegistry* blobRegistry();
    125   virtual void sampleGamepads(WebKit::WebGamepads&);
    126   virtual WebKit::WebString userAgent(const WebKit::WebURL& url);
    127   virtual WebKit::WebRTCPeerConnectionHandler* createRTCPeerConnectionHandler(
    128       WebKit::WebRTCPeerConnectionHandlerClient* client);
    129   virtual WebKit::WebMediaStreamCenter* createMediaStreamCenter(
    130       WebKit::WebMediaStreamCenterClient* client);
    131   virtual bool processMemorySizesInBytes(
    132       size_t* private_bytes, size_t* shared_bytes);
    133   virtual WebKit::WebGraphicsContext3D* createOffscreenGraphicsContext3D(
    134       const WebKit::WebGraphicsContext3D::Attributes& attributes);
    135   virtual WebKit::WebGraphicsContext3DProvider*
    136       createSharedOffscreenGraphicsContext3DProvider();
    137   virtual WebKit::WebCompositorSupport* compositorSupport();
    138   virtual WebKit::WebString convertIDNToUnicode(
    139       const WebKit::WebString& host, const WebKit::WebString& languages);
    140   virtual void setDeviceMotionListener(
    141       WebKit::WebDeviceMotionListener* listener) OVERRIDE;
    142   virtual void setDeviceOrientationListener(
    143       WebKit::WebDeviceOrientationListener* listener) OVERRIDE;
    144   virtual WebKit::WebCrypto* crypto() OVERRIDE;
    145   virtual void queryStorageUsageAndQuota(
    146       const WebKit::WebURL& storage_partition,
    147       WebKit::WebStorageQuotaType,
    148       WebKit::WebStorageQuotaCallbacks*) OVERRIDE;
    149 
    150 #if defined(OS_ANDROID)
    151   virtual void vibrate(unsigned int milliseconds);
    152   virtual void cancelVibration();
    153 #endif  // defined(OS_ANDROID)
    154 
    155   // Disables the WebSandboxSupport implementation for testing.
    156   // Tests that do not set up a full sandbox environment should call
    157   // SetSandboxEnabledForTesting(false) _before_ creating any instances
    158   // of this class, to ensure that we don't attempt to use sandbox-related
    159   // file descriptors or other resources.
    160   //
    161   // Returns the previous |enable| value.
    162   static bool SetSandboxEnabledForTesting(bool enable);
    163 
    164   // Set WebGamepads to return when sampleGamepads() is invoked.
    165   static void SetMockGamepadsForTesting(const WebKit::WebGamepads& pads);
    166   // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked.
    167   static void SetMockDeviceMotionDataForTesting(
    168       const WebKit::WebDeviceMotionData& data);
    169 
    170  private:
    171   bool CheckPreparsedJsCachingEnabled() const;
    172 
    173   scoped_ptr<RendererClipboardClient> clipboard_client_;
    174   scoped_ptr<WebClipboardImpl> clipboard_;
    175 
    176   class FileUtilities;
    177   scoped_ptr<FileUtilities> file_utilities_;
    178 
    179   class MimeRegistry;
    180   scoped_ptr<MimeRegistry> mime_registry_;
    181 
    182   class SandboxSupport;
    183   scoped_ptr<SandboxSupport> sandbox_support_;
    184 
    185   // This counter keeps track of the number of times sudden termination is
    186   // enabled or disabled. It starts at 0 (enabled) and for every disable
    187   // increments by 1, for every enable decrements by 1. When it reaches 0,
    188   // we tell the browser to enable fast termination.
    189   int sudden_termination_disables_;
    190 
    191   // If true, then a GetPlugins call is allowed to rescan the disk.
    192   bool plugin_refresh_allowed_;
    193 
    194   // Implementation of the WebSharedWorkerRepository APIs (provides an interface
    195   // to WorkerService on the browser thread.
    196   scoped_ptr<WebSharedWorkerRepositoryImpl> shared_worker_repository_;
    197 
    198   scoped_ptr<WebKit::WebIDBFactory> web_idb_factory_;
    199 
    200   scoped_ptr<WebFileSystemImpl> web_file_system_;
    201 
    202   scoped_ptr<WebKit::WebBlobRegistry> blob_registry_;
    203 
    204   scoped_ptr<DeviceMotionEventPump> device_motion_event_pump_;
    205   scoped_ptr<DeviceOrientationEventPump> device_orientation_event_pump_;
    206 
    207   scoped_refptr<base::MessageLoopProxy> child_thread_loop_;
    208   scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_;
    209   scoped_refptr<ThreadSafeSender> thread_safe_sender_;
    210   scoped_refptr<QuotaMessageFilter> quota_message_filter_;
    211 
    212   scoped_refptr<cc::ContextProvider> shared_offscreen_context_;
    213 
    214   webkit::WebCompositorSupportImpl compositor_support_;
    215 
    216   scoped_ptr<WebCryptoImpl> web_crypto_;
    217 };
    218 
    219 }  // namespace content
    220 
    221 #endif  // CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_
    222