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
This commit is contained in:
mvl%exedo.nl
2004-02-10 18:22:23 +00:00
parent cd3874a065
commit 94aeeaf580
11 changed files with 112 additions and 16 deletions

View File

@@ -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!

View File

@@ -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);
};

View File

@@ -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<nsIDOMPopupBlockedEvent> 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<nsIDOMEventTarget> 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;

View File

@@ -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();

View File

@@ -250,7 +250,9 @@
<menu label="&cookiePopupManager.label;"
accesskey="&cookiePopupManager.accesskey;"
id="popup"
insertbefore="navBeginGlobalItems">
insertbefore="navBeginGlobalItems"
oncommand="popupBlockerMenuCommand(event.target);"
onpopupshowing="return popupBlockerMenuShowing(event)" >
<menupopup>
<menuitem id="AllowPopups" label="&cookieAllowPopupsCmd.label;"
accesskey="&cookieAllowPopupsCmd.accesskey;"
@@ -263,6 +265,9 @@
accesskey="&cookieManagePopups.accesskey;"
oncommand="OpenManagePopups('');"
hidden="true"/>
<menuseparator id="popupMenuSeparator" hidden="true"/>
<!-- Additional items are generated, see popupBlockerMenuShowing()
in navigator.js -->
</menupopup>
</menu>
</menupopup>

View File

@@ -595,6 +595,7 @@ struct nsPopupBlockedEvent : public nsEvent
nsIURI* mRequestingWindowURI; // owning reference
nsIURI* mPopupWindowURI; // owning reference
nsString mPopupWindowFeatures;
};
/**

View File

@@ -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");

View File

@@ -331,11 +331,20 @@ Contributor(s):
<statusbarpanel class="statusbarpanel-progress" id="progress-panel" hidden="true">
<progressmeter class="progressmeter-statusbar" id="statusbar-icon" mode="normal" value="0"/>
</statusbarpanel>
<statusbarpanel id="popupIcon" class="statusbarpanel-iconic" hidden="true" oncommand="StatusbarViewPopupManager()" tooltiptext="&popupIcon.tooltiptext;"/>
<statusbarpanel id="popupIcon" class="statusbarpanel-iconic" hidden="true"
oncommand="StatusbarViewPopupManager()"
tooltiptext="&popupIcon.tooltiptext;"
context="popupBlockerMenu"/>
<statusbarpanel class="statusbarpanel-iconic" id="offline-status"/>
<statusbarpanel class="statusbarpanel-iconic" id="security-button"
onclick="BrowserPageInfo(null, 'securityTab')"/>
</statusbar>
<popupset>
<menupopup id="popupBlockerMenu"
oncommand="popupBlockerMenuCommand(event.target);"
onpopupshowing="return popupBlockerMenuShowing(event)"/>
<!-- Items are generated, see popupBlockerMenuShowing() -->
</popupset>
<popupset>
<popup id="networkProperties"/>
</popupset>

View File

@@ -331,6 +331,8 @@ nsBrowserStatusHandler.prototype =
if (blank ||
!("popupDomain" in browser)) {
browser.popupDomain = null;
browser.popupUrls = null;
browser.popupFeatures = null;
}
else {
var hostPort = "";
@@ -338,8 +340,11 @@ nsBrowserStatusHandler.prototype =
hostPort = locationURI.hostPort;
}
catch(ex) { }
if (hostPort != browser.popupDomain)
if (hostPort != browser.popupDomain) {
browser.popupDomain = null;
browser.popupUrls = null;
browser.popupFeatures = null;
}
}
var popupIcon = document.getElementById("popupIcon");

View File

@@ -79,3 +79,5 @@ searchFor=Search %S for "%S"
# For JVM Configuration
switchJVMTitle=Select Java version
switchJVMFailed=Failed to select this version of java
popupMenuShow=Show %S

View File

@@ -250,7 +250,9 @@
<menu label="&cookiePopupManager.label;"
accesskey="&cookiePopupManager.accesskey;"
id="popup"
insertbefore="navBeginGlobalItems">
insertbefore="navBeginGlobalItems"
oncommand="popupBlockerMenuCommand(event.target);"
onpopupshowing="return popupBlockerMenuShowing(event)" >
<menupopup>
<menuitem id="AllowPopups" label="&cookieAllowPopupsCmd.label;"
accesskey="&cookieAllowPopupsCmd.accesskey;"
@@ -263,6 +265,9 @@
accesskey="&cookieManagePopups.accesskey;"
oncommand="OpenManagePopups('');"
hidden="true"/>
<menuseparator id="popupMenuSeparator" hidden="true"/>
<!-- Additional items are generated, see popupBlockerMenuShowing()
in navigator.js -->
</menupopup>
</menu>
</menupopup>