2007-03-22 10:30:00 -07:00
|
|
|
# ***** BEGIN LICENSE BLOCK *****
|
|
|
|
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
#
|
|
|
|
# The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
# 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
# the License. You may obtain a copy of the License at
|
|
|
|
# http://www.mozilla.org/MPL/
|
|
|
|
#
|
|
|
|
# Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
# for the specific language governing rights and limitations under the
|
|
|
|
# License.
|
|
|
|
#
|
|
|
|
# The Original Code is mozilla.org code.
|
|
|
|
#
|
|
|
|
# The Initial Developer of the Original Code is
|
|
|
|
# Netscape Communications Corporation.
|
|
|
|
# Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
# the Initial Developer. All Rights Reserved.
|
|
|
|
#
|
|
|
|
# Contributor(s):
|
|
|
|
# Blake Ross <blake@cs.stanford.edu>
|
|
|
|
# David Hyatt <hyatt@mozilla.org>
|
|
|
|
# Peter Annema <disttsc@bart.nl>
|
|
|
|
# Dean Tessman <dean_tessman@hotmail.com>
|
|
|
|
# Kevin Puetz <puetzk@iastate.edu>
|
|
|
|
# Ben Goodger <ben@netscape.com>
|
|
|
|
# Pierre Chanial <chanial@noos.fr>
|
|
|
|
# Jason Eager <jce2@po.cwru.edu>
|
|
|
|
# Joe Hewitt <hewitt@netscape.com>
|
|
|
|
# Alec Flett <alecf@netscape.com>
|
|
|
|
# Asaf Romano <mozilla.mano@sent.com>
|
|
|
|
# Jason Barnabe <jason_barnabe@fastmail.fm>
|
|
|
|
# Peter Parente <parente@cs.unc.edu>
|
|
|
|
# Giorgio Maone <g.maone@informaction.com>
|
|
|
|
# Tom Germeau <tom.germeau@epigoon.com>
|
|
|
|
# Jesse Ruderman <jruderman@gmail.com>
|
|
|
|
# Joe Hughes <joe@retrovirus.com>
|
|
|
|
# Pamela Greene <pamg.bugs@gmail.com>
|
|
|
|
# Michael Ventnor <ventnors_dogs234@yahoo.com.au>
|
|
|
|
# Simon Bünzli <zeniko@gmail.com>
|
2007-07-02 21:15:25 -07:00
|
|
|
# Gijs Kruitbosch <gijskruitbosch@gmail.com>
|
2007-09-02 15:11:38 -07:00
|
|
|
# Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2008-04-02 20:02:08 -07:00
|
|
|
# Dan Mosedale <dmose@mozilla.org>
|
2008-10-22 23:36:52 -07:00
|
|
|
# Justin Dolske <dolske@mozilla.com>
|
2009-06-16 07:30:25 -07:00
|
|
|
# Kathleen Brade <brade@pearlcrescent.com>
|
|
|
|
# Mark Smith <mcs@pearlcrescent.com>
|
2011-07-10 13:53:22 -07:00
|
|
|
# Kailas Patil <patilkr24@gmail.com>
|
2011-09-21 03:16:25 -07:00
|
|
|
# Rob Campbell <rcampbell@mozilla.com>
|
2007-03-22 10:30:00 -07:00
|
|
|
#
|
|
|
|
# Alternatively, the contents of this file may be used under the terms of
|
|
|
|
# either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
# in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
# of those above. If you wish to allow use of your version of this file only
|
|
|
|
# under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
# use your version of this file under the terms of the MPL, indicate your
|
|
|
|
# decision by deleting the provisions above and replace them with the notice
|
|
|
|
# and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
# the provisions above, a recipient may use your version of this file under
|
|
|
|
# the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
#
|
|
|
|
# ***** END LICENSE BLOCK *****
|
|
|
|
|
2011-08-08 10:31:32 -07:00
|
|
|
function nsContextMenu(aXulMenu, aBrowser, aIsShift) {
|
2010-07-29 23:53:13 -07:00
|
|
|
this.shouldDisplay = true;
|
2011-08-08 10:31:32 -07:00
|
|
|
this.initMenu(aBrowser, aXulMenu, aIsShift);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prototype for nsContextMenu "class."
|
|
|
|
nsContextMenu.prototype = {
|
2011-08-08 10:31:32 -07:00
|
|
|
initMenu: function CM_initMenu(aBrowser, aXulMenu, aIsShift) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Get contextual info.
|
|
|
|
this.setTarget(document.popupNode, document.popupRangeParent,
|
|
|
|
document.popupRangeOffset);
|
2010-07-29 23:53:13 -07:00
|
|
|
if (!this.shouldDisplay)
|
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-29 23:53:13 -07:00
|
|
|
this.browser = aBrowser;
|
2011-08-08 10:31:32 -07:00
|
|
|
|
|
|
|
this.hasPageMenu = false;
|
|
|
|
if (!aIsShift) {
|
2011-08-18 09:37:26 -07:00
|
|
|
this.hasPageMenu = PageMenu.maybeBuildAndAttachMenu(this.target,
|
|
|
|
aXulMenu);
|
2011-08-08 10:31:32 -07:00
|
|
|
}
|
|
|
|
|
2010-07-29 23:53:13 -07:00
|
|
|
this.isFrameImage = document.getElementById("isFrameImage");
|
|
|
|
this.ellipsis = "\u2026";
|
|
|
|
try {
|
|
|
|
this.ellipsis = gPrefService.getComplexValue("intl.ellipsis",
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
|
|
|
} catch (e) { }
|
2007-03-22 10:30:00 -07:00
|
|
|
this.isTextSelected = this.isTextSelection();
|
|
|
|
this.isContentSelected = this.isContentSelection();
|
|
|
|
|
|
|
|
// Initialize (disable/remove) menu items.
|
|
|
|
this.initItems();
|
|
|
|
},
|
|
|
|
|
2007-03-27 17:47:29 -07:00
|
|
|
initItems: function CM_initItems() {
|
2011-08-08 10:31:32 -07:00
|
|
|
this.initPageMenuSeparator();
|
2007-03-22 10:30:00 -07:00
|
|
|
this.initOpenItems();
|
|
|
|
this.initNavigationItems();
|
|
|
|
this.initViewItems();
|
|
|
|
this.initMiscItems();
|
|
|
|
this.initSpellingItems();
|
|
|
|
this.initSaveItems();
|
|
|
|
this.initClipboardItems();
|
2008-10-22 23:36:52 -07:00
|
|
|
this.initMediaPlayerItems();
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2011-08-08 10:31:32 -07:00
|
|
|
initPageMenuSeparator: function CM_initPageMenuSeparator() {
|
|
|
|
this.showItem("page-menu-separator", this.hasPageMenu);
|
|
|
|
},
|
|
|
|
|
2007-03-27 17:47:29 -07:00
|
|
|
initOpenItems: function CM_initOpenItems() {
|
2008-08-26 17:20:41 -07:00
|
|
|
var isMailtoInternal = false;
|
|
|
|
if (this.onMailtoLink) {
|
|
|
|
var mailtoHandler = Cc["@mozilla.org/uriloader/external-protocol-service;1"].
|
|
|
|
getService(Ci.nsIExternalProtocolService).
|
|
|
|
getProtocolHandlerInfo("mailto");
|
|
|
|
isMailtoInternal = (!mailtoHandler.alwaysAskBeforeHandling &&
|
|
|
|
mailtoHandler.preferredAction == Ci.nsIHandlerInfo.useHelperApp &&
|
|
|
|
(mailtoHandler.preferredApplicationHandler instanceof Ci.nsIWebHandlerApp));
|
|
|
|
}
|
2009-09-09 02:10:53 -07:00
|
|
|
|
2009-10-31 00:59:23 -07:00
|
|
|
// Time to do some bad things and see if we've highlighted a URL that
|
|
|
|
// isn't actually linked.
|
|
|
|
var onPlainTextLink = false;
|
2009-12-12 18:22:09 -08:00
|
|
|
if (this.isTextSelected && !this.onLink) {
|
2009-10-31 00:59:23 -07:00
|
|
|
// Ok, we have some text, let's figure out if it looks like a URL.
|
|
|
|
let selection = document.commandDispatcher.focusedWindow
|
|
|
|
.getSelection();
|
|
|
|
let linkText = selection.toString().trim();
|
|
|
|
let uri;
|
|
|
|
if (/^(?:https?|ftp):/i.test(linkText)) {
|
|
|
|
try {
|
|
|
|
uri = makeURI(linkText);
|
|
|
|
} catch (ex) {}
|
2009-09-09 02:10:53 -07:00
|
|
|
}
|
2009-10-31 00:59:23 -07:00
|
|
|
// Check if this could be a valid url, just missing the protocol.
|
2011-06-21 02:59:29 -07:00
|
|
|
else if (/^(?:[a-z\d-]+\.)+[a-z]+$/i.test(linkText)) {
|
2009-10-31 00:59:23 -07:00
|
|
|
// Now let's see if this is an intentional link selection. Our guess is
|
|
|
|
// based on whether the selection begins/ends with whitespace or is
|
|
|
|
// preceded/followed by a non-word character.
|
|
|
|
|
|
|
|
// selection.toString() trims trailing whitespace, so we look for
|
|
|
|
// that explicitly in the first and last ranges.
|
|
|
|
let beginRange = selection.getRangeAt(0);
|
|
|
|
let delimitedAtStart = /^\s/.test(beginRange);
|
|
|
|
if (!delimitedAtStart) {
|
|
|
|
let container = beginRange.startContainer;
|
|
|
|
let offset = beginRange.startOffset;
|
|
|
|
if (container.nodeType == Node.TEXT_NODE && offset > 0)
|
|
|
|
delimitedAtStart = /\W/.test(container.textContent[offset - 1]);
|
|
|
|
else
|
|
|
|
delimitedAtStart = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
let delimitedAtEnd = false;
|
|
|
|
if (delimitedAtStart) {
|
|
|
|
let endRange = selection.getRangeAt(selection.rangeCount - 1);
|
|
|
|
delimitedAtEnd = /\s$/.test(endRange);
|
|
|
|
if (!delimitedAtEnd) {
|
|
|
|
let container = endRange.endContainer;
|
|
|
|
let offset = endRange.endOffset;
|
|
|
|
if (container.nodeType == Node.TEXT_NODE &&
|
|
|
|
offset < container.textContent.length)
|
|
|
|
delimitedAtEnd = /\W/.test(container.textContent[offset]);
|
|
|
|
else
|
|
|
|
delimitedAtEnd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delimitedAtStart && delimitedAtEnd) {
|
|
|
|
let uriFixup = Cc["@mozilla.org/docshell/urifixup;1"]
|
|
|
|
.getService(Ci.nsIURIFixup);
|
|
|
|
try {
|
|
|
|
uri = uriFixup.createFixupURI(linkText, uriFixup.FIXUP_FLAG_NONE);
|
|
|
|
} catch (ex) {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uri && uri.host) {
|
2009-09-09 02:10:53 -07:00
|
|
|
this.linkURI = uri;
|
|
|
|
this.linkURL = this.linkURI.spec;
|
|
|
|
onPlainTextLink = true;
|
|
|
|
}
|
|
|
|
}
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2009-09-09 02:10:53 -07:00
|
|
|
var shouldShow = this.onSaveableLink || isMailtoInternal || onPlainTextLink;
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-openlink", shouldShow);
|
|
|
|
this.showItem("context-openlinkintab", shouldShow);
|
2009-09-09 02:10:53 -07:00
|
|
|
this.showItem("context-openlinkincurrent", onPlainTextLink);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-sep-open", shouldShow);
|
|
|
|
},
|
|
|
|
|
2007-03-27 17:47:29 -07:00
|
|
|
initNavigationItems: function CM_initNavigationItems() {
|
2007-03-22 10:30:00 -07:00
|
|
|
var shouldShow = !(this.isContentSelected || this.onLink || this.onImage ||
|
2008-10-22 23:36:52 -07:00
|
|
|
this.onCanvas || this.onVideo || this.onAudio ||
|
|
|
|
this.onTextInput);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-back", shouldShow);
|
|
|
|
this.showItem("context-forward", shouldShow);
|
|
|
|
this.showItem("context-reload", shouldShow);
|
|
|
|
this.showItem("context-stop", shouldShow);
|
|
|
|
this.showItem("context-sep-stop", shouldShow);
|
|
|
|
|
|
|
|
// XXX: Stop is determined in browser.js; the canStop broadcaster is broken
|
|
|
|
//this.setItemAttrFromNode( "context-stop", "disabled", "canStop" );
|
|
|
|
},
|
|
|
|
|
2007-03-27 17:47:29 -07:00
|
|
|
initSaveItems: function CM_initSaveItems() {
|
2008-10-25 15:03:54 -07:00
|
|
|
var shouldShow = !(this.onTextInput || this.onLink ||
|
2008-10-22 23:36:52 -07:00
|
|
|
this.isContentSelected || this.onImage ||
|
|
|
|
this.onCanvas || this.onVideo || this.onAudio);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-savepage", shouldShow);
|
|
|
|
this.showItem("context-sendpage", shouldShow);
|
|
|
|
|
|
|
|
// Save+Send link depends on whether we're in a link.
|
|
|
|
this.showItem("context-savelink", this.onSaveableLink);
|
|
|
|
this.showItem("context-sendlink", this.onSaveableLink);
|
|
|
|
|
2008-10-22 23:36:52 -07:00
|
|
|
// Save image depends on having loaded its content, video and audio don't.
|
2007-07-02 21:15:25 -07:00
|
|
|
this.showItem("context-saveimage", this.onLoadedImage || this.onCanvas);
|
2008-10-22 23:36:52 -07:00
|
|
|
this.showItem("context-savevideo", this.onVideo);
|
|
|
|
this.showItem("context-saveaudio", this.onAudio);
|
2011-10-03 10:42:36 -07:00
|
|
|
this.showItem("context-video-saveimage", this.onVideo);
|
2009-07-09 18:26:35 -07:00
|
|
|
this.setItemAttr("context-savevideo", "disabled", !this.mediaURL);
|
|
|
|
this.setItemAttr("context-saveaudio", "disabled", !this.mediaURL);
|
2008-10-22 23:36:52 -07:00
|
|
|
// Send media URL (but not for canvas, since it's a big data: URL)
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-sendimage", this.onImage);
|
2008-10-22 23:36:52 -07:00
|
|
|
this.showItem("context-sendvideo", this.onVideo);
|
|
|
|
this.showItem("context-sendaudio", this.onAudio);
|
2009-07-09 18:26:35 -07:00
|
|
|
this.setItemAttr("context-sendvideo", "disabled", !this.mediaURL);
|
|
|
|
this.setItemAttr("context-sendaudio", "disabled", !this.mediaURL);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-03-27 17:47:29 -07:00
|
|
|
initViewItems: function CM_initViewItems() {
|
2007-03-22 10:30:00 -07:00
|
|
|
// View source is always OK, unless in directory listing.
|
|
|
|
this.showItem("context-viewpartialsource-selection",
|
|
|
|
this.isContentSelected);
|
|
|
|
this.showItem("context-viewpartialsource-mathml",
|
|
|
|
this.onMathML && !this.isContentSelected);
|
|
|
|
|
2008-10-25 15:03:54 -07:00
|
|
|
var shouldShow = !(this.isContentSelected ||
|
2008-10-22 23:36:52 -07:00
|
|
|
this.onImage || this.onCanvas ||
|
|
|
|
this.onVideo || this.onAudio ||
|
|
|
|
this.onLink || this.onTextInput);
|
2011-09-23 09:43:37 -07:00
|
|
|
var showInspect = gPrefService.getBoolPref("devtools.inspector.enabled");
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-viewsource", shouldShow);
|
|
|
|
this.showItem("context-viewinfo", shouldShow);
|
2011-09-23 09:43:37 -07:00
|
|
|
this.showItem("inspect-separator", showInspect);
|
|
|
|
this.showItem("context-inspect", showInspect);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2009-09-14 08:20:03 -07:00
|
|
|
this.showItem("context-sep-viewsource", shouldShow);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Set as Desktop background depends on whether an image was clicked on,
|
|
|
|
// and only works if we have a shell service.
|
|
|
|
var haveSetDesktopBackground = false;
|
|
|
|
#ifdef HAVE_SHELL_SERVICE
|
|
|
|
// Only enable Set as Desktop Background if we can get the shell service.
|
|
|
|
var shell = getShellService();
|
|
|
|
if (shell)
|
|
|
|
haveSetDesktopBackground = true;
|
|
|
|
#endif
|
|
|
|
this.showItem("context-setDesktopBackground",
|
|
|
|
haveSetDesktopBackground && this.onLoadedImage);
|
|
|
|
|
|
|
|
if (haveSetDesktopBackground && this.onLoadedImage) {
|
|
|
|
document.getElementById("context-setDesktopBackground")
|
|
|
|
.disabled = this.disableSetDesktopBackground();
|
|
|
|
}
|
|
|
|
|
2008-10-27 15:47:01 -07:00
|
|
|
// Reload image depends on an image that's not fully loaded
|
|
|
|
this.showItem("context-reloadimage", (this.onImage && !this.onCompletedImage));
|
2008-02-13 02:38:33 -08:00
|
|
|
|
2007-07-02 21:15:25 -07:00
|
|
|
// View image depends on having an image that's not standalone
|
|
|
|
// (or is in a frame), or a canvas.
|
|
|
|
this.showItem("context-viewimage", (this.onImage &&
|
2011-11-02 13:52:21 -07:00
|
|
|
(!this.inSyntheticDoc || this.inFrame)) || this.onCanvas);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-02 13:52:21 -07:00
|
|
|
// View video depends on not having a standalone video.
|
|
|
|
this.showItem("context-viewvideo", this.onVideo && (!this.inSyntheticDoc || this.inFrame));
|
2009-07-09 18:26:35 -07:00
|
|
|
this.setItemAttr("context-viewvideo", "disabled", !this.mediaURL);
|
2008-10-30 12:29:40 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// View background image depends on whether there is one.
|
2009-09-23 02:07:12 -07:00
|
|
|
this.showItem("context-viewbgimage", shouldShow && !this._hasMultipleBGImages);
|
|
|
|
this.showItem("context-sep-viewbgimage", shouldShow && !this._hasMultipleBGImages);
|
2007-03-22 10:30:00 -07:00
|
|
|
document.getElementById("context-viewbgimage")
|
|
|
|
.disabled = !this.hasBGImage;
|
2009-10-22 17:32:49 -07:00
|
|
|
|
2009-10-29 00:42:45 -07:00
|
|
|
this.showItem("context-viewimageinfo", this.onImage);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2007-03-27 17:47:29 -07:00
|
|
|
initMiscItems: function CM_initMiscItems() {
|
2009-09-14 08:19:58 -07:00
|
|
|
var isTextSelected = this.isTextSelected;
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Use "Bookmark This Link" if on a link.
|
|
|
|
this.showItem("context-bookmarkpage",
|
2008-10-22 23:36:52 -07:00
|
|
|
!(this.isContentSelected || this.onTextInput || this.onLink ||
|
|
|
|
this.onImage || this.onVideo || this.onAudio));
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-bookmarklink", this.onLink && !this.onMailtoLink);
|
2009-09-14 08:19:58 -07:00
|
|
|
this.showItem("context-searchselect", isTextSelected);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-keywordfield",
|
|
|
|
this.onTextInput && this.onKeywordField);
|
|
|
|
this.showItem("frame", this.inFrame);
|
2009-09-14 08:19:58 -07:00
|
|
|
this.showItem("frame-sep", this.inFrame && isTextSelected);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-09-02 15:11:38 -07:00
|
|
|
// Hide menu entries for images, show otherwise
|
|
|
|
if (this.inFrame) {
|
|
|
|
if (mimeTypeIsTextBased(this.target.ownerDocument.contentType))
|
|
|
|
this.isFrameImage.removeAttribute('hidden');
|
|
|
|
else
|
|
|
|
this.isFrameImage.setAttribute('hidden', 'true');
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// BiDi UI
|
2007-03-27 17:47:29 -07:00
|
|
|
this.showItem("context-sep-bidi", top.gBidiUI);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-bidi-text-direction-toggle",
|
2007-03-27 17:47:29 -07:00
|
|
|
this.onTextInput && top.gBidiUI);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-bidi-page-direction-toggle",
|
2007-03-27 17:47:29 -07:00
|
|
|
!this.onTextInput && top.gBidiUI);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
initSpellingItems: function() {
|
|
|
|
var canSpell = InlineSpellCheckerUI.canSpellCheck;
|
|
|
|
var onMisspelling = InlineSpellCheckerUI.overMisspelling;
|
|
|
|
this.showItem("spell-check-enabled", canSpell);
|
2010-06-01 11:08:38 -07:00
|
|
|
this.showItem("spell-separator", canSpell || this.onEditableArea);
|
2011-09-13 11:58:54 -07:00
|
|
|
document.getElementById("spell-check-enabled")
|
|
|
|
.setAttribute("checked", canSpell && InlineSpellCheckerUI.enabled);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
this.showItem("spell-add-to-dictionary", onMisspelling);
|
|
|
|
|
|
|
|
// suggestion list
|
|
|
|
this.showItem("spell-suggestions-separator", onMisspelling);
|
|
|
|
if (onMisspelling) {
|
|
|
|
var suggestionsSeparator =
|
|
|
|
document.getElementById("spell-add-to-dictionary");
|
2010-07-29 23:53:13 -07:00
|
|
|
var numsug =
|
|
|
|
InlineSpellCheckerUI.addSuggestionsToMenu(suggestionsSeparator.parentNode,
|
|
|
|
suggestionsSeparator, 5);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("spell-no-suggestions", numsug == 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.showItem("spell-no-suggestions", false);
|
|
|
|
|
|
|
|
// dictionary list
|
|
|
|
this.showItem("spell-dictionaries", InlineSpellCheckerUI.enabled);
|
|
|
|
if (canSpell) {
|
|
|
|
var dictMenu = document.getElementById("spell-dictionaries-menu");
|
|
|
|
var dictSep = document.getElementById("spell-language-separator");
|
|
|
|
InlineSpellCheckerUI.addDictionaryListToMenu(dictMenu, dictSep);
|
|
|
|
this.showItem("spell-add-dictionaries-main", false);
|
|
|
|
}
|
2010-06-01 11:08:38 -07:00
|
|
|
else if (this.onEditableArea) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// when there is no spellchecker but we might be able to spellcheck
|
|
|
|
// add the add to dictionaries item. This will ensure that people
|
|
|
|
// with no dictionaries will be able to download them
|
|
|
|
this.showItem("spell-add-dictionaries-main", true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
this.showItem("spell-add-dictionaries-main", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
initClipboardItems: function() {
|
|
|
|
// Copy depends on whether there is selected text.
|
|
|
|
// Enabling this context menu item is now done through the global
|
|
|
|
// command updating system
|
|
|
|
// this.setItemAttr( "context-copy", "disabled", !this.isTextSelected() );
|
|
|
|
goUpdateGlobalEditMenuItems();
|
|
|
|
|
|
|
|
this.showItem("context-undo", this.onTextInput);
|
|
|
|
this.showItem("context-sep-undo", this.onTextInput);
|
|
|
|
this.showItem("context-cut", this.onTextInput);
|
|
|
|
this.showItem("context-copy",
|
|
|
|
this.isContentSelected || this.onTextInput);
|
|
|
|
this.showItem("context-paste", this.onTextInput);
|
|
|
|
this.showItem("context-delete", this.onTextInput);
|
|
|
|
this.showItem("context-sep-paste", this.onTextInput);
|
2008-10-22 23:36:52 -07:00
|
|
|
this.showItem("context-selectall", !(this.onLink || this.onImage ||
|
|
|
|
this.onVideo || this.onAudio) || this.isDesignMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
this.showItem("context-sep-selectall", this.isContentSelected );
|
|
|
|
|
|
|
|
// XXX dr
|
|
|
|
// ------
|
|
|
|
// nsDocumentViewer.cpp has code to determine whether we're
|
|
|
|
// on a link or an image. we really ought to be using that...
|
|
|
|
|
|
|
|
// Copy email link depends on whether we're on an email link.
|
|
|
|
this.showItem("context-copyemail", this.onMailtoLink);
|
|
|
|
|
2008-02-22 03:23:56 -08:00
|
|
|
// Copy link location depends on whether we're on a non-mailto link.
|
|
|
|
this.showItem("context-copylink", this.onLink && !this.onMailtoLink);
|
2008-10-22 23:36:52 -07:00
|
|
|
this.showItem("context-sep-copylink", this.onLink &&
|
|
|
|
(this.onImage || this.onVideo || this.onAudio));
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef CONTEXT_COPY_IMAGE_CONTENTS
|
|
|
|
// Copy image contents depends on whether we're on an image.
|
|
|
|
this.showItem("context-copyimage-contents", this.onImage);
|
|
|
|
#endif
|
|
|
|
// Copy image location depends on whether we're on an image.
|
|
|
|
this.showItem("context-copyimage", this.onImage);
|
2008-10-22 23:36:52 -07:00
|
|
|
this.showItem("context-copyvideourl", this.onVideo);
|
|
|
|
this.showItem("context-copyaudiourl", this.onAudio);
|
2009-07-09 18:26:35 -07:00
|
|
|
this.setItemAttr("context-copyvideourl", "disabled", !this.mediaURL);
|
|
|
|
this.setItemAttr("context-copyaudiourl", "disabled", !this.mediaURL);
|
2008-10-22 23:36:52 -07:00
|
|
|
this.showItem("context-sep-copyimage", this.onImage ||
|
|
|
|
this.onVideo || this.onAudio);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2008-10-22 23:36:52 -07:00
|
|
|
initMediaPlayerItems: function() {
|
|
|
|
var onMedia = (this.onVideo || this.onAudio);
|
|
|
|
// Several mutually exclusive items... play/pause, mute/unmute, show/hide
|
2009-07-14 13:26:33 -07:00
|
|
|
this.showItem("context-media-play", onMedia && (this.target.paused || this.target.ended));
|
|
|
|
this.showItem("context-media-pause", onMedia && !this.target.paused && !this.target.ended);
|
2008-10-22 23:36:52 -07:00
|
|
|
this.showItem("context-media-mute", onMedia && !this.target.muted);
|
|
|
|
this.showItem("context-media-unmute", onMedia && this.target.muted);
|
2009-10-01 01:49:00 -07:00
|
|
|
this.showItem("context-media-showcontrols", onMedia && !this.target.controls);
|
|
|
|
this.showItem("context-media-hidecontrols", onMedia && this.target.controls);
|
|
|
|
this.showItem("context-video-fullscreen", this.onVideo);
|
2011-10-03 20:47:41 -07:00
|
|
|
var statsShowing = this.onVideo && this.target.wrappedJSObject.mozMediaStatisticsShowing;
|
|
|
|
this.showItem("context-video-showstats", this.onVideo && this.target.controls && !statsShowing);
|
|
|
|
this.showItem("context-video-hidestats", this.onVideo && this.target.controls && statsShowing);
|
|
|
|
|
2009-07-09 18:26:35 -07:00
|
|
|
// Disable them when there isn't a valid media source loaded.
|
|
|
|
if (onMedia) {
|
2010-09-02 17:03:03 -07:00
|
|
|
var hasError = this.target.error != null ||
|
|
|
|
this.target.networkState == this.target.NETWORK_NO_SOURCE;
|
2009-07-09 18:26:35 -07:00
|
|
|
this.setItemAttr("context-media-play", "disabled", hasError);
|
|
|
|
this.setItemAttr("context-media-pause", "disabled", hasError);
|
|
|
|
this.setItemAttr("context-media-mute", "disabled", hasError);
|
|
|
|
this.setItemAttr("context-media-unmute", "disabled", hasError);
|
|
|
|
this.setItemAttr("context-media-showcontrols", "disabled", hasError);
|
|
|
|
this.setItemAttr("context-media-hidecontrols", "disabled", hasError);
|
2011-10-03 10:42:36 -07:00
|
|
|
if (this.onVideo) {
|
|
|
|
let canSaveSnapshot = this.target.readyState >= this.target.HAVE_CURRENT_DATA;
|
|
|
|
this.setItemAttr("context-video-saveimage", "disabled", !canSaveSnapshot);
|
|
|
|
this.setItemAttr("context-video-fullscreen", "disabled", hasError);
|
2011-10-03 20:47:41 -07:00
|
|
|
this.setItemAttr("context-video-showstats", "disabled", hasError);
|
|
|
|
this.setItemAttr("context-video-hidestats", "disabled", hasError);
|
2011-10-03 10:42:36 -07:00
|
|
|
}
|
2009-07-09 18:26:35 -07:00
|
|
|
}
|
2008-10-22 23:36:52 -07:00
|
|
|
this.showItem("context-media-sep-commands", onMedia);
|
|
|
|
},
|
|
|
|
|
2011-09-21 03:16:25 -07:00
|
|
|
inspectNode: function CM_inspectNode() {
|
|
|
|
if (InspectorUI.isTreePanelOpen) {
|
|
|
|
InspectorUI.inspectNode(this.target);
|
|
|
|
InspectorUI.stopInspecting();
|
|
|
|
} else {
|
|
|
|
InspectorUI.openInspectorUI(this.target);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Set various context menu attributes based on the state of the world.
|
|
|
|
setTarget: function (aNode, aRangeParent, aRangeOffset) {
|
|
|
|
const xulNS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
|
2008-02-23 23:42:40 -08:00
|
|
|
if (aNode.namespaceURI == xulNS ||
|
2010-08-05 23:55:42 -07:00
|
|
|
aNode.nodeType == Node.DOCUMENT_NODE ||
|
2008-02-23 23:42:40 -08:00
|
|
|
this.isTargetAFormControl(aNode)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
this.shouldDisplay = false;
|
2010-07-29 23:53:13 -07:00
|
|
|
return;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Initialize contextual info.
|
|
|
|
this.onImage = false;
|
|
|
|
this.onLoadedImage = false;
|
2008-02-13 02:38:33 -08:00
|
|
|
this.onCompletedImage = false;
|
2007-07-02 21:15:25 -07:00
|
|
|
this.onCanvas = false;
|
2008-10-22 23:36:52 -07:00
|
|
|
this.onVideo = false;
|
|
|
|
this.onAudio = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
this.onTextInput = false;
|
|
|
|
this.onKeywordField = false;
|
2008-10-22 23:36:52 -07:00
|
|
|
this.mediaURL = "";
|
2007-03-22 10:30:00 -07:00
|
|
|
this.onLink = false;
|
2010-07-29 23:53:13 -07:00
|
|
|
this.onMailtoLink = false;
|
|
|
|
this.onSaveableLink = false;
|
|
|
|
this.link = null;
|
2007-03-22 10:30:00 -07:00
|
|
|
this.linkURL = "";
|
|
|
|
this.linkURI = null;
|
|
|
|
this.linkProtocol = "";
|
|
|
|
this.onMathML = false;
|
|
|
|
this.inFrame = false;
|
2011-11-02 13:52:21 -07:00
|
|
|
this.inSyntheticDoc = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
this.hasBGImage = false;
|
|
|
|
this.bgImageURL = "";
|
2010-07-29 23:53:13 -07:00
|
|
|
this.onEditableArea = false;
|
|
|
|
this.isDesignMode = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Clear any old spellchecking items from the menu, this used to
|
|
|
|
// be in the menu hiding code but wasn't getting called in all
|
|
|
|
// situations. Here, we can ensure it gets cleaned up any time the
|
|
|
|
// menu is shown. Note: must be before uninit because that clears the
|
|
|
|
// internal vars
|
|
|
|
InlineSpellCheckerUI.clearSuggestionsFromMenu();
|
|
|
|
InlineSpellCheckerUI.clearDictionaryListFromMenu();
|
|
|
|
|
|
|
|
InlineSpellCheckerUI.uninit();
|
|
|
|
|
|
|
|
// Remember the node that was clicked.
|
|
|
|
this.target = aNode;
|
|
|
|
|
2011-11-02 13:52:21 -07:00
|
|
|
// Check if we are in a synthetic document (stand alone image, video, etc.).
|
|
|
|
this.inSyntheticDoc = this.target.ownerDocument.mozSyntheticDocument;
|
2007-03-22 10:30:00 -07:00
|
|
|
// First, do checks for nodes that never have children.
|
|
|
|
if (this.target.nodeType == Node.ELEMENT_NODE) {
|
|
|
|
// See if the user clicked on an image.
|
|
|
|
if (this.target instanceof Ci.nsIImageLoadingContent &&
|
|
|
|
this.target.currentURI) {
|
|
|
|
this.onImage = true;
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var request =
|
|
|
|
this.target.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
|
|
|
if (request && (request.imageStatus & request.STATUS_SIZE_AVAILABLE))
|
|
|
|
this.onLoadedImage = true;
|
2008-02-13 02:38:33 -08:00
|
|
|
if (request && (request.imageStatus & request.STATUS_LOAD_COMPLETE))
|
|
|
|
this.onCompletedImage = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-10-22 23:36:52 -07:00
|
|
|
this.mediaURL = this.target.currentURI.spec;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-07-02 21:15:25 -07:00
|
|
|
else if (this.target instanceof HTMLCanvasElement) {
|
|
|
|
this.onCanvas = true;
|
|
|
|
}
|
2008-10-22 23:36:52 -07:00
|
|
|
else if (this.target instanceof HTMLVideoElement) {
|
|
|
|
this.onVideo = true;
|
2009-07-09 18:26:35 -07:00
|
|
|
this.mediaURL = this.target.currentSrc || this.target.src;
|
2008-10-22 23:36:52 -07:00
|
|
|
}
|
|
|
|
else if (this.target instanceof HTMLAudioElement) {
|
|
|
|
this.onAudio = true;
|
2009-07-09 18:26:35 -07:00
|
|
|
this.mediaURL = this.target.currentSrc || this.target.src;
|
2008-10-22 23:36:52 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
else if (this.target instanceof HTMLInputElement ) {
|
|
|
|
this.onTextInput = this.isTargetATextBox(this.target);
|
2011-05-02 15:13:22 -07:00
|
|
|
// Allow spellchecking UI on all text and search inputs.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (this.onTextInput && ! this.target.readOnly &&
|
2011-05-02 15:13:22 -07:00
|
|
|
(this.target.type == "text" || this.target.type == "search")) {
|
2010-06-01 11:08:38 -07:00
|
|
|
this.onEditableArea = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
InlineSpellCheckerUI.init(this.target.QueryInterface(Ci.nsIDOMNSEditableElement).editor);
|
|
|
|
InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
|
|
|
|
}
|
|
|
|
this.onKeywordField = this.isTargetAKeywordField(this.target);
|
|
|
|
}
|
|
|
|
else if (this.target instanceof HTMLTextAreaElement) {
|
|
|
|
this.onTextInput = true;
|
|
|
|
if (!this.target.readOnly) {
|
2010-06-01 11:08:38 -07:00
|
|
|
this.onEditableArea = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
InlineSpellCheckerUI.init(this.target.QueryInterface(Ci.nsIDOMNSEditableElement).editor);
|
|
|
|
InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (this.target instanceof HTMLHtmlElement) {
|
|
|
|
var bodyElt = this.target.ownerDocument.body;
|
|
|
|
if (bodyElt) {
|
2009-09-23 02:07:12 -07:00
|
|
|
let computedURL;
|
|
|
|
try {
|
|
|
|
computedURL = this.getComputedURL(bodyElt, "background-image");
|
|
|
|
this._hasMultipleBGImages = false;
|
|
|
|
} catch (e) {
|
|
|
|
this._hasMultipleBGImages = true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (computedURL) {
|
|
|
|
this.hasBGImage = true;
|
|
|
|
this.bgImageURL = makeURLAbsolute(bodyElt.baseURI,
|
|
|
|
computedURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Second, bubble out, looking for items of interest that can have childen.
|
|
|
|
// Always pick the innermost link, background image, etc.
|
|
|
|
const XMLNS = "http://www.w3.org/XML/1998/namespace";
|
|
|
|
var elem = this.target;
|
|
|
|
while (elem) {
|
|
|
|
if (elem.nodeType == Node.ELEMENT_NODE) {
|
|
|
|
// Link?
|
|
|
|
if (!this.onLink &&
|
2010-12-27 12:42:10 -08:00
|
|
|
// Be consistent with what hrefAndLinkNodeForClickEvent
|
|
|
|
// does in browser.js
|
2007-03-22 10:30:00 -07:00
|
|
|
((elem instanceof HTMLAnchorElement && elem.href) ||
|
2007-07-12 17:32:37 -07:00
|
|
|
(elem instanceof HTMLAreaElement && elem.href) ||
|
2007-03-22 10:30:00 -07:00
|
|
|
elem instanceof HTMLLinkElement ||
|
|
|
|
elem.getAttributeNS("http://www.w3.org/1999/xlink", "type") == "simple")) {
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Target is a link or a descendant of a link.
|
|
|
|
this.onLink = true;
|
|
|
|
|
|
|
|
// Remember corresponding element.
|
2010-12-27 12:42:10 -08:00
|
|
|
this.link = elem;
|
2007-03-22 10:30:00 -07:00
|
|
|
this.linkURL = this.getLinkURL();
|
|
|
|
this.linkURI = this.getLinkURI();
|
|
|
|
this.linkProtocol = this.getLinkProtocol();
|
|
|
|
this.onMailtoLink = (this.linkProtocol == "mailto");
|
|
|
|
this.onSaveableLink = this.isLinkSaveable( this.link );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Background image? Don't bother if we've already found a
|
|
|
|
// background image further down the hierarchy. Otherwise,
|
|
|
|
// we look for the computed background-image style.
|
2009-09-23 02:07:12 -07:00
|
|
|
if (!this.hasBGImage &&
|
|
|
|
!this._hasMultipleBGImages) {
|
|
|
|
let bgImgUrl;
|
|
|
|
try {
|
|
|
|
bgImgUrl = this.getComputedURL(elem, "background-image");
|
|
|
|
this._hasMultipleBGImages = false;
|
|
|
|
} catch (e) {
|
|
|
|
this._hasMultipleBGImages = true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
if (bgImgUrl) {
|
|
|
|
this.hasBGImage = true;
|
|
|
|
this.bgImageURL = makeURLAbsolute(elem.baseURI,
|
|
|
|
bgImgUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
elem = elem.parentNode;
|
|
|
|
}
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// See if the user clicked on MathML
|
|
|
|
const NS_MathML = "http://www.w3.org/1998/Math/MathML";
|
|
|
|
if ((this.target.nodeType == Node.TEXT_NODE &&
|
|
|
|
this.target.parentNode.namespaceURI == NS_MathML)
|
|
|
|
|| (this.target.namespaceURI == NS_MathML))
|
|
|
|
this.onMathML = true;
|
|
|
|
|
|
|
|
// See if the user clicked in a frame.
|
|
|
|
var docDefaultView = this.target.ownerDocument.defaultView;
|
|
|
|
if (docDefaultView != docDefaultView.top)
|
|
|
|
this.inFrame = true;
|
|
|
|
|
|
|
|
// if the document is editable, show context menu like in text inputs
|
2010-06-01 11:08:38 -07:00
|
|
|
if (!this.onEditableArea) {
|
|
|
|
var win = this.target.ownerDocument.defaultView;
|
|
|
|
if (win) {
|
|
|
|
var isEditable = false;
|
|
|
|
try {
|
|
|
|
var editingSession = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIEditingSession);
|
|
|
|
if (editingSession.windowIsEditable(win) &&
|
|
|
|
this.getComputedStyle(this.target, "-moz-user-modify") == "read-write") {
|
|
|
|
isEditable = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
// If someone built with composer disabled, we can't get an editing session.
|
2007-07-23 15:16:30 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-01 11:08:38 -07:00
|
|
|
if (isEditable) {
|
|
|
|
this.onTextInput = true;
|
|
|
|
this.onKeywordField = false;
|
|
|
|
this.onImage = false;
|
|
|
|
this.onLoadedImage = false;
|
|
|
|
this.onCompletedImage = false;
|
|
|
|
this.onMathML = false;
|
|
|
|
this.inFrame = false;
|
|
|
|
this.hasBGImage = false;
|
|
|
|
this.isDesignMode = true;
|
|
|
|
this.onEditableArea = true;
|
|
|
|
InlineSpellCheckerUI.init(editingSession.getEditorForWindow(win));
|
|
|
|
var canSpell = InlineSpellCheckerUI.canSpellCheck;
|
|
|
|
InlineSpellCheckerUI.initFromEvent(aRangeParent, aRangeOffset);
|
|
|
|
this.showItem("spell-check-enabled", canSpell);
|
|
|
|
this.showItem("spell-separator", canSpell);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns the computed style attribute for the given element.
|
|
|
|
getComputedStyle: function(aElem, aProp) {
|
2007-07-23 15:16:30 -07:00
|
|
|
return aElem.ownerDocument
|
|
|
|
.defaultView
|
|
|
|
.getComputedStyle(aElem, "").getPropertyValue(aProp);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Returns a "url"-type computed style attribute value, with the url() stripped.
|
|
|
|
getComputedURL: function(aElem, aProp) {
|
|
|
|
var url = aElem.ownerDocument
|
|
|
|
.defaultView.getComputedStyle(aElem, "")
|
|
|
|
.getPropertyCSSValue(aProp);
|
2009-09-23 02:07:12 -07:00
|
|
|
if (url instanceof CSSValueList) {
|
|
|
|
if (url.length != 1)
|
|
|
|
throw "found multiple URLs";
|
|
|
|
url = url[0];
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
return url.primitiveType == CSSPrimitiveValue.CSS_URI ?
|
|
|
|
url.getStringValue() : null;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns true if clicked-on link targets a resource that can be saved.
|
|
|
|
isLinkSaveable: function(aLink) {
|
|
|
|
// We don't do the Right Thing for news/snews yet, so turn them off
|
|
|
|
// until we do.
|
|
|
|
return this.linkProtocol && !(
|
|
|
|
this.linkProtocol == "mailto" ||
|
|
|
|
this.linkProtocol == "javascript" ||
|
|
|
|
this.linkProtocol == "news" ||
|
|
|
|
this.linkProtocol == "snews" );
|
|
|
|
},
|
|
|
|
|
|
|
|
// Open linked-to URL in a new window.
|
|
|
|
openLink : function () {
|
2010-12-24 15:11:45 -08:00
|
|
|
var doc = this.target.ownerDocument;
|
|
|
|
urlSecurityCheck(this.linkURL, doc.nodePrincipal);
|
|
|
|
openLinkIn(this.linkURL, "window",
|
|
|
|
{ charset: doc.characterSet,
|
|
|
|
referrerURI: doc.documentURIObject });
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Open linked-to URL in a new tab.
|
|
|
|
openLinkInTab: function() {
|
2010-12-24 15:11:45 -08:00
|
|
|
var doc = this.target.ownerDocument;
|
|
|
|
urlSecurityCheck(this.linkURL, doc.nodePrincipal);
|
|
|
|
openLinkIn(this.linkURL, "tab",
|
|
|
|
{ charset: doc.characterSet,
|
|
|
|
referrerURI: doc.documentURIObject });
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2009-09-09 02:10:53 -07:00
|
|
|
// open URL in current tab
|
|
|
|
openLinkInCurrent: function() {
|
2010-12-24 15:11:45 -08:00
|
|
|
var doc = this.target.ownerDocument;
|
|
|
|
urlSecurityCheck(this.linkURL, doc.nodePrincipal);
|
|
|
|
openLinkIn(this.linkURL, "current",
|
|
|
|
{ charset: doc.characterSet,
|
|
|
|
referrerURI: doc.documentURIObject });
|
2009-09-09 02:10:53 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Open frame in a new tab.
|
|
|
|
openFrameInTab: function() {
|
2007-08-25 22:18:47 -07:00
|
|
|
var doc = this.target.ownerDocument;
|
2008-04-08 11:45:08 -07:00
|
|
|
var frameURL = doc.location.href;
|
2007-09-17 13:57:48 -07:00
|
|
|
var referrer = doc.referrer;
|
2010-12-24 15:11:45 -08:00
|
|
|
openLinkIn(frameURL, "tab",
|
|
|
|
{ charset: doc.characterSet,
|
|
|
|
referrerURI: referrer ? makeURI(referrer) : null });
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Reload clicked-in frame.
|
|
|
|
reloadFrame: function() {
|
|
|
|
this.target.ownerDocument.location.reload();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Open clicked-in frame in its own window.
|
|
|
|
openFrame: function() {
|
2007-08-25 22:18:47 -07:00
|
|
|
var doc = this.target.ownerDocument;
|
2008-04-08 11:45:08 -07:00
|
|
|
var frameURL = doc.location.href;
|
2007-09-17 13:57:48 -07:00
|
|
|
var referrer = doc.referrer;
|
2010-12-24 15:11:45 -08:00
|
|
|
openLinkIn(frameURL, "window",
|
|
|
|
{ charset: doc.characterSet,
|
|
|
|
referrerURI: referrer ? makeURI(referrer) : null });
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Open clicked-in frame in the same window.
|
|
|
|
showOnlyThisFrame: function() {
|
2007-08-25 22:18:47 -07:00
|
|
|
var doc = this.target.ownerDocument;
|
2008-04-08 11:45:08 -07:00
|
|
|
var frameURL = doc.location.href;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-08-25 22:18:47 -07:00
|
|
|
urlSecurityCheck(frameURL, this.browser.contentPrincipal,
|
|
|
|
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
|
2007-09-17 13:57:48 -07:00
|
|
|
var referrer = doc.referrer;
|
|
|
|
this.browser.loadURI(frameURL, referrer ? makeURI(referrer) : null);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// View Partial Source
|
|
|
|
viewPartialSource: function(aContext) {
|
|
|
|
var focusedWindow = document.commandDispatcher.focusedWindow;
|
|
|
|
if (focusedWindow == window)
|
|
|
|
focusedWindow = content;
|
|
|
|
|
|
|
|
var docCharset = null;
|
|
|
|
if (focusedWindow)
|
|
|
|
docCharset = "charset=" + focusedWindow.document.characterSet;
|
|
|
|
|
|
|
|
// "View Selection Source" and others such as "View MathML Source"
|
|
|
|
// are mutually exclusive, with the precedence given to the selection
|
|
|
|
// when there is one
|
|
|
|
var reference = null;
|
|
|
|
if (aContext == "selection")
|
|
|
|
reference = focusedWindow.getSelection();
|
|
|
|
else if (aContext == "mathml")
|
|
|
|
reference = this.target;
|
|
|
|
else
|
|
|
|
throw "not reached";
|
|
|
|
|
|
|
|
// unused (and play nice for fragments generated via XSLT too)
|
|
|
|
var docUrl = null;
|
|
|
|
window.openDialog("chrome://global/content/viewPartialSource.xul",
|
|
|
|
"_blank", "scrollbars,resizable,chrome,dialog=no",
|
|
|
|
docUrl, docCharset, reference, aContext);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Open new "view source" window with the frame's URL.
|
|
|
|
viewFrameSource: function() {
|
|
|
|
BrowserViewSourceOfDocument(this.target.ownerDocument);
|
|
|
|
},
|
|
|
|
|
|
|
|
viewInfo: function() {
|
|
|
|
BrowserPageInfo(this.target.ownerDocument.defaultView.top.document);
|
|
|
|
},
|
|
|
|
|
2009-10-22 17:32:49 -07:00
|
|
|
viewImageInfo: function() {
|
2009-10-29 00:42:45 -07:00
|
|
|
BrowserPageInfo(this.target.ownerDocument.defaultView.top.document,
|
|
|
|
"mediaTab", this.target);
|
2009-10-22 17:32:49 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
viewFrameInfo: function() {
|
|
|
|
BrowserPageInfo(this.target.ownerDocument);
|
|
|
|
},
|
|
|
|
|
2008-10-27 15:47:01 -07:00
|
|
|
reloadImage: function(e) {
|
2008-10-22 23:36:52 -07:00
|
|
|
urlSecurityCheck(this.mediaURL,
|
2008-02-13 02:38:33 -08:00
|
|
|
this.browser.contentPrincipal,
|
|
|
|
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
|
|
|
|
|
|
|
|
if (this.target instanceof Ci.nsIImageLoadingContent)
|
|
|
|
this.target.forceReload();
|
|
|
|
},
|
|
|
|
|
2008-10-22 23:36:52 -07:00
|
|
|
// Change current window to the URL of the image, video, or audio.
|
|
|
|
viewMedia: function(e) {
|
2007-07-03 14:11:15 -07:00
|
|
|
var viewURL;
|
|
|
|
|
|
|
|
if (this.onCanvas)
|
|
|
|
viewURL = this.target.toDataURL();
|
|
|
|
else {
|
2008-10-22 23:36:52 -07:00
|
|
|
viewURL = this.mediaURL;
|
2007-07-03 14:11:15 -07:00
|
|
|
urlSecurityCheck(viewURL,
|
|
|
|
this.browser.contentPrincipal,
|
|
|
|
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var doc = this.target.ownerDocument;
|
2007-07-03 14:11:15 -07:00
|
|
|
openUILink(viewURL, e, null, null, null, null, doc.documentURIObject );
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2011-10-03 10:42:36 -07:00
|
|
|
saveVideoFrameAsImage: function () {
|
|
|
|
urlSecurityCheck(this.mediaURL, this.browser.contentPrincipal,
|
|
|
|
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
|
|
|
|
let name = "";
|
|
|
|
try {
|
|
|
|
let uri = makeURI(this.mediaURL);
|
|
|
|
let url = uri.QueryInterface(Ci.nsIURL);
|
|
|
|
if (url.fileBaseName)
|
|
|
|
name = url.fileBaseName + ".jpg";
|
|
|
|
} catch (e) { }
|
|
|
|
if (!name)
|
|
|
|
name = "snapshot.jpg";
|
|
|
|
var video = this.target;
|
|
|
|
var canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
|
|
|
canvas.width = video.videoWidth;
|
|
|
|
canvas.height = video.videoHeight;
|
|
|
|
var ctxDraw = canvas.getContext("2d");
|
|
|
|
ctxDraw.drawImage(video, 0, 0);
|
2011-10-11 00:14:27 -07:00
|
|
|
saveImageURL(canvas.toDataURL("image/jpeg", ""), name, "SaveImageTitle", true, false, document.documentURIObject);
|
2011-10-03 10:42:36 -07:00
|
|
|
},
|
|
|
|
|
2009-10-01 01:49:00 -07:00
|
|
|
fullScreenVideo: function () {
|
|
|
|
this.target.pause();
|
|
|
|
|
|
|
|
openDialog("chrome://browser/content/fullscreen-video.xhtml",
|
2010-08-02 19:55:25 -07:00
|
|
|
"", "chrome,centerscreen,dialog=no", this.target);
|
2009-10-01 01:49:00 -07:00
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Change current window to the URL of the background image.
|
|
|
|
viewBGImage: function(e) {
|
|
|
|
urlSecurityCheck(this.bgImageURL,
|
|
|
|
this.browser.contentPrincipal,
|
|
|
|
Ci.nsIScriptSecurityManager.DISALLOW_SCRIPT);
|
|
|
|
var doc = this.target.ownerDocument;
|
|
|
|
openUILink(this.bgImageURL, e, null, null, null, null, doc.documentURIObject );
|
|
|
|
},
|
|
|
|
|
|
|
|
disableSetDesktopBackground: function() {
|
|
|
|
// Disable the Set as Desktop Background menu item if we're still trying
|
|
|
|
// to load the image or the load failed.
|
|
|
|
if (!(this.target instanceof Ci.nsIImageLoadingContent))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (("complete" in this.target) && !this.target.complete)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (this.target.currentURI.schemeIs("javascript"))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
var request = this.target
|
|
|
|
.QueryInterface(Ci.nsIImageLoadingContent)
|
|
|
|
.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
|
|
|
if (!request)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
setDesktopBackground: function() {
|
|
|
|
// Paranoia: check disableSetDesktopBackground again, in case the
|
|
|
|
// image changed since the context menu was initiated.
|
|
|
|
if (this.disableSetDesktopBackground())
|
|
|
|
return;
|
|
|
|
|
|
|
|
urlSecurityCheck(this.target.currentURI.spec,
|
|
|
|
this.target.ownerDocument.nodePrincipal);
|
|
|
|
|
|
|
|
// Confirm since it's annoying if you hit this accidentally.
|
|
|
|
const kDesktopBackgroundURL =
|
|
|
|
"chrome://browser/content/setDesktopBackground.xul";
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
// On Mac, the Set Desktop Background window is not modal.
|
|
|
|
// Don't open more than one Set Desktop Background window.
|
|
|
|
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
|
|
|
|
.getService(Components.interfaces.nsIWindowMediator);
|
|
|
|
var dbWin = wm.getMostRecentWindow("Shell:SetDesktopBackground");
|
|
|
|
if (dbWin) {
|
|
|
|
dbWin.gSetBackground.init(this.target);
|
|
|
|
dbWin.focus();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
openDialog(kDesktopBackgroundURL, "",
|
|
|
|
"centerscreen,chrome,dialog=no,dependent,resizable=no",
|
|
|
|
this.target);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
// On non-Mac platforms, the Set Wallpaper dialog is modal.
|
|
|
|
openDialog(kDesktopBackgroundURL, "",
|
|
|
|
"centerscreen,chrome,dialog,modal,dependent",
|
|
|
|
this.target);
|
|
|
|
#endif
|
|
|
|
},
|
|
|
|
|
|
|
|
// Save URL of clicked-on frame.
|
|
|
|
saveFrame: function () {
|
|
|
|
saveDocument(this.target.ownerDocument);
|
|
|
|
},
|
|
|
|
|
2011-07-10 13:53:22 -07:00
|
|
|
// Helper function to wait for appropriate MIME-type headers and
|
|
|
|
// then prompt the user with a file picker
|
|
|
|
saveHelper: function(linkURL, linkText, dialogTitle, bypassCache, doc) {
|
2008-04-02 20:02:08 -07:00
|
|
|
// canonical def in nsURILoader.h
|
|
|
|
const NS_ERROR_SAVE_LINK_AS_TIMEOUT = 0x805d0020;
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2008-04-02 20:02:08 -07:00
|
|
|
// an object to proxy the data through to
|
|
|
|
// nsIExternalHelperAppService.doContent, which will wait for the
|
|
|
|
// appropriate MIME-type headers and then prompt the user with a
|
|
|
|
// file picker
|
|
|
|
function saveAsListener() {}
|
|
|
|
saveAsListener.prototype = {
|
|
|
|
extListener: null,
|
|
|
|
|
|
|
|
onStartRequest: function saveLinkAs_onStartRequest(aRequest, aContext) {
|
|
|
|
|
|
|
|
// if the timer fired, the error status will have been caused by that,
|
|
|
|
// and we'll be restarting in onStopRequest, so no reason to notify
|
|
|
|
// the user
|
|
|
|
if (aRequest.status == NS_ERROR_SAVE_LINK_AS_TIMEOUT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
timer.cancel();
|
|
|
|
|
|
|
|
// some other error occured; notify the user...
|
|
|
|
if (!Components.isSuccessCode(aRequest.status)) {
|
|
|
|
try {
|
|
|
|
const sbs = Cc["@mozilla.org/intl/stringbundle;1"].
|
|
|
|
getService(Ci.nsIStringBundleService);
|
|
|
|
const bundle = sbs.createBundle(
|
|
|
|
"chrome://mozapps/locale/downloads/downloads.properties");
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2008-04-02 20:02:08 -07:00
|
|
|
const title = bundle.GetStringFromName("downloadErrorAlertTitle");
|
|
|
|
const msg = bundle.GetStringFromName("downloadErrorGeneric");
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2008-04-02 20:02:08 -07:00
|
|
|
const promptSvc = Cc["@mozilla.org/embedcomp/prompt-service;1"].
|
|
|
|
getService(Ci.nsIPromptService);
|
|
|
|
promptSvc.alert(doc.defaultView, title, msg);
|
|
|
|
} catch (ex) {}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var extHelperAppSvc =
|
|
|
|
Cc["@mozilla.org/uriloader/external-helper-app-service;1"].
|
|
|
|
getService(Ci.nsIExternalHelperAppService);
|
|
|
|
var channel = aRequest.QueryInterface(Ci.nsIChannel);
|
|
|
|
this.extListener =
|
|
|
|
extHelperAppSvc.doContent(channel.contentType, aRequest,
|
|
|
|
doc.defaultView, true);
|
|
|
|
this.extListener.onStartRequest(aRequest, aContext);
|
|
|
|
},
|
|
|
|
|
|
|
|
onStopRequest: function saveLinkAs_onStopRequest(aRequest, aContext,
|
|
|
|
aStatusCode) {
|
|
|
|
if (aStatusCode == NS_ERROR_SAVE_LINK_AS_TIMEOUT) {
|
|
|
|
// do it the old fashioned way, which will pick the best filename
|
|
|
|
// it can without waiting.
|
2011-07-10 13:53:22 -07:00
|
|
|
saveURL(linkURL, linkText, dialogTitle, bypassCache, false, doc.documentURIObject);
|
2008-04-02 20:02:08 -07:00
|
|
|
}
|
|
|
|
if (this.extListener)
|
|
|
|
this.extListener.onStopRequest(aRequest, aContext, aStatusCode);
|
|
|
|
},
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2008-04-02 20:02:08 -07:00
|
|
|
onDataAvailable: function saveLinkAs_onDataAvailable(aRequest, aContext,
|
|
|
|
aInputStream,
|
|
|
|
aOffset, aCount) {
|
|
|
|
this.extListener.onDataAvailable(aRequest, aContext, aInputStream,
|
|
|
|
aOffset, aCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function callbacks() {}
|
|
|
|
callbacks.prototype = {
|
|
|
|
getInterface: function sLA_callbacks_getInterface(aIID) {
|
|
|
|
if (aIID.equals(Ci.nsIAuthPrompt) || aIID.equals(Ci.nsIAuthPrompt2)) {
|
2010-10-25 09:47:23 -07:00
|
|
|
// If the channel demands authentication prompt, we must cancel it
|
|
|
|
// because the save-as-timer would expire and cancel the channel
|
|
|
|
// before we get credentials from user. Both authentication dialog
|
|
|
|
// and save as dialog would appear on the screen as we fall back to
|
|
|
|
// the old fashioned way after the timeout.
|
|
|
|
timer.cancel();
|
|
|
|
channel.cancel(NS_ERROR_SAVE_LINK_AS_TIMEOUT);
|
2008-04-02 20:02:08 -07:00
|
|
|
}
|
|
|
|
throw Cr.NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it we don't have the headers after a short time, the user
|
|
|
|
// won't have received any feedback from their click. that's bad. so
|
|
|
|
// we give up waiting for the filename.
|
|
|
|
function timerCallback() {}
|
|
|
|
timerCallback.prototype = {
|
|
|
|
notify: function sLA_timer_notify(aTimer) {
|
|
|
|
channel.cancel(NS_ERROR_SAVE_LINK_AS_TIMEOUT);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set up a channel to do the saving
|
|
|
|
var ioService = Cc["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Ci.nsIIOService);
|
2011-07-10 13:53:22 -07:00
|
|
|
var channel = ioService.newChannelFromURI(makeURI(linkURL));
|
2008-04-02 20:02:08 -07:00
|
|
|
channel.notificationCallbacks = new callbacks();
|
2011-07-10 13:53:22 -07:00
|
|
|
|
|
|
|
let flags = Ci.nsIChannel.LOAD_CALL_CONTENT_SNIFFERS;
|
|
|
|
|
|
|
|
if (bypassCache)
|
|
|
|
flags |= Ci.nsIRequest.LOAD_BYPASS_CACHE;
|
|
|
|
|
|
|
|
if (channel instanceof Ci.nsICachingChannel)
|
|
|
|
flags |= Ci.nsICachingChannel.LOAD_BYPASS_LOCAL_CACHE_IF_BUSY;
|
|
|
|
|
|
|
|
channel.loadFlags |= flags;
|
|
|
|
|
2009-06-16 07:30:25 -07:00
|
|
|
if (channel instanceof Ci.nsIHttpChannel) {
|
2008-04-02 20:02:08 -07:00
|
|
|
channel.referrer = doc.documentURIObject;
|
2009-06-16 07:30:25 -07:00
|
|
|
if (channel instanceof Ci.nsIHttpChannelInternal)
|
|
|
|
channel.forceAllowThirdPartyCookie = true;
|
|
|
|
}
|
2008-04-02 20:02:08 -07:00
|
|
|
|
|
|
|
// fallback to the old way if we don't see the headers quickly
|
|
|
|
var timeToWait =
|
|
|
|
gPrefService.getIntPref("browser.download.saveLinkAsFilenameTimeout");
|
|
|
|
var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
timer.initWithCallback(new timerCallback(), timeToWait,
|
|
|
|
timer.TYPE_ONE_SHOT);
|
|
|
|
|
|
|
|
// kick off the channel with our proxy object as the listener
|
|
|
|
channel.asyncOpen(new saveAsListener(), null);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2011-07-10 13:53:22 -07:00
|
|
|
// Save URL of clicked-on link.
|
|
|
|
saveLink: function() {
|
|
|
|
var doc = this.target.ownerDocument;
|
|
|
|
urlSecurityCheck(this.linkURL, doc.nodePrincipal);
|
|
|
|
|
|
|
|
this.saveHelper(this.linkURL, this.linkText(), null, true, doc);
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
sendLink: function() {
|
|
|
|
// we don't know the title of the link so pass in an empty string
|
|
|
|
MailIntegration.sendMessage( this.linkURL, "" );
|
|
|
|
},
|
|
|
|
|
2011-09-06 17:20:35 -07:00
|
|
|
// Backwards-compatibility wrapper
|
2008-10-22 23:36:52 -07:00
|
|
|
saveImage : function() {
|
|
|
|
if (this.onCanvas || this.onImage)
|
|
|
|
this.saveMedia();
|
|
|
|
},
|
|
|
|
|
|
|
|
// Save URL of the clicked upon image, video, or audio.
|
|
|
|
saveMedia: function() {
|
2007-03-22 10:30:00 -07:00
|
|
|
var doc = this.target.ownerDocument;
|
2007-07-02 21:15:25 -07:00
|
|
|
if (this.onCanvas) {
|
|
|
|
// Bypass cache, since it's a data: URL.
|
|
|
|
saveImageURL(this.target.toDataURL(), "canvas.png", "SaveImageTitle",
|
|
|
|
true, false, doc.documentURIObject);
|
|
|
|
}
|
2008-10-22 23:36:52 -07:00
|
|
|
else if (this.onImage) {
|
|
|
|
urlSecurityCheck(this.mediaURL, doc.nodePrincipal);
|
|
|
|
saveImageURL(this.mediaURL, null, "SaveImageTitle", false,
|
2007-07-02 21:15:25 -07:00
|
|
|
false, doc.documentURIObject);
|
|
|
|
}
|
2008-10-22 23:36:52 -07:00
|
|
|
else if (this.onVideo || this.onAudio) {
|
|
|
|
urlSecurityCheck(this.mediaURL, doc.nodePrincipal);
|
|
|
|
var dialogTitle = this.onVideo ? "SaveVideoTitle" : "SaveAudioTitle";
|
2011-07-10 13:53:22 -07:00
|
|
|
this.saveHelper(this.mediaURL, null, dialogTitle, false, doc);
|
2008-10-22 23:36:52 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
2011-09-06 17:20:35 -07:00
|
|
|
// Backwards-compatibility wrapper
|
2008-10-22 23:36:52 -07:00
|
|
|
sendImage : function() {
|
|
|
|
if (this.onCanvas || this.onImage)
|
|
|
|
this.sendMedia();
|
|
|
|
},
|
|
|
|
|
|
|
|
sendMedia: function() {
|
|
|
|
MailIntegration.sendMessage(this.mediaURL, "");
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
// Generate email address and put it on clipboard.
|
|
|
|
copyEmail: function() {
|
|
|
|
// Copy the comma-separated list of email addresses only.
|
|
|
|
// There are other ways of embedding email addresses in a mailto:
|
|
|
|
// link, but such complex parsing is beyond us.
|
|
|
|
var url = this.linkURL;
|
|
|
|
var qmark = url.indexOf("?");
|
|
|
|
var addresses;
|
|
|
|
|
|
|
|
// 7 == length of "mailto:"
|
|
|
|
addresses = qmark > 7 ? url.substring(7, qmark) : url.substr(7);
|
|
|
|
|
|
|
|
// Let's try to unescape it using a character set
|
|
|
|
// in case the address is not ASCII.
|
|
|
|
try {
|
|
|
|
var characterSet = this.target.ownerDocument.characterSet;
|
|
|
|
const textToSubURI = Cc["@mozilla.org/intl/texttosuburi;1"].
|
|
|
|
getService(Ci.nsITextToSubURI);
|
|
|
|
addresses = textToSubURI.unEscapeURIForUI(characterSet, addresses);
|
|
|
|
}
|
|
|
|
catch(ex) {
|
|
|
|
// Do nothing.
|
|
|
|
}
|
|
|
|
|
|
|
|
var clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].
|
|
|
|
getService(Ci.nsIClipboardHelper);
|
|
|
|
clipboard.copyString(addresses);
|
|
|
|
},
|
|
|
|
|
|
|
|
///////////////
|
|
|
|
// Utilities //
|
|
|
|
///////////////
|
|
|
|
|
|
|
|
// Show/hide one item (specified via name or the item element itself).
|
|
|
|
showItem: function(aItemOrId, aShow) {
|
|
|
|
var item = aItemOrId.constructor == String ?
|
|
|
|
document.getElementById(aItemOrId) : aItemOrId;
|
|
|
|
if (item)
|
|
|
|
item.hidden = !aShow;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Set given attribute of specified context-menu item. If the
|
|
|
|
// value is null, then it removes the attribute (which works
|
|
|
|
// nicely for the disabled attribute).
|
|
|
|
setItemAttr: function(aID, aAttr, aVal ) {
|
|
|
|
var elem = document.getElementById(aID);
|
|
|
|
if (elem) {
|
|
|
|
if (aVal == null) {
|
|
|
|
// null indicates attr should be removed.
|
|
|
|
elem.removeAttribute(aAttr);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Set attr=val.
|
|
|
|
elem.setAttribute(aAttr, aVal);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// Set context menu attribute according to like attribute of another node
|
|
|
|
// (such as a broadcaster).
|
|
|
|
setItemAttrFromNode: function(aItem_id, aAttr, aOther_id) {
|
|
|
|
var elem = document.getElementById(aOther_id);
|
|
|
|
if (elem && elem.getAttribute(aAttr) == "true")
|
|
|
|
this.setItemAttr(aItem_id, aAttr, "true");
|
|
|
|
else
|
|
|
|
this.setItemAttr(aItem_id, aAttr, null);
|
|
|
|
},
|
|
|
|
|
|
|
|
// Temporary workaround for DOM api not yet implemented by XUL nodes.
|
|
|
|
cloneNode: function(aItem) {
|
|
|
|
// Create another element like the one we're cloning.
|
|
|
|
var node = document.createElement(aItem.tagName);
|
|
|
|
|
|
|
|
// Copy attributes from argument item to the new one.
|
|
|
|
var attrs = aItem.attributes;
|
|
|
|
for (var i = 0; i < attrs.length; i++) {
|
|
|
|
var attr = attrs.item(i);
|
|
|
|
node.setAttribute(attr.nodeName, attr.nodeValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Voila!
|
|
|
|
return node;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Generate fully qualified URL for clicked-on link.
|
|
|
|
getLinkURL: function() {
|
|
|
|
var href = this.link.href;
|
|
|
|
if (href)
|
|
|
|
return href;
|
|
|
|
|
|
|
|
href = this.link.getAttributeNS("http://www.w3.org/1999/xlink",
|
|
|
|
"href");
|
|
|
|
|
|
|
|
if (!href || !href.match(/\S/)) {
|
|
|
|
// Without this we try to save as the current doc,
|
|
|
|
// for example, HTML case also throws if empty
|
|
|
|
throw "Empty href";
|
|
|
|
}
|
|
|
|
|
|
|
|
return makeURLAbsolute(this.link.baseURI, href);
|
|
|
|
},
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
getLinkURI: function() {
|
|
|
|
try {
|
2009-07-28 22:55:18 -07:00
|
|
|
return makeURI(this.linkURL);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
catch (ex) {
|
|
|
|
// e.g. empty URL string
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
2010-07-14 19:00:12 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
getLinkProtocol: function() {
|
|
|
|
if (this.linkURI)
|
|
|
|
return this.linkURI.scheme; // can be |undefined|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Get text of link.
|
|
|
|
linkText: function() {
|
|
|
|
var text = gatherTextUnder(this.link);
|
|
|
|
if (!text || !text.match(/\S/)) {
|
|
|
|
text = this.link.getAttribute("title");
|
|
|
|
if (!text || !text.match(/\S/)) {
|
|
|
|
text = this.link.getAttribute("alt");
|
|
|
|
if (!text || !text.match(/\S/))
|
|
|
|
text = this.linkURL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return text;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Get selected text. Only display the first 15 chars.
|
|
|
|
isTextSelection: function() {
|
|
|
|
// Get 16 characters, so that we can trim the selection if it's greater
|
|
|
|
// than 15 chars
|
|
|
|
var selectedText = getBrowserSelection(16);
|
|
|
|
|
|
|
|
if (!selectedText)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (selectedText.length > 15)
|
2008-01-23 23:20:44 -08:00
|
|
|
selectedText = selectedText.substr(0,15) + this.ellipsis;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Use the current engine if the search bar is visible, the default
|
|
|
|
// engine otherwise.
|
|
|
|
var engineName = "";
|
|
|
|
var ss = Cc["@mozilla.org/browser/search-service;1"].
|
|
|
|
getService(Ci.nsIBrowserSearchService);
|
2007-10-08 13:17:14 -07:00
|
|
|
if (isElementVisible(BrowserSearch.searchBar))
|
2007-03-22 10:30:00 -07:00
|
|
|
engineName = ss.currentEngine.name;
|
|
|
|
else
|
|
|
|
engineName = ss.defaultEngine.name;
|
|
|
|
|
|
|
|
// format "Search <engine> for <selection>" string to show in menu
|
|
|
|
var menuLabel = gNavigatorBundle.getFormattedString("contextMenuSearchText",
|
|
|
|
[engineName,
|
|
|
|
selectedText]);
|
|
|
|
document.getElementById("context-searchselect").label = menuLabel;
|
2008-07-29 07:41:54 -07:00
|
|
|
document.getElementById("context-searchselect").accessKey =
|
|
|
|
gNavigatorBundle.getString("contextMenuSearchText.accesskey");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
|
|
|
// Returns true if anything is selected.
|
|
|
|
isContentSelection: function() {
|
|
|
|
return !document.commandDispatcher.focusedWindow.getSelection().isCollapsed;
|
|
|
|
},
|
|
|
|
|
|
|
|
toString: function () {
|
|
|
|
return "contextMenu.target = " + this.target + "\n" +
|
|
|
|
"contextMenu.onImage = " + this.onImage + "\n" +
|
|
|
|
"contextMenu.onLink = " + this.onLink + "\n" +
|
|
|
|
"contextMenu.link = " + this.link + "\n" +
|
|
|
|
"contextMenu.inFrame = " + this.inFrame + "\n" +
|
|
|
|
"contextMenu.hasBGImage = " + this.hasBGImage + "\n";
|
|
|
|
},
|
|
|
|
|
2009-02-26 12:36:01 -08:00
|
|
|
// Returns true if aNode is a from control (except text boxes and images).
|
2008-02-23 23:42:40 -08:00
|
|
|
// This is used to disable the context menu for form controls.
|
|
|
|
isTargetAFormControl: function(aNode) {
|
|
|
|
if (aNode instanceof HTMLInputElement)
|
2010-05-12 00:17:07 -07:00
|
|
|
return (!aNode.mozIsTextField(false) && aNode.type != "image");
|
2008-02-23 23:42:40 -08:00
|
|
|
|
|
|
|
return (aNode instanceof HTMLButtonElement) ||
|
|
|
|
(aNode instanceof HTMLSelectElement) ||
|
|
|
|
(aNode instanceof HTMLOptionElement) ||
|
|
|
|
(aNode instanceof HTMLOptGroupElement);
|
|
|
|
},
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
isTargetATextBox: function(node) {
|
|
|
|
if (node instanceof HTMLInputElement)
|
2010-05-12 00:17:07 -07:00
|
|
|
return node.mozIsTextField(false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return (node instanceof HTMLTextAreaElement);
|
|
|
|
},
|
|
|
|
|
|
|
|
isTargetAKeywordField: function(aNode) {
|
2008-06-15 18:28:01 -07:00
|
|
|
if (!(aNode instanceof HTMLInputElement))
|
|
|
|
return false;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var form = aNode.form;
|
2008-06-15 18:28:01 -07:00
|
|
|
if (!form || aNode.type == "password")
|
2007-03-22 10:30:00 -07:00
|
|
|
return false;
|
|
|
|
|
|
|
|
var method = form.method.toUpperCase();
|
|
|
|
|
|
|
|
// These are the following types of forms we can create keywords for:
|
|
|
|
//
|
|
|
|
// method encoding type can create keyword
|
|
|
|
// GET * YES
|
|
|
|
// * YES
|
|
|
|
// POST YES
|
|
|
|
// POST application/x-www-form-urlencoded YES
|
|
|
|
// POST text/plain NO (a little tricky to do)
|
|
|
|
// POST multipart/form-data NO
|
|
|
|
// POST everything else YES
|
|
|
|
return (method == "GET" || method == "") ||
|
|
|
|
(form.enctype != "text/plain") && (form.enctype != "multipart/form-data");
|
|
|
|
},
|
|
|
|
|
|
|
|
// Determines whether or not the separator with the specified ID should be
|
|
|
|
// shown or not by determining if there are any non-hidden items between it
|
|
|
|
// and the previous separator.
|
|
|
|
shouldShowSeparator: function (aSeparatorID) {
|
|
|
|
var separator = document.getElementById(aSeparatorID);
|
|
|
|
if (separator) {
|
|
|
|
var sibling = separator.previousSibling;
|
|
|
|
while (sibling && sibling.localName != "menuseparator") {
|
|
|
|
if (!sibling.hidden)
|
|
|
|
return true;
|
|
|
|
sibling = sibling.previousSibling;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
addDictionaries: function() {
|
|
|
|
var uri = formatURL("browser.dictionaries.download.url", true);
|
|
|
|
|
|
|
|
var locale = "-";
|
|
|
|
try {
|
|
|
|
locale = gPrefService.getComplexValue("intl.accept_languages",
|
|
|
|
Ci.nsIPrefLocalizedString).data;
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
var version = "-";
|
|
|
|
try {
|
|
|
|
version = Cc["@mozilla.org/xre/app-info;1"].
|
|
|
|
getService(Ci.nsIXULAppInfo).version;
|
|
|
|
}
|
|
|
|
catch (e) { }
|
|
|
|
|
|
|
|
uri = uri.replace(/%LOCALE%/, escape(locale)).replace(/%VERSION%/, version);
|
|
|
|
|
|
|
|
var newWindowPref = gPrefService.getIntPref("browser.link.open_newwindow");
|
|
|
|
var where = newWindowPref == 3 ? "tab" : "window";
|
|
|
|
|
|
|
|
openUILinkIn(uri, where);
|
|
|
|
},
|
|
|
|
|
|
|
|
bookmarkThisPage: function CM_bookmarkThisPage() {
|
2007-11-19 18:01:53 -08:00
|
|
|
window.top.PlacesCommandHook.bookmarkPage(this.browser, PlacesUtils.bookmarksMenuFolderId, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
bookmarkLink: function CM_bookmarkLink() {
|
2007-11-19 18:01:53 -08:00
|
|
|
window.top.PlacesCommandHook.bookmarkLink(PlacesUtils.bookmarksMenuFolderId, this.linkURL,
|
2007-11-13 08:30:58 -08:00
|
|
|
this.linkText());
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
addBookmarkForFrame: function CM_addBookmarkForFrame() {
|
|
|
|
var doc = this.target.ownerDocument;
|
2007-08-17 00:22:12 -07:00
|
|
|
var uri = doc.documentURIObject;
|
|
|
|
|
|
|
|
var itemId = PlacesUtils.getMostRecentBookmarkForURI(uri);
|
|
|
|
if (itemId == -1) {
|
|
|
|
var title = doc.title;
|
2008-03-13 12:25:49 -07:00
|
|
|
var description = PlacesUIUtils.getDescriptionFromDocument(doc);
|
2011-10-27 02:11:43 -07:00
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "add"
|
|
|
|
, type: "bookmark"
|
|
|
|
, uri: uri
|
|
|
|
, title: title
|
|
|
|
, description: description
|
|
|
|
, hiddenRows: [ "description"
|
|
|
|
, "location"
|
|
|
|
, "loadInSidebar"
|
|
|
|
, "folderPicker"
|
|
|
|
, "keyword" ]
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PlacesUIUtils.showBookmarkDialog({ action: "edit"
|
|
|
|
, type: "bookmark"
|
|
|
|
, itemId: itemId
|
|
|
|
});
|
2007-08-17 00:22:12 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
savePageAs: function CM_savePageAs() {
|
|
|
|
saveDocument(this.browser.contentDocument);
|
|
|
|
},
|
|
|
|
|
|
|
|
sendPage: function CM_sendPage() {
|
|
|
|
MailIntegration.sendLinkForWindow(this.browser.contentWindow);
|
|
|
|
},
|
|
|
|
|
|
|
|
printFrame: function CM_printFrame() {
|
|
|
|
PrintUtils.print(this.target.ownerDocument.defaultView);
|
2007-03-27 17:47:29 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
switchPageDirection: function CM_switchPageDirection() {
|
|
|
|
SwitchDocumentDirection(this.browser.contentWindow);
|
2008-10-22 23:36:52 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
mediaCommand : function CM_mediaCommand(command) {
|
|
|
|
var media = this.target;
|
|
|
|
|
|
|
|
switch (command) {
|
|
|
|
case "play":
|
|
|
|
media.play();
|
|
|
|
break;
|
|
|
|
case "pause":
|
|
|
|
media.pause();
|
|
|
|
break;
|
|
|
|
case "mute":
|
|
|
|
media.muted = true;
|
|
|
|
break;
|
|
|
|
case "unmute":
|
|
|
|
media.muted = false;
|
|
|
|
break;
|
|
|
|
case "hidecontrols":
|
|
|
|
media.removeAttribute("controls");
|
|
|
|
break;
|
|
|
|
case "showcontrols":
|
|
|
|
media.setAttribute("controls", "true");
|
|
|
|
break;
|
2011-10-03 20:47:41 -07:00
|
|
|
case "showstats":
|
2011-10-27 02:11:43 -07:00
|
|
|
var event = document.createEvent("CustomEvent");
|
|
|
|
event.initCustomEvent("media-showStatistics", false, true, true);
|
2011-10-03 20:47:41 -07:00
|
|
|
media.dispatchEvent(event);
|
|
|
|
break;
|
|
|
|
case "hidestats":
|
2011-10-27 02:11:43 -07:00
|
|
|
var event = document.createEvent("CustomEvent");
|
|
|
|
event.initCustomEvent("media-showStatistics", false, true, false);
|
2011-10-03 20:47:41 -07:00
|
|
|
media.dispatchEvent(event);
|
|
|
|
break;
|
2008-10-22 23:36:52 -07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
copyMediaLocation : function () {
|
|
|
|
var clipboard = Cc["@mozilla.org/widget/clipboardhelper;1"].
|
|
|
|
getService(Ci.nsIClipboardHelper);
|
|
|
|
clipboard.copyString(this.mediaURL);
|
2009-06-09 18:59:18 -07:00
|
|
|
},
|
|
|
|
|
|
|
|
get imageURL() {
|
|
|
|
if (this.onImage)
|
|
|
|
return this.mediaURL;
|
|
|
|
return "";
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|