|
@@ -34,6 +34,7 @@ const ERROR_CONNECTION_ERROR_CHROMIUM = "Could not establish connection. Receivi
|
|
|
const ERROR_CONNECTION_LOST_CHROMIUM = "The message port closed before a response was received.";
|
|
const ERROR_CONNECTION_LOST_CHROMIUM = "The message port closed before a response was received.";
|
|
|
const ERROR_CONNECTION_LOST_GECKO = "Message manager disconnected";
|
|
const ERROR_CONNECTION_LOST_GECKO = "Message manager disconnected";
|
|
|
const ERROR_EDITOR_PAGE_CHROMIUM = "Cannot access contents of url ";
|
|
const ERROR_EDITOR_PAGE_CHROMIUM = "Cannot access contents of url ";
|
|
|
|
|
+const ERROR_CHANNEL_CLOSED_CHROMIUM = "A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received";
|
|
|
const INJECT_SCRIPTS_STEP = 1;
|
|
const INJECT_SCRIPTS_STEP = 1;
|
|
|
const EXECUTE_SCRIPTS_STEP = 2;
|
|
const EXECUTE_SCRIPTS_STEP = 2;
|
|
|
const TASK_PENDING_STATE = "pending";
|
|
const TASK_PENDING_STATE = "pending";
|
|
@@ -160,11 +161,13 @@ function addTask(info) {
|
|
|
tab: info.tab,
|
|
tab: info.tab,
|
|
|
options: info.options,
|
|
options: info.options,
|
|
|
method: info.method,
|
|
method: info.method,
|
|
|
- done: function () {
|
|
|
|
|
|
|
+ done: function (runNextTasks = true) {
|
|
|
const index = tasks.findIndex(taskInfo => taskInfo.id == this.id);
|
|
const index = tasks.findIndex(taskInfo => taskInfo.id == this.id);
|
|
|
if (index > -1) {
|
|
if (index > -1) {
|
|
|
tasks.splice(index, 1);
|
|
tasks.splice(index, 1);
|
|
|
- runTasks();
|
|
|
|
|
|
|
+ if (runNextTasks) {
|
|
|
|
|
+ runTasks();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -235,6 +238,7 @@ function isIgnoredError(error) {
|
|
|
return error.message == ERROR_CONNECTION_LOST_CHROMIUM ||
|
|
return error.message == ERROR_CONNECTION_LOST_CHROMIUM ||
|
|
|
error.message == ERROR_CONNECTION_ERROR_CHROMIUM ||
|
|
error.message == ERROR_CONNECTION_ERROR_CHROMIUM ||
|
|
|
error.message == ERROR_CONNECTION_LOST_GECKO ||
|
|
error.message == ERROR_CONNECTION_LOST_GECKO ||
|
|
|
|
|
+ error.message == ERROR_CHANNEL_CLOSED_CHROMIUM ||
|
|
|
error.message.startsWith(ERROR_EDITOR_PAGE_CHROMIUM + JSON.stringify(editor.EDITOR_URL));
|
|
error.message.startsWith(ERROR_EDITOR_PAGE_CHROMIUM + JSON.stringify(editor.EDITOR_URL));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -243,7 +247,7 @@ function isSavingTab(tab) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function onInit(tab) {
|
|
function onInit(tab) {
|
|
|
- cancelTab(tab.id);
|
|
|
|
|
|
|
+ cancelTab(tab.id, false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function onTabReplaced(addedTabId, removedTabId) {
|
|
function onTabReplaced(addedTabId, removedTabId) {
|
|
@@ -292,8 +296,12 @@ function setCancelCallback(taskId, cancelCallback) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function cancelTab(tabId) {
|
|
|
|
|
- Array.from(tasks).filter(taskInfo => taskInfo.tab.id == tabId && !taskInfo.options.autoSave).forEach(cancel);
|
|
|
|
|
|
|
+function cancelTab(tabId, stopProcessing = true) {
|
|
|
|
|
+ Array.from(tasks).filter(taskInfo =>
|
|
|
|
|
+ taskInfo.tab.id == tabId &&
|
|
|
|
|
+ !taskInfo.options.autoSave &&
|
|
|
|
|
+ (stopProcessing || taskInfo.status != TASK_PROCESSING_STATE)
|
|
|
|
|
+ ).forEach(cancel);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function cancelTask(taskId) {
|
|
function cancelTask(taskId) {
|
|
@@ -301,7 +309,7 @@ function cancelTask(taskId) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function cancelAllTasks() {
|
|
function cancelAllTasks() {
|
|
|
- Array.from(tasks).forEach(cancel);
|
|
|
|
|
|
|
+ Array.from(tasks).forEach(taskInfo => cancel(taskInfo, false));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function getTasksInfo() {
|
|
function getTasksInfo() {
|
|
@@ -312,24 +320,28 @@ function getTaskInfo(taskId) {
|
|
|
return tasks.find(taskInfo => taskInfo.id == taskId);
|
|
return tasks.find(taskInfo => taskInfo.id == taskId);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function cancel(taskInfo) {
|
|
|
|
|
|
|
+function cancel(taskInfo, runNextTasks) {
|
|
|
const tabId = taskInfo.tab.id;
|
|
const tabId = taskInfo.tab.id;
|
|
|
taskInfo.cancelled = true;
|
|
taskInfo.cancelled = true;
|
|
|
- browser.tabs.sendMessage(tabId, {
|
|
|
|
|
- method: "content.cancelSave",
|
|
|
|
|
- options: {
|
|
|
|
|
- loadDeferredImages: taskInfo.options.loadDeferredImages,
|
|
|
|
|
- loadDeferredImagesKeepZoomLevel: taskInfo.options.loadDeferredImagesKeepZoomLevel
|
|
|
|
|
|
|
+ if (tabId) {
|
|
|
|
|
+ browser.tabs.sendMessage(tabId, {
|
|
|
|
|
+ method: "content.cancelSave",
|
|
|
|
|
+ options: {
|
|
|
|
|
+ loadDeferredImages: taskInfo.options.loadDeferredImages,
|
|
|
|
|
+ loadDeferredImagesKeepZoomLevel: taskInfo.options.loadDeferredImagesKeepZoomLevel
|
|
|
|
|
+ }
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ // ignored
|
|
|
|
|
+ });
|
|
|
|
|
+ if (taskInfo.method == "content.autosave") {
|
|
|
|
|
+ ui.onEnd(tabId, true);
|
|
|
}
|
|
}
|
|
|
- });
|
|
|
|
|
|
|
+ ui.onCancelled(taskInfo.tab);
|
|
|
|
|
+ }
|
|
|
if (taskInfo.cancel) {
|
|
if (taskInfo.cancel) {
|
|
|
taskInfo.cancel();
|
|
taskInfo.cancel();
|
|
|
}
|
|
}
|
|
|
- if (taskInfo.method == "content.autosave") {
|
|
|
|
|
- ui.onEnd(tabId, true);
|
|
|
|
|
- }
|
|
|
|
|
- ui.onCancelled(taskInfo.tab);
|
|
|
|
|
- taskInfo.done();
|
|
|
|
|
|
|
+ taskInfo.done(runNextTasks);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function mapTaskInfo(taskInfo) {
|
|
function mapTaskInfo(taskInfo) {
|