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..0abe258944f7170931b69db96799c9ad471b3c6b |
--- /dev/null |
+++ b/chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handler2.cc |
@@ -0,0 +1,125 @@ |
+// 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_AURA) |
flackr
2012/03/05 16:16:03
This is only included if USE_AURA is defined, so t
bshe
2012/03/06 01:33:27
Done.
|
+#include "ash/desktop_background/desktop_background_controller.h" |
flackr
2012/03/05 16:16:03
And I don't think you actually use this class in h
bshe
2012/03/06 01:33:27
The ash constant and functions, such as ash::kDefa
|
+#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; |
+ /* |
+ SkBitmap* res = new SkBitmap(); |
+ for (int i = 0; i < ash::kDefaultWallpaperCount; ++i) { |
+ ash::GetDefaultWallpaperThumbnail(i, res); |
+ image_urls.Append(Value::CreateStringValue( |
+ web_ui_util::GetImageDataUrl(*res))); |
+ //image_urls.Append(Value::CreateStringValue( |
+ // web_ui_util::GetImageDataUrl(ash::GetDefaultWallpaperThumbnail(i)))); |
+ } |
+ */ |
+ 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->SetUserWallpaper(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 |