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

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

Issue 9703031: Retry landing "Enable users change desktop background image from settings page in Chromeos Aura bui… (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Merge to trunk 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 "ash/desktop_background/desktop_background_resources.h"
8 #include "base/bind.h"
9 #include "base/bind_helpers.h"
10 #include "base/metrics/histogram.h"
11 #include "base/path_service.h"
12 #include "base/string_number_conversions.h"
13 #include "base/string_util.h"
14 #include "base/values.h"
15 #include "chrome/browser/chromeos/login/user_manager.h"
16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/browser/ui/browser_window.h"
19 #include "chrome/browser/ui/views/window.h"
20 #include "chrome/browser/ui/webui/web_ui_util.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 "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/views/widget/widget.h"
28
29 namespace chromeos {
30 namespace options2 {
31
32 SetWallpaperOptionsHandler::SetWallpaperOptionsHandler()
33 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
34 }
35
36 SetWallpaperOptionsHandler::~SetWallpaperOptionsHandler() {
37 }
38
39 void SetWallpaperOptionsHandler::GetLocalizedValues(
40 DictionaryValue* localized_strings) {
41 DCHECK(localized_strings);
42 localized_strings->SetString("setWallpaperPage",
43 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TITLE));
44 localized_strings->SetString("setWallpaperPageDescription",
45 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TEXT));
46 }
47
48 void SetWallpaperOptionsHandler::RegisterMessages() {
49 web_ui()->RegisterMessageCallback("onSetWallpaperPageInitialized",
50 base::Bind(&SetWallpaperOptionsHandler::HandlePageInitialized,
51 base::Unretained(this)));
52 web_ui()->RegisterMessageCallback("onSetWallpaperPageShown",
53 base::Bind(&SetWallpaperOptionsHandler::HandlePageShown,
54 base::Unretained(this)));
55 web_ui()->RegisterMessageCallback("selectWallpaper",
56 base::Bind(&SetWallpaperOptionsHandler::HandleSelectImage,
57 base::Unretained(this)));
58 }
59
60 void SetWallpaperOptionsHandler::SendDefaultImages() {
61 ListValue image_urls;
62
63 for (int i = 0; i < ash::GetWallpaperCount(); ++i) {
64 image_urls.Append(Value::CreateStringValue(
65 web_ui_util::GetImageDataUrl(ash::GetWallpaperThumbnail(i))));
66 }
67
68 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages",
69 image_urls);
70 }
71
72 void SetWallpaperOptionsHandler::HandlePageInitialized(
73 const base::ListValue* args) {
74 DCHECK(args && args->empty());
75
76 SendDefaultImages();
77 }
78
79 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) {
80 DCHECK(args && args->empty());
81 chromeos::UserManager* user_manager = chromeos::UserManager::Get();
82 const chromeos::User& user = user_manager->GetLoggedInUser();
83 DCHECK(!user.email().empty());
84 int index = user_manager->GetUserWallpaper(user.email());
85 DCHECK(index >=0 && index < ash::GetWallpaperCount());
86 base::FundamentalValue index_value(index);
87 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage",
88 index_value);
89 }
90
91 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) {
92 std::string image_index_string;
93 int image_index;
94 if (!args ||
95 args->GetSize() != 1 ||
96 !args->GetString(0, &image_index_string) ||
97 !base::StringToInt(image_index_string, &image_index) ||
98 image_index < 0 || image_index >= ash::GetWallpaperCount())
99 NOTREACHED();
100
101 UserManager* user_manager = UserManager::Get();
102 const User& user = user_manager->GetLoggedInUser();
103 DCHECK(!user.email().empty());
104 user_manager->SaveWallpaperDefaultIndex(user.email(), image_index);
105 }
106
107 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const {
108 Browser* browser =
109 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui()));
110 if (!browser)
111 return NULL;
112 return browser->window()->GetNativeHandle();
113 }
114
115 } // namespace options2
116 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698