Bug 832990 - Part 1 - Make MenuItemInfo classes parcelable. r=Grisha. a=RyanVM
authorJan Henning <jh+bugzilla@buttercookie.de>
Thu, 25 Jan 2018 20:20:35 +0100
changeset 454677 86d6ff85a12102157fc3db46d9fb4fcd49c2c2e9
parent 454676 565b8dcd3e87a78507323bded95fc468b2bd2300
child 454678 42a636fb6dce797f066d585db45e86505c272872
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGrisha, RyanVM
bugs832990, 1414084
milestone59.0
Bug 832990 - Part 1 - Make MenuItemInfo classes parcelable. r=Grisha. a=RyanVM Longer term, the MenuItemInfo handling needs to be moved out of BrowserApp in order to solve bug 1414084 [1], but the easier short term solution is to just save the cached menu data via the savedInstanceState. This means that MenuItemInfo and friends have to be made parcelable. [1] Because of GeckoView, add-ons may load (and attempt to add menu items) while BrowserApp isn't even alive. MozReview-Commit-ID: HzPe7ZKbJOj
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -30,16 +30,18 @@ import android.graphics.drawable.Drawabl
 import android.net.Uri;
 import android.nfc.NdefMessage;
 import android.nfc.NdefRecord;
 import android.nfc.NfcAdapter;
 import android.nfc.NfcEvent;
 import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
+import android.os.Parcel;
+import android.os.Parcelable;
 import android.os.StrictMode;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.annotation.StringRes;
 import android.support.annotation.UiThread;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -267,29 +269,98 @@ public class BrowserApp extends GeckoApp
     public static final String TAB_HISTORY_FRAGMENT_TAG = "tabHistoryFragment";
 
     // When the static action bar is shown, only the real toolbar chrome should be
     // shown when the toolbar is visible. Causing the toolbar animator to also
     // show the snapshot causes the content to shift under the users finger.
     // See: Bug 1358554
     private boolean mShowingToolbarChromeForActionBar;
 
-    private static class MenuItemInfo {
+    private static class MenuItemInfo implements Parcelable {
         public int id;
         public String label;
         public boolean checkable;
         public boolean checked;
         public boolean enabled = true;
         public boolean visible = true;
         public int parent;
         public boolean added;   // So we can re-add after a locale change.
+
+        @Override
+        public int describeContents() {
+            return 0;
+        }
+
+        @Override
+        public void writeToParcel(Parcel dest, int flags) {
+            dest.writeInt(id);
+            dest.writeString(label);
+            dest.writeInt(checkable ? 1 : 0);
+            dest.writeInt(checked ? 1 : 0);
+            dest.writeInt(enabled ? 1 : 0);
+            dest.writeInt(visible ? 1 : 0);
+            dest.writeInt(parent);
+            dest.writeInt(added ? 1 : 0);
+        }
+
+        public static final Parcelable.Creator<MenuItemInfo> CREATOR
+                = new Parcelable.Creator<MenuItemInfo>() {
+            @Override
+            public MenuItemInfo createFromParcel(Parcel source) {
+                return new MenuItemInfo(source);
+            }
+
+            @Override
+            public MenuItemInfo[] newArray(int size) {
+                return new MenuItemInfo[size];
+            }
+        };
+
+        private MenuItemInfo(Parcel source) {
+            id = source.readInt();
+            label = source.readString();
+            checkable = source.readInt() != 0;
+            checked = source.readInt() != 0;
+            enabled = source.readInt() != 0;
+            visible = source.readInt() != 0;
+            parent = source.readInt();
+            added = source.readInt() != 0;
+        }
+
+        public MenuItemInfo() { }
     }
 
     private static class BrowserActionItemInfo extends MenuItemInfo {
         public String uuid;
+
+        @Override
+        public void writeToParcel(Parcel dest, int flags) {
+            super.writeToParcel(dest, flags);
+            dest.writeString(uuid);
+        }
+
+        public static final Parcelable.Creator<BrowserActionItemInfo> CREATOR
+                = new Parcelable.Creator<BrowserActionItemInfo>() {
+            @Override
+            public BrowserActionItemInfo createFromParcel(Parcel source) {
+                return new BrowserActionItemInfo(source);
+            }
+
+            @Override
+            public BrowserActionItemInfo[] newArray(int size) {
+                return new BrowserActionItemInfo[size];
+            }
+        };
+
+        private BrowserActionItemInfo(Parcel source) {
+            super(source);
+            uuid = source.readString();
+        }
+
+        public BrowserActionItemInfo() { }
     }
 
     // The types of guest mode dialogs we show.
     public static enum GuestModeDialog {
         ENTERING,
         LEAVING
     }