One more part of bug 453571. Use [optional] for the optional arguments for window.open() and friends. r+sr=bzbarsky@mit.edu

This commit is contained in:
Johnny Stenback 2008-09-09 18:23:34 -07:00
Родитель 15ba12b39c
Коммит c45a4fe89e
5 изменённых файлов: 40 добавлений и 129 удалений

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

@ -38,7 +38,7 @@
#include "domstubs.idl"
[scriptable, uuid(8fcfcc79-054f-437b-965d-807d9b602d0f)]
[scriptable, uuid(14efb76c-5bd6-449e-b36f-0cbd22981f20)]
interface nsIDOMJSWindow : nsISupports
{
void dump(in DOMString str);
@ -77,17 +77,28 @@ interface nsIDOMJSWindow : nsISupports
void disableExternalCapture();
/**
* These are the scriptable versions of nsIDOMWindowInternal::open() and
* nsIDOMWindowInternal::openDialog() that take 3 optional arguments. Unlike
* the nsIDOMWindowInternal methods, these methods assume that they are
* called from JavaScript and hence will look on the JS context stack to
* determine the caller and hence correct security context for doing their
* search for an existing named window. Also, these methods will set the
* default charset on the newly opened window based on the current document
* charset in the caller.
* This is the scriptable versions of nsIDOMWindowInternal::open()
* that takes 3 optional arguments. Its binary name is OpenJS to
* avoid colliding with nsIDOMWindowInternal::open(), which has the
* same signature. The reason we can't have that collision is that
* the implementation needs to know whether it was called from JS or
* not.
*
* IOW, DO NOT CALL THIS FROM C++
*/
nsIDOMWindow open();
nsIDOMWindow openDialog();
[binaryname(OpenJS)] nsIDOMWindow open([optional] in DOMString url,
[optional] in DOMString name,
[optional] in DOMString options);
/**
* This is the scriptable versions of
* nsIDOMWindowInternal::openDialog() that takes 3 optional
* arguments, plus any additional arguments are passed on as
* arguments on the dialog's window object (window.arguments).
*/
nsIDOMWindow openDialog([optional] in DOMString url,
[optional] in DOMString name,
[optional] in DOMString options);
/**
* window.frames in Netscape 4.x and IE is just a reference to the

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

@ -160,12 +160,15 @@ interface nsIDOMWindowInternal : nsIDOMWindow2
*/
[noscript] nsIDOMWindow open(in DOMString url, in DOMString name,
in DOMString options);
// This method works like open except that aExtraArgument gets
// converted into the array window.arguments in JS, if
// aExtraArgument is a nsISupportsArray then the individual items in
// the array are inserted into window.arguments, and primitive
// nsISupports (nsISupportsPrimitives) types are converted to native
// JS types when possible.
/**
* This method works like open except that aExtraArgument gets
* converted into the array window.arguments in JS, if
* aExtraArgument is a nsISupportsArray then the individual items in
* the array are inserted into window.arguments, and primitive
* nsISupports (nsISupportsPrimitives) types are converted to native
* JS types when possible.
*/
[noscript] nsIDOMWindow openDialog(in DOMString url, in DOMString name,
in DOMString options,
in nsISupports aExtraArgument);

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

@ -4949,54 +4949,17 @@ nsGlobalWindow::Open(const nsAString& aUrl, const nsAString& aName,
}
NS_IMETHODIMP
nsGlobalWindow::Open(nsIDOMWindow **_retval)
nsGlobalWindow::OpenJS(const nsAString& aUrl, const nsAString& aName,
const nsAString& aOptions, nsIDOMWindow **_retval)
{
*_retval = nsnull;
nsAXPCNativeCallContext *ncc = nsnull;
nsresult rv = nsContentUtils::XPConnect()->
GetCurrentNativeCallContext(&ncc);
NS_ENSURE_SUCCESS(rv, rv);
if (!ncc)
return NS_ERROR_NOT_AVAILABLE;
JSContext *cx = nsnull;
rv = ncc->GetJSContext(&cx);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString url, name, options;
PRUint32 argc;
jsval *argv = nsnull;
ncc->GetArgc(&argc);
ncc->GetArgvPtr(&argv);
if (argc > 0) {
JSAutoRequest ar(cx);
switch (argc) {
default:
case 3:
nsJSUtils::ConvertJSValToString(options, cx, argv[2]);
case 2:
nsJSUtils::ConvertJSValToString(name, cx, argv[1]);
case 1:
nsJSUtils::ConvertJSValToString(url, cx, argv[0]);
break;
}
}
return OpenInternal(url, name, options,
return OpenInternal(aUrl, aName, aOptions,
PR_FALSE, // aDialog
PR_FALSE, // aContentModal
PR_FALSE, // aCalledNoScript
PR_TRUE, // aDoJSFixups
nsnull, nsnull, // No args
GetPrincipal(), // aCalleePrincipal
cx, // aJSCallerContext
nsContentUtils::GetCurrentJSContext(), // aJSCallerContext
_retval);
}
@ -5019,7 +4982,8 @@ nsGlobalWindow::OpenDialog(const nsAString& aUrl, const nsAString& aName,
}
NS_IMETHODIMP
nsGlobalWindow::OpenDialog(nsIDOMWindow** _retval)
nsGlobalWindow::OpenDialog(const nsAString& aUrl, const nsAString& aName,
const nsAString& aOptions, nsIDOMWindow** _retval)
{
if (!nsContentUtils::IsCallerTrustedForWrite()) {
return NS_ERROR_DOM_SECURITY_ERR;
@ -5038,8 +5002,6 @@ nsGlobalWindow::OpenDialog(nsIDOMWindow** _retval)
rv = ncc->GetJSContext(&cx);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoString url, name, options;
PRUint32 argc;
jsval *argv = nsnull;
@ -5047,27 +5009,14 @@ nsGlobalWindow::OpenDialog(nsIDOMWindow** _retval)
ncc->GetArgc(&argc);
ncc->GetArgvPtr(&argv);
if (argc > 0) {
JSAutoRequest ar(cx);
switch (argc) {
default:
case 3:
nsJSUtils::ConvertJSValToString(options, cx, argv[2]);
case 2:
nsJSUtils::ConvertJSValToString(name, cx, argv[1]);
case 1:
nsJSUtils::ConvertJSValToString(url, cx, argv[0]);
break;
}
}
// Strip the url, name and options from the args seen by scripts.
PRUint32 argOffset = argc < 3 ? argc : 3;
nsCOMPtr<nsIArray> argvArray;
rv = NS_CreateJSArgv(cx, argc-argOffset, argv+argOffset, getter_AddRefs(argvArray));
rv = NS_CreateJSArgv(cx, argc - argOffset, argv + argOffset,
getter_AddRefs(argvArray));
NS_ENSURE_SUCCESS(rv, rv);
return OpenInternal(url, name, options,
return OpenInternal(aUrl, aName, aOptions,
PR_TRUE, // aDialog
PR_FALSE, // aContentModal
PR_FALSE, // aCalledNoScript

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

@ -118,49 +118,6 @@ nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename,
return JS_FALSE;
}
jsval
nsJSUtils::ConvertStringToJSVal(const nsString& aProp, JSContext* aContext)
{
JSString *jsstring =
::JS_NewUCStringCopyN(aContext, reinterpret_cast<const jschar*>
(aProp.get()),
aProp.Length());
// set the return value
return STRING_TO_JSVAL(jsstring);
}
void
nsJSUtils::ConvertJSValToString(nsAString& aString, JSContext* aContext,
jsval aValue)
{
JSString *jsstring;
if ((jsstring = ::JS_ValueToString(aContext, aValue)) != nsnull) {
aString.Assign(reinterpret_cast<const PRUnichar*>
(::JS_GetStringChars(jsstring)),
::JS_GetStringLength(jsstring));
}
else {
aString.Truncate();
}
}
PRBool
nsJSUtils::ConvertJSValToUint32(PRUint32* aProp, JSContext* aContext,
jsval aValue)
{
uint32 temp;
if (::JS_ValueToECMAUint32(aContext, aValue, &temp)) {
*aProp = (PRUint32)temp;
}
else {
::JS_ReportError(aContext, "Parameter must be an integer");
return JS_FALSE;
}
return JS_TRUE;
}
nsIScriptGlobalObject *
nsJSUtils::GetStaticScriptGlobal(JSContext* aContext, JSObject* aObj)
{

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

@ -60,15 +60,6 @@ public:
static JSBool GetCallingLocation(JSContext* aContext, const char* *aFilename,
PRUint32* aLineno, nsIPrincipal* aPrincipal);
static jsval ConvertStringToJSVal(const nsString& aProp,
JSContext* aContext);
static void ConvertJSValToString(nsAString& aString,
JSContext* aContext, jsval aValue);
static PRBool ConvertJSValToUint32(PRUint32* aProp, JSContext* aContext,
jsval aValue);
static nsIScriptGlobalObject *GetStaticScriptGlobal(JSContext* aContext,
JSObject* aObj);