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 75833 7254c4f4a8050e0d1369655ad10e1792035677b5
parent 75832 7f4eeae55c3006aa4c34a623e8d3e63040455c7e
child 75834 a9677078eb734443381c11fc95fbcf04c01bf455
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmfinkle
bugs681718
milestone9.0a1
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();