Chromium Code Reviews| 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 |
| 74 class PasswordsPrivateGetPlaintextPasswordFunction::PlaintextPasswordObserver : | |
| 75 public extensions::PasswordsPrivateDelegate::Observer { | |
| 76 public: | |
| 77 PlaintextPasswordObserver( | |
| 78 const extensions::api::passwords_private::LoginPair& login_pair, | |
| 79 const scoped_refptr<extensions:: | |
| 80 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.
| |
| 81 extensions::PasswordsPrivateDelegate* delegate) | |
| 82 : fn_needing_reply_(fn_needing_reply), | |
| 83 delegate_(delegate) { | |
| 84 // Unfortunately, the copy constructor for generated API dictionaries is | |
| 85 // private, so copy the fields individually. | |
| 86 login_pair_.origin_url = login_pair.origin_url; | |
| 87 login_pair_.username = login_pair.username; | |
| 88 | |
| 89 // Observe plaintext password retrieval. | |
| 90 delegate_->AddObserver(this); | |
| 91 } | |
| 92 | |
| 93 ~PlaintextPasswordObserver() override { | |
| 94 delegate_->RemoveObserver(this); | |
| 95 } | |
| 96 | |
| 97 // extensions::PasswordsPrivateDelegate::Observer overrides; | |
| 98 void OnPlaintextPasswordFetched( | |
| 99 const std::string& origin_url, | |
| 100 const std::string& username, | |
| 101 const std::string& plaintext_password) override { | |
| 102 if (login_pair_.origin_url == origin_url && | |
| 103 login_pair_.username == username) { | |
| 104 fn_needing_reply_->ReplyWithPlaintextPassword(plaintext_password); | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 private: | |
| 109 // The LoginPair whose password is being requested. | |
| 110 extensions::api::passwords_private::LoginPair login_pair_; | |
| 111 | |
| 112 // The function waiting on a response containing the password. A | |
| 113 // scoped_refptr is used to ensure that the function is not deleted before | |
| 114 // the plaintext password has been returned. | |
| 115 scoped_refptr<extensions::PasswordsPrivateGetPlaintextPasswordFunction> | |
| 116 fn_needing_reply_; | |
| 117 | |
| 118 // The delegate this class is observing. | |
| 119 extensions::PasswordsPrivateDelegate* delegate_; | |
| 120 }; | |
| 121 | |
| 122 PasswordsPrivateGetPlaintextPasswordFunction:: | |
| 123 PasswordsPrivateGetPlaintextPasswordFunction() | |
| 124 : observer_(nullptr) {} | |
| 125 | |
| 65 PasswordsPrivateGetPlaintextPasswordFunction:: | 126 PasswordsPrivateGetPlaintextPasswordFunction:: |
| 66 ~PasswordsPrivateGetPlaintextPasswordFunction() {} | 127 ~PasswordsPrivateGetPlaintextPasswordFunction() {} |
| 67 | 128 |
| 68 ExtensionFunction::ResponseAction | 129 ExtensionFunction::ResponseAction |
| 69 PasswordsPrivateGetPlaintextPasswordFunction::Run() { | 130 PasswordsPrivateGetPlaintextPasswordFunction::Run() { |
| 70 scoped_ptr<api::passwords_private::GetPlaintextPassword::Params> | 131 scoped_ptr<api::passwords_private::GetPlaintextPassword::Params> |
| 71 parameters = api::passwords_private::GetPlaintextPassword::Params:: | 132 parameters = api::passwords_private::GetPlaintextPassword::Params:: |
| 72 Create(*args_); | 133 Create(*args_); |
| 73 EXTENSION_FUNCTION_VALIDATE(parameters.get()); | 134 EXTENSION_FUNCTION_VALIDATE(parameters.get()); |
| 74 | 135 |
| 75 // TODO(khorimoto): Implement. | 136 PasswordsPrivateDelegate* delegate = |
| 137 PasswordsPrivateDelegateFactory::GetForBrowserContext(browser_context()); | |
| 76 | 138 |
| 77 return RespondNow(NoArguments()); | 139 // Set up an observer for the plaintext password retrieval. When the password |
| 140 // has been fetched, the observer will be deleted in | |
| 141 // ReplyWithPlaintextPassword(). | |
| 142 observer_ = new PlaintextPasswordObserver( | |
| 143 parameters->login_pair, make_scoped_refptr(this), delegate); | |
| 144 | |
| 145 // Now, request the password and let the observer listen for it. | |
| 146 delegate->RequestShowPassword( | |
| 147 parameters->login_pair.origin_url, | |
| 148 parameters->login_pair.username, | |
| 149 content::WebContents::FromRenderViewHost(render_view_host()) | |
| 150 ->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.
| |
| 151 | |
| 152 return RespondLater(); | |
| 153 } | |
| 154 | |
| 155 void PasswordsPrivateGetPlaintextPasswordFunction::ReplyWithPlaintextPassword( | |
| 156 const std::string& plaintext_password) { | |
| 157 scoped_ptr<base::StringValue> password_value( | |
| 158 new base::StringValue(plaintext_password)); | |
| 159 Respond(OneArgument(password_value.Pass())); | |
| 160 | |
| 161 // Delete |observer_|. This, in turn, will also cause |this| to be deleted | |
| 162 // since |observer_|'s |fn_needing_reply| will have its refcount decremented | |
| 163 // to 0. | |
| 164 delete observer_; | |
| 78 } | 165 } |
| 79 | 166 |
| 80 } // namespace extensions | 167 } // namespace extensions |
| OLD | NEW |