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

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

Issue 1946143002: Destroy (Password)AutofillAgent safely (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Also setChecked Created 4 years, 7 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
« no previous file with comments | « components/autofill/content/renderer/password_generation_agent.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 if (editing_popup_shown_) { 172 if (editing_popup_shown_) {
173 password_generation::LogPasswordGenerationEvent( 173 password_generation::LogPasswordGenerationEvent(
174 password_generation::EDITING_POPUP_SHOWN); 174 password_generation::EDITING_POPUP_SHOWN);
175 } 175 }
176 editing_popup_shown_ = false; 176 editing_popup_shown_ = false;
177 } 177 }
178 178
179 FindPossibleGenerationForm(); 179 FindPossibleGenerationForm();
180 } 180 }
181 181
182 void PasswordGenerationAgent::OnDestruct() {
183 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
184 }
185
182 void PasswordGenerationAgent::OnDynamicFormsSeen() { 186 void PasswordGenerationAgent::OnDynamicFormsSeen() {
183 FindPossibleGenerationForm(); 187 FindPossibleGenerationForm();
184 } 188 }
185 189
186 void PasswordGenerationAgent::FindPossibleGenerationForm() { 190 void PasswordGenerationAgent::FindPossibleGenerationForm() {
187 if (!enabled_) 191 if (!enabled_ || !render_frame())
188 return; 192 return;
189 193
190 // We don't want to generate passwords if the browser won't store or sync 194 // We don't want to generate passwords if the browser won't store or sync
191 // them. 195 // them.
192 if (!ShouldAnalyzeDocument()) 196 if (!ShouldAnalyzeDocument())
193 return; 197 return;
194 198
195 // If we have already found a signup form for this page, no need to continue. 199 // If we have already found a signup form for this page, no need to continue.
196 if (generation_form_data_) 200 if (generation_form_data_)
197 return; 201 return;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (!possible_account_creation_forms_.empty()) { 234 if (!possible_account_creation_forms_.empty()) {
231 VLOG(2) << possible_account_creation_forms_.size() 235 VLOG(2) << possible_account_creation_forms_.size()
232 << " possible account creation forms deteceted"; 236 << " possible account creation forms deteceted";
233 DetermineGenerationElement(); 237 DetermineGenerationElement();
234 } 238 }
235 } 239 }
236 240
237 bool PasswordGenerationAgent::ShouldAnalyzeDocument() const { 241 bool PasswordGenerationAgent::ShouldAnalyzeDocument() const {
238 // Make sure that this security origin is allowed to use password manager. 242 // Make sure that this security origin is allowed to use password manager.
239 // Generating a password that can't be saved is a bad idea. 243 // Generating a password that can't be saved is a bad idea.
240 blink::WebSecurityOrigin origin = 244 if (!render_frame() ||
241 render_frame()->GetWebFrame()->document().getSecurityOrigin(); 245 !render_frame()
242 if (!origin.canAccessPasswordManager()) { 246 ->GetWebFrame()
247 ->document()
248 .getSecurityOrigin()
249 .canAccessPasswordManager()) {
243 VLOG(1) << "No PasswordManager access"; 250 VLOG(1) << "No PasswordManager access";
244 return false; 251 return false;
245 } 252 }
246 253
247 return true; 254 return true;
248 } 255 }
249 256
250 bool PasswordGenerationAgent::OnMessageReceived(const IPC::Message& message) { 257 bool PasswordGenerationAgent::OnMessageReceived(const IPC::Message& message) {
251 bool handled = true; 258 bool handled = true;
252 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message) 259 IPC_BEGIN_MESSAGE_MAP(PasswordGenerationAgent, message)
(...skipping 15 matching lines...) Expand all
268 DetermineGenerationElement(); 275 DetermineGenerationElement();
269 } 276 }
270 277
271 void PasswordGenerationAgent::OnPasswordAccepted( 278 void PasswordGenerationAgent::OnPasswordAccepted(
272 const base::string16& password) { 279 const base::string16& password) {
273 password_is_generated_ = true; 280 password_is_generated_ = true;
274 password_generation::LogPasswordGenerationEvent( 281 password_generation::LogPasswordGenerationEvent(
275 password_generation::PASSWORD_ACCEPTED); 282 password_generation::PASSWORD_ACCEPTED);
276 for (auto& password_element : generation_form_data_->password_elements) { 283 for (auto& password_element : generation_form_data_->password_elements) {
277 password_element.setValue(password, true /* sendEvents */); 284 password_element.setValue(password, true /* sendEvents */);
285 // setValue() above may have resulted in JavaScript closing the frame.
286 if (!render_frame())
287 return;
278 password_element.setAutofilled(true); 288 password_element.setAutofilled(true);
279 // Needed to notify password_autofill_agent that the content of the field 289 // Needed to notify password_autofill_agent that the content of the field
280 // has changed. Without this we will overwrite the generated 290 // has changed. Without this we will overwrite the generated
281 // password with an Autofilled password when saving. 291 // password with an Autofilled password when saving.
282 // https://crbug.com/493455 292 // https://crbug.com/493455
283 password_agent_->UpdateStateForTextChange(password_element); 293 password_agent_->UpdateStateForTextChange(password_element);
284 // Advance focus to the next input field. We assume password fields in 294 // Advance focus to the next input field. We assume password fields in
285 // an account creation form are always adjacent. 295 // an account creation form are always adjacent.
286 render_frame()->GetRenderView()->GetWebView()->advanceFocus(false); 296 render_frame()->GetRenderView()->GetWebView()->advanceFocus(false);
287 } 297 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // Password isn't generated and there are fewer than kMaximumOfferSize 483 // Password isn't generated and there are fewer than kMaximumOfferSize
474 // characters typed, so keep offering the password. Note this function 484 // characters typed, so keep offering the password. Note this function
475 // will just keep the previous popup if one is already showing. 485 // will just keep the previous popup if one is already showing.
476 ShowGenerationPopup(); 486 ShowGenerationPopup();
477 } 487 }
478 488
479 return true; 489 return true;
480 } 490 }
481 491
482 void PasswordGenerationAgent::ShowGenerationPopup() { 492 void PasswordGenerationAgent::ShowGenerationPopup() {
493 if (!render_frame())
494 return;
483 Send(new AutofillHostMsg_ShowPasswordGenerationPopup( 495 Send(new AutofillHostMsg_ShowPasswordGenerationPopup(
484 routing_id(), 496 routing_id(),
485 render_frame()->GetRenderView()->ElementBoundsInWindow( 497 render_frame()->GetRenderView()->ElementBoundsInWindow(
486 generation_element_), 498 generation_element_),
487 generation_element_.maxLength(), 499 generation_element_.maxLength(),
488 generation_element_.nameForAutofill(), 500 generation_element_.nameForAutofill(),
489 is_manually_triggered_, 501 is_manually_triggered_,
490 *generation_form_data_->form)); 502 *generation_form_data_->form));
491 generation_popup_shown_ = true; 503 generation_popup_shown_ = true;
492 } 504 }
493 505
494 void PasswordGenerationAgent::ShowEditingPopup() { 506 void PasswordGenerationAgent::ShowEditingPopup() {
507 if (!render_frame())
508 return;
495 Send(new AutofillHostMsg_ShowPasswordEditingPopup( 509 Send(new AutofillHostMsg_ShowPasswordEditingPopup(
496 routing_id(), 510 routing_id(),
497 render_frame()->GetRenderView()->ElementBoundsInWindow( 511 render_frame()->GetRenderView()->ElementBoundsInWindow(
498 generation_element_), 512 generation_element_),
499 *generation_form_data_->form)); 513 *generation_form_data_->form));
500 editing_popup_shown_ = true; 514 editing_popup_shown_ = true;
501 } 515 }
502 516
503 void PasswordGenerationAgent::HidePopup() { 517 void PasswordGenerationAgent::HidePopup() {
504 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id())); 518 Send(new AutofillHostMsg_HidePasswordGenerationPopup(routing_id()));
505 } 519 }
506 520
507 void PasswordGenerationAgent::OnUserTriggeredGeneratePassword() { 521 void PasswordGenerationAgent::OnUserTriggeredGeneratePassword() {
508 if (last_focused_password_element_.isNull()) 522 if (last_focused_password_element_.isNull() || !render_frame())
509 return; 523 return;
510 524
511 blink::WebFormElement form = last_focused_password_element_.form(); 525 blink::WebFormElement form = last_focused_password_element_.form();
512 std::unique_ptr<PasswordForm> password_form; 526 std::unique_ptr<PasswordForm> password_form;
513 std::vector<blink::WebFormControlElement> control_elements; 527 std::vector<blink::WebFormControlElement> control_elements;
514 if (!form.isNull()) { 528 if (!form.isNull()) {
515 password_form = CreatePasswordFormFromWebForm(form, nullptr, nullptr); 529 password_form = CreatePasswordFormFromWebForm(form, nullptr, nullptr);
516 control_elements = form_util::ExtractAutofillableElementsInForm(form); 530 control_elements = form_util::ExtractAutofillableElementsInForm(form);
517 } else { 531 } else {
518 const blink::WebFrame& frame = *render_frame()->GetWebFrame(); 532 const blink::WebFrame& frame = *render_frame()->GetWebFrame();
(...skipping 14 matching lines...) Expand all
533 GetAccountCreationPasswordFields(control_elements, &password_elements); 547 GetAccountCreationPasswordFields(control_elements, &password_elements);
534 password_elements = FindPasswordElementsForGeneration( 548 password_elements = FindPasswordElementsForGeneration(
535 password_elements, last_focused_password_element_.nameForAutofill()); 549 password_elements, last_focused_password_element_.nameForAutofill());
536 generation_form_data_.reset(new AccountCreationFormData( 550 generation_form_data_.reset(new AccountCreationFormData(
537 make_linked_ptr(password_form.release()), password_elements)); 551 make_linked_ptr(password_form.release()), password_elements));
538 is_manually_triggered_ = true; 552 is_manually_triggered_ = true;
539 ShowGenerationPopup(); 553 ShowGenerationPopup();
540 } 554 }
541 555
542 } // namespace autofill 556 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/password_generation_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698