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

Side by Side Diff: chrome/browser/ui/webui/new_profile_dom_handler.cc

Issue 7275026: Revert 90820 - Multi-Profiles: New Profile Setup UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 5 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) 2011 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/new_profile_dom_handler.h"
6
7 #include "base/string_number_conversions.h"
8 #include "base/values.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/profiles/profile_info_cache.h"
12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/common/url_constants.h"
14 #include "content/browser/tab_contents/tab_contents.h"
15
16 NewProfileDOMHandler::NewProfileDOMHandler() {
17 }
18
19 void NewProfileDOMHandler::RegisterMessages() {
20 web_ui_->RegisterMessageCallback("create",
21 NewCallback(this, &NewProfileDOMHandler::HandleCreate));
22 web_ui_->RegisterMessageCallback("cancel",
23 NewCallback(this, &NewProfileDOMHandler::HandleCancel));
24 web_ui_->RegisterMessageCallback("requestProfileInfo",
25 NewCallback(this, &NewProfileDOMHandler::HandleRequestProfileInfo));
26 }
27
28 void NewProfileDOMHandler::HandleCreate(const ListValue* args) {
29 string16 profile_name;
30 bool ret = args->GetString(0, &profile_name);
31 if (!ret || profile_name.empty())
32 return;
33
34 std::string string_index;
35 ret = args->GetString(1, &string_index);
36 if (!ret || string_index.empty())
37 return;
38 int profile_avatar_index;
39 if (!base::StringToInt(string_index, &profile_avatar_index))
40 return;
41
42 ProfileInfoCache& cache =
43 g_browser_process->profile_manager()->GetProfileInfoCache();
44 size_t index = cache.GetIndexOfProfileWithPath(
45 web_ui_->GetProfile()->GetPath());
46 if (index != std::string::npos) {
47 cache.SetNameOfProfileAtIndex(index, profile_name);
48 cache.SetAvatarIconOfProfileAtIndex(index, profile_avatar_index);
49 }
50
51 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUINewTabURL),
52 GURL(), CURRENT_TAB,
53 PageTransition::LINK);
54 }
55
56 void NewProfileDOMHandler::HandleCancel(const ListValue* args) {
57 // TODO(sail): delete this profile.
58 }
59
60 void NewProfileDOMHandler::HandleRequestProfileInfo(const ListValue* args) {
61 SendDefaultAvatarImages();
62 SendProfileInfo();
63 }
64
65 void NewProfileDOMHandler::SendDefaultAvatarImages() {
66 ListValue image_url_list;
67 for (size_t i = 0; i < ProfileInfoCache::GetDefaultAvatarIconCount(); i++) {
68 std::string url = ProfileInfoCache::GetDefaultAvatarIconUrl(i);
69 image_url_list.Append(Value::CreateStringValue(url));
70 }
71 web_ui_->CallJavascriptFunction("setDefaultAvatarImages", image_url_list);
72 }
73
74 void NewProfileDOMHandler::SendProfileInfo() {
75 ProfileInfoCache& cache =
76 g_browser_process->profile_manager()->GetProfileInfoCache();
77 size_t index = cache.GetIndexOfProfileWithPath(
78 web_ui_->GetProfile()->GetPath());
79 if (index != std::string::npos) {
80 StringValue profile_name(cache.GetNameOfProfileAtIndex(index));
81 FundamentalValue profile_icon_index(static_cast<int>(
82 cache.GetAvatarIconIndexOfProfileAtIndex(index)));
83 web_ui_->CallJavascriptFunction("setProfileInfo",
84 profile_name,
85 profile_icon_index);
86 }
87 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/new_profile_dom_handler.h ('k') | chrome/browser/ui/webui/new_profile_ui.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698