1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-23 11:56:00 +01:00

make tab object for message sender

This commit is contained in:
Kyle Spearrin 2018-01-12 15:53:37 -05:00
parent 06c8f17d06
commit 729380c0ec

View File

@ -44,16 +44,7 @@ class BrowserApi {
const returnedTabs: any[] = [];
tabs.forEach((tab: any) => {
const winIndex = safari.application.browserWindows.indexOf(tab.browserWindow);
const tabIndex = tab.browserWindow.tabs.indexOf(tab);
returnedTabs.push({
id: winIndex + '_' + tabIndex,
index: tabIndex,
windowId: winIndex,
title: tab.title,
active: tab === tab.browserWindow.activeTab,
url: tab.url || 'about:blank',
});
returnedTabs.push(BrowserApi.makeTabObject(tab));
});
return Promise.resolve(returnedTabs);
@ -169,14 +160,33 @@ class BrowserApi {
} else if (BrowserApi.isSafariApi) {
safari.application.addEventListener('message', async (msgEvent: any) => {
callback(msgEvent.message, {
tab: {
id: null, // TODO
},
tab: BrowserApi.makeTabObject(msgEvent.target),
frameId: null,
}, () => { /* No responses in Safari */ });
}, false);
}
}
private static makeTabObject(tab: any) {
if (BrowserApi.isChromeApi) {
return tab;
}
if (!tab.browserWindow) {
return {};
}
const winIndex = safari.application.browserWindows.indexOf(tab.browserWindow);
const tabIndex = tab.browserWindow.tabs.indexOf(tab);
return {
id: winIndex + '_' + tabIndex,
index: tabIndex,
windowId: winIndex,
title: tab.title,
active: tab === tab.browserWindow.activeTab,
url: tab.url || 'about:blank',
};
}
}
export { BrowserApi };