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 "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
16 #include "third_party/WebKit/public/platform/WebIDBFactory.h"
17 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
20 class MessageLoopProxy
;
24 class ContextProvider
;
28 class SyncMessageFilter
;
32 class WebBatteryStatus
;
33 class WebDeviceMotionData
;
34 class WebDeviceOrientationData
;
35 class WebGraphicsContext3DProvider
;
39 class BatteryStatusDispatcher
;
40 class DeviceLightEventPump
;
41 class DeviceMotionEventPump
;
42 class DeviceOrientationEventPump
;
43 class PlatformEventObserverBase
;
44 class QuotaMessageFilter
;
45 class RendererClipboardClient
;
47 class ThreadSafeSender
;
48 class WebClipboardImpl
;
49 class WebDatabaseObserverImpl
;
50 class WebFileSystemImpl
;
52 class CONTENT_EXPORT RendererBlinkPlatformImpl
: public BlinkPlatformImpl
{
54 RendererBlinkPlatformImpl();
55 virtual ~RendererBlinkPlatformImpl();
57 void set_plugin_refresh_allowed(bool plugin_refresh_allowed
) {
58 plugin_refresh_allowed_
= plugin_refresh_allowed
;
61 virtual blink::WebClipboard
* clipboard();
62 virtual blink::WebMimeRegistry
* mimeRegistry();
63 virtual blink::WebFileUtilities
* fileUtilities();
64 virtual blink::WebSandboxSupport
* sandboxSupport();
65 virtual blink::WebCookieJar
* cookieJar();
66 virtual blink::WebThemeEngine
* themeEngine();
67 virtual blink::WebSpeechSynthesizer
* createSpeechSynthesizer(
68 blink::WebSpeechSynthesizerClient
* client
);
69 virtual bool sandboxEnabled();
70 virtual unsigned long long visitedLinkHash(
71 const char* canonicalURL
, size_t length
);
72 virtual bool isLinkVisited(unsigned long long linkHash
);
73 virtual void createMessageChannel(blink::WebMessagePortChannel
** channel1
,
74 blink::WebMessagePortChannel
** channel2
);
75 virtual blink::WebPrescientNetworking
* prescientNetworking();
76 virtual void cacheMetadata(
77 const blink::WebURL
&, double, const char*, size_t);
78 virtual blink::WebString
defaultLocale();
79 virtual void suddenTerminationChanged(bool enabled
);
80 virtual blink::WebStorageNamespace
* createLocalStorageNamespace();
81 virtual blink::Platform::FileHandle
databaseOpenFile(
82 const blink::WebString
& vfs_file_name
, int desired_flags
);
83 virtual int databaseDeleteFile(const blink::WebString
& vfs_file_name
,
85 virtual long databaseGetFileAttributes(
86 const blink::WebString
& vfs_file_name
);
87 virtual long long databaseGetFileSize(
88 const blink::WebString
& vfs_file_name
);
89 virtual long long databaseGetSpaceAvailableForOrigin(
90 const blink::WebString
& origin_identifier
);
91 virtual blink::WebString
signedPublicKeyAndChallengeString(
92 unsigned key_size_index
,
93 const blink::WebString
& challenge
,
94 const blink::WebURL
& url
);
95 virtual void getPluginList(bool refresh
,
96 blink::WebPluginListBuilder
* builder
);
97 virtual blink::WebPublicSuffixList
* publicSuffixList();
98 virtual void screenColorProfile(blink::WebVector
<char>* to_profile
);
99 virtual blink::WebScrollbarBehavior
* scrollbarBehavior();
100 virtual blink::WebIDBFactory
* idbFactory();
101 virtual blink::WebFileSystem
* fileSystem();
102 virtual bool canAccelerate2dCanvas();
103 virtual bool isThreadedCompositingEnabled();
104 virtual double audioHardwareSampleRate();
105 virtual size_t audioHardwareBufferSize();
106 virtual unsigned audioHardwareOutputChannels();
107 virtual blink::WebDatabaseObserver
* databaseObserver();
109 virtual blink::WebAudioDevice
* createAudioDevice(
110 size_t buffer_size
, unsigned input_channels
, unsigned channels
,
111 double sample_rate
, blink::WebAudioDevice::RenderCallback
* callback
,
112 const blink::WebString
& input_device_id
);
114 virtual bool loadAudioResource(
115 blink::WebAudioBus
* destination_bus
, const char* audio_file_data
,
118 virtual blink::WebMIDIAccessor
*
119 createMIDIAccessor(blink::WebMIDIAccessorClient
* client
);
121 virtual blink::WebBlobRegistry
* blobRegistry();
122 virtual void sampleGamepads(blink::WebGamepads
&);
123 virtual blink::WebRTCPeerConnectionHandler
* createRTCPeerConnectionHandler(
124 blink::WebRTCPeerConnectionHandlerClient
* client
);
125 virtual blink::WebMediaStreamCenter
* createMediaStreamCenter(
126 blink::WebMediaStreamCenterClient
* client
);
127 virtual bool processMemorySizesInBytes(
128 size_t* private_bytes
, size_t* shared_bytes
);
129 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
130 const blink::WebGraphicsContext3D::Attributes
& attributes
);
131 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
132 const blink::WebGraphicsContext3D::Attributes
& attributes
,
133 blink::WebGraphicsContext3D
* share_context
);
134 virtual blink::WebGraphicsContext3DProvider
*
135 createSharedOffscreenGraphicsContext3DProvider();
136 virtual blink::WebCompositorSupport
* compositorSupport();
137 virtual blink::WebString
convertIDNToUnicode(
138 const blink::WebString
& host
, const blink::WebString
& languages
);
139 virtual void startListening(blink::WebPlatformEventType
,
140 blink::WebPlatformEventListener
*);
141 virtual void stopListening(blink::WebPlatformEventType
);
142 virtual void queryStorageUsageAndQuota(
143 const blink::WebURL
& storage_partition
,
144 blink::WebStorageQuotaType
,
145 blink::WebStorageQuotaCallbacks
);
146 virtual void vibrate(unsigned int milliseconds
);
147 virtual void cancelVibration();
149 // Set the PlatformEventObserverBase in |platform_event_observers_| associated
150 // with |type| to |observer|. If there was already an observer associated to
151 // the given |type|, it will be replaced.
152 // Note that |observer| will be owned by this object after the call.
153 void SetPlatformEventObserverForTesting(
154 blink::WebPlatformEventType type
,
155 scoped_ptr
<PlatformEventObserverBase
> observer
);
157 // Disables the WebSandboxSupport implementation for testing.
158 // Tests that do not set up a full sandbox environment should call
159 // SetSandboxEnabledForTesting(false) _before_ creating any instances
160 // of this class, to ensure that we don't attempt to use sandbox-related
161 // file descriptors or other resources.
163 // Returns the previous |enable| value.
164 static bool SetSandboxEnabledForTesting(bool enable
);
166 // Set a double to return when setDeviceLightListener is invoked.
167 static void SetMockDeviceLightDataForTesting(double data
);
168 // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked.
169 static void SetMockDeviceMotionDataForTesting(
170 const blink::WebDeviceMotionData
& data
);
171 // Set WebDeviceOrientationData to return when setDeviceOrientationListener
173 static void SetMockDeviceOrientationDataForTesting(
174 const blink::WebDeviceOrientationData
& data
);
176 // Notifies blink::WebBatteryStatusListener that battery status has changed.
177 void MockBatteryStatusChangedForTesting(
178 const blink::WebBatteryStatus
& status
);
180 WebDatabaseObserverImpl
* web_database_observer_impl() {
181 return web_database_observer_impl_
.get();
185 bool CheckPreparsedJsCachingEnabled() const;
187 // Factory that takes a type and return PlatformEventObserverBase that matches
189 static PlatformEventObserverBase
* CreatePlatformEventObserverFromType(
190 blink::WebPlatformEventType type
);
192 // Use the data previously set via SetMockDevice...DataForTesting() and send
193 // them to the registered listener.
194 void SendFakeDeviceEventDataForTesting(blink::WebPlatformEventType type
);
196 scoped_ptr
<RendererClipboardClient
> clipboard_client_
;
197 scoped_ptr
<WebClipboardImpl
> clipboard_
;
200 scoped_ptr
<FileUtilities
> file_utilities_
;
203 scoped_ptr
<MimeRegistry
> mime_registry_
;
205 class SandboxSupport
;
206 scoped_ptr
<SandboxSupport
> sandbox_support_
;
208 // This counter keeps track of the number of times sudden termination is
209 // enabled or disabled. It starts at 0 (enabled) and for every disable
210 // increments by 1, for every enable decrements by 1. When it reaches 0,
211 // we tell the browser to enable fast termination.
212 int sudden_termination_disables_
;
214 // If true, then a GetPlugins call is allowed to rescan the disk.
215 bool plugin_refresh_allowed_
;
217 scoped_ptr
<blink::WebIDBFactory
> web_idb_factory_
;
219 scoped_ptr
<blink::WebBlobRegistry
> blob_registry_
;
221 WebPublicSuffixListImpl public_suffix_list_
;
223 scoped_ptr
<DeviceLightEventPump
> device_light_event_pump_
;
224 scoped_ptr
<DeviceMotionEventPump
> device_motion_event_pump_
;
225 scoped_ptr
<DeviceOrientationEventPump
> device_orientation_event_pump_
;
227 scoped_refptr
<base::MessageLoopProxy
> child_thread_loop_
;
228 scoped_refptr
<IPC::SyncMessageFilter
> sync_message_filter_
;
229 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
230 scoped_refptr
<QuotaMessageFilter
> quota_message_filter_
;
232 scoped_ptr
<WebDatabaseObserverImpl
> web_database_observer_impl_
;
234 cc_blink::WebCompositorSupportImpl compositor_support_
;
236 scoped_ptr
<blink::WebScrollbarBehavior
> web_scrollbar_behavior_
;
238 scoped_ptr
<BatteryStatusDispatcher
> battery_status_dispatcher_
;
240 IDMap
<PlatformEventObserverBase
, IDMapOwnPointer
> platform_event_observers_
;
242 DISALLOW_COPY_AND_ASSIGN(RendererBlinkPlatformImpl
);
245 } // namespace content
247 #endif // CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_