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

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

Issue 10021066: Replace the index mapping of wallpaper picker UI and hard coded wallpaper index in C++ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge to trunk Created 8 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handle r2.h" 5 #include "chrome/browser/ui/webui/options2/chromeos/set_wallpaper_options_handle r2.h"
6 6
7 #include "ash/desktop_background/desktop_background_controller.h" 7 #include "ash/desktop_background/desktop_background_controller.h"
8 #include "ash/desktop_background/desktop_background_resources.h" 8 #include "ash/desktop_background/desktop_background_resources.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
12 #include "base/metrics/histogram.h" 12 #include "base/metrics/histogram.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "chrome/browser/chromeos/login/user_manager.h" 17 #include "chrome/browser/chromeos/login/user_manager.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
20 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
21 #include "chrome/browser/ui/webui/web_ui_util.h" 21 #include "chrome/browser/ui/views/window.h"
22 #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2. h"
22 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
23 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/web_ui.h" 25 #include "content/public/browser/web_ui.h"
25 #include "grit/generated_resources.h" 26 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
27 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/views/widget/widget.h" 29 #include "ui/views/widget/widget.h"
29 30
30 namespace chromeos { 31 namespace chromeos {
31 namespace options2 { 32 namespace options2 {
(...skipping 29 matching lines...) Expand all
61 } 62 }
62 63
63 void SetWallpaperOptionsHandler::SendDefaultImages() { 64 void SetWallpaperOptionsHandler::SendDefaultImages() {
64 ListValue images; 65 ListValue images;
65 DictionaryValue* image_detail; 66 DictionaryValue* image_detail;
66 ash::WallpaperInfo image_info; 67 ash::WallpaperInfo image_info;
67 68
68 for (int i = 0; i < ash::GetWallpaperCount(); ++i) { 69 for (int i = 0; i < ash::GetWallpaperCount(); ++i) {
69 images.Append(image_detail = new DictionaryValue()); 70 images.Append(image_detail = new DictionaryValue());
70 image_info = ash::GetWallpaperInfo(i); 71 image_info = ash::GetWallpaperInfo(i);
71 image_detail->SetString("url", web_ui_util::GetImageDataUrl( 72 image_detail->SetString("url", GetDefaultWallpaperThumbnailURL(i));
72 ash::GetWallpaperThumbnail(i)));
73 image_detail->SetString("author", image_info.author); 73 image_detail->SetString("author", image_info.author);
74 image_detail->SetString("website", image_info.website); 74 image_detail->SetString("website", image_info.website);
75 } 75 }
76 76
77 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages", 77 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages",
78 images); 78 images);
79 } 79 }
80 80
81 void SetWallpaperOptionsHandler::HandlePageInitialized( 81 void SetWallpaperOptionsHandler::HandlePageInitialized(
82 const base::ListValue* args) { 82 const base::ListValue* args) {
83 DCHECK(args && args->empty()); 83 DCHECK(args && args->empty());
84 84
85 SendDefaultImages(); 85 SendDefaultImages();
86 } 86 }
87 87
88 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { 88 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) {
89 DCHECK(args && args->empty()); 89 DCHECK(args && args->empty());
90 int index = chromeos::UserManager::Get()->GetUserWallpaperIndex(); 90 int index = chromeos::UserManager::Get()->GetUserWallpaperIndex();
91 base::FundamentalValue index_value(index); 91 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index));
92 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", 92 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage",
93 index_value); 93 image_url);
94 } 94 }
95 95
96 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) { 96 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) {
97 std::string image_index_string; 97 std::string image_url;
98 int image_index;
99 if (!args || 98 if (!args ||
100 args->GetSize() != 1 || 99 args->GetSize() != 1 ||
101 !args->GetString(0, &image_index_string) || 100 !args->GetString(0, &image_url))
102 !base::StringToInt(image_index_string, &image_index) ||
103 image_index < 0 || image_index >= ash::GetWallpaperCount())
104 NOTREACHED(); 101 NOTREACHED();
105 102
106 UserManager::Get()->SaveUserWallpaperIndex(image_index); 103 if (image_url.empty())
107 ash::Shell::GetInstance()->desktop_background_controller()-> 104 return;
108 SetDesktopBackgroundImageMode(); 105
106 int user_image_index;
107 if (IsDefaultWallpaperURL(image_url, &user_image_index)) {
108 UserManager::Get()->SaveUserWallpaperIndex(user_image_index);
109 ash::Shell::GetInstance()->desktop_background_controller()->
110 SetDesktopBackgroundImageMode();
111 }
109 } 112 }
110 113
111 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { 114 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const {
112 Browser* browser = 115 Browser* browser =
113 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); 116 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui()));
114 if (!browser) 117 if (!browser)
115 return NULL; 118 return NULL;
116 return browser->window()->GetNativeHandle(); 119 return browser->window()->GetNativeHandle();
117 } 120 }
118 121
119 } // namespace options2 122 } // namespace options2
120 } // namespace chromeos 123 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698