diff --git a/xpfe/AppCores/idl/ToolkitCore.idl b/xpfe/AppCores/idl/ToolkitCore.idl index 6e58ad64597f..899721ec751b 100644 --- a/xpfe/AppCores/idl/ToolkitCore.idl +++ b/xpfe/AppCores/idl/ToolkitCore.idl @@ -4,5 +4,6 @@ interface ToolkitCore : BaseAppCore {0x81, 0xb2, 0x00, 0x60, 0x08, 0x3a, 0x0b, 0xcf}} *\ void ToolkitCore(); + void ShowDialog(in wstring url, in Window parent); void ShowWindow(in wstring url, in Window parent); }; diff --git a/xpfe/AppCores/public/nsIDOMToolkitCore.h b/xpfe/AppCores/public/nsIDOMToolkitCore.h index 04b215644b95..ebfbc0cc1bf5 100644 --- a/xpfe/AppCores/public/nsIDOMToolkitCore.h +++ b/xpfe/AppCores/public/nsIDOMToolkitCore.h @@ -35,20 +35,24 @@ class nsIDOMToolkitCore : public nsIDOMBaseAppCore { public: static const nsIID& GetIID() { static nsIID iid = NS_IDOMTOOLKITCORE_IID; return iid; } + NS_IMETHOD ShowDialog(const nsString& aUrl, nsIDOMWindow* aParent)=0; + NS_IMETHOD ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent)=0; }; #define NS_DECL_IDOMTOOLKITCORE \ + NS_IMETHOD ShowDialog(const nsString& aUrl, nsIDOMWindow* aParent); \ NS_IMETHOD ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent); \ #define NS_FORWARD_IDOMTOOLKITCORE(_to) \ + NS_IMETHOD ShowDialog(const nsString& aUrl, nsIDOMWindow* aParent) { return _to##ShowDialog(aUrl, aParent); } \ NS_IMETHOD ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent) { return _to##ShowWindow(aUrl, aParent); } \ -extern nsresult NS_InitToolkitCoreClass(nsIScriptContext *aContext, void **aPrototype); +extern "C" NS_DOM nsresult NS_InitToolkitCoreClass(nsIScriptContext *aContext, void **aPrototype); extern "C" NS_DOM nsresult NS_NewScriptToolkitCore(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn); diff --git a/xpfe/AppCores/src/nsJSToolkitCore.cpp b/xpfe/AppCores/src/nsJSToolkitCore.cpp index 1d4c6ffccf69..eed0338390e6 100644 --- a/xpfe/AppCores/src/nsJSToolkitCore.cpp +++ b/xpfe/AppCores/src/nsJSToolkitCore.cpp @@ -130,6 +130,51 @@ ResolveToolkitCore(JSContext *cx, JSObject *obj, jsval id) } +// +// Native method ShowDialog +// +PR_STATIC_CALLBACK(JSBool) +ToolkitCoreShowDialog(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMToolkitCore *nativeThis = (nsIDOMToolkitCore*)JS_GetPrivate(cx, obj); + JSBool rBool = JS_FALSE; + nsAutoString b0; + nsIDOMWindowPtr b1; + + *rval = JSVAL_NULL; + + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + if (argc >= 2) { + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)&b1, + kIWindowIID, + "Window", + cx, + argv[1])) { + return JS_FALSE; + } + + if (NS_OK != nativeThis->ShowDialog(b0, b1)) { + return JS_FALSE; + } + + *rval = JSVAL_VOID; + } + else { + JS_ReportError(cx, "Function ShowDialog requires 2 parameters"); + return JS_FALSE; + } + + return JS_TRUE; +} + + // // Native method ShowWindow // @@ -207,6 +252,7 @@ static JSPropertySpec ToolkitCoreProperties[] = // static JSFunctionSpec ToolkitCoreMethods[] = { + {"ShowDialog", ToolkitCoreShowDialog, 2}, {"ShowWindow", ToolkitCoreShowWindow, 2}, {0} }; @@ -264,7 +310,7 @@ ToolkitCore(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) // // ToolkitCore class initialization // -nsresult NS_InitToolkitCoreClass(nsIScriptContext *aContext, void **aPrototype) +extern "C" NS_DOM nsresult NS_InitToolkitCoreClass(nsIScriptContext *aContext, void **aPrototype) { JSContext *jscontext = (JSContext *)aContext->GetNativeContext(); JSObject *proto = nsnull; diff --git a/xpfe/AppCores/src/nsToolkitCore.cpp b/xpfe/AppCores/src/nsToolkitCore.cpp index c3791979d7c9..a9de73414e4b 100644 --- a/xpfe/AppCores/src/nsToolkitCore.cpp +++ b/xpfe/AppCores/src/nsToolkitCore.cpp @@ -127,6 +127,44 @@ nsToolkitCore::Init(const nsString& aId) { } +NS_IMETHODIMP +nsToolkitCore::ShowDialog(const nsString& aUrl, nsIDOMWindow* aParent) { + + nsresult rv; + nsString controllerCID; + nsIAppShellService *appShell; + nsIWidget *window; + + window = nsnull; + + nsCOMPtr urlObj; + rv = NS_NewURL(getter_AddRefs(urlObj), aUrl); + if (NS_FAILED(rv)) + return rv; + + rv = nsServiceManager::GetService(kAppShellServiceCID, kIAppShellServiceIID, + (nsISupports**) &appShell); + if (NS_FAILED(rv)) + return rv; + + // hardwired temporary hack. See nsAppRunner.cpp at main() + controllerCID = "43147b80-8a39-11d2-9938-0080c7cb1081"; + + nsCOMPtr webWindow = DOMWindowToWebShellWindow(aParent); + nsCOMPtr parent; + if (webWindow) + webWindow->GetWidget(*getter_AddRefs(parent)); + + appShell->CreateTopLevelWindow(parent, urlObj, controllerCID, window, + nsnull, nsnull, 615, 650); + nsServiceManager::ReleaseService(kAppShellServiceCID, appShell); + + if (window != nsnull) + window->Show(PR_TRUE); + + return rv; +} + NS_IMETHODIMP nsToolkitCore::ShowWindow(const nsString& aUrl, nsIDOMWindow* aParent) {