This commit is contained in:
jst%mozilla.org 2007-01-13 01:08:43 +00:00
Родитель c3d2420f97
Коммит b6e35b8cde
7 изменённых файлов: 57 добавлений и 70 удалений

Просмотреть файл

@ -529,14 +529,12 @@ const gPopupBlockerObserver = {
var label = bundle_browser.getFormattedString("popupShowPopupPrefix",
[popupURIspec]);
menuitem.setAttribute("label", label);
menuitem.setAttribute("requestingWindowURI", pageReport[i].requestingWindowURI.spec);
menuitem.setAttribute("popupWindowURI", popupURIspec);
menuitem.setAttribute("popupWindowFeatures", pageReport[i].popupWindowFeatures);
#ifndef MOZILLA_1_8_BRANCH
# bug 314700
menuitem.setAttribute("popupWindowName", pageReport[i].popupWindowName);
#endif
menuitem.setAttribute("oncommand", "gPopupBlockerObserver.showBlockedPopup(event);");
menuitem.requestingWindow = pageReport[i].requestingWindow;
menuitem.requestingDocument = pageReport[i].requestingDocument;
aEvent.target.appendChild(menuitem);
}
}
@ -561,30 +559,17 @@ const gPopupBlockerObserver = {
showBlockedPopup: function (aEvent)
{
var requestingWindow = aEvent.target.getAttribute("requestingWindowURI");
var requestingWindowURI =
Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService)
.newURI(requestingWindow, null, null);
var target = aEvent.target;
var popupWindowURI = target.getAttribute("popupWindowURI");
var features = target.getAttribute("popupWindowFeatures");
var name = target.getAttribute("popupWindowName");
var popupWindowURI = aEvent.target.getAttribute("popupWindowURI");
var features = aEvent.target.getAttribute("popupWindowFeatures");
#ifndef MOZILLA_1_8_BRANCH
# bug 314700
var name = aEvent.target.getAttribute("popupWindowName");
#endif
var dwi = target.requestingWindow;
var shell = findChildShell(null, gBrowser.selectedBrowser.docShell,
requestingWindowURI);
if (shell) {
var ifr = shell.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var dwi = ifr.getInterface(Components.interfaces.nsIDOMWindowInternal);
#ifdef MOZILLA_1_8_BRANCH
# bug 314700
dwi.open(popupWindowURI, "", features);
#else
// If we have a requesting window and the requesting document is
// still the current document, open the popup.
if (dwi && dwi.document == target.requestingDocument) {
dwi.open(popupWindowURI, name, features);
#endif
}
},

Просмотреть файл

@ -1912,9 +1912,10 @@ enum BWCOpenDest {
- (void)whitelistAndShowPopup:(nsIDOMPopupBlockedEvent*)aPopupBlockedEvent
{
nsCOMPtr<nsIDOMWindow> requestingWindow;
aPopupBlockedEvent->GetRequestingWindow(getter_AddRefs(requestingWindow));
// get the URIs for the popup window, and it's parent document
nsCOMPtr<nsIURI> requestingWindowURI, popupWindowURI;
aPopupBlockedEvent->GetRequestingWindowURI(getter_AddRefs(requestingWindowURI));
nsCOMPtr<nsIURI> popupWindowURI;
aPopupBlockedEvent->GetPopupWindowURI(getter_AddRefs(popupWindowURI));
nsAutoString windowName, features;
@ -1930,15 +1931,10 @@ enum BWCOpenDest {
#endif
// find the docshell for the blocked popup window, in order to show it
nsCOMPtr<nsIDocShell> popupWinDocShell = [[mBrowserView getBrowserView] findDocShellForURI:requestingWindowURI];
if (!popupWinDocShell)
if (!requestingWindow)
return;
nsCOMPtr<nsIDOMWindowInternal> domWin = do_GetInterface(popupWinDocShell);
if (!domWin)
return;
nsCOMPtr<nsPIDOMWindow> piDomWin = do_QueryInterface(domWin);
nsCOMPtr<nsPIDOMWindow> piDomWin = do_QueryInterface(requestingWindow);
if (!piDomWin)
return;

Просмотреть файл

@ -62,7 +62,6 @@ nsDOMPopupBlockedEvent::~nsDOMPopupBlockedEvent()
if (mEventIsInternal) {
if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) {
nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent);
NS_IF_RELEASE(event->mRequestingWindowURI);
NS_IF_RELEASE(event->mPopupWindowURI);
}
}
@ -79,7 +78,7 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
NS_IMETHODIMP
nsDOMPopupBlockedEvent::InitPopupBlockedEvent(const nsAString & aTypeArg,
PRBool aCanBubbleArg, PRBool aCancelableArg,
nsIURI *aRequestingWindowURI,
nsIDOMWindow *aRequestingWindow,
nsIURI *aPopupWindowURI,
const nsAString & aPopupWindowName,
const nsAString & aPopupWindowFeatures)
@ -92,9 +91,8 @@ nsDOMPopupBlockedEvent::InitPopupBlockedEvent(const nsAString & aTypeArg,
case NS_POPUPBLOCKED_EVENT:
{
nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent);
event->mRequestingWindowURI = aRequestingWindowURI;
event->mRequestingWindow = do_GetWeakReference(aRequestingWindow);
event->mPopupWindowURI = aPopupWindowURI;
NS_IF_ADDREF(event->mRequestingWindowURI);
NS_IF_ADDREF(event->mPopupWindowURI);
event->mPopupWindowFeatures = aPopupWindowFeatures;
event->mPopupWindowName = aPopupWindowName;
@ -108,16 +106,15 @@ nsDOMPopupBlockedEvent::InitPopupBlockedEvent(const nsAString & aTypeArg,
}
NS_IMETHODIMP
nsDOMPopupBlockedEvent::GetRequestingWindowURI(nsIURI **aRequestingWindowURI)
nsDOMPopupBlockedEvent::GetRequestingWindow(nsIDOMWindow **aRequestingWindow)
{
NS_ENSURE_ARG_POINTER(aRequestingWindowURI);
if (mEvent->eventStructType == NS_POPUPBLOCKED_EVENT) {
nsPopupBlockedEvent* event = NS_STATIC_CAST(nsPopupBlockedEvent*, mEvent);
*aRequestingWindowURI = event->mRequestingWindowURI;
NS_IF_ADDREF(*aRequestingWindowURI);
return NS_OK;
CallQueryReferent(event->mRequestingWindow.get(), aRequestingWindow);
} else {
*aRequestingWindow = 0;
}
*aRequestingWindowURI = 0;
return NS_OK; // Don't throw an exception
}

Просмотреть файл

@ -44,10 +44,19 @@ interface nsIURI;
* posted when a popup window is blocked.
*/
[scriptable, uuid(bb57e9bb-0c89-459c-977d-5cbc1831bdf5)]
[scriptable, uuid(05be571f-c3ea-4959-a340-c57b1591ae4b)]
interface nsIDOMPopupBlockedEvent : nsIDOMEvent
{
readonly attribute nsIURI requestingWindowURI;
/**
* The window object that attempted to open the blocked popup
* (i.e. the window object on which open() was called).
*/
readonly attribute nsIDOMWindow requestingWindow;
/**
* The URI of the window that was blocked.
*/
readonly attribute nsIURI popupWindowURI;
/**
@ -65,7 +74,7 @@ interface nsIDOMPopupBlockedEvent : nsIDOMEvent
void initPopupBlockedEvent(in DOMString typeArg,
in boolean canBubbleArg,
in boolean cancelableArg,
in nsIURI requestingWindowURI,
in nsIDOMWindow requestingWindow,
in nsIURI popupWindowURI,
in DOMString popupWindowName,
in DOMString popupWindowFeatures);

Просмотреть файл

@ -4235,19 +4235,23 @@ PRBool IsPopupBlocked(nsIDOMDocument* aDoc)
static
void FirePopupBlockedEvent(nsIDOMDocument* aDoc,
nsIURI *aRequestingURI, nsIURI *aPopupURI,
nsIDOMWindow *aRequestingWindow, nsIURI *aPopupURI,
const nsAString &aPopupWindowName,
const nsAString &aPopupWindowFeatures)
{
if (aDoc) {
// Fire a "DOMPopupBlocked" event so that the UI can hear about blocked popups.
// Fire a "DOMPopupBlocked" event so that the UI can hear about
// blocked popups.
nsCOMPtr<nsIDOMDocumentEvent> docEvent(do_QueryInterface(aDoc));
nsCOMPtr<nsIDOMEvent> event;
docEvent->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"), getter_AddRefs(event));
docEvent->CreateEvent(NS_LITERAL_STRING("PopupBlockedEvents"),
getter_AddRefs(event));
if (event) {
nsCOMPtr<nsIDOMPopupBlockedEvent> pbev(do_QueryInterface(event));
pbev->InitPopupBlockedEvent(NS_LITERAL_STRING("DOMPopupBlocked"),
PR_TRUE, PR_TRUE, aRequestingURI, aPopupURI, aPopupWindowName, aPopupWindowFeatures);
PR_TRUE, PR_TRUE, aRequestingWindow,
aPopupURI, aPopupWindowName,
aPopupWindowFeatures);
nsCOMPtr<nsIPrivateDOMEvent> privateEvent(do_QueryInterface(event));
privateEvent->SetTrusted(PR_TRUE);
@ -4373,12 +4377,7 @@ nsGlobalWindow::FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
nsCOMPtr<nsIDOMDocument> topDoc;
topWindow->GetDocument(getter_AddRefs(topDoc));
nsCOMPtr<nsIURI> requestingURI;
nsCOMPtr<nsIURI> popupURI;
nsCOMPtr<nsIWebNavigation> webNav =
do_GetInterface((nsIScriptGlobalObject *)this);
if (webNav)
webNav->GetCurrentURI(getter_AddRefs(requestingURI));
// build the URI of the would-have-been popup window
// (see nsWindowWatcher::URIfromURL)
@ -4416,7 +4415,8 @@ nsGlobalWindow::FireAbuseEvents(PRBool aBlocked, PRBool aWindow,
// fire an event chock full of informative URIs
if (aBlocked)
FirePopupBlockedEvent(topDoc, requestingURI, popupURI, aPopupWindowName, aPopupWindowFeatures);
FirePopupBlockedEvent(topDoc, this, popupURI, aPopupWindowName,
aPopupWindowFeatures);
if (aWindow)
FirePopupWindowEvent(topDoc);
}

Просмотреть файл

@ -424,8 +424,10 @@
if (this.pageReport) {
var i = 0;
while (i < this.pageReport.length) {
if (this.findChildShell(this.docShell,
this.pageReport[i].requestingWindowURI))
// Filter out irrelevant reports.
if (this.pageReport[i].requestingWindow &&
(this.pageReport[i].requestingWindow.document ==
this.pageReport[i].requestingDocument))
i++;
else
this.pageReport.splice(i, 1);
@ -481,20 +483,17 @@
this.pageReport = new Array();
}
#ifdef MOZILLA_1_8_BRANCH
# bug 314700
var obj = { requestingWindowURI: evt.requestingWindowURI,
popupWindowURI: evt.popupWindowURI,
popupWindowFeatures: evt.popupWindowFeatures };
#else
var obj = { requestingWindowURI: evt.requestingWindowURI,
var obj = { requestingWindow: evt.requestingWindow,
// Record the current document in the requesting window
// before it can change.
requestingDocument: evt.requestingWindow.document,
popupWindowURI: evt.popupWindowURI,
popupWindowFeatures: evt.popupWindowFeatures,
popupWindowName: evt.popupWindowName };
#endif
this.pageReport.push(obj);
this.pageReport.reported = false;
this.updatePageReport()
this.updatePageReport();
]]>
</body>
</method>

Просмотреть файл

@ -54,6 +54,7 @@
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsIDOMKeyEvent.h"
#include "nsWeakPtr.h"
class nsIRenderingContext;
class nsIRegion;
@ -885,11 +886,11 @@ class nsPopupBlockedEvent : public nsEvent
public:
nsPopupBlockedEvent(PRBool isTrusted, PRUint32 msg)
: nsEvent(isTrusted, msg, NS_POPUPBLOCKED_EVENT),
mRequestingWindowURI(nsnull), mPopupWindowURI(nsnull)
mPopupWindowURI(nsnull)
{
}
nsIURI* mRequestingWindowURI; // owning reference
nsWeakPtr mRequestingWindow;
nsIURI* mPopupWindowURI; // owning reference
nsString mPopupWindowFeatures;
nsString mPopupWindowName;