OLD | NEW |
---|---|
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/views/window.h" | 21 #include "chrome/browser/ui/views/window.h" |
22 #include "chrome/browser/ui/webui/web_ui_util.h" | 22 #include "chrome/browser/ui/webui/options2/chromeos/wallpaper_thumbnail_source2. h" |
23 #include "chrome/common/chrome_notification_types.h" | 23 #include "chrome/common/chrome_notification_types.h" |
24 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
25 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
29 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
30 | 30 |
31 namespace chromeos { | 31 namespace chromeos { |
32 namespace options2 { | 32 namespace options2 { |
(...skipping 25 matching lines...) Expand all Loading... | |
58 base::Unretained(this))); | 58 base::Unretained(this))); |
59 web_ui()->RegisterMessageCallback("selectWallpaper", | 59 web_ui()->RegisterMessageCallback("selectWallpaper", |
60 base::Bind(&SetWallpaperOptionsHandler::HandleSelectImage, | 60 base::Bind(&SetWallpaperOptionsHandler::HandleSelectImage, |
61 base::Unretained(this))); | 61 base::Unretained(this))); |
62 } | 62 } |
63 | 63 |
64 void SetWallpaperOptionsHandler::SendDefaultImages() { | 64 void SetWallpaperOptionsHandler::SendDefaultImages() { |
65 ListValue images; | 65 ListValue images; |
66 DictionaryValue* image_detail; | 66 DictionaryValue* image_detail; |
67 ash::WallpaperInfo image_info; | 67 ash::WallpaperInfo image_info; |
68 | |
James Hawkins
2012/04/20 19:40:17
Please don't make random whitespace changes like t
bshe
2012/04/20 21:11:43
Sorry. Didn't notice it. Thanks.
On 2012/04/20 19
| |
69 for (int i = 0; i < ash::GetWallpaperCount(); ++i) { | 68 for (int i = 0; i < ash::GetWallpaperCount(); ++i) { |
70 images.Append(image_detail = new DictionaryValue()); | 69 images.Append(image_detail = new DictionaryValue()); |
71 image_info = ash::GetWallpaperInfo(i); | 70 image_info = ash::GetWallpaperInfo(i); |
72 image_detail->SetString("url", web_ui_util::GetImageDataUrl( | 71 image_detail->SetString("url", GetDefaultWallpaperThumbnailURL(i)); |
73 ash::GetWallpaperThumbnail(i))); | |
74 image_detail->SetString("author", image_info.author); | 72 image_detail->SetString("author", image_info.author); |
75 image_detail->SetString("website", image_info.website); | 73 image_detail->SetString("website", image_info.website); |
76 } | 74 } |
77 | 75 |
78 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages", | 76 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages", |
79 images); | 77 images); |
80 } | 78 } |
81 | 79 |
82 void SetWallpaperOptionsHandler::HandlePageInitialized( | 80 void SetWallpaperOptionsHandler::HandlePageInitialized( |
83 const base::ListValue* args) { | 81 const base::ListValue* args) { |
84 DCHECK(args && args->empty()); | 82 DCHECK(args && args->empty()); |
85 | 83 |
86 SendDefaultImages(); | 84 SendDefaultImages(); |
87 } | 85 } |
88 | 86 |
89 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { | 87 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { |
90 DCHECK(args && args->empty()); | 88 DCHECK(args && args->empty()); |
91 int index = chromeos::UserManager::Get()->GetUserWallpaperIndex(); | 89 int index = chromeos::UserManager::Get()->GetUserWallpaperIndex(); |
92 base::FundamentalValue index_value(index); | 90 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); |
93 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", | 91 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", |
94 index_value); | 92 image_url); |
95 } | 93 } |
96 | 94 |
97 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) { | 95 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) { |
98 std::string image_index_string; | 96 std::string image_url; |
99 int image_index; | |
100 if (!args || | 97 if (!args || |
101 args->GetSize() != 1 || | 98 args->GetSize() != 1 || |
102 !args->GetString(0, &image_index_string) || | 99 !args->GetString(0, &image_url)) |
103 !base::StringToInt(image_index_string, &image_index) || | |
104 image_index < 0 || image_index >= ash::GetWallpaperCount()) | |
105 NOTREACHED(); | 100 NOTREACHED(); |
106 | 101 |
107 UserManager::Get()->SaveUserWallpaperIndex(image_index); | 102 if (image_url.empty()) |
108 ash::Shell::GetInstance()->desktop_background_controller()-> | 103 return; |
109 SetDesktopBackgroundImageMode(); | 104 |
105 int user_image_index; | |
106 if (IsDefaultWallpaperURL(image_url, &user_image_index)) { | |
107 UserManager::Get()->SaveUserWallpaperIndex(user_image_index); | |
108 ash::Shell::GetInstance()->desktop_background_controller()-> | |
109 SetDesktopBackgroundImageMode(); | |
110 } | |
110 } | 111 } |
111 | 112 |
112 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { | 113 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { |
113 Browser* browser = | 114 Browser* browser = |
114 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); | 115 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); |
115 if (!browser) | 116 if (!browser) |
116 return NULL; | 117 return NULL; |
117 return browser->window()->GetNativeHandle(); | 118 return browser->window()->GetNativeHandle(); |
118 } | 119 } |
119 | 120 |
120 } // namespace options2 | 121 } // namespace options2 |
121 } // namespace chromeos | 122 } // namespace chromeos |
OLD | NEW |