From a3c433242e23db4705b2bf5e4e24555d3d66644d Mon Sep 17 00:00:00 2001 From: "mconnor%myrealbox.com" Date: Sat, 24 Jul 2004 00:24:30 +0000 Subject: [PATCH] bug 231393 - Tab URL does not persist on bad links if tabs switched, patch by pike@pikey.me.uk based on jag's patch for bug 103720, r=me git-svn-id: svn://10.0.0.236/trunk@159761 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/browser/base/content/browser.js | 15 +++++++++ mozilla/toolkit/content/widgets/browser.xml | 10 +++++- .../toolkit/content/widgets/tabbrowser.xml | 32 +++++++++++++++++-- 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/mozilla/browser/base/content/browser.js b/mozilla/browser/base/content/browser.js index fd27cd6ead7..6fd84ae451b 100644 --- a/mozilla/browser/base/content/browser.js +++ b/mozilla/browser/base/content/browser.js @@ -2515,6 +2515,10 @@ nsBrowserStatusHandler.prototype = var browser = getBrowser().selectedBrowser; if (aWebProgress.DOMWindow == content) { + // The document loaded correctly, clear the value if we should + if (browser.userTypedClear) + browser.userTypedValue = null; + //XXXBlake don't we have to reinit this.urlBar, etc. // when the toolbar changes? var userTypedValue = browser.userTypedValue; @@ -4358,6 +4362,14 @@ function stylesheetSwitchAll(frameset, title) { function updatePageTheme(evt) { + // XXX - Accessing window._content.document can generate an + // onLocationChange for the current tab, this can cause the url + // bar to be cleared. Prevent that happening by setting the clear + // state to false for the duration of this function. + var browser = getBrowser().selectedBrowser; + var userTypedClear = browser.userTypedClear; + browser.userTypedClear = false; + if (!gPageThemeButton) gPageThemeButton = document.getElementById("page-theme-button"); @@ -4383,6 +4395,9 @@ function updatePageTheme(evt) } else gPageThemeButton.removeAttribute("themes"); + + // Restore clear state + browser.userTypedClear = userTypedClear; } /* End of the Page Theme functions */ diff --git a/mozilla/toolkit/content/widgets/browser.xml b/mozilla/toolkit/content/widgets/browser.xml index 49b7c91addd..9d85bb40145 100644 --- a/mozilla/toolkit/content/widgets/browser.xml +++ b/mozilla/toolkit/content/widgets/browser.xml @@ -414,10 +414,18 @@ null - + + true + + + null + + false diff --git a/mozilla/toolkit/content/widgets/tabbrowser.xml b/mozilla/toolkit/content/widgets/tabbrowser.xml index 9e5b19a18c5..d46ed82cfaa 100644 --- a/mozilla/toolkit/content/widgets/tabbrowser.xml +++ b/mozilla/toolkit/content/widgets/tabbrowser.xml @@ -194,10 +194,13 @@ if (aStateFlags & nsIWebProgressListener.STATE_START && aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) { - // Reset so we can see if the user typed between the document - // load starting and the location changing. + // It's okay to clear what the user typed when we start + // loading a document. If the user types, this flag gets + // set to false, if the document load ends without an + // onLocationChange, this flag also gets set to false + // (so we keep it while switching tabs after failed load if (aWebProgress.DOMWindow == this.mBrowser.contentWindow) - this.mBrowser.userTypedValue = null; + this.mBrowser.userTypedClear = true; if (!this.mBlank) { this.mTab.setAttribute("busy", "true"); @@ -211,6 +214,11 @@ } else if (aStateFlags & nsIWebProgressListener.STATE_STOP && aStateFlags & nsIWebProgressListener.STATE_IS_NETWORK) { + // The document is done loading, it's okay to clear + // the value again. + if (aWebProgress.DOMWindow == this.mBrowser.contentWindow) + this.mBrowser.userTypedClear = false; + if (this.mBlank) this.mBlank = false; @@ -242,6 +250,10 @@ , onLocationChange : function(aWebProgress, aRequest, aLocation) { + // The document loaded correctly, clear the value if we should + if (this.mBrowser.userTypedClear) + this.mBrowser.userTypedValue = null; + if (!this.mBlank && this.mTabBrowser.mCurrentTab == this.mTab) { for (var i = 0; i < this.mTabBrowser.mProgressListeners.length; i++) { var p = this.mTabBrowser.mProgressListeners[i]; @@ -451,6 +463,11 @@ var webProgress = this.mCurrentBrowser.webProgress; var securityUI = this.mCurrentBrowser.securityUI; + // Remember the current clear state, then set it to false + // so we don't clear the userTypedValue when just switching + // tabs. Set it back to its old state after we're done. + var userTypedClear = this.mCurrentBrowser.userTypedClear; + this.mCurrentBrowser.userTypedClear = false; var i, p; for (i = 0; i < this.mProgressListeners.length; i++) { p = this.mProgressListeners[i]; @@ -463,6 +480,7 @@ p.onLinkIconAvailable(listener.mIcon); } } + this.mCurrentBrowser.userTypedClear = userTypedClear; // Update the window title. this.updateTitlebar(); @@ -817,6 +835,10 @@ this.mTabFilters[position] = filter; if (!blank) { + // pretend the user typed this so it'll be available till + // the document successfully loads + b.userTypedValue = aURI; + if (aPostData === undefined) aPostData = null; b.loadURIWithFlags(aURI, nsIWebNavigation.LOAD_FLAGS_NONE, @@ -1349,6 +1371,10 @@ onget="return this.mCurrentBrowser.canFindAgain;" readonly="true"/> + +