From 94aeeaf580b751a7afc8a6f5a9d24cc9eaa7772f Mon Sep 17 00:00:00 2001 From: "mvl%exedo.nl" Date: Tue, 10 Feb 2004 18:22:23 +0000 Subject: [PATCH] Add a way to manually show a single blocked pop-up window. Pass the features of the window.open() call in DOMPopupBlockedEvent. Bug 198846, r=danm, sr=jag git-svn-id: svn://10.0.0.236/trunk@152603 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/events/src/nsDOMEvent.cpp | 16 ++++++- .../idl/events/nsIDOMPopupBlockedEvent.idl | 9 +++- mozilla/dom/src/base/nsGlobalWindow.cpp | 18 +++---- mozilla/dom/src/base/nsGlobalWindow.h | 3 +- .../content/cookieNavigatorOverlay.xul | 7 ++- mozilla/widget/public/nsGUIEvent.h | 1 + .../browser/resources/content/navigator.js | 47 ++++++++++++++++++- .../browser/resources/content/navigator.xul | 11 ++++- .../content/nsBrowserStatusHandler.js | 7 ++- .../locale/en-US/navigator.properties | 2 + .../content/permissionsNavigatorOverlay.xul | 7 ++- 11 files changed, 112 insertions(+), 16 deletions(-) diff --git a/mozilla/content/events/src/nsDOMEvent.cpp b/mozilla/content/events/src/nsDOMEvent.cpp index 498eb7f5109..c4dca04e708 100644 --- a/mozilla/content/events/src/nsDOMEvent.cpp +++ b/mozilla/content/events/src/nsDOMEvent.cpp @@ -1347,7 +1347,8 @@ nsDOMEvent::InitKeyEvent(const nsAString& aTypeArg, PRBool aCanBubbleArg, PRBool NS_IMETHODIMP nsDOMEvent::InitPopupBlockedEvent(const nsAString & aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIURI *aRequestingWindowURI, - nsIURI *aPopupWindowURI) + nsIURI *aPopupWindowURI, + const nsAString & aPopupWindowFeatures) { NS_ENSURE_SUCCESS(SetEventType(aTypeArg), NS_ERROR_FAILURE); mEvent->flags |= aCanBubbleArg ? NS_EVENT_FLAG_NONE : NS_EVENT_FLAG_CANT_BUBBLE; @@ -1361,6 +1362,7 @@ NS_IMETHODIMP nsDOMEvent::InitPopupBlockedEvent(const nsAString & aTypeArg, event->mPopupWindowURI = aPopupWindowURI; NS_IF_ADDREF(event->mRequestingWindowURI); NS_IF_ADDREF(event->mPopupWindowURI); + event->mPopupWindowFeatures = aPopupWindowFeatures; return NS_OK; } @@ -1395,6 +1397,18 @@ NS_IMETHODIMP nsDOMEvent::GetPopupWindowURI(nsIURI **aPopupWindowURI) return NS_OK; // Don't throw an exception } +/* readonly attribute DOMString popupFeatures; */ +NS_IMETHODIMP nsDOMEvent::GetPopupWindowFeatures(nsAString &aPopupWindowFeatures) +{ + if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) { + nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent); + aPopupWindowFeatures = event->mPopupWindowFeatures; + return NS_OK; + } + aPopupWindowFeatures.Truncate(); + return NS_OK; // Don't throw an exception +} + NS_METHOD nsDOMEvent::DuplicatePrivateData() { //XXX Write me! diff --git a/mozilla/dom/public/idl/events/nsIDOMPopupBlockedEvent.idl b/mozilla/dom/public/idl/events/nsIDOMPopupBlockedEvent.idl index 0fd343da2a4..131774f1e1a 100644 --- a/mozilla/dom/public/idl/events/nsIDOMPopupBlockedEvent.idl +++ b/mozilla/dom/public/idl/events/nsIDOMPopupBlockedEvent.idl @@ -50,9 +50,16 @@ interface nsIDOMPopupBlockedEvent : nsIDOMEvent readonly attribute nsIURI requestingWindowURI; readonly attribute nsIURI popupWindowURI; + /** + * The string of features passed to the window.open() call + * (as the third argument) + */ + readonly attribute DOMString popupWindowFeatures; + void initPopupBlockedEvent(in DOMString typeArg, in boolean canBubbleArg, in boolean cancelableArg, in nsIURI requestingWindowURI, - in nsIURI popupWindowURI); + in nsIURI popupWindowURI, + in DOMString popupWindowFeatures); }; diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index cacd2940404..843bea89a67 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -2946,7 +2946,8 @@ PRBool IsPopupBlocked(nsIDOMDocument* aDoc) static void FirePopupBlockedEvent(nsIDOMDocument* aDoc, - nsIURI *aRequestingURI, nsIURI *aPopupURI) + nsIURI *aRequestingURI, nsIURI *aPopupURI, + const nsAString &aPopupWindowFeatures) { if (aDoc) { // Fire a "DOMPopupBlocked" event so that the UI can hear about blocked popups. @@ -2956,7 +2957,7 @@ void FirePopupBlockedEvent(nsIDOMDocument* aDoc, if (event) { nsCOMPtr pbev(do_QueryInterface(event)); pbev->InitPopupBlockedEvent(NS_LITERAL_STRING("DOMPopupBlocked"), - PR_TRUE, PR_TRUE, aRequestingURI, aPopupURI); + PR_TRUE, PR_TRUE, aRequestingURI, aPopupURI, aPopupWindowFeatures); PRBool noDefault; nsCOMPtr targ(do_QueryInterface(aDoc)); targ->DispatchEvent(event, &noDefault); @@ -3222,7 +3223,8 @@ PRBool GlobalWindowImpl::CheckOpenAllow(PRUint32 aAbuseLevel, */ void GlobalWindowImpl::FireAbuseEvents(PRBool aBlocked, PRBool aWindow, - const nsAString &aPopupURL) + const nsAString &aPopupURL, + const nsAString &aPopupWindowFeatures) { // fetch the URI of the window requesting the opened window @@ -3276,7 +3278,7 @@ GlobalWindowImpl::FireAbuseEvents(PRBool aBlocked, PRBool aWindow, // fire an event chock full of informative URIs if (aBlocked) - FirePopupBlockedEvent(topDoc, requestingURI, popupURI); + FirePopupBlockedEvent(topDoc, requestingURI, popupURI, aPopupWindowFeatures); if (aWindow) FirePopupWindowEvent(topDoc); } @@ -3291,7 +3293,7 @@ GlobalWindowImpl::Open(const nsAString& aUrl, PRUint32 abuseLevel = CheckForAbusePoint(); if (!CheckOpenAllow(abuseLevel, aName)) { - FireAbuseEvents(PR_TRUE, PR_FALSE, aUrl); + FireAbuseEvents(PR_TRUE, PR_FALSE, aUrl, aOptions); return NS_ERROR_FAILURE; // unlike the public Open method, return an error } @@ -3306,7 +3308,7 @@ GlobalWindowImpl::Open(const nsAString& aUrl, } } if (abuseLevel >= openAbused) - FireAbuseEvents(PR_FALSE, PR_TRUE, aUrl); + FireAbuseEvents(PR_FALSE, PR_TRUE, aUrl, aOptions); } return rv; } @@ -3354,7 +3356,7 @@ GlobalWindowImpl::Open(nsIDOMWindow **_retval) PRUint32 abuseLevel = CheckForAbusePoint(); if (!CheckOpenAllow(abuseLevel, name)) { - FireAbuseEvents(PR_TRUE, PR_FALSE, url); + FireAbuseEvents(PR_TRUE, PR_FALSE, url, options); return NS_OK; // don't open the window, but also don't throw a JS exception } @@ -3393,7 +3395,7 @@ GlobalWindowImpl::Open(nsIDOMWindow **_retval) } } if (abuseLevel >= openAbused) - FireAbuseEvents(PR_FALSE, PR_TRUE, url); + FireAbuseEvents(PR_FALSE, PR_TRUE, url, options); } return rv; diff --git a/mozilla/dom/src/base/nsGlobalWindow.h b/mozilla/dom/src/base/nsGlobalWindow.h index 68c160c93d0..5afcdf9411b 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.h +++ b/mozilla/dom/src/base/nsGlobalWindow.h @@ -249,7 +249,8 @@ protected: PRUint32 CheckForAbusePoint(); PRBool CheckOpenAllow(PRUint32 aAbuseLevel, const nsAString &aName); void FireAbuseEvents(PRBool aBlocked, PRBool aWindow, - const nsAString &aPopupURL); + const nsAString &aPopupURL, + const nsAString &aPopupWindowFeatures); void FlushPendingNotifications(PRBool aFlushReflows); void EnsureReflowFlushAndPaint(); diff --git a/mozilla/extensions/cookie/resources/content/cookieNavigatorOverlay.xul b/mozilla/extensions/cookie/resources/content/cookieNavigatorOverlay.xul index 2638ab93508..a90a257c74f 100644 --- a/mozilla/extensions/cookie/resources/content/cookieNavigatorOverlay.xul +++ b/mozilla/extensions/cookie/resources/content/cookieNavigatorOverlay.xul @@ -250,7 +250,9 @@ + insertbefore="navBeginGlobalItems" + oncommand="popupBlockerMenuCommand(event.target);" + onpopupshowing="return popupBlockerMenuShowing(event)" > diff --git a/mozilla/widget/public/nsGUIEvent.h b/mozilla/widget/public/nsGUIEvent.h index 41d1783a3bf..676236a1e26 100644 --- a/mozilla/widget/public/nsGUIEvent.h +++ b/mozilla/widget/public/nsGUIEvent.h @@ -595,6 +595,7 @@ struct nsPopupBlockedEvent : public nsEvent nsIURI* mRequestingWindowURI; // owning reference nsIURI* mPopupWindowURI; // owning reference + nsString mPopupWindowFeatures; }; /** diff --git a/mozilla/xpfe/browser/resources/content/navigator.js b/mozilla/xpfe/browser/resources/content/navigator.js index fd20f40b1aa..d79af806f49 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.js +++ b/mozilla/xpfe/browser/resources/content/navigator.js @@ -2151,7 +2151,13 @@ function onPopupBlocked(aEvent) { if (browser == getBrowser().selectedBrowser) { var popupIcon = document.getElementById("popupIcon"); popupIcon.hidden = false; - } + } + if (!browser.popupUrls) { + browser.popupUrls = []; + browser.popupFeatures = []; + } + browser.popupUrls.push(aEvent.popupWindowURI); + browser.popupFeatures.push(aEvent.popupWindowFeatures); } } } @@ -2177,6 +2183,45 @@ function StatusbarViewPopupManager() { "chrome,resizable=yes", hostPort); } +function popupBlockerMenuShowing(event) { + var parent = event.target; + var browser = getBrowser().selectedBrowser; + var separator = document.getElementById("popupMenuSeparator"); + + if ("popupDomain" in browser) { + createShowPopupsMenu(parent); + if (separator) + separator.hidden = false; + } else { + if (separator) + separator.hidden = true; + } +} + +function createShowPopupsMenu(parent) { + while (parent.lastChild && parent.lastChild.hasAttribute("uri")) + parent.removeChild(parent.lastChild); + + var browser = getBrowser().selectedBrowser; + + for (var i = 0; i < browser.popupUrls.length; i++) { + var menuitem = document.createElement("menuitem"); + menuitem.setAttribute("label", gNavigatorBundle.getFormattedString('popupMenuShow', [browser.popupUrls[i].spec])); + menuitem.setAttribute("uri", browser.popupUrls[i].spec); + menuitem.setAttribute("features", browser.popupFeatures[i]); + parent.appendChild(menuitem); + } + + return true; +} + +function popupBlockerMenuCommand(target) { + var uri = target.getAttribute("uri"); + if (uri) { + window.open(uri, "", target.getAttribute("features")); + } +} + function toHistory() { toOpenWindowByType("history:manager", "chrome://communicator/content/history/history.xul"); diff --git a/mozilla/xpfe/browser/resources/content/navigator.xul b/mozilla/xpfe/browser/resources/content/navigator.xul index ade104610bd..5cafb70c7df 100644 --- a/mozilla/xpfe/browser/resources/content/navigator.xul +++ b/mozilla/xpfe/browser/resources/content/navigator.xul @@ -331,11 +331,20 @@ Contributor(s): -