summaryrefslogtreecommitdiffstats
path: root/content/renderer/renderer_blink_platform_impl.h
blob: c78d484b6b5443ccf3d9cdb69c325b8ec4ad1178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_
#define CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_

#include <stddef.h>
#include <stdint.h>

#include "base/compiler_specific.h"
#include "base/id_map.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "cc/blink/web_compositor_support_impl.h"
#include "content/child/blink_platform_impl.h"
#include "content/common/content_export.h"
#include "content/renderer/origin_trials/web_trial_token_validator_impl.h"
#include "content/renderer/webpublicsuffixlist_impl.h"
#include "device/vibration/vibration_manager.mojom.h"
#include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
#include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBFactory.h"
#include "third_party/WebKit/public/platform/modules/screen_orientation/WebScreenOrientationType.h"

namespace cc {
class ContextProvider;
}

namespace IPC {
class SyncMessageFilter;
}

namespace blink {
class WebCanvasCaptureHandler;
class WebDeviceMotionData;
class WebDeviceOrientationData;
class WebGraphicsContext3DProvider;
class WebMediaPlayer;
class WebMediaRecorderHandler;
class WebMediaStream;
class WebSecurityOrigin;
class WebServiceWorkerCacheStorage;
}

namespace scheduler {
class RendererScheduler;
class WebThreadImplForRendererScheduler;
}

namespace content {
class DeviceLightEventPump;
class DeviceMotionEventPump;
class DeviceOrientationEventPump;
class LocalStorageCachedAreas;
class PlatformEventObserverBase;
class QuotaMessageFilter;
class RendererClipboardDelegate;
class RenderView;
class ThreadSafeSender;
class WebClipboardImpl;
class WebDatabaseObserverImpl;
class WebFileSystemImpl;

class CONTENT_EXPORT RendererBlinkPlatformImpl : public BlinkPlatformImpl {
 public:
  explicit RendererBlinkPlatformImpl(
      scheduler::RendererScheduler* renderer_scheduler);
  ~RendererBlinkPlatformImpl() override;

  // Shutdown must be called just prior to shutting down blink.
  void Shutdown();

  void set_plugin_refresh_allowed(bool plugin_refresh_allowed) {
    plugin_refresh_allowed_ = plugin_refresh_allowed;
  }
  // Platform methods:
  blink::WebClipboard* clipboard() override;
  blink::WebMimeRegistry* mimeRegistry() override;
  blink::WebFileUtilities* fileUtilities() override;
  blink::WebSandboxSupport* sandboxSupport() override;
  blink::WebCookieJar* cookieJar() override;
  blink::WebThemeEngine* themeEngine() override;
  blink::WebSpeechSynthesizer* createSpeechSynthesizer(
      blink::WebSpeechSynthesizerClient* client) override;
  virtual bool sandboxEnabled();
  unsigned long long visitedLinkHash(const char* canonicalURL,
                                     size_t length) override;
  bool isLinkVisited(unsigned long long linkHash) override;
  void createMessageChannel(blink::WebMessagePortChannel** channel1,
                            blink::WebMessagePortChannel** channel2) override;
  blink::WebPrescientNetworking* prescientNetworking() override;
  void cacheMetadata(const blink::WebURL&,
                     int64_t,
                     const char*,
                     size_t) override;
  blink::WebString defaultLocale() override;
  void suddenTerminationChanged(bool enabled) override;
  blink::WebStorageNamespace* createLocalStorageNamespace() override;
  blink::Platform::FileHandle databaseOpenFile(
      const blink::WebString& vfs_file_name,
      int desired_flags) override;
  int databaseDeleteFile(const blink::WebString& vfs_file_name,
                         bool sync_dir) override;
  long databaseGetFileAttributes(
      const blink::WebString& vfs_file_name) override;
  long long databaseGetFileSize(const blink::WebString& vfs_file_name) override;
  long long databaseGetSpaceAvailableForOrigin(
      const blink::WebString& origin_identifier) override;
  bool databaseSetFileSize(const blink::WebString& vfs_file_name,
                           long long size) override;
  blink::WebString signedPublicKeyAndChallengeString(
      unsigned key_size_index,
      const blink::WebString& challenge,
      const blink::WebURL& url,
      const blink::WebURL& top_origin) override;
  void getPluginList(bool refresh,
                     blink::WebPluginListBuilder* builder) override;
  blink::WebPublicSuffixList* publicSuffixList() override;
  void screenColorProfile(blink::WebVector<char>* to_profile) override;
  blink::WebScrollbarBehavior* scrollbarBehavior() override;
  blink::WebIDBFactory* idbFactory() override;
  blink::WebServiceWorkerCacheStorage* cacheStorage(
      const blink::WebSecurityOrigin& security_origin) override;
  blink::WebFileSystem* fileSystem() override;
  bool canAccelerate2dCanvas() override;
  bool isThreadedCompositingEnabled() override;
  bool isThreadedAnimationEnabled() override;
  double audioHardwareSampleRate() override;
  size_t audioHardwareBufferSize() override;
  unsigned audioHardwareOutputChannels() override;
  blink::WebDatabaseObserver* databaseObserver() override;

  blink::WebAudioDevice* createAudioDevice(
      size_t buffer_size,
      unsigned input_channels,
      unsigned channels,
      double sample_rate,
      blink::WebAudioDevice::RenderCallback* callback,
      const blink::WebString& input_device_id,
      const blink::WebSecurityOrigin& security_origin) override;

  bool loadAudioResource(blink::WebAudioBus* destination_bus,
                         const char* audio_file_data,
                         size_t data_size) override;

  blink::WebMIDIAccessor* createMIDIAccessor(
      blink::WebMIDIAccessorClient* client) override;

  blink::WebBlobRegistry* blobRegistry() override;
  void sampleGamepads(blink::WebGamepads&) override;
  blink::WebRTCPeerConnectionHandler* createRTCPeerConnectionHandler(
      blink::WebRTCPeerConnectionHandlerClient* client) override;
  blink::WebRTCCertificateGenerator* createRTCCertificateGenerator() override;
  blink::WebMediaRecorderHandler* createMediaRecorderHandler() override;
  blink::WebMediaStreamCenter* createMediaStreamCenter(
      blink::WebMediaStreamCenterClient* client) override;
  blink::WebCanvasCaptureHandler* createCanvasCaptureHandler(
      const blink::WebSize& size,
      double frame_rate,
      blink::WebMediaStreamTrack* track) override;
  void createHTMLVideoElementCapturer(
      blink::WebMediaStream* web_media_stream,
      blink::WebMediaPlayer* web_media_player) override;
  blink::WebGraphicsContext3DProvider* createOffscreenGraphicsContext3DProvider(
      const blink::WebGraphicsContext3D::Attributes& attributes,
      blink::WebGraphicsContext3DProvider* share_provider,
      blink::WebGraphicsContext3D::WebGraphicsInfo* gl_info) override;
  blink::WebGraphicsContext3DProvider*
  createSharedOffscreenGraphicsContext3DProvider() override;
  blink::WebCompositorSupport* compositorSupport() override;
  blink::WebString convertIDNToUnicode(
      const blink::WebString& host,
      const blink::WebString& languages) override;
  void connectToRemoteService(const char* name,
                              mojo::ScopedMessagePipeHandle handle) override;
  void startListening(blink::WebPlatformEventType,
                      blink::WebPlatformEventListener*) override;
  void stopListening(blink::WebPlatformEventType) override;
  void queryStorageUsageAndQuota(const blink::WebURL& storage_partition,
                                 blink::WebStorageQuotaType,
                                 blink::WebStorageQuotaCallbacks) override;
  void vibrate(unsigned int milliseconds) override;
  void cancelVibration() override;
  blink::WebThread* currentThread() override;
  void recordRappor(const char* metric,
                    const blink::WebString& sample) override;
  void recordRapporURL(const char* metric, const blink::WebURL& url) override;

  blink::WebTrialTokenValidator* trialTokenValidator() override;

  // Set the PlatformEventObserverBase in |platform_event_observers_| associated
  // with |type| to |observer|. If there was already an observer associated to
  // the given |type|, it will be replaced.
  // Note that |observer| will be owned by this object after the call.
  void SetPlatformEventObserverForTesting(
      blink::WebPlatformEventType type,
      scoped_ptr<PlatformEventObserverBase> observer);

  // Disables the WebSandboxSupport implementation for testing.
  // Tests that do not set up a full sandbox environment should call
  // SetSandboxEnabledForTesting(false) _before_ creating any instances
  // of this class, to ensure that we don't attempt to use sandbox-related
  // file descriptors or other resources.
  //
  // Returns the previous |enable| value.
  static bool SetSandboxEnabledForTesting(bool enable);

  //  Set a double to return when setDeviceLightListener is invoked.
  static void SetMockDeviceLightDataForTesting(double data);
  // Set WebDeviceMotionData to return when setDeviceMotionListener is invoked.
  static void SetMockDeviceMotionDataForTesting(
      const blink::WebDeviceMotionData& data);
  // Set WebDeviceOrientationData to return when setDeviceOrientationListener
  // is invoked.
  static void SetMockDeviceOrientationDataForTesting(
      const blink::WebDeviceOrientationData& data);

  WebDatabaseObserverImpl* web_database_observer_impl() {
    return web_database_observer_impl_.get();
  }

  blink::WebURLLoader* createURLLoader() override;

 private:
  bool CheckPreparsedJsCachingEnabled() const;

  // Factory that takes a type and return PlatformEventObserverBase that matches
  // it.
  static PlatformEventObserverBase* CreatePlatformEventObserverFromType(
      blink::WebPlatformEventType type);

  // Use the data previously set via SetMockDevice...DataForTesting() and send
  // them to the registered listener.
  void SendFakeDeviceEventDataForTesting(blink::WebPlatformEventType type);
  device::VibrationManagerPtr& GetConnectedVibrationManagerService();

  scoped_ptr<blink::WebThread> main_thread_;

  scoped_ptr<RendererClipboardDelegate> clipboard_delegate_;
  scoped_ptr<WebClipboardImpl> clipboard_;

  class FileUtilities;
  scoped_ptr<FileUtilities> file_utilities_;

  class MimeRegistry;
  scoped_ptr<MimeRegistry> mime_registry_;

#if !defined(OS_ANDROID) && !defined(OS_WIN)
  class SandboxSupport;
  scoped_ptr<SandboxSupport> sandbox_support_;
#endif

  // This counter keeps track of the number of times sudden termination is
  // enabled or disabled. It starts at 0 (enabled) and for every disable
  // increments by 1, for every enable decrements by 1. When it reaches 0,
  // we tell the browser to enable fast termination.
  int sudden_termination_disables_;

  // If true, then a GetPlugins call is allowed to rescan the disk.
  bool plugin_refresh_allowed_;

  scoped_ptr<blink::WebIDBFactory> web_idb_factory_;

  scoped_ptr<blink::WebBlobRegistry> blob_registry_;

  WebPublicSuffixListImpl public_suffix_list_;

  scoped_ptr<DeviceLightEventPump> device_light_event_pump_;
  scoped_ptr<DeviceMotionEventPump> device_motion_event_pump_;
  scoped_ptr<DeviceOrientationEventPump> device_orientation_event_pump_;

  scoped_refptr<base::SingleThreadTaskRunner> default_task_runner_;
  scoped_refptr<base::SingleThreadTaskRunner> loading_task_runner_;
  scoped_refptr<IPC::SyncMessageFilter> sync_message_filter_;
  scoped_refptr<ThreadSafeSender> thread_safe_sender_;
  scoped_refptr<QuotaMessageFilter> quota_message_filter_;

  scoped_ptr<WebDatabaseObserverImpl> web_database_observer_impl_;

  cc_blink::WebCompositorSupportImpl compositor_support_;

  scoped_ptr<blink::WebScrollbarBehavior> web_scrollbar_behavior_;

  // Handle to the Vibration mojo service.
  device::VibrationManagerPtr vibration_manager_;

  IDMap<PlatformEventObserverBase, IDMapOwnPointer> platform_event_observers_;

  scheduler::RendererScheduler* renderer_scheduler_;  // NOT OWNED

  WebTrialTokenValidatorImpl trial_token_validator_;

  scoped_ptr<LocalStorageCachedAreas> local_storage_cached_areas_;

  DISALLOW_COPY_AND_ASSIGN(RendererBlinkPlatformImpl);
};

}  // namespace content

#endif  // CONTENT_RENDERER_RENDERER_BLINK_PLATFORM_IMPL_H_