[Pkg-mozext-commits] [firebug] 35/56: Issue 7686 find update and upgrade firebug

David Prévot taffit at moszumanska.debian.org
Wed Nov 19 21:01:44 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository firebug.

commit edb08d6eea21d275423c8bcb32bae6a864949542
Author: Jan Odvarko <odvarko at gmail.com>
Date:   Wed Oct 29 13:54:06 2014 +0100

    Issue 7686 find update and upgrade firebug
---
 .../content/firebug/firefox/browserOverlay.css     |   4 +
 .../content/firebug/firefox/browserOverlay.js      | 123 +++++++++++++++++++--
 .../firefox/multiprocessNotificationPanel.xml      |  28 ++++-
 .../en-US/multiprocess-notification.properties     |   3 +-
 4 files changed, 146 insertions(+), 12 deletions(-)

diff --git a/extension/content/firebug/firefox/browserOverlay.css b/extension/content/firebug/firefox/browserOverlay.css
index 930af39..2d10ae7 100644
--- a/extension/content/firebug/firefox/browserOverlay.css
+++ b/extension/content/firebug/firefox/browserOverlay.css
@@ -223,3 +223,7 @@ fbMultiprocessNotificationPanel .warningbox {
 fbMultiprocessNotificationPanel .warningicon {
     margin-right: 4px;
 }
+
+fbMultiprocessNotificationPanel .progress {
+    margin: 8px;
+}
diff --git a/extension/content/firebug/firefox/browserOverlay.js b/extension/content/firebug/firefox/browserOverlay.js
index 8e066aa..59c7140 100644
--- a/extension/content/firebug/firefox/browserOverlay.js
+++ b/extension/content/firebug/firefox/browserOverlay.js
@@ -14,8 +14,8 @@ define([
     "firebug/firefox/browserToolbar",
     "firebug/lib/system",
 ],
-function(FBTrace, Options, Locale, Events, Arr, Str, Xpcom, BrowserOverlayLib, BrowserCommands,
-    BrowserMenu, BrowserToolbar, System) {
+function(FBTrace, Options, Locale, Events, Arr, Str, Xpcom, BrowserOverlayLib,
+    BrowserCommands, BrowserMenu, BrowserToolbar, System) {
 
 // ********************************************************************************************* //
 // Constants
@@ -617,10 +617,11 @@ BrowserOverlay.prototype =
 
     initializeMultiprocessUI: function()
     {
+      // xxxHonza: when exactly is the binding applied?
       this.win.setTimeout(() => {
         var startButton = this.doc.getElementById("firebug-button");
         startButton.mutliprocessEnabled();
-      });
+      }, 400);
     },
 
     showMultiprocessNotification: function()
@@ -632,6 +633,7 @@ BrowserOverlay.prototype =
             panel = this.doc.createElement("fbMultiprocessNotificationPanel");
             panel.setAttribute("upgradecommand", "Firebug.browserOverlay.onUpgradeFirebug(event)");
             panel.setAttribute("disablecommand", "Firebug.browserOverlay.onDisableE10s(event)");
+            panel.setAttribute("cancelcommand", "Firebug.browserOverlay.onCancelUpgrade(event)");
             popupSet.appendChild(panel);
         }
 
@@ -645,21 +647,122 @@ BrowserOverlay.prototype =
 
       Options.setPref("browser.tabs", "remote.autostart", false);
 
-      Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup).
-          quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
+      restartFirefox();
     },
 
     onUpgradeFirebug: function(event)
     {
-      Events.cancelEvent(event);
+        Events.cancelEvent(event);
+
+        var self = this;
+        var panel = this.doc.querySelector("fbMultiprocessNotificationPanel");
+
+        // Listen for installation end
+        var listener =
+        {
+          onInstallEnded: function(install, addon)
+          {
+              install.removeListener(listener);
+              self.install = null;
+
+              // Bug 749745: on FF14+, onInstallEnded is called just before `startup()`
+              // is called, but we expect to resolve the promise only after it.
+              // As startup is called synchronously just after onInstallEnded,
+              // a simple setTimeout(0) is enough
+              self.win.setTimeout(function()
+              {
+                restartFirefox();
+              }, 0);
+          },
+          onInstallFailed: function (install)
+          {
+              install.removeListener(listener);
+              self.install = null;
+              Cu.reportError(install.error);
+          },
+          onDownloadFailed: function(install)
+          {
+              this.onInstallFailed(install);
+          },
+          onDownloadStarted: function(install)
+          {
+              panel.progress.setAttribute("value", "0");
+              panel.upgradeButton.setAttribute("collapsed", "true");
+              panel.progress.removeAttribute("collapsed");
+              panel.cancelButton.removeAttribute("collapsed");
+          },
+          onDownloadProgress: function(install)
+          {
+              var value = install.progress / (install.maxProgress / 100);
+              panel.progress.value = value;
+          }
+        };
+
+        findFirebugUpdate(function(url)
+        {
+            AddonManager.getInstallForURL(url, (install) =>
+            {
+                install.addListener(listener);
+                install.install();
+                self.install = install;
+            }, "application/x-xpinstall");
+        });
 
-      // xxxHonza: TODO:
-      // - Install Firebug 3 (alpha) from getfirebug.com
-      // - Setup a page for "Learn more..." link in the notification
-      //  AddonManager.installAddonsFromWebpage
+        // TODO: Setup a page for "Learn more..." link in the notification
     },
+
+    onCancelUpgrade: function(event)
+    {
+        Events.cancelEvent(event);
+
+        if (!this.install)
+          return;
+
+        this.install.cancel();
+        this.install = null;
+
+        var panel = this.doc.querySelector("fbMultiprocessNotificationPanel");
+        panel.upgradeButton.removeAttribute("collapsed");
+        panel.progress.setAttribute("value", "0");
+        panel.progress.setAttribute("collapsed", "true");
+        panel.cancelButton.setAttribute("collapsed", "true");
+    }
 };
 
+function findFirebugUpdate(callback)
+{
+    const XMLHttpRequest = Components.Constructor(
+      "@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest");
+
+    var url = "https://getfirebug.com/releases/firebug/3.0/update.rdf";
+    var xhr = new XMLHttpRequest({mozAnon: true});
+    xhr.open("GET", url, true);
+
+    xhr.onload = function()
+    {
+        if (xhr.status !== 200)
+          return;
+
+        var parser = Xpcom.CCIN("@mozilla.org/xmlextras/domparser;1", "nsIDOMParser");
+        var doc = parser.parseFromString(xhr.responseText, "text/xml");
+        var root = doc.documentElement;
+        var link = root.querySelector("updateLink");
+        callback(link.textContent);
+    };
+
+    xhr.onerror = function(e)
+    {
+        Cu.reportError(e.target.status);
+    };
+
+    xhr.send(null);
+}
+
+function restartFirefox() {
+    Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup).
+        quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
+}
+
 // ********************************************************************************************* //
 // Registration
 
diff --git a/extension/content/firebug/firefox/multiprocessNotificationPanel.xml b/extension/content/firebug/firefox/multiprocessNotificationPanel.xml
index 9c13c0c..6688626 100644
--- a/extension/content/firebug/firefox/multiprocessNotificationPanel.xml
+++ b/extension/content/firebug/firefox/multiprocessNotificationPanel.xml
@@ -33,6 +33,9 @@
                         class="text-link popup-notification-learnmore-link learnMore"
                         href="https://getfirebug.com/"/>
                     <xul:hbox align="right">
+                        <xul:progressmeter anonid="progress" class="progress"
+                            mode="determined" value="0" collapsed="true"/>
+                        <xul:spacer width="20px" />
                         <xul:button anonid="upgrade" type="menu-button"
                             xbl:inherits="oncommand=upgradecommand"
                             class="popup-notification-menubutton">
@@ -41,8 +44,10 @@
                                     xbl:inherits="oncommand=disablecommand"/>
                             </xul:menupopup>
                         </xul:button>
+                        <xul:button anonid="cancel" type="button" collapsed="true"
+                            xbl:inherits="oncommand=cancelcommand">
+                        </xul:button>
                     </xul:hbox>
-
                 </xul:vbox>
             </xul:hbox>
         </xul:panel>
@@ -69,6 +74,9 @@
 
                 var disableMenu = document.getAnonymousElementByAttribute(this, "anonid", "disable");
                 disableMenu.label = Locale.$STR("multiprocess.disable");
+
+                var cancelButton = document.getAnonymousElementByAttribute(this, "anonid", "cancel");
+                cancelButton.label = Locale.$STR("multiprocess.cancel");
             ]]></body>
         </method>
 
@@ -82,6 +90,24 @@
                 panel.openPopup(startButton.button, "after_end", -offsetX, -offsetY, false, false);
             ]]></body>
         </method>
+
+        <property name="progress">
+            <getter><![CDATA[
+                return document.getAnonymousElementByAttribute(this, "anonid", "progress");
+            ]]></getter>
+        </property>
+
+        <property name="upgradeButton">
+            <getter><![CDATA[
+                return document.getAnonymousElementByAttribute(this, "anonid", "upgrade");
+            ]]></getter>
+        </property>
+
+        <property name="cancelButton">
+            <getter><![CDATA[
+                return document.getAnonymousElementByAttribute(this, "anonid", "cancel");
+            ]]></getter>
+        </property>
     </implementation>
 </binding>
 </bindings>
diff --git a/extension/locale/en-US/multiprocess-notification.properties b/extension/locale/en-US/multiprocess-notification.properties
index a02a8b3..3be06e1 100644
--- a/extension/locale/en-US/multiprocess-notification.properties
+++ b/extension/locale/en-US/multiprocess-notification.properties
@@ -5,4 +5,5 @@ multiprocess.description=You are running Firebug 2 in multiprocess Firefox brows
 multiprocess.learnMore=Learn more...
 multiprocess.warning=You might want to disable multiprocess feature on this browser in order to continue using Firebug 2, but you will be at a significant performance, stability, and security disadvantage.
 multiprocess.upgrade=Upgrade and Restart
-multiprocess.disable=Disable e10s
\ No newline at end of file
+multiprocess.disable=Disable e10s
+multiprocess.cancel=Cancel
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/firebug.git



More information about the Pkg-mozext-commits mailing list