bug 454518 -allow opening URLs that are not linked from the context menu (if selected), r=gavin, ui-r=beltzner

This commit is contained in:
Mike Connor
2009-09-09 05:10:53 -04:00
parent 2271bb0e59
commit 1e8a35a91b
3 changed files with 33 additions and 1 deletions

View File

@@ -44,6 +44,10 @@
accesskey="&spellAddToDictionary.accesskey;"
oncommand="InlineSpellCheckerUI.addToDictionary();"/>
<menuseparator id="spell-suggestions-separator"/>
<menuitem id="context-openlinkincurrent"
label="&openLinkCmdInCurrent.label;"
accesskey="&openLinkCmdInCurrent.accesskey;"
oncommand="gContextMenu.openLinkInCurrent();"/>
<menuitem id="context-openlink"
label="&openLinkCmd.label;"
accesskey="&openLinkCmd.accesskey;"

View File

@@ -143,9 +143,29 @@ nsContextMenu.prototype = {
mailtoHandler.preferredAction == Ci.nsIHandlerInfo.useHelperApp &&
(mailtoHandler.preferredApplicationHandler instanceof Ci.nsIWebHandlerApp));
}
var shouldShow = this.onSaveableLink || isMailtoInternal;
// time to do some bad things and see if we've highlighted a URL that isn't actually linked
if (this.isTextSelected) {
// ok, we have some text, let's figure out if it looks like a URL
var someText = document.commandDispatcher.focusedWindow
.getSelection().toString();
try {
var uri = makeURI(someText);
}
catch (ex) { }
var onPlainTextLink = false;
if (uri && /^(https?|ftp)/i.test(uri.scheme) && uri.host) {
this.linkURI = uri;
this.linkURL = this.linkURI.spec;
onPlainTextLink = true;
}
}
var shouldShow = this.onSaveableLink || isMailtoInternal || onPlainTextLink;
this.showItem("context-openlink", shouldShow);
this.showItem("context-openlinkintab", shouldShow);
this.showItem("context-openlinkincurrent", onPlainTextLink);
this.showItem("context-sep-open", shouldShow);
},
@@ -655,6 +675,12 @@ nsContextMenu.prototype = {
openNewTabWith(this.linkURL, this.target.ownerDocument, null, null, false);
},
// open URL in current tab
openLinkInCurrent: function() {
openUILinkIn(this.linkURL, "current", null, null,
this.target.ownerDocument.documentURIObject);
},
// Open frame in a new tab.
openFrameInTab: function() {
var doc = this.target.ownerDocument;

View File

@@ -235,6 +235,8 @@
<!ENTITY openLinkCmd.label "Open Link in New Window">
<!ENTITY openLinkCmd.accesskey "W">
<!ENTITY openLinkCmdInCurrent.label "Open Link">
<!ENTITY openLinkCmdInCurrent.accesskey "O">
<!ENTITY openLinkCmdInTab.label "Open Link in New Tab">
<!ENTITY openLinkCmdInTab.accesskey "T">
<!ENTITY openFrameCmd.label "Open Frame in New Window">