| 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/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/sync_setup_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.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/google/google_util.h" | 13 #include "chrome/browser/google/google_util.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/profiles/profile_info_cache.h" | 15 #include "chrome/browser/profiles/profile_info_cache.h" |
| 16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 17 #include "chrome/browser/profiles/profile_metrics.h" | 17 #include "chrome/browser/profiles/profile_metrics.h" |
| 18 #include "chrome/browser/sync/profile_sync_service.h" | 18 #include "chrome/browser/sync/profile_sync_service.h" |
| 19 #include "chrome/browser/sync/protocol/service_constants.h" | 19 #include "chrome/browser/sync/protocol/service_constants.h" |
| 20 #include "chrome/browser/sync/signin_manager.h" | 20 #include "chrome/browser/sync/signin_manager.h" |
| 21 #include "chrome/browser/sync/sync_setup_flow.h" | 21 #include "chrome/browser/sync/sync_setup_flow.h" |
| 22 #include "chrome/browser/sync/util/oauth.h" | 22 #include "chrome/browser/sync/util/oauth.h" |
| 23 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
| 24 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" | 24 #include "chrome/browser/ui/webui/sync_promo/sync_promo_trial.h" |
| 25 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" | 25 #include "chrome/browser/ui/webui/sync_promo/sync_promo_ui.h" |
| 26 #include "chrome/common/net/gaia/gaia_constants.h" | 26 #include "chrome/common/net/gaia/gaia_constants.h" |
| 27 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 28 #include "content/browser/tab_contents/tab_contents.h" | 28 #include "content/browser/renderer_host/render_view_host.h" |
| 29 #include "content/browser/renderer_host/render_view_host_delegate.h" |
| 30 #include "content/public/browser/web_contents.h" |
| 29 #include "grit/chromium_strings.h" | 31 #include "grit/chromium_strings.h" |
| 30 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
| 31 #include "grit/locale_settings.h" | 33 #include "grit/locale_settings.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 33 | 35 |
| 34 using l10n_util::GetStringFUTF16; | 36 using l10n_util::GetStringFUTF16; |
| 35 using l10n_util::GetStringUTF16; | 37 using l10n_util::GetStringUTF16; |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); | 239 GetStringUTF16(IDS_SHORT_PRODUCT_NAME))); |
| 238 localized_strings->SetString( | 240 localized_strings->SetString( |
| 239 "syncEverythingHelpURL", | 241 "syncEverythingHelpURL", |
| 240 google_util::StringAppendGoogleLocaleParam( | 242 google_util::StringAppendGoogleLocaleParam( |
| 241 chrome::kSyncEverythingLearnMoreURL)); | 243 chrome::kSyncEverythingLearnMoreURL)); |
| 242 | 244 |
| 243 // The experimental body string only appears if we are on the launch page | 245 // The experimental body string only appears if we are on the launch page |
| 244 // version of the Sync Promo. | 246 // version of the Sync Promo. |
| 245 int message_body_resource_id = IDS_SYNC_PROMO_MESSAGE_BODY_A; | 247 int message_body_resource_id = IDS_SYNC_PROMO_MESSAGE_BODY_A; |
| 246 if (web_ui && SyncPromoUI::GetIsLaunchPageForSyncPromoURL( | 248 if (web_ui && SyncPromoUI::GetIsLaunchPageForSyncPromoURL( |
| 247 web_ui->tab_contents()->GetURL())) { | 249 web_ui->web_contents()->GetURL())) { |
| 248 message_body_resource_id = sync_promo_trial::GetMessageBodyResID(); | 250 message_body_resource_id = sync_promo_trial::GetMessageBodyResID(); |
| 249 } | 251 } |
| 250 localized_strings->SetString( | 252 localized_strings->SetString( |
| 251 "promoMessageBody", | 253 "promoMessageBody", |
| 252 GetStringUTF16(message_body_resource_id)); | 254 GetStringUTF16(message_body_resource_id)); |
| 253 | 255 |
| 254 std::string create_account_url = google_util::StringAppendGoogleLocaleParam( | 256 std::string create_account_url = google_util::StringAppendGoogleLocaleParam( |
| 255 chrome::kSyncCreateNewAccountURL); | 257 chrome::kSyncCreateNewAccountURL); |
| 256 string16 create_account = GetStringUTF16(IDS_SYNC_CREATE_ACCOUNT); | 258 string16 create_account = GetStringUTF16(IDS_SYNC_CREATE_ACCOUNT); |
| 257 create_account= UTF8ToUTF16("<a id='create-account-link' target='_blank' " | 259 create_account= UTF8ToUTF16("<a id='create-account-link' target='_blank' " |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 FilePath profile_file_path = profile->GetPath(); | 446 FilePath profile_file_path = profile->GetPath(); |
| 445 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); | 447 ProfileMetrics::LogProfileSyncSignIn(profile_file_path); |
| 446 } | 448 } |
| 447 } | 449 } |
| 448 | 450 |
| 449 void SyncSetupHandler::SetFlow(SyncSetupFlow* flow) { | 451 void SyncSetupHandler::SetFlow(SyncSetupFlow* flow) { |
| 450 flow_ = flow; | 452 flow_ = flow; |
| 451 } | 453 } |
| 452 | 454 |
| 453 void SyncSetupHandler::Focus() { | 455 void SyncSetupHandler::Focus() { |
| 454 static_cast<RenderViewHostDelegate*>(web_ui()->tab_contents())->Activate(); | 456 web_ui()->web_contents()->GetRenderViewHost()->delegate()->Activate(); |
| 455 } | 457 } |
| 456 | 458 |
| 457 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { | 459 void SyncSetupHandler::OnDidClosePage(const ListValue* args) { |
| 458 CloseSyncSetup(); | 460 CloseSyncSetup(); |
| 459 } | 461 } |
| 460 | 462 |
| 461 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { | 463 void SyncSetupHandler::HandleSubmitAuth(const ListValue* args) { |
| 462 std::string json; | 464 std::string json; |
| 463 if (!args->GetString(0, &json)) { | 465 if (!args->GetString(0, &json)) { |
| 464 NOTREACHED() << "Could not read JSON argument"; | 466 NOTREACHED() << "Could not read JSON argument"; |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } | 662 } |
| 661 | 663 |
| 662 void SyncSetupHandler::ShowLoginErrorMessage(const string16& error_message) { | 664 void SyncSetupHandler::ShowLoginErrorMessage(const string16& error_message) { |
| 663 DictionaryValue args; | 665 DictionaryValue args; |
| 664 Profile* profile = Profile::FromWebUI(web_ui()); | 666 Profile* profile = Profile::FromWebUI(web_ui()); |
| 665 ProfileSyncService* service = profile->GetProfileSyncService(); | 667 ProfileSyncService* service = profile->GetProfileSyncService(); |
| 666 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); | 668 SyncSetupFlow::GetArgsForGaiaLogin(service, &args); |
| 667 args.SetString("error_message", error_message); | 669 args.SetString("error_message", error_message); |
| 668 ShowGaiaLogin(args); | 670 ShowGaiaLogin(args); |
| 669 } | 671 } |
| OLD | NEW |