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/id_map.h"
     10 #include "base/memory/scoped_ptr.h"
     11 #include "cc/blink/web_compositor_support_impl.h"
     12 #include "content/child/blink_platform_impl.h"
     13 #include "content/common/content_export.h"
     14 #include "content/renderer/webpublicsuffixlist_impl.h"
     15 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
     16 #include "third_party/WebKit/public/platform/WebIDBFactory.h"
     17 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
     18 
     19 namespace base {
     20 class MessageLoopProxy;
     21 }
     22 
     23 namespace cc {
     24 class ContextProvider;
     25 }
     26 
     27 namespace IPC {
     28 class SyncMessageFilter;
     29 }
     30 
     31 namespace blink {
     32 class WebBatteryStatus;
     33 class WebDeviceMotionData;
     34 class WebDeviceOrientationData;
     35 class WebGraphicsContext3DProvider;
     36 }
     37 
     38 namespace content {
     39 class BatteryStatusDispatcher;
     40 class DeviceLightEventPump;
     41 class DeviceMotionEventPump;
     42 class DeviceOrientationEventPump;
     43 class PlatformEventObserverBase;
     44 class QuotaMessageFilter;
     45 class RendererClipboardClient;
     46 class RenderView;
     47 class ThreadSafeSender;
     48 class WebClipboardImpl;
     49 class WebDatabaseObserverImpl;
     50 class WebFileSystemImpl;
     51 
     52 class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
     53     : public BlinkPlatformImpl {
     54  public:
     55   RendererWebKitPlatformSupportImpl();
     56   virtual ~RendererWebKitPlatformSupportImpl();
     57 
     58   void set_plugin_refresh_allowed(bool plugin_refresh_allowed) {
     59     plugin_refresh_allowed_ = plugin_refresh_allowed;
     60   }
     61   // Platform methods:
     62   virtual blink::WebClipboard* clipboard();
     63   virtual blink::WebMimeRegistry* mimeRegistry();
     64   virtual blink::WebFileUtilities* fileUtilities();
     65   virtual blink::WebSandboxSupport* sandboxSupport();
     66   virtual blink::WebCookieJar* cookieJar();
     67   virtual blink::WebThemeEngine* themeEngine();
     68   virtual blink::WebSpeechSynthesizer* createSpeechSynthesizer(
     69       blink::WebSpeechSynthesizerClient* client);
     70   virtual bool sandboxEnabled();
     71   virtual unsigned long long visitedLinkHash(
     72       const char* canonicalURL, size_t length);
     73   virtual bool isLinkVisited(unsigned long long linkHash);
     74   virtual void createMessageChannel(blink::WebMessagePortChannel** channel1,
     75                                     blink::WebMessagePortChannel** channel2);
     76   virtual blink::WebPrescientNetworking* prescientNetworking();
     77   virtual void cacheMetadata(
     78       const blink::WebURL&, double, const char*, size_t);
     79   virtual blink::WebString defaultLocale();
     80   virtual void suddenTerminationChanged(bool enabled);
     81   virtual blink::WebStorageNamespace* createLocalStorageNamespace();
     82   virtual blink::Platform::FileHandle databaseOpenFile(
     83       const blink::WebString& vfs_file_name, int desired_flags);
     84   virtual int databaseDeleteFile(const blink::WebString& vfs_file_name,
     85                                  bool sync_dir);
     86   virtual long databaseGetFileAttributes(
     87       const blink::WebString& vfs_file_name);
     88   virtual long long databaseGetFileSize(
     89       const blink::WebString& vfs_file_name);
     90   virtual long long databaseGetSpaceAvailableForOrigin(
     91       const blink::WebString& origin_identifier);
     92   virtual blink::WebString signedPublicKeyAndChallengeString(
     93       unsigned key_size_index,
     94       const blink::WebString& challenge,
     95       const blink::WebURL& url);
     96   virtual void getPluginList(bool refresh,
     97                              blink::WebPluginListBuilder* builder);
     98   virtual blink::WebPublicSuffixList* publicSuffixList();
     99   virtual void screenColorProfile(blink::WebVector<char>* to_profile);
    100   virtual blink::WebScrollbarBehavior* scrollbarBehavior();
    101   virtual blink::WebIDBFactory* idbFactory();
    102   virtual blink::WebFileSystem* fileSystem();
    103   virtual bool canAccelerate2dCanvas();
    104   virtual bool isThreadedCompositingEnabled();
    105   virtual double audioHardwareSampleRate();
    106   virtual size_t audioHardwareBufferSize();
    107   virtual unsigned audioHardwareOutputChannels();
    108   virtual blink::WebDatabaseObserver* databaseObserver();
    109 
    110   virtual blink::WebAudioDevice* createAudioDevice(
    111       size_t buffer_size, unsigned input_channels, unsigned channels,
    112       double sample_rate, blink::WebAudioDevice::RenderCallback* callback,
    113       const blink::WebString& input_device_id);
    114 
    115   virtual bool loadAudioResource(
    116       blink::WebAudioBus* destination_bus, const char* audio_file_data,
    117       size_t data_size);
    118 
    119   virtual blink::WebMIDIAccessor*
    120       createMIDIAccessor(blink::WebMIDIAccessorClient* client);
    121 
    122   virtual blink::WebBlobRegistry* blobRegistry();
    123   virtual void sampleGamepads(blink::WebGamepads&);
    124   virtual blink::WebRTCPeerConnectionHandler* createRTCPeerConnectionHandler(
    125       blink::WebRTCPeerConnectionHandlerClient* client);
    126   virtual blink::WebMediaStreamCenter* createMediaStreamCenter(
    127       blink::WebMediaStreamCenterClient* client);
    128   virtual bool processMemorySizesInBytes(
    129       size_t* private_bytes, size_t* shared_bytes);
    130   virtual blink::WebGraphicsContext3D* createOffscreenGraphicsContext3D(
    131       const blink::WebGraphicsContext3D::Attributes& attributes);
    132   virtual blink::WebGraphicsContext3D* createOffscreenGraphicsContext3D(
    133       const blink::WebGraphicsContext3D::Attributes& attributes,
    134       blink::WebGraphicsContext3D* share_context);
    135   virtual blink::WebGraphicsContext3DProvider*
    136       createSharedOffscreenGraphicsContext3DProvider();
    137   virtual blink::WebCompositorSupport* compositorSupport();
    138   virtual blink::WebString convertIDNToUnicode(
    139       const blink::WebString& host, const blink::WebString& languages);
    140   virtual void startListening(blink::WebPlatformEventType,
    141                               blink::WebPlatformEventListener*);
    142   virtual void stopListening(blink::WebPlatformEventType);
    143   virtual void queryStorageUsageAndQuota(
    144       const blink::WebURL& storage_partition,
    145       blink::WebStorageQuotaType,
    146       blink::WebStorageQuotaCallbacks);
    147   virtual void vibrate(unsigned int milliseconds);
    148   virtual void cancelVibration();
    149 
    150   // Set the PlatformEventObserverBase in |platform_event_observers_| associated
    151   // with |type| to |observer|. If there was already an observer associated to
    152   // the given |type|, it will be replaced.
    153   // Note that |observer| will be owned by this object after the call.
    154   void SetPlatformEventObserverForTesting(
    155       blink::WebPlatformEventType type,
    156       scoped_ptr<PlatformEventObserverBase> observer);
    157 
    158   // Disables the WebSandboxSupport implementation for testing.
    159   // Tests that do not set up a full sandbox environment should call
    160   // SetSandboxEnabledForTesting(false) _before_ creating any instances
    161   // of this class, to ensure that we don't attempt to use sandbox-related
    162   // file descriptors or other resources.
    163   //
    164   // Returns the previous |enable| value.
    165   static bool SetSandboxEnabledForTesting(bool enable);
    166 
    167   //  Set a double to return when setDeviceLightListener is invoked.
    168   static void SetMockDeviceLightDataForTesting(double data);
    169   // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked.
    170   static void SetMockDeviceMotionDataForTesting(
    171       const blink::WebDeviceMotionData& data);
    172   // Set WebDeviceOrientationData to return when setDeviceOrientationListener
    173   // is invoked.
    174   static void SetMockDeviceOrientationDataForTesting(
    175       const blink::WebDeviceOrientationData& data);
    176 
    177   // Notifies blink::WebBatteryStatusListener that battery status has changed.
    178   void MockBatteryStatusChangedForTesting(
    179       const blink::WebBatteryStatus& status);
    180 
    181   WebDatabaseObserverImpl* web_database_observer_impl() {
    182     return web_database_observer_impl_.get();
    183   }
    184 
    185  private:
    186   bool CheckPreparsedJsCachingEnabled() const;
    187 
    188   // Factory that takes a type and return PlatformEventObserverBase that matches
    189   // it.
    190   static PlatformEventObserverBase* CreatePlatformEventObserverFromType(
    191       blink::WebPlatformEventType type);
    192 
    193   // Use the data previously set via SetMockDevice...DataForTesting() and send
    194   // them to the registered listener.
    195   void SendFakeDeviceEventDataForTesting(blink::WebPlatformEventType type);
    196 
    197   scoped_ptr<RendererClipboardClient> clipboard_client_;
    198   scoped_ptr<WebClipboardImpl> clipboard_;
    199 
    200   class FileUtilities;
    201   scoped_ptr<FileUtilities> file_utilities_;
    202 
    203   class MimeRegistry;
    204   scoped_ptr<MimeRegistry> mime_registry_;
    205 
    206   class SandboxSupport;
    207   scoped_ptr<SandboxSupport> sandbox_support_;
    208 
    209   // This counter keeps track of the number of times sudden termination is
    210   // enabled or disabled. It starts at 0 (enabled) and for every disable
    211   // increments by 1, for every enable decrements by 1. When it reaches 0,
    212   // we tell the browser to enable fast termination.
    213   int sudden_termination_disables_;
    214 
    215   // If true, then a GetPlugins call is allowed to rescan the disk.
    216   bool plugin_refresh_allowed_;
    217 
    218   scoped_ptr<blink::WebIDBFactory> web_idb_factory_;
    219 
    220   scoped_ptr<blink::WebBlobRegistry> blob_registry_;
    221 
    222   WebPublicSuffixListImpl public_suffix_list_;
    223 
    224   scoped_ptr<DeviceLightEventPump> device_light_event_pump_;
    225   scoped_ptr<DeviceMotionEventPump> device_motion_event_pump_;
    226   scoped_ptr<DeviceOrientationEventPump> device_orientation_event_pump_;
    227 
    228   scoped_refptr<base::MessageLoopProxy> child_thread_loop_;
    229   scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_;
    230   scoped_refptr<ThreadSafeSender> thread_safe_sender_;
    231   scoped_refptr<QuotaMessageFilter> quota_message_filter_;
    232 
    233   scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_;
    234 
    235   cc_blink::WebCompositorSupportImpl compositor_support_;
    236 
    237   scoped_ptr<blink::WebScrollbarBehavior> web_scrollbar_behavior_;
    238 
    239   scoped_ptr<BatteryStatusDispatcher> battery_status_dispatcher_;
    240 
    241   IDMap<PlatformEventObserverBase, IDMapOwnPointer> platform_event_observers_;
    242 
    243   DISALLOW_COPY_AND_ASSIGN(RendererWebKitPlatformSupportImpl);
    244 };
    245 
    246 }  // namespace content
    247 
    248 #endif  // CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_
    249