Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_controller_impl.cc

Issue 22623002: Extract AutofillDialogController interface and common utilities. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
11 #include "apps/native_app_window.h" 11 #include "apps/native_app_window.h"
12 #include "apps/shell_window.h" 12 #include "apps/shell_window.h"
13 #include "apps/shell_window_registry.h" 13 #include "apps/shell_window_registry.h"
14 #include "base/base64.h" 14 #include "base/base64.h"
15 #include "base/bind.h" 15 #include "base/bind.h"
16 #include "base/i18n/rtl.h" 16 #include "base/i18n/rtl.h"
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/prefs/pref_service.h" 18 #include "base/prefs/pref_service.h"
19 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
20 #include "base/strings/string_split.h" 20 #include "base/strings/string_split.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/time/time.h" 23 #include "base/time/time.h"
24 #include "chrome/browser/autofill/personal_data_manager_factory.h" 24 #include "chrome/browser/autofill/personal_data_manager_factory.h"
25 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/prefs/scoped_user_pref_update.h" 26 #include "chrome/browser/prefs/scoped_user_pref_update.h"
27 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/autofill/autofill_credit_card_bubble_controller.h" 28 #include "chrome/browser/ui/autofill/autofill_credit_card_bubble_controller.h"
29 #include "chrome/browser/ui/autofill/autofill_dialog_common.h"
29 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" 30 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
30 #include "chrome/browser/ui/autofill/data_model_wrapper.h" 31 #include "chrome/browser/ui/autofill/data_model_wrapper.h"
31 #include "chrome/browser/ui/browser.h" 32 #include "chrome/browser/ui/browser.h"
32 #include "chrome/browser/ui/browser_finder.h" 33 #include "chrome/browser/ui/browser_finder.h"
33 #include "chrome/browser/ui/browser_navigator.h" 34 #include "chrome/browser/ui/browser_navigator.h"
34 #include "chrome/browser/ui/browser_window.h" 35 #include "chrome/browser/ui/browser_window.h"
35 #include "chrome/common/chrome_version_info.h" 36 #include "chrome/common/chrome_version_info.h"
36 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
37 #include "chrome/common/render_messages.h" 38 #include "chrome/common/render_messages.h"
38 #include "chrome/common/url_constants.h" 39 #include "chrome/common/url_constants.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 // Limit Wallet items refresh rate to at most once per minute. 104 // Limit Wallet items refresh rate to at most once per minute.
104 const int kWalletItemsRefreshRateSeconds = 60; 105 const int kWalletItemsRefreshRateSeconds = 60;
105 106
106 // Returns true if |card_type| is supported by Wallet. 107 // Returns true if |card_type| is supported by Wallet.
107 bool IsWalletSupportedCard(const std::string& card_type) { 108 bool IsWalletSupportedCard(const std::string& card_type) {
108 return card_type == autofill::kVisaCard || 109 return card_type == autofill::kVisaCard ||
109 card_type == autofill::kMasterCard || 110 card_type == autofill::kMasterCard ||
110 card_type == autofill::kDiscoverCard; 111 card_type == autofill::kDiscoverCard;
111 } 112 }
112 113
113 // Returns true if |input| should be shown when |field_type| has been requested.
114 bool InputTypeMatchesFieldType(const DetailInput& input,
115 const AutofillType& field_type) {
116 // If any credit card expiration info is asked for, show both month and year
117 // inputs.
118 ServerFieldType server_type = field_type.GetStorableType();
119 if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
120 server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
121 server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
122 server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
123 server_type == CREDIT_CARD_EXP_MONTH) {
124 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
125 input.type == CREDIT_CARD_EXP_MONTH;
126 }
127
128 if (server_type == CREDIT_CARD_TYPE)
129 return input.type == CREDIT_CARD_NUMBER;
130
131 // Check the groups to distinguish billing types from shipping ones.
132 AutofillType input_type = AutofillType(input.type);
133 return input_type.GetStorableType() == server_type &&
134 input_type.group() == field_type.group();
135 }
136
137 // Returns true if |input| in the given |section| should be used for a
138 // site-requested |field|.
139 bool DetailInputMatchesField(DialogSection section,
140 const DetailInput& input,
141 const AutofillField& field) {
142 AutofillType field_type = field.Type();
143
144 // The credit card name is filled from the billing section's data.
145 if (field_type.GetStorableType() == CREDIT_CARD_NAME &&
146 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) {
147 return input.type == NAME_BILLING_FULL;
148 }
149
150 return InputTypeMatchesFieldType(input, field_type);
151 }
152
153 bool IsCreditCardType(ServerFieldType type) {
154 return AutofillType(type).group() == CREDIT_CARD;
155 }
156
157 // Returns true if |input| should be used to fill a site-requested |field| which 114 // Returns true if |input| should be used to fill a site-requested |field| which
158 // is notated with a "shipping" tag, for use when the user has decided to use 115 // is notated with a "shipping" tag, for use when the user has decided to use
159 // the billing address as the shipping address. 116 // the billing address as the shipping address.
160 bool DetailInputMatchesShippingField(const DetailInput& input, 117 bool DetailInputMatchesShippingField(const DetailInput& input,
161 const AutofillField& field) { 118 const AutofillField& field) {
162 // Equivalent billing field type is used to support UseBillingAsShipping 119 // Equivalent billing field type is used to support UseBillingAsShipping
163 // usecase. 120 // usecase.
164 ServerFieldType field_type = 121 ServerFieldType field_type =
165 AutofillType::GetEquivalentBillingFieldType( 122 AutofillType::GetEquivalentBillingFieldType(
166 field.Type().GetStorableType()); 123 field.Type().GetStorableType());
167 124
168 return InputTypeMatchesFieldType(input, AutofillType(field_type)); 125 return common::InputTypeMatchesFieldType(input, AutofillType(field_type));
169 }
170
171 // Constructs |inputs| from template data.
172 void BuildInputs(const DetailInput* input_template,
173 size_t template_size,
174 DetailInputs* inputs) {
175 for (size_t i = 0; i < template_size; ++i) {
176 const DetailInput* input = &input_template[i];
177 inputs->push_back(*input);
178 }
179 } 126 }
180 127
181 // Initializes |form_group| from user-entered data. 128 // Initializes |form_group| from user-entered data.
182 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs, 129 void FillFormGroupFromOutputs(const DetailOutputMap& detail_outputs,
183 FormGroup* form_group) { 130 FormGroup* form_group) {
184 for (DetailOutputMap::const_iterator iter = detail_outputs.begin(); 131 for (DetailOutputMap::const_iterator iter = detail_outputs.begin();
185 iter != detail_outputs.end(); ++iter) { 132 iter != detail_outputs.end(); ++iter) {
186 ServerFieldType type = iter->first->type; 133 ServerFieldType type = iter->first->type;
187 if (!iter->second.empty()) { 134 if (!iter->second.empty()) {
188 if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) { 135 if (type == ADDRESS_HOME_COUNTRY || type == ADDRESS_BILLING_COUNTRY) {
(...skipping 29 matching lines...) Expand all
218 profile->SetInfo(AutofillType(it->first->type), 165 profile->SetInfo(AutofillType(it->first->type),
219 trimmed, 166 trimmed,
220 g_browser_process->GetApplicationLocale()); 167 g_browser_process->GetApplicationLocale());
221 } 168 }
222 } else { 169 } else {
223 // Copy the credit card name to |profile| in addition to |card| as 170 // Copy the credit card name to |profile| in addition to |card| as
224 // wallet::Instrument requires a recipient name for its billing address. 171 // wallet::Instrument requires a recipient name for its billing address.
225 if (card && it->first->type == NAME_FULL) 172 if (card && it->first->type == NAME_FULL)
226 card->SetRawInfo(CREDIT_CARD_NAME, trimmed); 173 card->SetRawInfo(CREDIT_CARD_NAME, trimmed);
227 174
228 if (IsCreditCardType(it->first->type)) { 175 if (common::IsCreditCardType(it->first->type)) {
229 if (card) 176 if (card)
230 card->SetRawInfo(it->first->type, trimmed); 177 card->SetRawInfo(it->first->type, trimmed);
231 } else if (profile) { 178 } else if (profile) {
232 profile->SetRawInfo(it->first->type, trimmed); 179 profile->SetRawInfo(it->first->type, trimmed);
233 } 180 }
234 } 181 }
235 } 182 }
236 } 183 }
237 184
238 // Returns the containing window for the given |web_contents|. The containing 185 // Returns the containing window for the given |web_contents|. The containing
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
437 return base::string16(); 384 return base::string16();
438 } 385 }
439 386
440 gfx::Image GetGeneratedCardImage(const string16& card_number) { 387 gfx::Image GetGeneratedCardImage(const string16& card_number) {
441 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 388 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
442 const gfx::ImageSkia* card = 389 const gfx::ImageSkia* card =
443 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD); 390 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD);
444 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); 391 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false);
445 canvas.DrawImageInt(*card, 0, 0); 392 canvas.DrawImageInt(*card, 0, 0);
446 393
447 #if !defined(OS_ANDROID)
448 gfx::Rect display_rect(gfx::Point(), card->size()); 394 gfx::Rect display_rect(gfx::Point(), card->size());
449 display_rect.Inset(14, 0, 14, 0); 395 display_rect.Inset(14, 0, 14, 0);
450 // TODO(estade): fallback font for systems that don't have Helvetica? 396 // TODO(estade): fallback font for systems that don't have Helvetica?
451 gfx::Font helvetica("Helvetica", 14); 397 gfx::Font helvetica("Helvetica", 14);
452 gfx::ShadowValues shadows; 398 gfx::ShadowValues shadows;
453 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1), 399 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1),
454 0.0, 400 0.0,
455 SkColorSetARGB(85, 0, 0, 0))); 401 SkColorSetARGB(85, 0, 0, 0)));
456 canvas.DrawStringWithShadows( 402 canvas.DrawStringWithShadows(
457 card_number, 403 card_number,
458 helvetica, 404 helvetica,
459 SK_ColorWHITE, 405 SK_ColorWHITE,
460 display_rect, 0, 0, shadows); 406 display_rect, 0, 0, shadows);
461 #endif
462 407
463 gfx::ImageSkia skia(canvas.ExtractImageRep()); 408 gfx::ImageSkia skia(canvas.ExtractImageRep());
464 return gfx::Image(skia); 409 return gfx::Image(skia);
465 } 410 }
466 411
467 } // namespace 412 } // namespace
468 413
469 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} 414 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {}
470 415
471 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { 416 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() {
472 if (popup_controller_) 417 if (popup_controller_)
473 popup_controller_->Hide(); 418 popup_controller_->Hide();
474 419
475 GetMetricLogger().LogDialogInitialUserState( 420 GetMetricLogger().LogDialogInitialUserState(
476 GetDialogType(), initial_user_state_); 421 GetDialogType(), initial_user_state_);
477 422
478 if (deemphasized_render_view_ && web_contents()) { 423 if (deemphasized_render_view_ && web_contents()) {
479 web_contents()->GetRenderViewHost()->Send( 424 web_contents()->GetRenderViewHost()->Send(
480 new ChromeViewMsg_SetVisuallyDeemphasized( 425 new ChromeViewMsg_SetVisuallyDeemphasized(
481 web_contents()->GetRenderViewHost()->GetRoutingID(), false)); 426 web_contents()->GetRenderViewHost()->GetRoutingID(), false));
482 } 427 }
483 } 428 }
484 429
485 #if !defined(OS_ANDROID)
486 // static 430 // static
487 base::WeakPtr<AutofillDialogControllerImpl> 431 base::WeakPtr<AutofillDialogControllerImpl>
488 AutofillDialogControllerImpl::Create( 432 AutofillDialogControllerImpl::Create(
489 content::WebContents* contents, 433 content::WebContents* contents,
490 const FormData& form_structure, 434 const FormData& form_structure,
491 const GURL& source_url, 435 const GURL& source_url,
492 const DialogType dialog_type, 436 const DialogType dialog_type,
493 const base::Callback<void(const FormStructure*, 437 const base::Callback<void(const FormStructure*,
494 const std::string&)>& callback) { 438 const std::string&)>& callback) {
495 // AutofillDialogControllerImpl owns itself. 439 // AutofillDialogControllerImpl owns itself.
496 AutofillDialogControllerImpl* autofill_dialog_controller = 440 AutofillDialogControllerImpl* autofill_dialog_controller =
497 new AutofillDialogControllerImpl(contents, 441 new AutofillDialogControllerImpl(contents,
498 form_structure, 442 form_structure,
499 source_url, 443 source_url,
500 dialog_type, 444 dialog_type,
501 callback); 445 callback);
502 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); 446 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr();
503 } 447 }
504 #endif // !defined(OS_ANDROID)
505 448
506 // static 449 // static
507 void AutofillDialogControllerImpl::RegisterProfilePrefs( 450 void AutofillDialogControllerImpl::RegisterProfilePrefs(
508 user_prefs::PrefRegistrySyncable* registry) { 451 user_prefs::PrefRegistrySyncable* registry) {
509 registry->RegisterIntegerPref( 452 registry->RegisterIntegerPref(
510 ::prefs::kAutofillDialogShowCount, 453 ::prefs::kAutofillDialogShowCount,
511 0, 454 0,
512 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 455 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
513 registry->RegisterBooleanPref( 456 registry->RegisterBooleanPref(
514 ::prefs::kAutofillDialogHasPaidWithWallet, 457 ::prefs::kAutofillDialogHasPaidWithWallet,
515 false, 458 false,
516 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 459 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
517 registry->RegisterBooleanPref( 460 registry->RegisterBooleanPref(
518 ::prefs::kAutofillDialogPayWithoutWallet, 461 ::prefs::kAutofillDialogPayWithoutWallet,
519 false, 462 false,
520 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 463 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
521 registry->RegisterDictionaryPref( 464 registry->RegisterDictionaryPref(
522 ::prefs::kAutofillDialogAutofillDefault, 465 ::prefs::kAutofillDialogAutofillDefault,
523 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 466 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
524 } 467 }
525 468
469 // static
470 base::WeakPtr<AutofillDialogController> AutofillDialogController::Create(
471 content::WebContents* contents,
472 const FormData& form_structure,
473 const GURL& source_url,
474 const DialogType dialog_type,
475 const base::Callback<void(const FormStructure*,
476 const std::string&)>& callback) {
477 return AutofillDialogControllerImpl::Create(contents,
478 form_structure,
479 source_url,
480 dialog_type,
481 callback);
482 }
483
484 // static
485 void AutofillDialogController::RegisterProfilePrefs(
486 user_prefs::PrefRegistrySyncable* registry) {
487 AutofillDialogControllerImpl::RegisterProfilePrefs(registry);
488 }
489
526 void AutofillDialogControllerImpl::Show() { 490 void AutofillDialogControllerImpl::Show() {
527 dialog_shown_timestamp_ = base::Time::Now(); 491 dialog_shown_timestamp_ = base::Time::Now();
528 492
529 content::NavigationEntry* entry = 493 content::NavigationEntry* entry =
530 web_contents()->GetController().GetActiveEntry(); 494 web_contents()->GetController().GetActiveEntry();
531 const GURL& active_url = entry ? entry->GetURL() : web_contents()->GetURL(); 495 const GURL& active_url = entry ? entry->GetURL() : web_contents()->GetURL();
532 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); 496 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin();
533 497
534 // Log any relevant UI metrics and security exceptions. 498 // Log any relevant UI metrics and security exceptions.
535 GetMetricLogger().LogDialogUiEvent( 499 GetMetricLogger().LogDialogUiEvent(
(...skipping 20 matching lines...) Expand all
556 form_structure_.ParseFieldTypesFromAutocompleteAttributes( 520 form_structure_.ParseFieldTypesFromAutocompleteAttributes(
557 &has_types, &has_sections); 521 &has_types, &has_sections);
558 522
559 // Fail if the author didn't specify autocomplete types. 523 // Fail if the author didn't specify autocomplete types.
560 if (!has_types) { 524 if (!has_types) {
561 callback_.Run(NULL, std::string()); 525 callback_.Run(NULL, std::string());
562 delete this; 526 delete this;
563 return; 527 return;
564 } 528 }
565 529
566 const DetailInput kEmailInputs[] = { 530 common::BuildInputsForSection(SECTION_EMAIL,
567 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, 531 &requested_email_fields_);
568 }; 532 common::BuildInputsForSection(SECTION_CC,
569 533 &requested_cc_fields_);
570 const DetailInput kCCInputs[] = { 534 common::BuildInputsForSection(SECTION_BILLING,
571 { 2, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, 535 &requested_billing_fields_);
572 { 3, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, 536 common::BuildInputsForSection(SECTION_CC_BILLING,
573 { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR, 537 &requested_cc_billing_fields_);
574 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, 538 common::BuildInputsForSection(SECTION_SHIPPING,
575 { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, 539 &requested_shipping_fields_);
576 1.5 },
577 };
578
579 const DetailInput kBillingInputs[] = {
580 { 4, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME },
581 { 5, ADDRESS_BILLING_LINE1,
582 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
583 { 6, ADDRESS_BILLING_LINE2,
584 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
585 { 7, ADDRESS_BILLING_CITY,
586 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
587 // TODO(estade): state placeholder should depend on locale.
588 { 8, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
589 { 8, ADDRESS_BILLING_ZIP,
590 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
591 // We don't allow the user to change the country: http://crbug.com/247518
592 { -1, ADDRESS_BILLING_COUNTRY, 0 },
593 { 10, PHONE_BILLING_WHOLE_NUMBER,
594 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
595 };
596
597 const DetailInput kShippingInputs[] = {
598 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME },
599 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
600 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
601 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
602 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
603 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
604 { -1, ADDRESS_HOME_COUNTRY, 0 },
605 { 17, PHONE_HOME_WHOLE_NUMBER,
606 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
607 };
608
609 BuildInputs(kEmailInputs,
610 arraysize(kEmailInputs),
611 &requested_email_fields_);
612
613 BuildInputs(kCCInputs,
614 arraysize(kCCInputs),
615 &requested_cc_fields_);
616
617 BuildInputs(kBillingInputs,
618 arraysize(kBillingInputs),
619 &requested_billing_fields_);
620
621 BuildInputs(kCCInputs,
622 arraysize(kCCInputs),
623 &requested_cc_billing_fields_);
624 BuildInputs(kBillingInputs,
625 arraysize(kBillingInputs),
626 &requested_cc_billing_fields_);
627
628 BuildInputs(kShippingInputs,
629 arraysize(kShippingInputs),
630 &requested_shipping_fields_);
631 540
632 // Test whether we need to show the shipping section. If filling that section 541 // Test whether we need to show the shipping section. If filling that section
633 // would be a no-op, don't show it. 542 // would be a no-op, don't show it.
634 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); 543 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING);
635 EmptyDataModelWrapper empty_wrapper; 544 EmptyDataModelWrapper empty_wrapper;
636 cares_about_shipping_ = empty_wrapper.FillFormStructure( 545 cares_about_shipping_ = empty_wrapper.FillFormStructure(
637 inputs, 546 inputs,
638 base::Bind(DetailInputMatchesField, SECTION_SHIPPING), 547 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING),
639 &form_structure_); 548 &form_structure_);
640 549
641 SuggestionsUpdated(); 550 SuggestionsUpdated();
642 551
643 int show_count = 552 int show_count =
644 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount); 553 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount);
645 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount, 554 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount,
646 show_count + 1); 555 show_count + 1);
647 556
648 // TODO(estade): don't show the dialog if the site didn't specify the right 557 // TODO(estade): don't show the dialog if the site didn't specify the right
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 !IsSubmitPausedOn(wallet::VERIFY_CVV) && 769 !IsSubmitPausedOn(wallet::VERIFY_CVV) &&
861 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; 770 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE;
862 if (!show_wallet_interstitial) 771 if (!show_wallet_interstitial)
863 return DialogOverlayState(); 772 return DialogOverlayState();
864 773
865 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 774 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
866 DialogOverlayState state; 775 DialogOverlayState state;
867 776
868 state.strings.push_back(DialogOverlayString()); 777 state.strings.push_back(DialogOverlayString());
869 DialogOverlayString& string = state.strings.back(); 778 DialogOverlayString& string = state.strings.back();
870 #if !defined(OS_ANDROID)
871 // gfx::Font isn't implemented on Android; DeriveFont() causes a null deref.
872 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); 779 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4);
873 #endif
874 780
875 // First-run, post-submit, Wallet expository page. 781 // First-run, post-submit, Wallet expository page.
876 if (full_wallet_ && full_wallet_->required_actions().empty()) { 782 if (full_wallet_ && full_wallet_->required_actions().empty()) {
877 string16 cc_number = 783 string16 cc_number =
878 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER)); 784 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER));
879 DCHECK_EQ(16U, cc_number.size()); 785 DCHECK_EQ(16U, cc_number.size());
880 state.image = GetGeneratedCardImage( 786 state.image = GetGeneratedCardImage(
881 ASCIIToUTF16("xxxx xxxx xxxx ") + 787 ASCIIToUTF16("xxxx xxxx xxxx ") +
882 cc_number.substr(cc_number.size() - 4)); 788 cc_number.substr(cc_number.size() - 4));
883 string.text = l10n_util::GetStringUTF16( 789 string.text = l10n_util::GetStringUTF16(
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1514 1420
1515 DetailInputs* inputs = MutableRequestedFieldsForSection(section); 1421 DetailInputs* inputs = MutableRequestedFieldsForSection(section);
1516 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) { 1422 for (DetailInputs::iterator it = inputs->begin(); it != inputs->end(); ++it) {
1517 it->editable = InputIsEditable(*it, section); 1423 it->editable = InputIsEditable(*it, section);
1518 } 1424 }
1519 model->FillInputs(inputs); 1425 model->FillInputs(inputs);
1520 1426
1521 UpdateSection(section); 1427 UpdateSection(section);
1522 1428
1523 GetMetricLogger().LogDialogUiEvent( 1429 GetMetricLogger().LogDialogUiEvent(
1524 GetDialogType(), DialogSectionToUiEditEvent(section)); 1430 GetDialogType(), common::DialogSectionToUiEditEvent(section));
1525 } 1431 }
1526 1432
1527 void AutofillDialogControllerImpl::EditCancelledForSection( 1433 void AutofillDialogControllerImpl::EditCancelledForSection(
1528 DialogSection section) { 1434 DialogSection section) {
1529 ResetSectionInput(section); 1435 ResetSectionInput(section);
1530 UpdateSection(section); 1436 UpdateSection(section);
1531 } 1437 }
1532 1438
1533 gfx::Image AutofillDialogControllerImpl::IconForField( 1439 gfx::Image AutofillDialogControllerImpl::IconForField(
1534 ServerFieldType type, const string16& user_input) const { 1440 ServerFieldType type, const string16& user_input) const {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1787 } 1693 }
1788 1694
1789 // If the user clicks while the popup is already showing, be sure to hide 1695 // If the user clicks while the popup is already showing, be sure to hide
1790 // it. 1696 // it.
1791 if (!was_edit && popup_controller_.get()) { 1697 if (!was_edit && popup_controller_.get()) {
1792 HidePopup(); 1698 HidePopup();
1793 return; 1699 return;
1794 } 1700 }
1795 1701
1796 std::vector<string16> popup_values, popup_labels, popup_icons; 1702 std::vector<string16> popup_values, popup_labels, popup_icons;
1797 if (IsCreditCardType(input->type)) { 1703 if (common::IsCreditCardType(input->type)) {
1798 GetManager()->GetCreditCardSuggestions(AutofillType(input->type), 1704 GetManager()->GetCreditCardSuggestions(AutofillType(input->type),
1799 field_contents, 1705 field_contents,
1800 &popup_values, 1706 &popup_values,
1801 &popup_labels, 1707 &popup_labels,
1802 &popup_icons, 1708 &popup_icons,
1803 &popup_guids_); 1709 &popup_guids_);
1804 } else { 1710 } else {
1805 std::vector<ServerFieldType> field_types; 1711 std::vector<ServerFieldType> field_types;
1806 field_types.push_back(EMAIL_ADDRESS); 1712 field_types.push_back(EMAIL_ADDRESS);
1807 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin(); 1713 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
2089 1995
2090 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { 1996 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) {
2091 // TODO(estade): implement. 1997 // TODO(estade): implement.
2092 } 1998 }
2093 1999
2094 void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, 2000 void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value,
2095 int identifier) { 2001 int identifier) {
2096 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; 2002 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier];
2097 2003
2098 scoped_ptr<DataModelWrapper> wrapper; 2004 scoped_ptr<DataModelWrapper> wrapper;
2099 if (IsCreditCardType(input_showing_popup_->type)) { 2005 if (common::IsCreditCardType(input_showing_popup_->type)) {
2100 wrapper.reset(new AutofillCreditCardWrapper( 2006 wrapper.reset(new AutofillCreditCardWrapper(
2101 GetManager()->GetCreditCardByGUID(pair.first))); 2007 GetManager()->GetCreditCardByGUID(pair.first)));
2102 } else { 2008 } else {
2103 wrapper.reset(new AutofillProfileWrapper( 2009 wrapper.reset(new AutofillProfileWrapper(
2104 GetManager()->GetProfileByGUID(pair.first), pair.second)); 2010 GetManager()->GetProfileByGUID(pair.first), pair.second));
2105 } 2011 }
2106 2012
2107 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 2013 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
2108 DialogSection section = static_cast<DialogSection>(i); 2014 DialogSection section = static_cast<DialogSection>(i);
2109 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); 2015 wrapper->FillInputs(MutableRequestedFieldsForSection(section));
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
2364 return popup_controller_->HandleKeyPressEvent(event); 2270 return popup_controller_->HandleKeyPressEvent(event);
2365 2271
2366 return false; 2272 return false;
2367 } 2273 }
2368 2274
2369 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { 2275 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const {
2370 DCHECK_GT(form_structure_.field_count(), 0U); 2276 DCHECK_GT(form_structure_.field_count(), 0U);
2371 2277
2372 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 2278 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
2373 AutofillType type = form_structure_.field(i)->Type(); 2279 AutofillType type = form_structure_.field(i)->Type();
2374 if (IsCreditCardType(type.GetStorableType())) 2280 if (common::IsCreditCardType(type.GetStorableType()))
2375 return true; 2281 return true;
2376 } 2282 }
2377 2283
2378 return false; 2284 return false;
2379 } 2285 }
2380 2286
2381 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { 2287 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const {
2382 return source_url_.SchemeIs(chrome::kHttpsScheme); 2288 return source_url_.SchemeIs(chrome::kHttpsScheme);
2383 } 2289 }
2384 2290
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2442 2348
2443 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { 2349 void AutofillDialogControllerImpl::LoadRiskFingerprintData() {
2444 risk_data_.clear(); 2350 risk_data_.clear();
2445 2351
2446 uint64 obfuscated_gaia_id = 0; 2352 uint64 obfuscated_gaia_id = 0;
2447 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), 2353 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(),
2448 &obfuscated_gaia_id); 2354 &obfuscated_gaia_id);
2449 DCHECK(success); 2355 DCHECK(success);
2450 2356
2451 gfx::Rect window_bounds; 2357 gfx::Rect window_bounds;
2452 #if !defined(OS_ANDROID)
2453 window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds(); 2358 window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds();
2454 #endif
2455 2359
2456 PrefService* user_prefs = profile_->GetPrefs(); 2360 PrefService* user_prefs = profile_->GetPrefs();
2457 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); 2361 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset);
2458 std::string accept_languages = 2362 std::string accept_languages =
2459 user_prefs->GetString(::prefs::kAcceptLanguages); 2363 user_prefs->GetString(::prefs::kAcceptLanguages);
2460 base::Time install_time = base::Time::FromTimeT( 2364 base::Time install_time = base::Time::FromTimeT(
2461 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); 2365 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate));
2462 2366
2463 risk::GetFingerprint( 2367 risk::GetFingerprint(
2464 obfuscated_gaia_id, window_bounds, *web_contents(), 2368 obfuscated_gaia_id, window_bounds, *web_contents(),
2465 chrome::VersionInfo().Version(), charset, accept_languages, install_time, 2369 chrome::VersionInfo().Version(), charset, accept_languages, install_time,
2466 dialog_type_, g_browser_process->GetApplicationLocale(), 2370 dialog_type_, g_browser_process->GetApplicationLocale(),
2467 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, 2371 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData,
2468 weak_ptr_factory_.GetWeakPtr())); 2372 weak_ptr_factory_.GetWeakPtr()));
2469 } 2373 }
2470 2374
2471 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( 2375 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData(
2472 scoped_ptr<risk::Fingerprint> fingerprint) { 2376 scoped_ptr<risk::Fingerprint> fingerprint) {
2473 DCHECK(AreLegalDocumentsCurrent()); 2377 DCHECK(AreLegalDocumentsCurrent());
2474 2378
2475 std::string proto_data; 2379 std::string proto_data;
2476 fingerprint->SerializeToString(&proto_data); 2380 fingerprint->SerializeToString(&proto_data);
2477 bool success = base::Base64Encode(proto_data, &risk_data_); 2381 bool success = base::Base64Encode(proto_data, &risk_data_);
2478 DCHECK(success); 2382 DCHECK(success);
2479 2383
2480 SubmitWithWallet(); 2384 SubmitWithWallet();
2481 } 2385 }
2482 2386
2483 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { 2387 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) {
2484 #if !defined(OS_ANDROID)
2485 chrome::NavigateParams params( 2388 chrome::NavigateParams params(
2486 chrome::FindBrowserWithWebContents(web_contents()), 2389 chrome::FindBrowserWithWebContents(web_contents()),
2487 url, 2390 url,
2488 content::PAGE_TRANSITION_AUTO_BOOKMARK); 2391 content::PAGE_TRANSITION_AUTO_BOOKMARK);
2489 params.disposition = NEW_FOREGROUND_TAB; 2392 params.disposition = NEW_FOREGROUND_TAB;
2490 chrome::Navigate(&params); 2393 chrome::Navigate(&params);
2491 #endif
2492 } 2394 }
2493 2395
2494 bool AutofillDialogControllerImpl::IsEditingExistingData( 2396 bool AutofillDialogControllerImpl::IsEditingExistingData(
2495 DialogSection section) const { 2397 DialogSection section) const {
2496 return section_editing_state_.count(section) > 0; 2398 return section_editing_state_.count(section) > 0;
2497 } 2399 }
2498 2400
2499 bool AutofillDialogControllerImpl::IsManuallyEditingSection( 2401 bool AutofillDialogControllerImpl::IsManuallyEditingSection(
2500 DialogSection section) const { 2402 DialogSection section) const {
2501 return IsEditingExistingData(section) || 2403 return IsEditingExistingData(section) ||
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2808 SaveProfileGleanedFromSection(profile, section); 2710 SaveProfileGleanedFromSection(profile, section);
2809 2711
2810 AutofillProfileWrapper profile_wrapper(&profile, 0); 2712 AutofillProfileWrapper profile_wrapper(&profile, 0);
2811 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); 2713 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_);
2812 } 2714 }
2813 } 2715 }
2814 } 2716 }
2815 2717
2816 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { 2718 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) {
2817 FillOutputForSectionWithComparator( 2719 FillOutputForSectionWithComparator(
2818 section, base::Bind(DetailInputMatchesField, section)); 2720 section, base::Bind(common::DetailInputMatchesField, section));
2819 } 2721 }
2820 2722
2821 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( 2723 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection(
2822 DialogSection section) const { 2724 DialogSection section) const {
2823 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for 2725 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for
2824 // any of the fields. 2726 // any of the fields.
2825 if (section == SECTION_SHIPPING) 2727 if (section == SECTION_SHIPPING)
2826 return cares_about_shipping_; 2728 return cares_about_shipping_;
2827 2729
2828 return true; 2730 return true;
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
3410 AutofillMetrics::DIALOG_CANCELED); 3312 AutofillMetrics::DIALOG_CANCELED);
3411 } 3313 }
3412 3314
3413 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric( 3315 void AutofillDialogControllerImpl::LogSuggestionItemSelectedMetric(
3414 const SuggestionsMenuModel& model) { 3316 const SuggestionsMenuModel& model) {
3415 DialogSection section = SectionForSuggestionsMenuModel(model); 3317 DialogSection section = SectionForSuggestionsMenuModel(model);
3416 3318
3417 AutofillMetrics::DialogUiEvent dialog_ui_event; 3319 AutofillMetrics::DialogUiEvent dialog_ui_event;
3418 if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) { 3320 if (model.GetItemKeyForCheckedItem() == kAddNewItemKey) {
3419 // Selected to add a new item. 3321 // Selected to add a new item.
3420 dialog_ui_event = DialogSectionToUiItemAddedEvent(section); 3322 dialog_ui_event = common::DialogSectionToUiItemAddedEvent(section);
3421 } else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) { 3323 } else if (IsASuggestionItemKey(model.GetItemKeyForCheckedItem())) {
3422 // Selected an existing item. 3324 // Selected an existing item.
3423 dialog_ui_event = DialogSectionToUiSelectionChangedEvent(section); 3325 dialog_ui_event = common::DialogSectionToUiSelectionChangedEvent(section);
3424 } else { 3326 } else {
3425 // TODO(estade): add logging for "Manage items" or "Use billing for 3327 // TODO(estade): add logging for "Manage items" or "Use billing for
3426 // shipping"? 3328 // shipping"?
3427 return; 3329 return;
3428 } 3330 }
3429 3331
3430 GetMetricLogger().LogDialogUiEvent(GetDialogType(), dialog_ui_event); 3332 GetMetricLogger().LogDialogUiEvent(GetDialogType(), dialog_ui_event);
3431 } 3333 }
3432 3334
3433 void AutofillDialogControllerImpl::LogDialogLatencyToShow() { 3335 void AutofillDialogControllerImpl::LogDialogLatencyToShow() {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
3518 view_->GetUserInput(SECTION_CC_BILLING, &output); 3420 view_->GetUserInput(SECTION_CC_BILLING, &output);
3519 CreditCard card; 3421 CreditCard card;
3520 GetBillingInfoFromOutputs(output, &card, NULL, NULL); 3422 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
3521 backing_last_four = card.TypeAndLastFourDigits(); 3423 backing_last_four = card.TypeAndLastFourDigits();
3522 } 3424 }
3523 AutofillCreditCardBubbleController::ShowGeneratedCardUI( 3425 AutofillCreditCardBubbleController::ShowGeneratedCardUI(
3524 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); 3426 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits());
3525 } 3427 }
3526 3428
3527 } // namespace autofill 3429 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/autofill_dialog_controller_impl.h ('k') | chrome/browser/ui/autofill/autofill_dialog_types.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698