Bug 549566, clean-up beforeunload message, r=sicking

--HG--
extra : rebase_source : 5abe27de295f9285b926f105d7ec317ebe1503ff
This commit is contained in:
Olli Pettay 2010-03-03 14:41:57 +02:00
parent 3c1dfe889c
commit 4d09544717
4 changed files with 30 additions and 27 deletions

View File

@ -1541,6 +1541,7 @@ public:
return WrapNative(cx, scope, native, nsnull, vp, aHolder, aAllowWrapping);
}
static void StripNullChars(const nsAString& aInStr, nsAString& aOutStr);
private:
static PRBool InitializeEventTable();

View File

@ -5330,6 +5330,28 @@ nsContentUtils::WrapNative(JSContext *cx, JSObject *scope, nsISupports *native,
return rv;
}
void
nsContentUtils::StripNullChars(const nsAString& aInStr, nsAString& aOutStr)
{
// In common cases where we don't have nulls in the
// string we can simple simply bypass the checking code.
PRInt32 firstNullPos = aInStr.FindChar('\0');
if (firstNullPos == kNotFound) {
aOutStr.Assign(aInStr);
return;
}
aOutStr.SetCapacity(aInStr.Length() - 1);
nsAString::const_iterator start, end;
aInStr.BeginReading(start);
aInStr.EndReading(end);
while (start != end) {
if (*start != '\0')
aOutStr.Append(*start);
++start;
}
}
#ifdef DEBUG
class DebugWrapperTraversalCallback : public nsCycleCollectionTraversalCallback
{

View File

@ -382,29 +382,6 @@ IsAboutBlank(nsIURI* aURI)
return str.EqualsLiteral("about:blank");
}
static void
StripNullChars(const nsAString& aInStr,
nsAString& aOutStr)
{
// In common cases where we don't have nulls in the
// string we can simple simply bypass the checking code.
PRInt32 firstNullPos = aInStr.FindChar('\0');
if (firstNullPos == kNotFound) {
aOutStr.Assign(aInStr);
return;
}
nsAString::const_iterator start, end;
aInStr.BeginReading(start);
aInStr.EndReading(end);
while (start != end) {
if (*start != '\0')
aOutStr.Append(*start);
++start;
}
}
class nsDummyJavaPluginOwner : public nsIPluginInstanceOwner
{
public:
@ -4210,7 +4187,7 @@ nsGlobalWindow::Alert(const nsAString& aString)
// Remove non-terminating null characters from the
// string. See bug #310037.
nsAutoString final;
StripNullChars(*str, final);
nsContentUtils::StripNullChars(*str, final);
return prompter->Alert(title.get(), final.get());
}
@ -4240,7 +4217,7 @@ nsGlobalWindow::Confirm(const nsAString& aString, PRBool* aReturn)
// Remove non-terminating null characters from the
// string. See bug #310037.
nsAutoString final;
StripNullChars(aString, final);
nsContentUtils::StripNullChars(aString, final);
return prompter->Confirm(title.get(), final.get(),
aReturn);
@ -4288,8 +4265,8 @@ nsGlobalWindow::Prompt(const nsAString& aMessage, const nsAString& aInitial,
// Remove non-terminating null characters from the
// string. See bug #310037.
nsAutoString fixedMessage, fixedInitial;
StripNullChars(aMessage, fixedMessage);
StripNullChars(aInitial, fixedInitial);
nsContentUtils::StripNullChars(aMessage, fixedMessage);
nsContentUtils::StripNullChars(aInitial, fixedInitial);
rv = prompter->Prompt(title.get(), fixedMessage.get(), nsnull,
aSavePassword, fixedInitial.get(),

View File

@ -1151,6 +1151,9 @@ DocumentViewerImpl::PermitUnload(PRBool aCallerClosesWindow, PRBool *aPermitUnlo
beforeUnload->GetReturnValue(text);
if (pEvent->GetInternalNSEvent()->flags & NS_EVENT_FLAG_NO_DEFAULT ||
!text.IsEmpty()) {
nsAutoString tmp;
nsContentUtils::StripNullChars(text, tmp);
text = tmp;
// Ask the user if it's ok to unload the current page
nsCOMPtr<nsIPrompt> prompt = do_GetInterface(docShellNode);