| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 3501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3512 | 3512 |
| 3513 } // namespace | 3513 } // namespace |
| 3514 | 3514 |
| 3515 // See AddSavedPassword() in chrome/test/functional/pyauto.py for sample json | 3515 // See AddSavedPassword() in chrome/test/functional/pyauto.py for sample json |
| 3516 // input. | 3516 // input. |
| 3517 // Sample json output: { "password_added": true } | 3517 // Sample json output: { "password_added": true } |
| 3518 void TestingAutomationProvider::AddSavedPassword( | 3518 void TestingAutomationProvider::AddSavedPassword( |
| 3519 Browser* browser, | 3519 Browser* browser, |
| 3520 DictionaryValue* args, | 3520 DictionaryValue* args, |
| 3521 IPC::Message* reply_message) { | 3521 IPC::Message* reply_message) { |
| 3522 AutomationJSONReply reply(this, reply_message); | |
| 3523 DictionaryValue* password_dict = NULL; | 3522 DictionaryValue* password_dict = NULL; |
| 3524 | |
| 3525 if (!args->GetDictionary("password", &password_dict)) { | 3523 if (!args->GetDictionary("password", &password_dict)) { |
| 3526 reply.SendError("Password must be a dictionary."); | 3524 AutomationJSONReply(this, reply_message).SendError( |
| 3525 "Must specify a password dictionary."); |
| 3527 return; | 3526 return; |
| 3528 } | 3527 } |
| 3529 | 3528 |
| 3530 // The signon realm is effectively the primary key and must be included. | 3529 // The "signon realm" is effectively the primary key and must be included. |
| 3531 // Check here before calling GetPasswordFormFromDict. | 3530 // Check here before calling GetPasswordFormFromDict. |
| 3532 if (!password_dict->HasKey("signon_realm")) { | 3531 if (!password_dict->HasKey("signon_realm")) { |
| 3533 reply.SendError("Password must include signon_realm."); | 3532 AutomationJSONReply(this, reply_message).SendError( |
| 3533 "Password must include a value for 'signon_realm.'"); |
| 3534 return; | 3534 return; |
| 3535 } | 3535 } |
| 3536 |
| 3536 webkit_glue::PasswordForm new_password = | 3537 webkit_glue::PasswordForm new_password = |
| 3537 GetPasswordFormFromDict(*password_dict); | 3538 GetPasswordFormFromDict(*password_dict); |
| 3538 | 3539 |
| 3539 Profile* profile = browser->profile(); | |
| 3540 // Use IMPLICIT_ACCESS since new passwords aren't added in incognito mode. | 3540 // Use IMPLICIT_ACCESS since new passwords aren't added in incognito mode. |
| 3541 PasswordStore* password_store = | 3541 PasswordStore* password_store = |
| 3542 profile->GetPasswordStore(Profile::IMPLICIT_ACCESS); | 3542 browser->profile()->GetPasswordStore(Profile::IMPLICIT_ACCESS); |
| 3543 | 3543 |
| 3544 // Set the return based on whether setting the password succeeded. | 3544 // The password store does not exist for an incognito window. |
| 3545 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); | 3545 if (password_store == NULL) { |
| 3546 | 3546 scoped_ptr<DictionaryValue> return_value(new DictionaryValue); |
| 3547 // It will be null if it's accessed in an incognito window. | |
| 3548 if (password_store != NULL) { | |
| 3549 password_store->AddLogin(new_password); | |
| 3550 return_value->SetBoolean("password_added", true); | |
| 3551 } else { | |
| 3552 return_value->SetBoolean("password_added", false); | 3547 return_value->SetBoolean("password_added", false); |
| 3548 AutomationJSONReply(this, reply_message).SendSuccess(return_value.get()); |
| 3549 return; |
| 3553 } | 3550 } |
| 3554 | 3551 |
| 3555 reply.SendSuccess(return_value.get()); | 3552 // This observer will delete itself. |
| 3553 PasswordStoreLoginsChangedObserver *observer = |
| 3554 new PasswordStoreLoginsChangedObserver(this, reply_message, |
| 3555 "password_added"); |
| 3556 observer->Init(); |
| 3557 password_store->AddLogin(new_password); |
| 3556 } | 3558 } |
| 3557 | 3559 |
| 3558 // See RemoveSavedPassword() in chrome/test/functional/pyauto.py for sample | 3560 // See RemoveSavedPassword() in chrome/test/functional/pyauto.py for sample |
| 3559 // json input. | 3561 // json input. |
| 3560 // Sample json output: {} | 3562 // Sample json output: {} |
| 3561 void TestingAutomationProvider::RemoveSavedPassword( | 3563 void TestingAutomationProvider::RemoveSavedPassword( |
| 3562 Browser* browser, | 3564 Browser* browser, |
| 3563 DictionaryValue* args, | 3565 DictionaryValue* args, |
| 3564 IPC::Message* reply_message) { | 3566 IPC::Message* reply_message) { |
| 3565 AutomationJSONReply reply(this, reply_message); | 3567 AutomationJSONReply reply(this, reply_message); |
| 3566 DictionaryValue* password_dict = NULL; | 3568 DictionaryValue* password_dict = NULL; |
| 3567 | 3569 |
| 3568 if (!args->GetDictionary("password", &password_dict)) { | 3570 if (!args->GetDictionary("password", &password_dict)) { |
| 3569 reply.SendError("Password must be a dictionary."); | 3571 reply.SendError("Password must be a dictionary."); |
| 3570 return; | 3572 return; |
| 3571 } | 3573 } |
| 3572 | 3574 |
| 3573 // The signon realm is effectively the primary key and must be included. | 3575 // The signon realm is effectively the primary key and must be included. |
| 3574 // Check here before calling GetPasswordFormFromDict. | 3576 // Check here before calling GetPasswordFormFromDict. |
| 3575 if (!password_dict->HasKey("signon_realm")) { | 3577 if (!password_dict->HasKey("signon_realm")) { |
| 3576 reply.SendError("Password must include signon_realm."); | 3578 reply.SendError("Password must include signon_realm."); |
| 3577 return; | 3579 return; |
| 3578 } | 3580 } |
| 3579 webkit_glue::PasswordForm to_remove = | 3581 webkit_glue::PasswordForm to_remove = |
| 3580 GetPasswordFormFromDict(*password_dict); | 3582 GetPasswordFormFromDict(*password_dict); |
| 3581 | 3583 |
| 3582 Profile* profile = browser->profile(); | |
| 3583 // Use EXPLICIT_ACCESS since passwords can be removed in incognito mode. | 3584 // Use EXPLICIT_ACCESS since passwords can be removed in incognito mode. |
| 3584 PasswordStore* password_store = | 3585 PasswordStore* password_store = |
| 3585 profile->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 3586 browser->profile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); |
| 3586 | 3587 |
| 3587 password_store->RemoveLogin(to_remove); | 3588 password_store->RemoveLogin(to_remove); |
| 3588 reply.SendSuccess(NULL); | 3589 reply.SendSuccess(NULL); |
| 3589 } | 3590 } |
| 3590 | 3591 |
| 3591 // Sample json input: { "command": "GetSavedPasswords" } | 3592 // Sample json input: { "command": "GetSavedPasswords" } |
| 3592 // Refer to GetSavedPasswords() in chrome/test/pyautolib/pyauto.py for sample | 3593 // Refer to GetSavedPasswords() in chrome/test/pyautolib/pyauto.py for sample |
| 3593 // json output. | 3594 // json output. |
| 3594 void TestingAutomationProvider::GetSavedPasswords( | 3595 void TestingAutomationProvider::GetSavedPasswords( |
| 3595 Browser* browser, | 3596 Browser* browser, |
| 3596 DictionaryValue* args, | 3597 DictionaryValue* args, |
| 3597 IPC::Message* reply_message) { | 3598 IPC::Message* reply_message) { |
| 3598 Profile* profile = browser->profile(); | |
| 3599 // Use EXPLICIT_ACCESS since saved passwords can be retrieved in | 3599 // Use EXPLICIT_ACCESS since saved passwords can be retrieved in |
| 3600 // incognito mode. | 3600 // incognito mode. |
| 3601 PasswordStore* password_store = | 3601 PasswordStore* password_store = |
| 3602 profile->GetPasswordStore(Profile::EXPLICIT_ACCESS); | 3602 browser->profile()->GetPasswordStore(Profile::EXPLICIT_ACCESS); |
| 3603 password_store->GetAutofillableLogins( | 3603 password_store->GetAutofillableLogins( |
| 3604 new AutomationProviderGetPasswordsObserver(this, reply_message)); | 3604 new AutomationProviderGetPasswordsObserver(this, reply_message)); |
| 3605 // Observer deletes itself after returning. | 3605 // Observer deletes itself after sending the result. |
| 3606 } | 3606 } |
| 3607 | 3607 |
| 3608 // Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample | 3608 // Refer to ClearBrowsingData() in chrome/test/pyautolib/pyauto.py for sample |
| 3609 // json input. | 3609 // json input. |
| 3610 // Sample json output: {} | 3610 // Sample json output: {} |
| 3611 void TestingAutomationProvider::ClearBrowsingData( | 3611 void TestingAutomationProvider::ClearBrowsingData( |
| 3612 Browser* browser, | 3612 Browser* browser, |
| 3613 DictionaryValue* args, | 3613 DictionaryValue* args, |
| 3614 IPC::Message* reply_message) { | 3614 IPC::Message* reply_message) { |
| 3615 std::map<std::string, BrowsingDataRemover::TimePeriod> string_to_time_period; | 3615 std::map<std::string, BrowsingDataRemover::TimePeriod> string_to_time_period; |
| (...skipping 2089 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5705 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); | 5705 IPC::ParamTraits<std::vector<GURL> >::Write(reply_message_, redirects_gurl); |
| 5706 | 5706 |
| 5707 Send(reply_message_); | 5707 Send(reply_message_); |
| 5708 redirect_query_ = 0; | 5708 redirect_query_ = 0; |
| 5709 reply_message_ = NULL; | 5709 reply_message_ = NULL; |
| 5710 } | 5710 } |
| 5711 | 5711 |
| 5712 void TestingAutomationProvider::OnRemoveProvider() { | 5712 void TestingAutomationProvider::OnRemoveProvider() { |
| 5713 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5713 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5714 } | 5714 } |
| OLD | NEW |