Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/content_password_manager_d river.h" | 5 #include "components/password_manager/content/browser/content_password_manager_d river.h" |
| 6 | 6 |
| 7 #include <set> | |
| 8 | |
| 7 #include "components/autofill/content/browser/content_autofill_driver.h" | 9 #include "components/autofill/content/browser/content_autofill_driver.h" |
| 8 #include "components/autofill/core/common/form_data.h" | 10 #include "components/autofill/core/common/form_data.h" |
| 9 #include "components/autofill/core/common/password_form.h" | 11 #include "components/autofill/core/common/password_form.h" |
| 10 #include "components/password_manager/content/browser/bad_message.h" | 12 #include "components/password_manager/content/browser/bad_message.h" |
| 11 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" | 13 #include "components/password_manager/content/browser/content_password_manager_d river_factory.h" |
| 12 #include "components/password_manager/core/browser/log_manager.h" | 14 #include "components/password_manager/core/browser/log_manager.h" |
| 13 #include "components/password_manager/core/browser/password_manager.h" | 15 #include "components/password_manager/core/browser/password_manager.h" |
| 14 #include "components/password_manager/core/browser/password_manager_client.h" | 16 #include "components/password_manager/core/browser/password_manager_client.h" |
| 15 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/child_process_security_policy.h" | 18 #include "content/public/browser/child_process_security_policy.h" |
| 17 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
| 21 #include "content/public/browser/navigation_handle.h" | |
| 19 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 21 #include "content/public/browser/render_view_host.h" | 24 #include "content/public/browser/render_view_host.h" |
| 22 #include "content/public/browser/site_instance.h" | 25 #include "content/public/browser/site_instance.h" |
| 23 #include "content/public/browser/ssl_status.h" | 26 #include "content/public/browser/ssl_status.h" |
| 24 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 25 #include "content/public/common/origin_util.h" | 28 #include "content/public/common/origin_util.h" |
| 26 #include "net/cert/cert_status_flags.h" | 29 #include "net/cert/cert_status_flags.h" |
| 27 #include "services/service_manager/public/cpp/interface_provider.h" | 30 #include "services/service_manager/public/cpp/interface_provider.h" |
| 28 | 31 |
| 29 namespace password_manager { | 32 namespace password_manager { |
| 30 | 33 |
| 31 namespace { | 34 namespace { |
| 32 | 35 |
| 33 void MaybeNotifyPasswordInputShownOnHttp(content::RenderFrameHost* rfh) { | 36 const char kVisiblePasswordObserverWebContentsUserDataKey[] = |
| 34 content::WebContents* web_contents = | 37 "visible_password_observer"; |
| 35 content::WebContents::FromRenderFrameHost(rfh); | 38 |
| 36 if (!content::IsOriginSecure(web_contents->GetVisibleURL())) { | 39 // This class tracks password visibility notifications for the |
| 37 web_contents->OnPasswordInputShownOnHttp(); | 40 // RenderFrameHosts in a WebContents. There is one |
|
vabr (Chromium)
2016/11/03 14:57:44
Could this WebContentsObserver be simply merged wi
estark
2016/11/03 15:13:35
I did think about putting this logic in ContentPas
vabr (Chromium)
2016/11/03 15:19:59
Good point about keeping the factory focused on ju
| |
| 41 // VisiblePasswordObserver per WebContents. When a RenderFrameHost has a | |
| 42 // visible password field and the top-level URL is HTTP, the | |
| 43 // VisiblePasswordObserver notifies the WebContents, which allows the | |
| 44 // content embedder to adjust security UI. Similarly, when all | |
| 45 // RenderFrameHosts have hidden their password fields (either because | |
| 46 // the renderer sent a message reporting that all password fields are | |
| 47 // gone, or because the renderer crashed), the WebContents is notified | |
| 48 // so that security warnings can be removed by the embedder. | |
| 49 class VisiblePasswordObserver : public content::WebContentsObserver, | |
| 50 public base::SupportsUserData::Data { | |
|
dcheng
2016/11/03 05:33:34
I'd recommend using WebContentsUserData, which hel
estark
2016/11/03 15:13:35
Noted, will do once I work out with vabr (above) w
| |
| 51 public: | |
| 52 static VisiblePasswordObserver* GetOrCreateForWebContents( | |
| 53 content::WebContents* web_contents) { | |
| 54 VisiblePasswordObserver* observer = | |
|
vabr (Chromium)
2016/11/03 15:29:41
In addition to moving this out to its own .h/.cc f
estark
2016/11/03 18:54:13
Done.
| |
| 55 static_cast<VisiblePasswordObserver*>(web_contents->GetUserData( | |
| 56 kVisiblePasswordObserverWebContentsUserDataKey)); | |
| 57 if (observer) { | |
| 58 return observer; | |
| 59 } | |
| 60 | |
| 61 observer = new VisiblePasswordObserver(web_contents); | |
| 62 web_contents->SetUserData(kVisiblePasswordObserverWebContentsUserDataKey, | |
| 63 observer); | |
| 64 return observer; | |
| 38 } | 65 } |
| 39 } | 66 |
| 67 void RenderFrameHasVisiblePasswordField( | |
| 68 content::RenderFrameHost* render_frame_host) { | |
| 69 frame_tree_nodes_with_visible_password_fields_.insert( | |
| 70 render_frame_host->GetFrameTreeNodeId()); | |
| 71 MaybeNotifyPasswordInputShownOnHttp(); | |
| 72 } | |
| 73 | |
| 74 void RenderFrameHasNoVisiblePasswordFields( | |
| 75 content::RenderFrameHost* render_frame_host) { | |
| 76 frame_tree_nodes_with_visible_password_fields_.erase( | |
| 77 render_frame_host->GetFrameTreeNodeId()); | |
| 78 MaybeNotifyAllFieldsInvisible(); | |
| 79 } | |
| 80 | |
| 81 // WebContentsObserver: | |
| 82 void RenderFrameDeleted( | |
| 83 content::RenderFrameHost* render_frame_host) override { | |
| 84 // If a renderer process crashes, it won't send notifications that | |
| 85 // the password fields have been hidden, so watch for crashing | |
| 86 // processes and remove them from | |
| 87 // |frame_tree_nodes_with_visible_password_fields_|. | |
| 88 frame_tree_nodes_with_visible_password_fields_.erase( | |
| 89 render_frame_host->GetFrameTreeNodeId()); | |
| 90 MaybeNotifyAllFieldsInvisible(); | |
| 91 } | |
| 92 | |
| 93 private: | |
| 94 VisiblePasswordObserver(content::WebContents* web_contents) | |
| 95 : content::WebContentsObserver(web_contents), | |
| 96 web_contents_(web_contents) {} | |
| 97 | |
| 98 ~VisiblePasswordObserver() override {} | |
| 99 | |
| 100 void MaybeNotifyPasswordInputShownOnHttp() { | |
| 101 if (!content::IsOriginSecure(web_contents_->GetVisibleURL())) { | |
|
vabr (Chromium)
2016/11/03 15:29:41
Just a question: the status of the UI indication d
estark
2016/11/03 18:54:13
That's right. On navigation, we get messages from
| |
| 102 web_contents_->OnPasswordInputShownOnHttp(); | |
| 103 } | |
| 104 } | |
| 105 | |
| 106 void MaybeNotifyAllFieldsInvisible() { | |
| 107 if (frame_tree_nodes_with_visible_password_fields_.empty() && | |
| 108 !content::IsOriginSecure(web_contents_->GetVisibleURL())) { | |
| 109 web_contents_->OnAllPasswordInputsHiddenOnHttp(); | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 content::WebContents* web_contents_; | |
| 114 std::set<int> frame_tree_nodes_with_visible_password_fields_; | |
| 115 | |
| 116 DISALLOW_COPY_AND_ASSIGN(VisiblePasswordObserver); | |
| 117 }; | |
| 40 | 118 |
| 41 } // namespace | 119 } // namespace |
| 42 | 120 |
| 43 ContentPasswordManagerDriver::ContentPasswordManagerDriver( | 121 ContentPasswordManagerDriver::ContentPasswordManagerDriver( |
| 44 content::RenderFrameHost* render_frame_host, | 122 content::RenderFrameHost* render_frame_host, |
| 45 PasswordManagerClient* client, | 123 PasswordManagerClient* client, |
| 46 autofill::AutofillClient* autofill_client) | 124 autofill::AutofillClient* autofill_client) |
| 47 : render_frame_host_(render_frame_host), | 125 : render_frame_host_(render_frame_host), |
| 48 client_(client), | 126 client_(client), |
| 49 password_generation_manager_(client, this), | 127 password_generation_manager_(client, this), |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 void ContentPasswordManagerDriver::OnFocusedPasswordFormFound( | 279 void ContentPasswordManagerDriver::OnFocusedPasswordFormFound( |
| 202 const autofill::PasswordForm& password_form) { | 280 const autofill::PasswordForm& password_form) { |
| 203 if (!CheckChildProcessSecurityPolicy( | 281 if (!CheckChildProcessSecurityPolicy( |
| 204 password_form.origin, | 282 password_form.origin, |
| 205 BadMessageReason::CPMD_BAD_ORIGIN_FOCUSED_PASSWORD_FORM_FOUND)) | 283 BadMessageReason::CPMD_BAD_ORIGIN_FOCUSED_PASSWORD_FORM_FOUND)) |
| 206 return; | 284 return; |
| 207 GetPasswordManager()->OnPasswordFormForceSaveRequested(this, password_form); | 285 GetPasswordManager()->OnPasswordFormForceSaveRequested(this, password_form); |
| 208 } | 286 } |
| 209 | 287 |
| 210 void ContentPasswordManagerDriver::PasswordFieldVisibleInInsecureContext() { | 288 void ContentPasswordManagerDriver::PasswordFieldVisibleInInsecureContext() { |
| 211 MaybeNotifyPasswordInputShownOnHttp(render_frame_host_); | 289 VisiblePasswordObserver* observer = |
| 290 VisiblePasswordObserver::GetOrCreateForWebContents( | |
| 291 content::WebContents::FromRenderFrameHost(render_frame_host_)); | |
| 292 observer->RenderFrameHasVisiblePasswordField(render_frame_host_); | |
| 212 } | 293 } |
| 213 | 294 |
| 214 void ContentPasswordManagerDriver:: | 295 void ContentPasswordManagerDriver:: |
| 215 AllPasswordFieldsInInsecureContextInvisible() { | 296 AllPasswordFieldsInInsecureContextInvisible() { |
| 216 // TODO(estark): if all frames in the frame tree have their password | 297 VisiblePasswordObserver* observer = |
| 217 // fields hidden, then notify the WebContents that there are no | 298 VisiblePasswordObserver::GetOrCreateForWebContents( |
| 218 // visible password fields left. https://crbug.com/658764 | 299 content::WebContents::FromRenderFrameHost(render_frame_host_)); |
| 300 observer->RenderFrameHasNoVisiblePasswordFields(render_frame_host_); | |
| 219 } | 301 } |
| 220 | 302 |
| 221 void ContentPasswordManagerDriver::DidNavigateFrame( | 303 void ContentPasswordManagerDriver::DidNavigateFrame( |
| 222 const content::LoadCommittedDetails& details, | 304 const content::LoadCommittedDetails& details, |
| 223 const content::FrameNavigateParams& params) { | 305 const content::FrameNavigateParams& params) { |
| 224 // Clear page specific data after main frame navigation. | 306 // Clear page specific data after main frame navigation. |
| 225 if (!render_frame_host_->GetParent() && !details.is_in_page) { | 307 if (!render_frame_host_->GetParent() && !details.is_in_page) { |
| 226 GetPasswordManager()->DidNavigateMainFrame(); | 308 GetPasswordManager()->DidNavigateMainFrame(); |
| 227 GetPasswordAutofillManager()->DidNavigateMainFrame(); | 309 GetPasswordAutofillManager()->DidNavigateMainFrame(); |
| 228 } | 310 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 329 ContentPasswordManagerDriver::GetPasswordGenerationAgent() { | 411 ContentPasswordManagerDriver::GetPasswordGenerationAgent() { |
| 330 if (!password_gen_agent_) { | 412 if (!password_gen_agent_) { |
| 331 render_frame_host_->GetRemoteInterfaces()->GetInterface( | 413 render_frame_host_->GetRemoteInterfaces()->GetInterface( |
| 332 mojo::GetProxy(&password_gen_agent_)); | 414 mojo::GetProxy(&password_gen_agent_)); |
| 333 } | 415 } |
| 334 | 416 |
| 335 return password_gen_agent_; | 417 return password_gen_agent_; |
| 336 } | 418 } |
| 337 | 419 |
| 338 } // namespace password_manager | 420 } // namespace password_manager |
| OLD | NEW |