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

Side by Side Diff: components/autofill/core/browser/autofill_manager.cc

Issue 98753005: [Autofill] Sanitize all data that comes in over IPC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Loosen kMaxListSize a notch Created 6 years, 11 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 "components/autofill/core/browser/autofill_manager.h" 5 #include "components/autofill/core/browser/autofill_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 17 matching lines...) Expand all
28 #include "components/autofill/core/browser/autofill_manager_delegate.h" 28 #include "components/autofill/core/browser/autofill_manager_delegate.h"
29 #include "components/autofill/core/browser/autofill_manager_test_delegate.h" 29 #include "components/autofill/core/browser/autofill_manager_test_delegate.h"
30 #include "components/autofill/core/browser/autofill_metrics.h" 30 #include "components/autofill/core/browser/autofill_metrics.h"
31 #include "components/autofill/core/browser/autofill_profile.h" 31 #include "components/autofill/core/browser/autofill_profile.h"
32 #include "components/autofill/core/browser/autofill_type.h" 32 #include "components/autofill/core/browser/autofill_type.h"
33 #include "components/autofill/core/browser/credit_card.h" 33 #include "components/autofill/core/browser/credit_card.h"
34 #include "components/autofill/core/browser/form_structure.h" 34 #include "components/autofill/core/browser/form_structure.h"
35 #include "components/autofill/core/browser/personal_data_manager.h" 35 #include "components/autofill/core/browser/personal_data_manager.h"
36 #include "components/autofill/core/browser/phone_number.h" 36 #include "components/autofill/core/browser/phone_number.h"
37 #include "components/autofill/core/browser/phone_number_i18n.h" 37 #include "components/autofill/core/browser/phone_number_i18n.h"
38 #include "components/autofill/core/common/autofill_data_validation.h"
38 #include "components/autofill/core/common/autofill_pref_names.h" 39 #include "components/autofill/core/common/autofill_pref_names.h"
39 #include "components/autofill/core/common/autofill_switches.h" 40 #include "components/autofill/core/common/autofill_switches.h"
40 #include "components/autofill/core/common/form_data.h" 41 #include "components/autofill/core/common/form_data.h"
41 #include "components/autofill/core/common/form_data_predictions.h" 42 #include "components/autofill/core/common/form_data_predictions.h"
42 #include "components/autofill/core/common/form_field_data.h" 43 #include "components/autofill/core/common/form_field_data.h"
43 #include "components/autofill/core/common/password_form_fill_data.h" 44 #include "components/autofill/core/common/password_form_fill_data.h"
44 #include "components/user_prefs/pref_registry_syncable.h" 45 #include "components/user_prefs/pref_registry_syncable.h"
45 #include "grit/component_strings.h" 46 #include "grit/component_strings.h"
46 #include "third_party/WebKit/public/web/WebAutofillClient.h" 47 #include "third_party/WebKit/public/web/WebAutofillClient.h"
47 #include "ui/base/l10n/l10n_util.h" 48 #include "ui/base/l10n/l10n_util.h"
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 } 224 }
224 225
225 void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) { 226 void AutofillManager::SetExternalDelegate(AutofillExternalDelegate* delegate) {
226 // TODO(jrg): consider passing delegate into the ctor. That won't 227 // TODO(jrg): consider passing delegate into the ctor. That won't
227 // work if the delegate has a pointer to the AutofillManager, but 228 // work if the delegate has a pointer to the AutofillManager, but
228 // future directions may not need such a pointer. 229 // future directions may not need such a pointer.
229 external_delegate_ = delegate; 230 external_delegate_ = delegate;
230 autocomplete_history_manager_->SetExternalDelegate(delegate); 231 autocomplete_history_manager_->SetExternalDelegate(delegate);
231 } 232 }
232 233
234 void AutofillManager::ShowAutofillSettings() {
235 manager_delegate_->ShowAutofillSettings();
236 }
237
233 bool AutofillManager::OnFormSubmitted(const FormData& form, 238 bool AutofillManager::OnFormSubmitted(const FormData& form,
234 const TimeTicks& timestamp) { 239 const TimeTicks& timestamp) {
240 if (!IsValidFormData(form))
241 return false;
242
235 // Let Autocomplete know as well. 243 // Let Autocomplete know as well.
236 autocomplete_history_manager_->OnFormSubmitted(form); 244 autocomplete_history_manager_->OnFormSubmitted(form);
237 245
238 // Grab a copy of the form data. 246 // Grab a copy of the form data.
239 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); 247 scoped_ptr<FormStructure> submitted_form(new FormStructure(form));
240 248
241 if (!ShouldUploadForm(*submitted_form)) 249 if (!ShouldUploadForm(*submitted_form))
242 return false; 250 return false;
243 251
244 // Don't save data that was submitted through JavaScript. 252 // Don't save data that was submitted through JavaScript.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 initial_interaction_timestamp_, 302 initial_interaction_timestamp_,
295 timestamp)); 303 timestamp));
296 } 304 }
297 305
298 return true; 306 return true;
299 } 307 }
300 308
301 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, 309 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms,
302 const TimeTicks& timestamp, 310 const TimeTicks& timestamp,
303 autofill::FormsSeenState state) { 311 autofill::FormsSeenState state) {
312 if (!IsValidFormDataVector(forms))
313 return;
314
304 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN; 315 bool is_post_document_load = state == autofill::DYNAMIC_FORMS_SEEN;
305 // If new forms were added dynamically, treat as a new page. 316 // If new forms were added dynamically, treat as a new page.
306 if (is_post_document_load) 317 if (is_post_document_load)
307 Reset(); 318 Reset();
308 319
309 if (!driver_->RendererIsAvailable()) 320 if (!driver_->RendererIsAvailable())
310 return; 321 return;
311 322
312 bool enabled = IsAutofillEnabled(); 323 bool enabled = IsAutofillEnabled();
313 if (!has_logged_autofill_enabled_) { 324 if (!has_logged_autofill_enabled_) {
314 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); 325 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled);
315 has_logged_autofill_enabled_ = true; 326 has_logged_autofill_enabled_ = true;
316 } 327 }
317 328
318 if (!enabled) 329 if (!enabled)
319 return; 330 return;
320 331
321 forms_loaded_timestamp_ = timestamp; 332 forms_loaded_timestamp_ = timestamp;
322 ParseForms(forms); 333 ParseForms(forms);
323 } 334 }
324 335
325 void AutofillManager::OnTextFieldDidChange(const FormData& form, 336 void AutofillManager::OnTextFieldDidChange(const FormData& form,
326 const FormFieldData& field, 337 const FormFieldData& field,
327 const TimeTicks& timestamp) { 338 const TimeTicks& timestamp) {
339 if (!IsValidFormData(form) || !IsValidFormFieldData(field))
340 return;
341
328 FormStructure* form_structure = NULL; 342 FormStructure* form_structure = NULL;
329 AutofillField* autofill_field = NULL; 343 AutofillField* autofill_field = NULL;
330 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) 344 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field))
331 return; 345 return;
332 346
333 if (!user_did_type_) { 347 if (!user_did_type_) {
334 user_did_type_ = true; 348 user_did_type_ = true;
335 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE); 349 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_TYPE);
336 } 350 }
337 351
(...skipping 10 matching lines...) Expand all
348 } 362 }
349 363
350 UpdateInitialInteractionTimestamp(timestamp); 364 UpdateInitialInteractionTimestamp(timestamp);
351 } 365 }
352 366
353 void AutofillManager::OnQueryFormFieldAutofill(int query_id, 367 void AutofillManager::OnQueryFormFieldAutofill(int query_id,
354 const FormData& form, 368 const FormData& form,
355 const FormFieldData& field, 369 const FormFieldData& field,
356 const gfx::RectF& bounding_box, 370 const gfx::RectF& bounding_box,
357 bool display_warning) { 371 bool display_warning) {
372 if (!IsValidFormData(form) || !IsValidFormFieldData(field))
373 return;
374
358 std::vector<base::string16> values; 375 std::vector<base::string16> values;
359 std::vector<base::string16> labels; 376 std::vector<base::string16> labels;
360 std::vector<base::string16> icons; 377 std::vector<base::string16> icons;
361 std::vector<int> unique_ids; 378 std::vector<int> unique_ids;
362 379
363 external_delegate_->OnQuery(query_id, 380 external_delegate_->OnQuery(query_id,
364 form, 381 form,
365 field, 382 field,
366 bounding_box, 383 bounding_box,
367 display_warning); 384 display_warning);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 // hand off what we generated and they will send the results back to the 452 // hand off what we generated and they will send the results back to the
436 // renderer. 453 // renderer.
437 autocomplete_history_manager_->OnGetAutocompleteSuggestions( 454 autocomplete_history_manager_->OnGetAutocompleteSuggestions(
438 query_id, field.name, field.value, values, labels, icons, unique_ids); 455 query_id, field.name, field.value, values, labels, icons, unique_ids);
439 } 456 }
440 457
441 void AutofillManager::OnFillAutofillFormData(int query_id, 458 void AutofillManager::OnFillAutofillFormData(int query_id,
442 const FormData& form, 459 const FormData& form,
443 const FormFieldData& field, 460 const FormFieldData& field,
444 int unique_id) { 461 int unique_id) {
462 if (!IsValidFormData(form) || !IsValidFormFieldData(field))
463 return;
464
445 const AutofillDataModel* data_model = NULL; 465 const AutofillDataModel* data_model = NULL;
446 size_t variant = 0; 466 size_t variant = 0;
447 FormStructure* form_structure = NULL; 467 FormStructure* form_structure = NULL;
448 AutofillField* autofill_field = NULL; 468 AutofillField* autofill_field = NULL;
449 // NOTE: RefreshDataModels may invalidate |data_model| because it causes the 469 // NOTE: RefreshDataModels may invalidate |data_model| because it causes the
450 // PersonalDataManager to reload Mac address book entries. Thus it must come 470 // PersonalDataManager to reload Mac address book entries. Thus it must come
451 // before GetProfileOrCreditCard. 471 // before GetProfileOrCreditCard.
452 if (!RefreshDataModels() || 472 if (!RefreshDataModels() ||
453 !driver_->RendererIsAvailable() || 473 !driver_->RendererIsAvailable() ||
454 !GetProfileOrCreditCard(unique_id, &data_model, &variant) || 474 !GetProfileOrCreditCard(unique_id, &data_model, &variant) ||
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 535
516 autofilled_form_signatures_.push_front(form_structure->FormSignature()); 536 autofilled_form_signatures_.push_front(form_structure->FormSignature());
517 // Only remember the last few forms that we've seen, both to avoid false 537 // Only remember the last few forms that we've seen, both to avoid false
518 // positives and to avoid wasting memory. 538 // positives and to avoid wasting memory.
519 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember) 539 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember)
520 autofilled_form_signatures_.pop_back(); 540 autofilled_form_signatures_.pop_back();
521 541
522 driver_->SendFormDataToRenderer(query_id, result); 542 driver_->SendFormDataToRenderer(query_id, result);
523 } 543 }
524 544
525 void AutofillManager::OnShowAutofillDialog() {
526 manager_delegate_->ShowAutofillSettings();
527 }
528
529 void AutofillManager::OnDidPreviewAutofillFormData() { 545 void AutofillManager::OnDidPreviewAutofillFormData() {
530 if (test_delegate_) 546 if (test_delegate_)
531 test_delegate_->DidPreviewFormData(); 547 test_delegate_->DidPreviewFormData();
532 } 548 }
533 549
534 void AutofillManager::OnDidFillAutofillFormData(const TimeTicks& timestamp) { 550 void AutofillManager::OnDidFillAutofillFormData(const TimeTicks& timestamp) {
535 if (test_delegate_) 551 if (test_delegate_)
536 test_delegate_->DidFillFormData(); 552 test_delegate_->DidFillFormData();
537 553
538 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL); 554 metric_logger_->LogUserHappinessMetric(AutofillMetrics::USER_DID_AUTOFILL);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
592 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { 608 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() {
593 return form_structures_.get(); 609 return form_structures_.get();
594 } 610 }
595 611
596 void AutofillManager::SetTestDelegate( 612 void AutofillManager::SetTestDelegate(
597 autofill::AutofillManagerTestDelegate* delegate) { 613 autofill::AutofillManagerTestDelegate* delegate) {
598 test_delegate_ = delegate; 614 test_delegate_ = delegate;
599 } 615 }
600 616
601 void AutofillManager::OnAddPasswordFormMapping( 617 void AutofillManager::OnAddPasswordFormMapping(
602 const FormFieldData& form, 618 const FormFieldData& username_field,
603 const PasswordFormFillData& fill_data) { 619 const PasswordFormFillData& fill_data) {
604 external_delegate_->AddPasswordFormMapping(form, fill_data); 620 if (!IsValidFormFieldData(username_field) ||
621 !IsValidPasswordFormFillData(fill_data))
622 return;
623
624 external_delegate_->AddPasswordFormMapping(username_field, fill_data);
605 } 625 }
606 626
607 void AutofillManager::OnShowPasswordSuggestions( 627 void AutofillManager::OnShowPasswordSuggestions(
608 const FormFieldData& field, 628 const FormFieldData& field,
609 const gfx::RectF& bounds, 629 const gfx::RectF& bounds,
610 const std::vector<base::string16>& suggestions, 630 const std::vector<base::string16>& suggestions,
611 const std::vector<base::string16>& realms) { 631 const std::vector<base::string16>& realms) {
612 // Bail if the IPC message is corrupt. 632 if (!IsValidString16Vector(suggestions) ||
613 if (suggestions.size() != realms.size()) 633 !IsValidString16Vector(realms) ||
634 suggestions.size() != realms.size())
614 return; 635 return;
615 636
616 external_delegate_->OnShowPasswordSuggestions(suggestions, 637 external_delegate_->OnShowPasswordSuggestions(suggestions,
617 realms, 638 realms,
618 field, 639 field,
619 bounds); 640 bounds);
620 } 641 }
621 642
622 void AutofillManager::OnSetDataList(const std::vector<base::string16>& values, 643 void AutofillManager::OnSetDataList(const std::vector<base::string16>& values,
623 const std::vector<base::string16>& labels) { 644 const std::vector<base::string16>& labels) {
624 // Bail if the IPC message is corrupt. 645 if (!IsValidString16Vector(values) ||
625 if (values.size() != labels.size()) 646 !IsValidString16Vector(labels) ||
647 values.size() != labels.size())
626 return; 648 return;
627 649
628 external_delegate_->SetCurrentDataListValues(values, labels); 650 external_delegate_->SetCurrentDataListValues(values, labels);
629 } 651 }
630 652
631 void AutofillManager::OnLoadedServerPredictions( 653 void AutofillManager::OnLoadedServerPredictions(
632 const std::string& response_xml) { 654 const std::string& response_xml) {
633 // Parse and store the server predictions. 655 // Parse and store the server predictions.
634 FormStructure::ParseQueryResponse(response_xml, 656 FormStructure::ParseQueryResponse(response_xml,
635 form_structures_.get(), 657 form_structures_.get(),
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 return false; 1127 return false;
1106 1128
1107 // Disregard forms that we wouldn't ever autofill in the first place. 1129 // Disregard forms that we wouldn't ever autofill in the first place.
1108 if (!form.ShouldBeParsed(true)) 1130 if (!form.ShouldBeParsed(true))
1109 return false; 1131 return false;
1110 1132
1111 return true; 1133 return true;
1112 } 1134 }
1113 1135
1114 } // namespace autofill 1136 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.h ('k') | components/autofill/core/common/autofill_data_validation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698