Bug 162393 - Making our content area clicking and link handling more robust.

r=bzbarsky sr=jag a=asa
This commit is contained in:
caillon%returnzero.com 2002-10-17 04:09:20 +00:00
Родитель cce080956e
Коммит d7e5e89abc
4 изменённых файлов: 28 добавлений и 33 удалений

Просмотреть файл

@ -58,12 +58,6 @@ function initEditorContextMenuListener(aEvent)
addEventListener("load", initEditorContextMenuListener, false);
function editLink(aLinkURL)
{
urlSecurityCheck(aLinkURL, window.document); // XXX what is this? Why do we pass the chrome doc?
editPage(aLinkURL, window, false);
}
function editDocument(aDocument)
{
if (!aDocument)
@ -74,12 +68,8 @@ function editDocument(aDocument)
function editPageOrFrame()
{
var url;
var focusedWindow = document.commandDispatcher.focusedWindow;
if (isDocumentFrame(focusedWindow))
url = focusedWindow.location.href;
else
url = window._content.location.href;
var url = getContentFrameURI(focusedWindow);
editPage(url, window, false)
}
@ -92,8 +82,8 @@ function editPageOrFrame()
function editPage(url, launchWindow, delay)
{
var focusedWindow = document.commandDispatcher.focusedWindow;
if (isDocumentFrame(focusedWindow))
url = focusedWindow.location.href;
if (isContentFrame(focusedWindow))
url = Components.lookupMethod(focusedWindow, 'location').call(focusedWindow).href;
// Always strip off "view-source:"
if (url.slice(0,12) == "view-source:")

Просмотреть файл

@ -209,7 +209,7 @@ function loadEventHandlers(event)
function getContentAreaFrameCount()
{
var saveFrameItem = document.getElementById("savepage");
if (!_content || !_content.frames.length || !isDocumentFrame(document.commandDispatcher.focusedWindow))
if (!content || !content.frames.length || !isContentFrame(document.commandDispatcher.focusedWindow))
saveFrameItem.setAttribute("hidden", "true");
else
saveFrameItem.removeAttribute("hidden");
@ -219,8 +219,8 @@ function getContentAreaFrameCount()
function contentAreaFrameFocus()
{
var focusedWindow = document.commandDispatcher.focusedWindow;
if (isDocumentFrame(focusedWindow)) {
gFocusedURL = focusedWindow.location.href;
if (isContentFrame(focusedWindow)) {
gFocusedURL = Components.lookupMethod(focusedWindow, 'location').call(focusedWindow).href;
gFocusedDocument = focusedWindow.document;
}
}

Просмотреть файл

@ -206,6 +206,9 @@
function handleLinkClick(event, href, linkNode)
{
// Make sure we are allowed to open this URL
urlSecurityCheck(href, document);
switch (event.button) {
case 0: // if left button clicked
if (event.metaKey || event.ctrlKey) { // and meta or ctrl are down

Просмотреть файл

@ -40,38 +40,40 @@
* Determine whether or not a given focused DOMWindow is in the content
* area.
**/
function isDocumentFrame(aFocusedWindow)
function isContentFrame(aFocusedWindow)
{
var contentFrames = _content.frames;
if (contentFrames.length) {
for (var i = 0; i < contentFrames.length; ++i) {
if (aFocusedWindow == contentFrames[i])
return true;
}
}
return false;
var focusedTop = Components.lookupMethod(aFocusedWindow, 'top')
.call(aFocusedWindow);
return (focusedTop == window.content);
}
function urlSecurityCheck(url, doc)
{
// URL Loading Security Check
var focusedWindow = doc.commandDispatcher.focusedWindow;
var sourceWin = isDocumentFrame(focusedWindow) ? focusedWindow.location.href : focusedWindow._content.location.href;
var sourceURL = getContentFrameURI(focusedWindow);
const nsIScriptSecurityManager = Components.interfaces.nsIScriptSecurityManager;
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"].getService().
QueryInterface(nsIScriptSecurityManager);
var secMan = Components.classes["@mozilla.org/scriptsecuritymanager;1"]
.getService(nsIScriptSecurityManager);
try {
secMan.checkLoadURIStr(sourceWin, url, nsIScriptSecurityManager.STANDARD);
secMan.checkLoadURIStr(sourceURL, url, nsIScriptSecurityManager.STANDARD);
} catch (e) {
throw "Load of " + url + " denied.";
throw "Load of " + url + " denied.";
}
}
function getContentFrameURI(aFocusedWindow)
{
var contentFrame = isContentFrame(aFocusedWindow) ? aFocusedWindow : window.content;
return Components.lookupMethod(contentFrame, 'location').call(contentFrame).href;
}
function getReferrer(doc)
{
var focusedWindow = doc.commandDispatcher.focusedWindow;
var sourceURL =
isDocumentFrame(focusedWindow) ? focusedWindow.location.href : focusedWindow._content.location.href;
var sourceURL = getContentFrameURI(focusedWindow);
try {
var uri = Components.classes["@mozilla.org/network/standard-url;1"].createInstance(Components.interfaces.nsIURI);
uri.spec = sourceURL;
@ -156,7 +158,7 @@ function saveURL(aURL, aFileName, aFilePickerTitleKey, aShouldBypassCache)
function saveFrameDocument()
{
var focusedWindow = document.commandDispatcher.focusedWindow;
if (isDocumentFrame(focusedWindow))
if (isContentFrame(focusedWindow))
saveDocument(focusedWindow.document);
}