Chromium Code Reviews| Index: chrome/browser/extensions/api/passwords_private/passwords_private_api.cc |
| diff --git a/chrome/browser/extensions/api/passwords_private/passwords_private_api.cc b/chrome/browser/extensions/api/passwords_private/passwords_private_api.cc |
| index ce1128ab807c846af805e19541329ea36a7b229d..cd5439bb635a6417c9ecbcad6ef123201d1f921c 100644 |
| --- a/chrome/browser/extensions/api/passwords_private/passwords_private_api.cc |
| +++ b/chrome/browser/extensions/api/passwords_private/passwords_private_api.cc |
| @@ -5,7 +5,10 @@ |
| #include "chrome/browser/extensions/api/passwords_private/passwords_private_api.h" |
| #include "base/values.h" |
| +#include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate_factory.h" |
| #include "chrome/common/extensions/api/passwords_private.h" |
| +#include "components/password_manager/core/common/experiments.h" |
| +#include "content/public/browser/web_contents.h" |
| #include "extensions/browser/extension_function_registry.h" |
| namespace extensions { |
| @@ -18,9 +21,9 @@ PasswordsPrivateCanPasswordAccountBeManagedFunction:: |
| ExtensionFunction::ResponseAction |
| PasswordsPrivateCanPasswordAccountBeManagedFunction::Run() { |
| - // TODO(khorimoto): Implement. |
| - |
| - return RespondNow(NoArguments()); |
| + scoped_ptr<base::FundamentalValue> visible(new base::FundamentalValue( |
| + password_manager::ManageAccountLinkExperimentEnabled())); |
| + return RespondNow(OneArgument(visible.Pass())); |
| } |
| //////////////////////////////////////////////////////////////////////////////// |
| @@ -36,7 +39,11 @@ ExtensionFunction::ResponseAction |
| Create(*args_); |
| EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| - // TODO(khorimoto): Implement. |
| + PasswordsPrivateDelegate* delegate = |
| + PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
| + delegate->RemoveSavedPassword( |
| + parameters->login_pair.origin_url, |
| + parameters->login_pair.username); |
| return RespondNow(NoArguments()); |
| } |
| @@ -54,7 +61,9 @@ ExtensionFunction::ResponseAction |
| Params::Create(*args_); |
| EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| - // TODO(khorimoto): Implement. |
| + PasswordsPrivateDelegate* delegate = |
| + PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
| + delegate->RemovePasswordException(parameters->exception_url); |
| return RespondNow(NoArguments()); |
| } |
| @@ -62,6 +71,58 @@ ExtensionFunction::ResponseAction |
| //////////////////////////////////////////////////////////////////////////////// |
| // PasswordsPrivateGetPlaintextPasswordFunction |
| +class PasswordsPrivateGetPlaintextPasswordFunction::PlaintextPasswordObserver : |
| + public extensions::PasswordsPrivateDelegate::Observer { |
| + public: |
| + PlaintextPasswordObserver( |
| + const extensions::api::passwords_private::LoginPair& login_pair, |
| + const scoped_refptr<extensions:: |
| + PasswordsPrivateGetPlaintextPasswordFunction> fn_needing_reply, |
|
stevenjb
2015/05/26 22:35:25
This is in namespace extension, so all of the exte
Kyle Horimoto
2015/05/28 22:33:15
N/A, since this has been removed.
|
| + extensions::PasswordsPrivateDelegate* delegate) |
| + : fn_needing_reply_(fn_needing_reply), |
| + delegate_(delegate) { |
| + // Unfortunately, the copy constructor for generated API dictionaries is |
| + // private, so copy the fields individually. |
| + login_pair_.origin_url = login_pair.origin_url; |
| + login_pair_.username = login_pair.username; |
| + |
| + // Observe plaintext password retrieval. |
| + delegate_->AddObserver(this); |
| + } |
| + |
| + ~PlaintextPasswordObserver() override { |
| + delegate_->RemoveObserver(this); |
| + } |
| + |
| + // extensions::PasswordsPrivateDelegate::Observer overrides; |
| + void OnPlaintextPasswordFetched( |
| + const std::string& origin_url, |
| + const std::string& username, |
| + const std::string& plaintext_password) override { |
| + if (login_pair_.origin_url == origin_url && |
| + login_pair_.username == username) { |
| + fn_needing_reply_->ReplyWithPlaintextPassword(plaintext_password); |
| + } |
| + } |
| + |
| + private: |
| + // The LoginPair whose password is being requested. |
| + extensions::api::passwords_private::LoginPair login_pair_; |
| + |
| + // The function waiting on a response containing the password. A |
| + // scoped_refptr is used to ensure that the function is not deleted before |
| + // the plaintext password has been returned. |
| + scoped_refptr<extensions::PasswordsPrivateGetPlaintextPasswordFunction> |
| + fn_needing_reply_; |
| + |
| + // The delegate this class is observing. |
| + extensions::PasswordsPrivateDelegate* delegate_; |
| +}; |
| + |
| +PasswordsPrivateGetPlaintextPasswordFunction:: |
| + PasswordsPrivateGetPlaintextPasswordFunction() |
| + : observer_(nullptr) {} |
| + |
| PasswordsPrivateGetPlaintextPasswordFunction:: |
| ~PasswordsPrivateGetPlaintextPasswordFunction() {} |
| @@ -72,9 +133,35 @@ ExtensionFunction::ResponseAction |
| Create(*args_); |
| EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| - // TODO(khorimoto): Implement. |
| + PasswordsPrivateDelegate* delegate = |
| + PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
| - return RespondNow(NoArguments()); |
| + // Set up an observer for the plaintext password retrieval. When the password |
| + // has been fetched, the observer will be deleted in |
| + // ReplyWithPlaintextPassword(). |
| + observer_ = new PlaintextPasswordObserver( |
| + parameters->login_pair, make_scoped_refptr(this), delegate); |
| + |
| + // Now, request the password and let the observer listen for it. |
| + delegate->RequestShowPassword( |
| + parameters->login_pair.origin_url, |
| + parameters->login_pair.username, |
| + content::WebContents::FromRenderViewHost(render_view_host()) |
| + ->GetTopLevelNativeWindow()); |
|
stevenjb
2015/05/26 22:35:25
I don't think that we can guarantee that this will
Kyle Horimoto
2015/05/28 22:33:16
Used an event instead.
|
| + |
| + return RespondLater(); |
| +} |
| + |
| +void PasswordsPrivateGetPlaintextPasswordFunction::ReplyWithPlaintextPassword( |
| + const std::string& plaintext_password) { |
| + scoped_ptr<base::StringValue> password_value( |
| + new base::StringValue(plaintext_password)); |
| + Respond(OneArgument(password_value.Pass())); |
| + |
| + // Delete |observer_|. This, in turn, will also cause |this| to be deleted |
| + // since |observer_|'s |fn_needing_reply| will have its refcount decremented |
| + // to 0. |
| + delete observer_; |
| } |
| } // namespace extensions |