From b9e6cd58d2f47d7172471e5ff373bda4fe18deab Mon Sep 17 00:00:00 2001 From: "peterv%propagandism.org" Date: Wed, 5 May 2004 09:03:48 +0000 Subject: [PATCH] Remove CheckSecurityIsChromeCaller (use IsCallerChrome instead), remove some obsolete code (DOMString's can be null now). r/sr=jst. --- dom/src/base/nsGlobalWindow.cpp | 97 ++++++++------------------------- dom/src/base/nsGlobalWindow.h | 1 - 2 files changed, 24 insertions(+), 74 deletions(-) diff --git a/dom/src/base/nsGlobalWindow.cpp b/dom/src/base/nsGlobalWindow.cpp index cd18f6efb59..cdbf883118f 100644 --- a/dom/src/base/nsGlobalWindow.cpp +++ b/dom/src/base/nsGlobalWindow.cpp @@ -2175,37 +2175,16 @@ GlobalWindowImpl::SetTextZoom(float aZoom) return NS_ERROR_FAILURE; } -// static -nsresult -GlobalWindowImpl::CheckSecurityIsChromeCaller(PRBool *aIsChrome) -{ - NS_ENSURE_ARG_POINTER(aIsChrome); - - *aIsChrome = PR_FALSE; - - // Check if this is a privileged system script - - NS_ENSURE_TRUE(sSecMan, NS_ERROR_FAILURE); - - PRBool isChrome = PR_FALSE; - nsresult rv = sSecMan->SubjectPrincipalIsSystem(&isChrome); - if (NS_SUCCEEDED(rv)) { - *aIsChrome = isChrome; - } - - return NS_OK; -} - // static PRBool GlobalWindowImpl::IsCallerChrome() { - PRBool is_caller_chrome = PR_FALSE; + NS_ENSURE_TRUE(sSecMan, PR_FALSE); - nsresult rv = CheckSecurityIsChromeCaller(&is_caller_chrome); - NS_ENSURE_SUCCESS(rv, PR_FALSE); + PRBool isChrome = PR_FALSE; + nsresult rv = sSecMan->SubjectPrincipalIsSystem(&isChrome); - return is_caller_chrome; + return NS_SUCCEEDED(rv) ? isChrome : PR_FALSE; } void @@ -2262,17 +2241,16 @@ GlobalWindowImpl::Alert(const nsAString& aString) NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE); // Test whether title needs to prefixed with [script] - PRBool isChrome = PR_FALSE; nsAutoString newTitle; const PRUnichar *title = nsnull; - nsresult rv = CheckSecurityIsChromeCaller(&isChrome); - if (NS_FAILED(rv) || !isChrome) { + if (!IsCallerChrome()) { MakeScriptDialogTitle(EmptyString(), newTitle); title = newTitle.get(); } - NS_WARN_IF_FALSE(!isChrome, - "chrome shouldn't be calling alert(), use the prompt " - "service"); + else { + NS_WARNING("chrome shouldn't be calling alert(), use the prompt " + "service"); + } // Before bringing up the window, unsuppress painting and flush // pending reflows. @@ -2295,17 +2273,16 @@ GlobalWindowImpl::Confirm(const nsAString& aString, PRBool* aReturn) // XXX: Concatenation of optional args? // Test whether title needs to prefixed with [script] - PRBool isChrome = PR_FALSE; nsAutoString newTitle; const PRUnichar *title = nsnull; - nsresult rv = CheckSecurityIsChromeCaller(&isChrome); - if (NS_FAILED(rv) || !isChrome) { + if (!IsCallerChrome()) { MakeScriptDialogTitle(EmptyString(), newTitle); title = newTitle.get(); } - NS_WARN_IF_FALSE(!isChrome, - "chrome shouldn't be calling confirm(), use the prompt " - "service"); + else { + NS_WARNING("chrome shouldn't be calling confirm(), use the prompt " + "service"); + } nsCOMPtr prompter(do_GetInterface(mDocShell)); NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE); @@ -2324,14 +2301,11 @@ GlobalWindowImpl::Prompt(const nsAString& aMessage, PRUint32 aSavePassword, nsAString& aReturn) { + SetDOMStringToNull(aReturn); + NS_ENSURE_STATE(mDocShell); - aReturn.Truncate(); // XXX Null string!!! - - nsresult rv = NS_OK; - nsCOMPtr prompter(do_GetInterface(mDocShell)); - NS_ENSURE_TRUE(prompter, NS_ERROR_FAILURE); PRBool b; @@ -2343,47 +2317,24 @@ GlobalWindowImpl::Prompt(const nsAString& aMessage, // Test whether title needs to prefixed with [script] nsAutoString title; - PRBool isChrome = PR_FALSE; - rv = CheckSecurityIsChromeCaller(&isChrome); - if (NS_FAILED(rv) || !isChrome) { + if (!IsCallerChrome()) { MakeScriptDialogTitle(aTitle, title); } else { + NS_WARNING("chrome shouldn't be calling prompt(), use the prompt " + "service"); title.Assign(aTitle); } - NS_WARN_IF_FALSE(!isChrome, "chrome shouldn't be calling prompt(), use the prompt service"); - rv = prompter->Prompt(title.get(), - PromiseFlatString(aMessage).get(), nsnull, - aSavePassword, - PromiseFlatString(aInitial).get(), - getter_Copies(uniResult), &b); + nsresult rv = prompter->Prompt(title.get(), + PromiseFlatString(aMessage).get(), nsnull, + aSavePassword, + PromiseFlatString(aInitial).get(), + getter_Copies(uniResult), &b); NS_ENSURE_SUCCESS(rv, rv); if (uniResult && b) { aReturn.Assign(uniResult); } - else { - SetDOMStringToNull(aReturn); - - // XXX: Since DOMString's can't be null yet we'll haveto do this here... - - if (sXPConnect) { - nsCOMPtr ncc; - - sXPConnect->GetCurrentNativeCallContext(getter_AddRefs(ncc)); - - if (ncc) { - jsval *retval = nsnull; - - rv = ncc->GetRetValPtr(&retval); - NS_ENSURE_SUCCESS(rv, rv); - - *retval = JSVAL_NULL; - - ncc->SetReturnValueWasSet(PR_TRUE); - } - } - } return rv; } diff --git a/dom/src/base/nsGlobalWindow.h b/dom/src/base/nsGlobalWindow.h index a187ee61a1f..3fef12d1b48 100644 --- a/dom/src/base/nsGlobalWindow.h +++ b/dom/src/base/nsGlobalWindow.h @@ -250,7 +250,6 @@ protected: void EnsureReflowFlushAndPaint(); nsresult CheckSecurityWidthAndHeight(PRInt32* width, PRInt32* height); nsresult CheckSecurityLeftAndTop(PRInt32* left, PRInt32* top); - static nsresult CheckSecurityIsChromeCaller(PRBool *isChrome); static PRBool CanSetProperty(const char *aPrefName); void MakeScriptDialogTitle(const nsAString &aInTitle, nsAString &aOutTitle);