2018-01-14 00:16:19 +01:00
|
|
|
import { BrowserApi } from '../browser/browserApi';
|
|
|
|
|
2018-01-09 20:26:20 +01:00
|
|
|
import {
|
|
|
|
MessagingService,
|
|
|
|
PlatformUtilsService,
|
|
|
|
} from 'jslib/abstractions';
|
2018-01-04 22:06:00 +01:00
|
|
|
|
2018-01-09 20:26:20 +01:00
|
|
|
export default class BrowserMessagingService implements MessagingService {
|
|
|
|
constructor(private platformUtilsService: PlatformUtilsService) {
|
2018-01-04 22:06:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
send(subscriber: string, arg: any = {}) {
|
2018-01-14 00:16:19 +01:00
|
|
|
const message = Object.assign({}, { command: subscriber }, arg);
|
|
|
|
|
2018-01-11 21:34:55 +01:00
|
|
|
if (this.platformUtilsService.isSafari()) {
|
2018-01-14 00:16:19 +01:00
|
|
|
const bgPage = BrowserApi.getBackgroundPage();
|
|
|
|
bgPage.bitwardenMain.sendInternalRuntimeMessage(message);
|
2018-01-11 21:34:55 +01:00
|
|
|
} else {
|
|
|
|
chrome.runtime.sendMessage(message);
|
|
|
|
}
|
2018-01-04 22:06:00 +01:00
|
|
|
}
|
|
|
|
}
|