Bug 1253647 - Part 1 - Don't show page URL title on add-on restart doorhanger. r?sebastian draft
authorJan Henning <jh+bugzilla@buttercookie.de>
Wed, 10 May 2017 22:24:14 +0200
changeset 575741 a6cb6b948454e0ef46111d6d4804b6b2d6d672d7
parent 575740 9da1bb11da2413cbed7a2d489bf35797501f343f
child 628007 c1bca469fd3075d8be81fe9ec1a7d71d98ad368f
push id58154
push usermozilla@buttercookie.de
push dateWed, 10 May 2017 20:27:02 +0000
reviewerssebastian
bugs1253647
milestone55.0a1
Bug 1253647 - Part 1 - Don't show page URL title on add-on restart doorhanger. r?sebastian When a non-restartless add-on is (un)installed or updated, we show a doorhanger prompting the user to restart. Currently, the doorhanger's title is using the default logic for choosing its title, that is using the base domain of the tab the doorhanger is being displayed on. By chance, when the doorhanger is triggered from about:addons there is no domain to display, so the doorhanger is just displaying the restart notification. If however an add-on is automatically updated while the user is browsing, then the restart prompt will show the domain of the currently open tab in conjunction with the restart message. This can be confusing for the user, as it looks like it was in fact the current page that triggered the restart prompt. Therefore, we change this behaviour and just show a generic "Add-ons" as title for this case. MozReview-Commit-ID: 3pMwSiLul99
mobile/android/base/java/org/mozilla/gecko/DoorHangerPopup.java
mobile/android/base/java/org/mozilla/gecko/widget/DoorHanger.java
mobile/android/chrome/content/browser.js
--- a/mobile/android/base/java/org/mozilla/gecko/DoorHangerPopup.java
+++ b/mobile/android/base/java/org/mozilla/gecko/DoorHangerPopup.java
@@ -14,16 +14,18 @@ import org.mozilla.gecko.util.BundleEven
 import org.mozilla.gecko.util.EventCallback;
 import org.mozilla.gecko.util.GeckoBundle;
 import org.mozilla.gecko.widget.AnchoredPopup;
 import org.mozilla.gecko.widget.DoorHanger;
 import org.mozilla.gecko.widget.DoorhangerConfig;
 
 import java.util.HashSet;
 
+import static org.mozilla.gecko.widget.DoorHanger.Type;
+
 public class DoorHangerPopup extends AnchoredPopup
                              implements BundleEventListener,
                                         Tabs.OnTabsChangedListener,
                                         PopupWindow.OnDismissListener,
                                         DoorHanger.OnButtonClickListener {
     private static final String LOGTAG = "GeckoDoorHangerPopup";
 
     // Stores a set of all active DoorHanger notifications. A DoorHanger is
@@ -284,17 +286,19 @@ public class DoorHangerPopup extends Anc
             dismiss();
             return;
         }
 
         showDividers();
 
         final String baseDomain = tab.getBaseDomain();
 
-        if (TextUtils.isEmpty(baseDomain)) {
+        if (firstDoorhanger.getType() == Type.ADDON) {
+            firstDoorhanger.showTitle(null, mContext.getString(R.string.addons));
+        } else if (TextUtils.isEmpty(baseDomain)) {
             firstDoorhanger.hideTitle();
         } else {
             firstDoorhanger.showTitle(tab.getFavicon(), baseDomain);
         }
 
         if (isShowing()) {
             show();
             return;
--- a/mobile/android/base/java/org/mozilla/gecko/widget/DoorHanger.java
+++ b/mobile/android/base/java/org/mozilla/gecko/widget/DoorHanger.java
@@ -4,16 +4,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.widget;
 
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable;
+import android.support.annotation.Nullable;
 import android.support.v4.content.ContextCompat;
 import android.support.v4.widget.TextViewCompat;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewStub;
 import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
@@ -36,17 +37,27 @@ public abstract class DoorHanger extends
                 return new LoginDoorHanger(context, config);
             case TRACKING:
                 return new ContentSecurityDoorHanger(context, config, type);
         }
         return new DefaultDoorHanger(context, config, type);
     }
 
     // Doorhanger types created from Gecko are checked against enum strings to determine type.
-    public static enum Type { DEFAULT, LOGIN, TRACKING, GEOLOCATION, DESKTOPNOTIFICATION2, WEBRTC, VIBRATION, FLYWEBPUBLISHSERVER }
+    public enum Type {
+        DEFAULT,
+        LOGIN,
+        TRACKING,
+        GEOLOCATION,
+        DESKTOPNOTIFICATION2,
+        WEBRTC,
+        VIBRATION,
+        FLYWEBPUBLISHSERVER,
+        ADDON
+    }
 
     public interface OnButtonClickListener {
         public void onButtonClick(GeckoBundle response, DoorHanger doorhanger);
     }
 
     private static final String LOGTAG = "GeckoDoorHanger";
 
     // Divider between doorhangers.
@@ -138,16 +149,20 @@ public abstract class DoorHanger extends
 
         if (positiveButtonConfig != null) {
             mPositiveButton.setText(positiveButtonConfig.label);
             mPositiveButton.setOnClickListener(makeOnButtonClickListener(positiveButtonConfig.callback, "positive"));
             mPositiveButton.setVisibility(VISIBLE);
         }
    }
 
+    public Type getType() {
+        return mType;
+    }
+
     public int getTabId() {
         return mTabId;
     }
 
     public String getIdentifier() {
         return mIdentifier;
     }
 
@@ -202,17 +217,17 @@ public abstract class DoorHanger extends
 
         if (System.currentTimeMillis() <= mTimeout) {
             return false;
         }
 
         return true;
     }
 
-    public void showTitle(Bitmap favicon, String title) {
+    public void showTitle(@Nullable Bitmap favicon, String title) {
         mDoorhangerTitle.setText(title);
         TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds(mDoorhangerTitle, new BitmapDrawable(getResources(), favicon), null, null, null);
         if (favicon != null) {
             mDoorhangerTitle.setCompoundDrawablePadding((int) mContext.getResources().getDimension(R.dimen.doorhanger_drawable_padding));
         }
         mDoorhangerTitle.setVisibility(VISIBLE);
     }
 
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -5568,17 +5568,17 @@ var XPInstallObserver = {
           let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
           appStartup.quit(Ci.nsIAppStartup.eRestart | Ci.nsIAppStartup.eAttemptQuit);
         }
       },
       positive: true
     }];
 
     let message = Strings.browser.GetStringFromName("notificationRestart.normal");
-    NativeWindow.doorhanger.show(message, "addon-app-restart", buttons, BrowserApp.selectedTab.id, { persistence: -1 });
+    NativeWindow.doorhanger.show(message, "addon-app-restart", buttons, BrowserApp.selectedTab.id, { persistence: -1 }, "ADDON");
   },
 
   hideRestartPrompt: function() {
     NativeWindow.doorhanger.hide("addon-app-restart", BrowserApp.selectedTab.id);
   }
 };
 
 /**