Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handle r2.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/bind_helpers.h" | |
| 9 #include "base/metrics/histogram.h" | |
| 10 #include "base/path_service.h" | |
| 11 #include "base/string_util.h" | |
| 12 #include "base/values.h" | |
| 13 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 14 #include "chrome/browser/profiles/profile.h" | |
| 15 #include "chrome/browser/ui/browser_list.h" | |
| 16 #include "chrome/browser/ui/browser_window.h" | |
| 17 #include "chrome/browser/ui/views/window.h" | |
| 18 #include "chrome/browser/ui/webui/web_ui_util.h" | |
| 19 #include "chrome/common/chrome_paths.h" | |
| 20 #include "chrome/common/chrome_notification_types.h" | |
| 21 #include "content/public/browser/notification_service.h" | |
| 22 #include "content/public/browser/web_ui.h" | |
| 23 #include "grit/generated_resources.h" | |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | |
| 25 #include "ui/base/l10n/l10n_util.h" | |
| 26 #include "ui/base/resource/resource_bundle.h" | |
| 27 #include "ui/views/widget/widget.h" | |
| 28 | |
| 29 #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.
| |
| 30 #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
| |
| 31 #endif | |
| 32 | |
| 33 namespace chromeos { | |
| 34 namespace options2 { | |
| 35 | |
| 36 SetWallpaperOptionsHandler::SetWallpaperOptionsHandler() | |
| 37 : previous_index_(-1), | |
| 38 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) { | |
| 39 } | |
| 40 | |
| 41 SetWallpaperOptionsHandler::~SetWallpaperOptionsHandler() { | |
| 42 } | |
| 43 | |
| 44 void SetWallpaperOptionsHandler::GetLocalizedValues( | |
| 45 DictionaryValue* localized_strings) { | |
| 46 DCHECK(localized_strings); | |
| 47 localized_strings->SetString("setWallpaperPage", | |
| 48 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TITLE)); | |
| 49 localized_strings->SetString("setWallpaperPageDescription", | |
| 50 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TEXT)); | |
| 51 } | |
| 52 | |
| 53 void SetWallpaperOptionsHandler::RegisterMessages() { | |
| 54 web_ui()->RegisterMessageCallback("onSetWallpaperPageInitialized", | |
| 55 base::Bind(&SetWallpaperOptionsHandler::HandlePageInitialized, | |
| 56 base::Unretained(this))); | |
| 57 web_ui()->RegisterMessageCallback("selectWallpaper", | |
| 58 base::Bind(&SetWallpaperOptionsHandler::HandleSelectImage, | |
| 59 base::Unretained(this))); | |
| 60 } | |
| 61 | |
| 62 void SetWallpaperOptionsHandler::SendDefaultImages() { | |
| 63 ListValue image_urls; | |
| 64 /* | |
| 65 SkBitmap* res = new SkBitmap(); | |
| 66 for (int i = 0; i < ash::kDefaultWallpaperCount; ++i) { | |
| 67 ash::GetDefaultWallpaperThumbnail(i, res); | |
| 68 image_urls.Append(Value::CreateStringValue( | |
| 69 web_ui_util::GetImageDataUrl(*res))); | |
| 70 //image_urls.Append(Value::CreateStringValue( | |
| 71 // web_ui_util::GetImageDataUrl(ash::GetDefaultWallpaperThumbnail(i)))); | |
| 72 } | |
| 73 */ | |
| 74 for (int i = 0; i < ash::kDefaultWallpaperCount; ++i) { | |
| 75 image_urls.Append(Value::CreateStringValue( | |
| 76 web_ui_util::GetImageDataUrl(ash::GetDefaultWallpaperThumbnail(i)))); | |
| 77 } | |
| 78 | |
| 79 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages", | |
| 80 image_urls); | |
| 81 } | |
| 82 | |
| 83 void SetWallpaperOptionsHandler::HandlePageInitialized( | |
| 84 const base::ListValue* args) { | |
| 85 DCHECK(args && args->empty()); | |
| 86 | |
| 87 SendDefaultImages(); | |
| 88 } | |
| 89 | |
| 90 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) { | |
| 91 std::string image_url; | |
| 92 if (!args || | |
| 93 args->GetSize() != 1 || | |
| 94 !args->GetString(0, &image_url)) { | |
| 95 NOTREACHED(); | |
| 96 return; | |
| 97 } | |
| 98 DCHECK(!image_url.empty()); | |
| 99 | |
| 100 UserManager* user_manager = UserManager::Get(); | |
| 101 const User& user = user_manager->logged_in_user(); | |
| 102 int image_index = atoi(image_url.c_str()); | |
| 103 | |
| 104 if (image_index == previous_index_) | |
| 105 return; | |
| 106 previous_index_ = image_index; | |
| 107 | |
| 108 content::NotificationService::current()->Notify( | |
| 109 chrome::NOTIFICATION_DESKTOP_BACKGROUND_CHANGED, | |
| 110 content::Source<SetWallpaperOptionsHandler>(this), | |
| 111 content::Details<int>(&image_index)); | |
| 112 | |
| 113 user_manager->SetUserWallpaper(user.email(), image_index); | |
| 114 } | |
| 115 | |
| 116 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { | |
| 117 Browser* browser = | |
| 118 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); | |
| 119 if (!browser) | |
| 120 return NULL; | |
| 121 return browser->window()->GetNativeHandle(); | |
| 122 } | |
| 123 | |
| 124 } // namespace options2 | |
| 125 } // namespace chromeos | |
| OLD | NEW |