renderer_webkitplatformsupport_impl.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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.
4
5#ifndef CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_
6#define CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_
7
8#include "base/compiler_specific.h"
9#include "base/memory/scoped_ptr.h"
10#include "base/platform_file.h"
11#include "content/common/content_export.h"
12#include "content/common/webkitplatformsupport_impl.h"
13#include "third_party/WebKit/Source/Platform/chromium/public/WebGraphicsContext3D.h"
14#include "third_party/WebKit/Source/Platform/chromium/public/WebIDBFactory.h"
15#include "third_party/WebKit/Source/WebKit/chromium/public/WebSharedWorkerRepository.h"
16#include "webkit/renderer/compositor_bindings/web_compositor_support_impl.h"
17
18namespace cc {
19class ContextProvider;
20}
21
22namespace webkit_glue {
23class WebClipboardImpl;
24}
25
26namespace WebKit {
27class WebGraphicsContext3DProvider;
28}
29
30namespace content {
31class GamepadSharedMemoryReader;
32class RendererClipboardClient;
33class ThreadSafeSender;
34class WebFileSystemImpl;
35class WebSharedWorkerRepositoryImpl;
36
37class CONTENT_EXPORT RendererWebKitPlatformSupportImpl
38    : public WebKitPlatformSupportImpl {
39 public:
40  RendererWebKitPlatformSupportImpl();
41  virtual ~RendererWebKitPlatformSupportImpl();
42
43  void set_plugin_refresh_allowed(bool plugin_refresh_allowed) {
44    plugin_refresh_allowed_ = plugin_refresh_allowed;
45  }
46  // Platform methods:
47  virtual WebKit::WebClipboard* clipboard();
48  virtual WebKit::WebMimeRegistry* mimeRegistry();
49  virtual WebKit::WebFileUtilities* fileUtilities();
50  virtual WebKit::WebSandboxSupport* sandboxSupport();
51  virtual WebKit::WebCookieJar* cookieJar();
52  virtual WebKit::WebHyphenator* hyphenator();
53  virtual WebKit::WebThemeEngine* themeEngine();
54  virtual WebKit::WebSpeechSynthesizer* createSpeechSynthesizer(
55      WebKit::WebSpeechSynthesizerClient* client);
56  virtual bool sandboxEnabled();
57  virtual unsigned long long visitedLinkHash(
58      const char* canonicalURL, size_t length);
59  virtual bool isLinkVisited(unsigned long long linkHash);
60  virtual WebKit::WebMessagePortChannel* createMessagePortChannel();
61  virtual void prefetchHostName(const WebKit::WebString&);
62  virtual WebKit::WebPrescientNetworking* prescientNetworking();
63  virtual void cacheMetadata(
64      const WebKit::WebURL&, double, const char*, size_t);
65  virtual WebKit::WebString defaultLocale();
66  virtual void suddenTerminationChanged(bool enabled);
67  virtual WebKit::WebStorageNamespace* createLocalStorageNamespace(
68      const WebKit::WebString& path, unsigned quota);
69  virtual WebKit::Platform::FileHandle databaseOpenFile(
70      const WebKit::WebString& vfs_file_name, int desired_flags);
71  virtual int databaseDeleteFile(const WebKit::WebString& vfs_file_name,
72                                 bool sync_dir);
73  virtual long databaseGetFileAttributes(
74      const WebKit::WebString& vfs_file_name);
75  virtual long long databaseGetFileSize(
76      const WebKit::WebString& vfs_file_name);
77  virtual long long databaseGetSpaceAvailableForOrigin(
78      const WebKit::WebString& origin_identifier);
79  virtual WebKit::WebString signedPublicKeyAndChallengeString(
80      unsigned key_size_index,
81      const WebKit::WebString& challenge,
82      const WebKit::WebURL& url);
83  virtual void screenColorProfile(WebKit::WebVector<char>* to_profile);
84  virtual WebKit::WebIDBFactory* idbFactory();
85  virtual WebKit::WebFileSystem* fileSystem();
86  virtual WebKit::WebSharedWorkerRepository* sharedWorkerRepository();
87  virtual bool canAccelerate2dCanvas();
88  virtual bool isThreadedCompositingEnabled();
89  virtual double audioHardwareSampleRate();
90  virtual size_t audioHardwareBufferSize();
91  virtual unsigned audioHardwareOutputChannels();
92
93  // TODO(crogers): remove deprecated API as soon as WebKit calls new API.
94  virtual WebKit::WebAudioDevice* createAudioDevice(
95      size_t buffer_size, unsigned channels, double sample_rate,
96      WebKit::WebAudioDevice::RenderCallback* callback);
97  // TODO(crogers): remove deprecated API as soon as WebKit calls new API.
98  virtual WebKit::WebAudioDevice* createAudioDevice(
99      size_t buffer_size, unsigned input_channels, unsigned channels,
100      double sample_rate, WebKit::WebAudioDevice::RenderCallback* callback);
101
102  virtual WebKit::WebAudioDevice* createAudioDevice(
103      size_t buffer_size, unsigned input_channels, unsigned channels,
104      double sample_rate, WebKit::WebAudioDevice::RenderCallback* callback,
105      const WebKit::WebString& input_device_id);
106
107  virtual WebKit::WebBlobRegistry* blobRegistry();
108  virtual void sampleGamepads(WebKit::WebGamepads&);
109  virtual WebKit::WebString userAgent(const WebKit::WebURL& url);
110  virtual void GetPlugins(bool refresh,
111                          std::vector<webkit::WebPluginInfo>* plugins) OVERRIDE;
112  virtual WebKit::WebRTCPeerConnectionHandler* createRTCPeerConnectionHandler(
113      WebKit::WebRTCPeerConnectionHandlerClient* client);
114  virtual WebKit::WebMediaStreamCenter* createMediaStreamCenter(
115      WebKit::WebMediaStreamCenterClient* client);
116  virtual bool processMemorySizesInBytes(
117      size_t* private_bytes, size_t* shared_bytes);
118  virtual WebKit::WebGraphicsContext3D* createOffscreenGraphicsContext3D(
119      const WebKit::WebGraphicsContext3D::Attributes& attributes);
120  virtual WebKit::WebGraphicsContext3DProvider*
121      createSharedOffscreenGraphicsContext3DProvider();
122  virtual WebKit::WebCompositorSupport* compositorSupport();
123
124  // Disables the WebSandboxSupport implementation for testing.
125  // Tests that do not set up a full sandbox environment should call
126  // SetSandboxEnabledForTesting(false) _before_ creating any instances
127  // of this class, to ensure that we don't attempt to use sandbox-related
128  // file descriptors or other resources.
129  //
130  // Returns the previous |enable| value.
131  static bool SetSandboxEnabledForTesting(bool enable);
132
133  // Set WebGamepads to return when sampleGamepads() is invoked.
134  static void SetMockGamepadsForTesting(const WebKit::WebGamepads& pads);
135
136 private:
137  bool CheckPreparsedJsCachingEnabled() const;
138
139  scoped_ptr<RendererClipboardClient> clipboard_client_;
140  scoped_ptr<webkit_glue::WebClipboardImpl> clipboard_;
141
142  class FileUtilities;
143  scoped_ptr<FileUtilities> file_utilities_;
144
145  class MimeRegistry;
146  scoped_ptr<MimeRegistry> mime_registry_;
147
148  class SandboxSupport;
149  scoped_ptr<SandboxSupport> sandbox_support_;
150
151  class Hyphenator;
152  scoped_ptr<Hyphenator> hyphenator_;
153
154  // This counter keeps track of the number of times sudden termination is
155  // enabled or disabled. It starts at 0 (enabled) and for every disable
156  // increments by 1, for every enable decrements by 1. When it reaches 0,
157  // we tell the browser to enable fast termination.
158  int sudden_termination_disables_;
159
160  // If true, then a GetPlugins call is allowed to rescan the disk.
161  bool plugin_refresh_allowed_;
162
163  // Implementation of the WebSharedWorkerRepository APIs (provides an interface
164  // to WorkerService on the browser thread.
165  scoped_ptr<WebSharedWorkerRepositoryImpl> shared_worker_repository_;
166
167  scoped_ptr<WebKit::WebIDBFactory> web_idb_factory_;
168
169  scoped_ptr<WebFileSystemImpl> web_file_system_;
170
171  scoped_ptr<WebKit::WebBlobRegistry> blob_registry_;
172
173  scoped_ptr<GamepadSharedMemoryReader> gamepad_shared_memory_reader_;
174
175  scoped_refptr<ThreadSafeSender> thread_safe_sender_;
176
177  scoped_refptr<cc::ContextProvider> shared_offscreen_context_;
178
179  webkit::WebCompositorSupportImpl compositor_support_;
180};
181
182}  // namespace content
183
184#endif  // CONTENT_RENDERER_RENDERER_WEBKITPLATFORMSUPPORT_IMPL_H_
185