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

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

Powered by Google App Engine
This is Rietveld 408576698