Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/background/runtime.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export default class RuntimeBackground {
await this.main.collectPageDetailsForContentScript(sender.tab, msg.sender, sender.frameId);
break;
case 'bgAnswerMenuRequest':
console.log('received bgAnswerMenuRequest')
switch (msg.subcommand) {
case 'getCiphersForTab':
const logins = await this.cipherService.getAllDecryptedForUrl(sender.tab.url, null);
Expand Down Expand Up @@ -881,6 +882,7 @@ export default class RuntimeBackground {
}

private async loggedinAndUnlocked(command: string) {
console.log('loggedinAndUnlocked')
await this.main.setIcon();
await this.main.refreshBadgeAndMenu(false);
this.notificationsService.init(this.environmentService);
Expand Down
27 changes: 15 additions & 12 deletions src/browser/browserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class BrowserApi {
static async getTabFromCurrentWindowId(): Promise<any> {
return await BrowserApi.tabsQueryFirst({
active: true,
windowId: chrome.windows.WINDOW_ID_CURRENT,
windowId: browser.windows.WINDOW_ID_CURRENT,
});
}

Expand All @@ -37,7 +37,7 @@ export class BrowserApi {

static async tabsQuery(options: any): Promise<any[]> {
return new Promise(resolve => {
chrome.tabs.query(options, (tabs: any[]) => {
browser.tabs.query(options).then((tabs: any[]) => {
resolve(tabs);
});
});
Expand Down Expand Up @@ -65,13 +65,15 @@ export class BrowserApi {
}

static async tabSendMessage(tab: any, obj: any, options: any = null): Promise<any> {
console.log('tabSendMessage')
if (!tab || !tab.id) {
return;
}

console.log('tabSendMessage',tab.id, obj, options)
return new Promise<void>(resolve => {
chrome.tabs.sendMessage(tab.id, obj, options, () => {
if (chrome.runtime.lastError) {
browser.tabs.sendMessage(tab.id, obj, options).then(() => {
if (browser.runtime.lastError) {
// Some error happened
}
resolve();
Expand All @@ -80,23 +82,24 @@ export class BrowserApi {
}

static getBackgroundPage(): any {
return chrome.extension.getBackgroundPage();
return browser.extension.getBackgroundPage();
}

static getApplicationVersion(): string {
return chrome.runtime.getManifest().version;
return browser.runtime.getManifest().version;
}

static async isPopupOpen(): Promise<boolean> {
return Promise.resolve(chrome.extension.getViews({ type: 'popup' }).length > 0);
return Promise.resolve(browser.extension.getViews({ type: 'popup' }).length > 0);
}

static createNewTab(url: string, extensionPage: boolean = false, active: boolean = true) {
chrome.tabs.create({ url: url, active: active });
browser.tabs.create({ url: url, active: active });
}

static messageListener(name: string, callback: (message: any, sender: any, response: any) => void) {
chrome.runtime.onMessage.addListener((msg: any, sender: any, response: any) => {
browser.runtime.onMessage.addListener((msg: any, sender: any, response: any) => {
console.log('messageListenerFrombrowserApi', msg)
callback(msg, sender, response);
});
}
Expand Down Expand Up @@ -146,19 +149,19 @@ export class BrowserApi {
}

static getUILanguage(win: Window) {
return chrome.i18n.getUILanguage();
return browser.i18n.getUILanguage();
}

static reloadExtension(win: Window) {
if (win != null) {
return win.location.reload(true);
} else {
return chrome.runtime.reload();
return browser.runtime.reload();
}
}

static reloadOpenWindows() {
const views = chrome.extension.getViews() as Window[];
const views = browser.extension.getViews() as Window[];
views.filter(w => w.location.href != null).forEach(w => {
w.location.reload();
});
Expand Down
20 changes: 9 additions & 11 deletions src/browser/safariApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,18 @@ import { BrowserApi } from './browserApi';

export class SafariApp {
static sendMessageToApp(command: string, data: any = null, resolveNow = false): Promise<any> {
console.log('sendMessageToApp',command, data)
if (!BrowserApi.isSafariApi) {
console.log('resolbe null')
return Promise.resolve(null);
}
return new Promise(resolve => {
const now = new Date();
const messageId = now.getTime().toString() + '_' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
(browser as any).runtime.sendNativeMessage('com.bitwarden.desktop', {
id: messageId,
command: command,
data: data,
responseData: null,
}, (response: any) => {
resolve(response);
});
const now = new Date();
const messageId = now.getTime().toString() + '_' + Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
return browser.runtime.sendNativeMessage('io.cozy.pass.desktop', {
id: messageId,
command: command,
data: data,
responseData: null,
});
}
}
29 changes: 18 additions & 11 deletions src/content/menuCtrler.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function _onClick(event) {
} else {
show(this)
}
console.log('end _onCliek')
}

function _onKeyDown(event) {
Expand Down Expand Up @@ -291,6 +292,7 @@ function _onKeyDown(event) {
//
function show(targetEl) {
// console.log('menuCtrler.show() ');
console.log('SHOW()')
if (state.isFrozen) return
if (!state.isHidden && (state.lastFocusedEl === targetEl)) return
state.lastFocusedEl = targetEl
Expand Down Expand Up @@ -431,7 +433,7 @@ function moveSelection(n) {
}
state.selectedCipher = newCipherNode

chrome.runtime.sendMessage({
browser.runtime.sendMessage({
command : 'bgAnswerMenuRequest',
subcommand : 'menuMoveSelection',
targetCipher : newCipherNode.data.id,
Expand All @@ -457,7 +459,7 @@ function getPossibleTypesForField(fieldEl) {
/* --------------------------------------------------------------------- */
// Submit the currently selected cypher for autofill
function submit() {
chrome.runtime.sendMessage({
browser.runtime.sendMessage({
command : 'bgAnswerMenuRequest',
subcommand : 'fillFormWithCipher',
sender : 'menuCtrler',
Expand All @@ -470,7 +472,7 @@ menuCtrler.submit = submit
/* --------------------------------------------------------------------- */
// autofill the focused field with the detail of the currently selected cypher
function submitDetail() {
chrome.runtime.sendMessage({
browser.runtime.sendMessage({
command : 'bgAnswerMenuRequest',
subcommand : 'askMenuTofillFieldWithData',
sender : 'menuCtrler',
Expand Down Expand Up @@ -520,6 +522,7 @@ menuCtrler.setCiphers = setCiphers
// Run this function so that menuCtrler.state.selectedCipher corresponds
// to the initial selection within the menu
function selectFirstCipherToSuggestFor(fieldEl) {
console.log('selectFirstCipherToSuggestFor')
if (state.isHidden) return
if (!ciphers || ciphers._length == 0) return
if (!fieldEl) return
Expand Down Expand Up @@ -576,13 +579,13 @@ function _setIframeURLforMenuType(menuType, isPinLocked, isLocked) {
const hash = '#' + encodeURIComponent(JSON.stringify(state.iFrameHash));
const rand = '?' + Math.floor((Math.random()*1000000)+1)
if (menuType === 'autofillMenu') {
menuEl.src = chrome.runtime.getURL('inPageMenu/menu.html' + rand) + hash
menuEl.src = browser.runtime.getURL('inPageMenu/menu.html' + rand) + hash
} else if (menuType === 'loginMenu') {
let searchParams = ''
if (isPinLocked) searchParams = 'isPinLocked=true'
if (isLocked) searchParams += 'isLocked=true'
if (searchParams) searchParams = '?' + searchParams
menuEl.src = chrome.runtime.getURL('inPageMenu/loginMenu.html' + searchParams + rand) + hash
if (searchParams) searchParams = '&' + searchParams
menuEl.src = browser.runtime.getURL('inPageMenu/loginMenu.html' + rand + searchParams) + hash
}
}

Expand All @@ -594,7 +597,7 @@ function _forceIframeRefresh() {
if (!menuEl || !menuEl.src) return
const url = new URL(menuEl.src)
const rand = '?' + Math.floor((Math.random()*1000000)+1)
menuEl.src = url.origin + url.pathname + url.search + rand + url.hash
menuEl.src = url.origin + url.pathname + rand + url.search + url.hash
}


Expand Down Expand Up @@ -630,17 +633,21 @@ function _updateHash() {
// send informations to the iframe through the url's hash (no reload)
// the hash is a Json string
function _setApplyFadeInUrl(doApply, fieldTypes) {
console.log('_setApplyFadeInUrl', doApply, fieldTypes)
if (!menuEl || !menuEl.src) return
const url = new URL(menuEl.src)
console.log('url', url)
if (doApply) {
fieldTypes = {...{login: false, identity: false, card: false, fieldFormat:false},...fieldTypes}
console.log('setHash')
state.iFrameHash = {...state.iFrameHash, ...fieldTypes, applyFadeIn: true}
menuEl.src = url.origin + url.pathname + url.search + '#' +
encodeURIComponent(JSON.stringify(state.iFrameHash))
console.log('end setHash')
menuEl.src = url.origin + url.pathname + url.search + '#' +'%7B%22arrowD%22%3A0%2C%22hostFrameId%22%3A0%7D'
// encodeURIComponent(JSON.stringify(state.iFrameHash))
} else {
state.iFrameHash.applyFadeIn = false
menuEl.src = url.origin + url.pathname + url.search + '#' +
encodeURIComponent(JSON.stringify(state.iFrameHash))
menuEl.src = url.origin + url.pathname + url.search + '#' + '%7B%22arrowD%22%3A0%2C%22hostFrameId%22%3A0%7D'
// encodeURIComponent(JSON.stringify(state.iFrameHash))
}
}

Expand Down
43 changes: 23 additions & 20 deletions src/inPageMenu/loginMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var panel ,
document.addEventListener('DOMContentLoaded', () => {

// 0- ask rememberedCozyUrl
chrome.runtime.sendMessage({
browser.runtime.sendMessage({
command : 'bgAnswerMenuRequest',
subcommand: 'getRememberedCozyUrl',
sender : 'loginMenu.js',
Expand Down Expand Up @@ -84,20 +84,21 @@ document.addEventListener('DOMContentLoaded', () => {
}, false);
} else {
// retrieve i18n values and set elements textcontent
const i18nGetMessage = chrome.i18n.getMessage
urlLabelTxt = i18nGetMessage('cozyUrl' )
twoFaLabelTxt = i18nGetMessage('verificationCode' )
visiPwdBtn.title = i18nGetMessage('toggleVisibility' )
visi2faBtn.title = i18nGetMessage('toggleVisibility' )
submitBtn.textContent = i18nGetMessage('login' )
urlLabelTxt = browser.i18n.getMessage('cozyUrl' )
twoFaLabelTxt = browser.i18n.getMessage('verificationCode' )
visiPwdBtn.title = browser.i18n.getMessage('toggleVisibility' )
visi2faBtn.title = browser.i18n.getMessage('toggleVisibility' )
submitBtn.textContent = browser.i18n.getMessage('login' )
if (isPinLocked) {
title.textContent = i18nGetMessage('unlockWithPin' )
pwdLabelTxt = i18nGetMessage('pin' )
title.textContent = browser.i18n.getMessage('unlockWithPin' )
pwdLabelTxt = browser.i18n.getMessage('pin' )
urlInput.disabled = true
document.getElementById('url-row').classList.add('disabled')
} else {
title.textContent = i18nGetMessage('loginInPageMenuTitle')
pwdLabelTxt = i18nGetMessage('masterPass' )
title.textContent = browser.i18n.getMessage('loginInPageMenuTitle')
pwdLabelTxt = browser.i18n.getMessage('masterPass' )

console.log('title.textContent', browser.i18n.getMessage('loginInPageMenuTitle'))
}
}

Expand All @@ -115,17 +116,19 @@ document.addEventListener('DOMContentLoaded', () => {
});

// 8- listen to the commands sent by the addon
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
console.log('addListener')
browser.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
console.log('Received message ', msg)
// console.log('loginMenu heared msg', msg);
if (msg.command !== 'menuAnswerRequest') return
switch (msg.subcommand) {
case 'loginNOK':
// console.log("loginNOK heard in loginInPageMenu");
setError(chrome.i18n.getMessage('inPageMenuLoginError'))
setError(browser.i18n.getMessage('inPageMenuLoginError'))
break;
case '2faCheckNOK':
// console.log("2faCheckNOK heard in loginInPageMenu");
setError(chrome.i18n.getMessage('inPageMenuLogin2FACheckError'))
setError(browser.i18n.getMessage('inPageMenuLogin2FACheckError'))
adjustMenuHeight()
break;
case 'setRememberedCozyUrl':
Expand Down Expand Up @@ -189,7 +192,7 @@ document.addEventListener('DOMContentLoaded', () => {
function adjustMenuHeight() {
if (lastSentHeight === panel.offsetHeight) return
lastSentHeight = panel.offsetHeight
chrome.runtime.sendMessage({
browser.runtime.sendMessage({
command : 'bgAnswerMenuRequest' ,
subcommand: 'setMenuHeight' ,
height : lastSentHeight ,
Expand Down Expand Up @@ -227,7 +230,7 @@ async function submit() {
subcommand = 'unlock'
}

chrome.runtime.sendMessage({
browser.runtime.sendMessage({
command : 'bgAnswerMenuRequest',
subcommand: subcommand ,
sender : 'loginMenu.js' ,
Expand All @@ -243,9 +246,9 @@ async function submit() {
]

if (translatableMessages.includes(e.message)) {
setError(chrome.i18n.getMessage(e.message))
setError(browser.i18n.getMessage(e.message))
} else {
setError(chrome.i18n.getMessage('errorOccurred'))
setError(browser.i18n.getMessage('errorOccurred'))
}
}
}
Expand All @@ -262,7 +265,7 @@ async function submit2fa() {
return;
}

chrome.runtime.sendMessage({
browser.runtime.sendMessage({
command : 'bgAnswerMenuRequest',
subcommand: '2faCheck' ,
sender : 'loginMenu.js' ,
Expand Down Expand Up @@ -391,7 +394,7 @@ function setFocusOnEmptyField(){
/* --------------------------------------------------------------------- */
// Request the menu controler to close the iframe of the menu
function close(force) {
chrome.runtime.sendMessage({
browser.runtime.sendMessage({
command : 'bgAnswerMenuRequest',
force : force,
subcommand: 'closeMenu' ,
Expand Down
Loading