Bug 689599 - Ensure postData is non-null before accessing it in Browser.loadURI [r=mfinkle, a=asa]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 27 Sep 2011 12:45:49 -0700
changeset 78195 2b4f99e468aa1dadce226c880f6415b2879ab842
parent 78194 ec885a01be0738b1e1262b83714648e1684f69c3
child 78196 d6c48e7f9b9d5ff5a8ff3f592eb6a65e2d5efedf
push id388
push usermbrubeck@mozilla.com
push dateTue, 27 Sep 2011 22:31:14 +0000
treeherdermozilla-aurora@2b4f99e468aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle, asa
bugs689599
milestone9.0a2
Bug 689599 - Ensure postData is non-null before accessing it in Browser.loadURI [r=mfinkle, a=asa]
mobile/chrome/content/browser-ui.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/browser-ui.js
+++ b/mobile/chrome/content/browser-ui.js
@@ -708,19 +708,20 @@ var BrowserUI = {
     Browser.hideSidebars();
     this.closeAutoComplete();
 
     // Make sure we're online before attempting to load
     Util.forceOnline();
 
     let engine = Services.search.getEngineByName(aName);
     let submission = engine.getSubmission(searchValue, null);
-    Browser.selectedBrowser.userTypedValue = submission.uri.spec;
     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;
     this._titleChanged(Browser.selectedBrowser);
   },
 
   updateUIFocus: function _updateUIFocus() {
     if (Elements.contentShowing.getAttribute("disabled") == "true")
       Browser.selectedBrowser.messageManager.sendAsyncMessage("Browser:Blur", { });
   },
 
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -596,18 +596,17 @@ var Browser = {
 
       // Add new tab before closing the old one, in case there is only one.
       Browser.addTab(aURI, true, oldTab, aParams);
       if (/^about:(blank|empty)$/.test(currentURI) && !browser.canGoBack && !browser.canGoForward) {
         oldTab.chromeTab.ignoreUndo = true;
         this.closeTab(oldTab, { forceClose: true });
         oldTab = null;
       }
-    }
-    else {
+    } else {
       let params = aParams || {};
       let flags = params.flags || Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
       browser.loadURIWithFlags(aURI, flags, params.referrerURI, params.charset, params.postData);
     }
   },
 
   /**
    * Determine if the given URL is a shortcut/keyword and, if so, expand it
@@ -2937,17 +2936,17 @@ Tab.prototype = {
     let browser = this._createBrowser(aURI, null);
 
     // Should we fully load the new browser, or wait until later
     if ("delayLoad" in aParams && aParams.delayLoad)
       return;
 
     try {
       let flags = aParams.flags || Ci.nsIWebNavigation.LOAD_FLAGS_NONE;
-      let postData = "postData" in aParams ? aParams.postData.value : null;
+      let postData = ("postData" in aParams && aParams.postData) ? aParams.postData.value : null;
       let referrerURI = "referrerURI" in aParams ? aParams.referrerURI : null;
       let charset = "charset" in aParams ? aParams.charset : null;
       browser.loadURIWithFlags(aURI, flags, referrerURI, charset, postData);
     } catch(e) {
       dump("Error: " + e + "\n");
     }
   },