[rs-commit] r70 - in /redwax-signtext/trunk/src/linux: chrome/background.js firefox/background.js firefox/content.js
rs-commit at redwax.eu
rs-commit at redwax.eu
Mon Sep 19 17:16:44 CEST 2022
Author: minfrin at redwax.eu
Date: Mon Sep 19 17:16:44 2022
New Revision: 70
Log:
Make sure the errors were correctly wired back.
Modified:
redwax-signtext/trunk/src/linux/chrome/background.js
redwax-signtext/trunk/src/linux/firefox/background.js
redwax-signtext/trunk/src/linux/firefox/content.js
Modified: redwax-signtext/trunk/src/linux/chrome/background.js
==============================================================================
--- redwax-signtext/trunk/src/linux/chrome/background.js (original)
+++ redwax-signtext/trunk/src/linux/chrome/background.js Mon Sep 19 17:16:44 2022
@@ -15,9 +15,14 @@
csPorts.forEach(p => {
if (p.sender.tab.id == m.id) {
- console.log('Redwax SignText: background: message passed from native to content: ', m);
+ console.log('Redwax SignText: background: message passed from native to content: ', m);
- p.postMessage({ uuid: m.uuid, response: m.response, contentType: m.contentType });
+ if (typeof m.error !== "undefined") {
+ p.postMessage({ uuid: m.uuid, error: m.error, contentType: m.contentType });
+ }
+ else {
+ p.postMessage({ uuid: m.uuid, response: m.response, contentType: m.contentType });
+ }
}
});
}
Modified: redwax-signtext/trunk/src/linux/firefox/background.js
==============================================================================
--- redwax-signtext/trunk/src/linux/firefox/background.js (original)
+++ redwax-signtext/trunk/src/linux/firefox/background.js Mon Sep 19 17:16:44 2022
@@ -15,9 +15,14 @@
window.csPorts.forEach(p => {
if (p.sender.tab.id == m.id) {
- console.log('Redwax SignText: background: message passed from native to content: ', m);
+ console.log('Redwax SignText: background: message passed from native to content: ', m);
- p.postMessage({ uuid: m.uuid, response: m.response, contentType: m.contentType });
+ if (typeof m.error !== "undefined") {
+ p.postMessage({ uuid: m.uuid, error: m.error, contentType: m.contentType });
+ }
+ else {
+ p.postMessage({ uuid: m.uuid, response: m.response, contentType: m.contentType });
+ }
}
});
}
Modified: redwax-signtext/trunk/src/linux/firefox/content.js
==============================================================================
--- redwax-signtext/trunk/src/linux/firefox/content.js (original)
+++ redwax-signtext/trunk/src/linux/firefox/content.js Mon Sep 19 17:16:44 2022
@@ -74,13 +74,18 @@
const signTextHandler = function(e) {
/* message not for us */
- if (!(e.uuid === undefined) && !(e.uuid === uuid)) {
+ if ((typeof e.uuid === "undefined") || (e.uuid !== uuid)) {
/* do nothing */
}
/* an error was received, cancel the stream */
- else if (e.error) {
+ else if (typeof e.error !== "undefined") {
const error = new window.wrappedJSObject.Error(e.error);
stringReject(error);
+ port.onMessage.removeListener(signTextHandler);
+ }
+ /* no response, weird, throw an error back */
+ else if (typeof e.response === "undefined") {
+ stringReject(new Error("error:noResponse"));
port.onMessage.removeListener(signTextHandler);
}
/* an ack was received, send the next chunk */
@@ -159,138 +164,3 @@
}
-/*
- * Chrome / Safari
- * ===============
- *
- * We cannot exportFunction on Chrome or Safari. Instead, pass messages using document.dispatchEvent
- * to get data back and forth.
- */
-else {
-
- port.onMessage.addListener((message) => {
- document.dispatchEvent(new CustomEvent('eu.redwax.signTextResponse', {
- bubbles: true,
- detail: message
- }));
- });
-
- port.onDisconnect.addListener((p) => {
- if (p.error) {
- console.log(`Redwax SignText: disconnected due to an error: ${p.error.message}`);
- } else {
- console.log(`Redwax SignText: disconnected`);
- }
- });
-
-
- /*
- * Handle all webpage signtext info events, return our version
- * information.
- */
- document.addEventListener('eu.redwax.signTextRequestInfo', function(e) {
- /*
- * We've been asked for info about the signtext extension.
- *
- * This can be used to detect support for the extension
- * before trying to use it.
- */
- const manifest = browser.runtime.getManifest();
- e.target.dispatchEvent(new CustomEvent('eu.redwax.signTextResponseInfo', {
- bubbles: true,
- detail: {
- name: manifest.name,
- version: manifest.version
- }
- }));
-
- });
-
- /*
- * Handle all webpage signtext events, passing them as approriate
- * to the background script.
- */
- document.addEventListener('eu.redwax.signTextRequest', function(e) {
- /*
- * We've been asked to sign a specific request. Check the
- * request, and pass the request to the background if the
- * check passes.
- */
- if (e.detail.request) {
-
- /*
- * UUID valid? If not, complain.
- */
- if (typeof e.detail.uuid !== 'string') {
- /* error - uuid is missing or invalid */
- e.target.dispatchEvent(new CustomEvent('eu.redwax.signTextResponse', {
- bubbles: true,
- detail: {
- uuid: e.detail.uuid,
- error: 'error:uuidInvalid'
- }
- }));
- }
-
- /*
- * Hostname valid? If not, complain.
- */
- if (typeof e.detail.hostname !== 'string') {
- /* error - hostname is missing or invalid */
- e.target.dispatchEvent(new CustomEvent('eu.redwax.signTextResponse', {
- bubbles: true,
- detail: {
- uuid: e.detail.uuid,
- error: 'error:hostnameInvalid'
- }
- }));
- }
-
- /*
- * Content Type valid? If not, complain.
- */
- switch (e.detail.contentType) {
- case undefined:
- case 'text/plain':
- case 'application/pkcs7-mime': {
-
- /*
- * Checks have passed, send message to background script.
- */
- try {
- port.postMessage({
- uuid: e.detail.uuid,
- hostname: e.hostname,
- protocol: e.protocol,
- request: e.detail.request,
- contentType: e.detail.contentType
- });
- } catch (exception) {
- e.target.dispatchEvent(new CustomEvent('eu.redwax.signTextResponse', {
- bubbles: true,
- detail: {
- uuid: e.detail.uuid,
- error: 'error:postMessageFailed',
- exception: exception
- }
- }));
- }
-
- break;
- }
- default: {
- /* error - mime type unrecognised */
- e.target.dispatchEvent(new CustomEvent('eu.redwax.signTextResponse', {
- bubbles: true,
- detail: {
- uuid: e.detail.uuid,
- error: 'error:contentTypeUnrecognised'
- }
- }));
- }
- }
-
- }
- });
-
-}
More information about the rs-commit
mailing list