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

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 review 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_number_conversions.h"
12 #include "base/string_util.h"
13 #include "base/values.h"
14 #include "chrome/browser/chromeos/login/user_manager.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/browser_list.h"
17 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/views/window.h"
19 #include "chrome/browser/ui/webui/web_ui_util.h"
20 #include "chrome/common/chrome_paths.h"
21 #include "chrome/common/chrome_notification_types.h"
22 #include "content/public/browser/notification_service.h"
23 #include "content/public/browser/web_ui.h"
24 #include "grit/generated_resources.h"
25 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/views/widget/widget.h"
29
30 #if defined(USE_ASH)
31 #include "ash/desktop_background/desktop_background_resources.h"
32 #endif
33
34 namespace chromeos {
35 namespace options2 {
36
37 SetWallpaperOptionsHandler::SetWallpaperOptionsHandler()
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("onSetWallpaperPageShown",
58 base::Bind(&SetWallpaperOptionsHandler::HandlePageShown,
59 base::Unretained(this)));
60 web_ui()->RegisterMessageCallback("selectWallpaper",
61 base::Bind(&SetWallpaperOptionsHandler::HandleSelectImage,
62 base::Unretained(this)));
63 }
64
65 void SetWallpaperOptionsHandler::SendDefaultImages() {
66 ListValue image_urls;
67
68 for (int i = 0; i < ash::GetWallpaperCount(); ++i) {
69 image_urls.Append(Value::CreateStringValue(
70 web_ui_util::GetImageDataUrl(ash::GetDefaultWallpaperThumbnail(i))));
71 }
72
73 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages",
74 image_urls);
75 }
76
77 void SetWallpaperOptionsHandler::HandlePageInitialized(
78 const base::ListValue* args) {
79 DCHECK(args && args->empty());
80
81 SendDefaultImages();
82 }
83
84 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) {
85 DCHECK(args && args->empty());
86 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
87 const chromeos::User& user = user_manager->logged_in_user();
88 DCHECK(!user.email().empty());
89 int index = user_manager->GetUserWallpaper(user.email());
90 DCHECK(index >=0 && index < ash::GetWallpaperCount());
91 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage",
92 base::FundamentalValue(index));
93 }
94
95 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) {
96 std::string image_index_string;
97 int image_index;
98 if (!args ||
99 args->GetSize() != 1 ||
100 !args->GetString(0, &image_index_string) ||
101 !base::StringToInt(image_index_string, &image_index) ||
102 image_index < 0 || image_index >= ash::GetWallpaperCount()) {
103 NOTREACHED();
104 return;
James Hawkins 2012/03/08 14:30:39 NOTREACHED() should not be handled (by returning).
bshe 2012/03/08 16:36:40 +james Could you please be more specific here? It
James Hawkins 2012/03/08 17:12:07 The existing instances of this are wrong and shoul
105 }
106
107 UserManager* user_manager = UserManager::Get();
108 const User& user = user_manager->logged_in_user();
109 DCHECK(!user.email().empty());
110 user_manager->SaveWallpaperDefaultIndex(user.email(), image_index);
111 }
112
113 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const {
114 Browser* browser =
115 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui()));
116 if (!browser)
117 return NULL;
118 return browser->window()->GetNativeHandle();
119 }
120
121 } // namespace options2
122 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698