[PM-7610] [MV3] Guard overlay visibility and autofill on page load settings from awaiting indefinitely when there is no active account (#8833)

* guard overlay visibility and autofill on page load settings from awaiting indefinitely when there is no active account

* cleanup
This commit is contained in:
Jonathan Prusik 2024-04-19 15:21:54 -04:00 committed by GitHub
parent 395ed3f5d4
commit ec1af0cf9f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 4 deletions

View File

@ -1,3 +1,7 @@
import {
accountServiceFactory,
AccountServiceInitOptions,
} from "../../../auth/background/service-factories/account-service.factory";
import {
UserVerificationServiceInitOptions,
userVerificationServiceFactory,
@ -50,7 +54,8 @@ export type AutoFillServiceInitOptions = AutoFillServiceOptions &
LogServiceInitOptions &
UserVerificationServiceInitOptions &
DomainSettingsServiceInitOptions &
BrowserScriptInjectorServiceInitOptions;
BrowserScriptInjectorServiceInitOptions &
AccountServiceInitOptions;
export function autofillServiceFactory(
cache: { autofillService?: AbstractAutoFillService } & CachedServices,
@ -71,6 +76,7 @@ export function autofillServiceFactory(
await userVerificationServiceFactory(cache, opts),
await billingAccountProfileStateServiceFactory(cache, opts),
await browserScriptInjectorServiceFactory(cache, opts),
await accountServiceFactory(cache, opts),
),
);
}

View File

@ -87,6 +87,7 @@ describe("AutofillService", () => {
userVerificationService,
billingAccountProfileStateService,
scriptInjectorService,
accountService,
);
domainSettingsService = new DefaultDomainSettingsService(fakeStateProvider);

View File

@ -1,7 +1,9 @@
import { firstValueFrom } from "rxjs";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { UserVerificationService } from "@bitwarden/common/auth/abstractions/user-verification/user-verification.service.abstraction";
import { AutofillOverlayVisibility } from "@bitwarden/common/autofill/constants";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
import { DomainSettingsService } from "@bitwarden/common/autofill/services/domain-settings.service";
import { InlineMenuVisibilitySetting } from "@bitwarden/common/autofill/types";
@ -57,6 +59,7 @@ export default class AutofillService implements AutofillServiceInterface {
private userVerificationService: UserVerificationService,
private billingAccountProfileStateService: BillingAccountProfileStateService,
private scriptInjectorService: ScriptInjectorService,
private accountService: AccountService,
) {}
/**
@ -104,13 +107,26 @@ export default class AutofillService implements AutofillServiceInterface {
frameId = 0,
triggeringOnPageLoad = true,
): Promise<void> {
const mainAutofillScript = (await this.getOverlayVisibility())
// Autofill settings loaded from state can await the active account state indefinitely if
// not guarded by an active account check (e.g. the user is logged in)
const activeAccount = await firstValueFrom(this.accountService.activeAccount$);
// These settings are not available until the user logs in
let overlayVisibility: InlineMenuVisibilitySetting = AutofillOverlayVisibility.Off;
let autoFillOnPageLoadIsEnabled = false;
if (activeAccount) {
overlayVisibility = await this.getOverlayVisibility();
}
const mainAutofillScript = overlayVisibility
? "bootstrap-autofill-overlay.js"
: "bootstrap-autofill.js";
const injectedScripts = [mainAutofillScript];
const autoFillOnPageLoadIsEnabled = await this.getAutofillOnPageLoad();
if (activeAccount) {
autoFillOnPageLoadIsEnabled = await this.getAutofillOnPageLoad();
}
if (triggeringOnPageLoad && autoFillOnPageLoadIsEnabled) {
injectedScripts.push("autofiller.js");

View File

@ -29,6 +29,7 @@ import { PolicyService } from "@bitwarden/common/admin-console/services/policy/p
import { ProviderService } from "@bitwarden/common/admin-console/services/provider.service";
import { AccountService as AccountServiceAbstraction } from "@bitwarden/common/auth/abstractions/account.service";
import { AuthService as AuthServiceAbstraction } from "@bitwarden/common/auth/abstractions/auth.service";
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/auth/abstractions/avatar.service";
import { DeviceTrustCryptoServiceAbstraction } from "@bitwarden/common/auth/abstractions/device-trust-crypto.service.abstraction";
import { DevicesServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices/devices.service.abstraction";
import { DevicesApiServiceAbstraction } from "@bitwarden/common/auth/abstractions/devices-api.service.abstraction";
@ -137,7 +138,6 @@ import { EventUploadService } from "@bitwarden/common/services/event/event-uploa
import { NotificationsService } from "@bitwarden/common/services/notifications.service";
import { SearchService } from "@bitwarden/common/services/search.service";
import { VaultTimeoutSettingsService } from "@bitwarden/common/services/vault-timeout/vault-timeout-settings.service";
import { AvatarService as AvatarServiceAbstraction } from "@bitwarden/common/src/auth/abstractions/avatar.service";
import {
PasswordGenerationService,
PasswordGenerationServiceAbstraction,
@ -807,6 +807,7 @@ export default class MainBackground {
this.userVerificationService,
this.billingAccountProfileStateService,
this.scriptInjectorService,
this.accountService,
);
this.auditService = new AuditService(this.cryptoFunctionService, this.apiService);

View File

@ -312,6 +312,7 @@ const safeProviders: SafeProvider[] = [
UserVerificationService,
BillingAccountProfileStateService,
ScriptInjectorService,
AccountServiceAbstraction,
],
}),
safeProvider({