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

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: Merged the sources Created 4 years 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 <map>
9 #include <string>
10 #include <unordered_map>
11 #include <utility>
12
13 #include "base/callback.h"
14 #include "base/memory/weak_ptr.h"
15 #include "base/strings/string16.h"
16 #include "base/time/time.h"
17 #include "chrome/browser/chromeos/ui/request_pin_view.h"
18 #include "ui/views/widget/widget.h"
19
20 namespace chromeos {
21
22 // Manages the state of the dialog that requests the PIN from user. Used by the
23 // extensions that need to request the PIN. Implemented as requirement for
24 // crbug.com/612886
25 class PinDialogManager : RequestPinView::Delegate {
26 public:
27 enum RequestPinResponse {
28 SUCCESS,
29 INVALID_ID,
30 OTHER_FLOW_IN_PROGRESS,
31 DIALOG_DISPLAYED_ALREADY
32 };
33
34 enum StopPinRequestResponse { STOPPED, NO_ACTIVE_DIALOG, NO_USER_INPUT };
35
36 PinDialogManager();
37 ~PinDialogManager();
38
39 // Stores internally the |signRequestId| along with current timestamp.
40 void 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 // chromeos::RequestPinView::Delegate overrides.
71 void OnPinDialogInput() override;
72 void OnPinDialogClosed() override;
73
74 // Updates the existing dialog with new error message. Uses |callback| with
75 // empty string when user closes the dialog. Returns whether the provided
76 // |extension_id| matches the extension owning the active dialog.
77 PinDialogManager::StopPinRequestResponse UpdatePinDialog(
78 const std::string& extension_id,
79 RequestPinView::RequestPinErrorType error_type,
80 bool accept_input,
81 const RequestPinView::RequestPinCallback& callback);
82
83 // Returns whether the last PIN dialog from this extension was closed by the
84 // user.
85 bool LastPinDialogClosed(const std::string& extension_id);
86
87 // Called when extension calls the stopPinRequest method. The active dialog is
88 // closed if the |extension_id| matches the |active_dialog_extension_id_|.
89 // Returns whether the dialog was closed.
90 bool CloseDialog(const std::string& extension_id);
91
92 // Resets the manager data related to the extension.
93 void ExtensionUnloaded(const std::string& extension_id);
94
95 RequestPinView* active_view_for_testing() { return active_pin_dialog_; }
96 views::Widget* active_window_for_testing() { return active_window_; }
97
98 private:
99 using ExtensionNameRequestIdPair = std::pair<std::string, int>;
100
101 // Tells whether user closed the last request PIN dialog issued by an
102 // extension. The extension_id is the key and value is true if user closed the
103 // dialog. Used to determine if the limit of dialogs rejected by the user has
104 // been exceeded.
105 std::unordered_map<std::string, bool> last_response_closed_;
106
107 // The map with extension_id and sign request id issued by Chrome as key while
108 // the time when the id was generated is the value.
109 std::map<ExtensionNameRequestIdPair, base::Time> sign_request_times_;
110
111 // There can be only one active dialog to request the PIN at some point in
112 // time. Owned by |active_window_|.
113 RequestPinView* active_pin_dialog_ = nullptr;
114 std::string active_dialog_extension_id_;
115 views::Widget* active_window_ = nullptr;
116
117 base::WeakPtrFactory<PinDialogManager> weak_factory_;
118 };
119
120 } // namespace chromeos
121
122 #endif // CHROME_BROWSER_CHROMEOS_CERTIFICATE_PROVIDER_PIN_DIALOG_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698