| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/password_controller.h" | 5 #import "ios/chrome/browser/passwords/password_controller.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> |
| 10 #include <utility> | 11 #include <utility> |
| 11 #include <vector> | 12 #include <vector> |
| 12 | 13 |
| 13 #import "base/ios/weak_nsobject.h" | 14 #import "base/ios/weak_nsobject.h" |
| 14 #include "base/json/json_reader.h" | 15 #include "base/json/json_reader.h" |
| 15 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
| 16 #include "base/mac/foundation_util.h" | 17 #include "base/mac/foundation_util.h" |
| 17 #include "base/mac/scoped_nsobject.h" | 18 #include "base/mac/scoped_nsobject.h" |
| 18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/ptr_util.h" |
| 19 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 20 #include "base/strings/sys_string_conversions.h" | 21 #include "base/strings/sys_string_conversions.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 22 #include "components/autofill/core/common/password_form.h" | 23 #include "components/autofill/core/common/password_form.h" |
| 23 #include "components/autofill/core/common/password_form_fill_data.h" | 24 #include "components/autofill/core/common/password_form_fill_data.h" |
| 24 #include "components/browser_sync/browser/profile_sync_service.h" | 25 #include "components/browser_sync/browser/profile_sync_service.h" |
| 25 #include "components/infobars/core/infobar_manager.h" | 26 #include "components/infobars/core/infobar_manager.h" |
| 26 #include "components/password_manager/core/browser/password_bubble_experiment.h" | 27 #include "components/password_manager/core/browser/password_bubble_experiment.h" |
| 27 #include "components/password_manager/core/browser/password_generation_manager.h
" | 28 #include "components/password_manager/core/browser/password_generation_manager.h
" |
| 28 #include "components/password_manager/core/browser/password_manager.h" | 29 #include "components/password_manager/core/browser/password_manager.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 187 |
| 187 // The normalized URL of the web page. | 188 // The normalized URL of the web page. |
| 188 rootDict.SetString("origin", formData.origin.spec()); | 189 rootDict.SetString("origin", formData.origin.spec()); |
| 189 | 190 |
| 190 // The normalized URL from the "action" attribute of the <form> tag. | 191 // The normalized URL from the "action" attribute of the <form> tag. |
| 191 rootDict.SetString("action", formData.action.spec()); | 192 rootDict.SetString("action", formData.action.spec()); |
| 192 | 193 |
| 193 // Input elements in the form. The list does not necessarily contain | 194 // Input elements in the form. The list does not necessarily contain |
| 194 // all elements from the form, but all elements listed here are required | 195 // all elements from the form, but all elements listed here are required |
| 195 // to identify the right form to fill. | 196 // to identify the right form to fill. |
| 196 auto fieldList = make_scoped_ptr(new base::ListValue()); | 197 auto fieldList = base::WrapUnique(new base::ListValue()); |
| 197 | 198 |
| 198 auto usernameField = make_scoped_ptr(new base::DictionaryValue()); | 199 auto usernameField = base::WrapUnique(new base::DictionaryValue()); |
| 199 usernameField->SetString("name", formData.username_field.name); | 200 usernameField->SetString("name", formData.username_field.name); |
| 200 usernameField->SetString("value", formData.username_field.value); | 201 usernameField->SetString("value", formData.username_field.value); |
| 201 fieldList->Append(usernameField.release()); | 202 fieldList->Append(usernameField.release()); |
| 202 | 203 |
| 203 auto passwordField = make_scoped_ptr(new base::DictionaryValue()); | 204 auto passwordField = base::WrapUnique(new base::DictionaryValue()); |
| 204 passwordField->SetString("name", formData.password_field.name); | 205 passwordField->SetString("name", formData.password_field.name); |
| 205 passwordField->SetString("value", formData.password_field.value); | 206 passwordField->SetString("value", formData.password_field.value); |
| 206 fieldList->Append(passwordField.release()); | 207 fieldList->Append(passwordField.release()); |
| 207 | 208 |
| 208 rootDict.Set("fields", fieldList.release()); | 209 rootDict.Set("fields", fieldList.release()); |
| 209 | 210 |
| 210 std::string jsonString; | 211 std::string jsonString; |
| 211 base::JSONWriter::Write(rootDict, &jsonString); | 212 base::JSONWriter::Write(rootDict, &jsonString); |
| 212 return base::SysUTF8ToNSString(jsonString); | 213 return base::SysUTF8ToNSString(jsonString); |
| 213 } | 214 } |
| 214 | 215 |
| 215 // Returns true if the trust level for the current page URL of |web_state| is | 216 // Returns true if the trust level for the current page URL of |web_state| is |
| 216 // kAbsolute. If |page_url| is not null, fills it with the current page URL. | 217 // kAbsolute. If |page_url| is not null, fills it with the current page URL. |
| 217 bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { | 218 bool GetPageURLAndCheckTrustLevel(web::WebState* web_state, GURL* page_url) { |
| 218 auto trustLevel = web::URLVerificationTrustLevel::kNone; | 219 auto trustLevel = web::URLVerificationTrustLevel::kNone; |
| 219 GURL dummy; | 220 GURL dummy; |
| 220 if (!page_url) | 221 if (!page_url) |
| 221 page_url = &dummy; | 222 page_url = &dummy; |
| 222 *page_url = web_state->GetCurrentURL(&trustLevel); | 223 *page_url = web_state->GetCurrentURL(&trustLevel); |
| 223 return trustLevel == web::URLVerificationTrustLevel::kAbsolute; | 224 return trustLevel == web::URLVerificationTrustLevel::kAbsolute; |
| 224 } | 225 } |
| 225 | 226 |
| 226 } // namespace | 227 } // namespace |
| 227 | 228 |
| 228 @implementation PasswordController { | 229 @implementation PasswordController { |
| 229 scoped_ptr<PasswordManager> passwordManager_; | 230 std::unique_ptr<PasswordManager> passwordManager_; |
| 230 scoped_ptr<PasswordGenerationManager> passwordGenerationManager_; | 231 std::unique_ptr<PasswordGenerationManager> passwordGenerationManager_; |
| 231 scoped_ptr<PasswordManagerClient> passwordManagerClient_; | 232 std::unique_ptr<PasswordManagerClient> passwordManagerClient_; |
| 232 scoped_ptr<PasswordManagerDriver> passwordManagerDriver_; | 233 std::unique_ptr<PasswordManagerDriver> passwordManagerDriver_; |
| 233 base::scoped_nsobject<PasswordGenerationAgent> passwordGenerationAgent_; | 234 base::scoped_nsobject<PasswordGenerationAgent> passwordGenerationAgent_; |
| 234 | 235 |
| 235 JsPasswordManager* passwordJsManager_; // weak | 236 JsPasswordManager* passwordJsManager_; // weak |
| 236 | 237 |
| 237 // The pending form data. | 238 // The pending form data. |
| 238 scoped_ptr<autofill::PasswordFormFillData> formData_; | 239 std::unique_ptr<autofill::PasswordFormFillData> formData_; |
| 239 | 240 |
| 240 // Bridge to observe WebState from Objective-C. | 241 // Bridge to observe WebState from Objective-C. |
| 241 scoped_ptr<web::WebStateObserverBridge> webStateObserverBridge_; | 242 std::unique_ptr<web::WebStateObserverBridge> webStateObserverBridge_; |
| 242 } | 243 } |
| 243 | 244 |
| 244 - (instancetype)initWithWebState:(web::WebState*)webState | 245 - (instancetype)initWithWebState:(web::WebState*)webState |
| 245 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate { | 246 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate { |
| 246 self = [self initWithWebState:webState | 247 self = [self initWithWebState:webState |
| 247 passwordsUiDelegate:UIDelegate | 248 passwordsUiDelegate:UIDelegate |
| 248 client:nullptr]; | 249 client:nullptr]; |
| 249 return self; | 250 return self; |
| 250 } | 251 } |
| 251 | 252 |
| 252 - (instancetype)initWithWebState:(web::WebState*)webState | 253 - (instancetype)initWithWebState:(web::WebState*)webState |
| 253 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate | 254 passwordsUiDelegate:(id<PasswordsUiDelegate>)UIDelegate |
| 254 client:(scoped_ptr<PasswordManagerClient>) | 255 client:(std::unique_ptr<PasswordManagerClient>) |
| 255 passwordManagerClient { | 256 passwordManagerClient { |
| 256 DCHECK(webState); | 257 DCHECK(webState); |
| 257 self = [super init]; | 258 self = [super init]; |
| 258 if (self) { | 259 if (self) { |
| 259 webStateObserverBridge_.reset( | 260 webStateObserverBridge_.reset( |
| 260 new web::WebStateObserverBridge(webState, self)); | 261 new web::WebStateObserverBridge(webState, self)); |
| 261 if (passwordManagerClient) | 262 if (passwordManagerClient) |
| 262 passwordManagerClient_ = std::move(passwordManagerClient); | 263 passwordManagerClient_ = std::move(passwordManagerClient); |
| 263 else | 264 else |
| 264 passwordManagerClient_.reset(new IOSChromePasswordManagerClient(self)); | 265 passwordManagerClient_.reset(new IOSChromePasswordManagerClient(self)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 password:(NSString*)password | 319 password:(NSString*)password |
| 319 completionHandler:(void (^)(BOOL))completionHandler { | 320 completionHandler:(void (^)(BOOL))completionHandler { |
| 320 [self findPasswordFormsWithCompletionHandler:^( | 321 [self findPasswordFormsWithCompletionHandler:^( |
| 321 const std::vector<autofill::PasswordForm>& forms) { | 322 const std::vector<autofill::PasswordForm>& forms) { |
| 322 for (const auto& form : forms) { | 323 for (const auto& form : forms) { |
| 323 autofill::PasswordFormFillData formData; | 324 autofill::PasswordFormFillData formData; |
| 324 autofill::PasswordFormMap matches; | 325 autofill::PasswordFormMap matches; |
| 325 // Initialize |matches| to satisfy the expectation from | 326 // Initialize |matches| to satisfy the expectation from |
| 326 // InitPasswordFormFillData() that the preferred match (3rd parameter) | 327 // InitPasswordFormFillData() that the preferred match (3rd parameter) |
| 327 // should be one of the |matches|. | 328 // should be one of the |matches|. |
| 328 auto scoped_form = make_scoped_ptr(new autofill::PasswordForm(form)); | 329 auto scoped_form = base::WrapUnique(new autofill::PasswordForm(form)); |
| 329 matches.insert( | 330 matches.insert( |
| 330 std::make_pair(form.username_value, std::move(scoped_form))); | 331 std::make_pair(form.username_value, std::move(scoped_form))); |
| 331 autofill::InitPasswordFormFillData(form, matches, &form, false, false, | 332 autofill::InitPasswordFormFillData(form, matches, &form, false, false, |
| 332 &formData); | 333 &formData); |
| 333 [self fillPasswordForm:formData | 334 [self fillPasswordForm:formData |
| 334 withUsername:base::SysNSStringToUTF16(username) | 335 withUsername:base::SysNSStringToUTF16(username) |
| 335 password:base::SysNSStringToUTF16(password) | 336 password:base::SysNSStringToUTF16(password) |
| 336 completionHandler:completionHandler]; | 337 completionHandler:completionHandler]; |
| 337 } | 338 } |
| 338 }]; | 339 }]; |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 fromFormsJSON:(NSString*)jsonString | 422 fromFormsJSON:(NSString*)jsonString |
| 422 pageURL:(const GURL&)pageURL { | 423 pageURL:(const GURL&)pageURL { |
| 423 DCHECK(forms); | 424 DCHECK(forms); |
| 424 if (![jsonString length]) { | 425 if (![jsonString length]) { |
| 425 VLOG(1) << "Error in password controller javascript."; | 426 VLOG(1) << "Error in password controller javascript."; |
| 426 return; | 427 return; |
| 427 } | 428 } |
| 428 | 429 |
| 429 int errorCode = 0; | 430 int errorCode = 0; |
| 430 std::string errorMessage; | 431 std::string errorMessage; |
| 431 scoped_ptr<base::Value> jsonData(base::JSONReader::ReadAndReturnError( | 432 std::unique_ptr<base::Value> jsonData(base::JSONReader::ReadAndReturnError( |
| 432 std::string([jsonString UTF8String]), false, &errorCode, &errorMessage)); | 433 std::string([jsonString UTF8String]), false, &errorCode, &errorMessage)); |
| 433 if (errorCode || !jsonData || !jsonData->IsType(base::Value::TYPE_LIST)) { | 434 if (errorCode || !jsonData || !jsonData->IsType(base::Value::TYPE_LIST)) { |
| 434 VLOG(1) << "JSON parse error " << errorMessage | 435 VLOG(1) << "JSON parse error " << errorMessage |
| 435 << " JSON string: " << [jsonString UTF8String]; | 436 << " JSON string: " << [jsonString UTF8String]; |
| 436 return; | 437 return; |
| 437 } | 438 } |
| 438 | 439 |
| 439 const base::ListValue* formDataList; | 440 const base::ListValue* formDataList; |
| 440 if (!jsonData->GetAsList(&formDataList)) | 441 if (!jsonData->GetAsList(&formDataList)) |
| 441 return; | 442 return; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form | 486 - (BOOL)getPasswordForm:(autofill::PasswordForm*)form |
| 486 fromPasswordFormJSON:(NSString*)jsonString | 487 fromPasswordFormJSON:(NSString*)jsonString |
| 487 pageURL:(const GURL&)pageURL { | 488 pageURL:(const GURL&)pageURL { |
| 488 DCHECK(form); | 489 DCHECK(form); |
| 489 // There is no identifiable password form on the page. | 490 // There is no identifiable password form on the page. |
| 490 if ([jsonString isEqualToString:@"noPasswordsFound"]) | 491 if ([jsonString isEqualToString:@"noPasswordsFound"]) |
| 491 return NO; | 492 return NO; |
| 492 | 493 |
| 493 int errorCode = 0; | 494 int errorCode = 0; |
| 494 std::string errorMessage; | 495 std::string errorMessage; |
| 495 scoped_ptr<const base::Value> jsonData(base::JSONReader::ReadAndReturnError( | 496 std::unique_ptr<const base::Value> jsonData( |
| 496 std::string([jsonString UTF8String]), false, &errorCode, &errorMessage)); | 497 base::JSONReader::ReadAndReturnError(std::string([jsonString UTF8String]), |
| 498 false, &errorCode, &errorMessage)); |
| 497 | 499 |
| 498 // If the the JSON string contains null, there is no identifiable password | 500 // If the the JSON string contains null, there is no identifiable password |
| 499 // form on the page. | 501 // form on the page. |
| 500 if (!errorCode && !jsonData) { | 502 if (!errorCode && !jsonData) { |
| 501 return NO; | 503 return NO; |
| 502 } | 504 } |
| 503 | 505 |
| 504 if (errorCode || !jsonData->IsType(base::Value::TYPE_DICTIONARY)) { | 506 if (errorCode || !jsonData->IsType(base::Value::TYPE_DICTIONARY)) { |
| 505 VLOG(1) << "JSON parse error " << errorMessage | 507 VLOG(1) << "JSON parse error " << errorMessage |
| 506 << " JSON string: " << [jsonString UTF8String]; | 508 << " JSON string: " << [jsonString UTF8String]; |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 } | 735 } |
| 734 autofill::FormFieldData field; | 736 autofill::FormFieldData field; |
| 735 field.name = std::move(element); | 737 field.name = std::move(element); |
| 736 field.form_control_type = base::UTF16ToUTF8(type); | 738 field.form_control_type = base::UTF16ToUTF8(type); |
| 737 form->form_data.fields.push_back(field); | 739 form->form_data.fields.push_back(field); |
| 738 } | 740 } |
| 739 | 741 |
| 740 return YES; | 742 return YES; |
| 741 } | 743 } |
| 742 | 744 |
| 743 - (void)showSavePasswordInfoBar:(scoped_ptr<PasswordFormManager>)formToSave { | 745 - (void)showSavePasswordInfoBar: |
| 746 (std::unique_ptr<PasswordFormManager>)formToSave { |
| 744 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) | 747 if (!webStateObserverBridge_ || !webStateObserverBridge_->web_state()) |
| 745 return; | 748 return; |
| 746 | 749 |
| 747 bool isSmartLockBrandingEnabled = false; | 750 bool isSmartLockBrandingEnabled = false; |
| 748 if (self.browserState) { | 751 if (self.browserState) { |
| 749 sync_driver::SyncService* sync_service = | 752 sync_driver::SyncService* sync_service = |
| 750 IOSChromeProfileSyncServiceFactory::GetForBrowserState( | 753 IOSChromeProfileSyncServiceFactory::GetForBrowserState( |
| 751 self.browserState); | 754 self.browserState); |
| 752 isSmartLockBrandingEnabled = | 755 isSmartLockBrandingEnabled = |
| 753 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( | 756 password_bubble_experiment::IsSmartLockBrandingSavePromptEnabled( |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 | 811 |
| 809 - (PasswordManager*)passwordManager { | 812 - (PasswordManager*)passwordManager { |
| 810 return passwordManager_.get(); | 813 return passwordManager_.get(); |
| 811 } | 814 } |
| 812 | 815 |
| 813 - (JsPasswordManager*)passwordJsManager { | 816 - (JsPasswordManager*)passwordJsManager { |
| 814 return passwordJsManager_; | 817 return passwordJsManager_; |
| 815 } | 818 } |
| 816 | 819 |
| 817 @end | 820 @end |
| OLD | NEW |