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 <map> | |
9 #include <string> | |
10 #include <unordered_map> | |
11 | |
12 #include "base/callback.h" | |
13 #include "base/memory/weak_ptr.h" | |
14 #include "base/strings/string16.h" | |
15 #include "chrome/browser/chromeos/ui/request_pin_view.h" | |
16 #include "ui/views/widget/widget.h" | |
17 | |
18 namespace chromeos { | |
19 | |
20 // Manages the state of the dialog that requests the PIN from user. Used by the | |
21 // extensions that need to request the PIN. Implemented as requirement for | |
22 // crbug.com/612886 | |
23 class PinDialogManager : RequestPinView::Delegate { | |
24 public: | |
25 typedef std::pair<std::string, int> ExtensionNameRequestIdPair; | |
emaxx
2016/09/19 14:01:43
nit: Move this type definition into the private se
emaxx
2016/09/19 14:01:43
nit: #include <utility>
igorcov
2016/09/19 18:19:20
Done.
igorcov
2016/09/19 18:19:20
Done.
| |
26 | |
27 enum RequestPinResponse { | |
28 SUCCESS, | |
29 INVALID_ID, | |
30 OTHER_FLOW_IN_PROGRESS, | |
31 DIALOG_DISPLAYED_ALREADY | |
32 }; | |
33 | |
34 PinDialogManager(); | |
35 ~PinDialogManager(); | |
36 | |
37 // Stores internally the |signRequestId| along with current timestamp. Also | |
38 // cleans up the storage from expired IDs. In unlikely case that the ID | |
39 // exists in the storage, returns false. Otherwise returns true. | |
40 bool AddSignRequestId(const std::string& extension_id, int sign_request_id); | |
41 | |
42 // Creates a new RequestPinView object and displays it in a dialog or reuses | |
43 // the old dialog if active one exists just updating the parameters. | |
44 // |extension_id| - the ID of the extension requesting the dialog. | |
45 // |extension_name| - the name of the extension requesting the dialog. | |
46 // |sign_request_id| - the ID given by Chrome when the extension was asked to | |
47 // sign the data. It should be a valid, not expired ID at the time the | |
48 // extension is requesting PIN the first time. | |
49 // |code_type| - the type of input requested: either "PIN" or "PUK". | |
50 // |error_type| - the error template to be displayed inside the dialog. If | |
51 // NONE, no error is displayed. | |
52 // |attempts_left| - the number of attempts the user has to try the code. It | |
53 // is informational only, and enforced on Chrome side only in case it's | |
54 // zero. In that case the textfield is disabled and the user can't provide | |
55 // any input to extension. If -1 the textfield from the dialog is enabled | |
56 // but no information about the attepts left is not given to the user. | |
57 // |callback| - used to notify about the user input in the text_field from the | |
58 // dialog. | |
59 // Returns SUCCESS if the dialog is displayed and extension owns it. Otherwise | |
60 // the specific error is returned. | |
61 RequestPinResponse ShowPinDialog( | |
62 const std::string& extension_id, | |
63 const std::string& extension_name, | |
64 int sign_request_id, | |
65 RequestPinView::RequestPinCodeType code_type, | |
66 RequestPinView::RequestPinErrorType error_type, | |
67 int attempts_left, | |
68 const RequestPinView::RequestPinCallback& callback); | |
69 | |
70 // The user provided input to dialog. | |
71 void OnPinDialogInput(); | |
72 | |
73 // chromeos::CloseViewDelegate | |
74 void OnPinDialogClosed() override; | |
75 | |
76 // Updates the existing dialog with new error message. Uses |callback| with | |
77 // empty string when user closes the dialog. Returns whether the provided | |
78 // |extension_id| matches the extension owning the active dialog. | |
79 bool UpdatePinDialog(const std::string& extension_id, | |
80 RequestPinView::RequestPinErrorType error_type, | |
81 bool accept_input, | |
82 const RequestPinView::RequestPinCallback& callback); | |
83 | |
84 // Returns whether the last PIN dialog from this extension was closed by the | |
85 // user. | |
86 bool LastPinDialogClosed(const std::string& extension_id); | |
emaxx
2016/09/19 14:01:43
nit: Make the method const.
igorcov
2016/09/19 18:19:20
Done.
| |
87 | |
88 // Called when extension calls the stopPinRequest method. The active dialog is | |
89 // closed if the |extension_id| matches the |active_dialog_extension_id_|. | |
90 // Returns whether the dialog was closed. | |
91 bool CloseDialog(const std::string& extension_id); | |
92 | |
93 // Resets the manager data related to the extension. | |
94 void ExtensionUnloaded(const std::string& extension_id); | |
95 | |
96 RequestPinView* active_view_for_testing() { return active_pin_dialog_; } | |
97 views::Widget* active_window_for_testing() { return active_window_; } | |
98 | |
99 private: | |
100 // State about the last response from user to the requestPin from extension. | |
emaxx
2016/09/19 14:01:43
nit: Please use more specific words here than just
igorcov
2016/09/19 18:19:19
Done.
| |
101 std::unordered_map<std::string, bool> last_response_closed_; | |
102 | |
103 // The map with extension_id and sign request id issued by Chrome as key while | |
104 // the time when the id was generated is the value. | |
105 std::map<ExtensionNameRequestIdPair, base::Time> sign_request_times_; | |
emaxx
2016/09/19 14:01:43
nit: #include "base/time/time.h"
| |
106 | |
107 // There can be only one active dialog to request PIN from this extension. | |
emaxx
2016/09/19 14:01:43
nit: The current comment may be understood as ther
igorcov
2016/09/19 18:19:20
Done.
| |
108 // Owned by |active_window_|. | |
109 chromeos::RequestPinView* active_pin_dialog_ = nullptr; | |
emaxx
2016/09/19 14:01:43
nit: "chromeos::" is not required here.
igorcov
2016/09/19 18:19:20
Done.
| |
110 std::string active_dialog_extension_id_; | |
111 views::Widget* active_window_ = nullptr; | |
112 | |
113 base::WeakPtrFactory<PinDialogManager> weak_factory_; | |
114 }; | |
115 | |
116 } // namespace chromeos | |
117 | |
118 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_ | |
OLD | NEW |