Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: chrome/browser/chromeos/ui/request_pin_view.h

Issue 2094333002: Implementation for chrome.certificateProvider.requestPin/stopPinRequest (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed attemptsLeft with no error case Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 enum RequestPinCodeType { PIN, PUK, UNCHANGED };
29
30 enum RequestPinErrorType {
31 NONE,
32 INVALID_PIN,
33 INVALID_PUK,
34 MAX_ATTEMPTS_EXCEEDED,
35 UNKNOWN_ERROR
36 };
37
38 class CloseViewDelegate {
39 public:
40 // Notification when user closes the PIN dialog.
41 virtual void OnPinDialogClosed() = 0;
42 };
stevenjb 2016/09/08 16:29:31 This should be either defined within RequestPinVie
igorcov 2016/09/09 15:53:43 Good point. Fixed.
43
44 // A dialog box for requesting PIN code. Instances of this class are managed by
45 // PinDialogManager.
46 class RequestPinView : public views::DialogDelegateView,
47 public views::TextfieldController {
48 public:
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.
64 RequestPinView(const std::string& extension_name,
65 RequestPinCodeType code_type,
66 const int attempts_left,
67 const RequestPinCallback& callback,
68 CloseViewDelegate* 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;
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 should be 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(RequestPinCodeType code_type,
101 RequestPinErrorType error_type,
102 const int attempts_left,
103 const 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_; }
110 views::Label* error_label_for_testing() { return error_label_; }
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(RequestPinErrorType error_type, int attempts_left);
117 // Updates the header text |header_label_| based on values from
118 // |window_title_| and |code_type_|.
119 void UpdateHeaderText();
120
121 // Used to send the input when the view is not locked. If user closes the
122 // view, the provided input is empty.
123 RequestPinCallback callback_;
124
125 // Owned by the caller.
126 CloseViewDelegate* delegate_;
stevenjb 2016/09/08 16:29:31 nit: blank line separating commented member from o
igorcov 2016/09/09 15:53:43 Done.
127 base::string16 window_title_;
128 views::Label* header_label_ = nullptr;
129 base::string16 code_type_;
130 views::Textfield* textfield_ = nullptr;
131 views::Label* error_label_ = nullptr;
132
133 base::WeakPtrFactory<RequestPinView> weak_ptr_factory_;
134
135 DISALLOW_COPY_AND_ASSIGN(RequestPinView);
136 };
137
138 } // namespace chromeos
139
140 #endif // CHROME_BROWSER_CHROMEOS_UI_REQUEST_PIN_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698