| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import "ios/chrome/browser/passwords/password_generation_agent.h" | 5 #import "ios/chrome/browser/passwords/password_generation_agent.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/scoped_block.h" | 10 #include "base/mac/scoped_block.h" |
| 11 #include "base/stl_util.h" |
| 11 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 13 #include "components/autofill/core/browser/password_generator.h" | 14 #include "components/autofill/core/browser/password_generator.h" |
| 14 #include "components/autofill/core/common/form_data.h" | 15 #include "components/autofill/core/common/form_data.h" |
| 15 #include "components/autofill/core/common/password_form.h" | 16 #include "components/autofill/core/common/password_form.h" |
| 16 #include "components/autofill/core/common/password_generation_util.h" | 17 #include "components/autofill/core/common/password_generation_util.h" |
| 17 #import "components/autofill/ios/browser/js_suggestion_manager.h" | 18 #import "components/autofill/ios/browser/js_suggestion_manager.h" |
| 18 #include "components/password_manager/core/browser/password_manager.h" | 19 #include "components/password_manager/core/browser/password_manager.h" |
| 19 #include "google_apis/gaia/gaia_urls.h" | 20 #include "google_apis/gaia/gaia_urls.h" |
| 20 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" | 21 #import "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // Target length of generated passwords. | 39 // Target length of generated passwords. |
| 39 const int kGeneratedPasswordLength = 20; | 40 const int kGeneratedPasswordLength = 20; |
| 40 | 41 |
| 41 // The minimum number of text fields that a form needs to be considered as | 42 // The minimum number of text fields that a form needs to be considered as |
| 42 // an account creation form. | 43 // an account creation form. |
| 43 const size_t kMinimumTextFieldsForAccountCreation = 3; | 44 const size_t kMinimumTextFieldsForAccountCreation = 3; |
| 44 | 45 |
| 45 // Returns true if |urls| contains |url|. | |
| 46 bool VectorContainsURL(const std::vector<GURL>& urls, const GURL& url) { | |
| 47 return std::find(urls.begin(), urls.end(), url) != urls.end(); | |
| 48 } | |
| 49 | |
| 50 // Returns whether |field| should be considered a text field. Implementation | 46 // Returns whether |field| should be considered a text field. Implementation |
| 51 // mirrors that of password_controller.js. | 47 // mirrors that of password_controller.js. |
| 52 // TODO(crbug.com/433856): Figure out how to determine if |field| is visible. | 48 // TODO(crbug.com/433856): Figure out how to determine if |field| is visible. |
| 53 bool IsTextField(const autofill::FormFieldData& field) { | 49 bool IsTextField(const autofill::FormFieldData& field) { |
| 54 return field.form_control_type == "text" || | 50 return field.form_control_type == "text" || |
| 55 field.form_control_type == "email" || | 51 field.form_control_type == "email" || |
| 56 field.form_control_type == "number" || | 52 field.form_control_type == "number" || |
| 57 field.form_control_type == "tel" || field.form_control_type == "url" || | 53 field.form_control_type == "tel" || field.form_control_type == "url" || |
| 58 field.form_control_type == "search" || | 54 field.form_control_type == "search" || |
| 59 field.form_control_type == "password"; | 55 field.form_control_type == "password"; |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 // creation forms, wait. | 281 // creation forms, wait. |
| 286 if (!_possibleAccountCreationForm) | 282 if (!_possibleAccountCreationForm) |
| 287 return; | 283 return; |
| 288 if (_passwordFields.empty()) | 284 if (_passwordFields.empty()) |
| 289 return; | 285 return; |
| 290 | 286 |
| 291 // If the form origin hasn't been cleared by both the autofill and the | 287 // If the form origin hasn't been cleared by both the autofill and the |
| 292 // password manager, wait. | 288 // password manager, wait. |
| 293 GURL origin = _possibleAccountCreationForm->origin; | 289 GURL origin = _possibleAccountCreationForm->origin; |
| 294 if (!experimental_flags::UseOnlyLocalHeuristicsForPasswordGeneration()) { | 290 if (!experimental_flags::UseOnlyLocalHeuristicsForPasswordGeneration()) { |
| 295 if (!VectorContainsURL(_allowedGenerationFormOrigins, origin)) | 291 if (!base::ContainsValue(_allowedGenerationFormOrigins, origin)) |
| 296 return; | 292 return; |
| 297 } | 293 } |
| 298 | 294 |
| 299 // Use the first password field in the form as the generation field. | 295 // Use the first password field in the form as the generation field. |
| 300 _passwordGenerationField.reset( | 296 _passwordGenerationField.reset( |
| 301 new autofill::FormFieldData(_passwordFields[0])); | 297 new autofill::FormFieldData(_passwordFields[0])); |
| 302 autofill::password_generation::LogPasswordGenerationEvent( | 298 autofill::password_generation::LogPasswordGenerationEvent( |
| 303 autofill::password_generation::GENERATION_AVAILABLE); | 299 autofill::password_generation::GENERATION_AVAILABLE); |
| 304 } | 300 } |
| 305 | 301 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 DCHECK(_accessoryViewReadyCompletion); | 432 DCHECK(_accessoryViewReadyCompletion); |
| 437 _accessoryViewReadyCompletion([self currentAccessoryView], self); | 433 _accessoryViewReadyCompletion([self currentAccessoryView], self); |
| 438 } | 434 } |
| 439 | 435 |
| 440 - (BOOL)getLogKeyboardAccessoryMetrics { | 436 - (BOOL)getLogKeyboardAccessoryMetrics { |
| 441 // Only store metrics for regular Autofill, not passwords. | 437 // Only store metrics for regular Autofill, not passwords. |
| 442 return NO; | 438 return NO; |
| 443 } | 439 } |
| 444 | 440 |
| 445 @end | 441 @end |
| OLD | NEW |