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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 void SetWallpaperOptionsHandler::GetLocalizedValues( | 40 void SetWallpaperOptionsHandler::GetLocalizedValues( |
41 DictionaryValue* localized_strings) { | 41 DictionaryValue* localized_strings) { |
42 DCHECK(localized_strings); | 42 DCHECK(localized_strings); |
43 localized_strings->SetString("setWallpaperPage", | 43 localized_strings->SetString("setWallpaperPage", |
44 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TITLE)); | 44 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TITLE)); |
45 localized_strings->SetString("setWallpaperPageDescription", | 45 localized_strings->SetString("setWallpaperPageDescription", |
46 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TEXT)); | 46 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_DIALOG_TEXT)); |
47 localized_strings->SetString("setWallpaperAuthor", | 47 localized_strings->SetString("setWallpaperAuthor", |
48 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_AUTHOR_TEXT)); | 48 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_AUTHOR_TEXT)); |
| 49 localized_strings->SetString("randomCheckbox", |
| 50 l10n_util::GetStringUTF16(IDS_OPTIONS_SET_WALLPAPER_RANDOM)); |
49 } | 51 } |
50 | 52 |
51 void SetWallpaperOptionsHandler::RegisterMessages() { | 53 void SetWallpaperOptionsHandler::RegisterMessages() { |
52 web_ui()->RegisterMessageCallback("onSetWallpaperPageInitialized", | 54 web_ui()->RegisterMessageCallback("onSetWallpaperPageInitialized", |
53 base::Bind(&SetWallpaperOptionsHandler::HandlePageInitialized, | 55 base::Bind(&SetWallpaperOptionsHandler::HandlePageInitialized, |
54 base::Unretained(this))); | 56 base::Unretained(this))); |
55 web_ui()->RegisterMessageCallback("onSetWallpaperPageShown", | 57 web_ui()->RegisterMessageCallback("onSetWallpaperPageShown", |
56 base::Bind(&SetWallpaperOptionsHandler::HandlePageShown, | 58 base::Bind(&SetWallpaperOptionsHandler::HandlePageShown, |
57 base::Unretained(this))); | 59 base::Unretained(this))); |
58 web_ui()->RegisterMessageCallback("selectWallpaper", | 60 web_ui()->RegisterMessageCallback("selectDefaultWallpaper", |
59 base::Bind(&SetWallpaperOptionsHandler::HandleSelectImage, | 61 base::Bind(&SetWallpaperOptionsHandler::HandleDefaultWallpaper, |
| 62 base::Unretained(this))); |
| 63 web_ui()->RegisterMessageCallback("selectRandomWallpaper", |
| 64 base::Bind(&SetWallpaperOptionsHandler::HandleRandomWallpaper, |
60 base::Unretained(this))); | 65 base::Unretained(this))); |
61 } | 66 } |
62 | 67 |
63 void SetWallpaperOptionsHandler::SendDefaultImages() { | 68 void SetWallpaperOptionsHandler::SendDefaultImages() { |
64 ListValue images; | 69 ListValue images; |
65 DictionaryValue* image_detail; | 70 DictionaryValue* image_detail; |
66 ash::WallpaperInfo image_info; | 71 ash::WallpaperInfo image_info; |
67 | 72 |
68 for (int i = 0; i < ash::GetWallpaperCount(); ++i) { | 73 for (int i = 0; i < ash::GetWallpaperCount(); ++i) { |
69 images.Append(image_detail = new DictionaryValue()); | 74 images.Append(image_detail = new DictionaryValue()); |
70 image_info = ash::GetWallpaperInfo(i); | 75 image_info = ash::GetWallpaperInfo(i); |
71 image_detail->SetString("url", GetDefaultWallpaperThumbnailURL(i)); | 76 image_detail->SetString("url", GetDefaultWallpaperThumbnailURL(i)); |
72 image_detail->SetString("author", image_info.author); | 77 image_detail->SetString("author", image_info.author); |
73 image_detail->SetString("website", image_info.website); | 78 image_detail->SetString("website", image_info.website); |
74 } | 79 } |
75 | 80 |
76 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages", | 81 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setDefaultImages", |
77 images); | 82 images); |
78 } | 83 } |
79 | 84 |
80 void SetWallpaperOptionsHandler::HandlePageInitialized( | 85 void SetWallpaperOptionsHandler::HandlePageInitialized( |
81 const base::ListValue* args) { | 86 const base::ListValue* args) { |
82 DCHECK(args && args->empty()); | 87 DCHECK(args && args->empty()); |
83 | 88 |
84 SendDefaultImages(); | 89 SendDefaultImages(); |
85 } | 90 } |
86 | 91 |
87 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { | 92 void SetWallpaperOptionsHandler::HandlePageShown(const base::ListValue* args) { |
88 DCHECK(args && args->empty()); | 93 DCHECK(args && args->empty()); |
89 int index = chromeos::UserManager::Get()->GetUserWallpaperIndex(); | 94 User::WallpaperType type; |
| 95 int index; |
| 96 UserManager::Get()->GetLoggedInUserWallpaperProperties(type, index); |
90 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); | 97 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); |
| 98 base::FundamentalValue is_random(type == User::RANDOM); |
91 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", | 99 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", |
92 image_url); | 100 image_url, is_random); |
93 } | 101 } |
94 | 102 |
95 void SetWallpaperOptionsHandler::HandleSelectImage(const ListValue* args) { | 103 void SetWallpaperOptionsHandler::HandleDefaultWallpaper(const ListValue* args) { |
96 std::string image_url; | 104 std::string image_url; |
97 if (!args || | 105 if (!args || |
98 args->GetSize() != 1 || | 106 args->GetSize() != 1 || |
99 !args->GetString(0, &image_url)) | 107 !args->GetString(0, &image_url)) |
100 NOTREACHED(); | 108 NOTREACHED(); |
101 | 109 |
102 if (image_url.empty()) | 110 if (image_url.empty()) |
103 return; | 111 return; |
104 | 112 |
105 int user_image_index; | 113 int user_image_index; |
106 if (IsDefaultWallpaperURL(image_url, &user_image_index)) { | 114 if (IsDefaultWallpaperURL(image_url, &user_image_index)) { |
107 UserManager::Get()->SaveUserWallpaperIndex(user_image_index); | 115 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::DEFAULT, |
| 116 user_image_index); |
108 ash::Shell::GetInstance()->desktop_background_controller()-> | 117 ash::Shell::GetInstance()->desktop_background_controller()-> |
109 SetLoggedInUserWallpaper(); | 118 SetLoggedInUserWallpaper(); |
110 } | 119 } |
111 } | 120 } |
112 | 121 |
| 122 void SetWallpaperOptionsHandler::HandleRandomWallpaper(const ListValue* args) { |
| 123 int index = ash::GetRandomWallpaperIndex(); |
| 124 UserManager::Get()->SaveLoggedInUserWallpaperProperties(User::RANDOM, index); |
| 125 ash::Shell::GetInstance()->desktop_background_controller()-> |
| 126 SetDefaultWallpaper(index); |
| 127 base::StringValue image_url(GetDefaultWallpaperThumbnailURL(index)); |
| 128 base::FundamentalValue is_random(true); |
| 129 web_ui()->CallJavascriptFunction("SetWallpaperOptions.setSelectedImage", |
| 130 image_url, is_random); |
| 131 } |
| 132 |
113 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { | 133 gfx::NativeWindow SetWallpaperOptionsHandler::GetBrowserWindow() const { |
114 Browser* browser = | 134 Browser* browser = |
115 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); | 135 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui())); |
116 if (!browser) | 136 if (!browser) |
117 return NULL; | 137 return NULL; |
118 return browser->window()->GetNativeHandle(); | 138 return browser->window()->GetNativeHandle(); |
119 } | 139 } |
120 | 140 |
121 } // namespace options2 | 141 } // namespace options2 |
122 } // namespace chromeos | 142 } // namespace chromeos |
OLD | NEW |