Bug 1394158 - Make BrowserUtils.getSelectionDetails check for URLs inside editable elements r?Felipe
MozReview-Commit-ID: JVRJ3sqmGnA
--- 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 + "}");