Bug 883390 - Part 1.4 - Update urlbar more intelligently, use tasks in doOpenSearch like we do in goToURI. r=sfoster
authorJonathan Wilde <jwilde@jwilde.me>
Mon, 15 Jul 2013 11:27:28 -0700
changeset 138554 79e6b9d02f22ca628bb50d536fcd97cee03b283e
parent 138553 c112dc25fa8c639a4de4692e20c7978cb397ecad
child 138555 45a9aeb25008309fca5d5e8023047f85a2ca11d1
push idunknown
push userunknown
push dateunknown
reviewerssfoster
bugs883390
milestone25.0a1
Bug 883390 - Part 1.4 - Update urlbar more intelligently, use tasks in doOpenSearch like we do in goToURI. r=sfoster
browser/metro/base/content/WebProgress.js
browser/metro/base/content/bindings/urlbar.xml
browser/metro/base/content/browser-ui.js
browser/metro/base/content/browser.js
--- a/browser/metro/base/content/WebProgress.js
+++ b/browser/metro/base/content/WebProgress.js
@@ -79,18 +79,20 @@ const WebProgress = {
       identityBox.className = aTab._identityState;
     }
   },
 
   _locationChange: function _locationChange(aJson, aTab) {
     let spec = aJson.location;
     let location = spec.split("#")[0]; // Ignore fragment identifier changes.
 
-    if (aTab == Browser.selectedTab)
+    if (aTab == Browser.selectedTab) {
       BrowserUI.updateURI();
+      BrowserUI.update();
+    }
 
     let locationHasChanged = (location != aTab.browser.lastLocation);
     if (locationHasChanged) {
       Browser.getNotificationBox(aTab.browser).removeTransientNotifications();
       aTab.resetZoomLevel();
       aTab.browser.lastLocation = location;
       aTab.browser.userTypedValue = "";
       aTab.browser.appIcon = { href: null, size:-1 };
@@ -118,32 +120,25 @@ const WebProgress = {
       aTab.scrolledAreaChanged(true);
       aTab.updateThumbnailSource();
     });
   },
 
   _networkStart: function _networkStart(aJson, aTab) {
     aTab.startLoading();
 
-    if (aTab == Browser.selectedTab) {
+    if (aTab == Browser.selectedTab)
       BrowserUI.update(TOOLBARSTATE_LOADING);
-
-      // We should at least show something in the URLBar until
-      // the load has progressed further along
-      if (aTab.browser.currentURI.spec == "about:blank")
-        BrowserUI.updateURI({ captionOnly: true });
-    }
   },
 
   _networkStop: function _networkStop(aJson, aTab) {
     aTab.endLoading();
 
-    if (aTab == Browser.selectedTab) {
+    if (aTab == Browser.selectedTab)
       BrowserUI.update(TOOLBARSTATE_LOADED);
-    }
   },
 
   _windowStart: function _windowStart(aJson, aTab) {
     this._progressStart(aJson, aTab);
   },
 
   _windowStop: function _windowStop(aJson, aTab) {
     this._progressStop(aJson, aTab);
@@ -157,17 +152,17 @@ const WebProgress = {
 
     this._progressActive = true;
 
     // display the track
     Elements.progressContainer.removeAttribute("collapsed");
 
     // 'Whoosh' in
     this._progressCount = kProgressMarginStart;
-    Elements.progress.style.width = this._progressCount + "%"; 
+    Elements.progress.style.width = this._progressCount + "%";
     Elements.progress.removeAttribute("fade");
 
     // Create a pulse timer to keep things moving even if we don't
     // collect any state changes.
     setTimeout(function() {
       WebProgress._progressStepTimer();
     }, kHeartbeatDuration, this);
   },
@@ -199,26 +194,26 @@ const WebProgress = {
     setTimeout(function() {
       WebProgress._progressStepTimer();
     }, kHeartbeatDuration, this);
   },
 
   _progressStop: function _progressStop(aJson, aTab) {
     this._progressActive = false;
     // 'Whoosh out' and fade
-    Elements.progress.style.width = "100%"; 
+    Elements.progress.style.width = "100%";
     Elements.progress.setAttribute("fade", true);
   },
 
   _progressTransEnd: function _progressTransEnd(data) {
     if (!Elements.progress.hasAttribute("fade"))
       return;
     // Close out fade finished, reset
     if (data.propertyName == "opacity") {
-      Elements.progress.style.width = "0px"; 
+      Elements.progress.style.width = "0px";
       Elements.progressContainer.setAttribute("collapsed", true);
     }
   },
 
   _onTabSelect: function(aEvent) {
     let identityBox = document.getElementById("identity-box-inner");
     let tab = Browser.getTabFromChrome(aEvent.originalTarget);
     identityBox.className = tab._identityState || "";
--- a/browser/metro/base/content/browser-ui.js
+++ b/browser/metro/base/content/browser-ui.js
@@ -289,20 +289,32 @@ var BrowserUI = {
 #endif
   },
 
 
   /*********************************
    * Navigation
    */
 
+  /* Updates the overall state of the toolbar, but not the URL bar. */
   update: function(aState) {
+    let uri = this.getDisplayURI(Browser.selectedBrowser);
+    StartUI.update(uri);
+
+    this._updateButtons();
     this._updateToolbar();
   },
 
+  /* Updates the URL bar. */
+  updateURI: function(aOptions) {
+    let uri = this.getDisplayURI(Browser.selectedBrowser);
+    let cleanURI = Util.isURLEmpty(uri) ? "" : uri;
+    this._edit.value = cleanURI;
+  },
+
   getDisplayURI: function(browser) {
     let uri = browser.currentURI;
     let spec = uri.spec;
 
     try {
       spec = gURIFixup.createExposableURI(uri).spec;
     } catch (ex) {}
 
@@ -311,45 +323,28 @@ var BrowserUI = {
       let textToSubURI = Cc["@mozilla.org/intl/texttosuburi;1"].
                          getService(Ci.nsITextToSubURI);
       spec = textToSubURI.unEscapeNonAsciiURI(charset, spec);
     } catch (ex) {}
 
     return spec;
   },
 
-  /* Set the location to the current content */
-  updateURI: function(aOptions) {
-    aOptions = aOptions || {};
-
-    let uri = this.getDisplayURI(Browser.selectedBrowser);
-    let cleanURI = Util.isURLEmpty(uri) ? "" : uri;
-
-    this._edit.value = cleanURI;
-
-    if ("captionOnly" in aOptions && aOptions.captionOnly)
-      return;
-
-    StartUI.update(uri);
-    this._updateButtons();
-    this._updateToolbar();
-  },
-
   goToURI: function(aURI) {
     aURI = aURI || this._edit.value;
     if (!aURI)
       return;
 
     this._edit.value = aURI;
 
     // Make sure we're online before attempting to load
     Util.forceOnline();
 
     BrowserUI.showContent(aURI);
-    content.focus();
+    Browser.selectedBrowser.focus();
 
     Task.spawn(function() {
       let postData = {};
       aURI = yield Browser.getShortcutOrURI(aURI, postData);
       Browser.loadURI(aURI, { flags: Ci.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP, postData: postData });
 
       // Delay doing the fixup so the raw URI is passed to loadURIWithFlags
       // and the proper third-party fixup can be done
@@ -366,23 +361,27 @@ var BrowserUI = {
     let searchValue = this._edit.value;
     let engine = Services.search.getEngineByName(aName);
     let submission = engine.getSubmission(searchValue, null);
 
     this._edit.value = submission.uri.spec;
 
     // Make sure we're online before attempting to load
     Util.forceOnline();
+
     BrowserUI.showContent();
-
-    Browser.loadURI(submission.uri.spec, { postData: submission.postData });
+    Browser.selectedBrowser.focus();
 
-    // loadURI may open a new tab, so get the selectedBrowser afterward.
-    Browser.selectedBrowser.userTypedValue = submission.uri.spec;
-    this._titleChanged(Browser.selectedBrowser);
+    Task.spawn(function () {
+      Browser.loadURI(submission.uri.spec, { postData: submission.postData });
+
+      // loadURI may open a new tab, so get the selectedBrowser afterward.
+      Browser.selectedBrowser.userTypedValue = submission.uri.spec;
+      BrowserUI._titleChanged(Browser.selectedBrowser);
+    });
   },
 
   /*********************************
    * Tab management
    */
 
   newTab: function newTab(aURI, aOwner) {
     aURI = aURI || kStartOverlayURI;
--- a/browser/metro/base/content/browser.js
+++ b/browser/metro/base/content/browser.js
@@ -569,16 +569,17 @@ var Browser = {
       tab.active = true;
 
     if (isFirstTab) {
       // Don't waste time at startup updating the whole UI; just display the URL.
       BrowserUI._titleChanged(browser);
     } else {
       // Update all of our UI to reflect the new tab's location
       BrowserUI.updateURI();
+      BrowserUI.update();
 
       let event = document.createEvent("Events");
       event.initEvent("TabSelect", true, false);
       event.lastTab = lastTab;
       tab.chromeTab.dispatchEvent(event);
     }
 
     tab.lastSelected = Date.now();
@@ -1573,17 +1574,17 @@ Tab.prototype = {
   },
 
   _copyHistoryFrom: function _copyHistoryFrom(tab) {
     let otherHistory = tab._browser._webNavigation.sessionHistory;
     let history = this._browser._webNavigation.sessionHistory;
 
     // Ensure that history is initialized
     history.QueryInterface(Ci.nsISHistoryInternal);
-    
+
     for (let i = 0, length = otherHistory.index; i <= length; i++)
       history.addEntry(otherHistory.getEntryAtIndex(i, false), true);
   },
 
   _loadUsingParams: function _loadUsingParams(aBrowser, aURI, aParams) {
     let flags = aParams.flags || Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
     let postData = ("postData" in aParams && aParams.postData) ? aParams.postData.value : null;
     let referrerURI = "referrerURI" in aParams ? aParams.referrerURI : null;