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_WEBKITPLATFORMSUPPORT_IMPL_H_
6 #define CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_
8 #include "base/compiler_specific.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/platform_file.h"
11 #include "content/child/blink_platform_impl.h"
12 #include "content/common/content_export.h"
13 #include "content/renderer/webpublicsuffixlist_impl.h"
14 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
15 #include "third_party/WebKit/public/platform/WebIDBFactory.h"
16 #include "third_party/WebKit/public/platform/WebScreenOrientationType.h"
17 #include "webkit/renderer/compositor_bindings/web_compositor_support_impl.h"
20 class MessageLoopProxy
;
24 class ContextProvider
;
28 class SyncMessageFilter
;
32 class WebDeviceMotionData
;
33 class WebDeviceOrientationData
;
34 class WebGraphicsContext3DProvider
;
35 class WebScreenOrientationListener
;
39 class DeviceMotionEventPump
;
40 class DeviceOrientationEventPump
;
41 class QuotaMessageFilter
;
42 class RendererClipboardClient
;
43 class ScreenOrientationDispatcher
;
44 class ThreadSafeSender
;
45 class WebClipboardImpl
;
46 class WebDatabaseObserverImpl
;
47 class WebFileSystemImpl
;
49 class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
50 : public BlinkPlatformImpl
{
52 RendererWebKitPlatformSupportImpl();
53 virtual ~RendererWebKitPlatformSupportImpl();
55 void set_plugin_refresh_allowed(bool plugin_refresh_allowed
) {
56 plugin_refresh_allowed_
= plugin_refresh_allowed
;
59 virtual blink::WebClipboard
* clipboard();
60 virtual blink::WebMimeRegistry
* mimeRegistry();
61 virtual blink::WebFileUtilities
* fileUtilities();
62 virtual blink::WebSandboxSupport
* sandboxSupport();
63 virtual blink::WebCookieJar
* cookieJar();
64 virtual blink::WebThemeEngine
* themeEngine();
65 virtual blink::WebSpeechSynthesizer
* createSpeechSynthesizer(
66 blink::WebSpeechSynthesizerClient
* client
);
67 virtual bool sandboxEnabled();
68 virtual unsigned long long visitedLinkHash(
69 const char* canonicalURL
, size_t length
);
70 virtual bool isLinkVisited(unsigned long long linkHash
);
71 virtual void createMessageChannel(blink::WebMessagePortChannel
** channel1
,
72 blink::WebMessagePortChannel
** channel2
);
73 virtual blink::WebPrescientNetworking
* prescientNetworking();
74 virtual void cacheMetadata(
75 const blink::WebURL
&, double, const char*, size_t);
76 virtual blink::WebString
defaultLocale();
77 virtual void suddenTerminationChanged(bool enabled
);
78 virtual blink::WebStorageNamespace
* createLocalStorageNamespace();
79 virtual blink::Platform::FileHandle
databaseOpenFile(
80 const blink::WebString
& vfs_file_name
, int desired_flags
);
81 virtual int databaseDeleteFile(const blink::WebString
& vfs_file_name
,
83 virtual long databaseGetFileAttributes(
84 const blink::WebString
& vfs_file_name
);
85 virtual long long databaseGetFileSize(
86 const blink::WebString
& vfs_file_name
);
87 virtual long long databaseGetSpaceAvailableForOrigin(
88 const blink::WebString
& origin_identifier
);
89 virtual blink::WebString
signedPublicKeyAndChallengeString(
90 unsigned key_size_index
,
91 const blink::WebString
& challenge
,
92 const blink::WebURL
& url
);
93 virtual void getPluginList(bool refresh
,
94 blink::WebPluginListBuilder
* builder
);
95 virtual blink::WebPublicSuffixList
* publicSuffixList();
96 virtual void screenColorProfile(blink::WebVector
<char>* to_profile
);
97 virtual blink::WebScrollbarBehavior
* scrollbarBehavior();
98 virtual blink::WebIDBFactory
* idbFactory();
99 virtual blink::WebFileSystem
* fileSystem();
100 virtual bool canAccelerate2dCanvas();
101 virtual bool isThreadedCompositingEnabled();
102 virtual double audioHardwareSampleRate();
103 virtual size_t audioHardwareBufferSize();
104 virtual unsigned audioHardwareOutputChannels();
105 virtual blink::WebDatabaseObserver
* databaseObserver();
107 virtual blink::WebAudioDevice
* createAudioDevice(
108 size_t buffer_size
, unsigned input_channels
, unsigned channels
,
109 double sample_rate
, blink::WebAudioDevice::RenderCallback
* callback
,
110 const blink::WebString
& input_device_id
);
112 virtual bool loadAudioResource(
113 blink::WebAudioBus
* destination_bus
, const char* audio_file_data
,
116 virtual blink::WebMIDIAccessor
*
117 createMIDIAccessor(blink::WebMIDIAccessorClient
* client
);
119 virtual blink::WebBlobRegistry
* blobRegistry();
120 virtual void sampleGamepads(blink::WebGamepads
&) OVERRIDE
;
121 virtual void setGamepadListener(blink::WebGamepadListener
*) OVERRIDE
;
122 virtual blink::WebRTCPeerConnectionHandler
* createRTCPeerConnectionHandler(
123 blink::WebRTCPeerConnectionHandlerClient
* client
);
124 virtual blink::WebMediaStreamCenter
* createMediaStreamCenter(
125 blink::WebMediaStreamCenterClient
* client
);
126 virtual bool processMemorySizesInBytes(
127 size_t* private_bytes
, size_t* shared_bytes
);
128 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
129 const blink::WebGraphicsContext3D::Attributes
& attributes
);
130 virtual blink::WebGraphicsContext3D
* createOffscreenGraphicsContext3D(
131 const blink::WebGraphicsContext3D::Attributes
& attributes
,
132 blink::WebGraphicsContext3D
* share_context
);
133 virtual blink::WebGraphicsContext3DProvider
*
134 createSharedOffscreenGraphicsContext3DProvider();
135 virtual blink::WebCompositorSupport
* compositorSupport();
136 virtual blink::WebString
convertIDNToUnicode(
137 const blink::WebString
& host
, const blink::WebString
& languages
);
138 virtual void setDeviceMotionListener(
139 blink::WebDeviceMotionListener
* listener
) OVERRIDE
;
140 virtual void setDeviceOrientationListener(
141 blink::WebDeviceOrientationListener
* listener
) OVERRIDE
;
142 virtual void queryStorageUsageAndQuota(
143 const blink::WebURL
& storage_partition
,
144 blink::WebStorageQuotaType
,
145 blink::WebStorageQuotaCallbacks
) OVERRIDE
;
146 virtual void vibrate(unsigned int milliseconds
);
147 virtual void cancelVibration();
148 virtual void setScreenOrientationListener(
149 blink::WebScreenOrientationListener
*) OVERRIDE
;
150 virtual void lockOrientation(blink::WebScreenOrientationLockType
) OVERRIDE
;
151 virtual void unlockOrientation() OVERRIDE
;
153 // Disables the WebSandboxSupport implementation for testing.
154 // Tests that do not set up a full sandbox environment should call
155 // SetSandboxEnabledForTesting(false) _before_ creating any instances
156 // of this class, to ensure that we don't attempt to use sandbox-related
157 // file descriptors or other resources.
159 // Returns the previous |enable| value.
160 static bool SetSandboxEnabledForTesting(bool enable
);
162 // Set WebGamepads to return when sampleGamepads() is invoked.
163 static void SetMockGamepadsForTesting(const blink::WebGamepads
& pads
);
165 // Notifies blink::WebGamepadListener about a new gamepad if a listener
166 // has been set via setGamepadListener.
167 static void MockGamepadConnected(int index
, const blink::WebGamepad
& pad
);
169 // Notifies blink::WebGamepadListener that a gamepad has been disconnected if
170 // a listener has been set via setGamepadListener.
171 static void MockGamepadDisconnected(int index
, const blink::WebGamepad
& pad
);
173 // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked.
174 static void SetMockDeviceMotionDataForTesting(
175 const blink::WebDeviceMotionData
& data
);
176 // Set WebDeviceOrientationData to return when setDeviceOrientationListener
178 static void SetMockDeviceOrientationDataForTesting(
179 const blink::WebDeviceOrientationData
& data
);
180 // Forces the screen orientation for testing purposes.
181 static void SetMockScreenOrientationForTesting(
182 blink::WebScreenOrientationType
);
184 WebDatabaseObserverImpl
* web_database_observer_impl() {
185 return web_database_observer_impl_
.get();
189 bool CheckPreparsedJsCachingEnabled() const;
191 scoped_ptr
<RendererClipboardClient
> clipboard_client_
;
192 scoped_ptr
<WebClipboardImpl
> clipboard_
;
195 scoped_ptr
<FileUtilities
> file_utilities_
;
198 scoped_ptr
<MimeRegistry
> mime_registry_
;
200 class SandboxSupport
;
201 scoped_ptr
<SandboxSupport
> sandbox_support_
;
203 // This counter keeps track of the number of times sudden termination is
204 // enabled or disabled. It starts at 0 (enabled) and for every disable
205 // increments by 1, for every enable decrements by 1. When it reaches 0,
206 // we tell the browser to enable fast termination.
207 int sudden_termination_disables_
;
209 // If true, then a GetPlugins call is allowed to rescan the disk.
210 bool plugin_refresh_allowed_
;
212 scoped_ptr
<blink::WebIDBFactory
> web_idb_factory_
;
214 scoped_ptr
<blink::WebBlobRegistry
> blob_registry_
;
216 WebPublicSuffixListImpl public_suffix_list_
;
218 scoped_ptr
<DeviceMotionEventPump
> device_motion_event_pump_
;
219 scoped_ptr
<DeviceOrientationEventPump
> device_orientation_event_pump_
;
221 scoped_refptr
<base::MessageLoopProxy
> child_thread_loop_
;
222 scoped_refptr
<IPC::SyncMessageFilter
> sync_message_filter_
;
223 scoped_refptr
<ThreadSafeSender
> thread_safe_sender_
;
224 scoped_refptr
<QuotaMessageFilter
> quota_message_filter_
;
226 scoped_ptr
<WebDatabaseObserverImpl
> web_database_observer_impl_
;
228 webkit::WebCompositorSupportImpl compositor_support_
;
230 scoped_ptr
<ScreenOrientationDispatcher
> screen_orientation_dispatcher_
;
232 scoped_ptr
<blink::WebScrollbarBehavior
> web_scrollbar_behavior_
;
234 DISALLOW_COPY_AND_ASSIGN(RendererWebKitPlatformSupportImpl
);
237 } // namespace content
239 #endif // CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_