| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "chrome/browser/chromeos/extensions/wallpaper_private_api.h" | 5 #include "chrome/browser/chromeos/extensions/wallpaper_private_api.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
| 10 #include "ash/desktop_background/desktop_background_controller.h" | 10 #include "ash/desktop_background/desktop_background_controller.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/wm/mru_window_tracker.h" | 12 #include "ash/wm/mru_window_tracker.h" |
| 13 #include "ash/wm/window_state.h" | 13 #include "ash/wm/window_state.h" |
| 14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
| 15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 16 #include "base/file_util.h" | 16 #include "base/file_util.h" |
| 17 #include "base/files/file_enumerator.h" | 17 #include "base/files/file_enumerator.h" |
| 18 #include "base/memory/scoped_ptr.h" | 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/path_service.h" | 19 #include "base/path_service.h" |
| 20 #include "base/prefs/pref_service.h" | 20 #include "base/prefs/pref_service.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
| 23 #include "base/threading/worker_pool.h" | 23 #include "base/threading/worker_pool.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/chromeos/login/users/user.h" | |
| 26 #include "chrome/browser/chromeos/login/users/user_manager.h" | 25 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 27 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 26 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/common/chrome_paths.h" | 28 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
| 30 #include "components/user_manager/user.h" |
| 31 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 32 #include "extensions/browser/event_router.h" | 32 #include "extensions/browser/event_router.h" |
| 33 #include "grit/app_locale_settings.h" | 33 #include "grit/app_locale_settings.h" |
| 34 #include "grit/generated_resources.h" | 34 #include "grit/generated_resources.h" |
| 35 #include "grit/platform_locale_settings.h" | 35 #include "grit/platform_locale_settings.h" |
| 36 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 37 #include "ui/base/webui/web_ui_util.h" | 37 #include "ui/base/webui/web_ui_util.h" |
| 38 #include "url/gurl.h" | 38 #include "url/gurl.h" |
| 39 | 39 |
| 40 using base::BinaryValue; | 40 using base::BinaryValue; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 chromeos::WallpaperManager::Get(); | 370 chromeos::WallpaperManager::Get(); |
| 371 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 371 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
| 372 wallpaper_private::ToString(params->layout)); | 372 wallpaper_private::ToString(params->layout)); |
| 373 | 373 |
| 374 bool update_wallpaper = | 374 bool update_wallpaper = |
| 375 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); | 375 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); |
| 376 wallpaper_manager->SetWallpaperFromImageSkia( | 376 wallpaper_manager->SetWallpaperFromImageSkia( |
| 377 user_id_, image, layout, update_wallpaper); | 377 user_id_, image, layout, update_wallpaper); |
| 378 bool is_persistent = | 378 bool is_persistent = |
| 379 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); | 379 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); |
| 380 chromeos::WallpaperInfo info = { | 380 chromeos::WallpaperInfo info = {params->url, layout, |
| 381 params->url, | 381 user_manager::User::ONLINE, |
| 382 layout, | 382 base::Time::Now().LocalMidnight()}; |
| 383 chromeos::User::ONLINE, | |
| 384 base::Time::Now().LocalMidnight() | |
| 385 }; | |
| 386 wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent); | 383 wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent); |
| 387 SetResult(new base::FundamentalValue(true)); | 384 SetResult(new base::FundamentalValue(true)); |
| 388 Profile* profile = Profile::FromBrowserContext(browser_context()); | 385 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 389 // This API is only available to the component wallpaper picker. We do not | 386 // This API is only available to the component wallpaper picker. We do not |
| 390 // need to show the app's name if it is the component wallpaper picker. So set | 387 // need to show the app's name if it is the component wallpaper picker. So set |
| 391 // the pref to empty string. | 388 // the pref to empty string. |
| 392 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 389 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 393 std::string()); | 390 std::string()); |
| 394 SendResponse(true); | 391 SendResponse(true); |
| 395 } | 392 } |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 481 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
| 485 wallpaper_private::ToString(params->layout)); | 482 wallpaper_private::ToString(params->layout)); |
| 486 | 483 |
| 487 bool update_wallpaper = | 484 bool update_wallpaper = |
| 488 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); | 485 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); |
| 489 wallpaper_manager->SetWallpaperFromImageSkia( | 486 wallpaper_manager->SetWallpaperFromImageSkia( |
| 490 user_id_, *image.get(), layout, update_wallpaper); | 487 user_id_, *image.get(), layout, update_wallpaper); |
| 491 | 488 |
| 492 bool is_persistent = | 489 bool is_persistent = |
| 493 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); | 490 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); |
| 494 chromeos::WallpaperInfo info = { | 491 chromeos::WallpaperInfo info = {params->url, layout, |
| 495 params->url, | 492 user_manager::User::ONLINE, |
| 496 layout, | 493 base::Time::Now().LocalMidnight()}; |
| 497 chromeos::User::ONLINE, | |
| 498 base::Time::Now().LocalMidnight() | |
| 499 }; | |
| 500 Profile* profile = Profile::FromBrowserContext(browser_context()); | 494 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 501 // This API is only available to the component wallpaper picker. We do not | 495 // This API is only available to the component wallpaper picker. We do not |
| 502 // need to show the app's name if it is the component wallpaper picker. So set | 496 // need to show the app's name if it is the component wallpaper picker. So set |
| 503 // the pref to empty string. | 497 // the pref to empty string. |
| 504 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 498 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 505 std::string()); | 499 std::string()); |
| 506 wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent); | 500 wallpaper_manager->SetUserWallpaperInfo(user_id_, info, is_persistent); |
| 507 SendResponse(true); | 501 SendResponse(true); |
| 508 } | 502 } |
| 509 | 503 |
| 510 WallpaperPrivateResetWallpaperFunction:: | 504 WallpaperPrivateResetWallpaperFunction:: |
| 511 WallpaperPrivateResetWallpaperFunction() {} | 505 WallpaperPrivateResetWallpaperFunction() {} |
| 512 | 506 |
| 513 WallpaperPrivateResetWallpaperFunction:: | 507 WallpaperPrivateResetWallpaperFunction:: |
| 514 ~WallpaperPrivateResetWallpaperFunction() {} | 508 ~WallpaperPrivateResetWallpaperFunction() {} |
| 515 | 509 |
| 516 bool WallpaperPrivateResetWallpaperFunction::RunAsync() { | 510 bool WallpaperPrivateResetWallpaperFunction::RunAsync() { |
| 517 chromeos::WallpaperManager* wallpaper_manager = | 511 chromeos::WallpaperManager* wallpaper_manager = |
| 518 chromeos::WallpaperManager::Get(); | 512 chromeos::WallpaperManager::Get(); |
| 519 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); | 513 chromeos::UserManager* user_manager = chromeos::UserManager::Get(); |
| 520 | 514 |
| 521 std::string user_id = user_manager->GetActiveUser()->email(); | 515 std::string user_id = user_manager->GetActiveUser()->email(); |
| 522 wallpaper_manager->RemoveUserWallpaperInfo(user_id); | 516 wallpaper_manager->RemoveUserWallpaperInfo(user_id); |
| 523 | 517 |
| 524 chromeos::WallpaperInfo info = { | 518 chromeos::WallpaperInfo info = {std::string(), |
| 525 "", | 519 ash::WALLPAPER_LAYOUT_CENTER, |
| 526 ash::WALLPAPER_LAYOUT_CENTER, | 520 user_manager::User::DEFAULT, |
| 527 chromeos::User::DEFAULT, | 521 base::Time::Now().LocalMidnight()}; |
| 528 base::Time::Now().LocalMidnight() | |
| 529 }; | |
| 530 bool is_persistent = | 522 bool is_persistent = |
| 531 !user_manager->IsCurrentUserNonCryptohomeDataEphemeral(); | 523 !user_manager->IsCurrentUserNonCryptohomeDataEphemeral(); |
| 532 wallpaper_manager->SetUserWallpaperInfo(user_id, info, is_persistent); | 524 wallpaper_manager->SetUserWallpaperInfo(user_id, info, is_persistent); |
| 533 | 525 |
| 534 wallpaper_manager->SetDefaultWallpaperNow(user_id); | 526 wallpaper_manager->SetDefaultWallpaperNow(user_id); |
| 535 Profile* profile = Profile::FromBrowserContext(browser_context()); | 527 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 536 // This API is only available to the component wallpaper picker. We do not | 528 // This API is only available to the component wallpaper picker. We do not |
| 537 // need to show the app's name if it is the component wallpaper picker. So set | 529 // need to show the app's name if it is the component wallpaper picker. So set |
| 538 // the pref to empty string. | 530 // the pref to empty string. |
| 539 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 531 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 | 569 |
| 578 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( | 570 ash::WallpaperLayout layout = wallpaper_api_util::GetLayoutEnum( |
| 579 wallpaper_private::ToString(params->layout)); | 571 wallpaper_private::ToString(params->layout)); |
| 580 | 572 |
| 581 bool update_wallpaper = | 573 bool update_wallpaper = |
| 582 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); | 574 user_id_ == chromeos::UserManager::Get()->GetActiveUser()->email(); |
| 583 wallpaper_manager->SetCustomWallpaper(user_id_, | 575 wallpaper_manager->SetCustomWallpaper(user_id_, |
| 584 user_id_hash_, | 576 user_id_hash_, |
| 585 params->file_name, | 577 params->file_name, |
| 586 layout, | 578 layout, |
| 587 chromeos::User::CUSTOMIZED, | 579 user_manager::User::CUSTOMIZED, |
| 588 image, | 580 image, |
| 589 update_wallpaper); | 581 update_wallpaper); |
| 590 unsafe_wallpaper_decoder_ = NULL; | 582 unsafe_wallpaper_decoder_ = NULL; |
| 591 | 583 |
| 592 Profile* profile = Profile::FromBrowserContext(browser_context()); | 584 Profile* profile = Profile::FromBrowserContext(browser_context()); |
| 593 // This API is only available to the component wallpaper picker. We do not | 585 // This API is only available to the component wallpaper picker. We do not |
| 594 // need to show the app's name if it is the component wallpaper picker. So set | 586 // need to show the app's name if it is the component wallpaper picker. So set |
| 595 // the pref to empty string. | 587 // the pref to empty string. |
| 596 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, | 588 profile->GetPrefs()->SetString(prefs::kCurrentWallpaperAppName, |
| 597 std::string()); | 589 std::string()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 648 | 640 |
| 649 bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunAsync() { | 641 bool WallpaperPrivateSetCustomWallpaperLayoutFunction::RunAsync() { |
| 650 scoped_ptr<set_custom_wallpaper_layout::Params> params( | 642 scoped_ptr<set_custom_wallpaper_layout::Params> params( |
| 651 set_custom_wallpaper_layout::Params::Create(*args_)); | 643 set_custom_wallpaper_layout::Params::Create(*args_)); |
| 652 EXTENSION_FUNCTION_VALIDATE(params); | 644 EXTENSION_FUNCTION_VALIDATE(params); |
| 653 | 645 |
| 654 chromeos::WallpaperManager* wallpaper_manager = | 646 chromeos::WallpaperManager* wallpaper_manager = |
| 655 chromeos::WallpaperManager::Get(); | 647 chromeos::WallpaperManager::Get(); |
| 656 chromeos::WallpaperInfo info; | 648 chromeos::WallpaperInfo info; |
| 657 wallpaper_manager->GetLoggedInUserWallpaperInfo(&info); | 649 wallpaper_manager->GetLoggedInUserWallpaperInfo(&info); |
| 658 if (info.type != chromeos::User::CUSTOMIZED) { | 650 if (info.type != user_manager::User::CUSTOMIZED) { |
| 659 SetError("Only custom wallpaper can change layout."); | 651 SetError("Only custom wallpaper can change layout."); |
| 660 SendResponse(false); | 652 SendResponse(false); |
| 661 return false; | 653 return false; |
| 662 } | 654 } |
| 663 info.layout = wallpaper_api_util::GetLayoutEnum( | 655 info.layout = wallpaper_api_util::GetLayoutEnum( |
| 664 wallpaper_private::ToString(params->layout)); | 656 wallpaper_private::ToString(params->layout)); |
| 665 | 657 |
| 666 std::string email = chromeos::UserManager::Get()->GetActiveUser()->email(); | 658 std::string email = chromeos::UserManager::Get()->GetActiveUser()->email(); |
| 667 bool is_persistent = | 659 bool is_persistent = |
| 668 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); | 660 !chromeos::UserManager::Get()->IsCurrentUserNonCryptohomeDataEphemeral(); |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 this, file_list)); | 877 this, file_list)); |
| 886 } | 878 } |
| 887 | 879 |
| 888 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( | 880 void WallpaperPrivateGetOfflineWallpaperListFunction::OnComplete( |
| 889 const std::vector<std::string>& file_list) { | 881 const std::vector<std::string>& file_list) { |
| 890 base::ListValue* results = new base::ListValue(); | 882 base::ListValue* results = new base::ListValue(); |
| 891 results->AppendStrings(file_list); | 883 results->AppendStrings(file_list); |
| 892 SetResult(results); | 884 SetResult(results); |
| 893 SendResponse(true); | 885 SendResponse(true); |
| 894 } | 886 } |
| OLD | NEW |