| OLD | NEW |
| 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 |
| OLD | NEW |