зеркало из https://github.com/mozilla/pjs.git
Bug 397457 - context menu code cleanup, remove things we don't use, get rid of a failing security check on any click and replace it with a working one on right-click, catch up with 'API' changes around linkURI in Fx, do less string manipulation of URI specs, r=mkmelin, sr=mscott
This commit is contained in:
Родитель
0e58e32cf2
Коммит
3a203a2e28
|
@ -1,201 +1,186 @@
|
|||
# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
# ***** 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):
|
||||
# Alec Flett <alecf@netscape.com>
|
||||
# Ben Goodger <ben@netscape.com>
|
||||
# Mike Pinkerton <pinkerton@netscape.com>
|
||||
# Blake Ross <blakeross@telocity.com>
|
||||
# Christopher Thomas <cst@yecc.com>
|
||||
#
|
||||
# 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 *****
|
||||
|
||||
/*
|
||||
* - [ Dependencies ] ---------------------------------------------------------
|
||||
* utilityOverlay.js:
|
||||
* - gatherTextUnder
|
||||
*/
|
||||
|
||||
var pref = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
/**
|
||||
* extract the href from the link click event.
|
||||
* We look for HTMLAnchorElement, HTMLAreaElement, HTMLLinkElement,
|
||||
* HTMLInputElement.form.action, and nested anchor tags.
|
||||
*
|
||||
* @return href for the url being clicked
|
||||
*/
|
||||
function hRefForClickEvent(event)
|
||||
{
|
||||
var target = event.target;
|
||||
var href;
|
||||
var isKeyPress = (event.type == "keypress");
|
||||
|
||||
if (target instanceof HTMLAnchorElement ||
|
||||
target instanceof HTMLAreaElement ||
|
||||
target instanceof HTMLLinkElement)
|
||||
{
|
||||
if (target.hasAttribute("href"))
|
||||
href = target.href;
|
||||
}
|
||||
else if (target instanceof HTMLInputElement)
|
||||
{
|
||||
if (target.form && target.form.action)
|
||||
href = target.form.action;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we may be nested inside of a link node
|
||||
var linkNode = event.originalTarget;
|
||||
while (linkNode && !(linkNode instanceof HTMLAnchorElement))
|
||||
linkNode = linkNode.parentNode;
|
||||
|
||||
if (linkNode)
|
||||
href = linkNode.href;
|
||||
}
|
||||
|
||||
return href;
|
||||
}
|
||||
|
||||
function messagePaneOnResize(event)
|
||||
{
|
||||
// scale any overflowing images
|
||||
var messagepane = document.getElementById("messagepane");
|
||||
var doc = messagepane.contentDocument;
|
||||
var imgs = doc.images;
|
||||
# -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
# ***** 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):
|
||||
# Alec Flett <alecf@netscape.com>
|
||||
# Ben Goodger <ben@netscape.com>
|
||||
# Mike Pinkerton <pinkerton@netscape.com>
|
||||
# Blake Ross <blakeross@telocity.com>
|
||||
# Christopher Thomas <cst@yecc.com>
|
||||
#
|
||||
# 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 *****
|
||||
|
||||
var pref = Components.classes["@mozilla.org/preferences-service;1"]
|
||||
.getService(Components.interfaces.nsIPrefBranch);
|
||||
|
||||
/**
|
||||
* Extract the href from the link click event.
|
||||
* We look for HTMLAnchorElement, HTMLAreaElement, HTMLLinkElement,
|
||||
* HTMLInputElement.form.action, and nested anchor tags.
|
||||
*
|
||||
* @return href for the url being clicked
|
||||
*/
|
||||
function hRefForClickEvent(aEvent)
|
||||
{
|
||||
var target = aEvent.target;
|
||||
var href;
|
||||
var isKeyPress = (aEvent.type == "keypress");
|
||||
|
||||
if (target instanceof HTMLAnchorElement ||
|
||||
target instanceof HTMLAreaElement ||
|
||||
target instanceof HTMLLinkElement)
|
||||
{
|
||||
if (target.hasAttribute("href"))
|
||||
href = target.href;
|
||||
}
|
||||
else if (target instanceof HTMLInputElement)
|
||||
{
|
||||
if (target.form && target.form.action)
|
||||
href = target.form.action;
|
||||
}
|
||||
else
|
||||
{
|
||||
// we may be nested inside of a link node
|
||||
var linkNode = aEvent.originalTarget;
|
||||
while (linkNode && !(linkNode instanceof HTMLAnchorElement))
|
||||
linkNode = linkNode.parentNode;
|
||||
|
||||
if (linkNode)
|
||||
href = linkNode.href;
|
||||
}
|
||||
|
||||
return href;
|
||||
}
|
||||
|
||||
function messagePaneOnResize(aEvent)
|
||||
{
|
||||
// scale any overflowing images
|
||||
var messagepane = document.getElementById("messagepane");
|
||||
var doc = messagepane.contentDocument;
|
||||
var imgs = doc.images;
|
||||
for each (var img in imgs)
|
||||
{
|
||||
{
|
||||
if (img.className == "moz-attached-image")
|
||||
{
|
||||
{
|
||||
if (img.naturalWidth <= doc.width)
|
||||
{
|
||||
img.removeAttribute("isshrunk");
|
||||
img.removeAttribute("overflowing");
|
||||
}
|
||||
{
|
||||
img.removeAttribute("isshrunk");
|
||||
img.removeAttribute("overflowing");
|
||||
}
|
||||
else if (img.hasAttribute("shrinktofit"))
|
||||
{
|
||||
img.setAttribute("isshrunk", "true");
|
||||
img.removeAttribute("overflowing");
|
||||
}
|
||||
{
|
||||
img.setAttribute("isshrunk", "true");
|
||||
img.removeAttribute("overflowing");
|
||||
}
|
||||
else
|
||||
{
|
||||
img.setAttribute("overflowing", "true");
|
||||
img.removeAttribute("isshrunk");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called whenever the user clicks in the content area,
|
||||
// except when left-clicking on links (special case)
|
||||
// should always return true for click to go through
|
||||
function contentAreaClick(event)
|
||||
{
|
||||
var href = hRefForClickEvent(event);
|
||||
if (href)
|
||||
{
|
||||
handleLinkClick(event, href, null);
|
||||
if (!event.button) // left click only
|
||||
return gPhishingDetector.warnOnSuspiciousLinkClick(href); // let the phishing detector check the link
|
||||
}
|
||||
else if (!event.button)
|
||||
{
|
||||
var target = event.target;
|
||||
// is this an image that we might want to scale?
|
||||
const Ci = Components.interfaces;
|
||||
if (target instanceof Ci.nsIImageLoadingContent)
|
||||
{
|
||||
// make sure it loaded successfully
|
||||
var req = target.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
||||
if (!req || req.imageStatus & Ci.imgIRequest.STATUS_ERROR)
|
||||
return true;
|
||||
// is it an inline attachment?
|
||||
{
|
||||
img.setAttribute("overflowing", "true");
|
||||
img.removeAttribute("isshrunk");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called whenever the user clicks in the content area,
|
||||
// should always return true for click to go through
|
||||
function contentAreaClick(aEvent)
|
||||
{
|
||||
var href = hRefForClickEvent(aEvent);
|
||||
if (href && !aEvent.button) // left click on link only
|
||||
{
|
||||
// let the phishing detector check the link
|
||||
return gPhishingDetector.warnOnSuspiciousLinkClick(href);
|
||||
}
|
||||
if (!aEvent.button)
|
||||
{
|
||||
var target = aEvent.target;
|
||||
// is this an image that we might want to scale?
|
||||
const Ci = Components.interfaces;
|
||||
if (target instanceof Ci.nsIImageLoadingContent)
|
||||
{
|
||||
// make sure it loaded successfully
|
||||
var req = target.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
|
||||
if (!req || req.imageStatus & Ci.imgIRequest.STATUS_ERROR)
|
||||
return true;
|
||||
// is it an inline attachment?
|
||||
if (/^moz-attached-image/.test(target.className))
|
||||
{
|
||||
{
|
||||
if (target.hasAttribute("isshrunk"))
|
||||
{
|
||||
// currently shrunk to fit, so unshrink it
|
||||
target.removeAttribute("isshrunk");
|
||||
target.removeAttribute("shrinktofit");
|
||||
target.setAttribute("overflowing", "true");
|
||||
}
|
||||
{
|
||||
// currently shrunk to fit, so unshrink it
|
||||
target.removeAttribute("isshrunk");
|
||||
target.removeAttribute("shrinktofit");
|
||||
target.setAttribute("overflowing", "true");
|
||||
}
|
||||
else if (target.hasAttribute("overflowing"))
|
||||
{
|
||||
// user wants to shrink now
|
||||
target.setAttribute("isshrunk", "true");
|
||||
target.setAttribute("shrinktofit", "true");
|
||||
target.removeAttribute("overflowing");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function openNewTabOrWindow(event, href, sendReferrer)
|
||||
{
|
||||
// always return false for stand alone mail (MOZ_THUNDERBIRD)
|
||||
// let someone else deal with it
|
||||
return false;
|
||||
}
|
||||
|
||||
function getContentFrameURI(aFocusedWindow)
|
||||
{
|
||||
var contentFrame = isContentFrame(aFocusedWindow) ? aFocusedWindow : window.content;
|
||||
return contentFrame.location.href;
|
||||
}
|
||||
|
||||
function handleLinkClick(event, href, linkNode)
|
||||
{
|
||||
// Make sure we are allowed to open this URL
|
||||
var focusedWindow = document.commandDispatcher.focusedWindow;
|
||||
var sourceURL = getContentFrameURI(focusedWindow);
|
||||
urlSecurityCheck(href, sourceURL);
|
||||
return false;
|
||||
}
|
||||
|
||||
function middleMousePaste( event )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
function makeURLAbsolute( base, url )
|
||||
{
|
||||
// Construct nsIURL.
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"]
|
||||
.getService(Components.interfaces.nsIIOService);
|
||||
var baseURI = ioService.newURI(base, null, null);
|
||||
|
||||
return ioService.newURI(baseURI.resolve(url), null, null).spec;
|
||||
}
|
||||
{
|
||||
// user wants to shrink now
|
||||
target.setAttribute("isshrunk", "true");
|
||||
target.setAttribute("shrinktofit", "true");
|
||||
target.removeAttribute("overflowing");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function openNewTabOrWindow(aEvent, aHref, aSendReferrer)
|
||||
{
|
||||
// always return false for stand alone mail (MOZ_THUNDERBIRD)
|
||||
// let someone else deal with it
|
||||
return false;
|
||||
}
|
||||
|
||||
function getContentFrameURI(aFocusedWindow)
|
||||
{
|
||||
var contentFrame =
|
||||
isContentFrame(aFocusedWindow) ? aFocusedWindow : window.content;
|
||||
return contentFrame.location.href;
|
||||
}
|
||||
|
||||
function middleMousePaste(aEvent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
function makeURLAbsolute(aBase, aUrl)
|
||||
{
|
||||
// Construct nsIURL.
|
||||
var ioService = Components.classes["@mozilla.org/network/io-service;1"].
|
||||
getService(Components.interfaces.nsIIOService);
|
||||
var baseURI = ioService.newURI(aBase, null, null);
|
||||
|
||||
return ioService.newURI(baseURI.resolve(aUrl), null, null).spec;
|
||||
}
|
||||
|
|
|
@ -802,7 +802,7 @@ function IsMenuItemShowing(menuID)
|
|||
// message pane context menu helper methods
|
||||
function addEmail()
|
||||
{
|
||||
var url = gContextMenu.linkURL();
|
||||
var url = gContextMenu.linkURL;
|
||||
var addresses = getEmail(url);
|
||||
window.openDialog("chrome://messenger/content/addressbook/abNewCardDialog.xul",
|
||||
"",
|
||||
|
@ -812,7 +812,7 @@ function addEmail()
|
|||
|
||||
function composeEmailTo ()
|
||||
{
|
||||
var url = gContextMenu.linkURL();
|
||||
var url = gContextMenu.linkURL;
|
||||
var addresses = getEmail(url);
|
||||
var fields = Components.classes["@mozilla.org/messengercompose/composefields;1"].createInstance(Components.interfaces.nsIMsgCompFields);
|
||||
var params = Components.classes["@mozilla.org/messengercompose/composeparams;1"].createInstance(Components.interfaces.nsIMsgComposeParams);
|
||||
|
|
|
@ -60,6 +60,8 @@ var mailSession;
|
|||
var gMessengerBundle;
|
||||
var gBrandBundle;
|
||||
|
||||
var gContextMenu;
|
||||
|
||||
var datasourceContractIDPrefix = "@mozilla.org/rdf/datasource;1?name=";
|
||||
var accountManagerDSContractID = datasourceContractIDPrefix + "msgaccountmanager";
|
||||
var folderDSContractID = datasourceContractIDPrefix + "mailnewsfolders";
|
||||
|
|
|
@ -1125,7 +1125,7 @@
|
|||
oncommand="gContextMenu.saveImage();"/>
|
||||
<menuseparator id="messagePaneContext-sep-reportPhishing"/>
|
||||
<menuitem id="reportPhishingURL" label="&reportPhishingURL.label;" accesskey="&reportPhishingURL.accesskey;"
|
||||
oncommand="gPhishingDetector.reportPhishingURL(gContextMenu.linkURL());"/>
|
||||
oncommand="gPhishingDetector.reportPhishingURL(gContextMenu.linkURL);"/>
|
||||
</popup>
|
||||
|
||||
<popup id="toolbar-context-menu">
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче