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/WebIDBFactory.h"
18 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
21 class MessageLoopProxy
;
25 class ContextProvider
;
29 class SyncMessageFilter
;
33 class WebBatteryStatus
;
34 class WebDeviceMotionData
;
35 class WebDeviceOrientationData
;
36 class WebGraphicsContext3DProvider
;
40 class BatteryStatusDispatcher
;
41 class DeviceLightEventPump
;
42 class DeviceMotionEventPump
;
43 class DeviceOrientationEventPump
;
44 class PlatformEventObserverBase
;
45 class QuotaMessageFilter
;
46 class RendererClipboardDelegate
;
47 class RendererScheduler
;
49 class ThreadSafeSender
;
50 class WebClipboardImpl
;
51 class WebDatabaseObserverImpl
;
52 class WebFileSystemImpl
;
53 class WebSchedulerImpl
;
55 class CONTENT_EXPORT RendererBlinkPlatformImpl
: public BlinkPlatformImpl
{
57 explicit RendererBlinkPlatformImpl(RendererScheduler
* renderer_scheduler
);
58 virtual ~RendererBlinkPlatformImpl();
60 void set_plugin_refresh_allowed(bool plugin_refresh_allowed
) {
61 plugin_refresh_allowed_
= plugin_refresh_allowed
;
64 virtual blink::WebClipboard
* clipboard();
65 virtual blink::WebMimeRegistry
* mimeRegistry();
66 virtual blink::WebFileUtilities
* fileUtilities();
67 virtual blink::WebSandboxSupport
* sandboxSupport();
68 virtual blink::WebCookieJar
* cookieJar();
69 virtual blink::WebThemeEngine
* themeEngine();
70 virtual blink::WebSpeechSynthesizer
* createSpeechSynthesizer(
71 blink::WebSpeechSynthesizerClient
* client
);
72 virtual bool sandboxEnabled();
73 virtual unsigned long long visitedLinkHash(
74 const char* canonicalURL
, size_t length
);
75 virtual bool isLinkVisited(unsigned long long linkHash
);
76 virtual void createMessageChannel(blink::WebMessagePortChannel
** channel1
,
77 blink::WebMessagePortChannel
** channel2
);
78 virtual blink::WebPrescientNetworking
* prescientNetworking();
79 virtual void cacheMetadata(
80 const blink::WebURL
&, double, 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
,
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 blink::WebString
signedPublicKeyAndChallengeString(
95 unsigned key_size_index
,
96 const blink::WebString
& challenge
,
97 const blink::WebURL
& url
);
98 virtual void getPluginList(bool refresh
,
99 blink::WebPluginListBuilder
* builder
);
100 virtual blink::WebPublicSuffixList
* publicSuffixList();
101 virtual void screenColorProfile(blink::WebVector
<char>* to_profile
);
102 virtual blink::WebScrollbarBehavior
* scrollbarBehavior();
103 virtual blink::WebIDBFactory
* idbFactory();
104 virtual blink::WebFileSystem
* fileSystem();
105 virtual bool canAccelerate2dCanvas();
106 virtual bool isThreadedCompositingEnabled();
107 virtual double audioHardwareSampleRate();
108 virtual size_t audioHardwareBufferSize();
109 virtual unsigned audioHardwareOutputChannels();
110 virtual blink::WebDatabaseObserver
* databaseObserver();
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
);
117 virtual bool loadAudioResource(
118 blink::WebAudioBus
* destination_bus
, const char* audio_file_data
,
121 virtual blink::WebMIDIAccessor
*
122 createMIDIAccessor(blink::WebMIDIAccessorClient
* client
);
124 virtual blink::WebBlobRegistry
* blobRegistry();
125 virtual void sampleGamepads(blink::WebGamepads
&);
126 virtual blink::WebRTCPeerConnectionHandler
* createRTCPeerConnectionHandler(
127 blink::WebRTCPeerConnectionHandlerClient
* client
);
128 virtual blink::WebMediaStreamCenter
* createMediaStreamCenter(
129 blink::WebMediaStreamCenterClient
* client
);
130 virtual bool processMemorySizesInBytes(
131 size_t* private_bytes
, size_t* shared_bytes
);
132 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
133 const blink::WebGraphicsContext3D::Attributes
& attributes
);
134 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
135 const blink::WebGraphicsContext3D::Attributes
& attributes
,
136 blink::WebGraphicsContext3D
* share_context
);
137 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
138 const blink::WebGraphicsContext3D::Attributes
& attributes
,
139 blink::WebGraphicsContext3D
* share_context
,
140 blink::WebGLInfo
* gl_info
);
141 virtual blink::WebGraphicsContext3DProvider
*
142 createSharedOffscreenGraphicsContext3DProvider();
143 virtual blink::WebCompositorSupport
* compositorSupport();
144 virtual blink::WebString
convertIDNToUnicode(
145 const blink::WebString
& host
, const blink::WebString
& languages
);
146 virtual void startListening(blink::WebPlatformEventType
,
147 blink::WebPlatformEventListener
*);
148 virtual void stopListening(blink::WebPlatformEventType
);
149 virtual void queryStorageUsageAndQuota(
150 const blink::WebURL
& storage_partition
,
151 blink::WebStorageQuotaType
,
152 blink::WebStorageQuotaCallbacks
);
153 virtual void vibrate(unsigned int milliseconds
);
154 virtual void cancelVibration();
155 virtual blink::WebScheduler
* scheduler();
157 // Set the PlatformEventObserverBase in |platform_event_observers_| associated
158 // with |type| to |observer|. If there was already an observer associated to
159 // the given |type|, it will be replaced.
160 // Note that |observer| will be owned by this object after the call.
161 void SetPlatformEventObserverForTesting(
162 blink::WebPlatformEventType type
,
163 scoped_ptr
<PlatformEventObserverBase
> observer
);
165 // Disables the WebSandboxSupport implementation for testing.
166 // Tests that do not set up a full sandbox environment should call
167 // SetSandboxEnabledForTesting(false) _before_ creating any instances
168 // of this class, to ensure that we don't attempt to use sandbox-related
169 // file descriptors or other resources.
171 // Returns the previous |enable| value.
172 static bool SetSandboxEnabledForTesting(bool enable
);
174 // Set a double to return when setDeviceLightListener is invoked.
175 static void SetMockDeviceLightDataForTesting(double data
);
176 // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked.
177 static void SetMockDeviceMotionDataForTesting(
178 const blink::WebDeviceMotionData
& data
);
179 // Set WebDeviceOrientationData to return when setDeviceOrientationListener
181 static void SetMockDeviceOrientationDataForTesting(
182 const blink::WebDeviceOrientationData
& data
);
184 // Notifies blink::WebBatteryStatusListener that battery status has changed.
185 void MockBatteryStatusChangedForTesting(
186 const blink::WebBatteryStatus
& status
);
188 WebDatabaseObserverImpl
* web_database_observer_impl() {
189 return web_database_observer_impl_
.get();
193 bool CheckPreparsedJsCachingEnabled() const;
195 // Factory that takes a type and return PlatformEventObserverBase that matches
197 static PlatformEventObserverBase
* CreatePlatformEventObserverFromType(
198 blink::WebPlatformEventType type
);
200 // Use the data previously set via SetMockDevice...DataForTesting() and send
201 // them to the registered listener.
202 void SendFakeDeviceEventDataForTesting(blink::WebPlatformEventType type
);
203 device::VibrationManagerPtr
& GetConnectedVibrationManagerService();
205 scoped_ptr
<WebSchedulerImpl
> web_scheduler_
;
207 scoped_ptr
<RendererClipboardDelegate
> clipboard_delegate_
;
208 scoped_ptr
<WebClipboardImpl
> clipboard_
;
211 scoped_ptr
<FileUtilities
> file_utilities_
;
214 scoped_ptr
<MimeRegistry
> mime_registry_
;
216 class SandboxSupport
;
217 scoped_ptr
<SandboxSupport
> sandbox_support_
;
219 // This counter keeps track of the number of times sudden termination is
220 // enabled or disabled. It starts at 0 (enabled) and for every disable
221 // increments by 1, for every enable decrements by 1. When it reaches 0,
222 // we tell the browser to enable fast termination.
223 int sudden_termination_disables_
;
225 // If true, then a GetPlugins call is allowed to rescan the disk.
226 bool plugin_refresh_allowed_
;
228 scoped_ptr
<blink::WebIDBFactory
> web_idb_factory_
;
230 scoped_ptr
<blink::WebBlobRegistry
> blob_registry_
;
232 WebPublicSuffixListImpl public_suffix_list_
;
234 scoped_ptr
<DeviceLightEventPump
> device_light_event_pump_
;
235 scoped_ptr
<DeviceMotionEventPump
> device_motion_event_pump_
;
236 scoped_ptr
<DeviceOrientationEventPump
> device_orientation_event_pump_
;
238 scoped_refptr
<base::SingleThreadTaskRunner
> default_task_runner_
;
239 scoped_refptr
<IPC::SyncMessageFilter
> sync_message_filter_
;
240 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
241 scoped_refptr
<QuotaMessageFilter
> quota_message_filter_
;
243 scoped_ptr
<WebDatabaseObserverImpl
> web_database_observer_impl_
;
245 cc_blink::WebCompositorSupportImpl compositor_support_
;
247 scoped_ptr
<blink::WebScrollbarBehavior
> web_scrollbar_behavior_
;
249 scoped_ptr
<BatteryStatusDispatcher
> battery_status_dispatcher_
;
251 // Handle to the Vibration mojo service.
252 device::VibrationManagerPtr vibration_manager_
;
254 IDMap
<PlatformEventObserverBase
, IDMapOwnPointer
> platform_event_observers_
;
256 DISALLOW_COPY_AND_ASSIGN(RendererBlinkPlatformImpl
);
259 } // namespace content
261 #endif // CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_