| 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/options/sync_setup_handler.h" | 5 #include "chrome/browser/ui/webui/options/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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "chrome/browser/ui/browser_window.h" | 32 #include "chrome/browser/ui/browser_window.h" |
| 33 #include "chrome/browser/ui/singleton_tabs.h" | 33 #include "chrome/browser/ui/singleton_tabs.h" |
| 34 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" | 34 #include "chrome/browser/ui/webui/options/options_handlers_helper.h" |
| 35 #include "chrome/browser/ui/webui/signin/login_ui_service.h" | 35 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 36 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 36 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 37 #include "chrome/common/chrome_switches.h" | 37 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/url_constants.h" | 38 #include "chrome/common/url_constants.h" |
| 39 #include "chrome/grit/chromium_strings.h" | 39 #include "chrome/grit/chromium_strings.h" |
| 40 #include "chrome/grit/generated_resources.h" | 40 #include "chrome/grit/generated_resources.h" |
| 41 #include "chrome/grit/locale_settings.h" | 41 #include "chrome/grit/locale_settings.h" |
| 42 #include "components/autofill/core/common/autofill_pref_names.h" |
| 42 #include "components/browser_sync/browser/profile_sync_service.h" | 43 #include "components/browser_sync/browser/profile_sync_service.h" |
| 43 #include "components/google/core/browser/google_util.h" | 44 #include "components/google/core/browser/google_util.h" |
| 44 #include "components/signin/core/browser/signin_error_controller.h" | 45 #include "components/signin/core/browser/signin_error_controller.h" |
| 45 #include "components/signin/core/browser/signin_header_helper.h" | 46 #include "components/signin/core/browser/signin_header_helper.h" |
| 46 #include "components/signin/core/browser/signin_metrics.h" | 47 #include "components/signin/core/browser/signin_metrics.h" |
| 47 #include "components/signin/core/common/profile_management_switches.h" | 48 #include "components/signin/core/common/profile_management_switches.h" |
| 48 #include "components/sync_driver/sync_prefs.h" | 49 #include "components/sync_driver/sync_prefs.h" |
| 49 #include "content/public/browser/render_view_host.h" | 50 #include "content/public/browser/render_view_host.h" |
| 50 #include "content/public/browser/web_contents.h" | 51 #include "content/public/browser/web_contents.h" |
| 51 #include "content/public/browser/web_contents_delegate.h" | 52 #include "content/public/browser/web_contents_delegate.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 69 | 70 |
| 70 // A structure which contains all the configuration information for sync. | 71 // A structure which contains all the configuration information for sync. |
| 71 struct SyncConfigInfo { | 72 struct SyncConfigInfo { |
| 72 SyncConfigInfo(); | 73 SyncConfigInfo(); |
| 73 ~SyncConfigInfo(); | 74 ~SyncConfigInfo(); |
| 74 | 75 |
| 75 bool encrypt_all; | 76 bool encrypt_all; |
| 76 bool sync_everything; | 77 bool sync_everything; |
| 77 bool sync_nothing; | 78 bool sync_nothing; |
| 78 syncer::ModelTypeSet data_types; | 79 syncer::ModelTypeSet data_types; |
| 80 bool payments_integration_enabled; |
| 79 std::string passphrase; | 81 std::string passphrase; |
| 80 bool passphrase_is_gaia; | 82 bool passphrase_is_gaia; |
| 81 }; | 83 }; |
| 82 | 84 |
| 83 SyncConfigInfo::SyncConfigInfo() | 85 SyncConfigInfo::SyncConfigInfo() |
| 84 : encrypt_all(false), | 86 : encrypt_all(false), |
| 85 sync_everything(false), | 87 sync_everything(false), |
| 86 sync_nothing(false), | 88 sync_nothing(false), |
| 87 passphrase_is_gaia(false) { | 89 payments_integration_enabled(false), |
| 88 } | 90 passphrase_is_gaia(false) {} |
| 89 | 91 |
| 90 SyncConfigInfo::~SyncConfigInfo() {} | 92 SyncConfigInfo::~SyncConfigInfo() {} |
| 91 | 93 |
| 92 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { | 94 bool GetConfiguration(const std::string& json, SyncConfigInfo* config) { |
| 93 scoped_ptr<base::Value> parsed_value = base::JSONReader::Read(json); | 95 scoped_ptr<base::Value> parsed_value = base::JSONReader::Read(json); |
| 94 base::DictionaryValue* result; | 96 base::DictionaryValue* result; |
| 95 if (!parsed_value || !parsed_value->GetAsDictionary(&result)) { | 97 if (!parsed_value || !parsed_value->GetAsDictionary(&result)) { |
| 96 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; | 98 DLOG(ERROR) << "GetConfiguration() not passed a Dictionary"; |
| 97 return false; | 99 return false; |
| 98 } | 100 } |
| 99 | 101 |
| 100 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { | 102 if (!result->GetBoolean("syncAllDataTypes", &config->sync_everything)) { |
| 101 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; | 103 DLOG(ERROR) << "GetConfiguration() not passed a syncAllDataTypes value"; |
| 102 return false; | 104 return false; |
| 103 } | 105 } |
| 104 | 106 |
| 105 if (!result->GetBoolean("syncNothing", &config->sync_nothing)) { | 107 if (!result->GetBoolean("syncNothing", &config->sync_nothing)) { |
| 106 DLOG(ERROR) << "GetConfiguration() not passed a syncNothing value"; | 108 DLOG(ERROR) << "GetConfiguration() not passed a syncNothing value"; |
| 107 return false; | 109 return false; |
| 108 } | 110 } |
| 109 | 111 |
| 110 DCHECK(!(config->sync_everything && config->sync_nothing)) | 112 DCHECK(!(config->sync_everything && config->sync_nothing)) |
| 111 << "syncAllDataTypes and syncNothing cannot both be true"; | 113 << "syncAllDataTypes and syncNothing cannot both be true"; |
| 112 | 114 |
| 115 if (!result->GetBoolean("paymentsIntegrationEnabled", |
| 116 &config->payments_integration_enabled)) { |
| 117 DLOG(ERROR) << "GetConfiguration() not passed a paymentsIntegrationEnabled " |
| 118 << "value"; |
| 119 return false; |
| 120 } |
| 121 |
| 113 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); | 122 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); |
| 114 | 123 |
| 115 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); | 124 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); |
| 116 it != type_names.end(); ++it) { | 125 it != type_names.end(); ++it) { |
| 117 std::string key_name = it->second + std::string("Synced"); | 126 std::string key_name = it->second + std::string("Synced"); |
| 118 bool sync_value; | 127 bool sync_value; |
| 119 if (!result->GetBoolean(key_name, &sync_value)) { | 128 if (!result->GetBoolean(key_name, &sync_value)) { |
| 120 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; | 129 DLOG(ERROR) << "GetConfiguration() not passed a value for " << key_name; |
| 121 return false; | 130 return false; |
| 122 } | 131 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS }, | 241 { "bookmarks", IDS_SYNC_DATATYPE_BOOKMARKS }, |
| 233 { "preferences", IDS_SYNC_DATATYPE_PREFERENCES }, | 242 { "preferences", IDS_SYNC_DATATYPE_PREFERENCES }, |
| 234 { "autofill", IDS_SYNC_DATATYPE_AUTOFILL }, | 243 { "autofill", IDS_SYNC_DATATYPE_AUTOFILL }, |
| 235 { "themes", IDS_SYNC_DATATYPE_THEMES }, | 244 { "themes", IDS_SYNC_DATATYPE_THEMES }, |
| 236 { "passwords", IDS_SYNC_DATATYPE_PASSWORDS }, | 245 { "passwords", IDS_SYNC_DATATYPE_PASSWORDS }, |
| 237 { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS }, | 246 { "extensions", IDS_SYNC_DATATYPE_EXTENSIONS }, |
| 238 { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS }, | 247 { "typedURLs", IDS_SYNC_DATATYPE_TYPED_URLS }, |
| 239 { "apps", IDS_SYNC_DATATYPE_APPS }, | 248 { "apps", IDS_SYNC_DATATYPE_APPS }, |
| 240 { "wifiCredentials", IDS_SYNC_DATATYPE_WIFI_CREDENTIALS }, | 249 { "wifiCredentials", IDS_SYNC_DATATYPE_WIFI_CREDENTIALS }, |
| 241 { "openTabs", IDS_SYNC_DATATYPE_TABS }, | 250 { "openTabs", IDS_SYNC_DATATYPE_TABS }, |
| 251 { "enablePaymentsIntegration", IDS_AUTOFILL_USE_PAYMENTS_DATA }, |
| 242 { "serviceUnavailableError", IDS_SYNC_SETUP_ABORTED_BY_PENDING_CLEAR }, | 252 { "serviceUnavailableError", IDS_SYNC_SETUP_ABORTED_BY_PENDING_CLEAR }, |
| 243 { "confirmLabel", IDS_SYNC_CONFIRM_PASSPHRASE_LABEL }, | 253 { "confirmLabel", IDS_SYNC_CONFIRM_PASSPHRASE_LABEL }, |
| 244 { "emptyErrorMessage", IDS_SYNC_EMPTY_PASSPHRASE_ERROR }, | 254 { "emptyErrorMessage", IDS_SYNC_EMPTY_PASSPHRASE_ERROR }, |
| 245 { "mismatchErrorMessage", IDS_SYNC_PASSPHRASE_MISMATCH_ERROR }, | 255 { "mismatchErrorMessage", IDS_SYNC_PASSPHRASE_MISMATCH_ERROR }, |
| 246 { "customizeLinkLabel", IDS_SYNC_CUSTOMIZE_LINK_LABEL }, | 256 { "customizeLinkLabel", IDS_SYNC_CUSTOMIZE_LINK_LABEL }, |
| 247 { "confirmSyncPreferences", IDS_SYNC_CONFIRM_SYNC_PREFERENCES }, | 257 { "confirmSyncPreferences", IDS_SYNC_CONFIRM_SYNC_PREFERENCES }, |
| 248 { "syncEverything", IDS_SYNC_SYNC_EVERYTHING }, | 258 { "syncEverything", IDS_SYNC_SYNC_EVERYTHING }, |
| 249 { "useDefaultSettings", IDS_SYNC_USE_DEFAULT_SETTINGS }, | 259 { "useDefaultSettings", IDS_SYNC_USE_DEFAULT_SETTINGS }, |
| 250 { "enterPassphraseBody", IDS_SYNC_ENTER_PASSPHRASE_BODY }, | 260 { "enterPassphraseBody", IDS_SYNC_ENTER_PASSPHRASE_BODY }, |
| 251 { "enterGooglePassphraseBody", IDS_SYNC_ENTER_GOOGLE_PASSPHRASE_BODY }, | 261 { "enterGooglePassphraseBody", IDS_SYNC_ENTER_GOOGLE_PASSPHRASE_BODY }, |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 ProfileSyncService::EXPLICIT); | 571 ProfileSyncService::EXPLICIT); |
| 562 } | 572 } |
| 563 } | 573 } |
| 564 } | 574 } |
| 565 | 575 |
| 566 bool user_was_prompted_for_passphrase = | 576 bool user_was_prompted_for_passphrase = |
| 567 service->IsPassphraseRequiredForDecryption(); | 577 service->IsPassphraseRequiredForDecryption(); |
| 568 service->OnUserChoseDatatypes(configuration.sync_everything, | 578 service->OnUserChoseDatatypes(configuration.sync_everything, |
| 569 configuration.data_types); | 579 configuration.data_types); |
| 570 | 580 |
| 581 PrefService* pref_service = GetProfile()->GetPrefs(); |
| 582 pref_service->SetBoolean(autofill::prefs::kAutofillWalletImportEnabled, |
| 583 configuration.payments_integration_enabled); |
| 584 |
| 571 // Need to call IsPassphraseRequiredForDecryption() *after* calling | 585 // Need to call IsPassphraseRequiredForDecryption() *after* calling |
| 572 // OnUserChoseDatatypes() because the user may have just disabled the | 586 // OnUserChoseDatatypes() because the user may have just disabled the |
| 573 // encrypted datatypes (in which case we just want to exit, not prompt the | 587 // encrypted datatypes (in which case we just want to exit, not prompt the |
| 574 // user for a passphrase). | 588 // user for a passphrase). |
| 575 if (passphrase_failed || service->IsPassphraseRequiredForDecryption()) { | 589 if (passphrase_failed || service->IsPassphraseRequiredForDecryption()) { |
| 576 // We need a passphrase, or the user's attempt to set a passphrase failed - | 590 // We need a passphrase, or the user's attempt to set a passphrase failed - |
| 577 // prompt them again. This covers a few subtle cases: | 591 // prompt them again. This covers a few subtle cases: |
| 578 // 1) The user enters an incorrect passphrase *and* disabled the encrypted | 592 // 1) The user enters an incorrect passphrase *and* disabled the encrypted |
| 579 // data types. In that case we want to notify the user that the | 593 // data types. In that case we want to notify the user that the |
| 580 // passphrase was incorrect even though there are no longer any encrypted | 594 // passphrase was incorrect even though there are no longer any encrypted |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 sync_startup_tracker_.reset(); | 852 sync_startup_tracker_.reset(); |
| 839 configuring_sync_ = true; | 853 configuring_sync_ = true; |
| 840 DCHECK(service->IsBackendInitialized()) | 854 DCHECK(service->IsBackendInitialized()) |
| 841 << "Cannot configure sync until the sync backend is initialized"; | 855 << "Cannot configure sync until the sync backend is initialized"; |
| 842 | 856 |
| 843 // Setup args for the sync configure screen: | 857 // Setup args for the sync configure screen: |
| 844 // syncAllDataTypes: true if the user wants to sync everything | 858 // syncAllDataTypes: true if the user wants to sync everything |
| 845 // syncNothing: true if the user wants to sync nothing | 859 // syncNothing: true if the user wants to sync nothing |
| 846 // <data_type>Registered: true if the associated data type is supported | 860 // <data_type>Registered: true if the associated data type is supported |
| 847 // <data_type>Synced: true if the user wants to sync that specific data type | 861 // <data_type>Synced: true if the user wants to sync that specific data type |
| 862 // paymentsIntegrationEnabled: true if the user wants Payments integration |
| 848 // encryptionEnabled: true if sync supports encryption | 863 // encryptionEnabled: true if sync supports encryption |
| 849 // encryptAllData: true if user wants to encrypt all data (not just | 864 // encryptAllData: true if user wants to encrypt all data (not just |
| 850 // passwords) | 865 // passwords) |
| 851 // usePassphrase: true if the data is encrypted with a secondary passphrase | 866 // usePassphrase: true if the data is encrypted with a secondary passphrase |
| 852 // show_passphrase: true if a passphrase is needed to decrypt the sync data | 867 // show_passphrase: true if a passphrase is needed to decrypt the sync data |
| 853 base::DictionaryValue args; | 868 base::DictionaryValue args; |
| 854 | 869 |
| 855 // Tell the UI layer which data types are registered/enabled by the user. | 870 // Tell the UI layer which data types are registered/enabled by the user. |
| 856 const syncer::ModelTypeSet registered_types = | 871 const syncer::ModelTypeSet registered_types = |
| 857 service->GetRegisteredDataTypes(); | 872 service->GetRegisteredDataTypes(); |
| 858 const syncer::ModelTypeSet preferred_types = service->GetPreferredDataTypes(); | 873 const syncer::ModelTypeSet preferred_types = service->GetPreferredDataTypes(); |
| 859 const syncer::ModelTypeSet enforced_types = service->GetForcedDataTypes(); | 874 const syncer::ModelTypeSet enforced_types = service->GetForcedDataTypes(); |
| 860 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); | 875 syncer::ModelTypeNameMap type_names = syncer::GetUserSelectableTypeNameMap(); |
| 861 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); | 876 for (syncer::ModelTypeNameMap::const_iterator it = type_names.begin(); |
| 862 it != type_names.end(); ++it) { | 877 it != type_names.end(); ++it) { |
| 863 syncer::ModelType sync_type = it->first; | 878 syncer::ModelType sync_type = it->first; |
| 864 const std::string key_name = it->second; | 879 const std::string key_name = it->second; |
| 865 args.SetBoolean(key_name + "Registered", registered_types.Has(sync_type)); | 880 args.SetBoolean(key_name + "Registered", registered_types.Has(sync_type)); |
| 866 args.SetBoolean(key_name + "Synced", preferred_types.Has(sync_type)); | 881 args.SetBoolean(key_name + "Synced", preferred_types.Has(sync_type)); |
| 867 args.SetBoolean(key_name + "Enforced", enforced_types.Has(sync_type)); | 882 args.SetBoolean(key_name + "Enforced", enforced_types.Has(sync_type)); |
| 868 // TODO(treib): How do we want to handle pref groups, i.e. when only some of | 883 // TODO(treib): How do we want to handle pref groups, i.e. when only some of |
| 869 // the sync types behind a checkbox are force-enabled? crbug.com/403326 | 884 // the sync types behind a checkbox are force-enabled? crbug.com/403326 |
| 870 } | 885 } |
| 871 sync_driver::SyncPrefs sync_prefs(GetProfile()->GetPrefs()); | 886 PrefService* pref_service = GetProfile()->GetPrefs(); |
| 887 sync_driver::SyncPrefs sync_prefs(pref_service); |
| 872 args.SetBoolean("passphraseFailed", passphrase_failed); | 888 args.SetBoolean("passphraseFailed", passphrase_failed); |
| 873 args.SetBoolean("syncAllDataTypes", sync_prefs.HasKeepEverythingSynced()); | 889 args.SetBoolean("syncAllDataTypes", sync_prefs.HasKeepEverythingSynced()); |
| 874 args.SetBoolean("syncNothing", false); // Always false during initial setup. | 890 args.SetBoolean("syncNothing", false); // Always false during initial setup. |
| 891 args.SetBoolean( |
| 892 "paymentsIntegrationEnabled", |
| 893 pref_service->GetBoolean(autofill::prefs::kAutofillWalletImportEnabled)); |
| 875 args.SetBoolean("encryptAllData", service->IsEncryptEverythingEnabled()); | 894 args.SetBoolean("encryptAllData", service->IsEncryptEverythingEnabled()); |
| 876 args.SetBoolean("encryptAllDataAllowed", | 895 args.SetBoolean("encryptAllDataAllowed", |
| 877 service->IsEncryptEverythingAllowed()); | 896 service->IsEncryptEverythingAllowed()); |
| 878 | 897 |
| 879 // We call IsPassphraseRequired() here, instead of calling | 898 // We call IsPassphraseRequired() here, instead of calling |
| 880 // IsPassphraseRequiredForDecryption(), because we want to show the passphrase | 899 // IsPassphraseRequiredForDecryption(), because we want to show the passphrase |
| 881 // UI even if no encrypted data types are enabled. | 900 // UI even if no encrypted data types are enabled. |
| 882 args.SetBoolean("showPassphrase", service->IsPassphraseRequired()); | 901 args.SetBoolean("showPassphrase", service->IsPassphraseRequired()); |
| 883 | 902 |
| 884 // To distinguish between FROZEN_IMPLICIT_PASSPHRASE and CUSTOM_PASSPHRASE | 903 // To distinguish between FROZEN_IMPLICIT_PASSPHRASE and CUSTOM_PASSPHRASE |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 "SyncSetupOverlay.showSyncSetupPage", page, args); | 951 "SyncSetupOverlay.showSyncSetupPage", page, args); |
| 933 | 952 |
| 934 // Make sure the tab used for the Gaia sign in does not cover the settings | 953 // Make sure the tab used for the Gaia sign in does not cover the settings |
| 935 // tab. | 954 // tab. |
| 936 FocusUI(); | 955 FocusUI(); |
| 937 } | 956 } |
| 938 | 957 |
| 939 LoginUIService* SyncSetupHandler::GetLoginUIService() const { | 958 LoginUIService* SyncSetupHandler::GetLoginUIService() const { |
| 940 return LoginUIServiceFactory::GetForProfile(GetProfile()); | 959 return LoginUIServiceFactory::GetForProfile(GetProfile()); |
| 941 } | 960 } |
| OLD | NEW |