Bug 664697 - Convert newsblog util.js into a module. r=Standard8, r=philip.chee
authoralta88@gmail.com
Mon, 06 Jan 2014 08:50:32 -0500
changeset 17255 4b1338309c260cf48cb300ac019f5e85dc1e7e97
parent 17254 08b8cae1f27e6e959e0819864fe58d4df853705e
child 17256 a8155385a420ee7e6c9fc7cf5058cef93e3e86f4
push id1103
push usermbanner@mozilla.com
push dateTue, 18 Mar 2014 07:44:06 +0000
treeherdercomm-beta@50c6279a0af0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, philip.chee
bugs664697
Bug 664697 - Convert newsblog util.js into a module. r=Standard8, r=philip.chee
mail/base/content/mailWindowOverlay.js
mail/base/content/mailWindowOverlay.xul
mailnews/extensions/newsblog/content/FeedUtils.jsm
mailnews/extensions/newsblog/content/feed-subscriptions.js
mailnews/extensions/newsblog/content/feed-subscriptions.xul
mailnews/extensions/newsblog/content/feedAccountWizard.js
mailnews/extensions/newsblog/content/feedAccountWizard.xul
mailnews/extensions/newsblog/content/utils.js
mailnews/extensions/newsblog/jar.mn
mailnews/extensions/newsblog/js/newsblog.js
mailnews/extensions/newsblog/moz.build
mailnews/import/content/importDialog.xul
suite/mailnews/mailWindowOverlay.js
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -1,14 +1,16 @@
 /* -*- indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
+Components.utils.import("resource:///modules/FeedUtils.jsm");
 Components.utils.import("resource:///modules/gloda/dbview.js");
+Components.utils.import("resource:///modules/MailConsts.js");
 Components.utils.import("resource:///modules/mailServices.js");
 Components.utils.import("resource:///modules/MailUtils.js");
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/PluralForm.jsm");
 
 const ADDR_DB_LARGE_COMMIT       = 1;
 
 const kClassicMailLayout = 0;
@@ -24,20 +26,16 @@ const kMailLayoutCommandMap =
 // Per message header flags to keep track of whether the user is allowing remote
 // content for a particular message.
 // if you change or add more values to these constants, be sure to modify
 // the corresponding definitions in nsMsgContentPolicy.cpp
 const kNoRemoteContentPolicy = 0;
 const kBlockRemoteContent = 1;
 const kAllowRemoteContent = 2;
 
-Components.utils.import("resource:///modules/MailUtils.js");
-Components.utils.import("resource:///modules/MailConsts.js");
-Components.utils.import("resource://gre/modules/Services.jsm");
-
 // Timer to mark read, if the user has configured the app to mark a message as
 // read if it is viewed for more than n seconds.
 var gMarkViewedMessageAsReadTimer = null;
 
 // the user preference,
 // if HTML is not allowed. I assume, that the user could have set this to a
 // value > 1 in his prefs.js or user.js, but that the value will not
 // change during runtime other than through the MsgBody*() functions below.
--- a/mail/base/content/mailWindowOverlay.xul
+++ b/mail/base/content/mailWindowOverlay.xul
@@ -54,17 +54,16 @@
 <script type="application/javascript" src="chrome://messenger/content/folderDisplay.js"/>
 <script type="application/javascript" src="chrome://messenger-newsblog/content/newsblogOverlay.js"/>
 <script type="application/javascript" src="chrome://messenger/content/mail-offline.js"/>
 <script type="application/javascript" src="chrome://global/content/printUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/msgViewPickerOverlay.js"/>
 <script type="application/javascript" src="chrome://messenger/content/plugins.js"/>
 <script type="application/javascript" src="chrome://global/content/viewZoomOverlay.js"/>
 <script type="application/javascript" src="chrome://messenger/content/newmailaccount/uriListener.js"/>
-<script type="application/javascript" src="chrome://messenger-newsblog/content/utils.js"/>
 
 <stringbundleset id="stringbundleset">
   <stringbundle id="brand_bundle" src="chrome://branding/locale/brand.properties"/>
   <stringbundle id="bundle_messenger" src="chrome://messenger/locale/messenger.properties"/>
   <stringbundle id="bundle_offlinePrompts" src="chrome://messenger/locale/offline.properties"/>
 </stringbundleset>
 
 <!-- Performance optimization...we include utilityOverlay.xul which defines some command sets
rename from mailnews/extensions/newsblog/content/utils.js
rename to mailnews/extensions/newsblog/content/FeedUtils.jsm
--- a/mailnews/extensions/newsblog/content/utils.js
+++ b/mailnews/extensions/newsblog/content/FeedUtils.jsm
@@ -1,25 +1,28 @@
 /* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
-var Cc = Components.classes;
-var Ci = Components.interfaces;
-var Cr = Components.results;
-var Cu = Components.utils;
+const EXPORTED_SYMBOLS = ["Feed", "FeedItem", "FeedParser", "FeedUtils"];
+
+var {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource:///modules/gloda/log4moz.js");
 Cu.import("resource:///modules/mailServices.js");
 Cu.import("resource:///modules/MailUtils.js");
 Cu.import("resource://gre/modules/FileUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
+Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/Feed.js");
+Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/FeedItem.js");
+Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/feed-parser.js");
+
 var FeedUtils = {
   MOZ_PARSERERROR_NS: "http://www.mozilla.org/newlayout/xml/parsererror.xml",
 
   RDF_SYNTAX_NS: "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
   RDF_SYNTAX_TYPE: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
   get RDF_TYPE() { return this.rdf.GetResource(this.RDF_SYNTAX_TYPE) },
 
   RSS_090_NS: "http://my.netscape.com/rdf/simple/0.9/",
--- a/mailnews/extensions/newsblog/content/feed-subscriptions.js
+++ b/mailnews/extensions/newsblog/content/feed-subscriptions.js
@@ -1,15 +1,21 @@
 /* -*- Mode: JavaScript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
+Components.utils.import("resource:///modules/FeedUtils.jsm");
+Components.utils.import("resource:///modules/gloda/log4moz.js");
 Components.utils.import("resource:///modules/mailServices.js");
+Components.utils.import("resource://gre/modules/FileUtils.jsm");
 Components.utils.import("resource://gre/modules/PluralForm.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+var {classes: Cc, interfaces: Ci} = Components;
 
 var FeedSubscriptions = {
   get mTree() { return document.getElementById("rssSubscriptionsList"); },
 
   mFeedContainers: [],
   mRSSServer     : null,
   mActionMode    : null,
   kSubscribeMode : 1,
--- a/mailnews/extensions/newsblog/content/feed-subscriptions.xul
+++ b/mailnews/extensions/newsblog/content/feed-subscriptions.xul
@@ -20,25 +20,17 @@
         xmlns:nc="http://home.netscape.com/NC-rdf#"
         persist="width height screenX screenY sizemode"
         onload="FeedSubscriptions.onLoad();"
         onclose="return FeedSubscriptions.onClose();"
         onkeypress="FeedSubscriptions.onKeyPress(event);"
         onmousedown="FeedSubscriptions.onMouseDown(event);">
 
   <script type="application/javascript"
-          src="chrome://messenger-newsblog/content/utils.js"/>
-  <script type="application/javascript"
           src="chrome://messenger-newsblog/content/feed-subscriptions.js"/>
-  <script type="application/javascript"
-          src="chrome://messenger-newsblog/content/Feed.js"/>
-  <script type="application/javascript"
-          src="chrome://messenger-newsblog/content/FeedItem.js"/>
-  <script type="application/javascript"
-          src="chrome://messenger-newsblog/content/feed-parser.js"/>
 
   <keyset id="extensionsKeys">
     <key id="key_close"
          key="&cmd.close.commandKey;"
          modifiers="accel"
          oncommand="window.close();"/>
     <key id="key_close2"
          keycode="VK_ESCAPE"
--- a/mailnews/extensions/newsblog/content/feedAccountWizard.js
+++ b/mailnews/extensions/newsblog/content/feedAccountWizard.js
@@ -1,13 +1,15 @@
 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
+Components.utils.import("resource:///modules/FeedUtils.jsm");
+
 /* Feed account standalone wizard functions */
 let FeedAccountWizard = {
   accountName: "",
 
   accountSetupPageInit: function() {
     this.accountSetupPageValidate();
   },
 
--- a/mailnews/extensions/newsblog/content/feedAccountWizard.xul
+++ b/mailnews/extensions/newsblog/content/feedAccountWizard.xul
@@ -17,18 +17,16 @@
 <wizard id="FeedAccountWizard"
         title="&feedWindowTitle.label;"
         onwizardcancel="return FeedAccountWizard.onCancel();"
         onwizardfinish="return FeedAccountWizard.onFinish();"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
 
   <script type="application/javascript"
           src="chrome://messenger-newsblog/content/feedAccountWizard.js"/>
-  <script type="application/javascript"
-          src="chrome://messenger-newsblog/content/utils.js"/>
 
   <!-- Account setup page : User gets a choice to enter a name for the account -->
   <!-- Defaults : Feed account name -> default string -->
   <wizardpage id="accountsetuppage"
               pageid="accountsetuppage"
               label="&accnameTitle.label;"
               onpageshow="return FeedAccountWizard.accountSetupPageInit();"
               onpageadvanced="return FeedAccountWizard.accountSetupPageUnload();">
--- a/mailnews/extensions/newsblog/jar.mn
+++ b/mailnews/extensions/newsblog/jar.mn
@@ -3,15 +3,14 @@
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 newsblog.jar:
 % content messenger-newsblog %content/messenger-newsblog/
    content/messenger-newsblog/newsblogOverlay.js                (content/newsblogOverlay.js)
    content/messenger-newsblog/Feed.js                           (content/Feed.js)
    content/messenger-newsblog/FeedItem.js                       (content/FeedItem.js)
    content/messenger-newsblog/feed-parser.js                    (content/feed-parser.js)
-   content/messenger-newsblog/utils.js                          (content/utils.js)
 *  content/messenger-newsblog/feed-subscriptions.js             (content/feed-subscriptions.js)
    content/messenger-newsblog/feed-subscriptions.xul            (content/feed-subscriptions.xul)
    content/messenger-newsblog/am-newsblog.js                    (content/am-newsblog.js)
    content/messenger-newsblog/am-newsblog.xul                   (content/am-newsblog.xul)
    content/messenger-newsblog/feedAccountWizard.js              (content/feedAccountWizard.js)
    content/messenger-newsblog/feedAccountWizard.xul             (content/feedAccountWizard.xul)
--- a/mailnews/extensions/newsblog/js/newsblog.js
+++ b/mailnews/extensions/newsblog/js/newsblog.js
@@ -1,25 +1,23 @@
 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
-Components.utils.import("resource://gre/modules/Services.jsm");
-Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+var {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components;
 
-var gExternalScriptsLoaded = false;
+Cu.import("resource:///modules/FeedUtils.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 var nsNewsBlogFeedDownloader =
 {
   downloadFeed: function(aA, aFolder, aB, aC, aUrlListener, aMsgWindow)
   {
-    if (!gExternalScriptsLoaded)
-      loadScripts();
-
     if (Services.io.offline)
       return;
 
     // We don't yet support the ability to check for new articles while we are
     // in the middle of subscribing to a feed. For now, abort the check for
     // new feeds.
     if (FeedUtils.progressNotifier.mSubscribeMode)
     {
@@ -133,19 +131,16 @@ var nsNewsBlogFeedDownloader =
         FeedUtils.log.error("downloadFeed: error - " + ex);
         FeedUtils.progressNotifier.downloaded({name: aFolder.name}, 0);
       }
     }
   },
 
   subscribeToFeed: function(aUrl, aFolder, aMsgWindow)
   {
-    if (!gExternalScriptsLoaded)
-      loadScripts();
-
     // We don't support the ability to subscribe to several feeds at once yet.
     // For now, abort the subscription if we are already in the middle of
     // subscribing to a feed via drag and drop.
     if (FeedUtils.progressNotifier.mNumPendingFeedDownloads)
     {
       FeedUtils.log.warn("subscribeToFeed: Aborting RSS subscription. " +
                          "Feed downloads already in progress\n");
       return;
@@ -208,19 +203,16 @@ var nsNewsBlogFeedDownloader =
 
     FeedUtils.progressNotifier.init(aMsgWindow, true);
     FeedUtils.progressNotifier.mNumPendingFeedDownloads++;
     feed.download(true, FeedUtils.progressNotifier);
   },
 
   updateSubscriptionsDS: function(aFolder, aOrigFolder)
   {
-    if (!gExternalScriptsLoaded)
-      loadScripts();
-
     FeedUtils.log.debug("updateSubscriptionsDS: folder changed, aFolder - " +
                         aFolder.filePath.path);
     FeedUtils.log.debug("updateSubscriptionsDS: " + (aOrigFolder ?
                         "move/copy, aOrigFolder  - " + aOrigFolder.filePath.path :
                         "rename"));
 
     if ((aOrigFolder && FeedUtils.isInTrash(aOrigFolder)) ||
         (!aOrigFolder && FeedUtils.isInTrash(aFolder)))
@@ -242,56 +234,56 @@ var nsNewsBlogFeedDownloader =
     {
       let subFolder = subFolders.queryElementAt(i, Ci.nsIMsgFolder);
       FeedUtils.updateFolderChangeInFeedsDS(subFolder, aOrigFolder);
     }
   },
 
   QueryInterface: function(aIID)
   {
-    if (aIID.equals(Components.interfaces.nsINewsBlogFeedDownloader) ||
-        aIID.equals(Components.interfaces.nsISupports))
+    if (aIID.equals(Ci.nsINewsBlogFeedDownloader) ||
+        aIID.equals(Ci.nsISupports))
       return this;
 
-    throw Components.results.NS_ERROR_NO_INTERFACE;
+    throw Cr.NS_ERROR_NO_INTERFACE;
   }
 }
 
 var nsNewsBlogAcctMgrExtension =
 {
   name: "newsblog",
   chromePackageName: "messenger-newsblog",
   showPanel: function (server)
   {
     return false;
   },
   QueryInterface: function(aIID)
   {
-    if (aIID.equals(Components.interfaces.nsIMsgAccountManagerExtension) ||
-        aIID.equals(Components.interfaces.nsISupports))
+    if (aIID.equals(Ci.nsIMsgAccountManagerExtension) ||
+        aIID.equals(Ci.nsISupports))
       return this;
 
-    throw Components.results.NS_ERROR_NO_INTERFACE;
+    throw Cr.NS_ERROR_NO_INTERFACE;
   }
 }
 
 function FeedDownloader() {}
 
 FeedDownloader.prototype =
 {
   classID: Components.ID("{5c124537-adca-4456-b2b5-641ab687d1f6}"),
   _xpcom_factory:
   {
     createInstance: function (aOuter, aIID)
     {
       if (aOuter != null)
-        throw Components.results.NS_ERROR_NO_AGGREGATION;
-      if (!aIID.equals(Components.interfaces.nsINewsBlogFeedDownloader) &&
-          !aIID.equals(Components.interfaces.nsISupports))
-        throw Components.results.NS_ERROR_INVALID_ARG;
+        throw Cr.NS_ERROR_NO_AGGREGATION;
+      if (!aIID.equals(Ci.nsINewsBlogFeedDownloader) &&
+          !aIID.equals(Ci.nsISupports))
+        throw Cr.NS_ERROR_INVALID_ARG;
 
       // return the singleton
       return nsNewsBlogFeedDownloader.QueryInterface(aIID);
     }
   } // factory
 }; // feed downloader
 
 function AcctMgrExtension() {}
@@ -299,31 +291,21 @@ function AcctMgrExtension() {}
 AcctMgrExtension.prototype =
 {
   classID: Components.ID("{E109C05F-D304-4ca5-8C44-6DE1BFAF1F74}"),
   _xpcom_factory:
   {
     createInstance: function (aOuter, aIID)
     {
       if (aOuter != null)
-        throw Components.results.NS_ERROR_NO_AGGREGATION;
-      if (!aIID.equals(Components.interfaces.nsIMsgAccountManagerExtension) &&
-          !aIID.equals(Components.interfaces.nsISupports))
-        throw Components.results.NS_ERROR_INVALID_ARG;
+        throw Cr.NS_ERROR_NO_AGGREGATION;
+      if (!aIID.equals(Ci.nsIMsgAccountManagerExtension) &&
+          !aIID.equals(Ci.nsISupports))
+        throw Cr.NS_ERROR_INVALID_ARG;
 
       // return the singleton
       return nsNewsBlogAcctMgrExtension.QueryInterface(aIID);
     }
   } // factory
 }; // account manager extension
 
 var components = [FeedDownloader, AcctMgrExtension];
 var NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
-
-function loadScripts()
-{
-  Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/Feed.js");
-  Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/FeedItem.js");
-  Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/feed-parser.js");
-  Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/utils.js");
-
-  gExternalScriptsLoaded = true;
-}
--- a/mailnews/extensions/newsblog/moz.build
+++ b/mailnews/extensions/newsblog/moz.build
@@ -3,9 +3,12 @@
 # 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/.
 
 EXTRA_COMPONENTS += [
     'js/newsblog.js',
     'js/newsblog.manifest',
 ]
 
+EXTRA_JS_MODULES += [
+    'content/FeedUtils.jsm',
+]
 JAR_MANIFESTS += ['jar.mn']
--- a/mailnews/import/content/importDialog.xul
+++ b/mailnews/import/content/importDialog.xul
@@ -24,19 +24,17 @@
 #endif
         title="&importDialog.windowTitle;">
 
   <stringbundle id="bundle_importMsgs" src="chrome://messenger/locale/importMsgs.properties"/>
   <stringbundle id="bundle_addressbook" src="chrome://messenger/locale/addressbook/addressBook.properties"/>
   <stringbundle id="bundle_vcardImportMsgs" src="chrome://messenger/locale/vCardImportMsgs.properties"/>
   <stringbundle id="bundle_feeds" src="chrome://messenger-newsblog/locale/newsblog.properties"/>
   <script type="application/javascript" src="chrome://messenger/content/importDialog.js"/>
-  <script type="application/javascript" src="chrome://messenger-newsblog/content/Feed.js"/>
   <script type="application/javascript" src="chrome://messenger-newsblog/content/feed-subscriptions.js"/>
-  <script type="application/javascript" src="chrome://messenger-newsblog/content/utils.js"/>
 
   <keyset id="dialogKeys"/>
   
   <hbox class="box-header" id="header"
        title="&importTitle.label;"
        description="&importShortDesc.label;"/>
 
   <deck id="stateDeck" selectedIndex="0">
--- a/suite/mailnews/mailWindowOverlay.js
+++ b/suite/mailnews/mailWindowOverlay.js
@@ -1,18 +1,19 @@
 /* -*- Mode: javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 sw=2 sts=2 et :*/
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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/. */
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 Components.utils.import("resource://gre/modules/PluralForm.jsm");
+Components.utils.import("resource:///modules/FeedUtils.jsm");
+Components.utils.import("resource:///modules/folderUtils.jsm");
 Components.utils.import("resource:///modules/mailServices.js");
-Components.utils.import("resource:///modules/folderUtils.jsm");
 
 const kClassicMailLayout  = 0;
 const kWideMailLayout     = 1;
 const kVerticalMailLayout = 2;
 
 const kMouseButtonLeft   = 0;
 const kMouseButtonMiddle = 1;
 const kMouseButtonRight  = 2;
@@ -3090,24 +3091,22 @@ function FeedSetContentView(val)
       break;
     case 1:
       showSummary = true
       break;
     case 2:
       if (wintype == "mail:3pane") {
         // Get quickmode per feed pref from feeds.rdf
         var quickMode, targetRes;
-        if (!("FeedUtils" in window))
-          Services.scriptloader.loadSubScript("chrome://messenger-newsblog/content/utils.js");
         try
         {
-          var targetRes = FeedUtils.getParentTargetForChildResource(
-                            gFolderDisplay.displayedFolder.URI,
-                            FeedUtils.FZ_QUICKMODE,
-                            gFolderDisplay.displayedFolder.server);
+          targetRes = FeedUtils.getParentTargetForChildResource(
+                        gFolderDisplay.displayedFolder.URI,
+                        FeedUtils.FZ_QUICKMODE,
+                        gFolderDisplay.displayedFolder.server);
         }
         catch (ex) {};
 
         if (targetRes)
         {
           quickMode = targetRes.QueryInterface(Components.interfaces
                                .nsIRDFLiteral);
           quickMode = quickMode.Value;