From 459e7e42773b59790aad78a7a77b4b7ee949a93a Mon Sep 17 00:00:00 2001 From: "shliang%netscape.com" Date: Wed, 26 Mar 2003 02:03:13 +0000 Subject: [PATCH] 195924, 195921, 195928 - popup blocking changes to use whitelisting only and provide info dlg when popup first encountered. r=danm, sr=jag. --- dom/src/base/nsGlobalWindow.cpp | 84 ++++++---- .../content/cookieNavigatorOverlay.xul | 68 ++++---- .../cookie/resources/content/cookieOverlay.js | 6 - .../resources/content/cookiePrefsOverlay.xul | 2 +- .../cookie/resources/content/pref-popups.xul | 149 +++++++++++------- .../locale/en-US/cookieNavigatorOverlay.dtd | 12 +- .../resources/locale/en-US/pref-popups.dtd | 22 ++- modules/libpref/src/init/all.js | 4 +- themes/classic/jar.mn | 1 + .../classic/navigator/icons/about-popups.gif | 0 themes/classic/navigator/navigator.css | 5 + themes/modern/jar.mn | 1 + .../modern/navigator/icons/about-popups.gif | 0 themes/modern/navigator/navigator.css | 5 + xpfe/browser/resources/content/navigator.js | 82 +++++++--- xpfe/communicator/jar.mn | 2 + .../resources/content/aboutPopups.xul | 108 +++++++++++++ .../resources/content/popupManager.js | 145 +++++++---------- .../resources/content/popupManager.xul | 7 +- .../resources/locale/en-US/aboutPopups.dtd | 0 .../resources/locale/en-US/popupManager.dtd | 16 -- .../locale/en-US/popupManager.properties | 4 - .../permissions/content/aboutPopups.xul | 108 +++++++++++++ .../permissions/content/permissionsManager.js | 145 +++++++---------- .../content/permissionsManager.xul | 7 +- .../content/permissionsNavigatorOverlay.xul | 68 ++++---- .../permissions/content/permissionsOverlay.js | 6 - .../permissions/locale/en-US/aboutPopups.dtd | 0 .../locale/en-US/permissionsManager.dtd | 6 +- .../en-US/permissionsManager.properties | 2 - .../en-US/permissionsNavigatorOverlay.dtd | 12 +- .../resources/content/cookiePrefsOverlay.xul | 2 +- .../content/permissionsPrefsOverlay.xul | 2 +- .../prefwindow/resources/content/pref-help.js | 2 +- .../resources/content/pref-popups.xul | 149 +++++++++++------- .../resources/locale/en-US/pref-popups.dtd | 22 ++- 36 files changed, 753 insertions(+), 501 deletions(-) create mode 100644 themes/classic/navigator/icons/about-popups.gif create mode 100644 themes/modern/navigator/icons/about-popups.gif create mode 100644 xpfe/communicator/resources/content/aboutPopups.xul create mode 100644 xpfe/communicator/resources/locale/en-US/aboutPopups.dtd create mode 100644 xpfe/components/permissions/content/aboutPopups.xul create mode 100644 xpfe/components/permissions/locale/en-US/aboutPopups.dtd 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; + + +