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

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: removed irrelevant tests. 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 "base/base64.h" 13 #include "base/base64.h"
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/prefs/pref_service.h" 17 #include "base/prefs/pref_service.h"
18 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/strings/string_util.h" 20 #include "base/strings/string_util.h"
21 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
22 #include "base/time/time.h" 22 #include "base/time/time.h"
23 #include "chrome/browser/autofill/personal_data_manager_factory.h" 23 #include "chrome/browser/autofill/personal_data_manager_factory.h"
24 #include "chrome/browser/browser_process.h" 24 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/extensions/shell_window_registry.h" 25 #include "chrome/browser/extensions/shell_window_registry.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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 return base::string16(); 372 return base::string16();
426 } 373 }
427 374
428 gfx::Image GetGeneratedCardImage(const string16& card_number) { 375 gfx::Image GetGeneratedCardImage(const string16& card_number) {
429 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 376 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
430 const gfx::ImageSkia* card = 377 const gfx::ImageSkia* card =
431 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD); 378 rb.GetImageSkiaNamed(IDR_AUTOFILL_GENERATED_CARD);
432 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false); 379 gfx::Canvas canvas(card->size(), ui::SCALE_FACTOR_100P, false);
433 canvas.DrawImageInt(*card, 0, 0); 380 canvas.DrawImageInt(*card, 0, 0);
434 381
435 #if !defined(OS_ANDROID)
436 gfx::Rect display_rect(gfx::Point(), card->size()); 382 gfx::Rect display_rect(gfx::Point(), card->size());
437 display_rect.Inset(14, 0, 14, 0); 383 display_rect.Inset(14, 0, 14, 0);
438 // TODO(estade): fallback font for systems that don't have Helvetica? 384 // TODO(estade): fallback font for systems that don't have Helvetica?
439 gfx::Font helvetica("Helvetica", 14); 385 gfx::Font helvetica("Helvetica", 14);
440 gfx::ShadowValues shadows; 386 gfx::ShadowValues shadows;
441 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1), 387 shadows.push_back(gfx::ShadowValue(gfx::Point(0, 1),
442 0.0, 388 0.0,
443 SkColorSetARGB(85, 0, 0, 0))); 389 SkColorSetARGB(85, 0, 0, 0)));
444 canvas.DrawStringWithShadows( 390 canvas.DrawStringWithShadows(
445 card_number, 391 card_number,
446 helvetica, 392 helvetica,
447 SK_ColorWHITE, 393 SK_ColorWHITE,
448 display_rect, 0, 0, shadows); 394 display_rect, 0, 0, shadows);
449 #endif
450 395
451 gfx::ImageSkia skia(canvas.ExtractImageRep()); 396 gfx::ImageSkia skia(canvas.ExtractImageRep());
452 return gfx::Image(skia); 397 return gfx::Image(skia);
453 } 398 }
454 399
455 } // namespace 400 } // namespace
456 401
457 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {} 402 AutofillDialogViewDelegate::~AutofillDialogViewDelegate() {}
458 403
459 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() { 404 AutofillDialogControllerImpl::~AutofillDialogControllerImpl() {
460 if (popup_controller_) 405 if (popup_controller_)
461 popup_controller_->Hide(); 406 popup_controller_->Hide();
462 407
463 GetMetricLogger().LogDialogInitialUserState( 408 GetMetricLogger().LogDialogInitialUserState(
464 GetDialogType(), initial_user_state_); 409 GetDialogType(), initial_user_state_);
465 410
466 if (deemphasized_render_view_ && web_contents()) { 411 if (deemphasized_render_view_ && web_contents()) {
467 web_contents()->GetRenderViewHost()->Send( 412 web_contents()->GetRenderViewHost()->Send(
468 new ChromeViewMsg_SetVisuallyDeemphasized( 413 new ChromeViewMsg_SetVisuallyDeemphasized(
469 web_contents()->GetRenderViewHost()->GetRoutingID(), false)); 414 web_contents()->GetRenderViewHost()->GetRoutingID(), false));
470 } 415 }
471 } 416 }
472 417
473 #if !defined(OS_ANDROID)
474 // static 418 // static
475 base::WeakPtr<AutofillDialogControllerImpl> 419 base::WeakPtr<AutofillDialogControllerImpl>
476 AutofillDialogControllerImpl::Create( 420 AutofillDialogControllerImpl::Create(
477 content::WebContents* contents, 421 content::WebContents* contents,
478 const FormData& form_structure, 422 const FormData& form_structure,
479 const GURL& source_url, 423 const GURL& source_url,
480 const DialogType dialog_type, 424 const DialogType dialog_type,
481 const base::Callback<void(const FormStructure*, 425 const base::Callback<void(const FormStructure*,
482 const std::string&)>& callback) { 426 const std::string&)>& callback) {
483 // AutofillDialogControllerImpl owns itself. 427 // AutofillDialogControllerImpl owns itself.
484 AutofillDialogControllerImpl* autofill_dialog_controller = 428 AutofillDialogControllerImpl* autofill_dialog_controller =
485 new AutofillDialogControllerImpl(contents, 429 new AutofillDialogControllerImpl(contents,
486 form_structure, 430 form_structure,
487 source_url, 431 source_url,
488 dialog_type, 432 dialog_type,
489 callback); 433 callback);
490 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr(); 434 return autofill_dialog_controller->weak_ptr_factory_.GetWeakPtr();
491 } 435 }
492 #endif // !defined(OS_ANDROID)
493 436
494 // static 437 // static
495 void AutofillDialogControllerImpl::RegisterProfilePrefs( 438 void AutofillDialogControllerImpl::RegisterProfilePrefs(
496 user_prefs::PrefRegistrySyncable* registry) { 439 user_prefs::PrefRegistrySyncable* registry) {
497 registry->RegisterIntegerPref( 440 registry->RegisterIntegerPref(
498 ::prefs::kAutofillDialogShowCount, 441 ::prefs::kAutofillDialogShowCount,
499 0, 442 0,
500 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 443 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
501 registry->RegisterBooleanPref( 444 registry->RegisterBooleanPref(
502 ::prefs::kAutofillDialogHasPaidWithWallet, 445 ::prefs::kAutofillDialogHasPaidWithWallet,
503 false, 446 false,
504 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 447 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
505 registry->RegisterBooleanPref( 448 registry->RegisterBooleanPref(
506 ::prefs::kAutofillDialogPayWithoutWallet, 449 ::prefs::kAutofillDialogPayWithoutWallet,
507 false, 450 false,
508 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 451 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
509 registry->RegisterDictionaryPref( 452 registry->RegisterDictionaryPref(
510 ::prefs::kAutofillDialogAutofillDefault, 453 ::prefs::kAutofillDialogAutofillDefault,
511 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 454 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
512 } 455 }
513 456
457 // static
458 base::WeakPtr<AutofillDialogController> AutofillDialogController::Create(
459 content::WebContents* contents,
460 const FormData& form_structure,
461 const GURL& source_url,
462 const DialogType dialog_type,
463 const base::Callback<void(const FormStructure*,
464 const std::string&)>& callback) {
465 return AutofillDialogControllerImpl::Create(contents,
466 form_structure,
467 source_url,
468 dialog_type,
469 callback);
470 }
471
472 // static
473 void AutofillDialogController::RegisterProfilePrefs(
474 user_prefs::PrefRegistrySyncable* registry) {
475 AutofillDialogControllerImpl::RegisterProfilePrefs(registry);
476 }
477
514 void AutofillDialogControllerImpl::Show() { 478 void AutofillDialogControllerImpl::Show() {
515 dialog_shown_timestamp_ = base::Time::Now(); 479 dialog_shown_timestamp_ = base::Time::Now();
516 480
517 content::NavigationEntry* entry = 481 content::NavigationEntry* entry =
518 web_contents()->GetController().GetActiveEntry(); 482 web_contents()->GetController().GetActiveEntry();
519 const GURL& active_url = entry ? entry->GetURL() : web_contents()->GetURL(); 483 const GURL& active_url = entry ? entry->GetURL() : web_contents()->GetURL();
520 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); 484 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin();
521 485
522 // Log any relevant UI metrics and security exceptions. 486 // Log any relevant UI metrics and security exceptions.
523 GetMetricLogger().LogDialogUiEvent( 487 GetMetricLogger().LogDialogUiEvent(
(...skipping 20 matching lines...) Expand all
544 form_structure_.ParseFieldTypesFromAutocompleteAttributes( 508 form_structure_.ParseFieldTypesFromAutocompleteAttributes(
545 &has_types, &has_sections); 509 &has_types, &has_sections);
546 510
547 // Fail if the author didn't specify autocomplete types. 511 // Fail if the author didn't specify autocomplete types.
548 if (!has_types) { 512 if (!has_types) {
549 callback_.Run(NULL, std::string()); 513 callback_.Run(NULL, std::string());
550 delete this; 514 delete this;
551 return; 515 return;
552 } 516 }
553 517
554 const DetailInput kEmailInputs[] = { 518 common::BuildInputsForSection(SECTION_EMAIL,
555 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, 519 &requested_email_fields_);
556 }; 520 common::BuildInputsForSection(SECTION_CC,
557 521 &requested_cc_fields_);
558 const DetailInput kCCInputs[] = { 522 common::BuildInputsForSection(SECTION_BILLING,
559 { 2, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, 523 &requested_billing_fields_);
560 { 3, CREDIT_CARD_EXP_MONTH }, 524 common::BuildInputsForSection(SECTION_CC_BILLING,
561 { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR }, 525 &requested_cc_billing_fields_);
562 { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, 526 common::BuildInputsForSection(SECTION_SHIPPING,
563 1.5 }, 527 &requested_shipping_fields_);
564 };
565
566 const DetailInput kBillingInputs[] = {
567 { 4, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME },
568 { 5, ADDRESS_BILLING_LINE1,
569 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
570 { 6, ADDRESS_BILLING_LINE2,
571 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
572 { 7, ADDRESS_BILLING_CITY,
573 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
574 // TODO(estade): state placeholder should depend on locale.
575 { 8, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
576 { 8, ADDRESS_BILLING_ZIP,
577 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
578 // We don't allow the user to change the country: http://crbug.com/247518
579 { -1, ADDRESS_BILLING_COUNTRY, 0 },
580 { 10, PHONE_BILLING_WHOLE_NUMBER,
581 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
582 };
583
584 const DetailInput kShippingInputs[] = {
585 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME },
586 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
587 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
588 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
589 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
590 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
591 { -1, ADDRESS_HOME_COUNTRY, 0 },
592 { 17, PHONE_HOME_WHOLE_NUMBER,
593 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
594 };
595
596 BuildInputs(kEmailInputs,
597 arraysize(kEmailInputs),
598 &requested_email_fields_);
599
600 BuildInputs(kCCInputs,
601 arraysize(kCCInputs),
602 &requested_cc_fields_);
603
604 BuildInputs(kBillingInputs,
605 arraysize(kBillingInputs),
606 &requested_billing_fields_);
607
608 BuildInputs(kCCInputs,
609 arraysize(kCCInputs),
610 &requested_cc_billing_fields_);
611 BuildInputs(kBillingInputs,
612 arraysize(kBillingInputs),
613 &requested_cc_billing_fields_);
614
615 BuildInputs(kShippingInputs,
616 arraysize(kShippingInputs),
617 &requested_shipping_fields_);
618 528
619 // Test whether we need to show the shipping section. If filling that section 529 // Test whether we need to show the shipping section. If filling that section
620 // would be a no-op, don't show it. 530 // would be a no-op, don't show it.
621 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); 531 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING);
622 EmptyDataModelWrapper empty_wrapper; 532 EmptyDataModelWrapper empty_wrapper;
623 cares_about_shipping_ = empty_wrapper.FillFormStructure( 533 cares_about_shipping_ = empty_wrapper.FillFormStructure(
624 inputs, 534 inputs,
625 base::Bind(DetailInputMatchesField, SECTION_SHIPPING), 535 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING),
626 &form_structure_); 536 &form_structure_);
627 537
628 SuggestionsUpdated(); 538 SuggestionsUpdated();
629 539
630 int show_count = 540 int show_count =
631 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount); 541 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount);
632 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount, 542 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount,
633 show_count + 1); 543 show_count + 1);
634 544
635 // TODO(estade): don't show the dialog if the site didn't specify the right 545 // TODO(estade): don't show the dialog if the site didn't specify the right
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 !IsSubmitPausedOn(wallet::VERIFY_CVV) && 752 !IsSubmitPausedOn(wallet::VERIFY_CVV) &&
843 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; 753 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE;
844 if (!show_wallet_interstitial) 754 if (!show_wallet_interstitial)
845 return DialogOverlayState(); 755 return DialogOverlayState();
846 756
847 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 757 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
848 DialogOverlayState state; 758 DialogOverlayState state;
849 759
850 state.strings.push_back(DialogOverlayString()); 760 state.strings.push_back(DialogOverlayString());
851 DialogOverlayString& string = state.strings.back(); 761 DialogOverlayString& string = state.strings.back();
852 #if !defined(OS_ANDROID)
853 // gfx::Font isn't implemented on Android; DeriveFont() causes a null deref.
854 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); 762 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4);
855 #endif
856 763
857 // First-run, post-submit, Wallet expository page. 764 // First-run, post-submit, Wallet expository page.
858 if (full_wallet_ && full_wallet_->required_actions().empty()) { 765 if (full_wallet_ && full_wallet_->required_actions().empty()) {
859 string16 cc_number = 766 string16 cc_number =
860 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER)); 767 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER));
861 DCHECK_EQ(16U, cc_number.size()); 768 DCHECK_EQ(16U, cc_number.size());
862 state.image = GetGeneratedCardImage( 769 state.image = GetGeneratedCardImage(
863 ASCIIToUTF16("xxxx xxxx xxxx ") + 770 ASCIIToUTF16("xxxx xxxx xxxx ") +
864 cc_number.substr(cc_number.size() - 4)); 771 cc_number.substr(cc_number.size() - 4));
865 string.text = l10n_util::GetStringUTF16( 772 string.text = l10n_util::GetStringUTF16(
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
1750 } 1657 }
1751 1658
1752 // If the user clicks while the popup is already showing, be sure to hide 1659 // If the user clicks while the popup is already showing, be sure to hide
1753 // it. 1660 // it.
1754 if (!was_edit && popup_controller_.get()) { 1661 if (!was_edit && popup_controller_.get()) {
1755 HidePopup(); 1662 HidePopup();
1756 return; 1663 return;
1757 } 1664 }
1758 1665
1759 std::vector<string16> popup_values, popup_labels, popup_icons; 1666 std::vector<string16> popup_values, popup_labels, popup_icons;
1760 if (IsCreditCardType(input->type)) { 1667 if (common::IsCreditCardType(input->type)) {
1761 GetManager()->GetCreditCardSuggestions(AutofillType(input->type), 1668 GetManager()->GetCreditCardSuggestions(AutofillType(input->type),
1762 field_contents, 1669 field_contents,
1763 &popup_values, 1670 &popup_values,
1764 &popup_labels, 1671 &popup_labels,
1765 &popup_icons, 1672 &popup_icons,
1766 &popup_guids_); 1673 &popup_guids_);
1767 } else { 1674 } else {
1768 std::vector<ServerFieldType> field_types; 1675 std::vector<ServerFieldType> field_types;
1769 field_types.push_back(EMAIL_ADDRESS); 1676 field_types.push_back(EMAIL_ADDRESS);
1770 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin(); 1677 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin();
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
2052 1959
2053 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { 1960 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) {
2054 // TODO(estade): implement. 1961 // TODO(estade): implement.
2055 } 1962 }
2056 1963
2057 void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, 1964 void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value,
2058 int identifier) { 1965 int identifier) {
2059 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; 1966 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier];
2060 1967
2061 scoped_ptr<DataModelWrapper> wrapper; 1968 scoped_ptr<DataModelWrapper> wrapper;
2062 if (IsCreditCardType(input_showing_popup_->type)) { 1969 if (common::IsCreditCardType(input_showing_popup_->type)) {
2063 wrapper.reset(new AutofillCreditCardWrapper( 1970 wrapper.reset(new AutofillCreditCardWrapper(
2064 GetManager()->GetCreditCardByGUID(pair.first))); 1971 GetManager()->GetCreditCardByGUID(pair.first)));
2065 } else { 1972 } else {
2066 wrapper.reset(new AutofillProfileWrapper( 1973 wrapper.reset(new AutofillProfileWrapper(
2067 GetManager()->GetProfileByGUID(pair.first), pair.second)); 1974 GetManager()->GetProfileByGUID(pair.first), pair.second));
2068 } 1975 }
2069 1976
2070 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { 1977 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) {
2071 DialogSection section = static_cast<DialogSection>(i); 1978 DialogSection section = static_cast<DialogSection>(i);
2072 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); 1979 wrapper->FillInputs(MutableRequestedFieldsForSection(section));
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
2327 return popup_controller_->HandleKeyPressEvent(event); 2234 return popup_controller_->HandleKeyPressEvent(event);
2328 2235
2329 return false; 2236 return false;
2330 } 2237 }
2331 2238
2332 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { 2239 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const {
2333 DCHECK_GT(form_structure_.field_count(), 0U); 2240 DCHECK_GT(form_structure_.field_count(), 0U);
2334 2241
2335 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 2242 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
2336 AutofillType type = form_structure_.field(i)->Type(); 2243 AutofillType type = form_structure_.field(i)->Type();
2337 if (IsCreditCardType(type.GetStorableType())) 2244 if (common::IsCreditCardType(type.GetStorableType()))
2338 return true; 2245 return true;
2339 } 2246 }
2340 2247
2341 return false; 2248 return false;
2342 } 2249 }
2343 2250
2344 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { 2251 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const {
2345 return source_url_.SchemeIs(chrome::kHttpsScheme); 2252 return source_url_.SchemeIs(chrome::kHttpsScheme);
2346 } 2253 }
2347 2254
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
2405 2312
2406 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { 2313 void AutofillDialogControllerImpl::LoadRiskFingerprintData() {
2407 risk_data_.clear(); 2314 risk_data_.clear();
2408 2315
2409 uint64 obfuscated_gaia_id = 0; 2316 uint64 obfuscated_gaia_id = 0;
2410 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), 2317 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(),
2411 &obfuscated_gaia_id); 2318 &obfuscated_gaia_id);
2412 DCHECK(success); 2319 DCHECK(success);
2413 2320
2414 gfx::Rect window_bounds; 2321 gfx::Rect window_bounds;
2415 #if !defined(OS_ANDROID)
2416 window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds(); 2322 window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds();
2417 #endif
2418 2323
2419 PrefService* user_prefs = profile_->GetPrefs(); 2324 PrefService* user_prefs = profile_->GetPrefs();
2420 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); 2325 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset);
2421 std::string accept_languages = 2326 std::string accept_languages =
2422 user_prefs->GetString(::prefs::kAcceptLanguages); 2327 user_prefs->GetString(::prefs::kAcceptLanguages);
2423 base::Time install_time = base::Time::FromTimeT( 2328 base::Time install_time = base::Time::FromTimeT(
2424 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); 2329 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate));
2425 2330
2426 risk::GetFingerprint( 2331 risk::GetFingerprint(
2427 obfuscated_gaia_id, window_bounds, *web_contents(), 2332 obfuscated_gaia_id, window_bounds, *web_contents(),
2428 chrome::VersionInfo().Version(), charset, accept_languages, install_time, 2333 chrome::VersionInfo().Version(), charset, accept_languages, install_time,
2429 dialog_type_, g_browser_process->GetApplicationLocale(), 2334 dialog_type_, g_browser_process->GetApplicationLocale(),
2430 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, 2335 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData,
2431 weak_ptr_factory_.GetWeakPtr())); 2336 weak_ptr_factory_.GetWeakPtr()));
2432 } 2337 }
2433 2338
2434 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( 2339 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData(
2435 scoped_ptr<risk::Fingerprint> fingerprint) { 2340 scoped_ptr<risk::Fingerprint> fingerprint) {
2436 DCHECK(AreLegalDocumentsCurrent()); 2341 DCHECK(AreLegalDocumentsCurrent());
2437 2342
2438 std::string proto_data; 2343 std::string proto_data;
2439 fingerprint->SerializeToString(&proto_data); 2344 fingerprint->SerializeToString(&proto_data);
2440 bool success = base::Base64Encode(proto_data, &risk_data_); 2345 bool success = base::Base64Encode(proto_data, &risk_data_);
2441 DCHECK(success); 2346 DCHECK(success);
2442 2347
2443 SubmitWithWallet(); 2348 SubmitWithWallet();
2444 } 2349 }
2445 2350
2446 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { 2351 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) {
2447 #if !defined(OS_ANDROID)
2448 chrome::NavigateParams params( 2352 chrome::NavigateParams params(
2449 chrome::FindBrowserWithWebContents(web_contents()), 2353 chrome::FindBrowserWithWebContents(web_contents()),
2450 url, 2354 url,
2451 content::PAGE_TRANSITION_AUTO_BOOKMARK); 2355 content::PAGE_TRANSITION_AUTO_BOOKMARK);
2452 params.disposition = NEW_FOREGROUND_TAB; 2356 params.disposition = NEW_FOREGROUND_TAB;
2453 chrome::Navigate(&params); 2357 chrome::Navigate(&params);
2454 #endif
2455 } 2358 }
2456 2359
2457 bool AutofillDialogControllerImpl::IsEditingExistingData( 2360 bool AutofillDialogControllerImpl::IsEditingExistingData(
2458 DialogSection section) const { 2361 DialogSection section) const {
2459 return section_editing_state_.count(section) > 0; 2362 return section_editing_state_.count(section) > 0;
2460 } 2363 }
2461 2364
2462 bool AutofillDialogControllerImpl::IsManuallyEditingSection( 2365 bool AutofillDialogControllerImpl::IsManuallyEditingSection(
2463 DialogSection section) const { 2366 DialogSection section) const {
2464 return IsEditingExistingData(section) || 2367 return IsEditingExistingData(section) ||
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
2771 SaveProfileGleanedFromSection(profile, section); 2674 SaveProfileGleanedFromSection(profile, section);
2772 2675
2773 AutofillProfileWrapper profile_wrapper(&profile, 0); 2676 AutofillProfileWrapper profile_wrapper(&profile, 0);
2774 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); 2677 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_);
2775 } 2678 }
2776 } 2679 }
2777 } 2680 }
2778 2681
2779 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { 2682 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) {
2780 FillOutputForSectionWithComparator( 2683 FillOutputForSectionWithComparator(
2781 section, base::Bind(DetailInputMatchesField, section)); 2684 section, base::Bind(common::DetailInputMatchesField, section));
2782 } 2685 }
2783 2686
2784 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( 2687 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection(
2785 DialogSection section) const { 2688 DialogSection section) const {
2786 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for 2689 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for
2787 // any of the fields. 2690 // any of the fields.
2788 if (section == SECTION_SHIPPING) 2691 if (section == SECTION_SHIPPING)
2789 return cares_about_shipping_; 2692 return cares_about_shipping_;
2790 2693
2791 return true; 2694 return true;
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
3481 view_->GetUserInput(SECTION_CC_BILLING, &output); 3384 view_->GetUserInput(SECTION_CC_BILLING, &output);
3482 CreditCard card; 3385 CreditCard card;
3483 GetBillingInfoFromOutputs(output, &card, NULL, NULL); 3386 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
3484 backing_last_four = card.TypeAndLastFourDigits(); 3387 backing_last_four = card.TypeAndLastFourDigits();
3485 } 3388 }
3486 AutofillCreditCardBubbleController::ShowGeneratedCardUI( 3389 AutofillCreditCardBubbleController::ShowGeneratedCardUI(
3487 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); 3390 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits());
3488 } 3391 }
3489 3392
3490 } // namespace autofill 3393 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698