diff --git a/xpinstall/public/nsPIXPIProxy.idl b/xpinstall/public/nsPIXPIProxy.idl index add25afdb03..e69de29bb2d 100644 --- a/xpinstall/public/nsPIXPIProxy.idl +++ b/xpinstall/public/nsPIXPIProxy.idl @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is Mozilla Communicator client code, released - * March 31, 1998. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998-2001 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Daniel Veditz - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * 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 "nsISupports.idl" - -/** - * nsPIXPIProxy - * - * Used to handle miscellaneous things that XPInstall needs to perform - * over on the main UI thread. - */ -[scriptable,uuid(6F9D2890-167D-11d5-8DAF-000064657374)] -interface nsPIXPIProxy : nsISupports -{ - void refreshPlugins(in boolean reloadPages); - void notifyRestartNeeded(); - - void alert(in wstring title, in wstring text); - boolean confirm(in wstring title, in wstring text); -}; diff --git a/xpinstall/src/nsInstall.cpp b/xpinstall/src/nsInstall.cpp index bb487a4d7fd..0d143f35dfb 100644 --- a/xpinstall/src/nsInstall.cpp +++ b/xpinstall/src/nsInstall.cpp @@ -22,6 +22,7 @@ * Contributor(s): * Daniel Veditz * Douglas Turner + * Jens Bannmann * Pierre Phaneuf * Sean Su * Samir Gehani @@ -2564,22 +2565,55 @@ nsInstall::Alert(nsString& string) if (!ui) return UNEXPECTED_ERROR; - return ui->Alert( GetTranslatedString(NS_LITERAL_STRING("Alert").get()), - string.get()); + nsAutoString title; + title.AssignLiteral("Alert"); + if (!mUIName.IsEmpty()) + { + title = mUIName; + } + else + { + PRUnichar *t = GetTranslatedString(title.get()); + if (t) + title.Adopt(t); + } + return ui->Alert( title.get(), string.get()); } PRInt32 -nsInstall::Confirm(nsString& string, PRBool* aReturn) +nsInstall::ConfirmEx(nsString& aDialogTitle, nsString& aText, PRUint32 aButtonFlags, nsString& aButton0Title, nsString& aButton1Title, nsString& aButton2Title, nsString& aCheckMsg, PRBool* aCheckState, PRInt32* aReturn) { - *aReturn = PR_FALSE; /* default value */ + *aReturn = -1; /* default value */ nsPIXPIProxy *ui = GetUIThreadProxy(); if (!ui) return UNEXPECTED_ERROR; - return ui->Confirm( GetTranslatedString(NS_LITERAL_STRING("Confirm").get()), - string.get(), - aReturn); + nsAutoString title; + title.AssignLiteral("Confirm"); + if (!aDialogTitle.IsEmpty()) + { + title = aDialogTitle; + } + else if (!mUIName.IsEmpty()) + { + title = mUIName; + } + else + { + PRUnichar *t = GetTranslatedString(title.get()); + if (t) + title.Adopt(t); + } + return ui->ConfirmEx( title.get(), + aText.get(), + aButtonFlags, + aButton0Title.get(), + aButton1Title.get(), + aButton2Title.get(), + aCheckMsg.get(), + aCheckState, + aReturn); } diff --git a/xpinstall/src/nsInstall.h b/xpinstall/src/nsInstall.h index f9e507ca965..743bdce2ca8 100644 --- a/xpinstall/src/nsInstall.h +++ b/xpinstall/src/nsInstall.h @@ -22,6 +22,7 @@ * Contributor(s): * Daniel Veditz * Douglas Turner + * Jens Bannmann * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -313,7 +314,7 @@ class nsInstall PRBool InInstallTransaction(void) { return mInstalledFiles != nsnull; } PRInt32 Alert(nsString& string); - PRInt32 Confirm(nsString& string, PRBool* aReturn); + PRInt32 ConfirmEx(nsString& aDialogTitle, nsString& aText, PRUint32 aButtonFlags, nsString& aButton0Title, nsString& aButton1Title, nsString& aButton2Title, nsString& aCheckMsg, PRBool* aCheckState, PRInt32* aReturn); void InternalAbort(PRInt32 errcode); PRInt32 ScheduleForInstall(nsInstallObject* ob); diff --git a/xpinstall/src/nsJSInstall.cpp b/xpinstall/src/nsJSInstall.cpp index 352d4ec52e7..eb367f86fdc 100644 --- a/xpinstall/src/nsJSInstall.cpp +++ b/xpinstall/src/nsJSInstall.cpp @@ -20,6 +20,7 @@ * the Initial Developer. All Rights Reserved. * * Contributor(s): + * Jens Bannmann * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -46,6 +47,7 @@ #include "nsInstall.h" #include "nsInstallFile.h" #include "nsInstallTrigger.h" +#include "nsIPromptService.h" #include "nsIDOMInstallVersion.h" @@ -1573,7 +1575,7 @@ InstallAlert(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) } else { - JS_ReportError(cx, "Function LogComment requires 1 parameter"); + JS_ReportError(cx, "Function Alert requires 1 parameter"); return JS_FALSE; } @@ -1587,7 +1589,16 @@ PR_STATIC_CALLBACK(JSBool) InstallConfirm(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { nsInstall *nativeThis = (nsInstall*)JS_GetPrivate(cx, obj); - nsAutoString b0; + nsAutoString text; + nsAutoString title; + PRUint32 buttonFlags = nsIPromptService::STD_OK_CANCEL_BUTTONS; + nsAutoString button0Title; + nsAutoString button1Title; + nsAutoString button2Title; + nsAutoString checkMsg; + JSObject* checkObj = 0; + jsval jsCheckState = 0; + PRBool checkState = PR_FALSE; PRInt32 nativeRet; *rval = JSVAL_NULL; @@ -1598,26 +1609,81 @@ InstallConfirm(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rva return JS_TRUE; } - if(argc == 1) + if(argc == 0) { - // public int InstallConfirm (String aComment); - - ConvertJSValToStr(b0, cx, argv[0]); - - jsrefcount saveDepth = JS_SuspendRequest(cx);//Need to suspend use of thread or deadlock occurs - - nativeThis->Confirm(b0, &nativeRet); - - JS_ResumeRequest(cx, saveDepth); - - *rval = INT_TO_JSVAL(nativeRet); - } - else - { - JS_ReportError(cx, "Function LogComment requires 1 parameter"); + JS_ReportError(cx, "Function Confirm requires at least 1 parameter"); return JS_FALSE; } + // public int InstallConfirm (String aComment); + ConvertJSValToStr(text, cx, argv[0]); + + // Any additional parameters are optional. + // public int InstallConfirm (String aText, + // String aDialogTitle, + // Number aButtonFlags, + // String aButton0Title, + // String aButton1Title, + // String aButton2Title, + // String aCheckMsg, + // Object aCheckState); + if (argc > 1) + ConvertJSValToStr(title, cx, argv[1]); + + if(argc > 2) + { + if(!JSVAL_IS_INT(argv[2])) + { + JS_ReportError(cx, "Parameter 'aButtonFlags' must be a number"); + return JS_FALSE; + } + buttonFlags = JSVAL_TO_INT(argv[2]); + } + + if (argc > 3) + ConvertJSValToStr(button0Title, cx, argv[3]); + if (argc > 4) + ConvertJSValToStr(button1Title, cx, argv[4]); + if (argc > 5) + ConvertJSValToStr(button2Title, cx, argv[5]); + if (argc > 6) + ConvertJSValToStr(checkMsg, cx, argv[6]); + + if (argc > 7 && !JSVAL_IS_PRIMITIVE(argv[7])) + { + checkObj = JSVAL_TO_OBJECT(argv[7]); + if (!JS_GetProperty(cx, checkObj, "value", &jsCheckState) || + !JSVAL_IS_BOOLEAN(jsCheckState)) + { + JS_ReportError(cx, "Parameter 'aCheckState' must have a boolean 'value' property"); + return JS_FALSE; + } + JS_ValueToBoolean(cx, jsCheckState, &checkState); + } + + jsrefcount saveDepth = JS_SuspendRequest(cx); //Need to suspend use of thread or deadlock occurs + + nativeThis->ConfirmEx(title, text, buttonFlags, button0Title, button1Title, button2Title, checkMsg, &checkState, &nativeRet); + + JS_ResumeRequest(cx, saveDepth); + + // Only save back checkState when an object was passed as 8th parameter + if (checkObj) + { + jsCheckState = BOOLEAN_TO_JSVAL(checkState); + JS_SetProperty(cx, checkObj, "value", &jsCheckState); + } + + // To maintain compatibility with the classic one-arg confirm that returned 1 + // for OK and 0 for cancel/close, we have to swap 0 and 1 here, as confirmEx + // always returns 0 for the first (i.e. OK) button. + if (nativeRet == 0) + nativeRet = 1; // 0 = first button = OK => true(1) + else if (nativeRet == 1) + nativeRet = 0; // 1 = second button or window closed = Cancel => false(0) + + *rval = INT_TO_JSVAL(nativeRet); + return JS_TRUE; } @@ -1711,6 +1777,25 @@ static JSConstDoubleSpec install_constants[] = { nsInstall::REBOOT_NEEDED, "REBOOT_NEEDED" }, { nsInstall::INVALID_SIGNATURE, "INVALID_SIGNATURE" }, + // these are flags supported by confirm + { nsIPromptService::BUTTON_POS_0, "BUTTON_POS_0" }, + { nsIPromptService::BUTTON_POS_1, "BUTTON_POS_1" }, + { nsIPromptService::BUTTON_POS_2, "BUTTON_POS_2" }, + { nsIPromptService::BUTTON_TITLE_OK, "BUTTON_TITLE_OK" }, + { nsIPromptService::BUTTON_TITLE_CANCEL, "BUTTON_TITLE_CANCEL" }, + { nsIPromptService::BUTTON_TITLE_YES, "BUTTON_TITLE_YES" }, + { nsIPromptService::BUTTON_TITLE_NO, "BUTTON_TITLE_NO" }, + { nsIPromptService::BUTTON_TITLE_SAVE, "BUTTON_TITLE_SAVE" }, + { nsIPromptService::BUTTON_TITLE_DONT_SAVE, "BUTTON_TITLE_DONT_SAVE" }, + { nsIPromptService::BUTTON_TITLE_REVERT, "BUTTON_TITLE_REVERT" }, + { nsIPromptService::BUTTON_TITLE_IS_STRING, "BUTTON_TITLE_IS_STRING" }, + { nsIPromptService::BUTTON_POS_0_DEFAULT, "BUTTON_POS_0_DEFAULT" }, + { nsIPromptService::BUTTON_POS_1_DEFAULT, "BUTTON_POS_1_DEFAULT" }, + { nsIPromptService::BUTTON_POS_2_DEFAULT, "BUTTON_POS_2_DEFAULT" }, + { nsIPromptService::BUTTON_DELAY_ENABLE, "BUTTON_DELAY_ENABLE" }, + { nsIPromptService::STD_OK_CANCEL_BUTTONS, "STD_OK_CANCEL_BUTTONS" }, + { nsIPromptService::STD_YES_NO_BUTTONS, "STD_YES_NO_BUTTONS" }, + // these are bitwise values supported by addFile { DO_NOT_UNINSTALL, "DO_NOT_UNINSTALL" }, { WIN_SHARED_FILE, "WIN_SHARED_FILE" }, @@ -1742,7 +1827,7 @@ static JSFunctionSpec InstallMethods[] = {"addFile", InstallAddSubcomponent, 6}, {"alert", InstallAlert, 1}, {"cancelInstall", InstallAbortInstall, 1}, - {"confirm", InstallConfirm, 2}, + {"confirm", InstallConfirm, 8}, {"execute", InstallExecute, 2}, {"gestalt", InstallGestalt, 1}, {"getComponentFolder", InstallGetComponentFolder, 2}, diff --git a/xpinstall/src/nsXPIProxy.cpp b/xpinstall/src/nsXPIProxy.cpp index 473fce4740f..054badac456 100644 --- a/xpinstall/src/nsXPIProxy.cpp +++ b/xpinstall/src/nsXPIProxy.cpp @@ -22,6 +22,7 @@ * * Contributor(s): * Daniel Veditz + * Jens Bannmann * * Alternatively, the contents of this file may be used under the terms of * either of the GNU General Public License Version 2 or later (the "GPL"), @@ -93,13 +94,13 @@ nsXPIProxy::Alert(const PRUnichar* aTitle, const PRUnichar* aText) } NS_IMETHODIMP -nsXPIProxy::Confirm(const PRUnichar* aTitle, const PRUnichar* aText, PRBool *aReturn) +nsXPIProxy::ConfirmEx(const PRUnichar* aDialogTitle, const PRUnichar* aText, PRUint32 aButtonFlags, const PRUnichar* aButton0Title, const PRUnichar* aButton1Title, const PRUnichar* aButton2Title, const PRUnichar* aCheckMsg, PRBool* aCheckState, PRInt32* aReturn) { nsCOMPtr dialog(do_GetService("@mozilla.org/embedcomp/prompt-service;1")); if (!dialog) return NS_ERROR_FAILURE; - return dialog->Confirm( nsnull, aTitle, aText, aReturn ); + return dialog->ConfirmEx( nsnull, aDialogTitle, aText, aButtonFlags, aButton0Title, aButton1Title, aButton2Title, aCheckMsg, aCheckState, aReturn ); }