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

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

Issue 9580023: Enable user change background image in settings page in Aura build. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Address reveiw and auto select the current wallpaper thumbnail when select wallpaper overlay shows. Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_ASH)
30 #include "ash/desktop_background/desktop_background_resources.h"
31 #endif
32
33 namespace chromeos {
34 namespace options2 {
35
36 SetWallpaperOptionsHandler::SetWallpaperOptionsHandler()
37 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
38 }
39
40 SetWallpaperOptionsHandler::~SetWallpaperOptionsHandler() {
41 }
42
43 void SetWallpaperOptionsHandler::GetLocalizedValues(
44 DictionaryValue* localized_strings) {
45 DCHECK(localized_strings);
46 localized_strings->SetString("setWallpaperPage",
47 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TITLE));
48 localized_strings->SetString("setWallpaperPageDescription",
49 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TEXT));
50 }
51
52 void SetWallpaperOptionsHandler::RegisterMessages() {
53 web_ui()->RegisterMessageCallback("onSetWallpaperPageInitialized",
54 base::Bind(&SetWallpaperOptionsHandler::HandlePageInitialized,
55 base::Unretained(this)));
56 web_ui()->RegisterMessageCallback("onSetWallpaperPageShown",
57 base::Bind(&SetWallpaperOptionsHandler::HandlePageShown,
58 base::Unretained(this)));
59 web_ui()->RegisterMessageCallback("selectWallpaper",
60 base::Bind(&SetWallpaperOptionsHandler::HandleSelectImage,
61 base::Unretained(this)));
62 }
63
64 void SetWallpaperOptionsHandler::SendDefaultImages() {
65 ListValue image_urls;
66
67 for (int i = 0; i < ash::GetWallpaperCount(); ++i) {
68 image_urls.Append(Value::CreateStringValue(
69 web_ui_util::GetImageDataUrl(ash::GetDefaultWallpaperThumbnail(i))));
70 }
71
72 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages",
73 image_urls);
74 }
75
76 void SetWallpaperOptionsHandler::HandlePageInitialized(
77 const base::ListValue* args) {
78 DCHECK(args && args->empty());
79
80 SendDefaultImages();
81 }
82
83 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) {
84 DCHECK(args && args->empty());
85 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
86 const chromeos::User& user = user_manager->logged_in_user();
87 DCHECK(!user.email().empty());
88 int index = user_manager->GetUserWallpaper(user.email());
89 DCHECK(index >=0 && index < ash::GetWallpaperCount());
90 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage",
91 *Value::CreateIntegerValue(index));
flackr 2012/03/08 01:19:59 This is a memory leak. You can use the Fundamental
bshe 2012/03/08 03:19:24 Done.
92 }
93
94 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) {
95 std::string image_index_string;
96 if (!args ||
97 args->GetSize() != 1 ||
98 !args->GetString(0, &image_index_string)) {
99 NOTREACHED();
100 return;
101 }
102 DCHECK(!image_index_string.empty());
103
104 UserManager* user_manager = UserManager::Get();
105 const User& user = user_manager->logged_in_user();
106 int image_index = atoi(image_index_string.c_str());
flackr 2012/03/08 01:19:59 Use StringToInt from string_number_conversions.h,
bshe 2012/03/08 03:19:24 Done.
107 user_manager->SaveWallpaperDefaultIndex(user.email(), image_index);
108 }
109
110 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const {
111 Browser* browser =
112 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui()));
113 if (!browser)
114 return NULL;
115 return browser->window()->GetNativeHandle();
116 }
117
118 } // namespace options2
119 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698