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

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: Comment fixed Created 4 years, 4 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 (c) 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 // A dialog box for requesting PIN code.
39 class RequestPinView : public views::DialogDelegateView,
40 public views::TextfieldController {
41 public:
42 // Used to send the PIN/PUK entered by the user in the textfield to the
43 // extension that asked for the code.
44 using RequestPinCallback = base::Callback<void(const base::string16&)>;
45
46 // Creates the view, having in the header the |extension_name|, asking for
47 // PIN or PUK depending on |code_type|. UNCHANGED value in |code_type| is not
48 // accepted here. The |attempts_left| specifies the number of attempts user
49 // has to try the code. When zero the textfield is disabled and user cannot
50 // provide any input. When null, the user is allowed to provide the input and
51 // no information about the attepts left is displayed in the view. The
52 // |callback| is used to send the value of the PIN/PUK the user entered.
stevenjb 2016/08/11 01:58:55 Also here, separate the input parameter descriptio
igorcov1 2016/08/11 16:15:23 Done.
53 RequestPinView(const std::string& extension_name,
54 RequestPinCodeType code_type,
55 std::unique_ptr<int> attempts_left,
56 const RequestPinCallback& callback);
57 ~RequestPinView() override;
58
59 // views::TextfieldController
60 void ContentsChanged(views::Textfield* sender,
61 const base::string16& new_contents) override;
62
63 // views::DialogDelegateView
64 bool Cancel() override;
65 bool Accept() override;
66 base::string16 GetWindowTitle() const override;
67 ui::ModalType GetModalType() const override;
68 views::View* GetInitiallyFocusedView() override;
69 bool IsDialogButtonEnabled(ui::DialogButton button) const override;
70
71 // Returns whether the view is locked while waiting the extension to process
72 // the user input data.
73 bool IsLocked();
74
75 // Set the new callback to be used when user will provide the input. The old
76 // callback should be null or disposable at this point.
77 void SetCallback(const RequestPinCallback& callback);
78
79 // The |code_type| specifies whether the user is asked to enter PIN or PUK.
80 // If UNCHANGED value is provided, the dialog will display the same value that
81 // was last set. |error_type| is the error template to be displayed in red in
82 // the dialog if not NONE. |attempts_left| is included in the view as the
83 // number of attepts user can have to enter correct code. |accept_input|
84 // specifies whether the textfield is enabled. If disabled the user is unable
85 // to provide input.
stevenjb 2016/08/11 01:58:55 Here too.
igorcov1 2016/08/11 16:15:23 Done.
86 void SetDialogParameters(RequestPinCodeType code_type,
87 RequestPinErrorType error_type,
88 std::unique_ptr<int> attempts_left,
89 const bool accept_input);
90
91 // Set the name of extension that is using this view. The name is included in
92 // the header text displayed by the view.
93 void SetExtensionName(const std::string& extension_name);
94
95 views::Textfield* textfield_for_testing() { return textfield_; }
96 views::Label* error_label_for_testing() { return error_label_; }
97
98 private:
99 // This initializes the view, with all the UI components.
100 void Init();
101 void SetAcceptInput(bool accept_input);
102 void SetErrorMessage(RequestPinErrorType error_type,
103 std::unique_ptr<int> attempts_left);
104 // Updates the header text (header_label_) based on values from window_title_
105 // and code_type_.
106 void UpdateHeaderText();
107
108 RequestPinCallback callback_;
109 base::string16 window_title_;
110 views::Label* header_label_ = nullptr;
111 base::string16 code_type_;
112 views::Textfield* textfield_ = nullptr;
113 views::Label* error_label_ = nullptr;
114
115 // Flag to know when user submitted input and the view is locked, waiting for
116 // changes from outside.
117 bool locked_ = false;
118
119 base::WeakPtrFactory<RequestPinView> weak_ptr_factory_;
120
121 DISALLOW_COPY_AND_ASSIGN(RequestPinView);
122 };
123
124 } // namespace chromeos
125
126 #endif // CHROME_BROWSER_CHROMEOS_UI_REQUEST_PIN_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698