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 "components/autofill/content/renderer/password_generation_agent.h" | 5 #include "components/autofill/content/renderer/password_generation_agent.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "third_party/WebKit/public/platform/WebVector.h" | 26 #include "third_party/WebKit/public/platform/WebVector.h" |
27 #include "third_party/WebKit/public/web/WebDocument.h" | 27 #include "third_party/WebKit/public/web/WebDocument.h" |
28 #include "third_party/WebKit/public/web/WebFormElement.h" | 28 #include "third_party/WebKit/public/web/WebFormElement.h" |
29 #include "third_party/WebKit/public/web/WebInputElement.h" | 29 #include "third_party/WebKit/public/web/WebInputElement.h" |
30 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 30 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
31 #include "third_party/WebKit/public/web/WebView.h" | 31 #include "third_party/WebKit/public/web/WebView.h" |
32 #include "ui/gfx/geometry/rect.h" | 32 #include "ui/gfx/geometry/rect.h" |
33 | 33 |
34 namespace autofill { | 34 namespace autofill { |
35 | 35 |
36 using form_util::StripAuthAndParams; | |
37 | |
38 namespace { | 36 namespace { |
39 | 37 |
40 // Returns true if we think that this form is for account creation. |passwords| | 38 // Returns true if we think that this form is for account creation. |passwords| |
41 // is filled with the password field(s) in the form. | 39 // is filled with the password field(s) in the form. |
42 bool GetAccountCreationPasswordFields( | 40 bool GetAccountCreationPasswordFields( |
43 const std::vector<blink::WebFormControlElement>& control_elements, | 41 const std::vector<blink::WebFormControlElement>& control_elements, |
44 std::vector<blink::WebInputElement>* passwords) { | 42 std::vector<blink::WebInputElement>* passwords) { |
45 for (size_t i = 0; i < control_elements.size(); i++) { | 43 for (size_t i = 0; i < control_elements.size(); i++) { |
46 const blink::WebInputElement* input_element = | 44 const blink::WebInputElement* input_element = |
47 toWebInputElement(&control_elements[i]); | 45 toWebInputElement(&control_elements[i]); |
48 if (input_element && input_element->isTextField()) { | 46 if (input_element && input_element->isTextField()) { |
49 if (input_element->isPasswordField()) | 47 if (input_element->isPasswordField()) |
50 passwords->push_back(*input_element); | 48 passwords->push_back(*input_element); |
51 } | 49 } |
52 } | 50 } |
53 return !passwords->empty(); | 51 return !passwords->empty(); |
54 } | 52 } |
55 | 53 |
56 bool ContainsURL(const std::vector<GURL>& urls, const GURL& url) { | 54 bool ContainsURL(const std::vector<GURL>& urls, const GURL& url) { |
57 return std::find(urls.begin(), urls.end(), url) != urls.end(); | 55 return std::find(urls.begin(), urls.end(), url) != urls.end(); |
58 } | 56 } |
59 | 57 |
60 // Finds a form in |forms| that has the same action and name as |form|. | 58 // Finds a form in |forms| that has the same action and name as |form|. |
61 // If the action of a form in |forms| is empty, it uses |base_url| as action. It | |
62 // also strips parameters of the action. | |
63 const PasswordFormGenerationData* FindFormGenerationData( | 59 const PasswordFormGenerationData* FindFormGenerationData( |
64 const std::vector<PasswordFormGenerationData>& forms, | 60 const std::vector<PasswordFormGenerationData>& forms, |
65 const PasswordForm& form, | 61 const PasswordForm& form) { |
66 const GURL& base_url) { | |
67 for (const auto& form_it : forms) { | 62 for (const auto& form_it : forms) { |
68 GURL action = form_it.action; | 63 if (form_it.name == form.form_data.name && form_it.action == form.action) |
69 if (action.is_empty()) | |
70 action = base_url; | |
71 action = form_util::StripAuthAndParams(action); | |
72 if (form_it.name == form.form_data.name && action == form.action) | |
73 return &form_it; | 64 return &form_it; |
74 } | 65 } |
75 return nullptr; | 66 return nullptr; |
76 } | 67 } |
77 | 68 |
78 // This function returns a vector of password fields into which Chrome should | 69 // This function returns a vector of password fields into which Chrome should |
79 // fill the generated password. It assumes that |field_data| describes the field | 70 // fill the generated password. It assumes that |field_data| describes the field |
80 // where Chrome shows the password generation prompt. It returns no more | 71 // where Chrome shows the password generation prompt. It returns no more |
81 // than 2 elements. | 72 // than 2 elements. |
82 std::vector<blink::WebInputElement> FindPasswordElementsForGeneration( | 73 std::vector<blink::WebInputElement> FindPasswordElementsForGeneration( |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 const PasswordFormGenerationData* generation_data = nullptr; | 375 const PasswordFormGenerationData* generation_data = nullptr; |
385 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 376 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
386 switches::kLocalHeuristicsOnlyForPasswordGeneration)) { | 377 switches::kLocalHeuristicsOnlyForPasswordGeneration)) { |
387 VLOG(2) << "Bypassing additional checks."; | 378 VLOG(2) << "Bypassing additional checks."; |
388 } else if (!ContainsURL(not_blacklisted_password_form_origins_, | 379 } else if (!ContainsURL(not_blacklisted_password_form_origins_, |
389 possible_password_form->origin)) { | 380 possible_password_form->origin)) { |
390 VLOG(2) << "Have not received confirmation that password form isn't " | 381 VLOG(2) << "Have not received confirmation that password form isn't " |
391 << "blacklisted"; | 382 << "blacklisted"; |
392 continue; | 383 continue; |
393 } else { | 384 } else { |
394 generation_data = FindFormGenerationData( | 385 generation_data = FindFormGenerationData(generation_enabled_forms_, |
395 generation_enabled_forms_, *possible_password_form, | 386 *possible_password_form); |
396 render_frame()->GetWebFrame()->document().baseURL()); | |
397 if (!generation_data) { | 387 if (!generation_data) { |
398 if (AutocompleteAttributesSetForGeneration(*possible_password_form)) { | 388 if (AutocompleteAttributesSetForGeneration(*possible_password_form)) { |
399 VLOG(2) << "Ignoring lack of Autofill signal due to Autocomplete " | 389 VLOG(2) << "Ignoring lack of Autofill signal due to Autocomplete " |
400 << "attributes"; | 390 << "attributes"; |
401 password_generation::LogPasswordGenerationEvent( | 391 password_generation::LogPasswordGenerationEvent( |
402 password_generation::AUTOCOMPLETE_ATTRIBUTES_ENABLED_GENERATION); | 392 password_generation::AUTOCOMPLETE_ATTRIBUTES_ENABLED_GENERATION); |
403 } else { | 393 } else { |
404 VLOG(2) | 394 VLOG(2) |
405 << "Have not received confirmation from Autofill that form is " | 395 << "Have not received confirmation from Autofill that form is " |
406 << "used for account creation"; | 396 << "used for account creation"; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 ShowGenerationPopup(); | 572 ShowGenerationPopup(); |
583 } | 573 } |
584 | 574 |
585 const mojom::PasswordManagerDriverPtr& | 575 const mojom::PasswordManagerDriverPtr& |
586 PasswordGenerationAgent::GetPasswordManagerDriver() { | 576 PasswordGenerationAgent::GetPasswordManagerDriver() { |
587 DCHECK(password_agent_); | 577 DCHECK(password_agent_); |
588 return password_agent_->GetPasswordManagerDriver(); | 578 return password_agent_->GetPasswordManagerDriver(); |
589 } | 579 } |
590 | 580 |
591 } // namespace autofill | 581 } // namespace autofill |
OLD | NEW |