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

Side by Side Diff: components/autofill/content/renderer/password_generation_agent.cc

Issue 2320563002: [Password Generation] Use canonical version of action in for form matching in PasswordGenerationAgen (Closed)
Patch Set: Changed to password generation specific version Created 4 years, 3 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
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/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 13 matching lines...) Expand all
24 #include "services/shell/public/cpp/interface_registry.h" 24 #include "services/shell/public/cpp/interface_registry.h"
25 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" 25 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
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 using autofill::form_util::StripAuthAndParams;
vabr (Chromium) 2016/09/07 13:10:08 nit: Move this below "namespace autofill" and drop
kolos1 2016/09/07 13:19:00 Done.
35
34 namespace autofill { 36 namespace autofill {
35 37
36 namespace { 38 namespace {
37 39
38 // Returns true if we think that this form is for account creation. |passwords| 40 // Returns true if we think that this form is for account creation. |passwords|
39 // is filled with the password field(s) in the form. 41 // is filled with the password field(s) in the form.
40 bool GetAccountCreationPasswordFields( 42 bool GetAccountCreationPasswordFields(
41 const std::vector<blink::WebFormControlElement>& control_elements, 43 const std::vector<blink::WebFormControlElement>& control_elements,
42 std::vector<blink::WebInputElement>* passwords) { 44 std::vector<blink::WebInputElement>* passwords) {
43 for (size_t i = 0; i < control_elements.size(); i++) { 45 for (size_t i = 0; i < control_elements.size(); i++) {
44 const blink::WebInputElement* input_element = 46 const blink::WebInputElement* input_element =
45 toWebInputElement(&control_elements[i]); 47 toWebInputElement(&control_elements[i]);
46 if (input_element && input_element->isTextField()) { 48 if (input_element && input_element->isTextField()) {
47 if (input_element->isPasswordField()) 49 if (input_element->isPasswordField())
48 passwords->push_back(*input_element); 50 passwords->push_back(*input_element);
49 } 51 }
50 } 52 }
51 return !passwords->empty(); 53 return !passwords->empty();
52 } 54 }
53 55
54 bool ContainsURL(const std::vector<GURL>& urls, const GURL& url) { 56 bool ContainsURL(const std::vector<GURL>& urls, const GURL& url) {
55 return std::find(urls.begin(), urls.end(), url) != urls.end(); 57 return std::find(urls.begin(), urls.end(), url) != urls.end();
56 } 58 }
57 59
60 // 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.
58 const PasswordFormGenerationData* FindFormGenerationData( 63 const PasswordFormGenerationData* FindFormGenerationData(
59 const std::vector<PasswordFormGenerationData>& forms, 64 const std::vector<PasswordFormGenerationData>& forms,
60 const PasswordForm& form) { 65 const PasswordForm& form,
66 const GURL& base_url) {
61 for (const auto& form_it : forms) { 67 for (const auto& form_it : forms) {
62 if (form_it.name == form.form_data.name && form_it.action == form.action) 68 GURL action = form_it.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)
63 return &form_it; 73 return &form_it;
64 } 74 }
65 return nullptr; 75 return nullptr;
66 } 76 }
67 77
68 // This function returns a vector of password fields into which Chrome should 78 // This function returns a vector of password fields into which Chrome should
69 // fill the generated password. It assumes that |field_data| describes the field 79 // fill the generated password. It assumes that |field_data| describes the field
70 // where Chrome shows the password generation prompt. It returns no more 80 // where Chrome shows the password generation prompt. It returns no more
71 // than 2 elements. 81 // than 2 elements.
72 std::vector<blink::WebInputElement> FindPasswordElementsForGeneration( 82 std::vector<blink::WebInputElement> FindPasswordElementsForGeneration(
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 const PasswordFormGenerationData* generation_data = nullptr; 383 const PasswordFormGenerationData* generation_data = nullptr;
374 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 384 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
375 switches::kLocalHeuristicsOnlyForPasswordGeneration)) { 385 switches::kLocalHeuristicsOnlyForPasswordGeneration)) {
376 VLOG(2) << "Bypassing additional checks."; 386 VLOG(2) << "Bypassing additional checks.";
377 } else if (!ContainsURL(not_blacklisted_password_form_origins_, 387 } else if (!ContainsURL(not_blacklisted_password_form_origins_,
378 possible_password_form->origin)) { 388 possible_password_form->origin)) {
379 VLOG(2) << "Have not received confirmation that password form isn't " 389 VLOG(2) << "Have not received confirmation that password form isn't "
380 << "blacklisted"; 390 << "blacklisted";
381 continue; 391 continue;
382 } else { 392 } else {
383 generation_data = FindFormGenerationData(generation_enabled_forms_, 393 generation_data = FindFormGenerationData(
384 *possible_password_form); 394 generation_enabled_forms_, *possible_password_form,
395 render_frame()->GetWebFrame()->document().baseURL());
385 if (!generation_data) { 396 if (!generation_data) {
386 if (AutocompleteAttributesSetForGeneration(*possible_password_form)) { 397 if (AutocompleteAttributesSetForGeneration(*possible_password_form)) {
387 VLOG(2) << "Ignoring lack of Autofill signal due to Autocomplete " 398 VLOG(2) << "Ignoring lack of Autofill signal due to Autocomplete "
388 << "attributes"; 399 << "attributes";
389 password_generation::LogPasswordGenerationEvent( 400 password_generation::LogPasswordGenerationEvent(
390 password_generation::AUTOCOMPLETE_ATTRIBUTES_ENABLED_GENERATION); 401 password_generation::AUTOCOMPLETE_ATTRIBUTES_ENABLED_GENERATION);
391 } else { 402 } else {
392 VLOG(2) 403 VLOG(2)
393 << "Have not received confirmation from Autofill that form is " 404 << "Have not received confirmation from Autofill that form is "
394 << "used for account creation"; 405 << "used for account creation";
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 ShowGenerationPopup(); 581 ShowGenerationPopup();
571 } 582 }
572 583
573 const mojom::PasswordManagerDriverPtr& 584 const mojom::PasswordManagerDriverPtr&
574 PasswordGenerationAgent::GetPasswordManagerDriver() { 585 PasswordGenerationAgent::GetPasswordManagerDriver() {
575 DCHECK(password_agent_); 586 DCHECK(password_agent_);
576 return password_agent_->GetPasswordManagerDriver(); 587 return password_agent_->GetPasswordManagerDriver();
577 } 588 }
578 589
579 } // namespace autofill 590 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698