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