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 WEBKIT_SUPPORT_WEBKIT_SUPPORT_H_
6 #define WEBKIT_SUPPORT_WEBKIT_SUPPORT_H_
10 #include "base/basictypes.h"
11 #include "base/string16.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebReferrerPolicy.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgentClient.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSystem.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebGraphicsContext3D.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLRequest.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebVector.h"
19 #include "ui/base/keycodes/keyboard_codes.h"
22 class WebApplicationCacheHost
;
23 class WebApplicationCacheHostClient
;
24 class WebFileSystemCallbacks
;
27 class WebKitPlatformSupport
;
29 class WebMediaPlayerClient
;
31 class WebStorageNamespace
;
37 struct WebPluginParams
;
41 namespace webkit_media
{
42 class MediaStreamClient
;
45 // This package provides functions used by DumpRenderTree/chromium.
46 // DumpRenderTree/chromium uses some code in webkit/ of Chromium. In
47 // order to minimize the dependency from WebKit to Chromium, the
48 // following functions uses WebKit API classes as possible and hide
49 // implementation classes.
50 namespace webkit_support
{
52 // Initializes or terminates a test environment.
53 // |unit_test_mode| should be set to true when running in a TestSuite, in which
54 // case no AtExitManager is created and ICU is not initialized (as it is already
55 // done by the TestSuite).
56 // SetUpTestEnvironment() and SetUpTestEnvironmentForUnitTests() calls
57 // WebKit::initialize().
58 // TearDownTestEnvironment() calls WebKit::shutdown().
59 // SetUpTestEnvironmentForUnitTests() should be used when running in a
60 // TestSuite, in which case no AtExitManager is created and ICU is not
61 // initialized (as it is already done by the TestSuite).
62 void SetUpTestEnvironment();
63 void SetUpTestEnvironmentForUnitTests();
64 void SetUpTestEnvironment(WebKit::Platform
* shadow_platform_delegate
);
65 void SetUpTestEnvironmentForUnitTests(
66 WebKit::Platform
* shadow_platform_delegate
);
67 void TearDownTestEnvironment();
69 // Returns a pointer to a WebKitPlatformSupport implementation for
70 // DumpRenderTree. Needs to call SetUpTestEnvironment() before this.
71 // This returns a pointer to a static instance. Don't delete it.
72 WebKit::WebKitPlatformSupport
* GetWebKitPlatformSupport();
74 // This is used by WebFrameClient::createPlugin().
75 WebKit::WebPlugin
* CreateWebPlugin(WebKit::WebFrame
* frame
,
76 const WebKit::WebPluginParams
& params
);
78 // This is used by WebFrameClient::createMediaPlayer().
79 WebKit::WebMediaPlayer
* CreateMediaPlayer(
80 WebKit::WebFrame
* frame
,
81 const WebKit::WebURL
& url
,
82 WebKit::WebMediaPlayerClient
* client
,
83 webkit_media::MediaStreamClient
* media_stream_client
);
85 // This is used by WebFrameClient::createMediaPlayer().
86 WebKit::WebMediaPlayer
* CreateMediaPlayer(
87 WebKit::WebFrame
* frame
,
88 const WebKit::WebURL
& url
,
89 WebKit::WebMediaPlayerClient
* client
);
91 #if defined(OS_ANDROID)
92 void ReleaseMediaResources();
95 // This is used by WebFrameClient::createApplicationCacheHost().
96 WebKit::WebApplicationCacheHost
* CreateApplicationCacheHost(
97 WebKit::WebFrame
* frame
, WebKit::WebApplicationCacheHostClient
* client
);
99 // This is used by WebViewHost::createSessionStorageNamespace().
100 WebKit::WebStorageNamespace
* CreateSessionStorageNamespace(unsigned quota
);
102 // Returns the root directory of the WebKit code.
103 WebKit::WebString
GetWebKitRootDir();
105 enum GLBindingPreferences
{
107 GL_BINDING_SOFTWARE_RENDERER
109 void SetUpGLBindings(GLBindingPreferences
);
111 enum GraphicsContext3DImplementation
{
113 IN_PROCESS_COMMAND_BUFFER
115 // Registers which GraphicsContext3D Implementation to use.
116 void SetGraphicsContext3DImplementation(GraphicsContext3DImplementation
);
117 GraphicsContext3DImplementation
GetGraphicsContext3DImplementation();
119 WebKit::WebGraphicsContext3D
* CreateGraphicsContext3D(
120 const WebKit::WebGraphicsContext3D::Attributes
& attributes
,
121 WebKit::WebView
* web_view
);
123 // ------- URL load mocking.
124 // Registers the file at |file_path| to be served when |url| is requested.
125 // |response| is the response provided with the contents.
126 void RegisterMockedURL(const WebKit::WebURL
& url
,
127 const WebKit::WebURLResponse
& response
,
128 const WebKit::WebString
& file_path
);
130 // Registers the error to be returned when |url| is requested.
131 void RegisterMockedErrorURL(const WebKit::WebURL
& url
,
132 const WebKit::WebURLResponse
& response
,
133 const WebKit::WebURLError
& error
);
135 // Unregisters URLs so they are no longer mocked.
136 void UnregisterMockedURL(const WebKit::WebURL
& url
);
137 void UnregisterAllMockedURLs();
139 // Causes all pending asynchronous requests to be served. When this method
140 // returns all the pending requests have been processed.
141 void ServeAsynchronousMockedRequests();
143 // Returns the last request that handled by |ServeAsynchronousMockedRequests()|.
144 WebKit::WebURLRequest
GetLastHandledAsynchronousMockedRequest();
146 // Wrappers to minimize dependecy.
148 // -------- Debugging
149 bool BeingDebugged();
151 // -------- Message loop and task
153 // A wrapper for Chromium's Task class.
154 // The lifecycle is managed by webkit_support thus
155 // You shouldn't delete the object.
156 // Note that canceled object is just removed.
159 virtual ~TaskAdaptor() {}
160 virtual void Run() = 0;
163 void RunMessageLoop();
164 void QuitMessageLoop();
165 void QuitMessageLoopNow();
166 void RunAllPendingMessages();
167 void DispatchMessageLoop();
168 bool MessageLoopNestableTasksAllowed();
169 void MessageLoopSetNestableTasksAllowed(bool allowed
);
170 WebKit::WebDevToolsAgentClient::WebKitClientMessageLoop
*
171 CreateDevToolsMessageLoop();
172 void PostDelayedTask(void (*func
)(void*), void* context
, int64 delay_ms
);
174 void PostDelayedTask(TaskAdaptor
* task
, int64 delay_ms
);
176 // -------- File path and PathService
177 // Converts the specified path string to an absolute path in WebString.
178 // |utf8_path| is in UTF-8 encoding, not native multibyte string.
179 WebKit::WebString
GetAbsoluteWebStringFromUTF8Path(
180 const std::string
& utf8_path
);
182 // Create a WebURL from the specified string.
183 // If |path_or_url_in_nativemb| is a URL starting with scheme, this simply
184 // returns a WebURL for it. Otherwise, this returns a file:// URL.
185 WebKit::WebURL
CreateURLForPathOrURL(
186 const std::string
& path_or_url_in_nativemb
);
188 // Converts file:///tmp/LayoutTests URLs to the actual location on disk.
189 WebKit::WebURL
RewriteLayoutTestsURL(const std::string
& utf8_url
);
191 // Set the directory of specified file: URL as the current working directory.
192 bool SetCurrentDirectoryForFileURL(const WebKit::WebURL
& fileUrl
);
194 // Convert a file:/// URL to a base64 encoded data: URL.
195 WebKit::WebURL
LocalFileToDataURL(const WebKit::WebURL
& fileUrl
);
197 // Scoped temporary directories for use by webkit layout tests.
198 class ScopedTempDirectory
{
200 virtual ~ScopedTempDirectory() {}
201 virtual bool CreateUniqueTempDir() = 0;
202 virtual std::string
path() const = 0;
205 ScopedTempDirectory
* CreateScopedTempDirectory();
208 int64
GetCurrentTimeInMillisecond();
211 // A wrapper of net::EscapePath().
212 std::string
EscapePath(const std::string
& path
);
213 // Make an error description for layout tests.
214 std::string
MakeURLErrorDescription(const WebKit::WebURLError
& error
);
215 // Creates WebURLError for an aborted request.
216 WebKit::WebURLError
CreateCancelledError(const WebKit::WebURLRequest
& request
);
217 // Create "extra data" for a ResourceRequest required by Chrome's network stack.
218 WebKit::WebURLRequest::ExtraData
* CreateWebURLRequestExtraData(
219 WebKit::WebReferrerPolicy referrer_policy
);
222 void SetDatabaseQuota(int quota
);
223 void ClearAllDatabases();
226 void SetAcceptAllCookies(bool accept
);
229 #if defined(OS_WIN) || defined(OS_MACOSX)
230 void SetThemeEngine(WebKit::WebThemeEngine
* engine
);
231 WebKit::WebThemeEngine
* GetThemeEngine();
235 WebKit::WebURL
GetDevToolsPathAsURL();
238 void OpenFileSystem(WebKit::WebFrame
* frame
,
239 WebKit::WebFileSystem::Type type
,
242 WebKit::WebFileSystemCallbacks
* callbacks
);
243 void DeleteFileSystem(WebKit::WebFrame
* frame
,
244 WebKit::WebFileSystem::Type type
,
245 WebKit::WebFileSystemCallbacks
* callbacks
);
247 // Returns a filesystem ID for the newly created isolated filesystem.
248 WebKit::WebString
RegisterIsolatedFileSystem(
249 const WebKit::WebVector
<WebKit::WebString
>& filenames
);
251 // -------- Keyboard code
253 VKEY_LEFT
= ui::VKEY_LEFT
,
254 VKEY_RIGHT
= ui::VKEY_RIGHT
,
255 VKEY_UP
= ui::VKEY_UP
,
256 VKEY_DOWN
= ui::VKEY_DOWN
,
257 VKEY_RETURN
= ui::VKEY_RETURN
,
258 VKEY_INSERT
= ui::VKEY_INSERT
,
259 VKEY_DELETE
= ui::VKEY_DELETE
,
260 VKEY_PRIOR
= ui::VKEY_PRIOR
,
261 VKEY_NEXT
= ui::VKEY_NEXT
,
262 VKEY_HOME
= ui::VKEY_HOME
,
263 VKEY_END
= ui::VKEY_END
,
264 VKEY_SNAPSHOT
= ui::VKEY_SNAPSHOT
,
265 VKEY_F1
= ui::VKEY_F1
,
268 #if defined(TOOLKIT_GTK)
269 int NativeKeyCodeForWindowsKeyCode(int keycode
, bool shift
);
274 double GetForegroundTabTimerInterval();
278 void EnableWebCoreLogChannels(const std::string
& channels
);
282 void SetGamepadData(const WebKit::WebGamepads
& pads
);
284 } // namespace webkit_support
286 #endif // WEBKIT_SUPPORT_WEBKIT_SUPPORT_H_