OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/options/manage_profile_handler.h" | 5 #include "chrome/browser/ui/webui/options/manage_profile_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/value_conversions.h" | 11 #include "base/value_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/profiles/profile_info_cache.h" | 14 #include "chrome/browser/profiles/profile_info_cache.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | 15 #include "chrome/browser/profiles/profile_manager.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "content/browser/tab_contents/tab_contents.h" | |
17 #include "content/common/notification_service.h" | 18 #include "content/common/notification_service.h" |
18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
19 | 20 |
20 ManageProfileHandler::ManageProfileHandler() { | 21 ManageProfileHandler::ManageProfileHandler() { |
21 } | 22 } |
22 | 23 |
23 ManageProfileHandler::~ManageProfileHandler() { | 24 ManageProfileHandler::~ManageProfileHandler() { |
24 } | 25 } |
25 | 26 |
26 void ManageProfileHandler::GetLocalizedValues( | 27 void ManageProfileHandler::GetLocalizedValues( |
(...skipping 10 matching lines...) Expand all Loading... | |
37 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL }, | 38 { "deleteProfileOK", IDS_PROFILES_DELETE_OK_BUTTON_LABEL }, |
38 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE }, | 39 { "deleteProfileMessage", IDS_PROFILES_DELETE_MESSAGE }, |
39 }; | 40 }; |
40 | 41 |
41 RegisterStrings(localized_strings, resources, arraysize(resources)); | 42 RegisterStrings(localized_strings, resources, arraysize(resources)); |
42 } | 43 } |
43 | 44 |
44 void ManageProfileHandler::Initialize() { | 45 void ManageProfileHandler::Initialize() { |
45 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 46 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
46 NotificationService::AllSources()); | 47 NotificationService::AllSources()); |
47 InitializeDefaultProfileIcons(); | |
48 SendProfileNames(); | 48 SendProfileNames(); |
49 } | 49 } |
50 | 50 |
51 void ManageProfileHandler::RegisterMessages() { | 51 void ManageProfileHandler::RegisterMessages() { |
52 web_ui_->RegisterMessageCallback("setProfileNameAndIcon", | 52 web_ui_->RegisterMessageCallback("setProfileNameAndIcon", |
53 base::Bind(&ManageProfileHandler::SetProfileNameAndIcon, | 53 base::Bind(&ManageProfileHandler::SetProfileNameAndIcon, |
54 base::Unretained(this))); | 54 base::Unretained(this))); |
55 web_ui_->RegisterMessageCallback("deleteProfile", | 55 web_ui_->RegisterMessageCallback("deleteProfile", |
56 base::Bind(&ManageProfileHandler::DeleteProfile, | 56 base::Bind(&ManageProfileHandler::DeleteProfile, |
57 base::Unretained(this))); | 57 base::Unretained(this))); |
58 web_ui_->RegisterMessageCallback("requestDefaultProfileIcons", | |
59 base::Bind(&ManageProfileHandler::RequestDefaultProfileIcons, | |
60 base::Unretained(this))); | |
61 web_ui_->RegisterMessageCallback("requestProfileInfo", | |
62 base::Bind(&ManageProfileHandler::RequestProfileInfo, | |
63 base::Unretained(this))); | |
58 } | 64 } |
59 | 65 |
60 void ManageProfileHandler::Observe(int type, | 66 void ManageProfileHandler::Observe(int type, |
61 const NotificationSource& source, | 67 const NotificationSource& source, |
62 const NotificationDetails& details) { | 68 const NotificationDetails& details) { |
63 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) | 69 if (type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) |
64 SendProfileNames(); | 70 SendProfileNames(); |
65 else | 71 else |
66 OptionsPageUIHandler::Observe(type, source, details); | 72 OptionsPageUIHandler::Observe(type, source, details); |
67 } | 73 } |
68 | 74 |
69 void ManageProfileHandler::InitializeDefaultProfileIcons() { | 75 void ManageProfileHandler::RequestDefaultProfileIcons(const ListValue* args) { |
70 ListValue image_url_list; | 76 ListValue image_url_list; |
71 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) { | 77 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) { |
72 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i); | 78 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i); |
73 image_url_list.Append(Value::CreateStringValue(url)); | 79 image_url_list.Append(Value::CreateStringValue(url)); |
74 } | 80 } |
75 | 81 |
76 web_ui_->CallJavascriptFunction( | 82 web_ui_->CallJavascriptFunction( |
77 "ManageProfileOverlay.receiveDefaultProfileIcons", | 83 "ManageProfileOverlay.receiveDefaultProfileIcons", |
78 image_url_list); | 84 image_url_list); |
79 } | 85 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 Value* file_path_value; | 128 Value* file_path_value; |
123 FilePath profile_file_path; | 129 FilePath profile_file_path; |
124 if (!args->Get(0, &file_path_value) || | 130 if (!args->Get(0, &file_path_value) || |
125 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) | 131 !base::GetValueAsFilePath(*file_path_value, &profile_file_path)) |
126 return; | 132 return; |
127 | 133 |
128 g_browser_process->profile_manager()->ScheduleProfileForDeletion( | 134 g_browser_process->profile_manager()->ScheduleProfileForDeletion( |
129 profile_file_path); | 135 profile_file_path); |
130 } | 136 } |
131 | 137 |
138 void ManageProfileHandler::RequestProfileInfo(const ListValue* args) { | |
139 DictionaryValue profile_value; | |
James Hawkins
2011/10/04 20:33:42
DCHECK(args);
binji
2011/10/04 21:39:56
Done.
| |
140 | |
141 Value* index_value; | |
142 double index_double; | |
143 if (!args->Get(0, &index_value) || !index_value->GetAsDouble(&index_double)) | |
144 return; | |
145 | |
146 int index = static_cast<int>(index_double); | |
147 | |
148 ProfileInfoCache& cache = | |
149 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
150 int profile_count = cache.GetNumberOfProfiles(); | |
151 if (index < 0 && index >= profile_count) | |
James Hawkins
2011/10/04 20:33:42
When would this happen?
binji
2011/10/04 21:39:56
The user can type "chrome://settings/manageProfile
| |
152 return; | |
153 | |
154 FilePath current_profile_path = | |
155 web_ui_->tab_contents()->browser_context()->GetPath(); | |
156 size_t icon_index = cache.GetAvatarIconIndexOfProfileAtIndex(index); | |
157 FilePath profile_path = cache.GetPathOfProfileAtIndex(index); | |
158 profile_value.SetString("name", cache.GetNameOfProfileAtIndex(index)); | |
159 profile_value.SetString("iconURL", | |
160 cache.GetDefaultAvatarIconUrl(icon_index)); | |
161 profile_value.Set("filePath", base::CreateFilePathValue(profile_path)); | |
162 profile_value.SetBoolean("isCurrentProfile", | |
163 profile_path == current_profile_path); | |
164 | |
165 web_ui_->CallJavascriptFunction("ManageProfileOverlay.setProfileInfo", | |
166 profile_value); | |
167 } | |
OLD | NEW |