Skip to content

Commit

Permalink
Merge pull request #327 from alpheios-project/i325-remove-permissions3
Browse files Browse the repository at this point in the history
Remove permissions (tabs.onUpdated)
  • Loading branch information
irina060981 authored Nov 17, 2021
2 parents d17e8c0 + ca8a4c9 commit 5f42251
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions src/background/background-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default class BackgroundProcess {
browser.tabs.onAttached.addListener(this.tabAttachedListener.bind(this))
browser.tabs.onRemoved.addListener(this.tabRemovalListener.bind(this))
browser.tabs.onCreated.addListener(this.tabCreatedListener.bind(this))
browser.webNavigation.onCompleted.addListener(this.navigationCompletedListener.bind(this))
browser.tabs.onUpdated.addListener(this.navigationCompletedListener.bind(this))
browser.runtime.onUpdateAvailable.addListener(this.updateAvailableListener.bind(this))
browser.runtime.onInstalled.addListener(this.handleOnInstalled.bind(this))

Expand Down Expand Up @@ -240,7 +240,6 @@ export default class BackgroundProcess {
let newTab = new TabScript(tabObj) // eslint-disable-line prefer-const
newTab.tab = TabScript.props.tab.values.INFO // Set active tab to `info` by default
this.tabs.set(tabObj.uniqueId, newTab)

try {
await this.loadContentData(newTab)
} catch (error) {
Expand Down Expand Up @@ -576,6 +575,19 @@ export default class BackgroundProcess {
this.setBadgeState()
}

definedWindowIdByTabNum (tabId) {
let savedTab

for (let i = 0; i < this.tabs.size; i++) {
const tabsIter = this.tabs.values()
const tabInstance = tabsIter.next().value
if (tabInstance.tabObj && tabInstance.tabObj.tabId === tabId) {
savedTab = tabInstance
}
}
return savedTab ? savedTab.tabObj.windowId : 1
}

/**
* Called when a page is loaded.
* Use this to listen on webNavigation.onCompleted rather than tabs.onUpdated
Expand All @@ -586,40 +598,23 @@ export default class BackgroundProcess {
* @param details
* @return {Promise.<void>}
*/
async navigationCompletedListener (details) {
// on Firefox, a click the download blob url for downloading
// the user wordlist causes Firefox to issue a webNavigationCompleted
// event. so we should ignore events whose urls are blob: urls
if (details.url && details.url.match(/^blob:/)) {
return
}
const finalWindowId = this.defineCurrentWindowIdForActivation(details)
const tmpTabUniqueId = Tab.createUniqueId(details.tabId, finalWindowId)
async navigationCompletedListener (tabId) {
const finalWindowId = this.definedWindowIdByTabNum(tabId)
const tmpTabUniqueId = Tab.createUniqueId(tabId, finalWindowId)

if (this.tabs.has(tmpTabUniqueId)) {
const tab = this.tabs.get(tmpTabUniqueId)
// make sure this is a tab we know about
if (details.frameId === 0) {
// AND that it's not an iframe event
try {
await this.loadContentData(tab)
this.setContentState(tab)
this.checkEmbeddedContent(details.tabId)
this.notifyPageLoad(details.tabId)
if (tab.isActive()) {
this.notifyPageActive(details.tabId)
}
this.setBadgeState(tab)
} catch (error) {
console.error(`Cannot load content script for a tab with an ID of tabId = ${details.tabId}, windowId = ${details.windowId}`)
try {
await this.loadContentData(tab)
this.setContentState(tab)
this.checkEmbeddedContent(tabId)
this.notifyPageLoad(tabId)
if (tab.isActive()) {
this.notifyPageActive(tabId)
}
// but if it is an iFrame event
// firefox resets the browserAction icon and title when the user navigates to a new page
// even when the navigation is in a frame so we need to be sure it's updated
} else if (tab.isActive()) {
this.setIconState(tab)
this.setBadgeState(tab)
this.updateBrowserActionForTab(this.tabs.get(tmpTabUniqueId))
} catch (error) {
console.error(`Cannot load content script for a tab with an ID of tabId = ${tabId}, windowId = ${finalWindowId}`)
}
}
}
Expand Down Expand Up @@ -729,7 +724,6 @@ export default class BackgroundProcess {
}

setMenuForTab (tab) {
//
// Deactivate all previously activated menu items to keep an order intact
this.menuItems.activate.disable()
this.menuItems.deactivate.disable()
Expand Down

0 comments on commit 5f42251

Please sign in to comment.