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 // Shutdown must be called just prior to shutting down blink.
65 void set_plugin_refresh_allowed(bool plugin_refresh_allowed
) {
66 plugin_refresh_allowed_
= plugin_refresh_allowed
;
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
,
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 bool isThreadedAnimationEnabled();
116 virtual double audioHardwareSampleRate();
117 virtual size_t audioHardwareBufferSize();
118 virtual unsigned audioHardwareOutputChannels();
119 virtual blink::WebDatabaseObserver
* databaseObserver();
121 virtual blink::WebAudioDevice
* createAudioDevice(
122 size_t buffer_size
, unsigned input_channels
, unsigned channels
,
123 double sample_rate
, blink::WebAudioDevice::RenderCallback
* callback
,
124 const blink::WebString
& input_device_id
);
126 virtual bool loadAudioResource(
127 blink::WebAudioBus
* destination_bus
, const char* audio_file_data
,
130 virtual blink::WebMIDIAccessor
*
131 createMIDIAccessor(blink::WebMIDIAccessorClient
* client
);
133 virtual blink::WebBlobRegistry
* blobRegistry();
134 virtual void sampleGamepads(blink::WebGamepads
&);
135 virtual blink::WebRTCPeerConnectionHandler
* createRTCPeerConnectionHandler(
136 blink::WebRTCPeerConnectionHandlerClient
* client
);
137 virtual blink::WebMediaRecorderHandler
* createMediaRecorderHandler();
138 virtual blink::WebMediaStreamCenter
* createMediaStreamCenter(
139 blink::WebMediaStreamCenterClient
* client
);
140 virtual bool processMemorySizesInBytes(
141 size_t* private_bytes
, size_t* shared_bytes
);
142 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
143 const blink::WebGraphicsContext3D::Attributes
& attributes
);
144 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
145 const blink::WebGraphicsContext3D::Attributes
& attributes
,
146 blink::WebGraphicsContext3D
* share_context
);
147 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
148 const blink::WebGraphicsContext3D::Attributes
& attributes
,
149 blink::WebGraphicsContext3D
* share_context
,
150 blink::WebGLInfo
* gl_info
);
151 virtual blink::WebGraphicsContext3DProvider
*
152 createSharedOffscreenGraphicsContext3DProvider();
153 virtual blink::WebCompositorSupport
* compositorSupport();
154 virtual blink::WebString
convertIDNToUnicode(
155 const blink::WebString
& host
, const blink::WebString
& languages
);
156 virtual void startListening(blink::WebPlatformEventType
,
157 blink::WebPlatformEventListener
*);
158 virtual void stopListening(blink::WebPlatformEventType
);
159 virtual void queryStorageUsageAndQuota(
160 const blink::WebURL
& storage_partition
,
161 blink::WebStorageQuotaType
,
162 blink::WebStorageQuotaCallbacks
);
163 virtual void vibrate(unsigned int milliseconds
);
164 virtual void cancelVibration();
165 virtual blink::WebThread
* currentThread();
166 virtual void recordRappor(const char* metric
, const blink::WebString
& sample
);
167 virtual void recordRapporURL(const char* metric
, const blink::WebURL
& url
);
169 // Set the PlatformEventObserverBase in |platform_event_observers_| associated
170 // with |type| to |observer|. If there was already an observer associated to
171 // the given |type|, it will be replaced.
172 // Note that |observer| will be owned by this object after the call.
173 void SetPlatformEventObserverForTesting(
174 blink::WebPlatformEventType type
,
175 scoped_ptr
<PlatformEventObserverBase
> observer
);
177 // Disables the WebSandboxSupport implementation for testing.
178 // Tests that do not set up a full sandbox environment should call
179 // SetSandboxEnabledForTesting(false) _before_ creating any instances
180 // of this class, to ensure that we don't attempt to use sandbox-related
181 // file descriptors or other resources.
183 // Returns the previous |enable| value.
184 static bool SetSandboxEnabledForTesting(bool enable
);
186 // Set a double to return when setDeviceLightListener is invoked.
187 static void SetMockDeviceLightDataForTesting(double data
);
188 // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked.
189 static void SetMockDeviceMotionDataForTesting(
190 const blink::WebDeviceMotionData
& data
);
191 // Set WebDeviceOrientationData to return when setDeviceOrientationListener
193 static void SetMockDeviceOrientationDataForTesting(
194 const blink::WebDeviceOrientationData
& data
);
196 // Notifies blink::WebBatteryStatusListener that battery status has changed.
197 void MockBatteryStatusChangedForTesting(
198 const blink::WebBatteryStatus
& status
);
200 WebDatabaseObserverImpl
* web_database_observer_impl() {
201 return web_database_observer_impl_
.get();
205 bool CheckPreparsedJsCachingEnabled() const;
207 // Factory that takes a type and return PlatformEventObserverBase that matches
209 static PlatformEventObserverBase
* CreatePlatformEventObserverFromType(
210 blink::WebPlatformEventType type
);
212 // Use the data previously set via SetMockDevice...DataForTesting() and send
213 // them to the registered listener.
214 void SendFakeDeviceEventDataForTesting(blink::WebPlatformEventType type
);
215 device::VibrationManagerPtr
& GetConnectedVibrationManagerService();
217 scoped_ptr
<scheduler::WebThreadImplForRendererScheduler
> main_thread_
;
219 scoped_ptr
<RendererClipboardDelegate
> clipboard_delegate_
;
220 scoped_ptr
<WebClipboardImpl
> clipboard_
;
223 scoped_ptr
<FileUtilities
> file_utilities_
;
226 scoped_ptr
<MimeRegistry
> mime_registry_
;
228 #if !defined(OS_ANDROID) && !defined(OS_WIN)
229 class SandboxSupport
;
230 scoped_ptr
<SandboxSupport
> sandbox_support_
;
233 // This counter keeps track of the number of times sudden termination is
234 // enabled or disabled. It starts at 0 (enabled) and for every disable
235 // increments by 1, for every enable decrements by 1. When it reaches 0,
236 // we tell the browser to enable fast termination.
237 int sudden_termination_disables_
;
239 // If true, then a GetPlugins call is allowed to rescan the disk.
240 bool plugin_refresh_allowed_
;
242 scoped_ptr
<blink::WebIDBFactory
> web_idb_factory_
;
244 scoped_ptr
<blink::WebBlobRegistry
> blob_registry_
;
246 WebPublicSuffixListImpl public_suffix_list_
;
248 scoped_ptr
<DeviceLightEventPump
> device_light_event_pump_
;
249 scoped_ptr
<DeviceMotionEventPump
> device_motion_event_pump_
;
250 scoped_ptr
<DeviceOrientationEventPump
> device_orientation_event_pump_
;
252 scoped_refptr
<base::SingleThreadTaskRunner
> default_task_runner_
;
253 scoped_refptr
<IPC::SyncMessageFilter
> sync_message_filter_
;
254 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
255 scoped_refptr
<QuotaMessageFilter
> quota_message_filter_
;
257 scoped_ptr
<WebDatabaseObserverImpl
> web_database_observer_impl_
;
259 cc_blink::WebCompositorSupportImpl compositor_support_
;
261 scoped_ptr
<blink::WebScrollbarBehavior
> web_scrollbar_behavior_
;
263 scoped_ptr
<BatteryStatusDispatcher
> battery_status_dispatcher_
;
265 // Handle to the Vibration mojo service.
266 device::VibrationManagerPtr vibration_manager_
;
268 IDMap
<PlatformEventObserverBase
, IDMapOwnPointer
> platform_event_observers_
;
270 DISALLOW_COPY_AND_ASSIGN(RendererBlinkPlatformImpl
);
273 } // namespace content
275 #endif // CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_