| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #import "ios/chrome/browser/passwords/credential_manager.h" | 5 #import "ios/chrome/browser/passwords/credential_manager.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/ios/ios_util.h" | 9 #include "base/ios/ios_util.h" |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| 11 #include "base/mac/bind_objc_block.h" | 11 #include "base/mac/bind_objc_block.h" |
| 12 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
| 14 #include "base/threading/thread_task_runner_handle.h" |
| 15 #include "components/password_manager/core/browser/password_store_consumer.h" | 15 #include "components/password_manager/core/browser/password_store_consumer.h" |
| 16 #include "components/password_manager/core/common/credential_manager_types.h" | 16 #include "components/password_manager/core/common/credential_manager_types.h" |
| 17 #include "components/password_manager/core/common/password_manager_pref_names.h" | 17 #include "components/password_manager/core/common/password_manager_pref_names.h" |
| 18 #import "ios/chrome/browser/passwords/js_credential_manager.h" | 18 #import "ios/chrome/browser/passwords/js_credential_manager.h" |
| 19 #import "ios/web/public/url_scheme_util.h" | 19 #import "ios/web/public/url_scheme_util.h" |
| 20 #include "ios/web/public/web_state/credential.h" | 20 #include "ios/web/public/web_state/credential.h" |
| 21 #include "ios/web/public/web_state/url_verification_constants.h" | 21 #include "ios/web/public/web_state/url_verification_constants.h" |
| 22 #include "ios/web/public/web_state/web_state.h" | 22 #include "ios/web/public/web_state/web_state.h" |
| 23 #include "url/origin.h" | 23 #include "url/origin.h" |
| 24 | 24 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // function will attempt to retrieve a Credential from the PasswordStore that | 118 // function will attempt to retrieve a Credential from the PasswordStore that |
| 119 // meets the specified parameters and, if successful, send it back to the page | 119 // meets the specified parameters and, if successful, send it back to the page |
| 120 // via SendCredentialByID. | 120 // via SendCredentialByID. |
| 121 DCHECK_GE(request_id, 0); | 121 DCHECK_GE(request_id, 0); |
| 122 password_manager::PasswordStore* store = GetPasswordStore(); | 122 password_manager::PasswordStore* store = GetPasswordStore(); |
| 123 | 123 |
| 124 // If there's an outstanding request, or the PasswordStore isn't loaded yet, | 124 // If there's an outstanding request, or the PasswordStore isn't loaded yet, |
| 125 // the request should fail outright and the JS Promise should be rejected | 125 // the request should fail outright and the JS Promise should be rejected |
| 126 // with an appropriate error. | 126 // with an appropriate error. |
| 127 if (pending_request_ || !store) { | 127 if (pending_request_ || !store) { |
| 128 base::MessageLoop::current()->PostTask( | 128 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 129 FROM_HERE, | 129 FROM_HERE, |
| 130 base::Bind(&CredentialManager::RejectPromise, | 130 base::Bind(&CredentialManager::RejectPromise, |
| 131 weak_factory_.GetWeakPtr(), request_id, | 131 weak_factory_.GetWeakPtr(), request_id, |
| 132 pending_request_ ? ERROR_TYPE_PENDING_REQUEST | 132 pending_request_ ? ERROR_TYPE_PENDING_REQUEST |
| 133 : ERROR_TYPE_PASSWORD_STORE_UNAVAILABLE)); | 133 : ERROR_TYPE_PASSWORD_STORE_UNAVAILABLE)); |
| 134 return; | 134 return; |
| 135 } | 135 } |
| 136 | 136 |
| 137 // If the page requested a zero-click credential -- one that can be returned | 137 // If the page requested a zero-click credential -- one that can be returned |
| 138 // without first asking the user -- and if zero-click isn't currently | 138 // without first asking the user -- and if zero-click isn't currently |
| 139 // available, send back an empty credential. | 139 // available, send back an empty credential. |
| 140 if (zero_click_only && !IsZeroClickAllowed()) { | 140 if (zero_click_only && !IsZeroClickAllowed()) { |
| 141 base::MessageLoop::current()->PostTask( | 141 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 142 FROM_HERE, base::Bind(&CredentialManager::SendCredentialByID, | 142 FROM_HERE, base::Bind(&CredentialManager::SendCredentialByID, |
| 143 weak_factory_.GetWeakPtr(), request_id, | 143 weak_factory_.GetWeakPtr(), request_id, |
| 144 password_manager::CredentialInfo())); | 144 password_manager::CredentialInfo())); |
| 145 return; | 145 return; |
| 146 } | 146 } |
| 147 | 147 |
| 148 // If the page origin is untrusted, the request should be rejected. | 148 // If the page origin is untrusted, the request should be rejected. |
| 149 GURL page_url; | 149 GURL page_url; |
| 150 if (!GetUrlWithAbsoluteTrust(&page_url)) { | 150 if (!GetUrlWithAbsoluteTrust(&page_url)) { |
| 151 RejectPromise(request_id, ERROR_TYPE_SECURITY_ERROR_UNTRUSTED_ORIGIN); | 151 RejectPromise(request_id, ERROR_TYPE_SECURITY_ERROR_UNTRUSTED_ORIGIN); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 bool CredentialManager::GetUrlWithAbsoluteTrust(GURL* page_url) { | 377 bool CredentialManager::GetUrlWithAbsoluteTrust(GURL* page_url) { |
| 378 web::URLVerificationTrustLevel trust_level = | 378 web::URLVerificationTrustLevel trust_level = |
| 379 web::URLVerificationTrustLevel::kNone; | 379 web::URLVerificationTrustLevel::kNone; |
| 380 const GURL possibly_untrusted_url(web_state()->GetCurrentURL(&trust_level)); | 380 const GURL possibly_untrusted_url(web_state()->GetCurrentURL(&trust_level)); |
| 381 if (trust_level == web::URLVerificationTrustLevel::kAbsolute) { | 381 if (trust_level == web::URLVerificationTrustLevel::kAbsolute) { |
| 382 *page_url = possibly_untrusted_url; | 382 *page_url = possibly_untrusted_url; |
| 383 return true; | 383 return true; |
| 384 } | 384 } |
| 385 return false; | 385 return false; |
| 386 } | 386 } |
| OLD | NEW |