From 29a9c0be12a03b9f4fe674c2f01a4b3bb9ca7775 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Thu, 17 Nov 2016 20:00:30 -0800 Subject: [PATCH] Bug 1318371: Flush jar caches by path rather than creating a nsIFile in the content process. r=billm MozReview-Commit-ID: 4J88w5lxEsP --HG-- extra : rebase_source : af96201524bd1caeaf5c1ac2a80e47e8d3111590 extra : amend_source : 12f124c75cb035aa5326fad65cfb2325dc845a3d --- modules/libjar/nsJAR.cpp | 10 +++++++++- toolkit/components/extensions/ExtensionContent.jsm | 5 +---- toolkit/components/extensions/ExtensionTestCommon.jsm | 2 +- toolkit/components/extensions/ExtensionUtils.jsm | 4 ++-- toolkit/mozapps/extensions/internal/Content.js | 6 +----- 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/modules/libjar/nsJAR.cpp b/modules/libjar/nsJAR.cpp index fb9651658598..c53f5605b453 100644 --- a/modules/libjar/nsJAR.cpp +++ b/modules/libjar/nsJAR.cpp @@ -13,6 +13,7 @@ #include "nsIDataSignatureVerifier.h" #include "prprf.h" #include "mozilla/Omnijar.h" +#include "mozilla/Unused.h" #ifdef XP_UNIX #include @@ -1360,7 +1361,14 @@ nsZipReaderCache::Observe(nsISupports *aSubject, mZips.Clear(); } else if (strcmp(aTopic, "flush-cache-entry") == 0) { - nsCOMPtr file = do_QueryInterface(aSubject); + nsCOMPtr file; + if (aSubject) { + file = do_QueryInterface(aSubject); + } else if (aSomeData) { + nsDependentString fileName(aSomeData); + Unused << NS_NewLocalFile(fileName, false, getter_AddRefs(file)); + } + if (!file) return NS_OK; diff --git a/toolkit/components/extensions/ExtensionContent.jsm b/toolkit/components/extensions/ExtensionContent.jsm index e5cda504f6d0..53a2fff41d74 100644 --- a/toolkit/components/extensions/ExtensionContent.jsm +++ b/toolkit/components/extensions/ExtensionContent.jsm @@ -895,10 +895,7 @@ ExtensionManager = { } case "Extension:FlushJarCache": { - let nsIFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile", - "initWithPath"); - let file = new nsIFile(data.path); - flushJarCache(file); + flushJarCache(data.path); Services.cpmm.sendAsyncMessage("Extension:FlushJarCacheComplete"); break; } diff --git a/toolkit/components/extensions/ExtensionTestCommon.jsm b/toolkit/components/extensions/ExtensionTestCommon.jsm index 5fe44fa4dc43..a3514fe62edf 100644 --- a/toolkit/components/extensions/ExtensionTestCommon.jsm +++ b/toolkit/components/extensions/ExtensionTestCommon.jsm @@ -314,7 +314,7 @@ class ExtensionTestCommon { static generate(data) { let file = this.generateXPI(data); - flushJarCache(file); + flushJarCache(file.path); Services.ppmm.broadcastAsyncMessage("Extension:FlushJarCache", {path: file.path}); let fileURI = Services.io.newFileURI(file); diff --git a/toolkit/components/extensions/ExtensionUtils.jsm b/toolkit/components/extensions/ExtensionUtils.jsm index 95c1199ca56f..b8585f78c48a 100644 --- a/toolkit/components/extensions/ExtensionUtils.jsm +++ b/toolkit/components/extensions/ExtensionUtils.jsm @@ -885,8 +885,8 @@ function getMessageManager(target) { return target.QueryInterface(Ci.nsIMessageSender); } -function flushJarCache(jarFile) { - Services.obs.notifyObservers(jarFile, "flush-cache-entry", null); +function flushJarCache(jarPath) { + Services.obs.notifyObservers(null, "flush-cache-entry", jarPath); } const PlatformInfo = Object.freeze({ diff --git a/toolkit/mozapps/extensions/internal/Content.js b/toolkit/mozapps/extensions/internal/Content.js index 9f366ba32799..4a37be60b56f 100644 --- a/toolkit/mozapps/extensions/internal/Content.js +++ b/toolkit/mozapps/extensions/internal/Content.js @@ -12,9 +12,6 @@ var {classes: Cc, interfaces: Ci, utils: Cu} = Components; var {Services} = Cu.import("resource://gre/modules/Services.jsm", {}); -var nsIFile = Components.Constructor("@mozilla.org/file/local;1", "nsIFile", - "initWithPath"); - const MSG_JAR_FLUSH = "AddonJarFlush"; const MSG_MESSAGE_MANAGER_CACHES_FLUSH = "AddonMessageManagerCachesFlush"; @@ -23,8 +20,7 @@ try { if (Services.appinfo.processType !== Services.appinfo.PROCESS_TYPE_DEFAULT) { // Propagate JAR cache flush notifications across process boundaries. addMessageListener(MSG_JAR_FLUSH, function(message) { - let file = new nsIFile(message.data); - Services.obs.notifyObservers(file, "flush-cache-entry", null); + Services.obs.notifyObservers(null, "flush-cache-entry", message.data); }); // Propagate message manager caches flush notifications across processes. addMessageListener(MSG_MESSAGE_MANAGER_CACHES_FLUSH, function() {