| 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()) |
| 304 return; |
| 305 |
| 306 password_form->origin = GetCanonicalOriginForDocument(form.document()); |
| 315 GURL::Replacements rep; | 307 GURL::Replacements rep; |
| 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 | |
| 323 rep.SetPathStr(""); | 308 rep.SetPathStr(""); |
| 324 password_form->signon_realm = full_origin.ReplaceComponents(rep).spec(); | 309 password_form->signon_realm = |
| 325 | 310 password_form->origin.ReplaceComponents(rep).spec(); |
| 326 password_form->other_possible_usernames.swap(other_possible_usernames); | 311 password_form->other_possible_usernames.swap(other_possible_usernames); |
| 327 | 312 |
| 328 if (!password.isNull()) { | 313 if (!password.isNull()) { |
| 329 password_form->password_element = password.nameForAutofill(); | 314 password_form->password_element = password.nameForAutofill(); |
| 330 blink::WebString password_value = password.value(); | 315 blink::WebString password_value = password.value(); |
| 331 if (nonscript_modified_values != nullptr) { | 316 if (nonscript_modified_values != nullptr) { |
| 332 auto password_iterator = nonscript_modified_values->find(password); | 317 auto password_iterator = nonscript_modified_values->find(password); |
| 333 if (password_iterator != nonscript_modified_values->end()) | 318 if (password_iterator != nonscript_modified_values->end()) |
| 334 password_value = password_iterator->second; | 319 password_value = password_iterator->second; |
| 335 } | 320 } |
| 336 password_form->password_value = password_value; | 321 password_form->password_value = password_value; |
| 337 password_form->password_autocomplete_set = password.autoComplete(); | 322 password_form->password_autocomplete_set = password.autoComplete(); |
| 338 } | 323 } |
| 339 if (!new_password.isNull()) { | 324 if (!new_password.isNull()) { |
| 340 password_form->new_password_element = new_password.nameForAutofill(); | 325 password_form->new_password_element = new_password.nameForAutofill(); |
| 341 password_form->new_password_value = new_password.value(); | 326 password_form->new_password_value = new_password.value(); |
| 342 } | 327 } |
| 343 | 328 |
| 344 password_form->scheme = PasswordForm::SCHEME_HTML; | 329 password_form->scheme = PasswordForm::SCHEME_HTML; |
| 345 password_form->ssl_valid = false; | 330 password_form->ssl_valid = false; |
| 346 password_form->preferred = false; | 331 password_form->preferred = false; |
| 347 password_form->blacklisted_by_user = false; | 332 password_form->blacklisted_by_user = false; |
| 348 password_form->type = PasswordForm::TYPE_MANUAL; | 333 password_form->type = PasswordForm::TYPE_MANUAL; |
| 349 } | 334 } |
| 350 | 335 |
| 336 GURL StripAuthAndParams(const GURL& gurl) { |
| 337 // We want to keep the path but strip any authentication data, as well as |
| 338 // query and ref portions of URL, for the form action and form origin. |
| 339 GURL::Replacements rep; |
| 340 rep.ClearUsername(); |
| 341 rep.ClearPassword(); |
| 342 rep.ClearQuery(); |
| 343 rep.ClearRef(); |
| 344 return gurl.ReplaceComponents(rep); |
| 345 } |
| 346 |
| 351 } // namespace | 347 } // namespace |
| 352 | 348 |
| 349 GURL GetCanonicalActionForForm(const WebFormElement& form) { |
| 350 WebString action = form.action(); |
| 351 if (action.isNull()) |
| 352 action = WebString(""); // missing 'action' attribute implies current URL |
| 353 GURL full_action(form.document().completeURL(action)); |
| 354 return StripAuthAndParams(full_action); |
| 355 } |
| 356 |
| 357 GURL GetCanonicalOriginForDocument(const WebDocument& document) { |
| 358 GURL full_origin(document.url()); |
| 359 return StripAuthAndParams(full_origin); |
| 360 } |
| 361 |
| 353 scoped_ptr<PasswordForm> CreatePasswordForm( | 362 scoped_ptr<PasswordForm> CreatePasswordForm( |
| 354 const WebFormElement& web_form, | 363 const WebFormElement& web_form, |
| 355 const std::map<const blink::WebInputElement, blink::WebString>* | 364 const std::map<const blink::WebInputElement, blink::WebString>* |
| 356 nonscript_modified_values) { | 365 nonscript_modified_values) { |
| 357 if (web_form.isNull()) | 366 if (web_form.isNull()) |
| 358 return scoped_ptr<PasswordForm>(); | 367 return scoped_ptr<PasswordForm>(); |
| 359 | 368 |
| 360 scoped_ptr<PasswordForm> password_form(new PasswordForm()); | 369 scoped_ptr<PasswordForm> password_form(new PasswordForm()); |
| 361 GetPasswordForm(web_form, password_form.get(), nonscript_modified_values); | 370 GetPasswordForm(web_form, password_form.get(), nonscript_modified_values); |
| 362 | 371 |
| 363 if (!password_form->action.is_valid()) | 372 if (!password_form->action.is_valid()) |
| 364 return scoped_ptr<PasswordForm>(); | 373 return scoped_ptr<PasswordForm>(); |
| 365 | 374 |
| 366 WebFormElementToFormData(web_form, | 375 WebFormElementToFormData(web_form, |
| 367 blink::WebFormControlElement(), | 376 blink::WebFormControlElement(), |
| 368 REQUIRE_NONE, | 377 REQUIRE_NONE, |
| 369 EXTRACT_NONE, | 378 EXTRACT_NONE, |
| 370 &password_form->form_data, | 379 &password_form->form_data, |
| 371 NULL /* FormFieldData */); | 380 NULL /* FormFieldData */); |
| 372 | 381 |
| 373 return password_form.Pass(); | 382 return password_form.Pass(); |
| 374 } | 383 } |
| 375 | 384 |
| 376 } // namespace autofill | 385 } // namespace autofill |
| OLD | NEW |