| 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_form_conversion_utils.h" | 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "components/autofill/content/renderer/form_autofill_util.h" | 10 #include "components/autofill/content/renderer/form_autofill_util.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // We check that |username_value| was not obtained by autofilling | 287 // We check that |username_value| was not obtained by autofilling |
| 288 // |typed_username_value|. In case when it was, |typed_username_value| | 288 // |typed_username_value|. In case when it was, |typed_username_value| |
| 289 // is incomplete, so we should leave autofilled value. | 289 // is incomplete, so we should leave autofilled value. |
| 290 username_value = typed_username_value; | 290 username_value = typed_username_value; |
| 291 } | 291 } |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 password_form->username_value = username_value; | 294 password_form->username_value = username_value; |
| 295 } | 295 } |
| 296 | 296 |
| 297 // Get the document URL | |
| 298 GURL full_origin(form.document().url()); | |
| 299 | |
| 300 // Calculate the canonical action URL | |
| 301 WebString action = form.action(); | |
| 302 if (action.isNull()) | |
| 303 action = WebString(""); // missing 'action' attribute implies current URL | |
| 304 GURL full_action(form.document().completeURL(action)); | |
| 305 if (!full_action.is_valid()) | |
| 306 return; | |
| 307 | |
| 308 WebInputElement password; | 297 WebInputElement password; |
| 309 WebInputElement new_password; | 298 WebInputElement new_password; |
| 310 if (!LocateSpecificPasswords(passwords, &password, &new_password)) | 299 if (!LocateSpecificPasswords(passwords, &password, &new_password)) |
| 311 return; | 300 return; |
| 312 | 301 |
| 313 // We want to keep the path but strip any authentication data, as well as | 302 password_form->action = GetCanonicalActionForForm(form); |
| 314 // query and ref portions of URL, for the form action and form origin. | 303 if (!password_form->action.is_valid()) |
| 315 GURL::Replacements rep; | 304 return; |
| 316 rep.ClearUsername(); | |
| 317 rep.ClearPassword(); | |
| 318 rep.ClearQuery(); | |
| 319 rep.ClearRef(); | |
| 320 password_form->action = full_action.ReplaceComponents(rep); | |
| 321 password_form->origin = full_origin.ReplaceComponents(rep); | |
| 322 | 305 |
| 323 rep.SetPathStr(""); | 306 password_form->origin = GetCanonicalOriginForDocument(form.document()); |
| 324 password_form->signon_realm = full_origin.ReplaceComponents(rep).spec(); | 307 password_form->signon_realm = password_form->origin.GetWithEmptyPath().spec(); |
| 325 | |
| 326 password_form->other_possible_usernames.swap(other_possible_usernames); | 308 password_form->other_possible_usernames.swap(other_possible_usernames); |
| 327 | 309 |
| 328 if (!password.isNull()) { | 310 if (!password.isNull()) { |
| 329 password_form->password_element = password.nameForAutofill(); | 311 password_form->password_element = password.nameForAutofill(); |
| 330 blink::WebString password_value = password.value(); | 312 blink::WebString password_value = password.value(); |
| 331 if (nonscript_modified_values != nullptr) { | 313 if (nonscript_modified_values != nullptr) { |
| 332 auto password_iterator = nonscript_modified_values->find(password); | 314 auto password_iterator = nonscript_modified_values->find(password); |
| 333 if (password_iterator != nonscript_modified_values->end()) | 315 if (password_iterator != nonscript_modified_values->end()) |
| 334 password_value = password_iterator->second; | 316 password_value = password_iterator->second; |
| 335 } | 317 } |
| 336 password_form->password_value = password_value; | 318 password_form->password_value = password_value; |
| 337 password_form->password_autocomplete_set = password.autoComplete(); | 319 password_form->password_autocomplete_set = password.autoComplete(); |
| 338 } | 320 } |
| 339 if (!new_password.isNull()) { | 321 if (!new_password.isNull()) { |
| 340 password_form->new_password_element = new_password.nameForAutofill(); | 322 password_form->new_password_element = new_password.nameForAutofill(); |
| 341 password_form->new_password_value = new_password.value(); | 323 password_form->new_password_value = new_password.value(); |
| 342 } | 324 } |
| 343 | 325 |
| 344 password_form->scheme = PasswordForm::SCHEME_HTML; | 326 password_form->scheme = PasswordForm::SCHEME_HTML; |
| 345 password_form->ssl_valid = false; | 327 password_form->ssl_valid = false; |
| 346 password_form->preferred = false; | 328 password_form->preferred = false; |
| 347 password_form->blacklisted_by_user = false; | 329 password_form->blacklisted_by_user = false; |
| 348 password_form->type = PasswordForm::TYPE_MANUAL; | 330 password_form->type = PasswordForm::TYPE_MANUAL; |
| 349 } | 331 } |
| 350 | 332 |
| 333 GURL StripAuthAndParams(const GURL& gurl) { |
| 334 // We want to keep the path but strip any authentication data, as well as |
| 335 // query and ref portions of URL, for the form action and form origin. |
| 336 GURL::Replacements rep; |
| 337 rep.ClearUsername(); |
| 338 rep.ClearPassword(); |
| 339 rep.ClearQuery(); |
| 340 rep.ClearRef(); |
| 341 return gurl.ReplaceComponents(rep); |
| 342 } |
| 343 |
| 351 } // namespace | 344 } // namespace |
| 352 | 345 |
| 346 GURL GetCanonicalActionForForm(const WebFormElement& form) { |
| 347 WebString action = form.action(); |
| 348 if (action.isNull()) |
| 349 action = WebString(""); // missing 'action' attribute implies current URL |
| 350 GURL full_action(form.document().completeURL(action)); |
| 351 return StripAuthAndParams(full_action); |
| 352 } |
| 353 |
| 354 GURL GetCanonicalOriginForDocument(const WebDocument& document) { |
| 355 GURL full_origin(document.url()); |
| 356 return StripAuthAndParams(full_origin); |
| 357 } |
| 358 |
| 353 scoped_ptr<PasswordForm> CreatePasswordForm( | 359 scoped_ptr<PasswordForm> CreatePasswordForm( |
| 354 const WebFormElement& web_form, | 360 const WebFormElement& web_form, |
| 355 const std::map<const blink::WebInputElement, blink::WebString>* | 361 const std::map<const blink::WebInputElement, blink::WebString>* |
| 356 nonscript_modified_values) { | 362 nonscript_modified_values) { |
| 357 if (web_form.isNull()) | 363 if (web_form.isNull()) |
| 358 return scoped_ptr<PasswordForm>(); | 364 return scoped_ptr<PasswordForm>(); |
| 359 | 365 |
| 360 scoped_ptr<PasswordForm> password_form(new PasswordForm()); | 366 scoped_ptr<PasswordForm> password_form(new PasswordForm()); |
| 361 GetPasswordForm(web_form, password_form.get(), nonscript_modified_values); | 367 GetPasswordForm(web_form, password_form.get(), nonscript_modified_values); |
| 362 | 368 |
| 363 if (!password_form->action.is_valid()) | 369 if (!password_form->action.is_valid()) |
| 364 return scoped_ptr<PasswordForm>(); | 370 return scoped_ptr<PasswordForm>(); |
| 365 | 371 |
| 366 WebFormElementToFormData(web_form, | 372 WebFormElementToFormData(web_form, |
| 367 blink::WebFormControlElement(), | 373 blink::WebFormControlElement(), |
| 368 REQUIRE_NONE, | 374 REQUIRE_NONE, |
| 369 EXTRACT_NONE, | 375 EXTRACT_NONE, |
| 370 &password_form->form_data, | 376 &password_form->form_data, |
| 371 NULL /* FormFieldData */); | 377 NULL /* FormFieldData */); |
| 372 | 378 |
| 373 return password_form.Pass(); | 379 return password_form.Pass(); |
| 374 } | 380 } |
| 375 | 381 |
| 376 } // namespace autofill | 382 } // namespace autofill |
| OLD | NEW |