Bug 1027024 - Never translate 'language' disappears when close/open translation infobar using a expired key - follow-up, r=mikedeboer.
authorFlorian Quèze <florian@queze.net>
Mon, 21 Jul 2014 12:24:43 +0200
changeset 195360 b9c60f0356c2b04f31feb232d04d2e5841f2573b
parent 195224 4bafe35cfb6581bd57e6fec7330694f790208fba
child 195361 0859e0ab393418a461522898b70a210ef81ffc7a
push id46575
push userkwierso@gmail.com
push dateTue, 22 Jul 2014 00:35:21 +0000
treeherdermozilla-inbound@fee5c4bdd713 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmikedeboer
bugs1027024
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1027024 - Never translate 'language' disappears when close/open translation infobar using a expired key - follow-up, r=mikedeboer.
browser/components/translation/Translation.jsm
browser/components/translation/translation-infobar.xml
--- a/browser/components/translation/Translation.jsm
+++ b/browser/components/translation/Translation.jsm
@@ -65,17 +65,18 @@ this.Translation = {
     if (!Services.prefs.getBoolPref(TRANSLATION_PREF_SHOWUI))
       return;
 
     if (!aBrowser.translationUI)
       aBrowser.translationUI = new TranslationUI(aBrowser);
     let trUI = aBrowser.translationUI;
 
     // Set all values before showing a new translation infobar.
-    trUI._state = aData.state;
+    trUI._state = Translation.serviceUnavailable ? Translation.STATE_UNAVAILABLE
+                                                 : aData.state;
     trUI.detectedLanguage = aData.detectedLanguage;
     trUI.translatedFrom = aData.translatedFrom;
     trUI.translatedTo = aData.translatedTo;
     trUI.originalShown = aData.originalShown;
 
     trUI.showURLBarIcon();
 
     if (trUI.shouldShowInfoBar(aBrowser.currentURI))
@@ -232,33 +233,16 @@ TranslationUI.prototype = {
     if (perms.testExactPermission(aURI, "translate") ==  perms.DENY_ACTION) {
       TranslationHealthReport.recordAutoRejectedTranslationOffer();
       return false;
     }
 
     return true;
   },
 
-  showTranslationUI: function(aDetectedLanguage) {
-    this.detectedLanguage = aDetectedLanguage;
-
-    // Reset all values before showing a new translation infobar.
-    this.state = 0;
-    this.translatedFrom = "";
-    this.translatedTo = "";
-    this.originalShown = true;
-
-    this.showURLBarIcon();
-
-    if (!this.shouldShowInfoBar(this.browser.currentURI))
-      return null;
-
-    return this.showTranslationInfoBar();
-  },
-
   receiveMessage: function(msg) {
     switch (msg.name) {
       case "Translation:Finished":
         if (msg.data.success) {
           this.originalShown = false;
           this.state = Translation.STATE_TRANSLATED;
           this.showURLBarIcon();
 
--- a/browser/components/translation/translation-infobar.xml
+++ b/browser/components/translation/translation-infobar.xml
@@ -176,17 +176,17 @@
               fromLanguage.appendItem(name, code);
             }
             detectedLanguage.value = this.translation.detectedLanguage;
 
             // translatedFrom is only set if we have already translated this page.
             if (aTranslation.translatedFrom)
               fromLanguage.value = aTranslation.translatedFrom;
 
-            // Fill the list of supporter target languages.
+            // Fill the list of supported target languages.
             let toLanguage = this._getAnonElt("toLanguage");
             for (let code of Translation.supportedTargetLanguages)
               toLanguage.appendItem(bundle.GetStringFromName(code), code);
 
             if (aTranslation.translatedTo)
               toLanguage.value = aTranslation.translatedTo;
 
             if (aTranslation.state)
@@ -258,18 +258,25 @@
 
       <method name="optionsShowing">
         <body>
           <![CDATA[
             // Get the source language name.
             let lang;
             if (this.state == Translation.STATE_OFFER)
               lang = this._getAnonElt("detectedLanguage").value;
-            else
+            else {
               lang = this._getAnonElt("fromLanguage").value;
+
+              // If we have never attempted to translate the page before the
+              // service became unavailable, "fromLanguage" isn't set.
+              if (!lang && this.state == Translation.STATE_UNAVAILABLE)
+                lang = this.translation.detectedLanguage;
+            }
+
             let langBundle =
               Cc["@mozilla.org/intl/stringbundle;1"]
                 .getService(Ci.nsIStringBundleService)
                 .createBundle("chrome://global/locale/languageNames.properties");
             let langName = langBundle.GetStringFromName(lang);
 
             // Set the label and accesskey on the menuitem.
             let bundle =