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