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