Bug 1318371: Flush jar caches by path rather than creating a nsIFile in the content process. r?billm draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 17 Nov 2016 20:00:30 -0800
changeset 441000 af96201524bd1caeaf5c1ac2a80e47e8d3111590
parent 440999 06ef26669994ec4018e5072defb55b1af360c9f2
child 537461 30bd22012a7027ac134b6e53e3b36f8a89fea6a1
push id36323
push usermaglione.k@gmail.com
push dateFri, 18 Nov 2016 04:01:01 +0000
reviewersbillm
bugs1318371
milestone53.0a1
Bug 1318371: Flush jar caches by path rather than creating a nsIFile in the content process. r?billm MozReview-Commit-ID: 4J88w5lxEsP
modules/libjar/nsJAR.cpp
toolkit/components/extensions/ExtensionContent.jsm
toolkit/components/extensions/ExtensionTestCommon.jsm
toolkit/components/extensions/ExtensionUtils.jsm
toolkit/mozapps/extensions/internal/Content.js
--- a/modules/libjar/nsJAR.cpp
+++ b/modules/libjar/nsJAR.cpp
@@ -8,16 +8,17 @@
 #include "nsJAR.h"
 #include "nsIFile.h"
 #include "nsIX509Cert.h"
 #include "nsIConsoleService.h"
 #include "nsICryptoHash.h"
 #include "nsIDataSignatureVerifier.h"
 #include "prprf.h"
 #include "mozilla/Omnijar.h"
+#include "mozilla/Unused.h"
 
 #ifdef XP_UNIX
   #include <sys/stat.h>
 #elif defined (XP_WIN)
   #include <io.h>
 #endif
 
 using namespace mozilla;
@@ -1355,17 +1356,24 @@ nsZipReaderCache::Observe(nsISupports *a
   else if (strcmp(aTopic, "chrome-flush-caches") == 0) {
     MutexAutoLock lock(mLock);
     for (auto iter = mZips.Iter(); !iter.Done(); iter.Next()) {
       iter.UserData()->SetZipReaderCache(nullptr);
     }
     mZips.Clear();
   }
   else if (strcmp(aTopic, "flush-cache-entry") == 0) {
-    nsCOMPtr<nsIFile> file = do_QueryInterface(aSubject);
+    nsCOMPtr<nsIFile> 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;
 
     nsAutoCString uri;
     if (NS_FAILED(file->GetNativePath(uri)))
       return NS_OK;
 
     uri.Insert(NS_LITERAL_CSTRING("file:"), 0);
--- a/toolkit/components/extensions/ExtensionContent.jsm
+++ b/toolkit/components/extensions/ExtensionContent.jsm
@@ -887,20 +887,17 @@ ExtensionManager = {
 
         DocumentManager.shutdownExtension(data.id);
 
         this.extensions.delete(data.id);
         break;
       }
 
       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;
       }
     }
   },
 };
 
 class ExtensionGlobal {
--- a/toolkit/components/extensions/ExtensionTestCommon.jsm
+++ b/toolkit/components/extensions/ExtensionTestCommon.jsm
@@ -309,17 +309,17 @@ class ExtensionTestCommon {
    * new |Extension| instance which will execute it.
    *
    * @param {object} data
    * @returns {Extension}
    */
   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);
     let jarURI = Services.io.newURI("jar:" + fileURI.spec + "!/", null, null);
 
     // This may be "temporary" or "permanent".
     if (data.useAddonManager) {
       return new MockExtension(file, jarURI, data.useAddonManager);
--- a/toolkit/components/extensions/ExtensionUtils.jsm
+++ b/toolkit/components/extensions/ExtensionUtils.jsm
@@ -880,18 +880,18 @@ function promiseObserved(topic, test = (
 
 function getMessageManager(target) {
   if (target instanceof Ci.nsIFrameLoaderOwner) {
     return target.QueryInterface(Ci.nsIFrameLoaderOwner).frameLoader.messageManager;
   }
   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({
   os: (function() {
     let os = AppConstants.platform;
     if (os == "macosx") {
       os = "mac";
     }
--- a/toolkit/mozapps/extensions/internal/Content.js
+++ b/toolkit/mozapps/extensions/internal/Content.js
@@ -7,29 +7,25 @@
 "use strict";
 
 (function() {
 
 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";
 
 
 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() {
       Services.obs.notifyObservers(null, "message-manager-flush-caches", null);
     });
   }
 } catch (e) {
   Cu.reportError(e);