Bug 1083167 - Fix FormHistory error in ContentSearch by not passing an empty string to FormHistory.update. r=MattN, a=lsblakk
authorDrew Willcoxon <adw@mozilla.com>
Tue, 28 Oct 2014 13:46:29 -0700
changeset 225805 272d21e922037a9d68b5e2265f3436c38a4b636f
parent 225804 6459604b7ccc4642a0ad73eb66145c7d77788d55
child 225806 b10e61a4677157ae48537e6b5539db1619f04cac
push id7187
push userryanvm@gmail.com
push dateFri, 31 Oct 2014 15:59:42 +0000
treeherdermozilla-aurora@272d21e92203 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN, lsblakk
bugs1083167
milestone35.0a2
Bug 1083167 - Fix FormHistory error in ContentSearch by not passing an empty string to FormHistory.update. r=MattN, a=lsblakk
browser/modules/ContentSearch.jsm
--- a/browser/modules/ContentSearch.jsm
+++ b/browser/modules/ContentSearch.jsm
@@ -268,22 +268,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.isBrowserPrivate(msg.target)) {
+    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,
     }, {