OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "webkit/support/test_webkit_platform_support.h" | 5 #include "webkit/support/test_webkit_platform_support.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/metrics/stats_counters.h" | 8 #include "base/metrics/stats_counters.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
10 #include "base/scoped_temp_dir.h" | 10 #include "base/scoped_temp_dir.h" |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { | 317 WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { |
318 return ASCIIToUTF16("en-US"); | 318 return ASCIIToUTF16("en-US"); |
319 } | 319 } |
320 | 320 |
321 WebKit::WebStorageNamespace* | 321 WebKit::WebStorageNamespace* |
322 TestWebKitPlatformSupport::createLocalStorageNamespace( | 322 TestWebKitPlatformSupport::createLocalStorageNamespace( |
323 const WebKit::WebString& path, unsigned quota) { | 323 const WebKit::WebString& path, unsigned quota) { |
324 return dom_storage_system_.CreateLocalStorageNamespace(); | 324 return dom_storage_system_.CreateLocalStorageNamespace(); |
325 } | 325 } |
326 | 326 |
| 327 // Wrap a WebKit::WebIDBFactory to rewrite the data directory to |
| 328 // a scoped temp directory. In multiprocess Chromium this is rewritten |
| 329 // to a real profile directory during IPC. |
| 330 class TestWebIDBFactory : public WebKit::WebIDBFactory { |
| 331 public: |
| 332 TestWebIDBFactory() |
| 333 : factory_(WebKit::WebIDBFactory::create()) { |
| 334 // Create a new temp directory for Indexed DB storage, specific to this |
| 335 // factory. If this fails, WebKit uses in-memory storage. |
| 336 if (!indexed_db_dir_.CreateUniqueTempDir()) { |
| 337 LOG(WARNING) << "Failed to create a temp dir for Indexed DB, " |
| 338 "using in-memory storage."; |
| 339 DCHECK(indexed_db_dir_.path().empty()); |
| 340 } |
| 341 data_dir_ = webkit_support::GetAbsoluteWebStringFromUTF8Path( |
| 342 indexed_db_dir_.path().AsUTF8Unsafe()); |
| 343 } |
| 344 |
| 345 virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks, |
| 346 const WebKit::WebSecurityOrigin& origin, |
| 347 WebKit::WebFrame* frame, |
| 348 const WebString& dataDir) { |
| 349 factory_->getDatabaseNames(callbacks, origin, frame, |
| 350 dataDir.isEmpty() ? data_dir_ : dataDir); |
| 351 } |
| 352 |
| 353 virtual void open(const WebString& name, |
| 354 WebKit::WebIDBCallbacks* callbacks, |
| 355 const WebKit::WebSecurityOrigin& origin, |
| 356 WebKit::WebFrame* frame, |
| 357 const WebString& dataDir) { |
| 358 factory_->open(name, callbacks, origin, frame, |
| 359 dataDir.isEmpty() ? data_dir_ : dataDir); |
| 360 } |
| 361 |
| 362 virtual void deleteDatabase(const WebString& name, |
| 363 WebKit::WebIDBCallbacks* callbacks, |
| 364 const WebKit::WebSecurityOrigin& origin, |
| 365 WebKit::WebFrame* frame, |
| 366 const WebString& dataDir) { |
| 367 factory_->deleteDatabase(name, callbacks, origin, frame, |
| 368 dataDir.isEmpty() ? data_dir_ : dataDir); |
| 369 } |
| 370 private: |
| 371 scoped_ptr<WebIDBFactory> factory_; |
| 372 ScopedTempDir indexed_db_dir_; |
| 373 WebString data_dir_; |
| 374 }; |
| 375 |
327 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { | 376 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { |
328 return WebKit::WebIDBFactory::create(); | 377 return new TestWebIDBFactory(); |
329 } | 378 } |
330 | 379 |
331 void TestWebKitPlatformSupport::createIDBKeysFromSerializedValuesAndKeyPath( | 380 void TestWebKitPlatformSupport::createIDBKeysFromSerializedValuesAndKeyPath( |
332 const WebKit::WebVector<WebKit::WebSerializedScriptValue>& values, | 381 const WebKit::WebVector<WebKit::WebSerializedScriptValue>& values, |
333 const WebKit::WebIDBKeyPath& keyPath, | 382 const WebKit::WebIDBKeyPath& keyPath, |
334 WebKit::WebVector<WebKit::WebIDBKey>& keys_out) { | 383 WebKit::WebVector<WebKit::WebIDBKey>& keys_out) { |
335 WebKit::WebVector<WebKit::WebIDBKey> keys(values.size()); | 384 WebKit::WebVector<WebKit::WebIDBKey> keys(values.size()); |
336 for (size_t i = 0; i < values.size(); ++i) { | 385 for (size_t i = 0; i < values.size(); ++i) { |
337 keys[i] = WebKit::WebIDBKey::createFromValueAndKeyPath( | 386 keys[i] = WebKit::WebIDBKey::createFromValueAndKeyPath( |
338 values[i], keyPath); | 387 values[i], keyPath); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { | 490 const webkit_glue::ResourceLoaderBridge::RequestInfo& request_info) { |
442 return SimpleResourceLoaderBridge::Create(request_info); | 491 return SimpleResourceLoaderBridge::Create(request_info); |
443 } | 492 } |
444 | 493 |
445 webkit_glue::WebSocketStreamHandleBridge* | 494 webkit_glue::WebSocketStreamHandleBridge* |
446 TestWebKitPlatformSupport::CreateWebSocketBridge( | 495 TestWebKitPlatformSupport::CreateWebSocketBridge( |
447 WebKit::WebSocketStreamHandle* handle, | 496 WebKit::WebSocketStreamHandle* handle, |
448 webkit_glue::WebSocketStreamHandleDelegate* delegate) { | 497 webkit_glue::WebSocketStreamHandleDelegate* delegate) { |
449 return SimpleSocketStreamBridge::Create(handle, delegate); | 498 return SimpleSocketStreamBridge::Create(handle, delegate); |
450 } | 499 } |
OLD | NEW |