| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/password_manager/content/browser/visible_password_observer.
h" |
| 6 |
| 7 #include "content/public/browser/render_frame_host.h" |
| 8 #include "content/public/common/origin_util.h" |
| 9 |
| 10 DEFINE_WEB_CONTENTS_USER_DATA_KEY(password_manager::VisiblePasswordObserver); |
| 11 |
| 12 namespace password_manager { |
| 13 |
| 14 VisiblePasswordObserver::~VisiblePasswordObserver() {} |
| 15 |
| 16 void VisiblePasswordObserver::RenderFrameHasVisiblePasswordField( |
| 17 content::RenderFrameHost* render_frame_host) { |
| 18 frame_tree_nodes_with_visible_password_fields_.insert( |
| 19 render_frame_host->GetFrameTreeNodeId()); |
| 20 MaybeNotifyPasswordInputShownOnHttp(); |
| 21 } |
| 22 |
| 23 void VisiblePasswordObserver::RenderFrameHasNoVisiblePasswordFields( |
| 24 content::RenderFrameHost* render_frame_host) { |
| 25 frame_tree_nodes_with_visible_password_fields_.erase( |
| 26 render_frame_host->GetFrameTreeNodeId()); |
| 27 MaybeNotifyAllFieldsInvisible(); |
| 28 } |
| 29 |
| 30 void VisiblePasswordObserver::RenderFrameDeleted( |
| 31 content::RenderFrameHost* render_frame_host) { |
| 32 // If a renderer process crashes, it won't send notifications that |
| 33 // the password fields have been hidden, so watch for crashing |
| 34 // processes and remove them from |
| 35 // |frame_tree_nodes_with_visible_password_fields_|. |
| 36 frame_tree_nodes_with_visible_password_fields_.erase( |
| 37 render_frame_host->GetFrameTreeNodeId()); |
| 38 MaybeNotifyAllFieldsInvisible(); |
| 39 } |
| 40 |
| 41 VisiblePasswordObserver::VisiblePasswordObserver( |
| 42 content::WebContents* web_contents) |
| 43 : content::WebContentsObserver(web_contents), web_contents_(web_contents) {} |
| 44 |
| 45 void VisiblePasswordObserver::MaybeNotifyPasswordInputShownOnHttp() { |
| 46 if (!content::IsOriginSecure(web_contents_->GetVisibleURL())) { |
| 47 web_contents_->OnPasswordInputShownOnHttp(); |
| 48 } |
| 49 } |
| 50 |
| 51 void VisiblePasswordObserver::MaybeNotifyAllFieldsInvisible() { |
| 52 if (frame_tree_nodes_with_visible_password_fields_.empty() && |
| 53 !content::IsOriginSecure(web_contents_->GetVisibleURL())) { |
| 54 web_contents_->OnAllPasswordInputsHiddenOnHttp(); |
| 55 } |
| 56 } |
| 57 |
| 58 } // namespace password_manager |
| OLD | NEW |