Bug 681718 - Fix JS errors from text selection when long-tapping on local pages [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Wed, 24 Aug 2011 12:38:40 -0700
changeset 77144 7254c4f4a8050e0d1369655ad10e1792035677b5
parent 77143 7f4eeae55c3006aa4c34a623e8d3e63040455c7e
child 77145 a9677078eb734443381c11fc95fbcf04c01bf455
push id78
push userclegnitto@mozilla.com
push dateFri, 16 Dec 2011 17:32:24 +0000
treeherdermozilla-release@79d24e644fdd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs681718
milestone9.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 681718 - Fix JS errors from text selection when long-tapping on local pages [r=mfinkle]
mobile/chrome/content/content.js
--- a/mobile/chrome/content/content.js
+++ b/mobile/chrome/content/content.js
@@ -1360,17 +1360,17 @@ var SelectionHandler = {
       x -= rect.left;
       
       offset.y += rect.top + scrollOffset.y;
       y -= rect.top + scrollOffset.y;
       utils = elem.contentDocument.defaultView.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowUtils);
       elem = utils.elementFromPoint(x, y, true, false);
     }
     if (!elem)
-      return;
+      return {};
     
     return { contentWindow: elem.ownerDocument.defaultView, offset: offset };
   },
 
   receiveMessage: function sh_receiveMessage(aMessage) {
     let scrollOffset = ContentScroll.getScrollOffset(content);
     let utils = Util.getWindowUtils(content);
     let json = aMessage.json;
@@ -1379,16 +1379,19 @@ var SelectionHandler = {
       case "Browser:SelectionStart": {
         // Clear out the text cache
         this.selectedText = "";
 
         // if this is an iframe, dig down to find the document that was clicked
         let x = json.x - scrollOffset.x;
         let y = json.y - scrollOffset.y;
         let { contentWindow: contentWindow, offset: offset } = this.getCurrentWindowAndOffset(x, y, scrollOffset);
+        if (!contentWindow)
+          return;
+
         let currentDocShell = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShell);
 
         // Remove any previous selected or created ranges. Tapping anywhere on a
         // page will create an empty range.
         let selection = contentWindow.getSelection();
         selection.removeAllRanges();
 
         try {
@@ -1493,16 +1496,19 @@ var SelectionHandler = {
         let selection = this.contentWindow.getSelection()
         this.selectedText = selection.toString().trim();
 
         // Update the rect we use to test when finishing the clipboard operation
         let range = selection.getRangeAt(0).QueryInterface(Ci.nsIDOMNSRange);
         this.cache.rect = this._extractFromRange(range, this.cache.offset).rect;
         break;
       case "Browser:SelectionMeasure": {
+        if (!this.contentWindow)
+          return;
+
         let selection = this.contentWindow.getSelection();
         let range = selection.getRangeAt(0).QueryInterface(Ci.nsIDOMNSRange);
         if (!range)
           return;
 
         // Cache the selected text since the selection might be gone by the time we get the "end" message
         this.selectedText = selection.toString().trim();