One more part of bug 453571. Use [optional] for the optional arguments for window.open() and friends. r+sr=bzbarsky@mit.edu
authorJohnny Stenback <jst@mozilla.com>
Tue, 09 Sep 2008 18:23:34 -0700
changeset 19026 89f146305b76720cc3e982b762a12d29020cba1f
parent 19025 22805910408e956557eaee3a2cecc427eca72254
child 19027 ff043f7356f7d920403ac353db111325564570f6
push idunknown
push userunknown
push dateunknown
bugs453571
milestone1.9.1b1pre
One more part of bug 453571. Use [optional] for the optional arguments for window.open() and friends. r+sr=bzbarsky@mit.edu
dom/public/idl/base/nsIDOMJSWindow.idl
dom/public/idl/base/nsIDOMWindowInternal.idl
dom/src/base/nsGlobalWindow.cpp
dom/src/base/nsJSUtils.cpp
dom/src/base/nsJSUtils.h
--- a/dom/public/idl/base/nsIDOMJSWindow.idl
+++ b/dom/public/idl/base/nsIDOMJSWindow.idl
@@ -33,17 +33,17 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #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);
 
   /**
    * These methods take typeless arguments and optional arguments, the
    * first argument is either a function or a string, the second
    * argument must be a number (ms) and the rest of the arguments (2
@@ -72,27 +72,38 @@ interface nsIDOMJSWindow : nsISupports
    */
   void                      captureEvents(in long eventFlags);
   void                      releaseEvents(in long eventFlags);
   void                      routeEvent(in nsIDOMEvent evt);
   void                      enableExternalCapture();
   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
    * window itself (i.e. window.frames === window), but this doesn't
    * make sense from a generic API point of view so that's why this is
    * JS specific.
    *
    * This property is "replaceable" in JavaScript.
--- a/dom/public/idl/base/nsIDOMWindowInternal.idl
+++ b/dom/public/idl/base/nsIDOMWindowInternal.idl
@@ -155,22 +155,25 @@ interface nsIDOMWindowInternal : nsIDOMW
    * Open a new window with this one as the parent.  This method will
    * NOT examine the JS stack for purposes of determining a caller.
    * This window will be used for security checks during the search by
    * name and the default character set on the newly opened window
    * will just be the default character set of this window.
    */
   [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);
   void                      close();
 
   // XXX Should this be in nsIDOMChromeWindow?
   void                      updateCommands(in DOMString action);
 
--- a/dom/src/base/nsGlobalWindow.cpp
+++ b/dom/src/base/nsGlobalWindow.cpp
@@ -4944,64 +4944,27 @@ nsGlobalWindow::Open(const nsAString& aU
                       PR_FALSE,          // aDoJSFixups
                       nsnull, nsnull,    // No args
                       GetPrincipal(),    // aCalleePrincipal
                       nsnull,            // aJSCallerContext
                       _retval);
 }
 
 NS_IMETHODIMP
-nsGlobalWindow::Open(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,
+nsGlobalWindow::OpenJS(const nsAString& aUrl, const nsAString& aName,
+                       const nsAString& aOptions, nsIDOMWindow **_retval)
+{
+  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);
 }
 
 // like Open, but attaches to the new window any extra parameters past
 // [features] as a JS property named "arguments"
 NS_IMETHODIMP
 nsGlobalWindow::OpenDialog(const nsAString& aUrl, const nsAString& aName,
                            const nsAString& aOptions,
@@ -5014,17 +4977,18 @@ nsGlobalWindow::OpenDialog(const nsAStri
                       PR_FALSE,                   // aDoJSFixups
                       nsnull, aExtraArgument,     // Arguments
                       GetPrincipal(),             // aCalleePrincipal
                       nsnull,                     // aJSCallerContext
                       _retval);
 }
 
 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;
   }
 
   nsAXPCNativeCallContext *ncc = nsnull;
   nsresult rv = nsContentUtils::XPConnect()->
     GetCurrentNativeCallContext(&ncc);
@@ -5033,46 +4997,31 @@ nsGlobalWindow::OpenDialog(nsIDOMWindow*
   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;
 
   // XXX - need to get this as nsISupports?
   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
                       PR_FALSE,            // aDoJSFixups
                       argvArray, nsnull,   // Arguments
                       GetPrincipal(),      // aCalleePrincipal
                       cx,                  // aJSCallerContext
                       _retval);
--- a/dom/src/base/nsJSUtils.cpp
+++ b/dom/src/base/nsJSUtils.cpp
@@ -113,59 +113,16 @@ nsJSUtils::GetCallingLocation(JSContext*
       *aLineno = lineno;
       return JS_TRUE;
     }
   }
 
   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)
 {
   nsISupports* supports;
   JSClass* clazz;
   JSObject* parent;
   JSObject* glob = aObj; // starting point for search
 
--- a/dom/src/base/nsJSUtils.h
+++ b/dom/src/base/nsJSUtils.h
@@ -55,25 +55,16 @@ class nsIScriptGlobalObject;
 class nsIPrincipal;
 
 class nsJSUtils
 {
 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);
 
   static nsIScriptContext *GetStaticScriptContext(JSContext* aContext,
                                                   JSObject* aObj);
 
   static nsIScriptGlobalObject *GetDynamicScriptGlobal(JSContext *aContext);