Bug 775372 - Fix exceptions in _cancelTapHighlight when the highlight element is from a dead window [r=margaret]
authorMatt Brubeck <mbrubeck@mozilla.com>
Fri, 27 Jul 2012 16:03:18 -0700
changeset 100787 4b197ffb4dcc2561df68c2488d109be04da8edd9
parent 100786 7a1a791c856fdcb8478873f4e18791fff1d0d0ae
child 100788 b921323fa99efe38aade2f7fe3d4f161c851fae6
push id23193
push userryanvm@gmail.com
push dateSat, 28 Jul 2012 21:54:39 +0000
treeherdermozilla-central@29bff59d3bbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs775372
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 775372 - Fix exceptions in _cancelTapHighlight when the highlight element is from a dead window [r=margaret]
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -3472,37 +3472,47 @@ var BrowserEventHandler = {
 
   _highlightElement: null,
 
   _highlightTimeout: null,
 
   _doTapHighlight: function _doTapHighlight(aElement) {
     this._cancelTapHighlight();
     this._highlightTimeout = setTimeout(function(self) {
+      // If aElement is from a dead window, defaultView will be null.
+      if (!aElement.ownerDocument.defaultView)
+        return;
+
       DOMUtils.setContentState(aElement, kStateActive);
       self._highlightElement = aElement;
     }, kTapHighlightDelay, this);
   },
 
   _cancelTapHighlight: function _cancelTapHighlight() {
     if (this._highlightTimeout) {
       clearTimeout(this._highlightTimeout);
       this._highlightTimeout = null;
     }
 
     if (!this._highlightElement)
       return;
 
+    let ownerDocument = this._highlightElement.ownerDocument;
+    this._highlightElement = null;
+
+    // If _highlightElement is from a dead window, defaultView will be null.
+    if (!ownerDocument.defaultView)
+      return;
+
     // If the active element is in a sub-frame, we need to make that frame's document
     // active to remove the element's active state.
-    if (this._highlightElement.ownerDocument != BrowserApp.selectedBrowser.contentWindow.document)
-      DOMUtils.setContentState(this._highlightElement.ownerDocument.documentElement, kStateActive);
+    if (ownerDocument != BrowserApp.selectedBrowser.contentWindow.document)
+      DOMUtils.setContentState(ownerDocument.documentElement, kStateActive);
 
     DOMUtils.setContentState(BrowserApp.selectedBrowser.contentWindow.document.documentElement, kStateActive);
-    this._highlightElement = null;
   },
 
   _updateLastPosition: function(x, y, dx, dy) {
     this.lastX = x;
     this.lastY = y;
     this.lastTime = Date.now();
 
     this.motionBuffer.push({ dx: dx, dy: dy, time: this.lastTime });