| 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
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..3b95789cf497e4f9e0e1da09e21b7deb4a37a71f
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc
|
| @@ -0,0 +1,116 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| +#include "base/metrics/histogram.h"
|
| +#include "base/path_service.h"
|
| +#include "base/string_util.h"
|
| +#include "base/values.h"
|
| +#include "chrome/browser/chromeos/login/user_manager.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/ui/browser_list.h"
|
| +#include "chrome/browser/ui/browser_window.h"
|
| +#include "chrome/browser/ui/views/window.h"
|
| +#include "chrome/browser/ui/webui/web_ui_util.h"
|
| +#include "chrome/common/chrome_paths.h"
|
| +#include "chrome/common/chrome_notification_types.h"
|
| +#include "content/public/browser/notification_service.h"
|
| +#include "content/public/browser/web_ui.h"
|
| +#include "grit/generated_resources.h"
|
| +#include "third_party/skia/include/core/SkBitmap.h"
|
| +#include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/base/resource/resource_bundle.h"
|
| +#include "ui/views/widget/widget.h"
|
| +
|
| +#if defined(USE_ASH)
|
| +#include "ash/desktop_background/desktop_background_resources.h"
|
| +#endif
|
| +
|
| +namespace chromeos {
|
| +namespace options2 {
|
| +
|
| +SetWallpaperOptionsHandler::SetWallpaperOptionsHandler()
|
| + : previous_index_(-1),
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
|
| +}
|
| +
|
| +SetWallpaperOptionsHandler::~SetWallpaperOptionsHandler() {
|
| +}
|
| +
|
| +void SetWallpaperOptionsHandler::GetLocalizedValues(
|
| + DictionaryValue* localized_strings) {
|
| + DCHECK(localized_strings);
|
| + localized_strings->SetString("setWallpaperPage",
|
| + l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TITLE));
|
| + localized_strings->SetString("setWallpaperPageDescription",
|
| + l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TEXT));
|
| +}
|
| +
|
| +void SetWallpaperOptionsHandler::RegisterMessages() {
|
| + web_ui()->RegisterMessageCallback("onSetWallpaperPageInitialized",
|
| + base::Bind(&SetWallpaperOptionsHandler::HandlePageInitialized,
|
| + base::Unretained(this)));
|
| + web_ui()->RegisterMessageCallback("selectWallpaper",
|
| + base::Bind(&SetWallpaperOptionsHandler::HandleSelectImage,
|
| + base::Unretained(this)));
|
| +}
|
| +
|
| +void SetWallpaperOptionsHandler::SendDefaultImages() {
|
| + ListValue image_urls;
|
| +
|
| + for (int i = 0; i < ash::kDefaultWallpaperCount; ++i) {
|
| + image_urls.Append(Value::CreateStringValue(
|
| + web_ui_util::GetImageDataUrl(ash::GetDefaultWallpaperThumbnail(i))));
|
| + }
|
| +
|
| + web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages",
|
| + image_urls);
|
| +}
|
| +
|
| +void SetWallpaperOptionsHandler::HandlePageInitialized(
|
| + const base::ListValue* args) {
|
| + DCHECK(args && args->empty());
|
| +
|
| + SendDefaultImages();
|
| +}
|
| +
|
| +void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) {
|
| + std::string image_url;
|
| + if (!args ||
|
| + args->GetSize() != 1 ||
|
| + !args->GetString(0, &image_url)) {
|
| + NOTREACHED();
|
| + return;
|
| + }
|
| + DCHECK(!image_url.empty());
|
| +
|
| + UserManager* user_manager = UserManager::Get();
|
| + const User& user = user_manager->logged_in_user();
|
| + int image_index = atoi(image_url.c_str());
|
| +
|
| + if (image_index == previous_index_)
|
| + return;
|
| + previous_index_ = image_index;
|
| +
|
| + content::NotificationService::current()->Notify(
|
| + chrome::NOTIFICATION_DESKTOP_BACKGROUND_CHANGED,
|
| + content::Source<SetWallpaperOptionsHandler>(this),
|
| + content::Details<int>(&image_index));
|
| +
|
| + user_manager->SaveWallpaperToLocalState(user.email(), image_index);
|
| +}
|
| +
|
| +gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const {
|
| + Browser* browser =
|
| + BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui()));
|
| + if (!browser)
|
| + return NULL;
|
| + return browser->window()->GetNativeHandle();
|
| +}
|
| +
|
| +} // namespace options2
|
| +} // namespace chromeos
|
|
|