Bug 1083167 - Fix FormHistory error in ContentSearch by not passing an empty string to FormHistory.update. r=MattN, a=lmandel
authorDrew Willcoxon <adw@mozilla.com>
Tue, 28 Oct 2014 13:46:29 -0700
changeset 225889 cadb1112c8fb
parent 225888 73905ff57286
child 225890 340cfd2affa7
push id4058
push userdwillcoxon@mozilla.com
push date2014-10-31 16:37 +0000
treeherdermozilla-beta@cadb1112c8fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, lmandel
bugs1083167
milestone34.0
Bug 1083167 - Fix FormHistory error in ContentSearch by not passing an empty string to FormHistory.update. r=MattN, a=lmandel
browser/modules/ContentSearch.jsm
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -255,22 +255,24 @@ this.ContentSearch = {
       engineName: data.engineName,
       searchString: suggestions.term,
       formHistory: suggestions.local,
       remote: suggestions.remote,
     });
   }),
 
   _onMessageAddFormHistoryEntry: function (msg, entry) {
-    // There are some tests that use about:home and newtab that trigger a search
-    // and then immediately close the tab.  In those cases, the browser may have
-    // been destroyed by the time we receive this message, and as a result
-    // contentWindow is undefined.
-    if (!msg.target.contentWindow ||
-        PrivateBrowsingUtils.isWindowPrivate(msg.target.contentWindow)) {
+    let isPrivate = true;
+    try {
+      // isBrowserPrivate assumes that the passed-in browser has all the normal
+      // properties, which won't be true if the browser has been destroyed.
+      // That may be the case here due to the asynchronous nature of messaging.
+      isPrivate = PrivateBrowsingUtils.isBrowserPrivate(msg.target);
+    } catch (err) {}
+    if (isPrivate || entry === "") {
       return Promise.resolve();
     }
     let browserData = this._suggestionDataForBrowser(msg.target, true);
     FormHistory.update({
       op: "bump",
       fieldname: browserData.controller.formHistoryParam,
       value: entry,
     }, {