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

Side by Side Diff: components/password_manager/content/browser/visible_password_observer.cc

Issue 2500213002: Track visible password fields by RenderFrameHost, not frame tree node (Closed)
Patch Set: fix unit test memory leak Created 4 years, 1 month 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/password_manager/content/browser/visible_password_observer.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/password_manager/content/browser/visible_password_observer. h" 5 #include "components/password_manager/content/browser/visible_password_observer. h"
6 6
7 #include "content/public/browser/render_frame_host.h" 7 #include "content/public/browser/render_frame_host.h"
8 #include "content/public/common/origin_util.h" 8 #include "content/public/common/origin_util.h"
9 9
10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(password_manager::VisiblePasswordObserver); 10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(password_manager::VisiblePasswordObserver);
11 11
12 namespace password_manager { 12 namespace password_manager {
13 13
14 VisiblePasswordObserver::~VisiblePasswordObserver() {} 14 VisiblePasswordObserver::~VisiblePasswordObserver() {}
15 15
16 void VisiblePasswordObserver::RenderFrameHasVisiblePasswordField( 16 void VisiblePasswordObserver::RenderFrameHasVisiblePasswordField(
17 content::RenderFrameHost* render_frame_host) { 17 content::RenderFrameHost* render_frame_host) {
18 frame_tree_nodes_with_visible_password_fields_.insert( 18 frames_with_visible_password_fields_.insert(render_frame_host);
19 render_frame_host->GetFrameTreeNodeId());
20 MaybeNotifyPasswordInputShownOnHttp(); 19 MaybeNotifyPasswordInputShownOnHttp();
21 } 20 }
22 21
23 void VisiblePasswordObserver::RenderFrameHasNoVisiblePasswordFields( 22 void VisiblePasswordObserver::RenderFrameHasNoVisiblePasswordFields(
24 content::RenderFrameHost* render_frame_host) { 23 content::RenderFrameHost* render_frame_host) {
25 frame_tree_nodes_with_visible_password_fields_.erase( 24 frames_with_visible_password_fields_.erase(render_frame_host);
26 render_frame_host->GetFrameTreeNodeId());
27 MaybeNotifyAllFieldsInvisible(); 25 MaybeNotifyAllFieldsInvisible();
28 } 26 }
29 27
30 void VisiblePasswordObserver::RenderFrameDeleted( 28 void VisiblePasswordObserver::RenderFrameDeleted(
31 content::RenderFrameHost* render_frame_host) { 29 content::RenderFrameHost* render_frame_host) {
32 // If a renderer process crashes, it won't send notifications that 30 // If a renderer process crashes, it won't send notifications that
33 // the password fields have been hidden, so watch for crashing 31 // the password fields have been hidden, so watch for crashing
34 // processes and remove them from 32 // processes and remove them from
35 // |frame_tree_nodes_with_visible_password_fields_|. 33 // |frames_with_visible_password_fields_|.
36 frame_tree_nodes_with_visible_password_fields_.erase( 34 frames_with_visible_password_fields_.erase(render_frame_host);
37 render_frame_host->GetFrameTreeNodeId());
38 MaybeNotifyAllFieldsInvisible(); 35 MaybeNotifyAllFieldsInvisible();
39 } 36 }
40 37
41 VisiblePasswordObserver::VisiblePasswordObserver( 38 VisiblePasswordObserver::VisiblePasswordObserver(
42 content::WebContents* web_contents) 39 content::WebContents* web_contents)
43 : content::WebContentsObserver(web_contents), web_contents_(web_contents) {} 40 : content::WebContentsObserver(web_contents), web_contents_(web_contents) {}
44 41
45 void VisiblePasswordObserver::MaybeNotifyPasswordInputShownOnHttp() { 42 void VisiblePasswordObserver::MaybeNotifyPasswordInputShownOnHttp() {
46 if (!content::IsOriginSecure(web_contents_->GetVisibleURL())) { 43 if (!content::IsOriginSecure(web_contents_->GetVisibleURL())) {
47 web_contents_->OnPasswordInputShownOnHttp(); 44 web_contents_->OnPasswordInputShownOnHttp();
48 } 45 }
49 } 46 }
50 47
51 void VisiblePasswordObserver::MaybeNotifyAllFieldsInvisible() { 48 void VisiblePasswordObserver::MaybeNotifyAllFieldsInvisible() {
52 if (frame_tree_nodes_with_visible_password_fields_.empty() && 49 if (frames_with_visible_password_fields_.empty() &&
53 !content::IsOriginSecure(web_contents_->GetVisibleURL())) { 50 !content::IsOriginSecure(web_contents_->GetVisibleURL())) {
54 web_contents_->OnAllPasswordInputsHiddenOnHttp(); 51 web_contents_->OnAllPasswordInputsHiddenOnHttp();
55 } 52 }
56 } 53 }
57 54
58 } // namespace password_manager 55 } // namespace password_manager
OLDNEW
« no previous file with comments | « components/password_manager/content/browser/visible_password_observer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698