Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7191)

Unified Diff: chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc

Issue 10375010: Implement user selected wallpaper feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: James' review Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 cadf81360115c2809866710f9c46b9c68e6ce9be..77eec20d0c7c850a9b0b29295e9af2935f69f9da 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,26 @@ 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,
flackr 2012/05/09 21:26:16 One parameter per line when wrapping decl.
bshe 2012/05/10 16:10:26 Done.
+ 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 +122,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;
flackr 2012/05/09 21:26:16 Should be able to use: FundamentalValue selected_v
bshe 2012/05/10 16:10:26 Done.
+ scoped_ptr<Value> selected_value(Value::CreateIntegerValue(index));
+
+ web_ui()->CallJavascriptFunction(
+ "SetWallpaperOptions.populateWallpaperLayouts", layouts, *selected_value);
+}
+
void SetWallpaperOptionsHandler::HandlePageInitialized(
const base::ListValue* args) {
DCHECK(args && args->empty());
@@ -96,8 +163,49 @@ 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();
+ return;
flackr 2012/05/09 21:26:16 Either we expect this case or don't return for NOT
bshe 2012/05/10 16:10:26 Done.
+ }
+
+ // 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 wallpapper layout from JSON argument";
+
+ ash::WallpaperLayout layout =
+ static_cast<ash::WallpaperLayout>(selected_layout);
+
+ UserManager::Get()->SetLoggedInUserCustomWallpaperLayout(layout);
}
void SetWallpaperOptionsHandler::HandleDefaultWallpaper(const ListValue* args) {

Powered by Google App Engine
This is Rietveld 408576698