b=169443 Form submit buttons not working [embedding apps]

r=javi sr=rpotts
Adding files forgotton on earlier checkin
This commit is contained in:
kaie%netscape.com 2002-09-23 23:30:22 +00:00
Родитель 9b8287f271
Коммит 4422b19ce5
2 изменённых файлов: 331 добавлений и 0 удалений

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

@ -0,0 +1,272 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Terry Hayes <thayes@netscape.com>
* Javier Delgadillo <javi@netscape.com>
*/
#include "nsSecurityWarningDialogs.h"
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsReadableUtils.h"
#include "nsString.h"
#include "nsIPrompt.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
NS_IMPL_THREADSAFE_ISUPPORTS1(nsSecurityWarningDialogs, nsISecurityWarningDialogs);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
#define STRING_BUNDLE_URL "chrome://communicator/locale/security.properties"
#define ENTER_SITE_PREF "security.warn_entering_secure"
#define WEAK_SITE_PREF "security.warn_entering_weak"
#define LEAVE_SITE_PREF "security.warn_leaving_secure"
#define MIXEDCONTENT_PREF "security.warn_viewing_mixed"
#define INSECURE_SUBMIT_PREF "security.warn_submit_insecure"
nsSecurityWarningDialogs::nsSecurityWarningDialogs()
{
NS_INIT_ISUPPORTS();
}
nsSecurityWarningDialogs::~nsSecurityWarningDialogs()
{
}
nsresult
nsSecurityWarningDialogs::Init()
{
nsresult rv;
mPref = do_GetService(kPrefCID, &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIStringBundleService> service = do_GetService(kCStringBundleServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = service->CreateBundle(STRING_BUNDLE_URL,
getter_AddRefs(mStringBundle));
return rv;
}
NS_IMETHODIMP
nsSecurityWarningDialogs::AlertEnteringSecure(nsIInterfaceRequestor *ctx, PRBool *canceled)
{
nsresult rv;
rv = AlertDialog(ctx, ENTER_SITE_PREF,
NS_LITERAL_STRING("EnterSecureMessage").get(),
NS_LITERAL_STRING("EnterSecureShowAgain").get());
*canceled = PR_FALSE;
return rv;
}
NS_IMETHODIMP
nsSecurityWarningDialogs::AlertEnteringWeak(nsIInterfaceRequestor *ctx, PRBool *canceled)
{
nsresult rv;
rv = AlertDialog(ctx, WEAK_SITE_PREF,
NS_LITERAL_STRING("WeakSecureMessage").get(),
NS_LITERAL_STRING("WeakSecureShowAgain").get());
*canceled = PR_FALSE;
return rv;
}
NS_IMETHODIMP
nsSecurityWarningDialogs::AlertLeavingSecure(nsIInterfaceRequestor *ctx, PRBool *canceled)
{
nsresult rv;
rv = AlertDialog(ctx, LEAVE_SITE_PREF,
NS_LITERAL_STRING("LeaveSecureMessage").get(),
NS_LITERAL_STRING("LeaveSecureShowAgain").get());
*canceled = PR_FALSE;
return rv;
}
NS_IMETHODIMP
nsSecurityWarningDialogs::AlertMixedMode(nsIInterfaceRequestor *ctx, PRBool *canceled)
{
nsresult rv;
rv = AlertDialog(ctx, MIXEDCONTENT_PREF,
NS_LITERAL_STRING("MixedContentMessage").get(),
NS_LITERAL_STRING("MixedContentShowAgain").get());
*canceled = PR_FALSE;
return rv;
}
nsresult
nsSecurityWarningDialogs::AlertDialog(nsIInterfaceRequestor *ctx, const char *prefName,
const PRUnichar *dialogMessageName,
const PRUnichar *showAgainName)
{
nsresult rv;
// Get user's preference for this alert
PRBool prefValue;
rv = mPref->GetBoolPref(prefName, &prefValue);
if (NS_FAILED(rv)) prefValue = PR_TRUE;
// Stop if alert is not requested
if (!prefValue) return NS_OK;
// Get Prompt to use
nsCOMPtr<nsIPrompt> prompt = do_GetInterface(ctx);
if (!prompt) return NS_ERROR_FAILURE;
// Get messages strings from localization file
nsXPIDLString windowTitle, message, dontShowAgain;
mStringBundle->GetStringFromName(NS_LITERAL_STRING("Title").get(),
getter_Copies(windowTitle));
mStringBundle->GetStringFromName(dialogMessageName,
getter_Copies(message));
mStringBundle->GetStringFromName(showAgainName,
getter_Copies(dontShowAgain));
if (!windowTitle || !message || !dontShowAgain) return NS_ERROR_FAILURE;
#ifdef MOZ_PHOENIX
prefValue = PR_FALSE;
#endif
rv = prompt->AlertCheck(windowTitle, message, dontShowAgain, &prefValue);
if (NS_FAILED(rv)) return rv;
if (!prefValue) {
mPref->SetBoolPref(prefName, PR_FALSE);
}
return rv;
}
NS_IMETHODIMP
nsSecurityWarningDialogs::ConfirmPostToInsecure(nsIInterfaceRequestor *ctx, PRBool* _result)
{
nsresult rv;
rv = ConfirmDialog(ctx, INSECURE_SUBMIT_PREF,
NS_LITERAL_STRING("PostToInsecureFromInsecureMessage").get(),
NS_LITERAL_STRING("PostToInsecureFromInsecureShowAgain").get(),
_result);
return rv;
}
NS_IMETHODIMP
nsSecurityWarningDialogs::ConfirmPostToInsecureFromSecure(nsIInterfaceRequestor *ctx, PRBool* _result)
{
nsresult rv;
rv = ConfirmDialog(ctx, nsnull, // No preference for this one - it's too important
NS_LITERAL_STRING("PostToInsecureFromSecureMessage").get(),
nsnull,
_result);
return rv;
}
nsresult
nsSecurityWarningDialogs::ConfirmDialog(nsIInterfaceRequestor *ctx, const char *prefName,
const PRUnichar *messageName,
const PRUnichar *showAgainName,
PRBool* _result)
{
nsresult rv;
// Get user's preference for this alert
// prefName, showAgainName are null if there is no preference for this dialog
PRBool prefValue = PR_TRUE;
if (prefName != nsnull) {
rv = mPref->GetBoolPref(prefName, &prefValue);
if (NS_FAILED(rv)) prefValue = PR_TRUE;
}
// Stop if confirm is not requested
if (!prefValue) {
*_result = PR_TRUE;
return NS_OK;
}
// Get Prompt to use
nsCOMPtr<nsIPrompt> prompt = do_GetInterface(ctx);
if (!prompt) return NS_ERROR_FAILURE;
// Get messages strings from localization file
nsXPIDLString windowTitle, message, alertMe, cont;
mStringBundle->GetStringFromName(NS_LITERAL_STRING("Title").get(),
getter_Copies(windowTitle));
mStringBundle->GetStringFromName(messageName,
getter_Copies(message));
if (showAgainName != nsnull) {
mStringBundle->GetStringFromName(showAgainName,
getter_Copies(alertMe));
}
mStringBundle->GetStringFromName(NS_LITERAL_STRING("Continue").get(),
getter_Copies(cont));
// alertMe is allowed to be null
if (!windowTitle || !message || !cont) return NS_ERROR_FAILURE;
// Replace # characters with newlines to lay out the dialog.
PRUnichar* msgchars = NS_CONST_CAST(PRUnichar*, message.get());
PRUint32 i = 0;
for (i = 0; msgchars[i] != '\0'; i++) {
if (msgchars[i] == '#') {
msgchars[i] = '\n';
}
}
PRInt32 buttonPressed;
rv = prompt->ConfirmEx(windowTitle,
message,
(nsIPrompt::BUTTON_TITLE_IS_STRING * nsIPrompt::BUTTON_POS_0) +
(nsIPrompt::BUTTON_TITLE_CANCEL * nsIPrompt::BUTTON_POS_1),
cont,
nsnull,
nsnull,
alertMe,
&prefValue,
&buttonPressed);
if (NS_FAILED(rv)) return rv;
*_result = (buttonPressed != 1);
if (!prefValue && prefName != nsnull) {
mPref->SetBoolPref(prefName, PR_FALSE);
}
return rv;
}

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

@ -0,0 +1,59 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* 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.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2001 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Terry Hayes <thayes@netscape.com>
*/
#ifndef nsSecurityWarningDialogs_h
#define nsSecurityWarningDialogs_h
#include "nsISecurityWarningDialogs.h"
#include "nsIPref.h"
#include "nsIStringBundle.h"
#include "nsCOMPtr.h"
class nsSecurityWarningDialogs : public nsISecurityWarningDialogs
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSISECURITYWARNINGDIALOGS
nsSecurityWarningDialogs();
virtual ~nsSecurityWarningDialogs();
nsresult Init();
protected:
nsresult AlertDialog(nsIInterfaceRequestor *ctx, const char *prefName,
const PRUnichar *messageName,
const PRUnichar *showAgainName);
nsresult ConfirmDialog(nsIInterfaceRequestor *ctx, const char *prefName,
const PRUnichar *messageName,
const PRUnichar *showAgainName, PRBool* _result);
nsCOMPtr<nsIStringBundle> mStringBundle;
nsCOMPtr<nsIPref> mPref;
};
#define NS_SECURITYWARNINGDIALOGS_CID \
{ /* 8d995d4f-adcc-4159-b7f1-e94af72eeb88 */ \
0x8d995d4f, 0xadcc, 0x4159, \
{0xb7, 0xf1, 0xe9, 0x4a, 0xf7, 0x2e, 0xeb, 0x88} }
#endif