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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_login_handler.cc

Issue 8110003: Show avatar menu from NTP4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix mac build Created 9 years, 2 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
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.h ('k') | chrome/test/base/test_browser_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ntp/ntp_login_handler.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_login_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "base/values.h" 12 #include "base/values.h"
13 #include "chrome/browser/prefs/pref_notifier.h" 13 #include "chrome/browser/prefs/pref_notifier.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sync/profile_sync_service.h" 16 #include "chrome/browser/sync/profile_sync_service.h"
17 #include "chrome/browser/sync/sync_setup_flow.h" 17 #include "chrome/browser/sync/sync_setup_flow.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h"
21 #include "chrome/browser/ui/browser_window.h"
18 #include "chrome/browser/ui/webui/sync_promo_ui.h" 22 #include "chrome/browser/ui/webui/sync_promo_ui.h"
19 #include "chrome/common/chrome_notification_types.h" 23 #include "chrome/common/chrome_notification_types.h"
20 #include "chrome/common/pref_names.h" 24 #include "chrome/common/pref_names.h"
21 #include "chrome/common/url_constants.h" 25 #include "chrome/common/url_constants.h"
22 #include "content/browser/tab_contents/tab_contents.h" 26 #include "content/browser/tab_contents/tab_contents.h"
23 #include "content/common/notification_details.h" 27 #include "content/common/notification_details.h"
24 #include "grit/chromium_strings.h" 28 #include "grit/chromium_strings.h"
25 #include "grit/generated_resources.h" 29 #include "grit/generated_resources.h"
26 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
27 31
(...skipping 29 matching lines...) Expand all
57 } 61 }
58 62
59 void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) { 63 void NTPLoginHandler::HandleInitializeSyncLogin(const ListValue* args) {
60 UpdateLogin(); 64 UpdateLogin();
61 } 65 }
62 66
63 void NTPLoginHandler::HandleShowSyncLoginUI(const ListValue* args) { 67 void NTPLoginHandler::HandleShowSyncLoginUI(const ListValue* args) {
64 Profile* profile = Profile::FromWebUI(web_ui_); 68 Profile* profile = Profile::FromWebUI(web_ui_);
65 std::string username = profile->GetPrefs()->GetString( 69 std::string username = profile->GetPrefs()->GetString(
66 prefs::kGoogleServicesUsername); 70 prefs::kGoogleServicesUsername);
71
67 if (username.empty()) { 72 if (username.empty()) {
68 // The user isn't signed in, show the sync promo. 73 // The user isn't signed in, show the sync promo.
69 if (SyncPromoUI::ShouldShowSyncPromo(profile)) { 74 if (SyncPromoUI::ShouldShowSyncPromo(profile)) {
70 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUISyncPromoURL), 75 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUISyncPromoURL),
71 GURL(), CURRENT_TAB, 76 GURL(), CURRENT_TAB,
72 PageTransition::LINK); 77 PageTransition::LINK);
73 } 78 }
74 } else { 79 } else if (args->GetSize() == 4) {
75 // The user is signed in, show the profiles menu. 80 // The user is signed in, show the profiles menu.
76 // TODO(sail): Need to implement this. 81 Browser* browser = GetBrowser();
82 if (!browser)
83 return;
84 double x = 0;
85 double y = 0;
86 double width = 0;
87 double height = 0;
88 bool success = args->GetDouble(0, &x);
89 DCHECK(success);
90 success = args->GetDouble(1, &y);
91 DCHECK(success);
92 success = args->GetDouble(2, &width);
93 DCHECK(success);
94 success = args->GetDouble(3, &height);
95 DCHECK(success);
96 gfx::Rect rect(x, y, width, height);
97 browser->window()->ShowAvatarBubble(web_ui_->tab_contents(), rect);
77 } 98 }
78 } 99 }
79 100
80 void NTPLoginHandler::UpdateLogin() { 101 void NTPLoginHandler::UpdateLogin() {
81 Profile* profile = Profile::FromWebUI(web_ui_); 102 Profile* profile = Profile::FromWebUI(web_ui_);
82 std::string username = profile->GetPrefs()->GetString( 103 std::string username = profile->GetPrefs()->GetString(
83 prefs::kGoogleServicesUsername); 104 prefs::kGoogleServicesUsername);
84 string16 header, sub_header; 105 string16 header, sub_header;
85 if (!username.empty()) { 106 if (!username.empty()) {
86 header = UTF8ToUTF16(username); 107 header = UTF8ToUTF16(username);
(...skipping 20 matching lines...) Expand all
107 // For now we don't care about showing sync status on Chrome OS. The promo 128 // For now we don't care about showing sync status on Chrome OS. The promo
108 // UI and the avatar menu don't exist on that platform. 129 // UI and the avatar menu don't exist on that platform.
109 return false; 130 return false;
110 #else 131 #else
111 if (profile->IsOffTheRecord()) 132 if (profile->IsOffTheRecord())
112 return false; 133 return false;
113 134
114 return profile->GetOriginalProfile()->IsSyncAccessible(); 135 return profile->GetOriginalProfile()->IsSyncAccessible();
115 #endif 136 #endif
116 } 137 }
138
139 Browser* NTPLoginHandler::GetBrowser() {
140 for (TabContentsIterator it; !it.done(); ++it) {
141 TabContents* tab = it->tab_contents();
142 if (tab == web_ui_->tab_contents())
143 return it.browser();
144 }
145 return NULL;
146 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/ntp_login_handler.h ('k') | chrome/test/base/test_browser_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698