File: sheet_view_factory.cc

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (409 lines) | stat: -rw-r--r-- 17,913 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/webauthn/sheet_view_factory.h"

#include <memory>
#include <string>
#include <utility>

#include "base/check.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "chrome/browser/ui/autofill/payments/webauthn_dialog_model.h"
#include "chrome/browser/ui/views/webauthn/authenticator_bio_enrollment_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_client_pin_entry_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_create_user_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_gpm_arbitrary_pin_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_gpm_pin_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_hybrid_and_security_key_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_multi_source_picker_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_priority_mechanism_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_request_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/authenticator_select_account_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/combined_selector_sheet_view.h"
#include "chrome/browser/ui/views/webauthn/hover_list_view.h"
#include "chrome/browser/ui/views/webauthn/passkey_detail_view.h"
#include "chrome/browser/ui/webauthn/sheet_models.h"
#include "chrome/browser/ui/webauthn/transport_hover_list_model.h"
#include "chrome/browser/webauthn/authenticator_request_dialog_model.h"
#include "device/fido/fido_constants.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/style/typography.h"

#if BUILDFLAG(IS_MAC)
#include "chrome/browser/ui/views/webauthn/authenticator_touch_id_view.h"
#endif  // BUILDFLAG(IS_MAC)

namespace {

// Number of digits for the GPM Pin.
constexpr int kPinDigitCount = 6;

// A placeholder sheet to show in place of unimplemented sheets.
class PlaceholderSheetModel : public AuthenticatorSheetModelBase {
 public:
  using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase;

 private:
  // AuthenticatorSheetModelBase:
  std::u16string GetStepTitle() const override { return std::u16string(); }
  std::u16string GetStepDescription() const override {
    return std::u16string();
  }
};

// Represents a sheet in the Web Authentication request dialog that allows the
// user to pick the mechanism (i.e. USB / Windows API / phone / etc) to use.
class AuthenticatorMechanismSelectorSheetView
    : public AuthenticatorRequestSheetView {
 public:
  explicit AuthenticatorMechanismSelectorSheetView(
      std::unique_ptr<AuthenticatorMechanismSelectorSheetModel> model)
      : AuthenticatorRequestSheetView(std::move(model)) {}

  AuthenticatorMechanismSelectorSheetView(
      const AuthenticatorMechanismSelectorSheetView&) = delete;
  AuthenticatorMechanismSelectorSheetView& operator=(
      const AuthenticatorMechanismSelectorSheetView&) = delete;

 private:
  // AuthenticatorRequestSheetView:
  std::pair<std::unique_ptr<views::View>,
            AuthenticatorRequestSheetView::AutoFocus>
  BuildStepSpecificContent() override {
    auto* model = static_cast<AuthenticatorMechanismSelectorSheetModel*>(
        AuthenticatorRequestSheetView::model());
    return std::make_pair(
        std::make_unique<HoverListView>(
            std::make_unique<TransportHoverListModel>(model->dialog_model())),
        AutoFocus::kYes);
  }
};

class AuthenticatorCreatePasskeySheetView
    : public AuthenticatorRequestSheetView {
 public:
  explicit AuthenticatorCreatePasskeySheetView(
      std::unique_ptr<AuthenticatorCreatePasskeySheetModel> model)
      : AuthenticatorRequestSheetView(std::move(model)) {}

  AuthenticatorCreatePasskeySheetView(
      const AuthenticatorCreatePasskeySheetView&) = delete;
  AuthenticatorCreatePasskeySheetView& operator=(
      const AuthenticatorCreatePasskeySheetView&) = delete;

 private:
  // AuthenticatorRequestSheetView:
  std::pair<std::unique_ptr<views::View>,
            AuthenticatorRequestSheetView::AutoFocus>
  BuildStepSpecificContent() override {
    auto container = std::make_unique<views::BoxLayoutView>();
    container->SetOrientation(views::BoxLayout::Orientation::kVertical);
    container->SetCrossAxisAlignment(
        views::BoxLayout::CrossAxisAlignment::kStretch);
    container->SetBetweenChildSpacing(12);
    container->AddChildView(std::make_unique<PasskeyDetailView>(
        static_cast<AuthenticatorCreatePasskeySheetModel*>(model())
            ->dialog_model()
            ->user_entity));
    auto* label = container->AddChildView(std::make_unique<views::Label>(
        static_cast<AuthenticatorCreatePasskeySheetModel*>(model())
            ->passkey_storage_description(),
        views::style::CONTEXT_DIALOG_BODY_TEXT));
    label->SetMultiLine(true);
    label->SetHorizontalAlignment(gfx::HorizontalAlignment::ALIGN_LEFT);

    return std::make_pair(std::move(container), AutoFocus::kNo);
  }
};

}  // namespace

std::unique_ptr<AuthenticatorRequestSheetView> CreateSheetViewForCurrentStepOf(
    AuthenticatorRequestDialogModel* dialog_model) {
  using Step = AuthenticatorRequestDialogModel::Step;

  std::unique_ptr<AuthenticatorRequestSheetView> sheet_view;
  switch (dialog_model->step()) {
    case Step::kMechanismSelection:
      if (dialog_model->ui_presentation == UIPresentation::kModalImmediate) {
        CHECK(dialog_model->request_type ==
              device::FidoRequestType::kGetAssertion);
        sheet_view = std::make_unique<CombinedSelectorSheetView>(
            std::make_unique<CombinedSelectorSheetModel>(dialog_model));
      } else if (dialog_model->request_type ==
                 device::FidoRequestType::kGetAssertion) {
        sheet_view = std::make_unique<AuthenticatorMultiSourcePickerSheetView>(
            std::make_unique<AuthenticatorMultiSourcePickerSheetModel>(
                dialog_model));
      } else {
        sheet_view = std::make_unique<AuthenticatorMechanismSelectorSheetView>(
            std::make_unique<AuthenticatorMechanismSelectorSheetModel>(
                dialog_model));
      }
      break;
    case Step::kUsbInsertAndActivate:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorInsertAndActivateUsbSheetModel>(
              dialog_model));
      break;
    case Step::kErrorNoAvailableTransports:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorNoAvailableTransportsErrorModel>(
              dialog_model));
      break;
    case Step::kErrorNoPasskeys:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorNoPasskeysErrorModel>(dialog_model));
      break;
    case Step::kTimedOut:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorTimeoutErrorModel>(dialog_model));
      break;
    case Step::kKeyNotRegistered:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorNotRegisteredErrorModel>(dialog_model));
      break;
    case Step::kKeyAlreadyRegistered:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorAlreadyRegisteredErrorModel>(
              dialog_model));
      break;
    case Step::kMissingCapability:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          AuthenticatorGenericErrorSheetModel::ForMissingCapability(
              dialog_model));
      break;
    case Step::kStorageFull:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          AuthenticatorGenericErrorSheetModel::ForStorageFull(dialog_model));
      break;
    case Step::kErrorInternalUnrecognized:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorInternalUnrecognizedErrorSheetModel>(
              dialog_model));
      break;
    case Step::kErrorWindowsHelloNotEnabled:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          AuthenticatorGenericErrorSheetModel::ForWindowsHelloNotEnabled(
              dialog_model));
      break;
    case Step::kBlePowerOnAutomatic:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorBlePowerOnAutomaticSheetModel>(
              dialog_model));
      break;
    case Step::kBlePowerOnManual:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorBlePowerOnManualSheetModel>(
              dialog_model));
      break;
    case Step::kBlePermissionMac:
#if BUILDFLAG(IS_MAC)
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorBlePermissionMacSheetModel>(
              dialog_model));
      break;
#else
      NOTREACHED();
#endif
    case Step::kOffTheRecordInterstitial:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorOffTheRecordInterstitialSheetModel>(
              dialog_model));
      break;
    case Step::kCableActivate:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorPaaskSheetModel>(dialog_model));
      break;
    case Step::kCableV2QRCode:
      sheet_view = std::make_unique<AuthenticatorHybridAndSecurityKeySheetView>(
          std::make_unique<AuthenticatorHybridAndSecurityKeySheetModel>(
              dialog_model));
      break;
    case Step::kCableV2Connecting:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorConnectingSheetModel>(dialog_model));
      break;
    case Step::kCableV2Connected:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorConnectedSheetModel>(dialog_model));
      break;
    case Step::kCableV2Error:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorCableErrorSheetModel>(dialog_model));
      break;
    case Step::kClientPinChange:
      sheet_view = std::make_unique<AuthenticatorClientPinEntrySheetView>(
          std::make_unique<AuthenticatorClientPinEntrySheetModel>(
              dialog_model,
              AuthenticatorClientPinEntrySheetModel::Mode::kPinChange,
              dialog_model->pin_error));
      break;
    case Step::kClientPinEntry:
      sheet_view = std::make_unique<AuthenticatorClientPinEntrySheetView>(
          std::make_unique<AuthenticatorClientPinEntrySheetModel>(
              dialog_model,
              AuthenticatorClientPinEntrySheetModel::Mode::kPinEntry,
              dialog_model->pin_error));
      break;
    case Step::kClientPinSetup:
      sheet_view = std::make_unique<AuthenticatorClientPinEntrySheetView>(
          std::make_unique<AuthenticatorClientPinEntrySheetModel>(
              dialog_model,
              AuthenticatorClientPinEntrySheetModel::Mode::kPinSetup,
              dialog_model->pin_error));
      break;
    case Step::kClientPinTapAgain:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorClientPinTapAgainSheetModel>(
              dialog_model));
      break;
    case Step::kClientPinErrorSoftBlock:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          AuthenticatorGenericErrorSheetModel::ForClientPinErrorSoftBlock(
              dialog_model));
      break;
    case Step::kClientPinErrorHardBlock:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          AuthenticatorGenericErrorSheetModel::ForClientPinErrorHardBlock(
              dialog_model));
      break;
    case Step::kClientPinErrorAuthenticatorRemoved:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          AuthenticatorGenericErrorSheetModel::
              ForClientPinErrorAuthenticatorRemoved(dialog_model));
      break;
    case Step::kInlineBioEnrollment:
      sheet_view = std::make_unique<AuthenticatorBioEnrollmentSheetView>(
          std::make_unique<AuthenticatorBioEnrollmentSheetModel>(dialog_model));
      break;
    case Step::kRetryInternalUserVerification:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorRetryUvSheetModel>(dialog_model));
      break;
    case Step::kResidentCredentialConfirmation:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<
              AuthenticatorResidentCredentialConfirmationSheetView>(
              dialog_model));
      break;
    case Step::kSelectAccount:
      sheet_view = std::make_unique<AuthenticatorSelectAccountSheetView>(
          std::make_unique<AuthenticatorSelectAccountSheetModel>(
              dialog_model,
              AuthenticatorSelectAccountSheetModel::kPostUserVerification));
      break;
    case Step::kPreSelectAccount:
      sheet_view = std::make_unique<AuthenticatorSelectAccountSheetView>(
          std::make_unique<AuthenticatorSelectAccountSheetModel>(
              dialog_model,
              AuthenticatorSelectAccountSheetModel::kPreUserVerification));
      break;
    case Step::kSelectPriorityMechanism:
      sheet_view = std::make_unique<AuthenticatorPriorityMechanismSheetView>(
          std::make_unique<AuthenticatorPriorityMechanismSheetModel>(
              dialog_model));
      break;
    case Step::kCreatePasskey:
      sheet_view = std::make_unique<AuthenticatorCreatePasskeySheetView>(
          std::make_unique<AuthenticatorCreatePasskeySheetModel>(dialog_model));
      break;
    case Step::kGPMError:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorGPMErrorSheetModel>(dialog_model));
      break;
    case Step::kGPMConnecting:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorGPMConnectingSheetModel>(dialog_model));
      break;
    case Step::kGPMChangePin:
    case Step::kGPMCreatePin:
      sheet_view = std::make_unique<AuthenticatorGpmPinSheetView>(
          std::make_unique<AuthenticatorGpmPinSheetModel>(
              dialog_model, kPinDigitCount,
              AuthenticatorGpmPinSheetModelBase::Mode::kPinCreate));
      break;
    case Step::kGPMEnterPin:
      sheet_view = std::make_unique<AuthenticatorGpmPinSheetView>(
          std::make_unique<AuthenticatorGpmPinSheetModel>(
              dialog_model, kPinDigitCount,
              AuthenticatorGpmPinSheetModelBase::Mode::kPinEntry));
      break;
    case Step::kGPMChangeArbitraryPin:
    case Step::kGPMCreateArbitraryPin:
      sheet_view = std::make_unique<AuthenticatorGPMArbitraryPinSheetView>(
          std::make_unique<AuthenticatorGpmArbitraryPinSheetModel>(
              dialog_model,
              AuthenticatorGpmPinSheetModelBase::Mode::kPinCreate));
      break;
    case Step::kGPMEnterArbitraryPin:
      sheet_view = std::make_unique<AuthenticatorGPMArbitraryPinSheetView>(
          std::make_unique<AuthenticatorGpmArbitraryPinSheetModel>(
              dialog_model,
              AuthenticatorGpmPinSheetModelBase::Mode::kPinEntry));
      break;
    case Step::kTrustThisComputerAssertion:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorTrustThisComputerAssertionSheetModel>(
              dialog_model));
      break;
    case Step::kTrustThisComputerCreation:
      sheet_view = std::make_unique<AuthenticatorCreateUserSheetView>(
          std::make_unique<AuthenticatorTrustThisComputerCreationSheetModel>(
              dialog_model));
      break;
    case Step::kGPMCreatePasskey:
      sheet_view = std::make_unique<AuthenticatorCreateUserSheetView>(
          std::make_unique<AuthenticatorCreateGpmPasskeySheetModel>(
              dialog_model));
      break;
    case Step::kGPMConfirmOffTheRecordCreate:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorGpmIncognitoCreateSheetModel>(
              dialog_model));
      break;
    case Step::kGPMTouchID:
#if BUILDFLAG(IS_MAC)
      sheet_view = std::make_unique<AuthenticatorTouchIdView>(
          std::make_unique<AuthenticatorTouchIdSheetModel>(dialog_model));
#else
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<PlaceholderSheetModel>(dialog_model));
#endif
      break;
    case Step::kGPMLockedPin:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorGPMLockedPinSheetModel>(dialog_model));
      break;
    case Step::kErrorFetchingChallenge:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<AuthenticatorChallengeFetchErrorModel>(
              dialog_model));
      break;
    case Step::kNotStarted:
    case Step::kPasskeyAutofill:
    case Step::kPasskeyUpgrade:
    case Step::kClosed:
    case Step::kRecoverSecurityDomain:
    case Step::kGPMReauthForPinReset:
    case Step::kPasswordOsAuth:
      sheet_view = std::make_unique<AuthenticatorRequestSheetView>(
          std::make_unique<PlaceholderSheetModel>(dialog_model));
      break;
  }

  CHECK(sheet_view);
  return sheet_view;
}

std::unique_ptr<AuthenticatorRequestSheetView>
CreateSheetViewForAutofillWebAuthn(
    std::unique_ptr<autofill::WebauthnDialogModel> model) {
  return std::make_unique<AuthenticatorRequestSheetView>(std::move(model));
}