From bec832518f401a4035c7264c124f50b74669013e Mon Sep 17 00:00:00 2001 From: Geoff Lankow Date: Wed, 16 Nov 2022 23:12:37 +1300 Subject: [PATCH] Bug 1799764 - Reinstate OpenPGP UI code and enable some tests. r=aleca Differential Revision: https://phabricator.services.mozilla.com/D162688 --HG-- extra : rebase_source : 056408c81be89568b56e4775809e9a9191b90145 extra : source : d5fa37cb60ce653ed2380b0c292976d1fd20a14e --- mail/base/content/about3Pane.js | 6 +- mail/base/content/aboutMessage.js | 5 +- mail/base/content/aboutMessage.xhtml | 2 + .../openpgp/content/modules/mimeVerify.jsm | 61 ++++--------------- .../content/ui/enigmailMsgHdrViewOverlay.js | 6 +- .../smime/content/msgHdrViewSMIMEOverlay.js | 35 ++++++----- .../browser/openpgp/composition/browser.ini | 7 ++- mailnews/mime/test/unit/head_mime.js | 27 +------- .../mime/test/unit/test_openpgp_decrypt.js | 14 +---- 9 files changed, 48 insertions(+), 115 deletions(-) diff --git a/mail/base/content/about3Pane.js b/mail/base/content/about3Pane.js index b5fe5edd71..693bbf61c2 100644 --- a/mail/base/content/about3Pane.js +++ b/mail/base/content/about3Pane.js @@ -295,11 +295,11 @@ window.addEventListener("DOMContentLoaded", event => { } if (gFolder.isSpecialFolder(Ci.nsMsgFolderFlags.Drafts, true)) { - commandController.doCommand("cmd_editDraftMsg"); + commandController.doCommand("cmd_editDraftMsg", event); } else if (gFolder.isSpecialFolder(Ci.nsMsgFolderFlags.Templates, true)) { - commandController.doCommand("cmd_newMsgFromTemplate"); + commandController.doCommand("cmd_newMsgFromTemplate", event); } else { - commandController.doCommand("cmd_openMessage"); + commandController.doCommand("cmd_openMessage", event); } }); diff --git a/mail/base/content/aboutMessage.js b/mail/base/content/aboutMessage.js index 207ce8ece6..8a51adffb7 100644 --- a/mail/base/content/aboutMessage.js +++ b/mail/base/content/aboutMessage.js @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ -/* globals MailE10SUtils */ +/* globals Enigmail, MailE10SUtils */ // mailCommon.js /* globals commandController, dbViewWrapperListener */ @@ -126,6 +126,9 @@ window.addEventListener("DOMContentLoaded", event => { content = document.querySelector("browser"); OnLoadMsgHeaderPane(); + Enigmail.msg.messengerStartup(); + Enigmail.hdrView.hdrViewLoad(); + // The folder listener only does something interesting if this is a // standalone window or tab, so don't add it if we're inside about:3pane. if (window.browsingContext.parent.currentURI.spec != "about:3pane") { diff --git a/mail/base/content/aboutMessage.xhtml b/mail/base/content/aboutMessage.xhtml index 37254113c0..db149cc947 100644 --- a/mail/base/content/aboutMessage.xhtml +++ b/mail/base/content/aboutMessage.xhtml @@ -62,6 +62,8 @@ + + diff --git a/mail/extensions/openpgp/content/modules/mimeVerify.jsm b/mail/extensions/openpgp/content/modules/mimeVerify.jsm index b00d78c21b..6c95335f2b 100644 --- a/mail/extensions/openpgp/content/modules/mimeVerify.jsm +++ b/mail/extensions/openpgp/content/modules/mimeVerify.jsm @@ -10,9 +10,6 @@ const EXPORTED_SYMBOLS = ["EnigmailVerify"]; * Module for handling PGP/MIME signed messages implemented as JS module. */ -const { MailServices } = ChromeUtils.import( - "resource:///modules/MailServices.jsm" -); const { XPCOMUtils } = ChromeUtils.importESModule( "resource://gre/modules/XPCOMUtils.sys.mjs" ); @@ -55,7 +52,7 @@ function MimeVerify(protocol) { var EnigmailVerify = { _initialized: false, - lastMsgWindow: null, + lastWindow: null, lastMsgUri: null, manualMsgUri: null, @@ -76,10 +73,10 @@ var EnigmailVerify = { } }, - setMsgWindow(msgWindow, msgUriSpec) { - LOCAL_DEBUG("mimeVerify.jsm: setMsgWindow: " + msgUriSpec + "\n"); + setWindow(window, msgUriSpec) { + LOCAL_DEBUG("mimeVerify.jsm: setWindow: " + msgUriSpec + "\n"); - this.lastMsgWindow = msgWindow; + this.lastWindow = window; this.lastMsgUri = msgUriSpec; }, @@ -154,10 +151,9 @@ MimeVerify.prototype = { dataCount: 0, foundMsg: false, startMsgStr: "", - msgWindow: null, + window: null, msgUriSpec: null, statusDisplayed: false, - window: null, inStream: null, sigFile: null, sigData: "", @@ -165,36 +161,6 @@ MimeVerify.prototype = { QueryInterface: ChromeUtils.generateQI(["nsIStreamListener"]), - startStreaming(window, msgWindow, msgUriSpec) { - LOCAL_DEBUG("mimeVerify.jsm: startStreaming\n"); - - this.msgWindow = msgWindow; - this.msgUriSpec = msgUriSpec; - this.window = window; - let msgSvc = MailServices.messageServiceFromURI(this.msgUriSpec); - - msgSvc.streamMessage( - this.msgUriSpec, - this, - this.msgWindow, - null, - false, - null, - false - ); - }, - - verifyData(window, msgWindow, msgUriSpec, data) { - LOCAL_DEBUG("mimeVerify.jsm: streamFromChannel\n"); - - this.msgWindow = msgWindow; - this.msgUriSpec = msgUriSpec; - this.window = window; - this.onStartRequest(); - this.onTextData(data); - this.onStopRequest(); - }, - parseContentType() { let contentTypeLine = this.mimeSvc.contentType; @@ -495,7 +461,7 @@ MimeVerify.prototype = { onStopRequest() { lazy.EnigmailLog.DEBUG("mimeVerify.jsm: onStopRequest\n"); - this.msgWindow = EnigmailVerify.lastMsgWindow; + this.window = EnigmailVerify.lastWindow; this.msgUriSpec = EnigmailVerify.lastMsgUri; this.backgroundJob = false; @@ -610,8 +576,7 @@ MimeVerify.prototype = { } if (this.protocol === PGPMIME_PROTO) { - var windowManager = Services.wm; - var win = windowManager.getMostRecentWindow(null); + let win = this.window; if (!lazy.EnigmailDecryption.isReady(win)) { return; @@ -678,13 +643,11 @@ MimeVerify.prototype = { this.mimeSvc.outputDecryptedData(data, data.length); }, - setMsgWindow(msgWindow, msgUriSpec) { - lazy.EnigmailLog.DEBUG( - "mimeVerify.jsm: setMsgWindow: " + msgUriSpec + "\n" - ); + setWindow(window, msgUriSpec) { + lazy.EnigmailLog.DEBUG("mimeVerify.jsm: setWindow: " + msgUriSpec + "\n"); - if (!this.msgWindow) { - this.msgWindow = msgWindow; + if (!this.window) { + this.window = window; this.msgUriSpec = msgUriSpec; } }, @@ -693,7 +656,7 @@ MimeVerify.prototype = { lazy.EnigmailLog.DEBUG("mimeVerify.jsm: displayStatus\n"); if ( this.exitCode === null || - this.msgWindow === null || + this.window === null || this.statusDisplayed || this.backgroundJob ) { diff --git a/mail/extensions/openpgp/content/ui/enigmailMsgHdrViewOverlay.js b/mail/extensions/openpgp/content/ui/enigmailMsgHdrViewOverlay.js index 4ccc2572de..290f49853a 100644 --- a/mail/extensions/openpgp/content/ui/enigmailMsgHdrViewOverlay.js +++ b/mail/extensions/openpgp/content/ui/enigmailMsgHdrViewOverlay.js @@ -567,10 +567,7 @@ Enigmail.hdrView = { try { Enigmail.hdrView.statusBarHide(); - EnigmailVerify.setMsgWindow( - msgWindow, - Enigmail.msg.getCurrentMsgUriSpec() - ); + EnigmailVerify.setWindow(window, Enigmail.msg.getCurrentMsgUriSpec()); let msgFrame = document.getElementById("messagepane").contentDocument; @@ -600,6 +597,7 @@ Enigmail.hdrView = { ); try { + EnigmailVerify.setWindow(null, null); Enigmail.hdrView.statusBarHide(); } catch (ex) {} }, diff --git a/mail/extensions/smime/content/msgHdrViewSMIMEOverlay.js b/mail/extensions/smime/content/msgHdrViewSMIMEOverlay.js index 1e42922303..1775df3a19 100644 --- a/mail/extensions/smime/content/msgHdrViewSMIMEOverlay.js +++ b/mail/extensions/smime/content/msgHdrViewSMIMEOverlay.js @@ -4,8 +4,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ /* import-globals-from ../../../../mailnews/extensions/smime/msgReadSMIMEOverlay.js */ -/* import-globals-from ../../../base/content/folderDisplay.js */ -/* import-globals-from ../../../base/content/mailWindow.js */ /* import-globals-from ../../../base/content/msgHdrView.js */ var gEncryptedURIService = null; @@ -291,21 +289,22 @@ var smimeHeaderSink = { .GetStringFromName("CantDecryptBody") .replace(/%brand%/g, brand); - // insert our message - msgWindow.displayHTMLInMessagePane( - title, - "\n" + - '\n' + - "



\n" + - "\n" + - "
\n" + - '
\n' + - title + - "

\n" + - body + - "\n" + - "
", - false + // TODO: This should be replaced with a real page, and made not ugly. + HideMessageHeaderPane(); + MailE10SUtils.loadURI( + content, + "data:text/html;base64," + + btoa( + ` + + ${title} + + +

${title}

+ ${body} + + ` + ) ); break; } @@ -386,7 +385,7 @@ function msgHdrViewSMIMEOnLoad(event) { // we want to register our security header sink as an opaque nsISupports // on the msgHdrSink used by mail..... - msgWindow.msgHeaderSink.securityInfo = smimeHeaderSink; + top.msgWindow.msgHeaderSink.securityInfo = smimeHeaderSink; // Add ourself to the list of message display listeners so we get notified // when we are about to display a message. diff --git a/mail/test/browser/openpgp/composition/browser.ini b/mail/test/browser/openpgp/composition/browser.ini index 1ce2dcf898..6e2fa0fba8 100644 --- a/mail/test/browser/openpgp/composition/browser.ini +++ b/mail/test/browser/openpgp/composition/browser.ini @@ -9,11 +9,12 @@ prefs = mailnews.start_page.url=about:blank subsuite = thunderbird support-files = ../data/** -skip-if = true # TODO [browser_composeSigned.js] -skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH +skip-if = true # TODO +# skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH [browser_composeEncrypted.js] -skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH +skip-if = true # TODO +# skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH [browser_composeSwitchIdentity.js] skip-if = debug # Bug 1673652 - L10NRegistry throws NS_ERROR_FILE_UNRECOGNIZED_PATH diff --git a/mailnews/mime/test/unit/head_mime.js b/mailnews/mime/test/unit/head_mime.js index 33034fbc51..2b98fa336e 100644 --- a/mailnews/mime/test/unit/head_mime.js +++ b/mailnews/mime/test/unit/head_mime.js @@ -31,37 +31,14 @@ registerCleanupFunction(function() { load(gDEPTH + "mailnews/resources/mailShutdown.js"); }); -function apply_mime_conversion(msgUri, headerSink = {}, msgWindow = undefined) { - let stubHeaderSink = { - securityInfo: null, - QueryInterface: ChromeUtils.generateQI(["nsIMsgHeaderSink"]), - }; - - // Copy the descriptors from headerSink to stubHeaderSink. - let fullHeaderSink = Object.create(headerSink); - for (let name of Object.getOwnPropertyNames(stubHeaderSink)) { - if (!(name in headerSink)) { - Object.defineProperty( - fullHeaderSink, - name, - Object.getOwnPropertyDescriptor(stubHeaderSink, name) - ); - } - } - - msgWindow = - msgWindow || - Cc["@mozilla.org/messenger/msgwindow;1"].createInstance(Ci.nsIMsgWindow); - - msgWindow.msgHeaderSink = fullHeaderSink; - +function apply_mime_conversion(msgUri, smimeHeaderSink) { let service = MailServices.messageServiceFromURI(msgUri); // This is what we listen on in the end. let listener = new PromiseTestUtils.PromiseStreamListener(); // Make the underlying channel--we need this for the converter parameter. - let url = service.getUrlForUri(msgUri, msgWindow); + let url = service.getUrlForUri(msgUri); let channel = Services.io.newChannelFromURI( url, diff --git a/mailnews/mime/test/unit/test_openpgp_decrypt.js b/mailnews/mime/test/unit/test_openpgp_decrypt.js index ef7025f882..53de9d2f49 100644 --- a/mailnews/mime/test/unit/test_openpgp_decrypt.js +++ b/mailnews/mime/test/unit/test_openpgp_decrypt.js @@ -322,25 +322,15 @@ add_task(async function testMimeDecryptOpenPGPMessages() { let uri = hdr.folder.getUriForMsg(hdr); let sinkPromise = headerSink.expectResults(expectedResultCount); - let msgWindow = Cc["@mozilla.org/messenger/msgwindow;1"].createInstance( - Ci.nsIMsgWindow - ); - // Set the message window so displayStatus() invokes the hooks we are // interested in. - EnigmailVerify.lastMsgWindow = msgWindow; + EnigmailVerify.lastWindow = {}; // Stub this function so verifyDetached() can get the correct email. EnigmailDecryption.getFromAddr = () => test.from; // Trigger the actual mime work. - let conversion = apply_mime_conversion( - uri, - { - securityInfo: headerSink, - }, - msgWindow - ); + let conversion = apply_mime_conversion(uri, headerSink); await conversion.promise;