Bug 1394158 - Make BrowserUtils.getSelectionDetails check for URLs inside editable elements r?Felipe draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Sat, 26 Aug 2017 19:21:44 -0400
changeset 653700 62ed075059a82003cb75540575974d9b61d5aed7
parent 653698 3e9b7e7116b711d4996bbe990c662a870e16f70a
child 728386 bdd593014d29a55c7aa33ae191b30a265ed59476
push id76378
push userbmo:tchiovoloni@mozilla.com
push dateSat, 26 Aug 2017 23:33:49 +0000
reviewersFelipe
bugs1394158
milestone57.0a1
Bug 1394158 - Make BrowserUtils.getSelectionDetails check for URLs inside editable elements r?Felipe MozReview-Commit-ID: JVRJ3sqmGnA
toolkit/modules/BrowserUtils.jsm
--- a/toolkit/modules/BrowserUtils.jsm
+++ b/toolkit/modules/BrowserUtils.jsm
@@ -491,16 +491,27 @@ this.BrowserUtils = {
     let selection = focusedWindow.getSelection();
     let selectionStr = selection.toString();
     let fullText;
 
     let collapsed = selection.isCollapsed;
 
     let url;
     let linkText;
+
+    // try getting a selected text in text input.
+    if (!selectionStr && focusedElement instanceof Ci.nsIDOMNSEditableElement) {
+      // Don't get the selection for password fields. See bug 565717.
+      if (focusedElement instanceof Ci.nsIDOMHTMLTextAreaElement ||
+          (focusedElement instanceof Ci.nsIDOMHTMLInputElement &&
+           focusedElement.mozIsTextField(true))) {
+        selectionStr = focusedElement.editor.selection.toString();
+      }
+    }
+
     if (selectionStr) {
       // Have some text, let's figure out if it looks like a URL that isn't
       // actually a link.
       linkText = selectionStr.trim();
       if (/^(?:https?|ftp):/i.test(linkText)) {
         try {
           url = this.makeURI(linkText);
         } catch (ex) {}
@@ -543,26 +554,16 @@ this.BrowserUtils = {
                            .getService(Ci.nsIURIFixup);
           try {
             url = uriFixup.createFixupURI(linkText, uriFixup.FIXUP_FLAG_NONE);
           } catch (ex) {}
         }
       }
     }
 
-    // try getting a selected text in text input.
-    if (!selectionStr && focusedElement instanceof Ci.nsIDOMNSEditableElement) {
-      // Don't get the selection for password fields. See bug 565717.
-      if (focusedElement instanceof Ci.nsIDOMHTMLTextAreaElement ||
-          (focusedElement instanceof Ci.nsIDOMHTMLInputElement &&
-           focusedElement.mozIsTextField(true))) {
-        selectionStr = focusedElement.editor.selection.toString();
-      }
-    }
-
     if (selectionStr) {
       // Pass up to 16K through unmolested.  If an add-on needs more, they will
       // have to use a content script.
       fullText = selectionStr.substr(0, 16384);
 
       if (selectionStr.length > charLen) {
         // only use the first charLen important chars. see bug 221361
         var pattern = new RegExp("^(?:\\s*.){0," + charLen + "}");