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/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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "chrome/browser/prefs/pref_notifier.h" | 11 #include "chrome/browser/prefs/pref_notifier.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/sync/profile_sync_service.h" | 14 #include "chrome/browser/sync/profile_sync_service.h" |
15 #include "chrome/browser/sync/sync_setup_flow.h" | 15 #include "chrome/browser/sync/sync_setup_flow.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/browser/ui/webui/sync_promo_ui.h" | 20 #include "chrome/browser/ui/webui/sync_promo_ui.h" |
17 #include "chrome/common/chrome_notification_types.h" | 21 #include "chrome/common/chrome_notification_types.h" |
18 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
19 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
20 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
21 #include "content/common/notification_details.h" | 25 #include "content/common/notification_details.h" |
22 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
23 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
24 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
25 | 29 |
(...skipping 27 matching lines...) Expand all Loading... |
53 } | 57 } |
54 | 58 |
55 void NTPLoginHandler::HandleInitializeLogin(const ListValue* args) { | 59 void NTPLoginHandler::HandleInitializeLogin(const ListValue* args) { |
56 UpdateLogin(); | 60 UpdateLogin(); |
57 } | 61 } |
58 | 62 |
59 void NTPLoginHandler::HandleLoginContainerClicked(const ListValue* args) { | 63 void NTPLoginHandler::HandleLoginContainerClicked(const ListValue* args) { |
60 Profile* profile = Profile::FromWebUI(web_ui_); | 64 Profile* profile = Profile::FromWebUI(web_ui_); |
61 std::string username = profile->GetPrefs()->GetString( | 65 std::string username = profile->GetPrefs()->GetString( |
62 prefs::kGoogleServicesUsername); | 66 prefs::kGoogleServicesUsername); |
| 67 |
63 if (username.empty()) { | 68 if (username.empty()) { |
64 // The user isn't signed in, show the sync promo. | 69 // The user isn't signed in, show the sync promo. |
65 if (SyncPromoUI::ShouldShowSyncPromo()) { | 70 if (SyncPromoUI::ShouldShowSyncPromo()) { |
66 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUISyncPromoURL), | 71 web_ui_->tab_contents()->OpenURL(GURL(chrome::kChromeUISyncPromoURL), |
67 GURL(), CURRENT_TAB, | 72 GURL(), CURRENT_TAB, |
68 PageTransition::LINK); | 73 PageTransition::LINK); |
69 } | 74 } |
70 } else { | 75 } else if (args->GetSize() == 2) { |
71 // The user is signed in, show the profiles menu. | 76 // The user is signed in, show the profiles menu. |
72 // TODO(sail): Need to implement this. | 77 double x = 0; |
| 78 double y = 0; |
| 79 CHECK(args->GetDouble(0, &x)); |
| 80 CHECK(args->GetDouble(1, &y)); |
| 81 Browser* browser = GetBrowser(); |
| 82 if (!browser) |
| 83 return; |
| 84 browser->window()->ShowAvatarBubble(web_ui_->tab_contents(), x, y); |
73 } | 85 } |
74 } | 86 } |
75 | 87 |
76 void NTPLoginHandler::UpdateLogin() { | 88 void NTPLoginHandler::UpdateLogin() { |
77 std::string username = Profile::FromWebUI(web_ui_)->GetPrefs()->GetString( | 89 std::string username = Profile::FromWebUI(web_ui_)->GetPrefs()->GetString( |
78 prefs::kGoogleServicesUsername); | 90 prefs::kGoogleServicesUsername); |
79 string16 status1; | 91 string16 status1; |
80 string16 status2; | 92 string16 status2; |
81 if (!username.empty()) { | 93 if (!username.empty()) { |
82 status1 = UTF8ToUTF16(username); | 94 status1 = UTF8ToUTF16(username); |
(...skipping 10 matching lines...) Expand all Loading... |
93 bool NTPLoginHandler::ShouldShow(Profile* profile) { | 105 bool NTPLoginHandler::ShouldShow(Profile* profile) { |
94 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
95 return false; | 107 return false; |
96 #endif | 108 #endif |
97 | 109 |
98 if (profile->IsOffTheRecord()) | 110 if (profile->IsOffTheRecord()) |
99 return false; | 111 return false; |
100 | 112 |
101 return profile->GetOriginalProfile()->IsSyncAccessible(); | 113 return profile->GetOriginalProfile()->IsSyncAccessible(); |
102 } | 114 } |
| 115 |
| 116 Browser* NTPLoginHandler::GetBrowser() { |
| 117 for (TabContentsIterator it; !it.done(); ++it) { |
| 118 TabContents* tab = it->tab_contents(); |
| 119 if (tab == web_ui_->tab_contents()) |
| 120 return it.browser(); |
| 121 } |
| 122 return NULL; |
| 123 } |
OLD | NEW |