| 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..d0f83d97e4428249e558bed713503454a5fa6ccb 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());
|
| }
|
| @@ -63,6 +72,10 @@ ExtensionFunction::ResponseAction
|
| // PasswordsPrivateGetPlaintextPasswordFunction
|
|
|
| PasswordsPrivateGetPlaintextPasswordFunction::
|
| + PasswordsPrivateGetPlaintextPasswordFunction()
|
| + : observer_(nullptr) {}
|
| +
|
| +PasswordsPrivateGetPlaintextPasswordFunction::
|
| ~PasswordsPrivateGetPlaintextPasswordFunction() {}
|
|
|
| ExtensionFunction::ResponseAction
|
| @@ -72,9 +85,68 @@ 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());
|
| +
|
| + 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_;
|
| +}
|
| +
|
| +PasswordsPrivateGetPlaintextPasswordFunction::PlaintextPasswordObserver::
|
| + PlaintextPasswordObserver(
|
| + const extensions::api::passwords_private::LoginPair& login_pair,
|
| + const scoped_refptr<extensions::
|
| + PasswordsPrivateGetPlaintextPasswordFunction> fn_needing_reply,
|
| + 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);
|
| +}
|
| +
|
| +void PasswordsPrivateGetPlaintextPasswordFunction::PlaintextPasswordObserver::
|
| + OnPlaintextPasswordFetched(
|
| + const std::string& origin_url,
|
| + const std::string& username,
|
| + const std::string& plaintext_password) {
|
| + if (login_pair_.origin_url == origin_url &&
|
| + login_pair_.username == username) {
|
| + fn_needing_reply_->ReplyWithPlaintextPassword(plaintext_password);
|
| + }
|
| +}
|
| +
|
| +PasswordsPrivateGetPlaintextPasswordFunction::PlaintextPasswordObserver::
|
| + ~PlaintextPasswordObserver() {
|
| + delegate_->RemoveObserver(this);
|
| }
|
|
|
| } // namespace extensions
|
|
|