| 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 d71105f44a2633103b3ae9627b41d7fd056b03bd..e2dc781b8329f9ef226022628e91c2f2e5091622 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,8 +18,8 @@
|
| #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/common/chrome_notification_types.h"
|
| -#include "content/public/browser/notification_service.h"
|
| +#include "chrome/browser/ui/webui/web_ui_util.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| #include "content/public/browser/web_ui.h"
|
| #include "grit/generated_resources.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| @@ -30,11 +29,30 @@
|
| 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)) {
|
| }
|
|
|
| SetWallpaperOptionsHandler::~SetWallpaperOptionsHandler() {
|
| + if (select_file_dialog_.get())
|
| + select_file_dialog_->ListenerDestroyed();
|
| }
|
|
|
| void SetWallpaperOptionsHandler::GetLocalizedValues(
|
| @@ -48,6 +66,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("customWallpaper",
|
| + l10n_util::GetStringUTF16(IDS_OPTIONS_CUSTOME_WALLPAPER));
|
| }
|
|
|
| void SetWallpaperOptionsHandler::RegisterMessages() {
|
| @@ -63,6 +83,27 @@ 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::SetCustomWallpaperThumbnail() {
|
| + web_ui()->CallJavascriptFunction("SetWallpaperOptions.setCustomImage");
|
| +}
|
| +
|
| +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, this);
|
| + web_ui()->CallJavascriptFunction("SetWallpaperOptions.didSelectFile");
|
| }
|
|
|
| void SetWallpaperOptionsHandler::SendDefaultImages() {
|
| @@ -82,6 +123,31 @@ 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);
|
| +
|
| + base::FundamentalValue selected_value(static_cast<int>(layout));
|
| + web_ui()->CallJavascriptFunction(
|
| + "SetWallpaperOptions.populateWallpaperLayouts", layouts, selected_value);
|
| +}
|
| +
|
| void SetWallpaperOptionsHandler::HandlePageInitialized(
|
| const base::ListValue* args) {
|
| DCHECK(args && args->empty());
|
| @@ -96,8 +162,47 @@ void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) {
|
| UserManager::Get()->GetLoggedInUserWallpaperProperties(&type, &index);
|
| 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();
|
| +
|
| + // 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::HandleLayoutChanged(const ListValue* args) {
|
| + int selected_layout = ash::CENTER_CROPPED;
|
| + if (!ExtractIntegerValue(args, &selected_layout))
|
| + NOTREACHED() << "Could not read wallpaper layout from JSON argument";
|
| +
|
| + ash::WallpaperLayout layout =
|
| + static_cast<ash::WallpaperLayout>(selected_layout);
|
| +
|
| + UserManager::Get()->SetLoggedInUserCustomWallpaperLayout(layout);
|
| }
|
|
|
| void SetWallpaperOptionsHandler::HandleDefaultWallpaper(const ListValue* args) {
|
|
|