Bug 948899 - Move inline scripts and styles into separate file for mobile/android/chrome/content/aboutAddons.xhtml. r=mleibovic
authorErrietta Kostala <errietta@errietta.me>
Tue, 14 Jan 2014 09:49:08 -0500
changeset 163260 86d408022528081e7a27b3549af166b4a4e55e41
parent 163259 41a39fe891679268930085c272fc4d175190c52e
child 163261 8a2e16a8bf570e160d5335cf50bb2e8582bbbcc5
push id4323
push userryanvm@gmail.com
push dateTue, 14 Jan 2014 14:49:16 +0000
treeherderfx-team@8a2e16a8bf57 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmleibovic
bugs948899
milestone29.0a1
Bug 948899 - Move inline scripts and styles into separate file for mobile/android/chrome/content/aboutAddons.xhtml. r=mleibovic
mobile/android/chrome/content/aboutAddons.js
mobile/android/chrome/content/aboutAddons.xhtml
mobile/android/themes/core/aboutAddons.css
--- a/mobile/android/chrome/content/aboutAddons.js
+++ b/mobile/android/chrome/content/aboutAddons.js
@@ -23,16 +23,20 @@ XPCOMUtils.defineLazyGetter(window, "gCh
 
 XPCOMUtils.defineLazyGetter(window, "SelectHelper", function() gChromeWin.SelectHelper);
 
 var ContextMenus = {
   target: null,
 
   init: function() {
     document.addEventListener("contextmenu", this, false);
+
+    document.getElementById("contextmenu-enable").addEventListener("click", ContextMenus.enable.bind(this), false);
+    document.getElementById("contextmenu-disable").addEventListener("click", ContextMenus.disable.bind(this), false);
+    document.getElementById("contextmenu-uninstall").addEventListener("click", ContextMenus.uninstall.bind(this), false);
   },
 
   handleEvent: function(event) {
     // store the target of context menu events so that we know which app to act on
     this.target = event.target;
     while (!this.target.hasAttribute("contextmenu")) {
       this.target = this.target.parentNode;
     }
@@ -77,30 +81,34 @@ var ContextMenus = {
   }
 }
 
 function init() {
   window.addEventListener("popstate", onPopState, false);
 
   AddonManager.addInstallListener(Addons);
   AddonManager.addAddonListener(Addons);
-  Addons.getAddons();
+  Addons.init();
   showList();
   ContextMenus.init();
+
+  document.getElementById("header-button").addEventListener("click", openLink, false);
 }
 
+
 function uninit() {
   AddonManager.removeInstallListener(Addons);
   AddonManager.removeAddonListener(Addons);
 }
 
-function openLink(aElement) {
+function openLink(aEvent) {
   try {
     let formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"].getService(Ci.nsIURLFormatter);
-    let url = formatter.formatURLPref(aElement.getAttribute("pref"));
+
+    let url = formatter.formatURLPref(aEvent.currentTarget.getAttribute("pref"));
     let BrowserApp = gChromeWin.BrowserApp;
     BrowserApp.addTab(url, { selected: true, parentId: BrowserApp.selectedTab.id });
   } catch (ex) {}
 }
 
 function onPopState(aEvent) {
   // Called when back/forward is used to change the state of the page
   if (aEvent.state) {
@@ -174,32 +182,31 @@ var Addons = {
     outer.appendChild(inner);
     return outer;
   },
 
   _createBrowseItem: function _createBrowseItem() {
     let outer = document.createElement("div");
     outer.className = "addon-item list-item";
     outer.setAttribute("role", "button");
-    outer.addEventListener("click", function() {
-      openLink(document.getElementById("header-button"));
-    }.bind(this), true);
+    outer.setAttribute("pref", "extensions.getAddons.browseAddons");
+    outer.addEventListener("click", openLink, true);
 
     let img = document.createElement("img");
     img.className = "icon";
     img.setAttribute("src", "chrome://browser/skin/images/amo-logo.png");
     outer.appendChild(img);
 
     let inner = document.createElement("div");
     inner.className = "inner";
 
     let title = document.createElement("div");
     title.id = "browse-title";
     title.className = "title";
-    title.textContent = gStringBundle.GetStringFromName("addons.browseAll");;
+    title.textContent = gStringBundle.GetStringFromName("addons.browseAll");
     inner.appendChild(title);
 
     outer.appendChild(inner);
     return outer;
   },
 
   _createItemForAddon: function _createItemForAddon(aAddon) {
     let appManaged = (aAddon.scope == AddonManager.SCOPE_APPLICATION);
@@ -233,32 +240,37 @@ var Addons = {
   },
 
   _getElementForAddon: function(aKey) {
     let list = document.getElementById("addons-list");
     let element = list.querySelector("div[addonID=" + aKey.quote() + "]");
     return element;
   },
 
-  getAddons: function getAddons() {
+  init: function init() {
     let self = this;
     AddonManager.getAddonsByTypes(["extension", "theme", "locale"], function(aAddons) {
       // Clear all content before filling the addons
       let list = document.getElementById("addons-list");
       list.innerHTML = "";
 
       for (let i=0; i<aAddons.length; i++) {
         let item = self._createItemForAddon(aAddons[i]);
         list.appendChild(item);
       }
 
       // Add a "Browse all Firefox Add-ons" item to the bottom of the list.
       let browseItem = self._createBrowseItem();
       list.appendChild(browseItem);
     });
+
+    document.getElementById("uninstall-btn").addEventListener("click", Addons.uninstallCurrent.bind(this), false);
+    document.getElementById("cancel-btn").addEventListener("click", Addons.cancelUninstall.bind(this), false);
+    document.getElementById("disable-btn").addEventListener("click", Addons.disable.bind(this), false);
+    document.getElementById("enable-btn").addEventListener("click", Addons.enable.bind(this), false);
   },
 
   _getOpTypeForOperations: function _getOpTypeForOperations(aOperations) {
     if (aOperations & AddonManager.PENDING_UNINSTALL)
       return "needs-uninstall";
     if (aOperations & AddonManager.PENDING_ENABLE)
       return "needs-enable";
     if (aOperations & AddonManager.PENDING_DISABLE)
@@ -416,34 +428,43 @@ var Addons = {
   enable: function enable() {
     this.setEnabled(true);
   },
 
   disable: function disable() {
     this.setEnabled(false);
   },
 
-  uninstall: function uninstall(aAddon) {
-    let list = document.getElementById("addons-list");
+  uninstallCurrent: function uninstallCurrent() {
     let detailItem = document.querySelector("#addons-details > .addon-item");
 
-    let addon = aAddon || detailItem.addon;
+    let addon = detailItem.addon;
     if (!addon)
       return;
 
-    let listItem = this._getElementForAddon(addon.id);
+    this.uninstall(addon);
+  },
+
+  uninstall: function uninstall(aAddon) {
+    let list = document.getElementById("addons-list");
 
-    addon.uninstall();
-    if (addon.pendingOperations & AddonManager.PENDING_UNINSTALL) {
+    if (!aAddon) {
+        return;
+    }
+
+    let listItem = this._getElementForAddon(aAddon.id);
+
+    aAddon.uninstall();
+    if (aAddon.pendingOperations & AddonManager.PENDING_UNINSTALL) {
       this.showRestart();
 
       // A disabled addon doesn't need a restart so it has no pending ops and
       // can't be cancelled
-      let opType = this._getOpTypeForOperations(addon.pendingOperations);
-      if (!addon.isActive && opType == "")
+      let opType = this._getOpTypeForOperations(aAddon.pendingOperations);
+      if (!aAddon.isActive && opType == "")
         opType = "needs-uninstall";
 
       detailItem.setAttribute("opType", opType);
       listItem.setAttribute("opType", opType);
     } else {
       list.removeChild(listItem);
       history.back();
     }
@@ -513,8 +534,11 @@ var Addons = {
   },
 
   onDownloadFailed: function(aInstall) {
   },
 
   onDownloadCancelled: function(aInstall) {
   }
 }
+
+window.addEventListener("load", init, false);
+window.addEventListener("unload", uninit, false);
--- a/mobile/android/chrome/content/aboutAddons.xhtml
+++ b/mobile/android/chrome/content/aboutAddons.xhtml
@@ -16,78 +16,49 @@
 
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
   <title>&aboutAddons.title2;</title>
   <meta name="viewport" content="width=device-width; user-scalable=0" />
   <link rel="icon" type="image/png" sizes="64x64" href="chrome://branding/content/favicon64.png" />
   <link rel="stylesheet" href="chrome://browser/skin/aboutBase.css" type="text/css"/>
   <link rel="stylesheet" href="chrome://browser/skin/aboutAddons.css" type="text/css"/>
-  <style>
-    .hide-on-enable,
-    .show-on-error,
-    .show-on-uninstall,
-    .show-on-install,
-    .show-on-restart,
-    div[isDisabled="true"] .hide-on-disable {
-      display: none;
-    }
-    
-    div[error] .show-on-error,
-    div[opType="needs-restart"] .show-on-restart,
-    div[opType="needs-uninstall"] .show-on-uninstall,
-    div[opType="needs-install"] .show-on-install,
-    div[opType="needs-enable"] .show-on-enable,
-    div[opType="needs-disable"] .show-on-disable,
-    div[isDisabled="true"] .show-on-disable {
-      display: -moz-box;
-    }
-    
-    div[opType="needs-restart"] .hide-on-restart,
-    div[opType="needs-uninstall"] .hide-on-uninstall,
-    div[isDisabled="true"][opType="needs-uninstall"],
-    div[opType="needs-install"] .hide-on-install,
-    div[opType="needs-enable"] .hide-on-enable,
-    div[opType="needs-disable"] .hide-on-disable {
-      display: none;
-    }
-  </style>
 </head>
 
-<body dir="&locale.dir;" onload="init();" onunload="uninit();">
+<body dir="&locale.dir;">
   <menu type="context" id="addonmenu">
-    <menuitem id="contextmenu-enable" label="&addonAction.enable;" onclick="ContextMenus.enable();"></menuitem>
-    <menuitem id="contextmenu-disable" label="&addonAction.disable;" onclick="ContextMenus.disable();"></menuitem>
-    <menuitem id="contextmenu-uninstall" label="&addonAction.uninstall;" onclick="ContextMenus.uninstall();"></menuitem>
+    <menuitem id="contextmenu-enable" label="&addonAction.enable;"></menuitem>
+    <menuitem id="contextmenu-disable" label="&addonAction.disable;" ></menuitem>
+    <menuitem id="contextmenu-uninstall" label="&addonAction.uninstall;" ></menuitem>
   </menu>
 
   <div id="addons-header" class="header">
     <div>&aboutAddons.header2;</div>
-    <div id="header-button" role="button" aria-label="&aboutAddons.browseAll;" pref="extensions.getAddons.browseAddons" onclick="openLink(this);"/>
+    <div id="header-button" role="button" aria-label="&aboutAddons.browseAll;" pref="extensions.getAddons.browseAddons" />
   </div>
-  <div id="addons-list" class="list" style="display: none;">
+  <div id="addons-list" class="list">
   </div>
 
-  <div id="addons-details" class="list" style="display: none">
+  <div id="addons-details" class="list">
     <div class="addon-item list-item">
       <img class="icon"/>
       <div class="inner">
         <div class="details">
           <div class="tag"></div>
           <div class="title"></div>
           <div class="version"></div>
         </div>
         <div class="description-full"></div>
       </div>
       <div class="status status-uninstalled show-on-uninstall"></div>
       <div class="buttons">
-        <button id="enable-btn" class="show-on-disable hide-on-enable hide-on-uninstall" onclick="Addons.enable();">&addonAction.enable;</button>
-        <button id="disable-btn" class="show-on-enable hide-on-disable hide-on-uninstall" onclick="Addons.disable();">&addonAction.disable;</button>
-        <button id="uninstall-btn" class="hide-on-uninstall" onclick="Addons.uninstall();">&addonAction.uninstall;</button>
-        <button id="cancel-btn" class="show-on-uninstall" onclick="Addons.cancelUninstall();">&addonAction.undo;</button>
+        <button id="enable-btn" class="show-on-disable hide-on-enable hide-on-uninstall" >&addonAction.enable;</button>
+        <button id="disable-btn" class="show-on-enable hide-on-disable hide-on-uninstall" >&addonAction.disable;</button>
+        <button id="uninstall-btn" class="hide-on-uninstall" >&addonAction.uninstall;</button>
+        <button id="cancel-btn" class="show-on-uninstall" >&addonAction.undo;</button>
       </div>
       <div class="options-header">&aboutAddons.options;</div>
       <div class="options-box"></div>
     </div>
   </div>
 
   <script type="application/javascript;version=1.8" src="chrome://browser/content/aboutAddons.js"></script>
 </body>
--- a/mobile/android/themes/core/aboutAddons.css
+++ b/mobile/android/themes/core/aboutAddons.css
@@ -234,8 +234,40 @@ setting[type="string"] {
   -moz-binding: url("chrome://mozapps/content/extensions/setting.xml#setting-string");
 }
 
 setting[type="radio"],
 setting[type="menulist"] {
   display: -moz-box;
   -moz-binding: url("chrome://mozapps/content/extensions/setting.xml#setting-multi");
 }
+
+.hide-on-enable,
+.show-on-error,
+.show-on-uninstall,
+.show-on-install,
+.show-on-restart,
+div[isDisabled="true"] .hide-on-disable {
+  display: none;
+}
+
+div[error] .show-on-error,
+div[opType="needs-restart"] .show-on-restart,
+div[opType="needs-uninstall"] .show-on-uninstall,
+div[opType="needs-install"] .show-on-install,
+div[opType="needs-enable"] .show-on-enable,
+div[opType="needs-disable"] .show-on-disable,
+div[isDisabled="true"] .show-on-disable {
+  display: -moz-box;
+}
+
+div[opType="needs-restart"] .hide-on-restart,
+div[opType="needs-uninstall"] .hide-on-uninstall,
+div[isDisabled="true"][opType="needs-uninstall"],
+div[opType="needs-install"] .hide-on-install,
+div[opType="needs-enable"] .hide-on-enable,
+div[opType="needs-disable"] .hide-on-disable {
+  display: none;
+}
+
+#addons-list, #addons-details {
+  display: none;
+}