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

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

Issue 1946143002: Destroy (Password)AutofillAgent safely (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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/autofill_agent.h" 5 #include "components/autofill/content/renderer/autofill_agent.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <tuple> 9 #include <tuple>
10 10
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 return; 312 return;
313 } 313 }
314 314
315 if (!element || !element->isEnabled() || element->isReadOnly() || 315 if (!element || !element->isEnabled() || element->isReadOnly() ||
316 !element->isTextField()) 316 !element->isTextField())
317 return; 317 return;
318 318
319 element_ = *element; 319 element_ = *element;
320 } 320 }
321 321
322 void AutofillAgent::OnDestruct() {
323 Shutdown();
324 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
325 }
326
327 void AutofillAgent::Shutdown() {
328 legacy_.Shutdown();
329 weak_ptr_factory_.InvalidateWeakPtrs();
330 }
331
322 void AutofillAgent::FocusChangeComplete() { 332 void AutofillAgent::FocusChangeComplete() {
323 WebDocument doc = render_frame()->GetWebFrame()->document(); 333 WebDocument doc = render_frame()->GetWebFrame()->document();
324 WebElement focused_element; 334 WebElement focused_element;
325 if (!doc.isNull()) 335 if (!doc.isNull())
326 focused_element = doc.focusedElement(); 336 focused_element = doc.focusedElement();
327 337
328 if (!focused_element.isNull() && password_generation_agent_ && 338 if (!focused_element.isNull() && password_generation_agent_ &&
329 password_generation_agent_->FocusedNodeHasChanged(focused_element)) { 339 password_generation_agent_->FocusedNodeHasChanged(focused_element)) {
330 is_generation_popup_possibly_visible_ = true; 340 is_generation_popup_possibly_visible_ = true;
331 is_popup_possibly_visible_ = true; 341 is_popup_possibly_visible_ = true;
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 865
856 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent( 866 AutofillAgent::LegacyAutofillAgent::LegacyAutofillAgent(
857 content::RenderView* render_view, 867 content::RenderView* render_view,
858 AutofillAgent* agent) 868 AutofillAgent* agent)
859 : content::RenderViewObserver(render_view), agent_(agent) { 869 : content::RenderViewObserver(render_view), agent_(agent) {
860 } 870 }
861 871
862 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() { 872 AutofillAgent::LegacyAutofillAgent::~LegacyAutofillAgent() {
863 } 873 }
864 874
875 void AutofillAgent::LegacyAutofillAgent::Shutdown() {
876 agent_ = nullptr;
877 }
878
865 void AutofillAgent::LegacyAutofillAgent::OnDestruct() { 879 void AutofillAgent::LegacyAutofillAgent::OnDestruct() {
866 // No-op. Don't delete |this|. 880 // No-op. Don't delete |this|.
867 } 881 }
868 882
869 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() { 883 void AutofillAgent::LegacyAutofillAgent::FocusChangeComplete() {
870 agent_->FocusChangeComplete(); 884 if (agent_)
885 agent_->FocusChangeComplete();
871 } 886 }
872 887
873 } // namespace autofill 888 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698