1 // Copyright 2018 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_UI_WEBAUTHN_SHEET_MODELS_H_ 6 #define CHROME_BROWSER_UI_WEBAUTHN_SHEET_MODELS_H_ 7 8 #include <memory> 9 10 #include "base/macros.h" 11 #include "base/strings/string16.h" 12 #include "chrome/browser/ui/webauthn/authenticator_request_sheet_model.h" 13 #include "chrome/browser/ui/webauthn/transport_hover_list_model.h" 14 #include "chrome/browser/webauthn/authenticator_request_dialog_model.h" 15 16 namespace gfx { 17 struct VectorIcon; 18 } 19 20 namespace ui { 21 class MenuModel; 22 } 23 24 class OtherTransportsMenuModel; 25 26 // Base class for sheets, implementing the shared behavior used on most sheets, 27 // as well as maintaining a weak pointer to the dialog model. 28 class AuthenticatorSheetModelBase 29 : public AuthenticatorRequestSheetModel, 30 public AuthenticatorRequestDialogModel::Observer { 31 public: 32 explicit AuthenticatorSheetModelBase( 33 AuthenticatorRequestDialogModel* dialog_model); 34 ~AuthenticatorSheetModelBase() override; 35 dialog_model()36 AuthenticatorRequestDialogModel* dialog_model() const { 37 return dialog_model_; 38 } 39 40 protected: 41 // AuthenticatorRequestSheetModel: 42 bool IsActivityIndicatorVisible() const override; 43 bool IsBackButtonVisible() const override; 44 bool IsCancelButtonVisible() const override; 45 base::string16 GetCancelButtonLabel() const override; 46 bool IsAcceptButtonVisible() const override; 47 bool IsAcceptButtonEnabled() const override; 48 base::string16 GetAcceptButtonLabel() const override; 49 void OnBack() override; 50 void OnAccept() override; 51 void OnCancel() override; 52 53 // AuthenticatorRequestDialogModel::Observer: 54 void OnModelDestroyed() override; 55 56 private: 57 AuthenticatorRequestDialogModel* dialog_model_; 58 59 DISALLOW_COPY_AND_ASSIGN(AuthenticatorSheetModelBase); 60 }; 61 62 // The sheet shown for selecting the transport over which the security key 63 // should be accessed. 64 class AuthenticatorTransportSelectorSheetModel 65 : public AuthenticatorSheetModelBase, 66 public TransportHoverListModel::Delegate { 67 public: 68 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 69 70 // TransportHoverListModel::Delegate: 71 void OnTransportSelected(AuthenticatorTransport transport) override; 72 void StartWinNativeApi() override; 73 74 private: 75 // AuthenticatorSheetModelBase: 76 bool IsBackButtonVisible() const override; 77 const gfx::VectorIcon& GetStepIllustration( 78 ImageColorScheme color_scheme) const override; 79 base::string16 GetStepTitle() const override; 80 base::string16 GetStepDescription() const override; 81 }; 82 83 class AuthenticatorInsertAndActivateUsbSheetModel 84 : public AuthenticatorSheetModelBase { 85 public: 86 explicit AuthenticatorInsertAndActivateUsbSheetModel( 87 AuthenticatorRequestDialogModel* dialog_model); 88 ~AuthenticatorInsertAndActivateUsbSheetModel() override; 89 90 private: 91 // AuthenticatorSheetModelBase: 92 bool IsActivityIndicatorVisible() const override; 93 const gfx::VectorIcon& GetStepIllustration( 94 ImageColorScheme color_scheme) const override; 95 base::string16 GetStepTitle() const override; 96 base::string16 GetStepDescription() const override; 97 base::string16 GetAdditionalDescription() const override; 98 ui::MenuModel* GetOtherTransportsMenuModel() override; 99 100 std::unique_ptr<OtherTransportsMenuModel> other_transports_menu_model_; 101 }; 102 103 class AuthenticatorTimeoutErrorModel : public AuthenticatorSheetModelBase { 104 public: 105 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 106 107 private: 108 // AuthenticatorSheetModelBase: 109 bool IsBackButtonVisible() const override; 110 base::string16 GetCancelButtonLabel() const override; 111 const gfx::VectorIcon& GetStepIllustration( 112 ImageColorScheme color_scheme) const override; 113 base::string16 GetStepTitle() const override; 114 base::string16 GetStepDescription() const override; 115 }; 116 117 class AuthenticatorNoAvailableTransportsErrorModel 118 : public AuthenticatorSheetModelBase { 119 public: 120 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 121 122 private: 123 // AuthenticatorSheetModelBase: 124 bool IsBackButtonVisible() const override; 125 base::string16 GetCancelButtonLabel() const override; 126 const gfx::VectorIcon& GetStepIllustration( 127 ImageColorScheme color_scheme) const override; 128 base::string16 GetStepTitle() const override; 129 base::string16 GetStepDescription() const override; 130 }; 131 132 class AuthenticatorNotRegisteredErrorModel 133 : public AuthenticatorSheetModelBase { 134 public: 135 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 136 137 private: 138 // AuthenticatorSheetModelBase: 139 bool IsBackButtonVisible() const override; 140 base::string16 GetCancelButtonLabel() const override; 141 bool IsAcceptButtonVisible() const override; 142 bool IsAcceptButtonEnabled() const override; 143 base::string16 GetAcceptButtonLabel() const override; 144 const gfx::VectorIcon& GetStepIllustration( 145 ImageColorScheme color_scheme) const override; 146 base::string16 GetStepTitle() const override; 147 base::string16 GetStepDescription() const override; 148 void OnAccept() override; 149 }; 150 151 class AuthenticatorAlreadyRegisteredErrorModel 152 : public AuthenticatorSheetModelBase { 153 public: 154 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 155 156 private: 157 // AuthenticatorSheetModelBase: 158 bool IsBackButtonVisible() const override; 159 base::string16 GetCancelButtonLabel() const override; 160 bool IsAcceptButtonVisible() const override; 161 bool IsAcceptButtonEnabled() const override; 162 base::string16 GetAcceptButtonLabel() const override; 163 const gfx::VectorIcon& GetStepIllustration( 164 ImageColorScheme color_scheme) const override; 165 base::string16 GetStepTitle() const override; 166 base::string16 GetStepDescription() const override; 167 void OnAccept() override; 168 }; 169 170 class AuthenticatorInternalUnrecognizedErrorSheetModel 171 : public AuthenticatorSheetModelBase { 172 public: 173 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 174 175 private: 176 // AuthenticatorSheetModelBase: 177 bool IsBackButtonVisible() const override; 178 bool IsAcceptButtonVisible() const override; 179 bool IsAcceptButtonEnabled() const override; 180 base::string16 GetAcceptButtonLabel() const override; 181 const gfx::VectorIcon& GetStepIllustration( 182 ImageColorScheme color_scheme) const override; 183 base::string16 GetStepTitle() const override; 184 base::string16 GetStepDescription() const override; 185 void OnAccept() override; 186 }; 187 188 class AuthenticatorBlePowerOnManualSheetModel 189 : public AuthenticatorSheetModelBase { 190 public: 191 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 192 193 private: 194 // AuthenticatorSheetModelBase: 195 const gfx::VectorIcon& GetStepIllustration( 196 ImageColorScheme color_scheme) const override; 197 base::string16 GetStepTitle() const override; 198 base::string16 GetStepDescription() const override; 199 bool IsAcceptButtonVisible() const override; 200 bool IsAcceptButtonEnabled() const override; 201 base::string16 GetAcceptButtonLabel() const override; 202 void OnAccept() override; 203 204 // AuthenticatorRequestDialogModel::Observer: 205 void OnBluetoothPoweredStateChanged() override; 206 }; 207 208 class AuthenticatorBlePowerOnAutomaticSheetModel 209 : public AuthenticatorSheetModelBase { 210 public: 211 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 212 213 private: 214 // AuthenticatorSheetModelBase: 215 bool IsActivityIndicatorVisible() const override; 216 const gfx::VectorIcon& GetStepIllustration( 217 ImageColorScheme color_scheme) const override; 218 base::string16 GetStepTitle() const override; 219 base::string16 GetStepDescription() const override; 220 bool IsAcceptButtonVisible() const override; 221 bool IsAcceptButtonEnabled() const override; 222 base::string16 GetAcceptButtonLabel() const override; 223 void OnAccept() override; 224 225 bool busy_powering_on_ble_ = false; 226 }; 227 228 class AuthenticatorTouchIdIncognitoBumpSheetModel 229 : public AuthenticatorSheetModelBase { 230 public: 231 explicit AuthenticatorTouchIdIncognitoBumpSheetModel( 232 AuthenticatorRequestDialogModel* dialog_model); 233 ~AuthenticatorTouchIdIncognitoBumpSheetModel() override; 234 235 private: 236 // AuthenticatorSheetModelBase: 237 const gfx::VectorIcon& GetStepIllustration( 238 ImageColorScheme color_scheme) const override; 239 base::string16 GetStepTitle() const override; 240 base::string16 GetStepDescription() const override; 241 ui::MenuModel* GetOtherTransportsMenuModel() override; 242 bool IsAcceptButtonVisible() const override; 243 bool IsAcceptButtonEnabled() const override; 244 base::string16 GetAcceptButtonLabel() const override; 245 void OnAccept() override; 246 247 std::unique_ptr<OtherTransportsMenuModel> other_transports_menu_model_; 248 }; 249 250 class AuthenticatorPaaskSheetModel : public AuthenticatorSheetModelBase { 251 public: 252 explicit AuthenticatorPaaskSheetModel( 253 AuthenticatorRequestDialogModel* dialog_model); 254 ~AuthenticatorPaaskSheetModel() override; 255 256 private: 257 // AuthenticatorSheetModelBase: 258 bool IsBackButtonVisible() const override; 259 bool IsActivityIndicatorVisible() const override; 260 const gfx::VectorIcon& GetStepIllustration( 261 ImageColorScheme color_scheme) const override; 262 base::string16 GetStepTitle() const override; 263 base::string16 GetStepDescription() const override; 264 ui::MenuModel* GetOtherTransportsMenuModel() override; 265 266 std::unique_ptr<OtherTransportsMenuModel> other_transports_menu_model_; 267 }; 268 269 class AuthenticatorPaaskV2SheetModel : public AuthenticatorSheetModelBase { 270 public: 271 explicit AuthenticatorPaaskV2SheetModel( 272 AuthenticatorRequestDialogModel* dialog_model); 273 ~AuthenticatorPaaskV2SheetModel() override; 274 275 private: 276 // AuthenticatorSheetModelBase: 277 bool IsBackButtonVisible() const override; 278 bool IsActivityIndicatorVisible() const override; 279 const gfx::VectorIcon& GetStepIllustration( 280 ImageColorScheme color_scheme) const override; 281 base::string16 GetStepTitle() const override; 282 base::string16 GetStepDescription() const override; 283 ui::MenuModel* GetOtherTransportsMenuModel() override; 284 bool IsAcceptButtonVisible() const override; 285 bool IsAcceptButtonEnabled() const override; 286 base::string16 GetAcceptButtonLabel() const override; 287 void OnAccept() override; 288 289 std::unique_ptr<OtherTransportsMenuModel> other_transports_menu_model_; 290 }; 291 292 class AuthenticatorClientPinEntrySheetModel 293 : public AuthenticatorSheetModelBase { 294 public: 295 // Indicates whether the view should accommodate setting up a new PIN or 296 // entering an existing one. 297 enum class Mode { kPinEntry, kPinSetup }; 298 AuthenticatorClientPinEntrySheetModel( 299 AuthenticatorRequestDialogModel* dialog_model, 300 Mode mode); 301 ~AuthenticatorClientPinEntrySheetModel() override; 302 303 using AuthenticatorSheetModelBase::AuthenticatorSheetModelBase; 304 305 void SetPinCode(base::string16 pin_code); 306 void SetPinConfirmation(base::string16 pin_confirmation); 307 mode()308 Mode mode() const { return mode_; } 309 310 private: 311 // AuthenticatorSheetModelBase: 312 const gfx::VectorIcon& GetStepIllustration( 313 ImageColorScheme color_scheme) const override; 314 base::string16 GetStepTitle() const override; 315 base::string16 GetStepDescription() const override; 316 base::string16 GetError() const override; 317 bool IsAcceptButtonVisible() const override; 318 bool IsAcceptButtonEnabled() const override; 319 base::string16 GetAcceptButtonLabel() const override; 320 void OnAccept() override; 321 322 base::string16 pin_code_; 323 base::string16 pin_confirmation_; 324 base::string16 error_; 325 const Mode mode_; 326 }; 327 328 class AuthenticatorClientPinTapAgainSheetModel 329 : public AuthenticatorSheetModelBase { 330 public: 331 explicit AuthenticatorClientPinTapAgainSheetModel( 332 AuthenticatorRequestDialogModel* dialog_model); 333 ~AuthenticatorClientPinTapAgainSheetModel() override; 334 335 private: 336 // AuthenticatorSheetModelBase: 337 bool IsActivityIndicatorVisible() const override; 338 const gfx::VectorIcon& GetStepIllustration( 339 ImageColorScheme color_scheme) const override; 340 base::string16 GetStepTitle() const override; 341 base::string16 GetStepDescription() const override; 342 base::string16 GetAdditionalDescription() const override; 343 }; 344 345 class AuthenticatorBioEnrollmentSheetModel 346 : public AuthenticatorSheetModelBase { 347 public: 348 explicit AuthenticatorBioEnrollmentSheetModel( 349 AuthenticatorRequestDialogModel* dialog_model); 350 ~AuthenticatorBioEnrollmentSheetModel() override; 351 max_bio_samples()352 int max_bio_samples() { 353 return dialog_model()->max_bio_samples().value_or(1); 354 } bio_samples_remaining()355 int bio_samples_remaining() { 356 return dialog_model()->bio_samples_remaining().value_or(1); 357 } 358 359 private: 360 // AuthenticatorSheetModelBase: 361 bool IsActivityIndicatorVisible() const override; 362 const gfx::VectorIcon& GetStepIllustration( 363 ImageColorScheme color_scheme) const override; 364 base::string16 GetStepTitle() const override; 365 base::string16 GetStepDescription() const override; 366 bool IsAcceptButtonEnabled() const override; 367 bool IsAcceptButtonVisible() const override; 368 base::string16 GetAcceptButtonLabel() const override; 369 bool IsCancelButtonVisible() const override; 370 base::string16 GetCancelButtonLabel() const override; 371 void OnAccept() override; 372 void OnCancel() override; 373 }; 374 375 class AuthenticatorRetryUvSheetModel : public AuthenticatorSheetModelBase { 376 public: 377 explicit AuthenticatorRetryUvSheetModel( 378 AuthenticatorRequestDialogModel* dialog_model); 379 ~AuthenticatorRetryUvSheetModel() override; 380 381 private: 382 // AuthenticatorSheetModelBase: 383 bool IsActivityIndicatorVisible() const override; 384 const gfx::VectorIcon& GetStepIllustration( 385 ImageColorScheme color_scheme) const override; 386 base::string16 GetStepTitle() const override; 387 base::string16 GetStepDescription() const override; 388 base::string16 GetError() const override; 389 }; 390 391 // Generic error dialog that can only be dismissed. Backwards navigation is 392 // not visible. 393 class AuthenticatorGenericErrorSheetModel : public AuthenticatorSheetModelBase { 394 public: 395 static std::unique_ptr<AuthenticatorGenericErrorSheetModel> 396 ForClientPinErrorSoftBlock(AuthenticatorRequestDialogModel* dialog_model); 397 static std::unique_ptr<AuthenticatorGenericErrorSheetModel> 398 ForClientPinErrorHardBlock(AuthenticatorRequestDialogModel* dialog_model); 399 static std::unique_ptr<AuthenticatorGenericErrorSheetModel> 400 ForClientPinErrorAuthenticatorRemoved( 401 AuthenticatorRequestDialogModel* dialog_model); 402 static std::unique_ptr<AuthenticatorGenericErrorSheetModel> 403 ForMissingCapability(AuthenticatorRequestDialogModel* dialog_model); 404 static std::unique_ptr<AuthenticatorGenericErrorSheetModel> ForStorageFull( 405 AuthenticatorRequestDialogModel* dialog_model); 406 407 private: 408 AuthenticatorGenericErrorSheetModel( 409 AuthenticatorRequestDialogModel* dialog_model, 410 base::string16 title, 411 base::string16 description); 412 413 // AuthenticatorSheetModelBase: 414 bool IsBackButtonVisible() const override; 415 base::string16 GetCancelButtonLabel() const override; 416 const gfx::VectorIcon& GetStepIllustration( 417 ImageColorScheme color_scheme) const override; 418 base::string16 GetStepTitle() const override; 419 base::string16 GetStepDescription() const override; 420 421 base::string16 title_; 422 base::string16 description_; 423 }; 424 425 class AuthenticatorResidentCredentialConfirmationSheetView 426 : public AuthenticatorSheetModelBase { 427 public: 428 AuthenticatorResidentCredentialConfirmationSheetView( 429 AuthenticatorRequestDialogModel* dialog_model); 430 ~AuthenticatorResidentCredentialConfirmationSheetView() override; 431 432 private: 433 // AuthenticatorSheetModelBase: 434 const gfx::VectorIcon& GetStepIllustration( 435 ImageColorScheme color_scheme) const override; 436 bool IsBackButtonVisible() const override; 437 bool IsAcceptButtonVisible() const override; 438 bool IsAcceptButtonEnabled() const override; 439 base::string16 GetAcceptButtonLabel() const override; 440 base::string16 GetStepTitle() const override; 441 base::string16 GetStepDescription() const override; 442 void OnAccept() override; 443 }; 444 445 // The sheet shown when the user needs to select an account. 446 class AuthenticatorSelectAccountSheetModel 447 : public AuthenticatorSheetModelBase { 448 public: 449 explicit AuthenticatorSelectAccountSheetModel( 450 AuthenticatorRequestDialogModel* dialog_model); 451 ~AuthenticatorSelectAccountSheetModel() override; 452 453 // Set the index of the currently selected row. 454 void SetCurrentSelection(int selected); 455 456 // AuthenticatorSheetModelBase: 457 void OnAccept() override; 458 459 private: 460 // AuthenticatorSheetModelBase: 461 const gfx::VectorIcon& GetStepIllustration( 462 ImageColorScheme color_scheme) const override; 463 base::string16 GetStepTitle() const override; 464 base::string16 GetStepDescription() const override; 465 bool IsAcceptButtonVisible() const override; 466 bool IsAcceptButtonEnabled() const override; 467 base::string16 GetAcceptButtonLabel() const override; 468 469 size_t selected_ = 0; 470 }; 471 472 class AttestationPermissionRequestSheetModel 473 : public AuthenticatorSheetModelBase { 474 public: 475 explicit AttestationPermissionRequestSheetModel( 476 AuthenticatorRequestDialogModel* dialog_model); 477 ~AttestationPermissionRequestSheetModel() override; 478 479 // AuthenticatorSheetModelBase: 480 void OnAccept() override; 481 void OnCancel() override; 482 483 private: 484 // AuthenticatorSheetModelBase: 485 const gfx::VectorIcon& GetStepIllustration( 486 ImageColorScheme color_scheme) const override; 487 base::string16 GetStepTitle() const override; 488 base::string16 GetStepDescription() const override; 489 bool IsBackButtonVisible() const override; 490 bool IsAcceptButtonVisible() const override; 491 bool IsAcceptButtonEnabled() const override; 492 base::string16 GetAcceptButtonLabel() const override; 493 bool IsCancelButtonVisible() const override; 494 base::string16 GetCancelButtonLabel() const override; 495 }; 496 497 class AuthenticatorQRSheetModel : public AuthenticatorSheetModelBase { 498 public: 499 explicit AuthenticatorQRSheetModel( 500 AuthenticatorRequestDialogModel* dialog_model); 501 ~AuthenticatorQRSheetModel() override; 502 503 private: 504 // AuthenticatorSheetModelBase: 505 const gfx::VectorIcon& GetStepIllustration( 506 ImageColorScheme color_scheme) const override; 507 base::string16 GetStepTitle() const override; 508 base::string16 GetStepDescription() const override; 509 }; 510 511 #endif // CHROME_BROWSER_UI_WEBAUTHN_SHEET_MODELS_H_ 512