OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/autofill/autofill_dialog_controller_impl.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base64.h" | |
10 #include "base/bind.h" | 11 #include "base/bind.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 19 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
19 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
(...skipping 1391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1411 | 1412 |
1412 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { | 1413 const AutofillMetrics& AutofillDialogControllerImpl::GetMetricLogger() const { |
1413 return metric_logger_; | 1414 return metric_logger_; |
1414 } | 1415 } |
1415 | 1416 |
1416 DialogType AutofillDialogControllerImpl::GetDialogType() const { | 1417 DialogType AutofillDialogControllerImpl::GetDialogType() const { |
1417 return dialog_type_; | 1418 return dialog_type_; |
1418 } | 1419 } |
1419 | 1420 |
1420 std::string AutofillDialogControllerImpl::GetRiskData() const { | 1421 std::string AutofillDialogControllerImpl::GetRiskData() const { |
1421 // TODO(dbeam): Implement this. | 1422 // TODO(dbeam): remove the server restriction that this must not be empty. |
1422 return "risky business"; | 1423 return risk_data_; |
1423 } | 1424 } |
1424 | 1425 |
1425 void AutofillDialogControllerImpl::OnDidAcceptLegalDocuments() { | 1426 void AutofillDialogControllerImpl::OnDidAcceptLegalDocuments() { |
1426 // TODO(dbeam): Don't send risk params until legal documents are accepted: | 1427 legal_documents_are_current_ = true; |
1427 // http://crbug.com/173505 | 1428 LoadRiskFingerprintData(); |
1428 } | 1429 } |
1429 | 1430 |
1430 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { | 1431 void AutofillDialogControllerImpl::OnDidAuthenticateInstrument(bool success) { |
1431 DCHECK(is_submitting_ && IsPayingWithWallet()); | 1432 DCHECK(is_submitting_ && IsPayingWithWallet()); |
1432 | 1433 |
1433 // TODO(dbeam): use the returned full wallet. b/8332329 | 1434 // TODO(dbeam): use the returned full wallet. b/8332329 |
1434 if (success) | 1435 if (success) |
1435 GetFullWallet(); | 1436 GetFullWallet(); |
1436 else | 1437 else |
1437 DisableWallet(); | 1438 DisableWallet(); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1496 } | 1497 } |
1497 | 1498 |
1498 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 1499 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
1499 scoped_ptr<wallet::WalletItems> wallet_items) { | 1500 scoped_ptr<wallet::WalletItems> wallet_items) { |
1500 DCHECK(account_chooser_model_.WalletIsSelected()); | 1501 DCHECK(account_chooser_model_.WalletIsSelected()); |
1501 legal_documents_text_.clear(); | 1502 legal_documents_text_.clear(); |
1502 legal_document_link_ranges_.clear(); | 1503 legal_document_link_ranges_.clear(); |
1503 | 1504 |
1504 // TODO(dbeam): verify items support kCartCurrency? http://crbug.com/232952 | 1505 // TODO(dbeam): verify items support kCartCurrency? http://crbug.com/232952 |
1505 wallet_items_ = wallet_items.Pass(); | 1506 wallet_items_ = wallet_items.Pass(); |
1507 | |
1508 legal_documents_are_current_ = wallet_items_->legal_documents().empty(); | |
1509 if (legal_documents_are_current_) | |
1510 LoadRiskFingerprintData(); | |
1511 | |
1506 OnWalletOrSigninUpdate(); | 1512 OnWalletOrSigninUpdate(); |
1507 } | 1513 } |
1508 | 1514 |
1509 void AutofillDialogControllerImpl::OnDidSaveAddress( | 1515 void AutofillDialogControllerImpl::OnDidSaveAddress( |
1510 const std::string& address_id, | 1516 const std::string& address_id, |
1511 const std::vector<wallet::RequiredAction>& required_actions) { | 1517 const std::vector<wallet::RequiredAction>& required_actions) { |
1512 // TODO(dbeam): handle required actions. http://crbug.com/163508 | 1518 // TODO(dbeam): handle required actions. http://crbug.com/163508 |
1513 active_address_id_ = address_id; | 1519 active_address_id_ = address_id; |
1514 GetFullWallet(); | 1520 GetFullWallet(); |
1515 } | 1521 } |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1666 wallet_client_(profile_->GetRequestContext(), this), | 1672 wallet_client_(profile_->GetRequestContext(), this), |
1667 suggested_email_(this), | 1673 suggested_email_(this), |
1668 suggested_cc_(this), | 1674 suggested_cc_(this), |
1669 suggested_billing_(this), | 1675 suggested_billing_(this), |
1670 suggested_cc_billing_(this), | 1676 suggested_cc_billing_(this), |
1671 suggested_shipping_(this), | 1677 suggested_shipping_(this), |
1672 input_showing_popup_(NULL), | 1678 input_showing_popup_(NULL), |
1673 weak_ptr_factory_(this), | 1679 weak_ptr_factory_(this), |
1674 is_first_run_(!profile_->GetPrefs()->HasPrefPath( | 1680 is_first_run_(!profile_->GetPrefs()->HasPrefPath( |
1675 ::prefs::kAutofillDialogPayWithoutWallet)), | 1681 ::prefs::kAutofillDialogPayWithoutWallet)), |
1682 legal_documents_are_current_(false), | |
1676 is_submitting_(false), | 1683 is_submitting_(false), |
1677 autocheckout_is_running_(false), | 1684 autocheckout_is_running_(false), |
1678 had_autocheckout_error_(false), | 1685 had_autocheckout_error_(false), |
1679 was_ui_latency_logged_(false) { | 1686 was_ui_latency_logged_(false) { |
1680 // TODO(estade): remove duplicates from |form_structure|? | 1687 // TODO(estade): remove duplicates from |form_structure|? |
1681 DCHECK(!callback_.is_null()); | 1688 DCHECK(!callback_.is_null()); |
1682 } | 1689 } |
1683 | 1690 |
1684 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { | 1691 AutofillDialogView* AutofillDialogControllerImpl::CreateView() { |
1685 return AutofillDialogView::Create(this); | 1692 return AutofillDialogView::Create(this); |
1686 } | 1693 } |
1687 | 1694 |
1688 PersonalDataManager* AutofillDialogControllerImpl::GetManager() { | 1695 PersonalDataManager* AutofillDialogControllerImpl::GetManager() { |
1689 return PersonalDataManagerFactory::GetForProfile(profile_); | 1696 return PersonalDataManagerFactory::GetForProfile(profile_); |
1690 } | 1697 } |
1691 | 1698 |
1692 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { | 1699 wallet::WalletClient* AutofillDialogControllerImpl::GetWalletClient() { |
1693 return &wallet_client_; | 1700 return &wallet_client_; |
1694 } | 1701 } |
1695 | 1702 |
1696 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { | 1703 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { |
1697 return account_chooser_model_.WalletIsSelected() && | 1704 return account_chooser_model_.WalletIsSelected() && |
1698 SignedInState() == SIGNED_IN; | 1705 SignedInState() == SIGNED_IN; |
1699 } | 1706 } |
1700 | 1707 |
1701 bool AutofillDialogControllerImpl::IsFirstRun() const { | 1708 bool AutofillDialogControllerImpl::IsFirstRun() const { |
1702 return is_first_run_; | 1709 return is_first_run_; |
1703 } | 1710 } |
1704 | 1711 |
1712 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { | |
1713 if (!legal_documents_are_current_) | |
1714 return; | |
1715 | |
1716 uint64 obfuscated_gaia_id = 0; | |
1717 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), | |
1718 &obfuscated_gaia_id); | |
1719 DCHECK(success); | |
1720 | |
1721 gfx::Rect window_bounds; | |
1722 #if !defined(OS_ANDROID) | |
1723 window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds(); | |
1724 #else | |
1725 // TODO(dbeam): figure out the correct browser window size to pass along for | |
1726 // android. | |
1727 #endif | |
1728 | |
1729 PrefService* user_prefs = profile_->GetPrefs(); | |
1730 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); | |
1731 std::string accept_languages = | |
1732 user_prefs->GetString(::prefs::kAcceptLanguages); | |
1733 base::Time install_time = base::Time::FromTimeT( | |
1734 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); | |
1735 | |
1736 risk::GetFingerprint( | |
1737 obfuscated_gaia_id, window_bounds, *web_contents(), | |
1738 chrome::VersionInfo().Version(), charset, accept_languages, install_time, | |
1739 dialog_type_, g_browser_process->GetApplicationLocale(), | |
1740 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, | |
1741 weak_ptr_factory_.GetWeakPtr())); | |
1742 } | |
1743 | |
1744 void AutofillDialogControllerImpl::SerializeFingerprint( | |
1745 risk::Fingerprint* fingerprint, std::string* data) { | |
1746 fingerprint->SerializeToString(data); | |
1747 } | |
1748 | |
1705 void AutofillDialogControllerImpl::DisableWallet() { | 1749 void AutofillDialogControllerImpl::DisableWallet() { |
1706 signin_helper_.reset(); | 1750 signin_helper_.reset(); |
1707 account_chooser_model_.SetHadWalletError(); | 1751 account_chooser_model_.SetHadWalletError(); |
1708 GetWalletClient()->CancelRequests(); | 1752 GetWalletClient()->CancelRequests(); |
1709 wallet_items_.reset(); | 1753 wallet_items_.reset(); |
1710 full_wallet_.reset(); | 1754 full_wallet_.reset(); |
1711 SetIsSubmitting(false); | 1755 SetIsSubmitting(false); |
1712 } | 1756 } |
1713 | 1757 |
1714 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 1758 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2016 DialogSection section) { | 2060 DialogSection section) { |
2017 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 2061 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
2018 } | 2062 } |
2019 | 2063 |
2020 void AutofillDialogControllerImpl::HidePopup() { | 2064 void AutofillDialogControllerImpl::HidePopup() { |
2021 if (popup_controller_) | 2065 if (popup_controller_) |
2022 popup_controller_->Hide(); | 2066 popup_controller_->Hide(); |
2023 input_showing_popup_ = NULL; | 2067 input_showing_popup_ = NULL; |
2024 } | 2068 } |
2025 | 2069 |
2026 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { | |
2027 // TODO(dbeam): Add a CHECK or otherwise strong guarantee that the ToS have | |
2028 // been accepted prior to calling into this method. Also, ensure that the UI | |
Dan Beam
2013/05/07 04:02:50
why do we care if risk data is *loaded*? we care
Ilya Sherman
2013/05/07 09:11:41
Yes, what we really care about is whether it's sen
Ilya Sherman
2013/05/07 09:25:03
Actually, belay that. It looks like determining t
| |
2029 // contains a clear indication to the user as to what data will be collected. | |
2030 // Until then, this code should not be called. http://crbug.com/173505 | |
2031 | |
2032 int64 gaia_id = 0; | |
2033 bool success = | |
2034 base::StringToInt64(wallet_items_->obfuscated_gaia_id(), &gaia_id); | |
2035 DCHECK(success); | |
2036 | |
2037 gfx::Rect window_bounds = | |
2038 GetBaseWindowForWebContents(web_contents())->GetBounds(); | |
2039 | |
2040 PrefService* user_prefs = profile_->GetPrefs(); | |
2041 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); | |
2042 std::string accept_languages = | |
2043 user_prefs->GetString(::prefs::kAcceptLanguages); | |
2044 base::Time install_time = base::Time::FromTimeT( | |
2045 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); | |
2046 | |
2047 risk::GetFingerprint( | |
2048 gaia_id, window_bounds, *web_contents(), chrome::VersionInfo().Version(), | |
2049 charset, accept_languages, install_time, dialog_type_, | |
2050 g_browser_process->GetApplicationLocale(), | |
2051 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, | |
2052 weak_ptr_factory_.GetWeakPtr())); | |
2053 } | |
2054 | |
2055 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( | 2070 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( |
2056 scoped_ptr<risk::Fingerprint> fingerprint) { | 2071 scoped_ptr<risk::Fingerprint> fingerprint) { |
2057 NOTIMPLEMENTED(); | 2072 if (!legal_documents_are_current_) |
2073 return; | |
2074 | |
2075 std::string proto_data; | |
2076 SerializeFingerprint(fingerprint.get(), &proto_data); | |
2077 bool success = base::Base64Encode(proto_data, &risk_data_); | |
2078 DCHECK(success); | |
2058 } | 2079 } |
2059 | 2080 |
2060 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 2081 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
2061 DialogSection section) const { | 2082 DialogSection section) const { |
2062 std::map<DialogSection, bool>::const_iterator it = | 2083 std::map<DialogSection, bool>::const_iterator it = |
2063 section_editing_state_.find(section); | 2084 section_editing_state_.find(section); |
2064 return (it != section_editing_state_.end() && it->second) || | 2085 return (it != section_editing_state_.end() && it->second) || |
2065 SuggestionsMenuModelForSection(section)-> | 2086 SuggestionsMenuModelForSection(section)-> |
2066 GetItemKeyForCheckedItem() == kAddNewItemKey; | 2087 GetItemKeyForCheckedItem() == kAddNewItemKey; |
2067 } | 2088 } |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2384 url, | 2405 url, |
2385 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 2406 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
2386 params.disposition = NEW_FOREGROUND_TAB; | 2407 params.disposition = NEW_FOREGROUND_TAB; |
2387 chrome::Navigate(¶ms); | 2408 chrome::Navigate(¶ms); |
2388 #else | 2409 #else |
2389 // TODO(estade): use TabModelList? | 2410 // TODO(estade): use TabModelList? |
2390 #endif | 2411 #endif |
2391 } | 2412 } |
2392 | 2413 |
2393 } // namespace autofill | 2414 } // namespace autofill |
OLD | NEW |