| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 697 |
| 698 // TODO(estade): don't show the dialog if the site didn't specify the right | 698 // TODO(estade): don't show the dialog if the site didn't specify the right |
| 699 // fields. First we must figure out what the "right" fields are. | 699 // fields. First we must figure out what the "right" fields are. |
| 700 view_.reset(CreateView()); | 700 view_.reset(CreateView()); |
| 701 view_->Show(); | 701 view_->Show(); |
| 702 GetManager()->AddObserver(this); | 702 GetManager()->AddObserver(this); |
| 703 | 703 |
| 704 // Try to see if the user is already signed-in. If signed-in, fetch the user's | 704 // Try to see if the user is already signed-in. If signed-in, fetch the user's |
| 705 // Wallet data. Otherwise, see if the user could be signed in passively. | 705 // Wallet data. Otherwise, see if the user could be signed in passively. |
| 706 // TODO(aruslan): UMA metrics for sign-in. | 706 // TODO(aruslan): UMA metrics for sign-in. |
| 707 signin_helper_.reset(new wallet::WalletSigninHelper( | 707 FetchWalletCookieAndUserName(); |
| 708 this, profile_->GetRequestContext())); | |
| 709 signin_helper_->StartWalletCookieValueFetch(); | |
| 710 | 708 |
| 711 if (!account_chooser_model_.WalletIsSelected()) | 709 if (!account_chooser_model_.WalletIsSelected()) |
| 712 LogDialogLatencyToShow(); | 710 LogDialogLatencyToShow(); |
| 713 } | 711 } |
| 714 | 712 |
| 715 void AutofillDialogControllerImpl::Hide() { | 713 void AutofillDialogControllerImpl::Hide() { |
| 716 if (view_) | 714 if (view_) |
| 717 view_->Hide(); | 715 view_->Hide(); |
| 718 } | 716 } |
| 719 | 717 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 | 978 |
| 981 if (signin_helper_ || !wallet_items_) | 979 if (signin_helper_ || !wallet_items_) |
| 982 return REQUIRES_RESPONSE; | 980 return REQUIRES_RESPONSE; |
| 983 | 981 |
| 984 if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) | 982 if (wallet_items_->HasRequiredAction(wallet::GAIA_AUTH)) |
| 985 return REQUIRES_SIGN_IN; | 983 return REQUIRES_SIGN_IN; |
| 986 | 984 |
| 987 if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) | 985 if (wallet_items_->HasRequiredAction(wallet::PASSIVE_GAIA_AUTH)) |
| 988 return REQUIRES_PASSIVE_SIGN_IN; | 986 return REQUIRES_PASSIVE_SIGN_IN; |
| 989 | 987 |
| 988 // Since the username can be pre-fetched as a performance optimization, Wallet |
| 989 // required actions take precedence over a pending username fetch. |
| 990 if (username_fetcher_) |
| 991 return REQUIRES_RESPONSE; |
| 992 |
| 990 return SIGNED_IN; | 993 return SIGNED_IN; |
| 991 } | 994 } |
| 992 | 995 |
| 993 void AutofillDialogControllerImpl::SignedInStateUpdated() { | 996 void AutofillDialogControllerImpl::SignedInStateUpdated() { |
| 994 switch (SignedInState()) { | 997 switch (SignedInState()) { |
| 995 case SIGNED_IN: | 998 case SIGNED_IN: |
| 996 // Start fetching the user name if we don't know it yet. | 999 // Start fetching the user name if we don't know it yet. |
| 997 if (account_chooser_model_.active_wallet_account_name().empty()) { | 1000 if (account_chooser_model_.active_wallet_account_name().empty()) { |
| 998 signin_helper_.reset(new wallet::WalletSigninHelper( | 1001 DCHECK(!username_fetcher_); |
| 1002 username_fetcher_.reset(new wallet::WalletSigninHelper( |
| 999 this, profile_->GetRequestContext())); | 1003 this, profile_->GetRequestContext())); |
| 1000 signin_helper_->StartUserNameFetch(); | 1004 username_fetcher_->StartUserNameFetch(); |
| 1001 } else { | 1005 } else { |
| 1002 LogDialogLatencyToShow(); | 1006 LogDialogLatencyToShow(); |
| 1003 } | 1007 } |
| 1004 break; | 1008 break; |
| 1005 | 1009 |
| 1006 case REQUIRES_SIGN_IN: | 1010 case REQUIRES_SIGN_IN: |
| 1007 case SIGN_IN_DISABLED: | 1011 case SIGN_IN_DISABLED: |
| 1008 // Switch to the local account and refresh the dialog. | 1012 // Switch to the local account and refresh the dialog. |
| 1013 signin_helper_.reset(); |
| 1014 username_fetcher_.reset(); |
| 1009 OnWalletSigninError(); | 1015 OnWalletSigninError(); |
| 1010 break; | 1016 break; |
| 1011 | 1017 |
| 1012 case REQUIRES_PASSIVE_SIGN_IN: | 1018 case REQUIRES_PASSIVE_SIGN_IN: |
| 1019 // Cancel any pending username fetch and clear any stale username data. |
| 1020 username_fetcher_.reset(); |
| 1021 account_chooser_model_.ClearActiveWalletAccountName(); |
| 1022 |
| 1013 // Attempt to passively sign in the user. | 1023 // Attempt to passively sign in the user. |
| 1014 DCHECK(!signin_helper_); | 1024 DCHECK(!signin_helper_); |
| 1015 account_chooser_model_.ClearActiveWalletAccountName(); | |
| 1016 signin_helper_.reset(new wallet::WalletSigninHelper( | 1025 signin_helper_.reset(new wallet::WalletSigninHelper( |
| 1017 this, | 1026 this, |
| 1018 profile_->GetRequestContext())); | 1027 profile_->GetRequestContext())); |
| 1019 signin_helper_->StartPassiveSignin(); | 1028 signin_helper_->StartPassiveSignin(); |
| 1020 break; | 1029 break; |
| 1021 | 1030 |
| 1022 case REQUIRES_RESPONSE: | 1031 case REQUIRES_RESPONSE: |
| 1023 break; | 1032 break; |
| 1024 } | 1033 } |
| 1025 } | 1034 } |
| (...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 return model; | 1307 return model; |
| 1299 } | 1308 } |
| 1300 | 1309 |
| 1301 return NULL; | 1310 return NULL; |
| 1302 } | 1311 } |
| 1303 | 1312 |
| 1304 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { | 1313 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForAccountChooser() { |
| 1305 // If there were unrecoverable Wallet errors, or if there are choices other | 1314 // If there were unrecoverable Wallet errors, or if there are choices other |
| 1306 // than "Pay without the wallet", show the full menu. | 1315 // than "Pay without the wallet", show the full menu. |
| 1307 if (wallet_error_notification_ || | 1316 if (wallet_error_notification_ || |
| 1308 account_chooser_model_.HasAccountsToChoose()) { | 1317 (SignedInState() == SIGNED_IN && |
| 1318 account_chooser_model_.HasAccountsToChoose())) { |
| 1309 return &account_chooser_model_; | 1319 return &account_chooser_model_; |
| 1310 } | 1320 } |
| 1311 | 1321 |
| 1312 // Otherwise, there is no menu, just a sign in link. | 1322 // Otherwise, there is no menu, just a sign in link. |
| 1313 return NULL; | 1323 return NULL; |
| 1314 } | 1324 } |
| 1315 | 1325 |
| 1316 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { | 1326 gfx::Image AutofillDialogControllerImpl::AccountChooserImage() { |
| 1317 if (!MenuModelForAccountChooser()) { | 1327 if (!MenuModelForAccountChooser()) { |
| 1318 if (signin_registrar_.IsEmpty()) { | 1328 if (signin_registrar_.IsEmpty()) { |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2092 | 2102 |
| 2093 void AutofillDialogControllerImpl::Observe( | 2103 void AutofillDialogControllerImpl::Observe( |
| 2094 int type, | 2104 int type, |
| 2095 const content::NotificationSource& source, | 2105 const content::NotificationSource& source, |
| 2096 const content::NotificationDetails& details) { | 2106 const content::NotificationDetails& details) { |
| 2097 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); | 2107 DCHECK_EQ(type, content::NOTIFICATION_NAV_ENTRY_COMMITTED); |
| 2098 content::LoadCommittedDetails* load_details = | 2108 content::LoadCommittedDetails* load_details = |
| 2099 content::Details<content::LoadCommittedDetails>(details).ptr(); | 2109 content::Details<content::LoadCommittedDetails>(details).ptr(); |
| 2100 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { | 2110 if (wallet::IsSignInContinueUrl(load_details->entry->GetVirtualURL())) { |
| 2101 account_chooser_model_.SelectActiveWalletAccount(); | 2111 account_chooser_model_.SelectActiveWalletAccount(); |
| 2102 signin_helper_.reset(new wallet::WalletSigninHelper( | 2112 FetchWalletCookieAndUserName(); |
| 2103 this, profile_->GetRequestContext())); | |
| 2104 signin_helper_->StartWalletCookieValueFetch(); | |
| 2105 HideSignIn(); | 2113 HideSignIn(); |
| 2106 } | 2114 } |
| 2107 } | 2115 } |
| 2108 | 2116 |
| 2109 //////////////////////////////////////////////////////////////////////////////// | 2117 //////////////////////////////////////////////////////////////////////////////// |
| 2110 // SuggestionsMenuModelDelegate implementation. | 2118 // SuggestionsMenuModelDelegate implementation. |
| 2111 | 2119 |
| 2112 void AutofillDialogControllerImpl::SuggestionItemSelected( | 2120 void AutofillDialogControllerImpl::SuggestionItemSelected( |
| 2113 SuggestionsMenuModel* model, | 2121 SuggestionsMenuModel* model, |
| 2114 size_t index) { | 2122 size_t index) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2219 const std::string& username) { | 2227 const std::string& username) { |
| 2220 const string16 username16 = UTF8ToUTF16(username); | 2228 const string16 username16 = UTF8ToUTF16(username); |
| 2221 signin_helper_->StartWalletCookieValueFetch(); | 2229 signin_helper_->StartWalletCookieValueFetch(); |
| 2222 account_chooser_model_.SetActiveWalletAccountName(username16); | 2230 account_chooser_model_.SetActiveWalletAccountName(username16); |
| 2223 } | 2231 } |
| 2224 | 2232 |
| 2225 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( | 2233 void AutofillDialogControllerImpl::OnUserNameFetchSuccess( |
| 2226 const std::string& username) { | 2234 const std::string& username) { |
| 2227 ScopedViewUpdates updates(view_.get()); | 2235 ScopedViewUpdates updates(view_.get()); |
| 2228 const string16 username16 = UTF8ToUTF16(username); | 2236 const string16 username16 = UTF8ToUTF16(username); |
| 2229 signin_helper_.reset(); | 2237 username_fetcher_.reset(); |
| 2230 account_chooser_model_.SetActiveWalletAccountName(username16); | 2238 account_chooser_model_.SetActiveWalletAccountName(username16); |
| 2231 OnWalletOrSigninUpdate(); | 2239 OnWalletOrSigninUpdate(); |
| 2232 } | 2240 } |
| 2233 | 2241 |
| 2234 void AutofillDialogControllerImpl::OnPassiveSigninFailure( | 2242 void AutofillDialogControllerImpl::OnPassiveSigninFailure( |
| 2235 const GoogleServiceAuthError& error) { | 2243 const GoogleServiceAuthError& error) { |
| 2236 // TODO(aruslan): report an error. | 2244 // TODO(aruslan): report an error. |
| 2237 LOG(ERROR) << "failed to passively sign in: " << error.ToString(); | 2245 LOG(ERROR) << "failed to passively sign in: " << error.ToString(); |
| 2246 signin_helper_.reset(); |
| 2238 OnWalletSigninError(); | 2247 OnWalletSigninError(); |
| 2239 } | 2248 } |
| 2240 | 2249 |
| 2241 void AutofillDialogControllerImpl::OnUserNameFetchFailure( | 2250 void AutofillDialogControllerImpl::OnUserNameFetchFailure( |
| 2242 const GoogleServiceAuthError& error) { | 2251 const GoogleServiceAuthError& error) { |
| 2243 // TODO(aruslan): report an error. | 2252 // TODO(aruslan): report an error. |
| 2244 LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); | 2253 LOG(ERROR) << "failed to fetch the user account name: " << error.ToString(); |
| 2245 OnWalletSigninError(); | 2254 username_fetcher_.reset(); |
| 2255 // Only treat the failed fetch as an error if the user is known to already be |
| 2256 // signed in. Attempting to fetch the username prior to loading the |
| 2257 // |wallet_items_| is purely a performance optimization that shouldn't be |
| 2258 // treated as an error if it fails. |
| 2259 if (wallet_items_) |
| 2260 OnWalletSigninError(); |
| 2246 } | 2261 } |
| 2247 | 2262 |
| 2248 void AutofillDialogControllerImpl::OnDidFetchWalletCookieValue( | 2263 void AutofillDialogControllerImpl::OnDidFetchWalletCookieValue( |
| 2249 const std::string& cookie_value) { | 2264 const std::string& cookie_value) { |
| 2250 wallet_cookie_value_ = cookie_value; | 2265 wallet_cookie_value_ = cookie_value; |
| 2251 signin_helper_.reset(); | 2266 signin_helper_.reset(); |
| 2252 GetWalletItems(); | 2267 GetWalletItems(); |
| 2253 } | 2268 } |
| 2254 | 2269 |
| 2255 void AutofillDialogControllerImpl::OnDidGetWalletItems( | 2270 void AutofillDialogControllerImpl::OnDidGetWalletItems( |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2362 this, | 2377 this, |
| 2363 &AutofillDialogControllerImpl::OnSubmitButtonDelayEnd); | 2378 &AutofillDialogControllerImpl::OnSubmitButtonDelayEnd); |
| 2364 } | 2379 } |
| 2365 | 2380 |
| 2366 void AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting() { | 2381 void AutofillDialogControllerImpl::SubmitButtonDelayEndForTesting() { |
| 2367 DCHECK(submit_button_delay_timer_.IsRunning()); | 2382 DCHECK(submit_button_delay_timer_.IsRunning()); |
| 2368 submit_button_delay_timer_.user_task().Run(); | 2383 submit_button_delay_timer_.user_task().Run(); |
| 2369 submit_button_delay_timer_.Stop(); | 2384 submit_button_delay_timer_.Stop(); |
| 2370 } | 2385 } |
| 2371 | 2386 |
| 2387 void AutofillDialogControllerImpl:: |
| 2388 ClearLastWalletItemsFetchTimestampForTesting() { |
| 2389 last_wallet_items_fetch_timestamp_ = base::TimeTicks(); |
| 2390 } |
| 2391 |
| 2372 AutofillDialogControllerImpl::AutofillDialogControllerImpl( | 2392 AutofillDialogControllerImpl::AutofillDialogControllerImpl( |
| 2373 content::WebContents* contents, | 2393 content::WebContents* contents, |
| 2374 const FormData& form_structure, | 2394 const FormData& form_structure, |
| 2375 const GURL& source_url, | 2395 const GURL& source_url, |
| 2376 const base::Callback<void(const FormStructure*)>& callback) | 2396 const base::Callback<void(const FormStructure*)>& callback) |
| 2377 : WebContentsObserver(contents), | 2397 : WebContentsObserver(contents), |
| 2378 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), | 2398 profile_(Profile::FromBrowserContext(contents->GetBrowserContext())), |
| 2379 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), | 2399 initial_user_state_(AutofillMetrics::DIALOG_USER_STATE_UNKNOWN), |
| 2380 form_structure_(form_structure), | 2400 form_structure_(form_structure), |
| 2381 invoked_from_same_origin_(true), | 2401 invoked_from_same_origin_(true), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2471 } | 2491 } |
| 2472 | 2492 |
| 2473 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 2493 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
| 2474 DialogSection section) const { | 2494 DialogSection section) const { |
| 2475 return IsEditingExistingData(section) || | 2495 return IsEditingExistingData(section) || |
| 2476 SuggestionsMenuModelForSection(section)-> | 2496 SuggestionsMenuModelForSection(section)-> |
| 2477 GetItemKeyForCheckedItem() == kAddNewItemKey; | 2497 GetItemKeyForCheckedItem() == kAddNewItemKey; |
| 2478 } | 2498 } |
| 2479 | 2499 |
| 2480 void AutofillDialogControllerImpl::OnWalletSigninError() { | 2500 void AutofillDialogControllerImpl::OnWalletSigninError() { |
| 2481 signin_helper_.reset(); | |
| 2482 account_chooser_model_.SetHadWalletSigninError(); | 2501 account_chooser_model_.SetHadWalletSigninError(); |
| 2483 GetWalletClient()->CancelRequests(); | 2502 GetWalletClient()->CancelRequests(); |
| 2484 LogDialogLatencyToShow(); | 2503 LogDialogLatencyToShow(); |
| 2485 } | 2504 } |
| 2486 | 2505 |
| 2487 void AutofillDialogControllerImpl::DisableWallet( | 2506 void AutofillDialogControllerImpl::DisableWallet( |
| 2488 wallet::WalletClient::ErrorType error_type) { | 2507 wallet::WalletClient::ErrorType error_type) { |
| 2489 signin_helper_.reset(); | 2508 signin_helper_.reset(); |
| 2509 username_fetcher_.reset(); |
| 2490 wallet_items_.reset(); | 2510 wallet_items_.reset(); |
| 2491 wallet_errors_.clear(); | 2511 wallet_errors_.clear(); |
| 2492 GetWalletClient()->CancelRequests(); | 2512 GetWalletClient()->CancelRequests(); |
| 2493 SetIsSubmitting(false); | 2513 SetIsSubmitting(false); |
| 2494 wallet_error_notification_ = GetWalletError(error_type); | 2514 wallet_error_notification_ = GetWalletError(error_type); |
| 2495 account_chooser_model_.SetHadWalletError(); | 2515 account_chooser_model_.SetHadWalletError(); |
| 2496 } | 2516 } |
| 2497 | 2517 |
| 2498 void AutofillDialogControllerImpl::SuggestionsUpdated() { | 2518 void AutofillDialogControllerImpl::SuggestionsUpdated() { |
| 2499 ScopedViewUpdates updates(view_.get()); | 2519 ScopedViewUpdates updates(view_.get()); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2665 view_->ModelChanged(); | 2685 view_->ModelChanged(); |
| 2666 | 2686 |
| 2667 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 2687 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 2668 ResetSectionInput(static_cast<DialogSection>(i)); | 2688 ResetSectionInput(static_cast<DialogSection>(i)); |
| 2669 } | 2689 } |
| 2670 | 2690 |
| 2671 RestoreUserInputFromSnapshot(snapshot); | 2691 RestoreUserInputFromSnapshot(snapshot); |
| 2672 | 2692 |
| 2673 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 2693 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
| 2674 DialogSection section = static_cast<DialogSection>(i); | 2694 DialogSection section = static_cast<DialogSection>(i); |
| 2695 if (!SectionIsActive(section)) |
| 2696 continue; |
| 2697 |
| 2675 ShowEditUiIfBadSuggestion(section); | 2698 ShowEditUiIfBadSuggestion(section); |
| 2676 UpdateSection(section); | 2699 UpdateSection(section); |
| 2677 } | 2700 } |
| 2678 | 2701 |
| 2679 UpdateForErrors(); | 2702 UpdateForErrors(); |
| 2680 } | 2703 } |
| 2681 | 2704 |
| 2682 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( | 2705 void AutofillDialogControllerImpl::FillOutputForSectionWithComparator( |
| 2683 DialogSection section, | 2706 DialogSection section, |
| 2684 const InputFieldComparator& compare) { | 2707 const InputFieldComparator& compare) { |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3407 #endif | 3430 #endif |
| 3408 } | 3431 } |
| 3409 | 3432 |
| 3410 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { | 3433 void AutofillDialogControllerImpl::OnSubmitButtonDelayEnd() { |
| 3411 if (!view_) | 3434 if (!view_) |
| 3412 return; | 3435 return; |
| 3413 ScopedViewUpdates updates(view_.get()); | 3436 ScopedViewUpdates updates(view_.get()); |
| 3414 view_->UpdateButtonStrip(); | 3437 view_->UpdateButtonStrip(); |
| 3415 } | 3438 } |
| 3416 | 3439 |
| 3440 void AutofillDialogControllerImpl::FetchWalletCookieAndUserName() { |
| 3441 net::URLRequestContextGetter* request_context = profile_->GetRequestContext(); |
| 3442 signin_helper_.reset(new wallet::WalletSigninHelper(this, request_context)); |
| 3443 signin_helper_->StartWalletCookieValueFetch(); |
| 3444 |
| 3445 username_fetcher_.reset( |
| 3446 new wallet::WalletSigninHelper(this, request_context)); |
| 3447 username_fetcher_->StartUserNameFetch(); |
| 3448 } |
| 3449 |
| 3417 } // namespace autofill | 3450 } // namespace autofill |
| OLD | NEW |