| 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/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/metrics/stats_counters.h" | 9 #include "base/metrics/stats_counters.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { | 334 WebKit::WebString TestWebKitPlatformSupport::defaultLocale() { |
| 335 return ASCIIToUTF16("en-US"); | 335 return ASCIIToUTF16("en-US"); |
| 336 } | 336 } |
| 337 | 337 |
| 338 WebKit::WebStorageNamespace* | 338 WebKit::WebStorageNamespace* |
| 339 TestWebKitPlatformSupport::createLocalStorageNamespace( | 339 TestWebKitPlatformSupport::createLocalStorageNamespace( |
| 340 const WebKit::WebString& path, unsigned quota) { | 340 const WebKit::WebString& path, unsigned quota) { |
| 341 return dom_storage_system_.CreateLocalStorageNamespace(); | 341 return dom_storage_system_.CreateLocalStorageNamespace(); |
| 342 } | 342 } |
| 343 | 343 |
| 344 // Wrap a WebKit::WebIDBFactory to rewrite the data directory to | |
| 345 // a scoped temp directory. In multiprocess Chromium this is rewritten | |
| 346 // to a real profile directory during IPC. | |
| 347 class TestWebIDBFactory : public WebKit::WebIDBFactory { | |
| 348 public: | |
| 349 TestWebIDBFactory() { | |
| 350 // Create a new temp directory for Indexed DB storage, specific to this | |
| 351 // factory. If this fails, WebKit uses in-memory storage. | |
| 352 if (!indexed_db_dir_.CreateUniqueTempDir()) { | |
| 353 LOG(WARNING) << "Failed to create a temp dir for Indexed DB, " | |
| 354 "using in-memory storage."; | |
| 355 DCHECK(indexed_db_dir_.path().empty()); | |
| 356 } | |
| 357 data_dir_ = webkit_support::GetAbsoluteWebStringFromUTF8Path( | |
| 358 indexed_db_dir_.path().AsUTF8Unsafe()); | |
| 359 | |
| 360 // Lazily construct factory_ so that it gets allocated on the thread where | |
| 361 // it will be used. TestWebIDBFactory gets allocated on the main thread. | |
| 362 } | |
| 363 | |
| 364 virtual void getDatabaseNames(WebKit::WebIDBCallbacks* callbacks, | |
| 365 const WebKit::WebSecurityOrigin& origin, | |
| 366 WebKit::WebFrame* frame, | |
| 367 const WebString& dataDir) { | |
| 368 EnsureFactory(); | |
| 369 factory_->getDatabaseNames(callbacks, origin, frame, | |
| 370 dataDir.isEmpty() ? data_dir_ : dataDir); | |
| 371 } | |
| 372 | |
| 373 virtual void open(const WebString& name, | |
| 374 long long version, | |
| 375 long long transaction_id, | |
| 376 WebKit::WebIDBCallbacks* callbacks, | |
| 377 WebKit::WebIDBDatabaseCallbacks* databaseCallbacks, | |
| 378 const WebKit::WebSecurityOrigin& origin, | |
| 379 WebKit::WebFrame* frame, | |
| 380 const WebString& dataDir) { | |
| 381 EnsureFactory(); | |
| 382 factory_->open(name, version, transaction_id, callbacks, | |
| 383 databaseCallbacks, origin, frame, | |
| 384 dataDir.isEmpty() ? data_dir_ : dataDir); | |
| 385 } | |
| 386 | |
| 387 virtual void deleteDatabase(const WebString& name, | |
| 388 WebKit::WebIDBCallbacks* callbacks, | |
| 389 const WebKit::WebSecurityOrigin& origin, | |
| 390 WebKit::WebFrame* frame, | |
| 391 const WebString& dataDir) { | |
| 392 EnsureFactory(); | |
| 393 factory_->deleteDatabase(name, callbacks, origin, frame, | |
| 394 dataDir.isEmpty() ? data_dir_ : dataDir); | |
| 395 } | |
| 396 private: | |
| 397 void EnsureFactory() { | |
| 398 if (!factory_) | |
| 399 factory_.reset(WebKit::WebIDBFactory::create()); | |
| 400 } | |
| 401 | |
| 402 scoped_ptr<WebIDBFactory> factory_; | |
| 403 base::ScopedTempDir indexed_db_dir_; | |
| 404 WebString data_dir_; | |
| 405 }; | |
| 406 | |
| 407 WebKit::WebIDBFactory* TestWebKitPlatformSupport::idbFactory() { | |
| 408 return new TestWebIDBFactory(); | |
| 409 } | |
| 410 | |
| 411 #if defined(OS_WIN) || defined(OS_MACOSX) | 344 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 412 void TestWebKitPlatformSupport::SetThemeEngine(WebKit::WebThemeEngine* engine) { | 345 void TestWebKitPlatformSupport::SetThemeEngine(WebKit::WebThemeEngine* engine) { |
| 413 active_theme_engine_ = engine ? | 346 active_theme_engine_ = engine ? |
| 414 engine : WebKitPlatformSupportImpl::themeEngine(); | 347 engine : WebKitPlatformSupportImpl::themeEngine(); |
| 415 } | 348 } |
| 416 | 349 |
| 417 WebKit::WebThemeEngine* TestWebKitPlatformSupport::themeEngine() { | 350 WebKit::WebThemeEngine* TestWebKitPlatformSupport::themeEngine() { |
| 418 return active_theme_engine_; | 351 return active_theme_engine_; |
| 419 } | 352 } |
| 420 #endif | 353 #endif |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 return 0; | 537 return 0; |
| 605 } | 538 } |
| 606 | 539 |
| 607 WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve( | 540 WebKit::WebGestureCurve* TestWebKitPlatformSupport::createFlingAnimationCurve( |
| 608 int device_source, | 541 int device_source, |
| 609 const WebKit::WebFloatPoint& velocity, | 542 const WebKit::WebFloatPoint& velocity, |
| 610 const WebKit::WebSize& cumulative_scroll) { | 543 const WebKit::WebSize& cumulative_scroll) { |
| 611 // Caller will retain and release. | 544 // Caller will retain and release. |
| 612 return new WebGestureCurveMock(velocity, cumulative_scroll); | 545 return new WebGestureCurveMock(velocity, cumulative_scroll); |
| 613 } | 546 } |
| OLD | NEW |