Bug 1299576 - Part 2 - Cancel edit mode when restoring a recently closed tab. r=sebastian
authorJan Henning <jh+bugzilla@buttercookie.de>
Fri, 02 Sep 2016 20:43:08 +0200
changeset 354552 e4a4be903748749050f45b72e41b793f220ce900
parent 354551 d5a1f6c89fe80c94be43d6ab2fb13835b404443c
child 354553 f6c287542f098c5cc14dacc3da64ab604db25ae8
push id6570
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:26:13 +0000
treeherdermozilla-beta@f455459b2ae5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian
bugs1299576
milestone51.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 1299576 - Part 2 - Cancel edit mode when restoring a recently closed tab. r=sebastian When restoring a recently closed tab from the corresponding home panel, we normally directly switch to the freshly recreated tab. However if we've entered the home panels through editing mode (as opposed to opening a new tab with about:home), editing mode takes priority and the restored tab is opened in background instead, because we return to the originally selected tab when exiting editing mode. To fix this inconsistency, we introduce a new parameter for opening tabs from Gecko that cancels editing mode if necessary to allow for directly switching to the new tab. MozReview-Commit-ID: 4iqPISmtNIx
mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
mobile/android/base/java/org/mozilla/gecko/Tabs.java
mobile/android/chrome/content/browser.js
mobile/android/components/SessionStore.js
--- a/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/BrowserApp.java
@@ -688,16 +688,17 @@ public class BrowserApp extends GeckoApp
 
         EventDispatcher.getInstance().registerGeckoThreadListener((GeckoEventListener)this,
             "Gecko:DelayedStartup",
             "Menu:Open",
             "Menu:Update",
             "LightweightTheme:Update",
             "Search:Keyword",
             "Prompt:ShowTop",
+            "Tab:Added",
             "Video:Play");
 
         EventDispatcher.getInstance().registerGeckoThreadListener((NativeEventListener)this,
             "CharEncoding:Data",
             "CharEncoding:State",
             "Download:AndroidDownloadManager",
             "Experiments:GetActive",
             "Experiments:SetOverride",
@@ -1422,16 +1423,17 @@ public class BrowserApp extends GeckoApp
 
         EventDispatcher.getInstance().unregisterGeckoThreadListener((GeckoEventListener) this,
             "Gecko:DelayedStartup",
             "Menu:Open",
             "Menu:Update",
             "LightweightTheme:Update",
             "Search:Keyword",
             "Prompt:ShowTop",
+            "Tab:Added",
             "Video:Play");
 
         EventDispatcher.getInstance().unregisterGeckoThreadListener((NativeEventListener) this,
             "CharEncoding:Data",
             "CharEncoding:State",
             "Download:AndroidDownloadManager",
             "Experiments:GetActive",
             "Experiments:SetOverride",
@@ -2039,16 +2041,30 @@ public class BrowserApp extends GeckoApp
                 case "Prompt:ShowTop":
                     // Bring this activity to front so the prompt is visible..
                     Intent bringToFrontIntent = new Intent();
                     bringToFrontIntent.setClassName(AppConstants.ANDROID_PACKAGE_NAME, AppConstants.MOZ_ANDROID_BROWSER_INTENT_CLASS);
                     bringToFrontIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
                     startActivity(bringToFrontIntent);
                     break;
 
+                case "Tab:Added":
+                    if (message.getBoolean("cancelEditMode")) {
+                        ThreadUtils.postToUiThread(new Runnable() {
+                            @Override
+                            public void run() {
+                                // Set the target tab to null so it does not get selected (on editing
+                                // mode exit) in lieu of the tab that we're going to open and select.
+                                mTargetTabForEditingMode = null;
+                                mBrowserToolbar.cancelEdit();
+                            }
+                        });
+                    }
+                    break;
+
                 default:
                     super.handleMessage(event, message);
                     break;
             }
         } catch (Exception e) {
             Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
         }
     }
--- a/mobile/android/base/java/org/mozilla/gecko/Tabs.java
+++ b/mobile/android/base/java/org/mozilla/gecko/Tabs.java
@@ -467,16 +467,23 @@ public class Tabs implements GeckoEventL
             // All other events handled below should contain a tabID property
             int id = message.getInt("tabID");
             Tab tab = getTab(id);
 
             // "Tab:Added" is a special case because tab will be null if the tab was just added
             if (event.equals("Tab:Added")) {
                 String url = message.isNull("uri") ? null : message.getString("uri");
 
+                if (message.getBoolean("cancelEditMode")) {
+                    final Tab oldTab = getSelectedTab();
+                    if (oldTab != null) {
+                        oldTab.setIsEditing(false);
+                    }
+                }
+
                 if (message.getBoolean("stub")) {
                     if (tab == null) {
                         // Tab was already closed; abort
                         return;
                     }
                 } else {
                     tab = addTab(id, url, message.getBoolean("external"),
                                           message.getInt("parentId"),
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3520,17 +3520,18 @@ Tab.prototype = {
 
       let message = {
         type: "Tab:Added",
         tabID: this.id,
         uri: truncate(uri, MAX_URI_LENGTH),
         parentId: ("parentId" in aParams) ? aParams.parentId : -1,
         tabIndex: ("tabIndex" in aParams) ? aParams.tabIndex : -1,
         external: ("external" in aParams) ? aParams.external : false,
-        selected: ("selected" in aParams) ? aParams.selected : true,
+        selected: ("selected" in aParams || aParams.cancelEditMode === true) ? aParams.selected : true,
+        cancelEditMode: aParams.cancelEditMode === true,
         title: truncate(title, MAX_TITLE_LENGTH),
         delayLoad: aParams.delayLoad || false,
         desktopMode: this.desktopMode,
         isPrivate: isPrivate,
         stub: stub
       };
       Messaging.sendRequest(message);
     }
--- a/mobile/android/components/SessionStore.js
+++ b/mobile/android/components/SessionStore.js
@@ -1342,20 +1342,22 @@ SessionStore.prototype = {
     }
   },
 
   // This function iterates through a list of tab data restoring session for each of them.
   _restoreTabs: function ss_restoreTabs(aData) {
     let window = Services.wm.getMostRecentWindow("navigator:browser");
     for (let i = 0; i < aData.tabs.length; i++) {
       let tabData = JSON.parse(aData.tabs[i]);
+      let isSelectedTab = (i == aData.tabs.length - 1);
       let params = {
-        selected: (i == aData.tabs.length - 1),
+        selected: isSelectedTab,
         isPrivate: tabData.isPrivate,
         desktopMode: tabData.desktopMode,
+        cancelEditMode: isSelectedTab
       };
 
       let tab = window.BrowserApp.addTab(tabData.entries[tabData.index - 1].url, params);
       tab.browser.__SS_data = tabData;
       tab.browser.__SS_extdata = tabData.extData;
       this._restoreTab(tabData, tab.browser);
     }
   },