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