OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/extensions/api/passwords_private/passwords_private_api.
h" | 5 #include "chrome/browser/extensions/api/passwords_private/passwords_private_api.
h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/extensions/api/passwords_private/passwords_private_dele
gate_factory.h" |
8 #include "chrome/common/extensions/api/passwords_private.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" |
9 #include "extensions/browser/extension_function_registry.h" | 12 #include "extensions/browser/extension_function_registry.h" |
10 | 13 |
11 namespace extensions { | 14 namespace extensions { |
12 | 15 |
13 //////////////////////////////////////////////////////////////////////////////// | 16 //////////////////////////////////////////////////////////////////////////////// |
14 // PasswordsPrivateCanPasswordAccountBeManagedFunction | 17 // PasswordsPrivateCanPasswordAccountBeManagedFunction |
15 | 18 |
16 PasswordsPrivateCanPasswordAccountBeManagedFunction:: | 19 PasswordsPrivateCanPasswordAccountBeManagedFunction:: |
17 ~PasswordsPrivateCanPasswordAccountBeManagedFunction() {} | 20 ~PasswordsPrivateCanPasswordAccountBeManagedFunction() {} |
18 | 21 |
19 ExtensionFunction::ResponseAction | 22 ExtensionFunction::ResponseAction |
20 PasswordsPrivateCanPasswordAccountBeManagedFunction::Run() { | 23 PasswordsPrivateCanPasswordAccountBeManagedFunction::Run() { |
21 // TODO(khorimoto): Implement. | 24 scoped_ptr<base::FundamentalValue> visible(new base::FundamentalValue( |
22 | 25 password_manager::ManageAccountLinkExperimentEnabled())); |
23 return RespondNow(NoArguments()); | 26 return RespondNow(OneArgument(visible.Pass())); |
24 } | 27 } |
25 | 28 |
26 //////////////////////////////////////////////////////////////////////////////// | 29 //////////////////////////////////////////////////////////////////////////////// |
27 // PasswordsPrivateRemoveSavedPasswordFunction | 30 // PasswordsPrivateRemoveSavedPasswordFunction |
28 | 31 |
29 PasswordsPrivateRemoveSavedPasswordFunction:: | 32 PasswordsPrivateRemoveSavedPasswordFunction:: |
30 ~PasswordsPrivateRemoveSavedPasswordFunction() {} | 33 ~PasswordsPrivateRemoveSavedPasswordFunction() {} |
31 | 34 |
32 ExtensionFunction::ResponseAction | 35 ExtensionFunction::ResponseAction |
33 PasswordsPrivateRemoveSavedPasswordFunction::Run() { | 36 PasswordsPrivateRemoveSavedPasswordFunction::Run() { |
34 scoped_ptr<api::passwords_private::RemoveSavedPassword::Params> | 37 scoped_ptr<api::passwords_private::RemoveSavedPassword::Params> |
35 parameters = api::passwords_private::RemoveSavedPassword::Params:: | 38 parameters = api::passwords_private::RemoveSavedPassword::Params:: |
36 Create(*args_); | 39 Create(*args_); |
37 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 40 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
38 | 41 |
39 // TODO(khorimoto): Implement. | 42 PasswordsPrivateDelegate* delegate = |
| 43 PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
| 44 delegate->RemoveSavedPassword( |
| 45 parameters->login_pair.origin_url, |
| 46 parameters->login_pair.username); |
40 | 47 |
41 return RespondNow(NoArguments()); | 48 return RespondNow(NoArguments()); |
42 } | 49 } |
43 | 50 |
44 //////////////////////////////////////////////////////////////////////////////// | 51 //////////////////////////////////////////////////////////////////////////////// |
45 // PasswordsPrivateRemovePasswordExceptionFunction | 52 // PasswordsPrivateRemovePasswordExceptionFunction |
46 | 53 |
47 PasswordsPrivateRemovePasswordExceptionFunction:: | 54 PasswordsPrivateRemovePasswordExceptionFunction:: |
48 ~PasswordsPrivateRemovePasswordExceptionFunction() {} | 55 ~PasswordsPrivateRemovePasswordExceptionFunction() {} |
49 | 56 |
50 ExtensionFunction::ResponseAction | 57 ExtensionFunction::ResponseAction |
51 PasswordsPrivateRemovePasswordExceptionFunction::Run() { | 58 PasswordsPrivateRemovePasswordExceptionFunction::Run() { |
52 scoped_ptr<api::passwords_private::RemovePasswordException::Params> | 59 scoped_ptr<api::passwords_private::RemovePasswordException::Params> |
53 parameters = api::passwords_private::RemovePasswordException:: | 60 parameters = api::passwords_private::RemovePasswordException:: |
54 Params::Create(*args_); | 61 Params::Create(*args_); |
55 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 62 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
56 | 63 |
57 // TODO(khorimoto): Implement. | 64 PasswordsPrivateDelegate* delegate = |
| 65 PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
| 66 delegate->RemovePasswordException(parameters->exception_url); |
58 | 67 |
59 return RespondNow(NoArguments()); | 68 return RespondNow(NoArguments()); |
60 } | 69 } |
61 | 70 |
62 //////////////////////////////////////////////////////////////////////////////// | 71 //////////////////////////////////////////////////////////////////////////////// |
63 // PasswordsPrivateGetPlaintextPasswordFunction | 72 // PasswordsPrivateGetPlaintextPasswordFunction |
64 | 73 |
65 PasswordsPrivateGetPlaintextPasswordFunction:: | 74 PasswordsPrivateGetPlaintextPasswordFunction:: |
| 75 PasswordsPrivateGetPlaintextPasswordFunction() |
| 76 : observer_(nullptr) {} |
| 77 |
| 78 PasswordsPrivateGetPlaintextPasswordFunction:: |
66 ~PasswordsPrivateGetPlaintextPasswordFunction() {} | 79 ~PasswordsPrivateGetPlaintextPasswordFunction() {} |
67 | 80 |
68 ExtensionFunction::ResponseAction | 81 ExtensionFunction::ResponseAction |
69 PasswordsPrivateGetPlaintextPasswordFunction::Run() { | 82 PasswordsPrivateGetPlaintextPasswordFunction::Run() { |
70 scoped_ptr<api::passwords_private::GetPlaintextPassword::Params> | 83 scoped_ptr<api::passwords_private::GetPlaintextPassword::Params> |
71 parameters = api::passwords_private::GetPlaintextPassword::Params:: | 84 parameters = api::passwords_private::GetPlaintextPassword::Params:: |
72 Create(*args_); | 85 Create(*args_); |
73 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 86 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
74 | 87 |
75 // TODO(khorimoto): Implement. | 88 PasswordsPrivateDelegate* delegate = |
| 89 PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context()); |
76 | 90 |
77 return RespondNow(NoArguments()); | 91 // Set up an observer for the plaintext password retrieval. When the password |
| 92 // has been fetched, the observer will be deleted in |
| 93 // ReplyWithPlaintextPassword(). |
| 94 observer_ = new PlaintextPasswordObserver( |
| 95 parameters->login_pair, make_scoped_refptr(this), delegate); |
| 96 |
| 97 // Now, request the password and let the observer listen for it. |
| 98 delegate->RequestShowPassword( |
| 99 parameters->login_pair.origin_url, |
| 100 parameters->login_pair.username, |
| 101 content::WebContents::FromRenderViewHost(render_view_host()) |
| 102 ->GetTopLevelNativeWindow()); |
| 103 |
| 104 return RespondLater(); |
| 105 } |
| 106 |
| 107 void PasswordsPrivateGetPlaintextPasswordFunction::ReplyWithPlaintextPassword( |
| 108 const std::string& plaintext_password) { |
| 109 scoped_ptr<base::StringValue> password_value( |
| 110 new base::StringValue(plaintext_password)); |
| 111 Respond(OneArgument(password_value.Pass())); |
| 112 |
| 113 // Delete |observer_|. This, in turn, will also cause |this| to be deleted |
| 114 // since |observer_|'s |fn_needing_reply| will have its refcount decremented |
| 115 // to 0. |
| 116 delete observer_; |
| 117 } |
| 118 |
| 119 PasswordsPrivateGetPlaintextPasswordFunction::PlaintextPasswordObserver:: |
| 120 PlaintextPasswordObserver( |
| 121 const extensions::api::passwords_private::LoginPair& login_pair, |
| 122 const scoped_refptr<extensions:: |
| 123 PasswordsPrivateGetPlaintextPasswordFunction> fn_needing_reply, |
| 124 extensions::PasswordsPrivateDelegate* delegate) |
| 125 : fn_needing_reply_(fn_needing_reply), |
| 126 delegate_(delegate) { |
| 127 // Unfortunately, the copy constructor for generated API dictionaries is |
| 128 // private, so copy the fields individually. |
| 129 login_pair_.origin_url = login_pair.origin_url; |
| 130 login_pair_.username = login_pair.username; |
| 131 |
| 132 // Observe plaintext password retrieval. |
| 133 delegate_->AddObserver(this); |
| 134 } |
| 135 |
| 136 void PasswordsPrivateGetPlaintextPasswordFunction::PlaintextPasswordObserver:: |
| 137 OnPlaintextPasswordFetched( |
| 138 const std::string& origin_url, |
| 139 const std::string& username, |
| 140 const std::string& plaintext_password) { |
| 141 if (login_pair_.origin_url == origin_url && |
| 142 login_pair_.username == username) { |
| 143 fn_needing_reply_->ReplyWithPlaintextPassword(plaintext_password); |
| 144 } |
| 145 } |
| 146 |
| 147 PasswordsPrivateGetPlaintextPasswordFunction::PlaintextPasswordObserver:: |
| 148 ~PlaintextPasswordObserver() { |
| 149 delegate_->RemoveObserver(this); |
78 } | 150 } |
79 | 151 |
80 } // namespace extensions | 152 } // namespace extensions |
OLD | NEW |