diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index 25a31cb06b1..054b51634cc 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -2829,6 +2829,22 @@ void FirePopupBlockedEvent(nsIDOMDocument* aDoc) } } +void FirePopupWindowEvent(nsIDOMDocument* aDoc) +{ + if (aDoc) { + // Fire a "PopupWindow" event + nsCOMPtr docEvent(do_QueryInterface(aDoc)); + nsCOMPtr event; + docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); + if (event) { + event->InitEvent(NS_LITERAL_STRING("PopupWindow"), PR_TRUE, PR_TRUE); + PRBool noDefault; + nsCOMPtr targ(do_QueryInterface(aDoc)); + targ->DispatchEvent(event, &noDefault); + } + } +} + // static PRBool GlobalWindowImpl::CanSetProperty(const char *aPrefName) @@ -2870,7 +2886,7 @@ GlobalWindowImpl::CheckForAbusePoint () } if (!mIsDocumentLoaded || mRunningTimeout) { - return IsPopupBlocked(mDocument); + return PR_TRUE; } PRInt32 clickDelay = 0; @@ -2883,7 +2899,7 @@ GlobalWindowImpl::CheckForAbusePoint () LL_L2I(delta, ll_delta); delta /= 1000; if (delta > clickDelay) { - return IsPopupBlocked(mDocument); + return PR_TRUE; } } @@ -2945,31 +2961,40 @@ GlobalWindowImpl::Open(nsIDOMWindow **_retval) * If we're in a commonly abused state (top level script, running a timeout, * or onload/onunload), and the preference is enabled, prevent window.open(). */ - if (CheckForAbusePoint()) { - if (name.IsEmpty()) { - FirePopupBlockedEvent(mDocument); - return NS_OK; - } + PRBool abusedWindow = CheckForAbusePoint(); + + nsCOMPtr topWindow; + GetTop(getter_AddRefs(topWindow)); + nsCOMPtr topDoc; + topWindow->GetDocument(getter_AddRefs(topDoc)); - // Special case items that don't actually open new windows. - if (!name.EqualsIgnoreCase("_top") && - !name.EqualsIgnoreCase("_self") && - !name.EqualsIgnoreCase("_content")) { - - nsCOMPtr wwatch = - do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); - // If getting a window watcher fails, we'd fail downstream anyway - // when trying to open a new window so just bail here. - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr namedWindow; - wwatch->GetWindowByName(name.get(), this, - getter_AddRefs(namedWindow)); - - if (!namedWindow) { - FirePopupBlockedEvent(mDocument); + if (abusedWindow) { + if (IsPopupBlocked(mDocument)) { + if (name.IsEmpty()) { + FirePopupBlockedEvent(topDoc); return NS_OK; } + + // Special case items that don't actually open new windows. + if (!name.EqualsIgnoreCase("_top") && + !name.EqualsIgnoreCase("_self") && + !name.EqualsIgnoreCase("_content")) { + + nsCOMPtr wwatch = + do_GetService(NS_WINDOWWATCHER_CONTRACTID, &rv); + // If getting a window watcher fails, we'd fail downstream anyway + // when trying to open a new window so just bail here. + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr namedWindow; + wwatch->GetWindowByName(name.get(), this, + getter_AddRefs(namedWindow)); + + if (!namedWindow) { + FirePopupBlockedEvent(topDoc); + return NS_OK; + } + } } } @@ -2977,7 +3002,8 @@ GlobalWindowImpl::Open(nsIDOMWindow **_retval) nsCOMPtr chrome_win(do_QueryInterface(*_retval)); - if (NS_SUCCEEDED(rv) && !chrome_win) { + if (NS_SUCCEEDED(rv)) { + if (!chrome_win) { // A new non-chrome window was created from a call to // window.open() from JavaScript, make sure there's a document in // the new window. We do this by simply asking the new window for @@ -2995,8 +3021,12 @@ GlobalWindowImpl::Open(nsIDOMWindow **_retval) } #endif - nsCOMPtr doc; - (*_retval)->GetDocument(getter_AddRefs(doc)); + nsCOMPtr doc; + (*_retval)->GetDocument(getter_AddRefs(doc)); + } + + if (abusedWindow) + FirePopupWindowEvent(topDoc); } return rv; diff --git a/extensions/cookie/resources/content/cookieNavigatorOverlay.xul b/extensions/cookie/resources/content/cookieNavigatorOverlay.xul index 6b04076820f..e2fdc410297 100644 --- a/extensions/cookie/resources/content/cookieNavigatorOverlay.xul +++ b/extensions/cookie/resources/content/cookieNavigatorOverlay.xul @@ -110,10 +110,16 @@ var policy = pref.getBoolPref("dom.disable_open_during_load"); blocked = permissionmanager.testPermission(getBrowser().currentURI, nsIPermissionManager.POPUP_TYPE); + + document.getElementById("AboutPopups").hidden = policy; + document.getElementById("ManagePopups").hidden = !policy; - enableElement("BlockPopups", blocked != nsIPermissionManager.DENY_ACTION); - enableElement("AllowPopups", blocked != nsIPermissionManager.ALLOW_ACTION); - enableElement("ManagePopups", true); + if (policy) { + enableElement("AllowPopups", blocked != nsIPermissionManager.ALLOW_ACTION); + return; + } + + enableElement("AllowPopups", false); } function enableElement(elementID, enable) { @@ -158,32 +164,23 @@ } } - function PopupAction(action) { - var policy = pref.getBoolPref("dom.disable_open_during_load"); - var uri = getBrowser().currentURI; - - switch (action) { - case "block": - permissionmanager.add(uri, nsIPermissionManager.POPUP_TYPE, nsIPermissionManager.DENY_ACTION); - break; - case "allow": - var browsers = getBrowser().browsers; - var popupIcon = document.getElementById("popupIcon"); - permissionmanager.add(uri, nsIPermissionManager.POPUP_TYPE, nsIPermissionManager.ALLOW_ACTION); - for (var i = 0; i < browsers.length; i++) { - if (browsers[i].popupDomain == uri.host) { - browsers[i].popupDomain = null; - popupIcon.hidden = true; - } - } - break; - } + function PopupAction() { + var hostPort = getBrowser().currentURI.hostPort; + window.openDialog("chrome://communicator/content/popupManager.xul", "", + "chrome,resizable=yes,modal=yes", + hostPort, + false); } - function ViewPopupManager() { + function OpenAboutPopups() { + window.openDialog("chrome://communicator/content/aboutPopups.xul", "", + "chrome,centerscreen,resizable=yes", + false); + } + + function OpenManagePopups() { window.openDialog("chrome://communicator/content/popupManager.xul", "", - "chrome,resizable=yes,modal=yes", - pref.getBoolPref("dom.disable_open_during_load"), + "chrome,resizable=yes", "", false); } @@ -235,18 +232,17 @@ id="popup" insertbefore="navBeginGlobalItems"> - - - + oncommand="PopupAction();"/> + diff --git a/extensions/cookie/resources/content/cookieOverlay.js b/extensions/cookie/resources/content/cookieOverlay.js index 9a1f4a94e5f..6717c5d5a51 100644 --- a/extensions/cookie/resources/content/cookieOverlay.js +++ b/extensions/cookie/resources/content/cookieOverlay.js @@ -20,18 +20,12 @@ 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/extensions/cookie/resources/content/cookiePrefsOverlay.xul b/extensions/cookie/resources/content/cookiePrefsOverlay.xul index 9dbd2f86313..1ed3f538485 100644 --- a/extensions/cookie/resources/content/cookiePrefsOverlay.xul +++ b/extensions/cookie/resources/content/cookiePrefsOverlay.xul @@ -40,7 +40,7 @@ label="&images.label;"/> - + diff --git a/extensions/cookie/resources/content/pref-popups.xul b/extensions/cookie/resources/content/pref-popups.xul index fea8f175314..a5ec2b67982 100644 --- a/extensions/cookie/resources/content/pref-popups.xul +++ b/extensions/cookie/resources/content/pref-popups.xul @@ -48,37 +48,75 @@ onload="init()" headertitle="&title;"> - + + + + &popupDesc.label; + &popupDescAlt.label; + + + + &popupNote1.label; + + &popupNote2.label; + + +