Bug 496000 - Remove nsBeforePageUnloadEvent, r+sr=jst

--HG--
extra : rebase_source : 0288c06ade3ef23641bb2fe9a33143e865d90217
This commit is contained in:
Olli Pettay 2009-06-24 11:42:00 +03:00
Родитель ea3a7bda35
Коммит e6bdf094b7
8 изменённых файлов: 46 добавлений и 85 удалений

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

@ -93,7 +93,7 @@ NS_NewDOMPopupBlockedEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, n
nsresult
NS_NewDOMTextEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsTextEvent* aEvent);
nsresult
NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsBeforePageUnloadEvent* aEvent);
NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, nsEvent* aEvent);
nsresult
NS_NewDOMPageTransitionEvent(nsIDOMEvent** aResult, nsPresContext* aPresContext, class nsPageTransitionEvent* aEvent);
#ifdef MOZ_SVG

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

@ -39,33 +39,6 @@
#include "nsDOMBeforeUnloadEvent.h"
#include "nsContentUtils.h"
nsDOMBeforeUnloadEvent::nsDOMBeforeUnloadEvent(nsPresContext* aPresContext,
nsBeforePageUnloadEvent* aEvent)
: nsDOMEvent(aPresContext, aEvent ? aEvent :
new nsBeforePageUnloadEvent(PR_FALSE,
NS_BEFORE_PAGE_UNLOAD_EVENT))
{
NS_ASSERTION(mEvent->eventStructType == NS_BEFORE_PAGE_UNLOAD_EVENT,
"event type mismatch");
if (aEvent) {
mEventIsInternal = PR_FALSE;
}
else {
mEventIsInternal = PR_TRUE;
mEvent->time = PR_Now();
}
}
nsDOMBeforeUnloadEvent::~nsDOMBeforeUnloadEvent()
{
if (mEventIsInternal &&
mEvent->eventStructType == NS_BEFORE_PAGE_UNLOAD_EVENT) {
delete static_cast<nsBeforePageUnloadEvent*>(mEvent);
mEvent = nsnull;
}
}
NS_IMPL_ADDREF_INHERITED(nsDOMBeforeUnloadEvent, nsDOMEvent)
NS_IMPL_RELEASE_INHERITED(nsDOMBeforeUnloadEvent, nsDOMEvent)
@ -77,22 +50,20 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
NS_IMETHODIMP
nsDOMBeforeUnloadEvent::SetReturnValue(const nsAString& aReturnValue)
{
((nsBeforePageUnloadEvent *)mEvent)->text = aReturnValue;
mText = aReturnValue;
return NS_OK; // Don't throw an exception
}
NS_IMETHODIMP
nsDOMBeforeUnloadEvent::GetReturnValue(nsAString& aReturnValue)
{
aReturnValue = ((nsBeforePageUnloadEvent *)mEvent)->text;
aReturnValue = mText;
return NS_OK; // Don't throw an exception
}
nsresult NS_NewDOMBeforeUnloadEvent(nsIDOMEvent** aInstancePtrResult,
nsPresContext* aPresContext,
nsBeforePageUnloadEvent *aEvent)
nsEvent *aEvent)
{
nsDOMBeforeUnloadEvent* it =
new nsDOMBeforeUnloadEvent(aPresContext, aEvent);

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

@ -46,9 +46,8 @@ class nsDOMBeforeUnloadEvent : public nsIDOMBeforeUnloadEvent,
public nsDOMEvent
{
public:
nsDOMBeforeUnloadEvent(nsPresContext* aPresContext,
nsBeforePageUnloadEvent* aEvent);
virtual ~nsDOMBeforeUnloadEvent();
nsDOMBeforeUnloadEvent(nsPresContext* aPresContext, nsEvent* aEvent)
: nsDOMEvent(aPresContext, aEvent) {}
NS_DECL_ISUPPORTS_INHERITED
@ -57,6 +56,8 @@ public:
// nsIDOMBeforeUnloadEvent Interface
NS_DECL_NSIDOMBEFOREUNLOADEVENT
protected:
nsString mText;
};
#endif // nsDOMBeforeUnloadEvent_h__

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

@ -550,6 +550,8 @@ nsDOMEvent::SetEventType(const nsAString& aEventTypeArg)
mEvent->message = NS_LOAD;
else if (atom == nsGkAtoms::onunload)
mEvent->message = NS_PAGE_UNLOAD;
else if (atom == nsGkAtoms::onbeforeunload)
mEvent->message = NS_BEFORE_PAGE_UNLOAD;
else if (atom == nsGkAtoms::onabort)
mEvent->message = NS_IMAGE_ABORT;
else if (atom == nsGkAtoms::onerror)
@ -941,14 +943,6 @@ NS_METHOD nsDOMEvent::DuplicatePrivateData()
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
break;
}
case NS_BEFORE_PAGE_UNLOAD_EVENT:
{
newEvent = new nsBeforePageUnloadEvent(PR_FALSE, msg);
NS_ENSURE_TRUE(newEvent, NS_ERROR_OUT_OF_MEMORY);
static_cast<nsBeforePageUnloadEvent*>(newEvent)->text =
static_cast<nsBeforePageUnloadEvent*>(mEvent)->text;
break;
}
case NS_UI_EVENT:
{
newEvent = new nsUIEvent(PR_FALSE, msg,

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

@ -641,11 +641,6 @@ nsEventDispatcher::CreateEvent(nsPresContext* aPresContext,
case NS_TEXT_EVENT:
return NS_NewDOMTextEvent(aDOMEvent, aPresContext,
static_cast<nsTextEvent*>(aEvent));
case NS_BEFORE_PAGE_UNLOAD_EVENT:
return
NS_NewDOMBeforeUnloadEvent(aDOMEvent, aPresContext,
static_cast<nsBeforePageUnloadEvent*>
(aEvent));
case NS_PAGETRANSITION_EVENT:
return NS_NewDOMPageTransitionEvent(aDOMEvent, aPresContext,
static_cast<nsPageTransitionEvent*>
@ -729,6 +724,8 @@ nsEventDispatcher::CreateEvent(nsPresContext* aPresContext,
return NS_NewDOMNotifyPaintEvent(aDOMEvent, aPresContext, nsnull);
if (aEventType.LowerCaseEqualsLiteral("simplegestureevent"))
return NS_NewDOMSimpleGestureEvent(aDOMEvent, aPresContext, nsnull);
if (aEventType.LowerCaseEqualsLiteral("beforeunloadevent"))
return NS_NewDOMBeforeUnloadEvent(aDOMEvent, aPresContext, nsnull);
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}

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

@ -50,7 +50,7 @@
#include "nsDOMScriptObjectHolder.h"
#include "nsIMutableArray.h"
#include "nsVariant.h"
#include "nsIDOMBeforeUnloadEvent.h"
#ifdef NS_DEBUG
#include "nsIJSContextStack.h"
@ -251,18 +251,13 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
if (vrv)
vrv->GetDataType(&dataType);
if (eventString.EqualsLiteral("onbeforeunload")) {
nsCOMPtr<nsIPrivateDOMEvent> priv(do_QueryInterface(aEvent));
NS_ENSURE_TRUE(priv, NS_ERROR_UNEXPECTED);
nsEvent *event = priv->GetInternalNSEvent();
NS_ENSURE_TRUE(event && event->message == NS_BEFORE_PAGE_UNLOAD,
NS_ERROR_UNEXPECTED);
nsBeforePageUnloadEvent *beforeUnload =
static_cast<nsBeforePageUnloadEvent *>(event);
nsCOMPtr<nsIDOMBeforeUnloadEvent> beforeUnload = do_QueryInterface(aEvent);
NS_ENSURE_STATE(beforeUnload);
if (dataType != nsIDataType::VTYPE_VOID) {
aEvent->PreventDefault();
nsAutoString text;
beforeUnload->GetReturnValue(text);
// Set the text in the beforeUnload event as long as it wasn't
// already set (through event.returnValue, which takes
@ -274,8 +269,9 @@ nsJSEventListener::HandleEvent(nsIDOMEvent* aEvent)
dataType == nsIDataType::VTYPE_WSTRING_SIZE_IS ||
dataType == nsIDataType::VTYPE_CSTRING ||
dataType == nsIDataType::VTYPE_ASTRING)
&& beforeUnload->text.IsEmpty()) {
vrv->GetAsDOMString(beforeUnload->text);
&& text.IsEmpty()) {
vrv->GetAsDOMString(text);
beforeUnload->SetReturnValue(text);
}
}
} else if (dataType == nsIDataType::VTYPE_BOOL) {

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

@ -51,7 +51,9 @@
#include "nsIContentViewerContainer.h"
#include "nsIDocumentViewer.h"
#include "nsIDocumentViewerPrint.h"
#include "nsIDOMDocumentEvent.h"
#include "nsIPrivateDOMEvent.h"
#include "nsIDOMBeforeUnloadEvent.h"
#include "nsIDocument.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
@ -1078,12 +1080,21 @@ DocumentViewerImpl::PermitUnload(PRBool *aPermitUnload)
// Now, fire an BeforeUnload event to the document and see if it's ok
// to unload...
nsEventStatus status = nsEventStatus_eIgnore;
nsBeforePageUnloadEvent event(PR_TRUE, NS_BEFORE_PAGE_UNLOAD);
event.flags |= NS_EVENT_FLAG_CANT_BUBBLE;
nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(mDocument);
nsCOMPtr<nsIDOMEvent> event;
docEvent->CreateEvent(NS_LITERAL_STRING("beforeunloadevent"),
getter_AddRefs(event));
nsCOMPtr<nsIDOMBeforeUnloadEvent> beforeUnload = do_QueryInterface(event);
nsCOMPtr<nsIPrivateDOMEvent> pEvent = do_QueryInterface(beforeUnload);
NS_ENSURE_STATE(pEvent);
nsresult rv = event->InitEvent(NS_LITERAL_STRING("beforeunload"),
PR_FALSE, PR_TRUE);
NS_ENSURE_SUCCESS(rv, rv);
// XXX Dispatching to |window|, but using |document| as the target.
event.target = mDocument;
nsresult rv = NS_OK;
nsCOMPtr<nsIDOMEventTarget> target = do_QueryInterface(mDocument);
pEvent->SetTarget(target);
pEvent->SetTrusted(PR_TRUE);
// In evil cases we might be destroyed while handling the
// onbeforeunload event, don't let that happen. (see also bug#331040)
@ -1095,14 +1106,16 @@ DocumentViewerImpl::PermitUnload(PRBool *aPermitUnload)
nsAutoPopupStatePusher popupStatePusher(openAbused, PR_TRUE);
mInPermitUnload = PR_TRUE;
nsEventDispatcher::Dispatch(window, mPresContext, &event, nsnull, &status);
nsEventDispatcher::DispatchDOMEvent(window, nsnull, event, mPresContext,
nsnull);
mInPermitUnload = PR_FALSE;
}
nsCOMPtr<nsIDocShellTreeNode> docShellNode(do_QueryReferent(mContainer));
if (NS_SUCCEEDED(rv) && (event.flags & NS_EVENT_FLAG_NO_DEFAULT ||
!event.text.IsEmpty())) {
nsAutoString text;
beforeUnload->GetReturnValue(text);
if (pEvent->GetInternalNSEvent()->flags & NS_EVENT_FLAG_NO_DEFAULT ||
!text.IsEmpty()) {
// Ask the user if it's ok to unload the current page
nsCOMPtr<nsIPrompt> prompt = do_GetInterface(docShellNode);
@ -1124,14 +1137,14 @@ DocumentViewerImpl::PermitUnload(PRBool *aPermitUnload)
// Limit the length of the text the page can inject into this
// dialogue to 1024 characters.
PRInt32 len = PR_MIN(event.text.Length(), 1024);
PRInt32 len = PR_MIN(text.Length(), 1024);
nsAutoString msg;
if (len == 0) {
msg = preMsg + NS_LITERAL_STRING("\n\n") + postMsg;
} else {
msg = preMsg + NS_LITERAL_STRING("\n\n") +
StringHead(event.text, len) +
StringHead(text, len) +
NS_LITERAL_STRING("\n\n") + postMsg;
}

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

@ -90,7 +90,7 @@ class nsHashKey;
#define NS_POPUP_EVENT 23
#define NS_COMMAND_EVENT 24
#define NS_BEFORE_PAGE_UNLOAD_EVENT 26
#define NS_UI_EVENT 27
#define NS_PAGETRANSITION_EVENT 29
#ifdef MOZ_SVG
@ -536,17 +536,6 @@ public:
const PRUnichar* fileName;
};
class nsBeforePageUnloadEvent : public nsEvent
{
public:
nsBeforePageUnloadEvent(PRBool isTrusted, PRUint32 msg)
: nsEvent(isTrusted, msg, NS_BEFORE_PAGE_UNLOAD_EVENT)
{
}
nsString text;
};
/**
* Window resize event
*/