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

Side by Side Diff: chrome/browser/chromeos/certificate_provider/pin_dialog_manager.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 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 {
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. Used by the
24 // extensions that need to request the PIN. Implemented as requirement for
25 // crbug.com/612886
26 class PinDialogManager {
27 public:
28 PinDialogManager();
29 virtual ~PinDialogManager();
30
31 // The user provided input to dialog. |closed| tells whether the dialog was
32 // closed by the user without providing any input.
33 void OnPinDialogInput(const std::string& extension_id, const bool closed);
34
35 // Called by the view when PIN dialog is active while the last input is still
36 // processing at extension side. |dialog_closed| specifies whether that dialog
37 // was closed by the user.
38 void OnFlowInterrupted(bool dialog_closed);
39
40 // Returns whether the last PIN dialog from this extension was closed by the
41 // user.
42 bool LastPinDialogClosed(const std::string& extension_id);
43
44 // Updates the existing dialog with new error message. Uses |callback| with
45 // empty string when user closes the dialog. Returns whether the provided
46 // |extension_id| matches the extension owning the active dialog.
47 bool UpdatePinDialog(const std::string& extension_id,
48 RequestPinErrorType error_type,
49 const bool accept_input,
50 const RequestPinView::RequestPinCallback& callback);
51
52 // Creates a new RequestPinView object and displays it in a dialog or reuses
53 // the old dialog if active one exists just updating the parameters.
54 // |extension_id| - the ID of the extension requesting the dialog.
55 // |extension_name| - the name of the extension requesting the dialog.
56 // |sign_request_id| - the ID given by Chrome when the extension was asked to
57 // sign the data. It should be a valid, not expired ID at the time the
58 // extension is requesting PIN the first time.
59 // |code_type| - the type of input requested: either "PIN" or "PUK".
60 // |error_type| - the error template to be displayed inside the dialog. If
61 // NONE, no error is displayed.
62 // |attempts_left| - the number of attempts the user has to try the code. It
63 // is informational only, and enforced on Chrome side only in case it's
64 // zero. In that case the textfield is disabled and the user can't provide
65 // any input to extension. If -1 the textfield from the dialog is enabled
66 // but no information about the attepts left is not given to the user.
67 // |callback| - used to notify about the user input in the text_field from the
68 // dialog.
69 // Returns SUCCESS if the dialog is displayed and extension owns it. Otherwise
70 // the specific error is returned.
71 RequestPinResponse ShowPinDialog(
72 const std::string& extension_id,
73 const std::string& extension_name,
74 const long long sign_request_id,
75 RequestPinCodeType code_type,
76 RequestPinErrorType error_type,
77 const int attempts_left,
78 const RequestPinView::RequestPinCallback& callback);
79
80 // Called when extension calls the stopPinRequest method. The active dialog is
81 // closed if the |extension_id| matches the |active_dialog_extension_id_|.
82 // Returns whether the dialog was closed.
83 bool CloseDialog(const std::string& extension_id);
84
85 // Stores internally the |signRequestId| along with current timestamp. Also
86 // cleans up the storage from expired IDs. In unlikely case that the ID
87 // exists in the storage, returns false. Otherwise returns true.
88 bool AddSignRequestId(const uint64_t signRequestId);
89
90 // Resets the manager data related to the extension.
91 void ExtensionUnloaded(const std::string& extension_id);
92
93 RequestPinView* active_view_for_testing() { return active_pin_dialog_; }
94 views::Widget* active_window_for_testing() { return active_window_; }
95
96 private:
97 // Cleans the map of sign request ids, removing the ones that have expired.
98 void RemoveExpiredSignRequests(timeval* tv);
99
100 // State about the last response from user to the requestPin from extension.
101 std::map<std::string, bool> last_response_closed_;
102
103 // The map with sign request ids issued by Chrome as key and the time when the
104 // id was generated as value.
105 std::map<uint64_t, uint64_t> sign_request_times_;
106
107 // There can be only one active dialog to request PIN from this extension.
108 // Owned by |active_window_|.
109 chromeos::RequestPinView* active_pin_dialog_ = nullptr;
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698