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:
parent
51afcf5306
commit
f04027489a
@ -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,
|
||||
|
@ -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";
|
||||
}
|
||||
|
@ -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" &&
|
||||
|
@ -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;
|
@ -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();
|
||||
|
16
apps/web/src/app/platform/ipc/web-ipc.service.ts
Normal file
16
apps/web/src/app/platform/ipc/web-ipc.service.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
}
|
8
libs/common/src/platform/ipc/ipc-message.ts
Normal file
8
libs/common/src/platform/ipc/ipc-message.ts
Normal 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";
|
||||
}
|
@ -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() {}
|
||||
}
|
@ -1,2 +1 @@
|
||||
export * from "./services/browser-service";
|
||||
export * from "./ipc";
|
||||
|
@ -1,3 +0,0 @@
|
||||
export interface IpcMessage {
|
||||
payload: Uint8Array;
|
||||
}
|
Loading…
Reference in New Issue
Block a user