Bug 611553 - Make DOMWillOpenModalDialog a chrome-only event. r=dolske r=smaug a=akeybl
--- a/embedding/components/windowwatcher/src/nsAutoWindowStateHelper.cpp
+++ b/embedding/components/windowwatcher/src/nsAutoWindowStateHelper.cpp
@@ -5,24 +5,25 @@
#include "nsAutoWindowStateHelper.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMEventTarget.h"
#include "nsIDOMEvent.h"
#include "nsString.h"
+#include "nsGUIEvent.h"
/****************************************************************
****************** nsAutoWindowStateHelper *********************
****************************************************************/
nsAutoWindowStateHelper::nsAutoWindowStateHelper(nsIDOMWindow *aWindow)
: mWindow(aWindow),
- mDefaultEnabled(DispatchCustomEvent("DOMWillOpenModalDialog"))
+ mDefaultEnabled(DispatchEventToChrome("DOMWillOpenModalDialog"))
{
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(aWindow));
if (window) {
mCallerWindow = window->EnterModalState();
}
}
@@ -30,23 +31,38 @@ nsAutoWindowStateHelper::~nsAutoWindowSt
{
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mWindow));
if (window) {
window->LeaveModalState(mCallerWindow);
}
if (mDefaultEnabled) {
- DispatchCustomEvent("DOMModalDialogClosed");
+ DispatchEventToChrome("DOMModalDialogClosed");
}
}
bool
-nsAutoWindowStateHelper::DispatchCustomEvent(const char *aEventName)
+nsAutoWindowStateHelper::DispatchEventToChrome(const char *aEventName)
{
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mWindow);
if (!window) {
return true;
}
- return window->DispatchCustomEvent(aEventName);
+ // The functions of nsContentUtils do not provide the required behavior,
+ // so the following is inlined.
+ nsIDOMDocument* doc = window->GetExtantDocument();
+ if (!doc) {
+ return true;
+ }
+
+ nsCOMPtr<nsIDOMEvent> event;
+ doc->CreateEvent(NS_LITERAL_STRING("Events"), getter_AddRefs(event));
+ NS_ENSURE_TRUE(NS_SUCCEEDED(event->InitEvent(NS_ConvertASCIItoUTF16(aEventName), true, true)), false);
+ event->SetTrusted(true);
+ event->GetInternalNSEvent()->mFlags.mOnlyChromeDispatch = true;
+
+ nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(window));
+ bool defaultActionEnabled;
+ target->DispatchEvent(event, &defaultActionEnabled);
+ return defaultActionEnabled;
}
-
--- a/embedding/components/windowwatcher/src/nsAutoWindowStateHelper.h
+++ b/embedding/components/windowwatcher/src/nsAutoWindowStateHelper.h
@@ -22,17 +22,17 @@ public:
~nsAutoWindowStateHelper();
bool DefaultEnabled()
{
return mDefaultEnabled;
}
protected:
- bool DispatchCustomEvent(const char *aEventName);
+ bool DispatchEventToChrome(const char *aEventName);
nsIDOMWindow *mWindow;
nsCOMPtr<nsIDOMWindow> mCallerWindow;
bool mDefaultEnabled;
};
#endif
--- a/toolkit/components/prompts/src/nsPrompter.js
+++ b/toolkit/components/prompts/src/nsPrompter.js
@@ -167,22 +167,22 @@ let PromptUtils = {
flags >>= 8;
}
return [buttonLabels[0], buttonLabels[1], buttonLabels[2], defaultButtonNum, isDelayEnabled];
},
// Fire a dialog open/close event. Used by tabbrowser to focus the
// tab which is triggering a prompt.
- //
- // Bug 611553 - should make these notifications instead of events.
fireDialogEvent : function (domWin, eventName) {
let event = domWin.document.createEvent("Events");
event.initEvent(eventName, true, true);
- domWin.dispatchEvent(event);
+ let winUtils = domWin.QueryInterface(Ci.nsIInterfaceRequestor)
+ .getInterface(Ci.nsIDOMWindowUtils);
+ winUtils.dispatchEventToChromeOnly(domWin, event);
},
getAuthInfo : function (authInfo) {
let username, password;
let flags = authInfo.flags;
if (flags & Ci.nsIAuthInformation.NEED_DOMAIN && authInfo.domain)
username = authInfo.domain + "\\" + authInfo.username;