Chromium Code Reviews| 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_.empty() ? "risky business" : risk_data_; |
|
Ilya Sherman
2013/05/03 07:38:31
Why can risk_data_ be empty? We shouldn't issue r
Dan Beam
2013/05/03 09:24:47
Failed encoding, not loaded yet (there's nothing t
Ilya Sherman
2013/05/07 00:59:30
We should structure the code so that it's guarante
| |
| 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_docs_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_docs_current_ = wallet_items_->legal_documents().empty(); | |
| 1509 if (legal_docs_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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1695 | 1701 |
| 1696 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { | 1702 bool AutofillDialogControllerImpl::IsPayingWithWallet() const { |
| 1697 return account_chooser_model_.WalletIsSelected() && | 1703 return account_chooser_model_.WalletIsSelected() && |
| 1698 SignedInState() == SIGNED_IN; | 1704 SignedInState() == SIGNED_IN; |
| 1699 } | 1705 } |
| 1700 | 1706 |
| 1701 bool AutofillDialogControllerImpl::IsFirstRun() const { | 1707 bool AutofillDialogControllerImpl::IsFirstRun() const { |
| 1702 return is_first_run_; | 1708 return is_first_run_; |
| 1703 } | 1709 } |
| 1704 | 1710 |
| 1711 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { | |
| 1712 if (!legal_docs_current_) | |
| 1713 return; | |
|
Ilya Sherman
2013/05/03 07:38:31
Can this be a DCHECK instead?
Dan Beam
2013/05/03 09:24:47
A DCHECK() is not a strong assurance in release bu
Ilya Sherman
2013/05/07 00:59:30
DCHECKs are used to document expected state. Unle
Dan Beam
2013/05/07 04:02:50
Done.
| |
| 1714 | |
| 1715 uint64 obfuscated_gaia_id = 0; | |
| 1716 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), | |
| 1717 &obfuscated_gaia_id); | |
| 1718 DCHECK(success); | |
| 1719 | |
| 1720 gfx::Rect window_bounds = | |
| 1721 GetBaseWindowForWebContents(web_contents())->GetBounds(); | |
| 1722 | |
| 1723 PrefService* user_prefs = profile_->GetPrefs(); | |
| 1724 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); | |
| 1725 std::string accept_languages = | |
| 1726 user_prefs->GetString(::prefs::kAcceptLanguages); | |
| 1727 base::Time install_time = base::Time::FromTimeT( | |
| 1728 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); | |
| 1729 | |
| 1730 risk::GetFingerprint( | |
| 1731 obfuscated_gaia_id, window_bounds, *web_contents(), | |
| 1732 chrome::VersionInfo().Version(), charset, accept_languages, install_time, | |
| 1733 dialog_type_, g_browser_process->GetApplicationLocale(), | |
| 1734 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, | |
| 1735 weak_ptr_factory_.GetWeakPtr())); | |
| 1736 } | |
| 1737 | |
| 1738 void AutofillDialogControllerImpl::SerializeFingerprint( | |
| 1739 risk::Fingerprint* fingerprint, std::string* data) { | |
| 1740 fingerprint->SerializeToString(data); | |
| 1741 } | |
| 1742 | |
| 1705 void AutofillDialogControllerImpl::DisableWallet() { | 1743 void AutofillDialogControllerImpl::DisableWallet() { |
| 1706 signin_helper_.reset(); | 1744 signin_helper_.reset(); |
| 1707 account_chooser_model_.SetHadWalletError(); | 1745 account_chooser_model_.SetHadWalletError(); |
| 1708 GetWalletClient()->CancelRequests(); | 1746 GetWalletClient()->CancelRequests(); |
| 1709 wallet_items_.reset(); | 1747 wallet_items_.reset(); |
| 1710 full_wallet_.reset(); | 1748 full_wallet_.reset(); |
| 1711 SetIsSubmitting(false); | 1749 SetIsSubmitting(false); |
| 1712 } | 1750 } |
| 1713 | 1751 |
| 1714 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 1752 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2016 DialogSection section) { | 2054 DialogSection section) { |
| 2017 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); | 2055 return const_cast<DetailInputs*>(&RequestedFieldsForSection(section)); |
| 2018 } | 2056 } |
| 2019 | 2057 |
| 2020 void AutofillDialogControllerImpl::HidePopup() { | 2058 void AutofillDialogControllerImpl::HidePopup() { |
| 2021 if (popup_controller_) | 2059 if (popup_controller_) |
| 2022 popup_controller_->Hide(); | 2060 popup_controller_->Hide(); |
| 2023 input_showing_popup_ = NULL; | 2061 input_showing_popup_ = NULL; |
| 2024 } | 2062 } |
| 2025 | 2063 |
| 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 | |
| 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( | 2064 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( |
| 2056 scoped_ptr<risk::Fingerprint> fingerprint) { | 2065 scoped_ptr<risk::Fingerprint> fingerprint) { |
| 2057 NOTIMPLEMENTED(); | 2066 if (!legal_docs_current_) |
| 2067 return; | |
| 2068 | |
| 2069 std::string proto_data; | |
| 2070 SerializeFingerprint(fingerprint.get(), &proto_data); | |
| 2071 | |
| 2072 if (!base::Base64Encode(proto_data, &risk_data_)) | |
|
Dan Beam
2013/05/03 07:29:09
btw, I have no idea how this could fail, but it do
Ilya Sherman
2013/05/03 07:38:31
Yeah, I'm also uncertain. I think a DCHECK might
Dan Beam
2013/05/03 09:24:47
Maybe for this... I just don't understand why this
| |
| 2073 risk_data_.clear(); | |
| 2058 } | 2074 } |
| 2059 | 2075 |
| 2060 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 2076 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
| 2061 DialogSection section) const { | 2077 DialogSection section) const { |
| 2062 std::map<DialogSection, bool>::const_iterator it = | 2078 std::map<DialogSection, bool>::const_iterator it = |
| 2063 section_editing_state_.find(section); | 2079 section_editing_state_.find(section); |
| 2064 return (it != section_editing_state_.end() && it->second) || | 2080 return (it != section_editing_state_.end() && it->second) || |
| 2065 SuggestionsMenuModelForSection(section)-> | 2081 SuggestionsMenuModelForSection(section)-> |
| 2066 GetItemKeyForCheckedItem() == kAddNewItemKey; | 2082 GetItemKeyForCheckedItem() == kAddNewItemKey; |
| 2067 } | 2083 } |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2384 url, | 2400 url, |
| 2385 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 2401 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
| 2386 params.disposition = NEW_FOREGROUND_TAB; | 2402 params.disposition = NEW_FOREGROUND_TAB; |
| 2387 chrome::Navigate(¶ms); | 2403 chrome::Navigate(¶ms); |
| 2388 #else | 2404 #else |
| 2389 // TODO(estade): use TabModelList? | 2405 // TODO(estade): use TabModelList? |
| 2390 #endif | 2406 #endif |
| 2391 } | 2407 } |
| 2392 | 2408 |
| 2393 } // namespace autofill | 2409 } // namespace autofill |
| OLD | NEW |