Recording - minor fix to popup.js ('0' is a valid tabId), plus whitespace fixes

This commit is contained in:
Francis McKenzie 2020-01-24 09:52:26 +01:00
parent 30a2601d35
commit 46fe530f62
4 changed files with 40 additions and 36 deletions

View file

@ -420,7 +420,7 @@ const assignManager = {
const tab = await browser.tabs.get(tabId);
this.calculateContextMenu(tab);
},
async _getAssignment(tab) {
const cookieStore = this.getUserContextIdFromCookieStore(tab);
// Ensure we have a cookieStore to assign to
@ -430,11 +430,11 @@ const assignManager = {
}
return false;
},
_getByContainer(userContextId) {
return this.storageArea.getByContainer(userContextId);
},
removeContextMenu() {
// There is a focus issue in this menu where if you change window with a context menu click
// you get the wrong menu display because of async

View file

@ -7,7 +7,7 @@ const backgroundLogic = {
"about:blank"
]),
unhideQueue: [],
async getExtensionInfo() {
const manifestPath = browser.extension.getURL("manifest.json");
const response = await fetch(manifestPath);
@ -93,7 +93,7 @@ const backgroundLogic = {
}
});
},
asPromise(value) {
if (value === undefined) { return value; }
if (value instanceof Promise) { return value; }
@ -115,7 +115,7 @@ const backgroundLogic = {
} catch(e) { /* Assume tabId is invalid */ }
}
return null;
},
},
async getTabs(options) {
const requiredArguments = ["cookieStoreId", "windowId"];
@ -371,4 +371,4 @@ const backgroundLogic = {
}
return returnValue;
}
};
};

View file

@ -3,7 +3,7 @@ const messageHandler = {
// We use this to catch redirected tabs that have just opened
// If this were in platform we would change how the tab opens based on "new tab" link navigations such as ctrl+click
LAST_CREATED_TAB_TIMER: 2000,
init() {
// Handles messages from webextension code
browser.runtime.onMessage.addListener((m) => {
@ -80,7 +80,6 @@ const messageHandler = {
response = backgroundLogic.asPromise(backgroundLogic.invokeBrowserMethod(m.name, m.args));
break;
}
return response;
});
@ -264,32 +263,36 @@ const messageHandler = {
} while (!succeeded);
}
handleTabChangedStatus(status) {
if (status === "loading") {
if (!this.tabLoading) {
this.tabLoading = {};
this.tabLoading.promise = new Promise((resolve) => {
this.tabLoading.resolve = resolve;
});
}
} else {
if (this.tabLoading) {
this.tabLoading.resolve();
this.tabLoading = null;
}
handleTabStatusLoading() {
if (!this.tabLoading) {
this.tabLoading = {};
this.tabLoading.promise = new Promise((resolve) => {
this.tabLoading.resolve = resolve;
});
}
}
handleTabStatusComplete() {
if (this.tabLoading) {
this.tabLoading.resolve();
this.tabLoading = null;
}
}
handleTabRemoved() {
this.tabRemoved = true;
this.removeTabListeners();
this.handleTabChangedStatus("complete");
this.handleTabStatusComplete();
}
addTabListeners() {
this.onTabsUpdated = (eventTabId, info) => {
if (this.tabId === eventTabId) {
this.handleTabChangedStatus(info.status);
if (info.status === "loading") {
this.handleTabStatusLoading();
} else {
this.handleTabStatusComplete();
}
}
};

View file

@ -81,7 +81,7 @@ const Env = {
this.tabId = parseInt(tabId, 10);
this.isBrowserActionPopup = false;
} else {
this.tabId = null;
this.tabId = -1;
this.isBrowserActionPopup = this.hasFullBrowserAPI;
}
}
@ -106,15 +106,16 @@ const Logic = {
// API methods are ready, can continue with init
const initializingPanels = this.initializePanels();
// Retrieve the list of identities.
const identitiesPromise = this.refreshIdentities();
try {
await identitiesPromise;
} catch (e) {
throw new Error("Failed to retrieve the identities or variation. We cannot continue. ", e.message);
}
// Remove browserAction "upgraded" badge when opening panel
const clearingBadge = this.clearBrowserActionBadge();
@ -175,7 +176,7 @@ const Logic = {
}
}
},
// Used when popup is running within iframe on a webpage, so lacks privileged API
async injectAPI() {
const script = document.createElement("script");
@ -257,7 +258,7 @@ const Logic = {
},
async currentTab() {
if (Env.tabId) {
if (Env.tabId >= 0) {
return await browser.tabs.get(Env.tabId);
} else {
const activeTabs = await browser.tabs.query({ active: true, windowId: browser.windows.WINDOW_ID_CURRENT });
@ -267,7 +268,7 @@ const Logic = {
return false;
}
},
async numTabs() {
const activeTabs = await browser.tabs.query({ windowId: browser.windows.WINDOW_ID_CURRENT });
return activeTabs.length;
@ -732,19 +733,19 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
if (!isEnabled) {
recordIconElement.src = CONTAINER_RECORD_DISABLED_SRC;
recordLinkElement.classList.remove("active");
recordLinkElement.classList.remove("active");
recordLinkElement.classList.add("disabled");
} else {
recordIconElement.src = CONTAINER_RECORD_ENABLED_SRC;
recordLinkElement.classList.remove("disabled");
if (isActive) {
recordLinkElement.classList.add("active");
recordLinkElement.classList.add("active");
} else {
recordLinkElement.classList.remove("active");
recordLinkElement.classList.remove("active");
}
}
},
async prepareCurrentTabHeader() {
const currentTab = await Logic.currentTab();
const currentTabElement = document.getElementById("current-tab");
@ -774,7 +775,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {
try { await showingPanel; } catch (e) { /* Ignore show error, as we're immediately going to change panel */ }
Logic.showPanel(P_CONTAINERS_LIST);
throw new Error("Failed to " + (newRecordingTab ? "start" : "stop") + " recording: " + e.message);
}
}
});
currentTabElement.hidden = !currentTab;
this.setupAssignmentCheckbox(false, currentTabUserContextId);
@ -1339,7 +1340,7 @@ Logic.registerPanel(P_CONTAINER_RECORD, {
const editPanel = Logic.getPanel(P_CONTAINER_EDIT);
editPanel.showAssignedContainers(assignments, { elementId: "record-sites-assigned", sticky: true });
return Promise.resolve(null);
return Promise.resolve(null);
},
});