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