Chromium Code Reviews| 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() == 4) { |
| 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 Browser* browser = GetBrowser(); |
| 78 if (!browser) | |
| 79 return; | |
| 80 double x = 0; | |
| 81 double y = 0; | |
| 82 double width = 0; | |
| 83 double height = 0; | |
| 84 CHECK(args->GetDouble(0, &x)); | |
|
James Hawkins
2011/10/05 16:37:32
Why are these CHECKs?
sail
2011/10/05 16:40:54
I just copy pasted these from else where. Should I
James Hawkins
2011/10/05 16:43:53
Yes. CHECK should only be used to debug problems i
sail
2011/10/05 16:58:31
Fixed by using DCHECK(success) instead.
| |
| 85 CHECK(args->GetDouble(1, &y)); | |
| 86 CHECK(args->GetDouble(2, &width)); | |
| 87 CHECK(args->GetDouble(3, &height)); | |
| 88 gfx::Rect rect(x, y, width, height); | |
| 89 browser->window()->ShowAvatarBubble(web_ui_->tab_contents(), rect); | |
| 73 } | 90 } |
| 74 } | 91 } |
| 75 | 92 |
| 76 void NTPLoginHandler::UpdateLogin() { | 93 void NTPLoginHandler::UpdateLogin() { |
| 77 std::string username = Profile::FromWebUI(web_ui_)->GetPrefs()->GetString( | 94 std::string username = Profile::FromWebUI(web_ui_)->GetPrefs()->GetString( |
| 78 prefs::kGoogleServicesUsername); | 95 prefs::kGoogleServicesUsername); |
| 79 string16 status1; | 96 string16 status1; |
| 80 string16 status2; | 97 string16 status2; |
| 81 if (!username.empty()) { | 98 if (!username.empty()) { |
| 82 status1 = UTF8ToUTF16(username); | 99 status1 = UTF8ToUTF16(username); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 93 bool NTPLoginHandler::ShouldShow(Profile* profile) { | 110 bool NTPLoginHandler::ShouldShow(Profile* profile) { |
| 94 #if defined(OS_CHROMEOS) | 111 #if defined(OS_CHROMEOS) |
| 95 return false; | 112 return false; |
| 96 #endif | 113 #endif |
| 97 | 114 |
| 98 if (profile->IsOffTheRecord()) | 115 if (profile->IsOffTheRecord()) |
| 99 return false; | 116 return false; |
| 100 | 117 |
| 101 return profile->GetOriginalProfile()->IsSyncAccessible(); | 118 return profile->GetOriginalProfile()->IsSyncAccessible(); |
| 102 } | 119 } |
| 120 | |
| 121 Browser* NTPLoginHandler::GetBrowser() { | |
| 122 for (TabContentsIterator it; !it.done(); ++it) { | |
| 123 TabContents* tab = it->tab_contents(); | |
| 124 if (tab == web_ui_->tab_contents()) | |
| 125 return it.browser(); | |
| 126 } | |
| 127 return NULL; | |
| 128 } | |
| OLD | NEW |