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 |
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 Loading... |
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 InputTypeMatchesFieldType(input, AutofillType(field_type)); |
169 } | 126 } |
170 | 127 |
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 } | |
180 | |
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) { |
189 form_group->SetInfo(AutofillType(type), | 136 form_group->SetInfo(AutofillType(type), |
190 iter->second, | 137 iter->second, |
(...skipping 27 matching lines...) Expand all Loading... |
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 Loading... |
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_) { | 411 if (deemphasized_render_view_) { |
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 = contents_->GetController().GetActiveEntry(); | 481 content::NavigationEntry* entry = contents_->GetController().GetActiveEntry(); |
518 const GURL& active_url = entry ? entry->GetURL() : contents_->GetURL(); | 482 const GURL& active_url = entry ? entry->GetURL() : contents_->GetURL(); |
519 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); | 483 invoked_from_same_origin_ = active_url.GetOrigin() == source_url_.GetOrigin(); |
520 | 484 |
521 // Log any relevant UI metrics and security exceptions. | 485 // Log any relevant UI metrics and security exceptions. |
522 GetMetricLogger().LogDialogUiEvent( | 486 GetMetricLogger().LogDialogUiEvent( |
523 GetDialogType(), AutofillMetrics::DIALOG_UI_SHOWN); | 487 GetDialogType(), AutofillMetrics::DIALOG_UI_SHOWN); |
(...skipping 19 matching lines...) Expand all Loading... |
543 form_structure_.ParseFieldTypesFromAutocompleteAttributes( | 507 form_structure_.ParseFieldTypesFromAutocompleteAttributes( |
544 &has_types, &has_sections); | 508 &has_types, &has_sections); |
545 | 509 |
546 // Fail if the author didn't specify autocomplete types. | 510 // Fail if the author didn't specify autocomplete types. |
547 if (!has_types) { | 511 if (!has_types) { |
548 callback_.Run(NULL, std::string()); | 512 callback_.Run(NULL, std::string()); |
549 delete this; | 513 delete this; |
550 return; | 514 return; |
551 } | 515 } |
552 | 516 |
553 const DetailInput kEmailInputs[] = { | 517 common::BuildInputsForSection(SECTION_EMAIL, |
554 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 518 &requested_email_fields_); |
555 }; | 519 common::BuildInputsForSection(SECTION_CC, |
556 | 520 &requested_cc_fields_); |
557 const DetailInput kCCInputs[] = { | 521 common::BuildInputsForSection(SECTION_BILLING, |
558 { 2, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, | 522 &requested_billing_fields_); |
559 { 3, CREDIT_CARD_EXP_MONTH }, | 523 common::BuildInputsForSection(SECTION_CC_BILLING, |
560 { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR }, | 524 &requested_cc_billing_fields_); |
561 { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, | 525 common::BuildInputsForSection(SECTION_SHIPPING, |
562 1.5 }, | 526 &requested_shipping_fields_); |
563 }; | |
564 | |
565 const DetailInput kBillingInputs[] = { | |
566 { 4, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, | |
567 { 5, ADDRESS_BILLING_LINE1, | |
568 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | |
569 { 6, ADDRESS_BILLING_LINE2, | |
570 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | |
571 { 7, ADDRESS_BILLING_CITY, | |
572 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | |
573 // TODO(estade): state placeholder should depend on locale. | |
574 { 8, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | |
575 { 8, ADDRESS_BILLING_ZIP, | |
576 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | |
577 // We don't allow the user to change the country: http://crbug.com/247518 | |
578 { -1, ADDRESS_BILLING_COUNTRY, 0 }, | |
579 { 10, PHONE_BILLING_WHOLE_NUMBER, | |
580 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | |
581 }; | |
582 | |
583 const DetailInput kShippingInputs[] = { | |
584 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, | |
585 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | |
586 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | |
587 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | |
588 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | |
589 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | |
590 { -1, ADDRESS_HOME_COUNTRY, 0 }, | |
591 { 17, PHONE_HOME_WHOLE_NUMBER, | |
592 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | |
593 }; | |
594 | |
595 BuildInputs(kEmailInputs, | |
596 arraysize(kEmailInputs), | |
597 &requested_email_fields_); | |
598 | |
599 BuildInputs(kCCInputs, | |
600 arraysize(kCCInputs), | |
601 &requested_cc_fields_); | |
602 | |
603 BuildInputs(kBillingInputs, | |
604 arraysize(kBillingInputs), | |
605 &requested_billing_fields_); | |
606 | |
607 BuildInputs(kCCInputs, | |
608 arraysize(kCCInputs), | |
609 &requested_cc_billing_fields_); | |
610 BuildInputs(kBillingInputs, | |
611 arraysize(kBillingInputs), | |
612 &requested_cc_billing_fields_); | |
613 | |
614 BuildInputs(kShippingInputs, | |
615 arraysize(kShippingInputs), | |
616 &requested_shipping_fields_); | |
617 | 527 |
618 // Test whether we need to show the shipping section. If filling that section | 528 // Test whether we need to show the shipping section. If filling that section |
619 // would be a no-op, don't show it. | 529 // would be a no-op, don't show it. |
620 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); | 530 const DetailInputs& inputs = RequestedFieldsForSection(SECTION_SHIPPING); |
621 EmptyDataModelWrapper empty_wrapper; | 531 EmptyDataModelWrapper empty_wrapper; |
622 cares_about_shipping_ = empty_wrapper.FillFormStructure( | 532 cares_about_shipping_ = empty_wrapper.FillFormStructure( |
623 inputs, | 533 inputs, |
624 base::Bind(DetailInputMatchesField, SECTION_SHIPPING), | 534 base::Bind(common::DetailInputMatchesField, SECTION_SHIPPING), |
625 &form_structure_); | 535 &form_structure_); |
626 | 536 |
627 SuggestionsUpdated(); | 537 SuggestionsUpdated(); |
628 | 538 |
629 int show_count = | 539 int show_count = |
630 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount); | 540 profile_->GetPrefs()->GetInteger(::prefs::kAutofillDialogShowCount); |
631 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount, | 541 profile_->GetPrefs()->SetInteger(::prefs::kAutofillDialogShowCount, |
632 show_count + 1); | 542 show_count + 1); |
633 | 543 |
634 // TODO(estade): don't show the dialog if the site didn't specify the right | 544 // 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 Loading... |
841 !IsSubmitPausedOn(wallet::VERIFY_CVV) && | 751 !IsSubmitPausedOn(wallet::VERIFY_CVV) && |
842 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; | 752 GetDialogType() == DIALOG_TYPE_REQUEST_AUTOCOMPLETE; |
843 if (!show_wallet_interstitial) | 753 if (!show_wallet_interstitial) |
844 return DialogOverlayState(); | 754 return DialogOverlayState(); |
845 | 755 |
846 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 756 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
847 DialogOverlayState state; | 757 DialogOverlayState state; |
848 | 758 |
849 state.strings.push_back(DialogOverlayString()); | 759 state.strings.push_back(DialogOverlayString()); |
850 DialogOverlayString& string = state.strings.back(); | 760 DialogOverlayString& string = state.strings.back(); |
851 #if !defined(OS_ANDROID) | |
852 // gfx::Font isn't implemented on Android; DeriveFont() causes a null deref. | |
853 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); | 761 string.font = rb.GetFont(ui::ResourceBundle::BaseFont).DeriveFont(4); |
854 #endif | |
855 | 762 |
856 // First-run, post-submit, Wallet expository page. | 763 // First-run, post-submit, Wallet expository page. |
857 if (full_wallet_ && full_wallet_->required_actions().empty()) { | 764 if (full_wallet_ && full_wallet_->required_actions().empty()) { |
858 string16 cc_number = | 765 string16 cc_number = |
859 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER)); | 766 full_wallet_->GetInfo(AutofillType(CREDIT_CARD_NUMBER)); |
860 DCHECK_EQ(16U, cc_number.size()); | 767 DCHECK_EQ(16U, cc_number.size()); |
861 state.image = GetGeneratedCardImage( | 768 state.image = GetGeneratedCardImage( |
862 ASCIIToUTF16("xxxx xxxx xxxx ") + | 769 ASCIIToUTF16("xxxx xxxx xxxx ") + |
863 cc_number.substr(cc_number.size() - 4)); | 770 cc_number.substr(cc_number.size() - 4)); |
864 string.text = l10n_util::GetStringUTF16( | 771 string.text = l10n_util::GetStringUTF16( |
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 } | 1656 } |
1750 | 1657 |
1751 // If the user clicks while the popup is already showing, be sure to hide | 1658 // If the user clicks while the popup is already showing, be sure to hide |
1752 // it. | 1659 // it. |
1753 if (!was_edit && popup_controller_.get()) { | 1660 if (!was_edit && popup_controller_.get()) { |
1754 HidePopup(); | 1661 HidePopup(); |
1755 return; | 1662 return; |
1756 } | 1663 } |
1757 | 1664 |
1758 std::vector<string16> popup_values, popup_labels, popup_icons; | 1665 std::vector<string16> popup_values, popup_labels, popup_icons; |
1759 if (IsCreditCardType(input->type)) { | 1666 if (common::IsCreditCardType(input->type)) { |
1760 GetManager()->GetCreditCardSuggestions(AutofillType(input->type), | 1667 GetManager()->GetCreditCardSuggestions(AutofillType(input->type), |
1761 field_contents, | 1668 field_contents, |
1762 &popup_values, | 1669 &popup_values, |
1763 &popup_labels, | 1670 &popup_labels, |
1764 &popup_icons, | 1671 &popup_icons, |
1765 &popup_guids_); | 1672 &popup_guids_); |
1766 } else { | 1673 } else { |
1767 std::vector<ServerFieldType> field_types; | 1674 std::vector<ServerFieldType> field_types; |
1768 field_types.push_back(EMAIL_ADDRESS); | 1675 field_types.push_back(EMAIL_ADDRESS); |
1769 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin(); | 1676 for (DetailInputs::const_iterator iter = requested_shipping_fields_.begin(); |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 | 1958 |
2052 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { | 1959 void AutofillDialogControllerImpl::DidSelectSuggestion(int identifier) { |
2053 // TODO(estade): implement. | 1960 // TODO(estade): implement. |
2054 } | 1961 } |
2055 | 1962 |
2056 void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, | 1963 void AutofillDialogControllerImpl::DidAcceptSuggestion(const string16& value, |
2057 int identifier) { | 1964 int identifier) { |
2058 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; | 1965 const PersonalDataManager::GUIDPair& pair = popup_guids_[identifier]; |
2059 | 1966 |
2060 scoped_ptr<DataModelWrapper> wrapper; | 1967 scoped_ptr<DataModelWrapper> wrapper; |
2061 if (IsCreditCardType(input_showing_popup_->type)) { | 1968 if (common::IsCreditCardType(input_showing_popup_->type)) { |
2062 wrapper.reset(new AutofillCreditCardWrapper( | 1969 wrapper.reset(new AutofillCreditCardWrapper( |
2063 GetManager()->GetCreditCardByGUID(pair.first))); | 1970 GetManager()->GetCreditCardByGUID(pair.first))); |
2064 } else { | 1971 } else { |
2065 wrapper.reset(new AutofillProfileWrapper( | 1972 wrapper.reset(new AutofillProfileWrapper( |
2066 GetManager()->GetProfileByGUID(pair.first), pair.second)); | 1973 GetManager()->GetProfileByGUID(pair.first), pair.second)); |
2067 } | 1974 } |
2068 | 1975 |
2069 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { | 1976 for (size_t i = SECTION_MIN; i <= SECTION_MAX; ++i) { |
2070 DialogSection section = static_cast<DialogSection>(i); | 1977 DialogSection section = static_cast<DialogSection>(i); |
2071 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); | 1978 wrapper->FillInputs(MutableRequestedFieldsForSection(section)); |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2326 return popup_controller_->HandleKeyPressEvent(event); | 2233 return popup_controller_->HandleKeyPressEvent(event); |
2327 | 2234 |
2328 return false; | 2235 return false; |
2329 } | 2236 } |
2330 | 2237 |
2331 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { | 2238 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
2332 DCHECK_GT(form_structure_.field_count(), 0U); | 2239 DCHECK_GT(form_structure_.field_count(), 0U); |
2333 | 2240 |
2334 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 2241 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
2335 AutofillType type = form_structure_.field(i)->Type(); | 2242 AutofillType type = form_structure_.field(i)->Type(); |
2336 if (IsCreditCardType(type.GetStorableType())) | 2243 if (common::IsCreditCardType(type.GetStorableType())) |
2337 return true; | 2244 return true; |
2338 } | 2245 } |
2339 | 2246 |
2340 return false; | 2247 return false; |
2341 } | 2248 } |
2342 | 2249 |
2343 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { | 2250 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { |
2344 return source_url_.SchemeIs(chrome::kHttpsScheme); | 2251 return source_url_.SchemeIs(chrome::kHttpsScheme); |
2345 } | 2252 } |
2346 | 2253 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2404 | 2311 |
2405 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { | 2312 void AutofillDialogControllerImpl::LoadRiskFingerprintData() { |
2406 risk_data_.clear(); | 2313 risk_data_.clear(); |
2407 | 2314 |
2408 uint64 obfuscated_gaia_id = 0; | 2315 uint64 obfuscated_gaia_id = 0; |
2409 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), | 2316 bool success = base::StringToUint64(wallet_items_->obfuscated_gaia_id(), |
2410 &obfuscated_gaia_id); | 2317 &obfuscated_gaia_id); |
2411 DCHECK(success); | 2318 DCHECK(success); |
2412 | 2319 |
2413 gfx::Rect window_bounds; | 2320 gfx::Rect window_bounds; |
2414 #if !defined(OS_ANDROID) | |
2415 window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds(); | 2321 window_bounds = GetBaseWindowForWebContents(web_contents())->GetBounds(); |
2416 #endif | |
2417 | 2322 |
2418 PrefService* user_prefs = profile_->GetPrefs(); | 2323 PrefService* user_prefs = profile_->GetPrefs(); |
2419 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); | 2324 std::string charset = user_prefs->GetString(::prefs::kDefaultCharset); |
2420 std::string accept_languages = | 2325 std::string accept_languages = |
2421 user_prefs->GetString(::prefs::kAcceptLanguages); | 2326 user_prefs->GetString(::prefs::kAcceptLanguages); |
2422 base::Time install_time = base::Time::FromTimeT( | 2327 base::Time install_time = base::Time::FromTimeT( |
2423 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); | 2328 g_browser_process->local_state()->GetInt64(::prefs::kInstallDate)); |
2424 | 2329 |
2425 risk::GetFingerprint( | 2330 risk::GetFingerprint( |
2426 obfuscated_gaia_id, window_bounds, *web_contents(), | 2331 obfuscated_gaia_id, window_bounds, *web_contents(), |
2427 chrome::VersionInfo().Version(), charset, accept_languages, install_time, | 2332 chrome::VersionInfo().Version(), charset, accept_languages, install_time, |
2428 dialog_type_, g_browser_process->GetApplicationLocale(), | 2333 dialog_type_, g_browser_process->GetApplicationLocale(), |
2429 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, | 2334 base::Bind(&AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData, |
2430 weak_ptr_factory_.GetWeakPtr())); | 2335 weak_ptr_factory_.GetWeakPtr())); |
2431 } | 2336 } |
2432 | 2337 |
2433 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( | 2338 void AutofillDialogControllerImpl::OnDidLoadRiskFingerprintData( |
2434 scoped_ptr<risk::Fingerprint> fingerprint) { | 2339 scoped_ptr<risk::Fingerprint> fingerprint) { |
2435 DCHECK(AreLegalDocumentsCurrent()); | 2340 DCHECK(AreLegalDocumentsCurrent()); |
2436 | 2341 |
2437 std::string proto_data; | 2342 std::string proto_data; |
2438 fingerprint->SerializeToString(&proto_data); | 2343 fingerprint->SerializeToString(&proto_data); |
2439 bool success = base::Base64Encode(proto_data, &risk_data_); | 2344 bool success = base::Base64Encode(proto_data, &risk_data_); |
2440 DCHECK(success); | 2345 DCHECK(success); |
2441 | 2346 |
2442 SubmitWithWallet(); | 2347 SubmitWithWallet(); |
2443 } | 2348 } |
2444 | 2349 |
2445 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { | 2350 void AutofillDialogControllerImpl::OpenTabWithUrl(const GURL& url) { |
2446 #if !defined(OS_ANDROID) | |
2447 chrome::NavigateParams params( | 2351 chrome::NavigateParams params( |
2448 chrome::FindBrowserWithWebContents(web_contents()), | 2352 chrome::FindBrowserWithWebContents(web_contents()), |
2449 url, | 2353 url, |
2450 content::PAGE_TRANSITION_AUTO_BOOKMARK); | 2354 content::PAGE_TRANSITION_AUTO_BOOKMARK); |
2451 params.disposition = NEW_FOREGROUND_TAB; | 2355 params.disposition = NEW_FOREGROUND_TAB; |
2452 chrome::Navigate(¶ms); | 2356 chrome::Navigate(¶ms); |
2453 #endif | |
2454 } | 2357 } |
2455 | 2358 |
2456 bool AutofillDialogControllerImpl::IsEditingExistingData( | 2359 bool AutofillDialogControllerImpl::IsEditingExistingData( |
2457 DialogSection section) const { | 2360 DialogSection section) const { |
2458 return section_editing_state_.count(section) > 0; | 2361 return section_editing_state_.count(section) > 0; |
2459 } | 2362 } |
2460 | 2363 |
2461 bool AutofillDialogControllerImpl::IsManuallyEditingSection( | 2364 bool AutofillDialogControllerImpl::IsManuallyEditingSection( |
2462 DialogSection section) const { | 2365 DialogSection section) const { |
2463 return IsEditingExistingData(section) || | 2366 return IsEditingExistingData(section) || |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2770 SaveProfileGleanedFromSection(profile, section); | 2673 SaveProfileGleanedFromSection(profile, section); |
2771 | 2674 |
2772 AutofillProfileWrapper profile_wrapper(&profile, 0); | 2675 AutofillProfileWrapper profile_wrapper(&profile, 0); |
2773 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); | 2676 profile_wrapper.FillFormStructure(inputs, compare, &form_structure_); |
2774 } | 2677 } |
2775 } | 2678 } |
2776 } | 2679 } |
2777 | 2680 |
2778 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { | 2681 void AutofillDialogControllerImpl::FillOutputForSection(DialogSection section) { |
2779 FillOutputForSectionWithComparator( | 2682 FillOutputForSectionWithComparator( |
2780 section, base::Bind(DetailInputMatchesField, section)); | 2683 section, base::Bind(common::DetailInputMatchesField, section)); |
2781 } | 2684 } |
2782 | 2685 |
2783 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( | 2686 bool AutofillDialogControllerImpl::FormStructureCaresAboutSection( |
2784 DialogSection section) const { | 2687 DialogSection section) const { |
2785 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for | 2688 // For now, only SECTION_SHIPPING may be omitted due to a site not asking for |
2786 // any of the fields. | 2689 // any of the fields. |
2787 if (section == SECTION_SHIPPING) | 2690 if (section == SECTION_SHIPPING) |
2788 return cares_about_shipping_; | 2691 return cares_about_shipping_; |
2789 | 2692 |
2790 return true; | 2693 return true; |
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3480 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3383 view_->GetUserInput(SECTION_CC_BILLING, &output); |
3481 CreditCard card; | 3384 CreditCard card; |
3482 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3385 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
3483 backing_last_four = card.TypeAndLastFourDigits(); | 3386 backing_last_four = card.TypeAndLastFourDigits(); |
3484 } | 3387 } |
3485 AutofillCreditCardBubbleController::ShowGeneratedCardUI( | 3388 AutofillCreditCardBubbleController::ShowGeneratedCardUI( |
3486 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); | 3389 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); |
3487 } | 3390 } |
3488 | 3391 |
3489 } // namespace autofill | 3392 } // namespace autofill |
OLD | NEW |