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_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ | |
6 #define CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ | |
7 | |
8 #include <string> | |
9 | |
10 #include "base/callback.h" | |
11 #include "base/memory/weak_ptr.h" | |
12 #include "chrome/browser/chromeos/ui/request_pin_view.h" | |
13 | |
14 namespace chromeos { | |
15 | |
16 enum RequestPinResponse { | |
emaxx
2016/09/06 15:02:10
It's better to either make this "enum class" or mo
igorcov
2016/09/07 09:12:28
Done.
| |
17 SUCCESS, | |
18 INVALID_ID, | |
19 OTHER_FLOW_IN_PROGRESS, | |
20 DIALOG_DISPLAYED_ALREADY | |
21 }; | |
22 | |
23 // Manages the state of the dialog that requests the PIN from user. | |
stevenjb
2016/08/11 18:12:02
We should probably also describe the feature a bit
igorcov
2016/09/06 13:22:02
Done.
| |
24 class PinDialogManager { | |
25 public: | |
26 PinDialogManager(); | |
27 virtual ~PinDialogManager(); | |
emaxx
2016/09/06 15:02:10
There are no child classes of this class currently
igorcov
2016/09/07 09:12:28
Done.
| |
28 | |
29 // The user provided input to dialog. |closed| tells whether the dialog was | |
30 // closed by the user without providing any input. | |
31 void OnPinDialogInput(const std::string& extension_id, const bool closed); | |
emaxx
2016/09/06 15:02:10
nit: regarding "const bool", "const long long" etc
igorcov
2016/09/07 09:12:28
Done.
| |
32 | |
33 // Called by the view when user closes the PIN dialog while the last input is | |
34 // still processing at extension side. |value| is not used, but checked that | |
35 // it's empty. | |
36 void OnFlowInterrupted(const base::string16& value); | |
emaxx
2016/09/06 15:02:10
nit: #include "base/strings/string16.h"
emaxx
2016/09/06 15:02:10
Would it be easy to pass the extension_id here too
igorcov
2016/09/07 09:12:28
I've cleaned the extension_id from functions that
igorcov
2016/09/07 09:12:29
Done.
| |
37 | |
38 // Returns whether the last PIN dialog from this extension was closed by the | |
39 // user. | |
40 bool LastPinDialogClosed(const std::string& extension_id); | |
41 | |
42 // Updates the existing dialog with new error message. Uses |callback| with | |
43 // empty string when user closes the dialog. Returns whether the provided | |
44 // |extension_id| matches the extension owning the active dialog. | |
45 bool UpdatePinDialog(const std::string& extension_id, | |
46 RequestPinErrorType error_type, | |
47 const bool accept_input, | |
48 const RequestPinView::RequestPinCallback& callback); | |
49 | |
50 // Creates a new RequestPinView object and displays it in a dialog or reuses | |
emaxx
2016/09/06 15:02:10
nit: Maybe it would make sense to reorder the meth
igorcov
2016/09/07 09:12:29
Done.
| |
51 // the old dialog if active one exists just updating the parameters. | |
52 // |extension_id| - the ID of the extension requesting the dialog. | |
53 // |extension_name| - the name of the extension requesting the dialog. | |
54 // |sign_request_id| - the ID given by Chrome when the extension was asked to | |
55 // sign the data. It should be a valid, not expired ID at the time the | |
56 // extension is requesting PIN the first time. | |
57 // |code_type| - the type of input requested: either "PIN" or "PUK". | |
58 // |error_type| - the error template to be displayed inside the dialog. If | |
59 // NONE, no error is displayed. | |
60 // |attempts_left| - the number of attempts the user has to try the code. It | |
61 // is informational only, and enforced on Chrome side only in case it's | |
62 // zero. In that case the textfield is disabled and the user can't provide | |
63 // any input to extension. If nullptr the textfield from the dialog is | |
64 // enabled but no information about the attepts left is not given to the | |
65 // user. | |
66 // |callback| - used to notify about the user input in the text_field from the | |
67 // dialog. | |
68 // Returns SUCCESS if the dialog is displayed and extension owns it. Otherwise | |
69 // the specific error is returned. | |
70 RequestPinResponse ShowPinDialog( | |
71 const std::string& extension_id, | |
72 const std::string& extension_name, | |
73 const long long sign_request_id, | |
74 RequestPinCodeType code_type, | |
75 RequestPinErrorType error_type, | |
76 std::unique_ptr<int> attempts_left, | |
stevenjb
2016/08/11 18:12:02
Digging through the code, I don't see any reason f
igorcov
2016/09/06 13:22:02
Yes, the possibility for the parameter to be missi
| |
77 const RequestPinView::RequestPinCallback& callback); | |
78 | |
79 // Called when extension calls the stopPinRequest method. The active dialog is | |
80 // closed if the |extension_id| matches the |active_dialog_extension_id_|. | |
81 // Returns whether the dialog was closed. | |
82 bool CloseDialog(const std::string& extension_id); | |
83 | |
84 // Stores internally the |signRequestId| along with current timestamp. Also | |
85 // cleans up the storage from expired IDs. In unlikely case that the ID | |
86 // exists in the storage, returns false. Otherwise returns true. | |
87 bool AddSignRequestId(const uint64_t signRequestId); | |
88 | |
89 // Resets the manager data related to the extension. | |
90 void ExtensionUnloaded(const std::string& extension_id); | |
91 | |
92 RequestPinView* active_view_for_testing() { return active_pin_dialog_; } | |
93 views::Widget* active_window_for_testing() { return active_window_; } | |
emaxx
2016/09/06 15:02:10
nit: #include "ui/views/widget/widget.h".
igorcov
2016/09/07 09:12:28
Done.
| |
94 | |
95 private: | |
96 // Cleans the map of sign request ids, removing the ones that have expired. | |
97 void RemoveExpiredSignRequests(timeval* tv); | |
98 | |
99 // State about the last response from user to the requestPin from extension. | |
100 std::map<std::string, bool> last_response_closed_; | |
emaxx
2016/09/06 15:02:10
nit: #include <map>
(BTW, maybe use std::unordered
igorcov
2016/09/07 09:12:28
Done.
| |
101 | |
102 // The map with sign request ids issued by Chrome as key and the time when the | |
103 // id was generated as value. | |
104 std::map<uint64_t, uint64_t> sign_request_times_; | |
emaxx
2016/09/06 15:02:10
Is there a reason to use uint64_t for storing the
igorcov
2016/09/07 09:12:28
I've used timeval as that was one example I found
| |
105 | |
106 // There can be only one active dialog to request PIN from this extension. | |
107 // Owned by |active_window_|. | |
108 chromeos::RequestPinView* active_pin_dialog_ = nullptr; | |
109 std::string active_dialog_extension_id_; | |
110 views::Widget* active_window_ = nullptr; | |
111 | |
112 base::WeakPtrFactory<PinDialogManager> weak_factory_; | |
emaxx
2016/09/06 15:02:10
nit: #include "base/memory/weak_ptr.h".
igorcov
2016/09/07 09:12:28
Done.
| |
113 }; | |
114 | |
115 } // namespace chromeos | |
116 | |
117 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ | |
OLD | NEW |