1
0
mirror of https://github.com/bitwarden/browser.git synced 2025-01-19 20:51:35 +01:00

refactor: move into common

This commit is contained in:
Andreas Coroiu 2024-12-17 14:02:59 +01:00
parent 51afcf5306
commit f04027489a
No known key found for this signature in database
GPG Key ID: E70B5FFC81DFEC1A
12 changed files with 32 additions and 33 deletions

View File

@ -100,6 +100,7 @@ import {
} from "@bitwarden/common/platform/abstractions/storage.service";
import { SystemService as SystemServiceAbstraction } from "@bitwarden/common/platform/abstractions/system.service";
import { StateFactory } from "@bitwarden/common/platform/factories/state-factory";
import { IpcService } from "@bitwarden/common/platform/ipc";
import { Message, MessageListener, MessageSender } from "@bitwarden/common/platform/messaging";
// eslint-disable-next-line no-restricted-imports -- Used for dependency creation
import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal";
@ -208,7 +209,6 @@ import {
DefaultBiometricStateService,
KeyService as KeyServiceAbstraction,
} from "@bitwarden/key-management";
import { IpcService } from "@bitwarden/platform";
import {
IndividualVaultExportService,
IndividualVaultExportServiceAbstraction,

View File

@ -10,16 +10,3 @@ export interface BitwardenIpcWebApi {
*/
onMessage?: (payload: Uint8Array) => void;
}
export interface IpcMessage {
type: "bitwarden-ipc-message";
payload: Uint8Array;
}
export function getBitwardenIpcWebApi(): BitwardenIpcWebApi | undefined {
return (window as any).Bitwarden;
}
export function isIpcMessage(message: any): message is IpcMessage {
return message.type === "bitwarden-ipc-message";
}

View File

@ -1,8 +1,8 @@
import { isIpcMessage } from "./bitwarden-ipc-web-api";
// TODO: This content script should be dynamically reloaded when the extension is updated,
// to avoid "Extension context invalidated." errors.
import { isIpcMessage } from "@bitwarden/common/platform/ipc/ipc-message";
export function sendExtensionMessage(message: unknown) {
if (
typeof browser !== "undefined" &&

View File

@ -1,10 +0,0 @@
import { BitwardenIpcWebApi, IpcMessage } from "./bitwarden-ipc-web-api";
(window as any).Bitwarden = {
postMessage: (payload) =>
window.postMessage(
{ type: "bitwarden-ipc-message", payload } as IpcMessage,
window.location.origin,
),
onMessage: undefined,
} as BitwardenIpcWebApi;

View File

@ -1,9 +1,7 @@
import { IpcService } from "@bitwarden/platform";
import { IpcService, isIpcMessage } from "@bitwarden/common/platform/ipc";
import { BrowserApi } from "../browser/browser-api";
import { isIpcMessage } from "./content/bitwarden-ipc-web-api";
export class IpcBackgroundService extends IpcService {
override async init() {
await super.init();

View File

@ -0,0 +1,16 @@
import { IpcService, isIpcMessage } from "@bitwarden/common/platform/ipc";
export class WebIpcService extends IpcService {
override async init() {
await super.init();
window.addEventListener("message", (event) => {
const message = event.data;
if (!isIpcMessage(message)) {
return;
}
console.log("WEB Received IPC message", message);
});
}
}

View File

@ -0,0 +1,8 @@
export interface IpcMessage {
type: "bitwarden-ipc-message";
payload: Uint8Array;
}
export function isIpcMessage(message: any): message is IpcMessage {
return message.type === "bitwarden-ipc-message";
}

View File

@ -1,7 +1,11 @@
// import { Manager } from "@bitwarden/sdk-internal";
import { SdkService } from "../abstractions/sdk/sdk.service";
export abstract class IpcService {
// protected manager = new Manager();
constructor(private sdkService: SdkService) {}
async init() {}
}

View File

@ -1,2 +1 @@
export * from "./services/browser-service";
export * from "./ipc";

View File

@ -1,3 +0,0 @@
export interface IpcMessage {
payload: Uint8Array;
}