Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_UI_REQUEST_PIN_VIEW_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_UI_REQUEST_PIN_VIEW_H_ | |
| 7 | |
| 8 #include <memory> | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/compiler_specific.h" | |
| 13 #include "base/macros.h" | |
| 14 #include "base/memory/weak_ptr.h" | |
| 15 #include "base/strings/string16.h" | |
| 16 #include "ui/views/controls/textfield/textfield_controller.h" | |
| 17 #include "ui/views/view.h" | |
| 18 #include "ui/views/window/dialog_delegate.h" | |
| 19 | |
| 20 namespace views { | |
| 21 class Label; | |
| 22 } | |
| 23 | |
| 24 namespace chromeos { | |
| 25 | |
| 26 class PassphraseTextfield; | |
| 27 | |
| 28 // A dialog box for requesting PIN code. Instances of this class are managed by | |
| 29 // PinDialogManager. | |
| 30 class RequestPinView : public views::DialogDelegateView, | |
| 31 public views::TextfieldController { | |
| 32 public: | |
| 33 enum RequestPinCodeType { PIN, PUK, UNCHANGED }; | |
| 34 | |
| 35 enum RequestPinErrorType { | |
| 36 NONE, | |
| 37 INVALID_PIN, | |
| 38 INVALID_PUK, | |
| 39 MAX_ATTEMPTS_EXCEEDED, | |
| 40 UNKNOWN_ERROR | |
| 41 }; | |
| 42 | |
| 43 class Delegate { | |
| 44 public: | |
| 45 // Notification when user closes the PIN dialog. | |
| 46 virtual void OnPinDialogClosed() = 0; | |
| 47 }; | |
| 48 | |
| 49 // Used to send the PIN/PUK entered by the user in the textfield to the | |
| 50 // extension that asked for the code. | |
| 51 using RequestPinCallback = base::Callback<void(const base::string16&)>; | |
| 52 | |
| 53 // Creates the view to be embeded in the dialog that requests the PIN/PUK. | |
| 54 // |extension_name| - the name of the extension making the request. Displayed | |
| 55 // in the title and in the header of the view. | |
| 56 // |code_type| - the type of code requested, PIN or PUK. UNCHANGED is not | |
| 57 // accepted here. | |
| 58 // |attempts_left| - the number of attempts user has to try the code. When | |
| 59 // zero the textfield is disabled and user cannot provide any input. When | |
| 60 // -1 the user is allowed to provide the input and no information about | |
| 61 // the attepts left is displayed in the view. | |
| 62 // |callback| - used to send the value of the PIN/PUK the user entered. | |
| 63 // |delegate| - used to notify that dialog was closed. Cannot be null. | |
| 64 RequestPinView(const std::string& extension_name, | |
| 65 RequestPinView::RequestPinCodeType code_type, | |
| 66 int attempts_left, | |
| 67 const RequestPinCallback& callback, | |
| 68 Delegate* delegate); | |
| 69 ~RequestPinView() override; | |
| 70 | |
| 71 // views::TextfieldController | |
| 72 void ContentsChanged(views::Textfield* sender, | |
| 73 const base::string16& new_contents) override; | |
| 74 | |
| 75 // views::DialogDelegateView | |
| 76 bool Cancel() override; | |
| 77 bool Accept() override; | |
| 78 base::string16 GetWindowTitle() const override; | |
| 79 ui::ModalType GetModalType() const override; | |
|
emaxx
2016/09/19 14:01:44
nit: #include "ui/base/ui_base_types.h"
igorcov
2016/09/19 15:42:36
Done.
| |
| 80 views::View* GetInitiallyFocusedView() override; | |
| 81 bool IsDialogButtonEnabled(ui::DialogButton button) const override; | |
| 82 | |
| 83 // Returns whether the view is locked while waiting the extension to process | |
| 84 // the user input data. | |
| 85 bool IsLocked(); | |
| 86 | |
| 87 // Set the new callback to be used when user will provide the input. The old | |
| 88 // callback must be used and reset to null at this point. | |
| 89 void SetCallback(const RequestPinCallback& callback); | |
| 90 | |
| 91 // |code_type| - specifies whether the user is asked to enter PIN or PUK. If | |
| 92 // UNCHANGED value is provided, the dialog displays the same value that | |
| 93 // was last set. | |
| 94 // |error_type| - the error template to be displayed in red in the dialog. If | |
| 95 // NONE, no error is displayed. | |
| 96 // |attempts_left| - included in the view as the number of attepts user can | |
| 97 // have to enter correct code. | |
| 98 // |accept_input| - specifies whether the textfield is enabled. If disabled | |
| 99 // the user is unable to provide input. | |
| 100 void SetDialogParameters(RequestPinView::RequestPinCodeType code_type, | |
|
emaxx
2016/09/19 14:01:44
nit: "RequestPinView::" is not needed here or anyw
igorcov
2016/09/19 15:42:36
Done.
| |
| 101 RequestPinView::RequestPinErrorType error_type, | |
| 102 int attempts_left, | |
| 103 bool accept_input); | |
| 104 | |
| 105 // Set the name of extension that is using this view. The name is included in | |
| 106 // the header text displayed by the view. | |
| 107 void SetExtensionName(const std::string& extension_name); | |
| 108 | |
| 109 views::Textfield* textfield_for_testing() { return textfield_; } | |
|
emaxx
2016/09/19 14:01:44
nit: #include "ui/views/controls/textfield/textfie
igorcov
2016/09/19 15:42:36
Done.
| |
| 110 views::Label* error_label_for_testing() { return error_label_; } | |
|
emaxx
2016/09/19 14:01:44
nit: #include "ui/views/controls/label.h"
igorcov
2016/09/19 15:42:36
Done.
| |
| 111 | |
| 112 private: | |
| 113 // This initializes the view, with all the UI components. | |
| 114 void Init(); | |
| 115 void SetAcceptInput(bool accept_input); | |
| 116 void SetErrorMessage(RequestPinView::RequestPinErrorType error_type, | |
| 117 int attempts_left); | |
| 118 // Updates the header text |header_label_| based on values from | |
| 119 // |window_title_| and |code_type_|. | |
| 120 void UpdateHeaderText(); | |
| 121 | |
| 122 // Used to send the input when the view is not locked. If user closes the | |
| 123 // view, the provided input is empty. The |callback_| must be reset to null | |
| 124 // after being used, allowing to check that it was used when a new callback is | |
| 125 // set. | |
| 126 RequestPinCallback callback_; | |
| 127 | |
| 128 // Owned by the caller. | |
| 129 Delegate* delegate_; | |
| 130 | |
| 131 base::string16 window_title_; | |
| 132 views::Label* header_label_ = nullptr; | |
| 133 base::string16 code_type_; | |
| 134 views::Textfield* textfield_ = nullptr; | |
| 135 views::Label* error_label_ = nullptr; | |
| 136 | |
| 137 base::WeakPtrFactory<RequestPinView> weak_ptr_factory_; | |
| 138 | |
| 139 DISALLOW_COPY_AND_ASSIGN(RequestPinView); | |
| 140 }; | |
| 141 | |
| 142 } // namespace chromeos | |
| 143 | |
| 144 #endif // CHROME_BROWSER_CHROMEOS_UI_REQUEST_PIN_VIEW_H_ | |
| OLD | NEW |