| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/prefs/pref_notifier.h" | 12 #include "base/prefs/pref_notifier.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/chrome_notification_types.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/profiles/profile_info_cache.h" | 18 #include "chrome/browser/profiles/profile_info_cache.h" |
| 20 #include "chrome/browser/profiles/profile_manager.h" | 19 #include "chrome/browser/profiles/profile_manager.h" |
| 21 #include "chrome/browser/profiles/profile_metrics.h" | 20 #include "chrome/browser/profiles/profile_metrics.h" |
| 22 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 23 #include "chrome/browser/signin/signin_promo.h" | 22 #include "chrome/browser/signin/signin_promo.h" |
| 24 #include "chrome/browser/sync/profile_sync_service.h" | 23 #include "chrome/browser/sync/profile_sync_service.h" |
| 25 #include "chrome/browser/sync/profile_sync_service_factory.h" | 24 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 26 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
| 27 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 28 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 29 #include "chrome/browser/ui/chrome_pages.h" | 28 #include "chrome/browser/ui/chrome_pages.h" |
| 30 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 29 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 31 #include "chrome/browser/web_resource/promo_resource_service.h" | 30 #include "chrome/browser/web_resource/promo_resource_service.h" |
| 32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
| 34 #include "chrome/grit/chromium_strings.h" | 33 #include "chrome/grit/chromium_strings.h" |
| 35 #include "chrome/grit/generated_resources.h" | 34 #include "chrome/grit/generated_resources.h" |
| 36 #include "components/signin/core/browser/signin_manager.h" | 35 #include "components/signin/core/browser/signin_manager.h" |
| 37 #include "content/public/browser/host_zoom_map.h" | 36 #include "content/public/browser/host_zoom_map.h" |
| 38 #include "content/public/browser/notification_details.h" | |
| 39 #include "content/public/browser/notification_service.h" | |
| 40 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
| 41 #include "content/public/browser/web_ui.h" | 38 #include "content/public/browser/web_ui.h" |
| 42 #include "content/public/common/page_zoom.h" | 39 #include "content/public/common/page_zoom.h" |
| 43 #include "net/base/escape.h" | 40 #include "net/base/escape.h" |
| 44 #include "skia/ext/image_operations.h" | 41 #include "skia/ext/image_operations.h" |
| 45 #include "ui/base/l10n/l10n_util.h" | 42 #include "ui/base/l10n/l10n_util.h" |
| 46 #include "ui/base/webui/web_ui_util.h" | 43 #include "ui/base/webui/web_ui_util.h" |
| 47 #include "ui/gfx/canvas.h" | 44 #include "ui/gfx/canvas.h" |
| 48 #include "ui/gfx/image/image.h" | 45 #include "ui/gfx/image/image.h" |
| 49 | 46 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 75 return base::ASCIIToUTF16("<span class='" + css_class + "'>") + | 72 return base::ASCIIToUTF16("<span class='" + css_class + "'>") + |
| 76 net::EscapeForHTML(content) + base::ASCIIToUTF16("</span>"); | 73 net::EscapeForHTML(content) + base::ASCIIToUTF16("</span>"); |
| 77 } | 74 } |
| 78 | 75 |
| 79 } // namespace | 76 } // namespace |
| 80 | 77 |
| 81 NTPLoginHandler::NTPLoginHandler() { | 78 NTPLoginHandler::NTPLoginHandler() { |
| 82 } | 79 } |
| 83 | 80 |
| 84 NTPLoginHandler::~NTPLoginHandler() { | 81 NTPLoginHandler::~NTPLoginHandler() { |
| 82 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 83 // The profile_manager might be NULL in testing environments. |
| 84 if (profile_manager) |
| 85 profile_manager->GetProfileInfoCache().RemoveObserver(this); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void NTPLoginHandler::RegisterMessages() { | 88 void NTPLoginHandler::RegisterMessages() { |
| 89 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 90 // The profile_manager might be NULL in testing environments. |
| 91 if (profile_manager) |
| 92 profile_manager->GetProfileInfoCache().AddObserver(this); |
| 93 |
| 88 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 94 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 89 signin_allowed_pref_.Init(prefs::kSigninAllowed, | 95 signin_allowed_pref_.Init(prefs::kSigninAllowed, |
| 90 pref_service, | 96 pref_service, |
| 91 base::Bind(&NTPLoginHandler::UpdateLogin, | 97 base::Bind(&NTPLoginHandler::UpdateLogin, |
| 92 base::Unretained(this))); | 98 base::Unretained(this))); |
| 93 | 99 |
| 94 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | |
| 95 content::NotificationService::AllSources()); | |
| 96 | |
| 97 web_ui()->RegisterMessageCallback("initializeSyncLogin", | 100 web_ui()->RegisterMessageCallback("initializeSyncLogin", |
| 98 base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin, | 101 base::Bind(&NTPLoginHandler::HandleInitializeSyncLogin, |
| 99 base::Unretained(this))); | 102 base::Unretained(this))); |
| 100 web_ui()->RegisterMessageCallback("showSyncLoginUI", | 103 web_ui()->RegisterMessageCallback("showSyncLoginUI", |
| 101 base::Bind(&NTPLoginHandler::HandleShowSyncLoginUI, | 104 base::Bind(&NTPLoginHandler::HandleShowSyncLoginUI, |
| 102 base::Unretained(this))); | 105 base::Unretained(this))); |
| 103 web_ui()->RegisterMessageCallback("loginMessageSeen", | 106 web_ui()->RegisterMessageCallback("loginMessageSeen", |
| 104 base::Bind(&NTPLoginHandler::HandleLoginMessageSeen, | 107 base::Bind(&NTPLoginHandler::HandleLoginMessageSeen, |
| 105 base::Unretained(this))); | 108 base::Unretained(this))); |
| 106 web_ui()->RegisterMessageCallback("showAdvancedLoginUI", | 109 web_ui()->RegisterMessageCallback("showAdvancedLoginUI", |
| 107 base::Bind(&NTPLoginHandler::HandleShowAdvancedLoginUI, | 110 base::Bind(&NTPLoginHandler::HandleShowAdvancedLoginUI, |
| 108 base::Unretained(this))); | 111 base::Unretained(this))); |
| 109 } | 112 } |
| 110 | 113 |
| 111 void NTPLoginHandler::Observe(int type, | 114 void NTPLoginHandler::OnProfileUserNameChanged( |
| 112 const content::NotificationSource& source, | 115 const base::FilePath& profile_path) { |
| 113 const content::NotificationDetails& details) { | |
| 114 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, type); | |
| 115 UpdateLogin(); | 116 UpdateLogin(); |
| 116 } | 117 } |
| 117 | 118 |
| 118 void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) { | 119 void NTPLoginHandler::HandleInitializeSyncLogin(const base::ListValue* args) { |
| 119 UpdateLogin(); | 120 UpdateLogin(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { | 123 void NTPLoginHandler::HandleShowSyncLoginUI(const base::ListValue* args) { |
| 123 Profile* profile = Profile::FromWebUI(web_ui()); | 124 Profile* profile = Profile::FromWebUI(web_ui()); |
| 124 if (!signin::ShouldShowPromo(profile)) | 125 if (!signin::ShouldShowPromo(profile)) |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 values->SetString("login_status_message", message); | 253 values->SetString("login_status_message", message); |
| 253 values->SetString("login_status_url", | 254 values->SetString("login_status_url", |
| 254 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); | 255 hide_sync ? std::string() : chrome::kSyncLearnMoreURL); |
| 255 values->SetString("login_status_advanced", | 256 values->SetString("login_status_advanced", |
| 256 hide_sync ? base::string16() : | 257 hide_sync ? base::string16() : |
| 257 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); | 258 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_ADVANCED)); |
| 258 values->SetString("login_status_dismiss", | 259 values->SetString("login_status_dismiss", |
| 259 hide_sync ? base::string16() : | 260 hide_sync ? base::string16() : |
| 260 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); | 261 l10n_util::GetStringUTF16(IDS_SYNC_PROMO_NTP_BUBBLE_OK)); |
| 261 } | 262 } |
| OLD | NEW |