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