From 7bfc89b66db7bd681ae007e05d2f424b9efefe96 Mon Sep 17 00:00:00 2001 From: "jst%mozilla.jstenback.com" Date: Thu, 28 Oct 2004 00:36:30 +0000 Subject: [PATCH] Fixing part of bug 265790 (the part that's a regression from bug 265921). Make it possible to flag DOM events as trusted when created using DOM APIs from native code, and marking the DOMWindowClose event (and a few other fired from nsGlobalWindow) as trusted to make closing a tab from script close the tab only, and not the whole window. r+sr=bzbarsky@mit.edu, a=chofmann@mozilla.org git-svn-id: svn://10.0.0.236/trunk@164533 18797224-902f-48f8-a5cc-f745e15eee43 --- .../events/src/nsEventStateManager.cpp | 26 +++++++++++++------ mozilla/dom/src/base/nsGlobalWindow.cpp | 14 ++++++++++ 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/mozilla/content/events/src/nsEventStateManager.cpp b/mozilla/content/events/src/nsEventStateManager.cpp index bb07f8c5b84..b65d14ae600 100644 --- a/mozilla/content/events/src/nsEventStateManager.cpp +++ b/mozilla/content/events/src/nsEventStateManager.cpp @@ -4305,7 +4305,9 @@ nsEventStateManager::ForceViewUpdate(nsIView* aView) } NS_IMETHODIMP -nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent, PRBool *aPreventDefault) +nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, + nsIDOMEvent* aEvent, + PRBool *aPreventDefault) { nsresult ret = NS_OK; @@ -4314,14 +4316,22 @@ nsEventStateManager::DispatchNewEvent(nsISupports* aTarget, nsIDOMEvent* aEvent, nsCOMPtr eventTarget(do_QueryInterface(aTarget)); privEvt->SetTarget(eventTarget); - //Check security state to determine if dispatcher is trusted - nsIScriptSecurityManager *securityManager = - nsContentUtils::GetSecurityManager(); + //Check security state to determine if dispatcher is trusted + nsIScriptSecurityManager *securityManager = + nsContentUtils::GetSecurityManager(); - PRBool enabled; - nsresult res = - securityManager->IsCapabilityEnabled("UniversalBrowserWrite", &enabled); - privEvt->SetTrusted(NS_SUCCEEDED(res) && enabled); + PRBool trusted; + nsCOMPtr nsevent(do_QueryInterface(privEvt)); + + nsevent->GetIsTrusted(&trusted); + + if (!trusted) { + PRBool enabled; + nsresult res = + securityManager->IsCapabilityEnabled("UniversalBrowserWrite", + &enabled); + privEvt->SetTrusted(NS_SUCCEEDED(res) && enabled); + } nsEvent * innerEvent; privEvt->GetInternalNSEvent(&innerEvent); diff --git a/mozilla/dom/src/base/nsGlobalWindow.cpp b/mozilla/dom/src/base/nsGlobalWindow.cpp index ef1bbbc09f0..4fa51ee3e71 100644 --- a/mozilla/dom/src/base/nsGlobalWindow.cpp +++ b/mozilla/dom/src/base/nsGlobalWindow.cpp @@ -2102,6 +2102,10 @@ NS_IMETHODIMP GlobalWindowImpl::SetFullScreen(PRBool aFullScreen) return NS_ERROR_FAILURE; event->InitEvent(NS_LITERAL_STRING("fullscreen"), PR_FALSE, PR_TRUE); + + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + PRBool allowDefault; DispatchEvent(event, &allowDefault); @@ -2924,6 +2928,9 @@ void FirePopupBlockedEvent(nsIDOMDocument* aDoc, nsCOMPtr pbev(do_QueryInterface(event)); pbev->InitPopupBlockedEvent(NS_LITERAL_STRING("DOMPopupBlocked"), PR_TRUE, PR_TRUE, aRequestingURI, aPopupURI, aPopupWindowFeatures); + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + PRBool noDefault; nsCOMPtr targ(do_QueryInterface(aDoc)); targ->DispatchEvent(event, &noDefault); @@ -2940,6 +2947,10 @@ void FirePopupWindowEvent(nsIDOMDocument* aDoc) docEvent->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event)); if (event) { event->InitEvent(NS_LITERAL_STRING("PopupWindow"), PR_TRUE, PR_TRUE); + + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + PRBool noDefault; nsCOMPtr targ(do_QueryInterface(aDoc)); targ->DispatchEvent(event, &noDefault); @@ -3427,6 +3438,9 @@ GlobalWindowImpl::Close() if (event) { event->InitEvent(NS_LITERAL_STRING("DOMWindowClose"), PR_TRUE, PR_TRUE); + nsCOMPtr privateEvent(do_QueryInterface(event)); + privateEvent->SetTrusted(PR_TRUE); + PRBool executeDefault = PR_TRUE; DispatchEvent(event, &executeDefault);