diff --git a/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp b/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp index 8d26a14a751..a90cf1166a3 100644 --- a/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp +++ b/mozilla/embedding/components/windowwatcher/src/nsWindowWatcher.cpp @@ -566,26 +566,46 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent, } NS_ASSERTION(mWindowCreator, "attempted to open a new window with no WindowCreator"); + rv = NS_ERROR_FAILURE; if (mWindowCreator) { nsCOMPtr newChrome; - // If the window creator is an nsIWindowCreator2, we can give it some hints. + /* If the window creator is an nsIWindowCreator2, we can give it + some hints. The only hint at this time is whether the opening window + is in a situation that's likely to mean this is an unrequested + popup window we're creating. However we're not completely honest: + we clear that indicator if the opener is chrome, so that the + downstream consumer can treat the indicator to mean simply + that the new window is subject to popup control. */ nsCOMPtr windowCreator2(do_QueryInterface(mWindowCreator)); if (windowCreator2) { PRUint32 contextFlags = 0; + PRBool popupConditions = PR_FALSE; + + // is the parent under popup conditions? nsCOMPtr piWindow(do_QueryInterface(aParent)); - if (piWindow) { - PRBool parentIsLoadingOrRunningTimeout; - piWindow->IsLoadingOrRunningTimeout(&parentIsLoadingOrRunningTimeout); - if (parentIsLoadingOrRunningTimeout) - contextFlags |= nsIWindowCreator2::PARENT_IS_LOADING_OR_RUNNING_TIMEOUT; + if (piWindow) + piWindow->IsLoadingOrRunningTimeout(&popupConditions); + + // chrome is always allowed, so clear the flag if the opener is chrome + if (popupConditions) { + PRBool isChrome = PR_FALSE; + nsCOMPtr + sm(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID)); + if (sm) + sm->SubjectPrincipalIsSystem(&isChrome); + popupConditions = !isChrome; } - windowCreator2->CreateChromeWindow2(parentChrome, chromeFlags, contextFlags, - getter_AddRefs(newChrome)); + + if (popupConditions) + contextFlags |= nsIWindowCreator2::PARENT_IS_LOADING_OR_RUNNING_TIMEOUT; + + rv = windowCreator2->CreateChromeWindow2(parentChrome, chromeFlags, + contextFlags, getter_AddRefs(newChrome)); } else - mWindowCreator->CreateChromeWindow(parentChrome, chromeFlags, - getter_AddRefs(newChrome)); + rv = mWindowCreator->CreateChromeWindow(parentChrome, chromeFlags, + getter_AddRefs(newChrome)); if (newChrome) { /* It might be a chrome nsXULWindow, in which case it won't have an nsIDOMWindow (primary content shell). But in that case, it'll @@ -595,13 +615,15 @@ nsWindowWatcher::OpenWindowJS(nsIDOMWindow *aParent, GetWindowTreeItem(newWindow, getter_AddRefs(newDocShellItem)); if (!newDocShellItem) newDocShellItem = do_GetInterface(newChrome); + if (!newDocShellItem) + rv = NS_ERROR_FAILURE; } } } // better have a window to use by this point if (!newDocShellItem) - return NS_ERROR_FAILURE; + return rv; rv = ReadyOpenedDocShellItem(newDocShellItem, aParent, _retval); if (NS_FAILED(rv)) diff --git a/mozilla/extensions/cookie/resources/content/cookieNavigatorOverlay.xul b/mozilla/extensions/cookie/resources/content/cookieNavigatorOverlay.xul index 810bf81bb32..a33585d104c 100644 --- a/mozilla/extensions/cookie/resources/content/cookieNavigatorOverlay.xul +++ b/mozilla/extensions/cookie/resources/content/cookieNavigatorOverlay.xul @@ -32,7 +32,10 @@ privacy->cookie->block from java console return; @@ -88,16 +107,42 @@ disableElement.setAttribute("disabled","true"); enableElement.removeAttribute("disabled"); + if (popupmanager.testPermission(getBrowser().currentURI) == Components.interfaces.nsIPopupWindowManager.eDisallow) { + disableElement = document.getElementById("BlockPopups"); + enableElement = document.getElementById("AllowPopups"); + } else { + disableElement = document.getElementById("AllowPopups"); + enableElement = document.getElementById("BlockPopups"); + } + disableElement.setAttribute("disabled","true"); + if (popupmanager.testSuitability(getBrowser().currentURI)) + enableElement.removeAttribute("disabled"); + else + enableElement.setAttribute("disabled","true"); + + var pref; + pref = Components.classes['@mozilla.org/preferences-service;1']; + pref = pref.getService(); + pref = pref.QueryInterface(Components.interfaces.nsIPrefBranch); + + // hide the popup manager menus if the prefs aren't exactly right. + // it'd be nicer to leave it always visible and adjust prefs to match + // any user selections + try { + var hide = pref.getBoolPref("dom.disable_open_during_load"); + if (!hide) + hide = pref.getIntPref("privacy.popups.policy") != Components.interfaces.nsIPopupWindowManager.eAllowConditionally; + HidePopups(hide); + } catch(e) { + HidePopups(true); + } + // determine if image manager should be in the UI if (alreadyCheckedForImage) { return; } alreadyCheckedForImage = true; // remove image functions (unless overruled by the "imageblocker.enabled" pref) - var pref; - pref = Components.classes['@mozilla.org/preferences-service;1']; - pref = pref.getService(); - pref = pref.QueryInterface(Components.interfaces.nsIPrefBranch); try { if (!pref.getBoolPref("imageblocker.enabled")) { HideImage(); @@ -136,6 +181,16 @@ element = document.getElementById("BlockImages"); alert(element.getAttribute("msg")); break; + case "popupAllow": + popupmanager.add(getBrowser().currentURI, true); + element = document.getElementById("AllowPopups"); + alert(element.getAttribute("msg")); + break; + case "popupBlock": + popupmanager.add(getBrowser().currentURI, false); + element = document.getElementById("BlockPopups"); + alert(element.getAttribute("msg")); + break; default: } } @@ -182,5 +237,24 @@ oncommand="viewImages();"/> + + + + + + + + diff --git a/mozilla/extensions/cookie/resources/content/cookieOverlay.js b/mozilla/extensions/cookie/resources/content/cookieOverlay.js index 6717c5d5a51..9a1f4a94e5f 100644 --- a/mozilla/extensions/cookie/resources/content/cookieOverlay.js +++ b/mozilla/extensions/cookie/resources/content/cookieOverlay.js @@ -20,12 +20,18 @@ var COOKIEPERMISSION = 0; var IMAGEPERMISSION = 1; +var WINDOWPERMISSION = 2; function viewImages() { window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank", "chrome,resizable=yes", "imageManager" ); } +function viewPopups() { + window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank", + "chrome,resizable=yes", "popupManager" ); +} + function viewCookies() { window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank", "chrome,resizable=yes", "cookieManager"); diff --git a/mozilla/extensions/wallet/cookieviewer/CookieViewer.js b/mozilla/extensions/wallet/cookieviewer/CookieViewer.js index 4547af2a1f7..b68f8ed6a17 100644 --- a/mozilla/extensions/wallet/cookieviewer/CookieViewer.js +++ b/mozilla/extensions/wallet/cookieviewer/CookieViewer.js @@ -25,8 +25,9 @@ var kObserverService; // interface variables -var cookiemanager = null; // cookiemanager interfa +var cookiemanager = null; // cookiemanager interface var permissionmanager = null; // permissionmanager interface +var popupmanager = null; // popup manager var gDateService = null; // cookies and permissions list @@ -35,10 +36,16 @@ var permissions = []; var deletedCookies = []; var deletedPermissions = []; -// differentiate between cookies and images -var isImages = (window.arguments[0] == "imageManager"); +// differentiate between cookies, images, and popups const cookieType = 0; const imageType = 1; +const popupType = 2; + +var dialogType = cookieType; +if (window.arguments[0] == "imageManager") + dialogType = imageType; +else if (window.arguments[0] == "popupManager") + dialogType = popupType; var cookieBundle; @@ -49,11 +56,13 @@ function Startup() { // cookieManagerFromIcon // imageManager - // xpconnect to cookiemanager/permissionmanager interfaces + // xpconnect to cookiemanager/permissionmanager/popupmanager interfaces cookiemanager = Components.classes["@mozilla.org/cookiemanager;1"].getService(); cookiemanager = cookiemanager.QueryInterface(Components.interfaces.nsICookieManager); permissionmanager = Components.classes["@mozilla.org/permissionmanager;1"].getService(); permissionmanager = permissionmanager.QueryInterface(Components.interfaces.nsIPermissionManager); + popupmanager = Components.classes["@mozilla.org/PopupWindowManager;1"].getService(); + popupmanager = popupmanager.QueryInterface(Components.interfaces.nsIPopupWindowManager); // intialize gDateService if (!gDateService) { @@ -73,10 +82,10 @@ function Startup() { try { var tabBox = document.getElementById("tabbox"); var element; - if (!isImages) { + if (dialogType == cookieType) { element = document.getElementById("cookiesTab"); tabBox.selectedTab = element; - } else { + } else if (dialogType == imageType) { element = document.getElementById("cookieviewer"); element.setAttribute("title", cookieBundle.getString("imageTitle")); element = document.getElementById("permissionsTab"); @@ -86,6 +95,16 @@ function Startup() { element.value = cookieBundle.getString("textBannedImages"); element = document.getElementById("cookiesTab"); element.hidden = "true"; + } else { + element = document.getElementById("cookieviewer"); + element.setAttribute("title", cookieBundle.getString("imageTitle")); + element = document.getElementById("permissionsTab"); + element.label = cookieBundle.getString("tabBannedPopups"); + tabBox.selectedTab = element; + element = document.getElementById("permissionsText"); + element.value = cookieBundle.getString("textBannedPopups"); + element = document.getElementById("cookiesTab"); + element.hidden = "true"; } } catch(e) { } @@ -93,7 +112,7 @@ function Startup() { // load in the cookies and permissions cookiesTree = document.getElementById("cookiesTree"); permissionsTree = document.getElementById("permissionsTree"); - if (!isImages) { + if (dialogType == cookieType) { loadCookies(); } loadPermissions(); @@ -406,17 +425,20 @@ function loadPermissions() { var count = 0; var contentStr; var canStr, cannotStr; - if (isImages) { + if (dialogType == cookieType) { + canStr="can"; + cannotStr="cannot"; + } else if (dialogType == imageType) { canStr="canImages"; cannotStr="cannotImages"; } else { - canStr="can"; - cannotStr="cannot"; + canStr="canPopups"; + cannotStr="cannotPopups"; } while (enumerator.hasMoreElements()) { var nextPermission = enumerator.getNext(); nextPermission = nextPermission.QueryInterface(Components.interfaces.nsIPermission); - if (nextPermission.type == (isImages ? imageType : cookieType)) { + if (nextPermission.type == dialogType) { var host = nextPermission.host; permissions[count] = new Permission(count++, host, @@ -462,8 +484,17 @@ function DeleteAllPermissions() { } function FinalizePermissionDeletions() { + var ioService = Components.classes["@mozilla.org/network/io-service;1"] + .getService(Components.interfaces.nsIIOService); + for (var p=0; p parentURI; + + GetParentURI(aParent, getter_AddRefs(parentURI)); + if (aContextFlags & PARENT_IS_LOADING_OR_RUNNING_TIMEOUT) + allow = AllowWindowCreation(parentURI); + nsCOMPtr newWindow; if (aParent) { + if (allow == nsIPopupWindowManager::eDisallow) + return NS_OK; // ruse to not give scripts a catchable error + if (allow == nsIPopupWindowManager::eAllow && + (aContextFlags & PARENT_IS_LOADING_OR_RUNNING_TIMEOUT)) + aContextFlags &= ~PARENT_IS_LOADING_OR_RUNNING_TIMEOUT; + nsCOMPtr xulParent(do_GetInterface(aParent)); NS_ASSERTION(xulParent, "window created using non-XUL parent. that's unexpected, but may work."); + if (xulParent) xulParent->CreateNewWindow(aChromeFlags, getter_AddRefs(newWindow)); // And if it fails, don't try again without a parent. It could fail @@ -125,10 +157,49 @@ nsWindowCreator::CreateChromeWindow(nsIWebBrowserChrome *aParent, } // if anybody gave us anything to work with, use it - nsCOMPtr thing(do_QueryInterface(newWindow)); - if (thing) - thing->GetInterface(NS_GET_IID(nsIWebBrowserChrome), (void **) _retval); + if (newWindow) { + newWindow->SetContextFlags(aContextFlags); + nsCOMPtr thing(do_QueryInterface(newWindow)); + if (thing) + thing->GetInterface(NS_GET_IID(nsIWebBrowserChrome), (void **) _retval); + } return *_retval ? NS_OK : NS_ERROR_FAILURE; } +PRUint32 +nsWindowCreator::AllowWindowCreation(nsIURI *aURI) +{ + nsCOMPtr pm(do_GetService(NS_POPUPWINDOWMANAGER_CONTRACTID)); + if (!pm) + return nsIPopupWindowManager::eAllow; + + PRUint32 permission; + if (NS_SUCCEEDED(pm->TestPermission(aURI, &permission))) + return permission; + return nsIPopupWindowManager::eAllow; +} + +void +nsWindowCreator::GetParentURI(nsIWebBrowserChrome *aParent, nsIURI **aURI) +{ + if (!aParent) + return; + + nsCOMPtr treeOwner(do_GetInterface(aParent)); + if (treeOwner) { + nsCOMPtr content; + treeOwner->GetPrimaryContentShell(getter_AddRefs(content)); + nsCOMPtr domParent(do_GetInterface(content)); + if (domParent) { + nsCOMPtr location; + domParent->GetLocation(getter_AddRefs(location)); + if (location) { + nsAutoString url; + location->GetHref(url); + NS_NewURI(aURI, url); + } + } + } +} + diff --git a/mozilla/xpfe/bootstrap/nsWindowCreator.h b/mozilla/xpfe/bootstrap/nsWindowCreator.h index 524a6a3a0a1..e9e03e5cd56 100644 --- a/mozilla/xpfe/bootstrap/nsWindowCreator.h +++ b/mozilla/xpfe/bootstrap/nsWindowCreator.h @@ -38,10 +38,12 @@ #ifndef __nsWindowCreator_h_ #define __nsWindowCreator_h_ -#include "nsIWindowCreator.h" +#include "nsIWindowCreator2.h" + +class nsIURI; class nsWindowCreator : - public nsIWindowCreator + public nsIWindowCreator2 { public: nsWindowCreator(); @@ -49,6 +51,11 @@ public: NS_DECL_ISUPPORTS NS_DECL_NSIWINDOWCREATOR + NS_DECL_NSIWINDOWCREATOR2 + +private: + PRUint32 AllowWindowCreation(nsIURI *aURI); + void GetParentURI(nsIWebBrowserChrome *aParent, nsIURI **aURI); }; #endif diff --git a/mozilla/xpfe/components/permissions/content/permissionsNavigatorOverlay.xul b/mozilla/xpfe/components/permissions/content/permissionsNavigatorOverlay.xul index 810bf81bb32..a33585d104c 100644 --- a/mozilla/xpfe/components/permissions/content/permissionsNavigatorOverlay.xul +++ b/mozilla/xpfe/components/permissions/content/permissionsNavigatorOverlay.xul @@ -32,7 +32,10 @@ privacy->cookie->block from java console return; @@ -88,16 +107,42 @@ disableElement.setAttribute("disabled","true"); enableElement.removeAttribute("disabled"); + if (popupmanager.testPermission(getBrowser().currentURI) == Components.interfaces.nsIPopupWindowManager.eDisallow) { + disableElement = document.getElementById("BlockPopups"); + enableElement = document.getElementById("AllowPopups"); + } else { + disableElement = document.getElementById("AllowPopups"); + enableElement = document.getElementById("BlockPopups"); + } + disableElement.setAttribute("disabled","true"); + if (popupmanager.testSuitability(getBrowser().currentURI)) + enableElement.removeAttribute("disabled"); + else + enableElement.setAttribute("disabled","true"); + + var pref; + pref = Components.classes['@mozilla.org/preferences-service;1']; + pref = pref.getService(); + pref = pref.QueryInterface(Components.interfaces.nsIPrefBranch); + + // hide the popup manager menus if the prefs aren't exactly right. + // it'd be nicer to leave it always visible and adjust prefs to match + // any user selections + try { + var hide = pref.getBoolPref("dom.disable_open_during_load"); + if (!hide) + hide = pref.getIntPref("privacy.popups.policy") != Components.interfaces.nsIPopupWindowManager.eAllowConditionally; + HidePopups(hide); + } catch(e) { + HidePopups(true); + } + // determine if image manager should be in the UI if (alreadyCheckedForImage) { return; } alreadyCheckedForImage = true; // remove image functions (unless overruled by the "imageblocker.enabled" pref) - var pref; - pref = Components.classes['@mozilla.org/preferences-service;1']; - pref = pref.getService(); - pref = pref.QueryInterface(Components.interfaces.nsIPrefBranch); try { if (!pref.getBoolPref("imageblocker.enabled")) { HideImage(); @@ -136,6 +181,16 @@ element = document.getElementById("BlockImages"); alert(element.getAttribute("msg")); break; + case "popupAllow": + popupmanager.add(getBrowser().currentURI, true); + element = document.getElementById("AllowPopups"); + alert(element.getAttribute("msg")); + break; + case "popupBlock": + popupmanager.add(getBrowser().currentURI, false); + element = document.getElementById("BlockPopups"); + alert(element.getAttribute("msg")); + break; default: } } @@ -182,5 +237,24 @@ oncommand="viewImages();"/> + + + + + + + + diff --git a/mozilla/xpfe/components/permissions/content/permissionsOverlay.js b/mozilla/xpfe/components/permissions/content/permissionsOverlay.js index 6717c5d5a51..9a1f4a94e5f 100644 --- a/mozilla/xpfe/components/permissions/content/permissionsOverlay.js +++ b/mozilla/xpfe/components/permissions/content/permissionsOverlay.js @@ -20,12 +20,18 @@ var COOKIEPERMISSION = 0; var IMAGEPERMISSION = 1; +var WINDOWPERMISSION = 2; function viewImages() { window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank", "chrome,resizable=yes", "imageManager" ); } +function viewPopups() { + window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank", + "chrome,resizable=yes", "popupManager" ); +} + function viewCookies() { window.openDialog("chrome://communicator/content/wallet/CookieViewer.xul","_blank", "chrome,resizable=yes", "cookieManager");