| 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 "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handle
r.h" | 5 #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handle
r.h" |
| 6 | 6 |
| 7 #include "ash/desktop_background/desktop_background_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/chromeos/login/user_manager.h" | 16 #include "chrome/browser/chromeos/login/user_manager.h" |
| 17 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 17 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
| 18 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 19 #include "chrome/browser/ui/chrome_select_file_policy.h" | 20 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 20 #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source.h
" | 21 #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source.h
" |
| 21 #include "chrome/browser/ui/webui/web_ui_util.h" | 22 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 22 #include "chrome/common/chrome_paths.h" | 23 #include "chrome/common/chrome_paths.h" |
| 23 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
| 24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void SetWallpaperOptionsHandler::SetCustomWallpaperThumbnail() { | 100 void SetWallpaperOptionsHandler::SetCustomWallpaperThumbnail() { |
| 100 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setCustomImage"); | 101 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setCustomImage"); |
| 101 } | 102 } |
| 102 | 103 |
| 103 void SetWallpaperOptionsHandler::FileSelected(const FilePath& path, | 104 void SetWallpaperOptionsHandler::FileSelected(const FilePath& path, |
| 104 int index, | 105 int index, |
| 105 void* params) { | 106 void* params) { |
| 106 UserManager* user_manager = UserManager::Get(); | 107 UserManager* user_manager = UserManager::Get(); |
| 107 | 108 |
| 108 // Default wallpaper layout is CENTER_CROPPED. | 109 // Default wallpaper layout is CENTER_CROPPED. |
| 109 user_manager->SaveUserWallpaperFromFile( | 110 WallpaperManager::Get()->SetUserWallpaperFromFile( |
| 110 user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED, | 111 user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED, |
| 111 weak_factory_.GetWeakPtr()); | 112 weak_factory_.GetWeakPtr()); |
| 112 web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile"); | 113 web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile"); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void SetWallpaperOptionsHandler::SendDefaultImages() { | 116 void SetWallpaperOptionsHandler::SendDefaultImages() { |
| 116 ListValue images; | 117 ListValue images; |
| 117 DictionaryValue* image_detail; | 118 DictionaryValue* image_detail; |
| 118 ash::WallpaperInfo image_info; | 119 ash::WallpaperInfo image_info; |
| 119 | 120 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 DCHECK(args && args->empty()); | 160 DCHECK(args && args->empty()); |
| 160 | 161 |
| 161 SendDefaultImages(); | 162 SendDefaultImages(); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { | 165 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { |
| 165 DCHECK(args && args->empty()); | 166 DCHECK(args && args->empty()); |
| 166 User::WallpaperType type; | 167 User::WallpaperType type; |
| 167 int index; | 168 int index; |
| 168 base::Time date; | 169 base::Time date; |
| 169 UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index, &date); | 170 WallpaperManager::Get()->GetLoggedInUserWallpaperProperties( |
| 171 &type, &index, &date); |
| 170 if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) { | 172 if (type == User::DAILY && date != base::Time::Now().LocalMidnight()) { |
| 171 index = ash::GetNextWallpaperIndex(index); | 173 index = ash::GetNextWallpaperIndex(index); |
| 172 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, | 174 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, |
| 173 index); | 175 index); |
| 174 ash::Shell::GetInstance()->user_wallpaper_delegate()-> | 176 ash::Shell::GetInstance()->user_wallpaper_delegate()-> |
| 175 InitializeWallpaper(); | 177 InitializeWallpaper(); |
| 176 } | 178 } |
| 177 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); | 179 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); |
| 178 base::FundamentalValue is_daily(type == User::DAILY); | 180 base::FundamentalValue is_daily(type == User::DAILY); |
| 179 if (type == User::CUSTOMIZED) { | 181 if (type == User::CUSTOMIZED) { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DEFAULT, | 235 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DEFAULT, |
| 234 user_image_index); | 236 user_image_index); |
| 235 ash::Shell::GetInstance()->user_wallpaper_delegate()->InitializeWallpaper(); | 237 ash::Shell::GetInstance()->user_wallpaper_delegate()->InitializeWallpaper(); |
| 236 } | 238 } |
| 237 } | 239 } |
| 238 | 240 |
| 239 void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) { | 241 void SetWallpaperOptionsHandler::HandleDailyWallpaper(const ListValue* args) { |
| 240 User::WallpaperType type; | 242 User::WallpaperType type; |
| 241 int index; | 243 int index; |
| 242 base::Time date; | 244 base::Time date; |
| 243 UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index, &date); | 245 WallpaperManager::Get()->GetLoggedInUserWallpaperProperties( |
| 246 &type, &index, &date); |
| 244 if (date != base::Time::Now().LocalMidnight()) | 247 if (date != base::Time::Now().LocalMidnight()) |
| 245 index = ash::GetNextWallpaperIndex(index); | 248 index = ash::GetNextWallpaperIndex(index); |
| 246 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index); | 249 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DAILY, index); |
| 247 ash::Shell::GetInstance()->desktop_background_controller()-> | 250 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 248 SetDefaultWallpaper(index); | 251 SetDefaultWallpaper(index); |
| 249 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); | 252 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); |
| 250 base::FundamentalValue is_daily(true); | 253 base::FundamentalValue is_daily(true); |
| 251 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", | 254 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", |
| 252 image_url, is_daily); | 255 image_url, is_daily); |
| 253 } | 256 } |
| 254 | 257 |
| 255 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { | 258 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { |
| 256 Browser* browser = | 259 Browser* browser = |
| 257 browser::FindBrowserWithWebContents(web_ui()->GetWebContents()); | 260 browser::FindBrowserWithWebContents(web_ui()->GetWebContents()); |
| 258 return browser->window()->GetNativeWindow(); | 261 return browser->window()->GetNativeWindow(); |
| 259 } | 262 } |
| 260 | 263 |
| 261 } // namespace options2 | 264 } // namespace options2 |
| 262 } // namespace chromeos | 265 } // namespace chromeos |
| OLD | NEW |