1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/extensions/api/passwords_private/passwords_private_api.h"
7 #include "base/values.h"
8 #include "chrome/browser/extensions/api/passwords_private/passwords_private_delegate_factory.h"
9 #include "chrome/common/extensions/api/passwords_private.h"
10 #include "components/password_manager/core/common/experiments.h"
11 #include "content/public/browser/web_contents.h"
12 #include "extensions/browser/extension_function_registry.h"
14 namespace extensions
{
16 ////////////////////////////////////////////////////////////////////////////////
17 // PasswordsPrivateCanPasswordAccountBeManagedFunction
19 PasswordsPrivateCanPasswordAccountBeManagedFunction::
20 ~PasswordsPrivateCanPasswordAccountBeManagedFunction() {}
22 ExtensionFunction::ResponseAction
23 PasswordsPrivateCanPasswordAccountBeManagedFunction::Run() {
24 scoped_ptr
<base::FundamentalValue
> visible(new base::FundamentalValue(
25 password_manager::ManageAccountLinkExperimentEnabled()));
26 return RespondNow(OneArgument(visible
.Pass()));
29 ////////////////////////////////////////////////////////////////////////////////
30 // PasswordsPrivateRemoveSavedPasswordFunction
32 PasswordsPrivateRemoveSavedPasswordFunction::
33 ~PasswordsPrivateRemoveSavedPasswordFunction() {}
35 ExtensionFunction::ResponseAction
36 PasswordsPrivateRemoveSavedPasswordFunction::Run() {
37 scoped_ptr
<api::passwords_private::RemoveSavedPassword::Params
>
38 parameters
= api::passwords_private::RemoveSavedPassword::Params::
40 EXTENSION_FUNCTION_VALIDATE(parameters
.get());
42 PasswordsPrivateDelegate
* delegate
=
43 PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context(),
45 delegate
->RemoveSavedPassword(
46 parameters
->login_pair
.origin_url
,
47 parameters
->login_pair
.username
);
49 return RespondNow(NoArguments());
52 ////////////////////////////////////////////////////////////////////////////////
53 // PasswordsPrivateRemovePasswordExceptionFunction
55 PasswordsPrivateRemovePasswordExceptionFunction::
56 ~PasswordsPrivateRemovePasswordExceptionFunction() {}
58 ExtensionFunction::ResponseAction
59 PasswordsPrivateRemovePasswordExceptionFunction::Run() {
60 scoped_ptr
<api::passwords_private::RemovePasswordException::Params
>
61 parameters
= api::passwords_private::RemovePasswordException::
62 Params::Create(*args_
);
63 EXTENSION_FUNCTION_VALIDATE(parameters
.get());
65 PasswordsPrivateDelegate
* delegate
=
66 PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context(),
68 delegate
->RemovePasswordException(parameters
->exception_url
);
70 return RespondNow(NoArguments());
73 ////////////////////////////////////////////////////////////////////////////////
74 // PasswordsPrivateRequestPlaintextPasswordFunction
76 PasswordsPrivateRequestPlaintextPasswordFunction::
77 ~PasswordsPrivateRequestPlaintextPasswordFunction() {}
79 ExtensionFunction::ResponseAction
80 PasswordsPrivateRequestPlaintextPasswordFunction::Run() {
81 scoped_ptr
<api::passwords_private::RequestPlaintextPassword::Params
>
82 parameters
= api::passwords_private::RequestPlaintextPassword::Params::
84 EXTENSION_FUNCTION_VALIDATE(parameters
.get());
86 PasswordsPrivateDelegate
* delegate
=
87 PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context(),
90 delegate
->RequestShowPassword(parameters
->login_pair
.origin_url
,
91 parameters
->login_pair
.username
,
92 GetSenderWebContents());
94 // No response given from this API function; instead, listeners wait for the
95 // chrome.passwordsPrivate.onPlaintextPasswordRetrieved event to fire.
96 return RespondNow(NoArguments());
99 } // namespace extensions