Chromium Code Reviews| Index: chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc |
| diff --git a/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc |
| index 49175d7bc29efaaa0f8ffd642585601646323de4..ffd3db3de7522c9fe05af4ce423c2f6e7421180b 100644 |
| --- a/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc |
| +++ b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc |
| @@ -5,7 +5,6 @@ |
| #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.h" |
| #include "ash/desktop_background/desktop_background_controller.h" |
| -#include "ash/desktop_background/desktop_background_resources.h" |
| #include "ash/shell.h" |
| #include "base/bind.h" |
| #include "base/bind_helpers.h" |
| @@ -19,7 +18,9 @@ |
| #include "chrome/browser/ui/browser_list.h" |
| #include "chrome/browser/ui/browser_window.h" |
| #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2.h" |
| +#include "chrome/browser/ui/webui/web_ui_util.h" |
| #include "chrome/common/chrome_notification_types.h" |
| +#include "chrome/common/chrome_paths.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/web_ui.h" |
| #include "grit/generated_resources.h" |
| @@ -30,11 +31,33 @@ |
| namespace chromeos { |
| namespace options2 { |
| +namespace { |
| + |
| +// Returns info about extensions for files we support as wallpaper images. |
| +SelectFileDialog::FileTypeInfo GetUserImageFileTypeInfo() { |
| + SelectFileDialog::FileTypeInfo file_type_info; |
| + file_type_info.extensions.resize(3); |
| + |
| + file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("jpg")); |
| + file_type_info.extensions[1].push_back(FILE_PATH_LITERAL("jpeg")); |
| + |
| + file_type_info.extensions[2].push_back(FILE_PATH_LITERAL("png")); |
| + |
| + return file_type_info; |
| +} |
| + |
| +} // namespace |
| + |
| SetWallpaperOptionsHandler::SetWallpaperOptionsHandler() |
| : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { |
| + registrar_.Add(this, |
| + chrome::NOTIFICATION_LOGIN_USER_WALLPAPER_THUMBNAIL_UPDATED, |
| + content::NotificationService::AllSources()); |
| } |
| SetWallpaperOptionsHandler::~SetWallpaperOptionsHandler() { |
| + if (select_file_dialog_.get()) |
|
flackr
2012/05/04 19:06:17
Only indent 2
bshe
2012/05/08 22:22:18
Done.
|
| + select_file_dialog_->ListenerDestroyed(); |
| } |
| void SetWallpaperOptionsHandler::GetLocalizedValues( |
| @@ -48,6 +71,8 @@ void SetWallpaperOptionsHandler::GetLocalizedValues( |
| l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_AUTHOR_TEXT)); |
| localized_strings->SetString("randomCheckbox", |
| l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_RANDOM)); |
| + localized_strings->SetString("customeWallpaper", |
| + l10n_util::GetStringUTF16(IDS_OPTIONS_CUSTOME_WALLPAPER)); |
| } |
| void SetWallpaperOptionsHandler::RegisterMessages() { |
| @@ -63,6 +88,12 @@ void SetWallpaperOptionsHandler::RegisterMessages() { |
| web_ui()->RegisterMessageCallback("selectRandomWallpaper", |
| base::Bind(&SetWallpaperOptionsHandler::HandleRandomWallpaper, |
| base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback("chooseWallpaper", |
| + base::Bind(&SetWallpaperOptionsHandler::HandleChooseFile, |
| + base::Unretained(this))); |
| + web_ui()->RegisterMessageCallback("changeWallpaperLayout", |
| + base::Bind(&SetWallpaperOptionsHandler::HandleLayoutChanged, |
| + base::Unretained(this))); |
| } |
| void SetWallpaperOptionsHandler::SendDefaultImages() { |
| @@ -82,6 +113,33 @@ void SetWallpaperOptionsHandler::SendDefaultImages() { |
| images); |
| } |
| +void SetWallpaperOptionsHandler::SendLayoutOptions( |
| + ash::WallpaperLayout layout) { |
| + ListValue layouts; |
| + DictionaryValue* entry; |
| + |
| + layouts.Append(entry = new DictionaryValue()); |
| + entry->SetString("name", |
| + l10n_util::GetStringUTF16(IDS_OPTIONS_WALLPAPER_CENTER_LAYOUT)); |
| + entry->SetInteger("index", ash::CENTER); |
| + |
| + layouts.Append(entry = new DictionaryValue()); |
| + entry->SetString("name", |
| + l10n_util::GetStringUTF16(IDS_OPTIONS_WALLPAPER_CENTER_CROPPED_LAYOUT)); |
| + entry->SetInteger("index", ash::CENTER_CROPPED); |
| + |
| + layouts.Append(entry = new DictionaryValue()); |
| + entry->SetString("name", |
| + l10n_util::GetStringUTF16(IDS_OPTIONS_WALLPAPER_STRETCH_LAYOUT)); |
| + entry->SetInteger("index", ash::STRETCH); |
| + |
| + int index = layout; |
| + scoped_ptr<Value> selected_value(Value::CreateIntegerValue(index)); |
| + |
| + web_ui()->CallJavascriptFunction( |
| + "SetWallpaperOptions.populateWallpaperLayout", layouts, *selected_value); |
| +} |
| + |
| void SetWallpaperOptionsHandler::HandlePageInitialized( |
| const base::ListValue* args) { |
| DCHECK(args && args->empty()); |
| @@ -94,11 +152,67 @@ void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { |
| User::WallpaperType type; |
| int index; |
| UserManager::Get()->GetLoggedInUserWallpaperProperties(type, index); |
| - //int index = chromeos::UserManager::Get()->GetUserWallpaperIndex(); |
| base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); |
| base::FundamentalValue is_random(type == User::RANDOM); |
| - web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", |
| - image_url, is_random); |
| + if (type == User::CUSTOMIZED) { |
| + ash::WallpaperLayout layout = static_cast<ash::WallpaperLayout>(index); |
| + SendLayoutOptions(layout); |
| + web_ui()->CallJavascriptFunction("SetWallpaperOptions.setCustomImage"); |
| + } else { |
| + SendLayoutOptions(ash::CENTER_CROPPED); |
| + web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", |
| + image_url, is_random); |
| + } |
| +} |
| + |
| +void SetWallpaperOptionsHandler::HandleChooseFile(const ListValue* args) { |
| + DCHECK(args && args->empty()); |
| + if (!select_file_dialog_.get()) |
| + select_file_dialog_ = SelectFileDialog::Create(this); |
| + |
| + FilePath downloads_path; |
| + if (!PathService::Get(chrome::DIR_DEFAULT_DOWNLOADS, &downloads_path)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + |
| + // Static so we initialize it only once. |
| + CR_DEFINE_STATIC_LOCAL(SelectFileDialog::FileTypeInfo, file_type_info, |
| + (GetUserImageFileTypeInfo())); |
| + |
| + select_file_dialog_->SelectFile( |
| + SelectFileDialog::SELECT_OPEN_FILE, |
| + l10n_util::GetStringUTF16(IDS_DOWNLOAD_TITLE), |
| + downloads_path, |
| + &file_type_info, |
| + 0, |
| + FILE_PATH_LITERAL(""), |
| + web_ui()->GetWebContents(), |
| + GetBrowserWindow(), |
| + NULL); |
| +} |
| + |
| +void SetWallpaperOptionsHandler::FileSelected(const FilePath& path, |
| + int index, |
| + void* params) { |
| + UserManager* user_manager = UserManager::Get(); |
| + |
| + // Default wallpaper layout is CENTER_CROPPED. |
| + user_manager->SaveUserWallpaperFromFile( |
| + user_manager->GetLoggedInUser().email(), path, ash::CENTER_CROPPED); |
| + web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile"); |
| +} |
| + |
| +void SetWallpaperOptionsHandler::HandleLayoutChanged(const ListValue* args) { |
| + int selected_layout = -1; |
| + if (!ExtractIntegerValue(args, &selected_layout)) { |
| + NOTREACHED(); |
| + return; |
| + } |
| + ash::WallpaperLayout layout = |
| + static_cast<ash::WallpaperLayout>(selected_layout); |
| + |
| + UserManager::Get()->SetLoggedInUserCustomWallpaperLayout(layout); |
| } |
| void SetWallpaperOptionsHandler::HandleDefaultWallpaper(const ListValue* args) { |
| @@ -131,6 +245,23 @@ void SetWallpaperOptionsHandler::HandleRandomWallpaper(const ListValue* args) { |
| image_url, is_random); |
| } |
| +void SetWallpaperOptionsHandler::SetCustomWallpaperThumb() { |
| + web_ui()->CallJavascriptFunction("SetWallpaperOptions.setCustomImage"); |
| +} |
| + |
| +void SetWallpaperOptionsHandler::Observe( |
| + int type, |
| + const content::NotificationSource& source, |
| + const content::NotificationDetails& details) { |
| + OptionsPageUIHandler::Observe(type, source, details); |
| + if (type == chrome::NOTIFICATION_LOGIN_USER_WALLPAPER_THUMBNAIL_UPDATED) { |
| + // User custom wallpaper thumbnail has been updated. |
| + //SetCustomWallpaperThumb(); |
|
flackr
2012/05/04 19:06:17
Remove commented code.
bshe
2012/05/08 22:22:18
Done.
|
| + web_ui()->CallJavascriptFunction("SetWallpaperOptions.setCustomImage"); |
| + } |
| +} |
| + |
| + |
| gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { |
| Browser* browser = |
| BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); |