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