Factor the nsIPromptService implementation out of CocoaBrowserService, and move it to using a generic factory. Clean up some #includes. Change AppComponents.cpp to a .mm file since it needs to include some cocoa headers. r=pinkerton.

This commit is contained in:
bryner%netscape.com 2002-07-25 21:28:23 +00:00
parent 9070ad6df8
commit 8285e099f1
32 changed files with 2436 additions and 1708 deletions

View File

@ -36,14 +36,20 @@
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
#import "SecurityDialogs.h"
#import "CocoaPromptService.h"
#include "nsIGenericFactory.h"
// {0ffd3880-7a1a-11d6-a384-975d1d5f86fc}
#define NS_BADCERTHANDLER_CID \
{0x0ffd3880, 0x7a1a, 0x11d6,{0xa3, 0x84, 0x97, 0x5d, 0x1d, 0x5f, 0x86, 0xfc}}
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
NS_GENERIC_FACTORY_CONSTRUCTOR(SecurityDialogs);
NS_GENERIC_FACTORY_CONSTRUCTOR(CocoaPromptService);
static const nsModuleComponentInfo components[] = {
{
@ -51,6 +57,12 @@ static const nsModuleComponentInfo components[] = {
NS_BADCERTHANDLER_CID,
NS_NSSDIALOGS_CONTRACTID,
SecurityDialogsConstructor
},
{
"Prompt Service",
NS_PROMPTSERVICE_CID,
"@mozilla.org/embedcomp/prompt-service;1",
CocoaPromptServiceConstructor
}
};

View File

@ -65,6 +65,8 @@
#include "nsIClipboardCommands.h"
#include "nsIWebBrowser.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManagerUtils.h"
#include <QuickTime/QuickTime.h>

View File

@ -477,6 +477,7 @@
F50D9DF302EE194001BB4219,
F50D9DF702EE2B9B01BB4219,
F5D33CBF02EF61AA01A967F3,
F566BD1402EFA9AD01A967F3,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -597,6 +598,7 @@
F50D9DF802EE2B9B01BB4219,
F5D33CC002EF61AA01A967F3,
F5D33CC102EF61AA01A967F3,
F566BD1502EFA9AD01A967F3,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -1298,6 +1300,7 @@
F5DE10E90209DC0601A967DF,
F528E21A020FD9620168DE43,
F5D33CBE02EF61A901A967F3,
F566BD1302EFA9AD01A967F3,
);
isa = PBXGroup;
name = Dialogs;
@ -1501,6 +1504,7 @@
F50D9DE202ECC2C601BB4219,
F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3,
);
isa = PBXGroup;
name = Headers;
@ -3088,6 +3092,40 @@
settings = {
};
};
F566BD1202EFA9AD01A967F3 = {
isa = PBXFileReference;
path = CocoaPromptService.h;
refType = 2;
};
F566BD1302EFA9AD01A967F3 = {
isa = PBXFileReference;
path = CocoaPromptService.mm;
refType = 2;
};
F566BD1402EFA9AD01A967F3 = {
fileRef = F566BD1202EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1502EFA9AD01A967F3 = {
fileRef = F566BD1302EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1602EFA9AD01A967F3 = {
fileRef = F566BD1202EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1702EFA9AD01A967F3 = {
fileRef = F566BD1302EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F56769FB0208F74A010001CA = {
isa = PBXFileReference;
path = BrowserWindowController.mm;
@ -5139,6 +5177,7 @@
F5E37B0E02EE95E201A967F3,
F5E37B0F02EE95E201A967F3,
F5D33CC202EF61AA01A967F3,
F566BD1602EFA9AD01A967F3,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -5260,6 +5299,7 @@
F5E37B1202EE95E201A967F3,
F5D33CC302EF61AA01A967F3,
F5D33CC402EF61AA01A967F3,
F566BD1702EFA9AD01A967F3,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -7070,7 +7110,7 @@
};
F5D33CBD02EF61A901A967F3 = {
isa = PBXFileReference;
path = AppComponents.cpp;
path = AppComponents.mm;
refType = 2;
};
F5D33CBE02EF61A901A967F3 = {

View File

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef __CocoaPromptService_h__
#define __CocoaPromptService_h__
#include "nsIStringBundle.h"
#include "nsIPromptService.h"
#import <Cocoa/Cocoa.h>
class CocoaPromptService : public nsIPromptService
{
public:
CocoaPromptService();
virtual ~CocoaPromptService();
NS_DECL_ISUPPORTS;
NS_DECL_NSIPROMPTSERVICE;
private:
NSWindow *GetNSWindowForDOMWindow(nsIDOMWindow* window);
NSString *GetCommonDialogLocaleString(const char *s);
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
const PRUnichar *btnTitle);
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
};
#endif

View File

@ -0,0 +1,450 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#import "nsCocoaBrowserService.h"
#import "CocoaPromptService.h"
#include "nsCRT.h"
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsString.h"
#include "nsIServiceManagerUtils.h"
CocoaPromptService::CocoaPromptService()
{
NS_INIT_ISUPPORTS();
}
CocoaPromptService::~CocoaPromptService()
{
}
NS_IMPL_ISUPPORTS1(CocoaPromptService, nsIPromptService);
/* void alert (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
CocoaPromptService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (!window)
return NS_ERROR_FAILURE;
[controller alert:window title:titleStr text:textStr];
return NS_OK;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:window title:titleStr text:textStr];
}
return NS_OK;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
CocoaPromptService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
return NS_OK;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
}
return NS_OK;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
// correspond to the number of bits needed for shifting to obtain the flags for a particular
// button (should be defined in nsIPrompt*.idl instead of here)
const PRUint32 kButton0 = 0;
const PRUint32 kButton1 = 8;
const PRUint32 kButton2 = 16;
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
NS_IMETHODIMP
CocoaPromptService::ConfirmEx(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg,
PRBool *checkValue, PRInt32 *buttonPressed)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*buttonPressed = [controller confirmEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
return NS_OK;
}
/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* valueStr = [NSMutableString stringWithCharacters:*value length:(*value ? nsCRT::strlen(*value) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [valueStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[valueStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*value = retStr;
return NS_OK;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* userNameStr = [NSMutableString stringWithCharacters:*username length:(*username ? nsCRT::strlen(*username) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [userNameStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[userNameStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*username = retStr;
length = [passwordStr length];
retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [passwordStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
NS_IMETHODIMP
CocoaPromptService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 count,
const PRUnichar **selectList,
PRInt32 *outSelection,
PRBool *_retval)
{
#if DEBUG
NSLog(@"Uh-oh. Select has not been implemented.");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
NSWindow*
CocoaPromptService::GetNSWindowForDOMWindow(nsIDOMWindow* window)
{
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher) {
return nsnull;
}
nsCOMPtr<nsIWebBrowserChrome> chrome;
watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
if (!chrome) {
return nsnull;
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
if (!siteWindow) {
return nsnull;
}
NSWindow* nswin;
nsresult rv = siteWindow->GetSiteWindow((void**)&nswin);
if (NS_FAILED(rv))
return nsnull;
return nswin;
}
NSString *
CocoaPromptService::GetCommonDialogLocaleString(const char *key)
{
NSString *returnValue = @"";
nsresult rv;
if (!mCommonDialogStringBundle) {
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if ( service )
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
else
rv = NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return returnValue;
}
nsXPIDLString string;
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
if (NS_FAILED(rv)) return returnValue;
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
return returnValue;
}
NSString *
CocoaPromptService::GetButtonStringFromFlags(PRUint32 btnFlags,
PRUint32 btnIDAndShift,
const PRUnichar *btnTitle)
{
NSString *btnStr = nsnull;
switch ((btnFlags >> btnIDAndShift) & 0xff) {
case BUTTON_TITLE_OK:
btnStr = GetCommonDialogLocaleString("OK");
break;
case BUTTON_TITLE_CANCEL:
btnStr = GetCommonDialogLocaleString("Cancel");
break;
case BUTTON_TITLE_YES:
btnStr = GetCommonDialogLocaleString("Yes");
break;
case BUTTON_TITLE_NO:
btnStr = GetCommonDialogLocaleString("No");
break;
case BUTTON_TITLE_SAVE:
btnStr = GetCommonDialogLocaleString("Save");
break;
case BUTTON_TITLE_DONT_SAVE:
btnStr = GetCommonDialogLocaleString("DontSave");
break;
case BUTTON_TITLE_REVERT:
btnStr = GetCommonDialogLocaleString("Revert");
break;
case BUTTON_TITLE_IS_STRING:
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
}
return btnStr;
}

View File

@ -45,7 +45,8 @@
#include "nsIPrompt.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIServiceManagerUtils.h"
SecurityDialogs::SecurityDialogs()
{
NS_INIT_ISUPPORTS();

View File

@ -39,15 +39,12 @@
#define __nsCocoaBrowserService_h__
#import "nsAlertController.h"
#include "nsEmbedAPI.h"
#include "nsCOMPtr.h"
#include "nsIWindowCreator.h"
#include "nsIPromptService.h"
#include "nsIStringBundle.h"
#include "nsIHelperAppLauncherDialog.h"
#include "nsIFactory.h"
class nsCocoaBrowserService : public nsIWindowCreator,
public nsIPromptService,
public nsIFactory,
public nsIHelperAppLauncherDialog
{
@ -57,7 +54,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
NS_DECL_NSIPROMPTSERVICE
NS_DECL_NSIFACTORY
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
@ -72,12 +68,6 @@ public:
static PRUint32 sNumBrowsers;
private:
NSString *GetCommonDialogLocaleString(const char *s);
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
const PRUnichar *btnTitle);
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
static nsCocoaBrowserService* sSingleton;
static nsAlertController* sController;
static PRBool sCanTerminate;

View File

@ -41,22 +41,13 @@
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIProfile.h"
#include "nsIPrefService.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIPrompt.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIInterfaceRequestor.h"
#include "nsIExternalHelperAppService.h"
#include "nsIDownload.h"
#include "nsINSSDialogs.h"
#include "nsIGenericFactory.h"
#include "nsIComponentRegistrar.h"
#import "SecurityDialogs.h"
#include "nsEmbedAPI.h"
#include "nsIDownload.h"
#include "nsIExternalHelperAppService.h"
nsAlertController* nsCocoaBrowserService::sController = nsnull;
nsCocoaBrowserService* nsCocoaBrowserService::sSingleton = nsnull;
@ -65,7 +56,7 @@ PRBool nsCocoaBrowserService::sCanTerminate = PR_FALSE;
// This method should return a nsModuleComponentInfo array of
// application-provided XPCOM components to register. The implementation
// is in AppComponents.cpp.
// is in AppComponents.mm.
extern const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents);
// nsCocoaBrowserService implementation
@ -78,9 +69,8 @@ nsCocoaBrowserService::~nsCocoaBrowserService()
{
}
NS_IMPL_ISUPPORTS4(nsCocoaBrowserService,
NS_IMPL_ISUPPORTS3(nsCocoaBrowserService,
nsIWindowCreator,
nsIPromptService,
nsIFactory,
nsIHelperAppLauncherDialog)
@ -103,15 +93,6 @@ nsCocoaBrowserService::InitEmbedding()
if ( !cr )
return NS_ERROR_FAILURE;
// Register as the prompt service
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);
nsresult rv = cr->RegisterFactory(kPromptServiceCID, "Prompt Service", "@mozilla.org/embedcomp/prompt-service;1",
sSingleton);
if (NS_FAILED(rv))
return rv;
// Register as the window creator
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher)
@ -122,6 +103,7 @@ nsCocoaBrowserService::InitEmbedding()
int numComponents;
const nsModuleComponentInfo* componentInfo = GetAppModuleComponentInfo(&numComponents);
nsresult rv;
for (int i = 0; i < numComponents; ++i) {
nsCOMPtr<nsIGenericFactory> componentFactory;
rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), &(componentInfo[i]));
@ -235,396 +217,6 @@ nsCocoaBrowserService::LockFactory(PRBool lock)
return NS_OK;
}
// nsIPromptService implementation
static NSWindow*
GetNSWindowForDOMWindow(nsIDOMWindow* window)
{
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher) {
return nsnull;
}
nsCOMPtr<nsIWebBrowserChrome> chrome;
watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
if (!chrome) {
return nsnull;
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
if (!siteWindow) {
return nsnull;
}
NSWindow* nswin;
nsresult rv = siteWindow->GetSiteWindow((void**)&nswin);
if (NS_FAILED(rv))
return nsnull;
return nswin;
}
// Implementation of nsIPromptService
NS_IMETHODIMP
nsCocoaBrowserService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (!window)
return NS_ERROR_FAILURE;
[controller alert:window title:titleStr text:textStr];
return NS_OK;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:window title:titleStr text:textStr];
}
return NS_OK;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
nsCocoaBrowserService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
return NS_OK;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
}
return NS_OK;
}
NSString *
nsCocoaBrowserService::GetCommonDialogLocaleString(const char *key)
{
NSString *returnValue = @"";
nsresult rv;
if (!mCommonDialogStringBundle) {
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if ( service )
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
else
rv = NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return returnValue;
}
nsXPIDLString string;
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
if (NS_FAILED(rv)) return returnValue;
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
return returnValue;
}
NSString *
nsCocoaBrowserService::GetButtonStringFromFlags(PRUint32 btnFlags,
PRUint32 btnIDAndShift,
const PRUnichar *btnTitle)
{
NSString *btnStr = nsnull;
switch ((btnFlags >> btnIDAndShift) & 0xff) {
case BUTTON_TITLE_OK:
btnStr = GetCommonDialogLocaleString("OK");
break;
case BUTTON_TITLE_CANCEL:
btnStr = GetCommonDialogLocaleString("Cancel");
break;
case BUTTON_TITLE_YES:
btnStr = GetCommonDialogLocaleString("Yes");
break;
case BUTTON_TITLE_NO:
btnStr = GetCommonDialogLocaleString("No");
break;
case BUTTON_TITLE_SAVE:
btnStr = GetCommonDialogLocaleString("Save");
break;
case BUTTON_TITLE_DONT_SAVE:
btnStr = GetCommonDialogLocaleString("DontSave");
break;
case BUTTON_TITLE_REVERT:
btnStr = GetCommonDialogLocaleString("Revert");
break;
case BUTTON_TITLE_IS_STRING:
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
}
return btnStr;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
// correspond to the number of bits needed for shifting to obtain the flags for a particular
// button (should be defined in nsIPrompt*.idl instead of here)
const PRUint32 kButton0 = 0;
const PRUint32 kButton1 = 8;
const PRUint32 kButton2 = 16;
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
NS_IMETHODIMP
nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg,
PRBool *checkValue, PRInt32 *buttonPressed)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*buttonPressed = [controller confirmEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
return NS_OK;
}
/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* valueStr = [NSMutableString stringWithCharacters:*value length:(*value ? nsCRT::strlen(*value) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [valueStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[valueStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*value = retStr;
return NS_OK;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* userNameStr = [NSMutableString stringWithCharacters:*username length:(*username ? nsCRT::strlen(*username) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [userNameStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[userNameStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*username = retStr;
length = [passwordStr length];
retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [passwordStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
NS_IMETHODIMP
nsCocoaBrowserService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 count,
const PRUnichar **selectList,
PRInt32 *outSelection,
PRBool *_retval)
{
#if DEBUG
NSLog(@"Uh-oh. Select has not been implemented.");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
// Implementation of nsIWindowCreator
/* nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags); */

View File

@ -477,6 +477,7 @@
F50D9DF302EE194001BB4219,
F50D9DF702EE2B9B01BB4219,
F5D33CBF02EF61AA01A967F3,
F566BD1402EFA9AD01A967F3,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -597,6 +598,7 @@
F50D9DF802EE2B9B01BB4219,
F5D33CC002EF61AA01A967F3,
F5D33CC102EF61AA01A967F3,
F566BD1502EFA9AD01A967F3,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -1298,6 +1300,7 @@
F5DE10E90209DC0601A967DF,
F528E21A020FD9620168DE43,
F5D33CBE02EF61A901A967F3,
F566BD1302EFA9AD01A967F3,
);
isa = PBXGroup;
name = Dialogs;
@ -1501,6 +1504,7 @@
F50D9DE202ECC2C601BB4219,
F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3,
);
isa = PBXGroup;
name = Headers;
@ -3088,6 +3092,40 @@
settings = {
};
};
F566BD1202EFA9AD01A967F3 = {
isa = PBXFileReference;
path = CocoaPromptService.h;
refType = 2;
};
F566BD1302EFA9AD01A967F3 = {
isa = PBXFileReference;
path = CocoaPromptService.mm;
refType = 2;
};
F566BD1402EFA9AD01A967F3 = {
fileRef = F566BD1202EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1502EFA9AD01A967F3 = {
fileRef = F566BD1302EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1602EFA9AD01A967F3 = {
fileRef = F566BD1202EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1702EFA9AD01A967F3 = {
fileRef = F566BD1302EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F56769FB0208F74A010001CA = {
isa = PBXFileReference;
path = BrowserWindowController.mm;
@ -5139,6 +5177,7 @@
F5E37B0E02EE95E201A967F3,
F5E37B0F02EE95E201A967F3,
F5D33CC202EF61AA01A967F3,
F566BD1602EFA9AD01A967F3,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -5260,6 +5299,7 @@
F5E37B1202EE95E201A967F3,
F5D33CC302EF61AA01A967F3,
F5D33CC402EF61AA01A967F3,
F566BD1702EFA9AD01A967F3,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -7070,7 +7110,7 @@
};
F5D33CBD02EF61A901A967F3 = {
isa = PBXFileReference;
path = AppComponents.cpp;
path = AppComponents.mm;
refType = 2;
};
F5D33CBE02EF61A901A967F3 = {

View File

@ -36,14 +36,20 @@
*
* ***** END LICENSE BLOCK ***** */
#import <Cocoa/Cocoa.h>
#import "SecurityDialogs.h"
#import "CocoaPromptService.h"
#include "nsIGenericFactory.h"
// {0ffd3880-7a1a-11d6-a384-975d1d5f86fc}
#define NS_BADCERTHANDLER_CID \
{0x0ffd3880, 0x7a1a, 0x11d6,{0xa3, 0x84, 0x97, 0x5d, 0x1d, 0x5f, 0x86, 0xfc}}
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
NS_GENERIC_FACTORY_CONSTRUCTOR(SecurityDialogs);
NS_GENERIC_FACTORY_CONSTRUCTOR(CocoaPromptService);
static const nsModuleComponentInfo components[] = {
{
@ -51,6 +57,12 @@ static const nsModuleComponentInfo components[] = {
NS_BADCERTHANDLER_CID,
NS_NSSDIALOGS_CONTRACTID,
SecurityDialogsConstructor
},
{
"Prompt Service",
NS_PROMPTSERVICE_CID,
"@mozilla.org/embedcomp/prompt-service;1",
CocoaPromptServiceConstructor
}
};

View File

@ -65,6 +65,8 @@
#include "nsIClipboardCommands.h"
#include "nsIWebBrowser.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManagerUtils.h"
#include <QuickTime/QuickTime.h>

View File

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef __CocoaPromptService_h__
#define __CocoaPromptService_h__
#include "nsIStringBundle.h"
#include "nsIPromptService.h"
#import <Cocoa/Cocoa.h>
class CocoaPromptService : public nsIPromptService
{
public:
CocoaPromptService();
virtual ~CocoaPromptService();
NS_DECL_ISUPPORTS;
NS_DECL_NSIPROMPTSERVICE;
private:
NSWindow *GetNSWindowForDOMWindow(nsIDOMWindow* window);
NSString *GetCommonDialogLocaleString(const char *s);
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
const PRUnichar *btnTitle);
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
};
#endif

View File

@ -0,0 +1,450 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#import "nsCocoaBrowserService.h"
#import "CocoaPromptService.h"
#include "nsCRT.h"
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsString.h"
#include "nsIServiceManagerUtils.h"
CocoaPromptService::CocoaPromptService()
{
NS_INIT_ISUPPORTS();
}
CocoaPromptService::~CocoaPromptService()
{
}
NS_IMPL_ISUPPORTS1(CocoaPromptService, nsIPromptService);
/* void alert (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
CocoaPromptService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (!window)
return NS_ERROR_FAILURE;
[controller alert:window title:titleStr text:textStr];
return NS_OK;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:window title:titleStr text:textStr];
}
return NS_OK;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
CocoaPromptService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
return NS_OK;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
}
return NS_OK;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
// correspond to the number of bits needed for shifting to obtain the flags for a particular
// button (should be defined in nsIPrompt*.idl instead of here)
const PRUint32 kButton0 = 0;
const PRUint32 kButton1 = 8;
const PRUint32 kButton2 = 16;
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
NS_IMETHODIMP
CocoaPromptService::ConfirmEx(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg,
PRBool *checkValue, PRInt32 *buttonPressed)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*buttonPressed = [controller confirmEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
return NS_OK;
}
/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* valueStr = [NSMutableString stringWithCharacters:*value length:(*value ? nsCRT::strlen(*value) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [valueStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[valueStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*value = retStr;
return NS_OK;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* userNameStr = [NSMutableString stringWithCharacters:*username length:(*username ? nsCRT::strlen(*username) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [userNameStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[userNameStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*username = retStr;
length = [passwordStr length];
retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [passwordStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
NS_IMETHODIMP
CocoaPromptService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 count,
const PRUnichar **selectList,
PRInt32 *outSelection,
PRBool *_retval)
{
#if DEBUG
NSLog(@"Uh-oh. Select has not been implemented.");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
NSWindow*
CocoaPromptService::GetNSWindowForDOMWindow(nsIDOMWindow* window)
{
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher) {
return nsnull;
}
nsCOMPtr<nsIWebBrowserChrome> chrome;
watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
if (!chrome) {
return nsnull;
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
if (!siteWindow) {
return nsnull;
}
NSWindow* nswin;
nsresult rv = siteWindow->GetSiteWindow((void**)&nswin);
if (NS_FAILED(rv))
return nsnull;
return nswin;
}
NSString *
CocoaPromptService::GetCommonDialogLocaleString(const char *key)
{
NSString *returnValue = @"";
nsresult rv;
if (!mCommonDialogStringBundle) {
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if ( service )
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
else
rv = NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return returnValue;
}
nsXPIDLString string;
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
if (NS_FAILED(rv)) return returnValue;
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
return returnValue;
}
NSString *
CocoaPromptService::GetButtonStringFromFlags(PRUint32 btnFlags,
PRUint32 btnIDAndShift,
const PRUnichar *btnTitle)
{
NSString *btnStr = nsnull;
switch ((btnFlags >> btnIDAndShift) & 0xff) {
case BUTTON_TITLE_OK:
btnStr = GetCommonDialogLocaleString("OK");
break;
case BUTTON_TITLE_CANCEL:
btnStr = GetCommonDialogLocaleString("Cancel");
break;
case BUTTON_TITLE_YES:
btnStr = GetCommonDialogLocaleString("Yes");
break;
case BUTTON_TITLE_NO:
btnStr = GetCommonDialogLocaleString("No");
break;
case BUTTON_TITLE_SAVE:
btnStr = GetCommonDialogLocaleString("Save");
break;
case BUTTON_TITLE_DONT_SAVE:
btnStr = GetCommonDialogLocaleString("DontSave");
break;
case BUTTON_TITLE_REVERT:
btnStr = GetCommonDialogLocaleString("Revert");
break;
case BUTTON_TITLE_IS_STRING:
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
}
return btnStr;
}

View File

@ -45,7 +45,8 @@
#include "nsIPrompt.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIServiceManagerUtils.h"
SecurityDialogs::SecurityDialogs()
{
NS_INIT_ISUPPORTS();

View File

@ -39,15 +39,12 @@
#define __nsCocoaBrowserService_h__
#import "nsAlertController.h"
#include "nsEmbedAPI.h"
#include "nsCOMPtr.h"
#include "nsIWindowCreator.h"
#include "nsIPromptService.h"
#include "nsIStringBundle.h"
#include "nsIHelperAppLauncherDialog.h"
#include "nsIFactory.h"
class nsCocoaBrowserService : public nsIWindowCreator,
public nsIPromptService,
public nsIFactory,
public nsIHelperAppLauncherDialog
{
@ -57,7 +54,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
NS_DECL_NSIPROMPTSERVICE
NS_DECL_NSIFACTORY
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
@ -72,12 +68,6 @@ public:
static PRUint32 sNumBrowsers;
private:
NSString *GetCommonDialogLocaleString(const char *s);
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
const PRUnichar *btnTitle);
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
static nsCocoaBrowserService* sSingleton;
static nsAlertController* sController;
static PRBool sCanTerminate;

View File

@ -41,22 +41,13 @@
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIProfile.h"
#include "nsIPrefService.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIPrompt.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIInterfaceRequestor.h"
#include "nsIExternalHelperAppService.h"
#include "nsIDownload.h"
#include "nsINSSDialogs.h"
#include "nsIGenericFactory.h"
#include "nsIComponentRegistrar.h"
#import "SecurityDialogs.h"
#include "nsEmbedAPI.h"
#include "nsIDownload.h"
#include "nsIExternalHelperAppService.h"
nsAlertController* nsCocoaBrowserService::sController = nsnull;
nsCocoaBrowserService* nsCocoaBrowserService::sSingleton = nsnull;
@ -65,7 +56,7 @@ PRBool nsCocoaBrowserService::sCanTerminate = PR_FALSE;
// This method should return a nsModuleComponentInfo array of
// application-provided XPCOM components to register. The implementation
// is in AppComponents.cpp.
// is in AppComponents.mm.
extern const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents);
// nsCocoaBrowserService implementation
@ -78,9 +69,8 @@ nsCocoaBrowserService::~nsCocoaBrowserService()
{
}
NS_IMPL_ISUPPORTS4(nsCocoaBrowserService,
NS_IMPL_ISUPPORTS3(nsCocoaBrowserService,
nsIWindowCreator,
nsIPromptService,
nsIFactory,
nsIHelperAppLauncherDialog)
@ -103,15 +93,6 @@ nsCocoaBrowserService::InitEmbedding()
if ( !cr )
return NS_ERROR_FAILURE;
// Register as the prompt service
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);
nsresult rv = cr->RegisterFactory(kPromptServiceCID, "Prompt Service", "@mozilla.org/embedcomp/prompt-service;1",
sSingleton);
if (NS_FAILED(rv))
return rv;
// Register as the window creator
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher)
@ -122,6 +103,7 @@ nsCocoaBrowserService::InitEmbedding()
int numComponents;
const nsModuleComponentInfo* componentInfo = GetAppModuleComponentInfo(&numComponents);
nsresult rv;
for (int i = 0; i < numComponents; ++i) {
nsCOMPtr<nsIGenericFactory> componentFactory;
rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), &(componentInfo[i]));
@ -235,396 +217,6 @@ nsCocoaBrowserService::LockFactory(PRBool lock)
return NS_OK;
}
// nsIPromptService implementation
static NSWindow*
GetNSWindowForDOMWindow(nsIDOMWindow* window)
{
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher) {
return nsnull;
}
nsCOMPtr<nsIWebBrowserChrome> chrome;
watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
if (!chrome) {
return nsnull;
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
if (!siteWindow) {
return nsnull;
}
NSWindow* nswin;
nsresult rv = siteWindow->GetSiteWindow((void**)&nswin);
if (NS_FAILED(rv))
return nsnull;
return nswin;
}
// Implementation of nsIPromptService
NS_IMETHODIMP
nsCocoaBrowserService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (!window)
return NS_ERROR_FAILURE;
[controller alert:window title:titleStr text:textStr];
return NS_OK;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:window title:titleStr text:textStr];
}
return NS_OK;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
nsCocoaBrowserService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
return NS_OK;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
}
return NS_OK;
}
NSString *
nsCocoaBrowserService::GetCommonDialogLocaleString(const char *key)
{
NSString *returnValue = @"";
nsresult rv;
if (!mCommonDialogStringBundle) {
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if ( service )
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
else
rv = NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return returnValue;
}
nsXPIDLString string;
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
if (NS_FAILED(rv)) return returnValue;
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
return returnValue;
}
NSString *
nsCocoaBrowserService::GetButtonStringFromFlags(PRUint32 btnFlags,
PRUint32 btnIDAndShift,
const PRUnichar *btnTitle)
{
NSString *btnStr = nsnull;
switch ((btnFlags >> btnIDAndShift) & 0xff) {
case BUTTON_TITLE_OK:
btnStr = GetCommonDialogLocaleString("OK");
break;
case BUTTON_TITLE_CANCEL:
btnStr = GetCommonDialogLocaleString("Cancel");
break;
case BUTTON_TITLE_YES:
btnStr = GetCommonDialogLocaleString("Yes");
break;
case BUTTON_TITLE_NO:
btnStr = GetCommonDialogLocaleString("No");
break;
case BUTTON_TITLE_SAVE:
btnStr = GetCommonDialogLocaleString("Save");
break;
case BUTTON_TITLE_DONT_SAVE:
btnStr = GetCommonDialogLocaleString("DontSave");
break;
case BUTTON_TITLE_REVERT:
btnStr = GetCommonDialogLocaleString("Revert");
break;
case BUTTON_TITLE_IS_STRING:
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
}
return btnStr;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
// correspond to the number of bits needed for shifting to obtain the flags for a particular
// button (should be defined in nsIPrompt*.idl instead of here)
const PRUint32 kButton0 = 0;
const PRUint32 kButton1 = 8;
const PRUint32 kButton2 = 16;
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
NS_IMETHODIMP
nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg,
PRBool *checkValue, PRInt32 *buttonPressed)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*buttonPressed = [controller confirmEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
return NS_OK;
}
/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* valueStr = [NSMutableString stringWithCharacters:*value length:(*value ? nsCRT::strlen(*value) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [valueStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[valueStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*value = retStr;
return NS_OK;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* userNameStr = [NSMutableString stringWithCharacters:*username length:(*username ? nsCRT::strlen(*username) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [userNameStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[userNameStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*username = retStr;
length = [passwordStr length];
retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [passwordStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
NS_IMETHODIMP
nsCocoaBrowserService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 count,
const PRUnichar **selectList,
PRInt32 *outSelection,
PRBool *_retval)
{
#if DEBUG
NSLog(@"Uh-oh. Select has not been implemented.");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
// Implementation of nsIWindowCreator
/* nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags); */

74
chimera/AppComponents.mm Normal file
View File

@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#import <Cocoa/Cocoa.h>
#import "SecurityDialogs.h"
#import "CocoaPromptService.h"
#include "nsIGenericFactory.h"
// {0ffd3880-7a1a-11d6-a384-975d1d5f86fc}
#define NS_BADCERTHANDLER_CID \
{0x0ffd3880, 0x7a1a, 0x11d6,{0xa3, 0x84, 0x97, 0x5d, 0x1d, 0x5f, 0x86, 0xfc}}
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
NS_GENERIC_FACTORY_CONSTRUCTOR(SecurityDialogs);
NS_GENERIC_FACTORY_CONSTRUCTOR(CocoaPromptService);
static const nsModuleComponentInfo components[] = {
{
"Bad Cert Handler",
NS_BADCERTHANDLER_CID,
NS_NSSDIALOGS_CONTRACTID,
SecurityDialogsConstructor
},
{
"Prompt Service",
NS_PROMPTSERVICE_CID,
"@mozilla.org/embedcomp/prompt-service;1",
CocoaPromptServiceConstructor
}
};
const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents)
{
*outNumComponents = sizeof(components) / sizeof(components[0]);
return components;
}

View File

@ -65,6 +65,8 @@
#include "nsIClipboardCommands.h"
#include "nsIWebBrowser.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManagerUtils.h"
#include <QuickTime/QuickTime.h>

View File

@ -477,6 +477,7 @@
F50D9DF302EE194001BB4219,
F50D9DF702EE2B9B01BB4219,
F5D33CBF02EF61AA01A967F3,
F566BD1402EFA9AD01A967F3,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -597,6 +598,7 @@
F50D9DF802EE2B9B01BB4219,
F5D33CC002EF61AA01A967F3,
F5D33CC102EF61AA01A967F3,
F566BD1502EFA9AD01A967F3,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -1298,6 +1300,7 @@
F5DE10E90209DC0601A967DF,
F528E21A020FD9620168DE43,
F5D33CBE02EF61A901A967F3,
F566BD1302EFA9AD01A967F3,
);
isa = PBXGroup;
name = Dialogs;
@ -1501,6 +1504,7 @@
F50D9DE202ECC2C601BB4219,
F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3,
);
isa = PBXGroup;
name = Headers;
@ -3088,6 +3092,40 @@
settings = {
};
};
F566BD1202EFA9AD01A967F3 = {
isa = PBXFileReference;
path = CocoaPromptService.h;
refType = 2;
};
F566BD1302EFA9AD01A967F3 = {
isa = PBXFileReference;
path = CocoaPromptService.mm;
refType = 2;
};
F566BD1402EFA9AD01A967F3 = {
fileRef = F566BD1202EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1502EFA9AD01A967F3 = {
fileRef = F566BD1302EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1602EFA9AD01A967F3 = {
fileRef = F566BD1202EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1702EFA9AD01A967F3 = {
fileRef = F566BD1302EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F56769FB0208F74A010001CA = {
isa = PBXFileReference;
path = BrowserWindowController.mm;
@ -5139,6 +5177,7 @@
F5E37B0E02EE95E201A967F3,
F5E37B0F02EE95E201A967F3,
F5D33CC202EF61AA01A967F3,
F566BD1602EFA9AD01A967F3,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -5260,6 +5299,7 @@
F5E37B1202EE95E201A967F3,
F5D33CC302EF61AA01A967F3,
F5D33CC402EF61AA01A967F3,
F566BD1702EFA9AD01A967F3,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -7070,7 +7110,7 @@
};
F5D33CBD02EF61A901A967F3 = {
isa = PBXFileReference;
path = AppComponents.cpp;
path = AppComponents.mm;
refType = 2;
};
F5D33CBE02EF61A901A967F3 = {

View File

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef __CocoaPromptService_h__
#define __CocoaPromptService_h__
#include "nsIStringBundle.h"
#include "nsIPromptService.h"
#import <Cocoa/Cocoa.h>
class CocoaPromptService : public nsIPromptService
{
public:
CocoaPromptService();
virtual ~CocoaPromptService();
NS_DECL_ISUPPORTS;
NS_DECL_NSIPROMPTSERVICE;
private:
NSWindow *GetNSWindowForDOMWindow(nsIDOMWindow* window);
NSString *GetCommonDialogLocaleString(const char *s);
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
const PRUnichar *btnTitle);
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
};
#endif

View File

@ -0,0 +1,450 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#import "nsCocoaBrowserService.h"
#import "CocoaPromptService.h"
#include "nsCRT.h"
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsString.h"
#include "nsIServiceManagerUtils.h"
CocoaPromptService::CocoaPromptService()
{
NS_INIT_ISUPPORTS();
}
CocoaPromptService::~CocoaPromptService()
{
}
NS_IMPL_ISUPPORTS1(CocoaPromptService, nsIPromptService);
/* void alert (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
CocoaPromptService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (!window)
return NS_ERROR_FAILURE;
[controller alert:window title:titleStr text:textStr];
return NS_OK;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:window title:titleStr text:textStr];
}
return NS_OK;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
CocoaPromptService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
return NS_OK;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
}
return NS_OK;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
// correspond to the number of bits needed for shifting to obtain the flags for a particular
// button (should be defined in nsIPrompt*.idl instead of here)
const PRUint32 kButton0 = 0;
const PRUint32 kButton1 = 8;
const PRUint32 kButton2 = 16;
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
NS_IMETHODIMP
CocoaPromptService::ConfirmEx(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg,
PRBool *checkValue, PRInt32 *buttonPressed)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*buttonPressed = [controller confirmEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
return NS_OK;
}
/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* valueStr = [NSMutableString stringWithCharacters:*value length:(*value ? nsCRT::strlen(*value) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [valueStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[valueStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*value = retStr;
return NS_OK;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* userNameStr = [NSMutableString stringWithCharacters:*username length:(*username ? nsCRT::strlen(*username) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [userNameStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[userNameStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*username = retStr;
length = [passwordStr length];
retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [passwordStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
NS_IMETHODIMP
CocoaPromptService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 count,
const PRUnichar **selectList,
PRInt32 *outSelection,
PRBool *_retval)
{
#if DEBUG
NSLog(@"Uh-oh. Select has not been implemented.");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
NSWindow*
CocoaPromptService::GetNSWindowForDOMWindow(nsIDOMWindow* window)
{
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher) {
return nsnull;
}
nsCOMPtr<nsIWebBrowserChrome> chrome;
watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
if (!chrome) {
return nsnull;
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
if (!siteWindow) {
return nsnull;
}
NSWindow* nswin;
nsresult rv = siteWindow->GetSiteWindow((void**)&nswin);
if (NS_FAILED(rv))
return nsnull;
return nswin;
}
NSString *
CocoaPromptService::GetCommonDialogLocaleString(const char *key)
{
NSString *returnValue = @"";
nsresult rv;
if (!mCommonDialogStringBundle) {
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if ( service )
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
else
rv = NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return returnValue;
}
nsXPIDLString string;
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
if (NS_FAILED(rv)) return returnValue;
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
return returnValue;
}
NSString *
CocoaPromptService::GetButtonStringFromFlags(PRUint32 btnFlags,
PRUint32 btnIDAndShift,
const PRUnichar *btnTitle)
{
NSString *btnStr = nsnull;
switch ((btnFlags >> btnIDAndShift) & 0xff) {
case BUTTON_TITLE_OK:
btnStr = GetCommonDialogLocaleString("OK");
break;
case BUTTON_TITLE_CANCEL:
btnStr = GetCommonDialogLocaleString("Cancel");
break;
case BUTTON_TITLE_YES:
btnStr = GetCommonDialogLocaleString("Yes");
break;
case BUTTON_TITLE_NO:
btnStr = GetCommonDialogLocaleString("No");
break;
case BUTTON_TITLE_SAVE:
btnStr = GetCommonDialogLocaleString("Save");
break;
case BUTTON_TITLE_DONT_SAVE:
btnStr = GetCommonDialogLocaleString("DontSave");
break;
case BUTTON_TITLE_REVERT:
btnStr = GetCommonDialogLocaleString("Revert");
break;
case BUTTON_TITLE_IS_STRING:
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
}
return btnStr;
}

View File

@ -45,7 +45,8 @@
#include "nsIPrompt.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIServiceManagerUtils.h"
SecurityDialogs::SecurityDialogs()
{
NS_INIT_ISUPPORTS();

View File

@ -39,15 +39,12 @@
#define __nsCocoaBrowserService_h__
#import "nsAlertController.h"
#include "nsEmbedAPI.h"
#include "nsCOMPtr.h"
#include "nsIWindowCreator.h"
#include "nsIPromptService.h"
#include "nsIStringBundle.h"
#include "nsIHelperAppLauncherDialog.h"
#include "nsIFactory.h"
class nsCocoaBrowserService : public nsIWindowCreator,
public nsIPromptService,
public nsIFactory,
public nsIHelperAppLauncherDialog
{
@ -57,7 +54,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
NS_DECL_NSIPROMPTSERVICE
NS_DECL_NSIFACTORY
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
@ -72,12 +68,6 @@ public:
static PRUint32 sNumBrowsers;
private:
NSString *GetCommonDialogLocaleString(const char *s);
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
const PRUnichar *btnTitle);
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
static nsCocoaBrowserService* sSingleton;
static nsAlertController* sController;
static PRBool sCanTerminate;

View File

@ -41,22 +41,13 @@
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIProfile.h"
#include "nsIPrefService.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIPrompt.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIInterfaceRequestor.h"
#include "nsIExternalHelperAppService.h"
#include "nsIDownload.h"
#include "nsINSSDialogs.h"
#include "nsIGenericFactory.h"
#include "nsIComponentRegistrar.h"
#import "SecurityDialogs.h"
#include "nsEmbedAPI.h"
#include "nsIDownload.h"
#include "nsIExternalHelperAppService.h"
nsAlertController* nsCocoaBrowserService::sController = nsnull;
nsCocoaBrowserService* nsCocoaBrowserService::sSingleton = nsnull;
@ -65,7 +56,7 @@ PRBool nsCocoaBrowserService::sCanTerminate = PR_FALSE;
// This method should return a nsModuleComponentInfo array of
// application-provided XPCOM components to register. The implementation
// is in AppComponents.cpp.
// is in AppComponents.mm.
extern const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents);
// nsCocoaBrowserService implementation
@ -78,9 +69,8 @@ nsCocoaBrowserService::~nsCocoaBrowserService()
{
}
NS_IMPL_ISUPPORTS4(nsCocoaBrowserService,
NS_IMPL_ISUPPORTS3(nsCocoaBrowserService,
nsIWindowCreator,
nsIPromptService,
nsIFactory,
nsIHelperAppLauncherDialog)
@ -103,15 +93,6 @@ nsCocoaBrowserService::InitEmbedding()
if ( !cr )
return NS_ERROR_FAILURE;
// Register as the prompt service
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);
nsresult rv = cr->RegisterFactory(kPromptServiceCID, "Prompt Service", "@mozilla.org/embedcomp/prompt-service;1",
sSingleton);
if (NS_FAILED(rv))
return rv;
// Register as the window creator
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher)
@ -122,6 +103,7 @@ nsCocoaBrowserService::InitEmbedding()
int numComponents;
const nsModuleComponentInfo* componentInfo = GetAppModuleComponentInfo(&numComponents);
nsresult rv;
for (int i = 0; i < numComponents; ++i) {
nsCOMPtr<nsIGenericFactory> componentFactory;
rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), &(componentInfo[i]));
@ -235,396 +217,6 @@ nsCocoaBrowserService::LockFactory(PRBool lock)
return NS_OK;
}
// nsIPromptService implementation
static NSWindow*
GetNSWindowForDOMWindow(nsIDOMWindow* window)
{
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher) {
return nsnull;
}
nsCOMPtr<nsIWebBrowserChrome> chrome;
watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
if (!chrome) {
return nsnull;
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
if (!siteWindow) {
return nsnull;
}
NSWindow* nswin;
nsresult rv = siteWindow->GetSiteWindow((void**)&nswin);
if (NS_FAILED(rv))
return nsnull;
return nswin;
}
// Implementation of nsIPromptService
NS_IMETHODIMP
nsCocoaBrowserService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (!window)
return NS_ERROR_FAILURE;
[controller alert:window title:titleStr text:textStr];
return NS_OK;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:window title:titleStr text:textStr];
}
return NS_OK;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
nsCocoaBrowserService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
return NS_OK;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
}
return NS_OK;
}
NSString *
nsCocoaBrowserService::GetCommonDialogLocaleString(const char *key)
{
NSString *returnValue = @"";
nsresult rv;
if (!mCommonDialogStringBundle) {
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if ( service )
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
else
rv = NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return returnValue;
}
nsXPIDLString string;
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
if (NS_FAILED(rv)) return returnValue;
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
return returnValue;
}
NSString *
nsCocoaBrowserService::GetButtonStringFromFlags(PRUint32 btnFlags,
PRUint32 btnIDAndShift,
const PRUnichar *btnTitle)
{
NSString *btnStr = nsnull;
switch ((btnFlags >> btnIDAndShift) & 0xff) {
case BUTTON_TITLE_OK:
btnStr = GetCommonDialogLocaleString("OK");
break;
case BUTTON_TITLE_CANCEL:
btnStr = GetCommonDialogLocaleString("Cancel");
break;
case BUTTON_TITLE_YES:
btnStr = GetCommonDialogLocaleString("Yes");
break;
case BUTTON_TITLE_NO:
btnStr = GetCommonDialogLocaleString("No");
break;
case BUTTON_TITLE_SAVE:
btnStr = GetCommonDialogLocaleString("Save");
break;
case BUTTON_TITLE_DONT_SAVE:
btnStr = GetCommonDialogLocaleString("DontSave");
break;
case BUTTON_TITLE_REVERT:
btnStr = GetCommonDialogLocaleString("Revert");
break;
case BUTTON_TITLE_IS_STRING:
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
}
return btnStr;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
// correspond to the number of bits needed for shifting to obtain the flags for a particular
// button (should be defined in nsIPrompt*.idl instead of here)
const PRUint32 kButton0 = 0;
const PRUint32 kButton1 = 8;
const PRUint32 kButton2 = 16;
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
NS_IMETHODIMP
nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg,
PRBool *checkValue, PRInt32 *buttonPressed)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*buttonPressed = [controller confirmEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
return NS_OK;
}
/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* valueStr = [NSMutableString stringWithCharacters:*value length:(*value ? nsCRT::strlen(*value) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [valueStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[valueStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*value = retStr;
return NS_OK;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* userNameStr = [NSMutableString stringWithCharacters:*username length:(*username ? nsCRT::strlen(*username) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [userNameStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[userNameStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*username = retStr;
length = [passwordStr length];
retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [passwordStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
NS_IMETHODIMP
nsCocoaBrowserService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 count,
const PRUnichar **selectList,
PRInt32 *outSelection,
PRBool *_retval)
{
#if DEBUG
NSLog(@"Uh-oh. Select has not been implemented.");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
// Implementation of nsIWindowCreator
/* nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags); */

View File

@ -477,6 +477,7 @@
F50D9DF302EE194001BB4219,
F50D9DF702EE2B9B01BB4219,
F5D33CBF02EF61AA01A967F3,
F566BD1402EFA9AD01A967F3,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -597,6 +598,7 @@
F50D9DF802EE2B9B01BB4219,
F5D33CC002EF61AA01A967F3,
F5D33CC102EF61AA01A967F3,
F566BD1502EFA9AD01A967F3,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -1298,6 +1300,7 @@
F5DE10E90209DC0601A967DF,
F528E21A020FD9620168DE43,
F5D33CBE02EF61A901A967F3,
F566BD1302EFA9AD01A967F3,
);
isa = PBXGroup;
name = Dialogs;
@ -1501,6 +1504,7 @@
F50D9DE202ECC2C601BB4219,
F55C4DD302D2864D0130B065,
F5D33CBC02EF61A901A967F3,
F566BD1202EFA9AD01A967F3,
);
isa = PBXGroup;
name = Headers;
@ -3088,6 +3092,40 @@
settings = {
};
};
F566BD1202EFA9AD01A967F3 = {
isa = PBXFileReference;
path = CocoaPromptService.h;
refType = 2;
};
F566BD1302EFA9AD01A967F3 = {
isa = PBXFileReference;
path = CocoaPromptService.mm;
refType = 2;
};
F566BD1402EFA9AD01A967F3 = {
fileRef = F566BD1202EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1502EFA9AD01A967F3 = {
fileRef = F566BD1302EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1602EFA9AD01A967F3 = {
fileRef = F566BD1202EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F566BD1702EFA9AD01A967F3 = {
fileRef = F566BD1302EFA9AD01A967F3;
isa = PBXBuildFile;
settings = {
};
};
F56769FB0208F74A010001CA = {
isa = PBXFileReference;
path = BrowserWindowController.mm;
@ -5139,6 +5177,7 @@
F5E37B0E02EE95E201A967F3,
F5E37B0F02EE95E201A967F3,
F5D33CC202EF61AA01A967F3,
F566BD1602EFA9AD01A967F3,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -5260,6 +5299,7 @@
F5E37B1202EE95E201A967F3,
F5D33CC302EF61AA01A967F3,
F5D33CC402EF61AA01A967F3,
F566BD1702EFA9AD01A967F3,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -7070,7 +7110,7 @@
};
F5D33CBD02EF61A901A967F3 = {
isa = PBXFileReference;
path = AppComponents.cpp;
path = AppComponents.mm;
refType = 2;
};
F5D33CBE02EF61A901A967F3 = {

View File

@ -0,0 +1,74 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#import <Cocoa/Cocoa.h>
#import "SecurityDialogs.h"
#import "CocoaPromptService.h"
#include "nsIGenericFactory.h"
// {0ffd3880-7a1a-11d6-a384-975d1d5f86fc}
#define NS_BADCERTHANDLER_CID \
{0x0ffd3880, 0x7a1a, 0x11d6,{0xa3, 0x84, 0x97, 0x5d, 0x1d, 0x5f, 0x86, 0xfc}}
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
NS_GENERIC_FACTORY_CONSTRUCTOR(SecurityDialogs);
NS_GENERIC_FACTORY_CONSTRUCTOR(CocoaPromptService);
static const nsModuleComponentInfo components[] = {
{
"Bad Cert Handler",
NS_BADCERTHANDLER_CID,
NS_NSSDIALOGS_CONTRACTID,
SecurityDialogsConstructor
},
{
"Prompt Service",
NS_PROMPTSERVICE_CID,
"@mozilla.org/embedcomp/prompt-service;1",
CocoaPromptServiceConstructor
}
};
const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents)
{
*outNumComponents = sizeof(components) / sizeof(components[0]);
return components;
}

View File

@ -65,6 +65,8 @@
#include "nsIClipboardCommands.h"
#include "nsIWebBrowser.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIPrefBranch.h"
#include "nsIServiceManagerUtils.h"
#include <QuickTime/QuickTime.h>

View File

@ -0,0 +1,64 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#ifndef __CocoaPromptService_h__
#define __CocoaPromptService_h__
#include "nsIStringBundle.h"
#include "nsIPromptService.h"
#import <Cocoa/Cocoa.h>
class CocoaPromptService : public nsIPromptService
{
public:
CocoaPromptService();
virtual ~CocoaPromptService();
NS_DECL_ISUPPORTS;
NS_DECL_NSIPROMPTSERVICE;
private:
NSWindow *GetNSWindowForDOMWindow(nsIDOMWindow* window);
NSString *GetCommonDialogLocaleString(const char *s);
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
const PRUnichar *btnTitle);
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
};
#endif

View File

@ -0,0 +1,450 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** 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.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brian Ryner <bryner@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either 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 ***** */
#import "nsCocoaBrowserService.h"
#import "CocoaPromptService.h"
#include "nsCRT.h"
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsString.h"
#include "nsIServiceManagerUtils.h"
CocoaPromptService::CocoaPromptService()
{
NS_INIT_ISUPPORTS();
}
CocoaPromptService::~CocoaPromptService()
{
}
NS_IMPL_ISUPPORTS1(CocoaPromptService, nsIPromptService);
/* void alert (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
CocoaPromptService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (!window)
return NS_ERROR_FAILURE;
[controller alert:window title:titleStr text:textStr];
return NS_OK;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:window title:titleStr text:textStr];
}
return NS_OK;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
CocoaPromptService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
return NS_OK;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
}
return NS_OK;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
// correspond to the number of bits needed for shifting to obtain the flags for a particular
// button (should be defined in nsIPrompt*.idl instead of here)
const PRUint32 kButton0 = 0;
const PRUint32 kButton1 = 8;
const PRUint32 kButton2 = 16;
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
NS_IMETHODIMP
CocoaPromptService::ConfirmEx(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg,
PRBool *checkValue, PRInt32 *buttonPressed)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*buttonPressed = [controller confirmEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
return NS_OK;
}
/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* valueStr = [NSMutableString stringWithCharacters:*value length:(*value ? nsCRT::strlen(*value) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [valueStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[valueStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*value = retStr;
return NS_OK;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* userNameStr = [NSMutableString stringWithCharacters:*username length:(*username ? nsCRT::strlen(*username) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [userNameStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[userNameStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*username = retStr;
length = [passwordStr length];
retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
CocoaPromptService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [passwordStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
NS_IMETHODIMP
CocoaPromptService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 count,
const PRUnichar **selectList,
PRInt32 *outSelection,
PRBool *_retval)
{
#if DEBUG
NSLog(@"Uh-oh. Select has not been implemented.");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
NSWindow*
CocoaPromptService::GetNSWindowForDOMWindow(nsIDOMWindow* window)
{
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher) {
return nsnull;
}
nsCOMPtr<nsIWebBrowserChrome> chrome;
watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
if (!chrome) {
return nsnull;
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
if (!siteWindow) {
return nsnull;
}
NSWindow* nswin;
nsresult rv = siteWindow->GetSiteWindow((void**)&nswin);
if (NS_FAILED(rv))
return nsnull;
return nswin;
}
NSString *
CocoaPromptService::GetCommonDialogLocaleString(const char *key)
{
NSString *returnValue = @"";
nsresult rv;
if (!mCommonDialogStringBundle) {
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if ( service )
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
else
rv = NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return returnValue;
}
nsXPIDLString string;
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
if (NS_FAILED(rv)) return returnValue;
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
return returnValue;
}
NSString *
CocoaPromptService::GetButtonStringFromFlags(PRUint32 btnFlags,
PRUint32 btnIDAndShift,
const PRUnichar *btnTitle)
{
NSString *btnStr = nsnull;
switch ((btnFlags >> btnIDAndShift) & 0xff) {
case BUTTON_TITLE_OK:
btnStr = GetCommonDialogLocaleString("OK");
break;
case BUTTON_TITLE_CANCEL:
btnStr = GetCommonDialogLocaleString("Cancel");
break;
case BUTTON_TITLE_YES:
btnStr = GetCommonDialogLocaleString("Yes");
break;
case BUTTON_TITLE_NO:
btnStr = GetCommonDialogLocaleString("No");
break;
case BUTTON_TITLE_SAVE:
btnStr = GetCommonDialogLocaleString("Save");
break;
case BUTTON_TITLE_DONT_SAVE:
btnStr = GetCommonDialogLocaleString("DontSave");
break;
case BUTTON_TITLE_REVERT:
btnStr = GetCommonDialogLocaleString("Revert");
break;
case BUTTON_TITLE_IS_STRING:
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
}
return btnStr;
}

View File

@ -45,7 +45,8 @@
#include "nsIPrompt.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIServiceManagerUtils.h"
SecurityDialogs::SecurityDialogs()
{
NS_INIT_ISUPPORTS();

View File

@ -39,15 +39,12 @@
#define __nsCocoaBrowserService_h__
#import "nsAlertController.h"
#include "nsEmbedAPI.h"
#include "nsCOMPtr.h"
#include "nsIWindowCreator.h"
#include "nsIPromptService.h"
#include "nsIStringBundle.h"
#include "nsIHelperAppLauncherDialog.h"
#include "nsIFactory.h"
class nsCocoaBrowserService : public nsIWindowCreator,
public nsIPromptService,
public nsIFactory,
public nsIHelperAppLauncherDialog
{
@ -57,7 +54,6 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_NSIWINDOWCREATOR
NS_DECL_NSIPROMPTSERVICE
NS_DECL_NSIFACTORY
NS_DECL_NSIHELPERAPPLAUNCHERDIALOG
@ -72,12 +68,6 @@ public:
static PRUint32 sNumBrowsers;
private:
NSString *GetCommonDialogLocaleString(const char *s);
NSString *GetButtonStringFromFlags(PRUint32 btnFlags, PRUint32 btnIDAndShift,
const PRUnichar *btnTitle);
nsCOMPtr<nsIStringBundle> mCommonDialogStringBundle;
static nsCocoaBrowserService* sSingleton;
static nsAlertController* sController;
static PRBool sCanTerminate;

View File

@ -41,22 +41,13 @@
#include "nsIWindowWatcher.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsIProfile.h"
#include "nsIPrefService.h"
#include "nsCRT.h"
#include "nsString.h"
#include "nsIPrompt.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIInterfaceRequestor.h"
#include "nsIExternalHelperAppService.h"
#include "nsIDownload.h"
#include "nsINSSDialogs.h"
#include "nsIGenericFactory.h"
#include "nsIComponentRegistrar.h"
#import "SecurityDialogs.h"
#include "nsEmbedAPI.h"
#include "nsIDownload.h"
#include "nsIExternalHelperAppService.h"
nsAlertController* nsCocoaBrowserService::sController = nsnull;
nsCocoaBrowserService* nsCocoaBrowserService::sSingleton = nsnull;
@ -65,7 +56,7 @@ PRBool nsCocoaBrowserService::sCanTerminate = PR_FALSE;
// This method should return a nsModuleComponentInfo array of
// application-provided XPCOM components to register. The implementation
// is in AppComponents.cpp.
// is in AppComponents.mm.
extern const nsModuleComponentInfo* GetAppModuleComponentInfo(int* outNumComponents);
// nsCocoaBrowserService implementation
@ -78,9 +69,8 @@ nsCocoaBrowserService::~nsCocoaBrowserService()
{
}
NS_IMPL_ISUPPORTS4(nsCocoaBrowserService,
NS_IMPL_ISUPPORTS3(nsCocoaBrowserService,
nsIWindowCreator,
nsIPromptService,
nsIFactory,
nsIHelperAppLauncherDialog)
@ -103,15 +93,6 @@ nsCocoaBrowserService::InitEmbedding()
if ( !cr )
return NS_ERROR_FAILURE;
// Register as the prompt service
#define NS_PROMPTSERVICE_CID \
{0xa2112d6a, 0x0e28, 0x421f, {0xb4, 0x6a, 0x25, 0xc0, 0xb3, 0x8, 0xcb, 0xd0}}
static NS_DEFINE_CID(kPromptServiceCID, NS_PROMPTSERVICE_CID);
nsresult rv = cr->RegisterFactory(kPromptServiceCID, "Prompt Service", "@mozilla.org/embedcomp/prompt-service;1",
sSingleton);
if (NS_FAILED(rv))
return rv;
// Register as the window creator
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher)
@ -122,6 +103,7 @@ nsCocoaBrowserService::InitEmbedding()
int numComponents;
const nsModuleComponentInfo* componentInfo = GetAppModuleComponentInfo(&numComponents);
nsresult rv;
for (int i = 0; i < numComponents; ++i) {
nsCOMPtr<nsIGenericFactory> componentFactory;
rv = NS_NewGenericFactory(getter_AddRefs(componentFactory), &(componentInfo[i]));
@ -235,396 +217,6 @@ nsCocoaBrowserService::LockFactory(PRBool lock)
return NS_OK;
}
// nsIPromptService implementation
static NSWindow*
GetNSWindowForDOMWindow(nsIDOMWindow* window)
{
nsCOMPtr<nsIWindowWatcher> watcher(do_GetService("@mozilla.org/embedcomp/window-watcher;1"));
if (!watcher) {
return nsnull;
}
nsCOMPtr<nsIWebBrowserChrome> chrome;
watcher->GetChromeForWindow(window, getter_AddRefs(chrome));
if (!chrome) {
return nsnull;
}
nsCOMPtr<nsIEmbeddingSiteWindow> siteWindow(do_QueryInterface(chrome));
if (!siteWindow) {
return nsnull;
}
NSWindow* nswin;
nsresult rv = siteWindow->GetSiteWindow((void**)&nswin);
if (NS_FAILED(rv))
return nsnull;
return nswin;
}
// Implementation of nsIPromptService
NS_IMETHODIMP
nsCocoaBrowserService::Alert(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (!window)
return NS_ERROR_FAILURE;
[controller alert:window title:titleStr text:textStr];
return NS_OK;
}
/* void alertCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::AlertCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
[controller alertCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
[controller alert:window title:titleStr text:textStr];
}
return NS_OK;
}
/* boolean confirm (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text); */
NS_IMETHODIMP
nsCocoaBrowserService::Confirm(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
return NS_OK;
}
/* boolean confirmCheck (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::ConfirmCheck(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
const PRUnichar *checkMsg,
PRBool *checkValue, PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*_retval = (PRBool)[controller confirmCheck:window title:titleStr text:textStr checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*_retval = (PRBool)[controller confirm:window title:titleStr text:textStr];
}
return NS_OK;
}
NSString *
nsCocoaBrowserService::GetCommonDialogLocaleString(const char *key)
{
NSString *returnValue = @"";
nsresult rv;
if (!mCommonDialogStringBundle) {
#define kCommonDialogsStrings "chrome://global/locale/commonDialogs.properties"
nsCOMPtr<nsIStringBundleService> service = do_GetService(NS_STRINGBUNDLE_CONTRACTID);
if ( service )
rv = service->CreateBundle(kCommonDialogsStrings, getter_AddRefs(mCommonDialogStringBundle));
else
rv = NS_ERROR_FAILURE;
if (NS_FAILED(rv)) return returnValue;
}
nsXPIDLString string;
rv = mCommonDialogStringBundle->GetStringFromName(NS_ConvertASCIItoUCS2(key).get(), getter_Copies(string));
if (NS_FAILED(rv)) return returnValue;
returnValue = [NSString stringWithCharacters:string length:(string ? nsCRT::strlen(string) : 0)];
return returnValue;
}
NSString *
nsCocoaBrowserService::GetButtonStringFromFlags(PRUint32 btnFlags,
PRUint32 btnIDAndShift,
const PRUnichar *btnTitle)
{
NSString *btnStr = nsnull;
switch ((btnFlags >> btnIDAndShift) & 0xff) {
case BUTTON_TITLE_OK:
btnStr = GetCommonDialogLocaleString("OK");
break;
case BUTTON_TITLE_CANCEL:
btnStr = GetCommonDialogLocaleString("Cancel");
break;
case BUTTON_TITLE_YES:
btnStr = GetCommonDialogLocaleString("Yes");
break;
case BUTTON_TITLE_NO:
btnStr = GetCommonDialogLocaleString("No");
break;
case BUTTON_TITLE_SAVE:
btnStr = GetCommonDialogLocaleString("Save");
break;
case BUTTON_TITLE_DONT_SAVE:
btnStr = GetCommonDialogLocaleString("DontSave");
break;
case BUTTON_TITLE_REVERT:
btnStr = GetCommonDialogLocaleString("Revert");
break;
case BUTTON_TITLE_IS_STRING:
btnStr = [NSString stringWithCharacters:btnTitle length:(btnTitle ? nsCRT::strlen(btnTitle) : 0)];
}
return btnStr;
}
// these constants are used for identifying the buttons and are intentionally overloaded to
// correspond to the number of bits needed for shifting to obtain the flags for a particular
// button (should be defined in nsIPrompt*.idl instead of here)
const PRUint32 kButton0 = 0;
const PRUint32 kButton1 = 8;
const PRUint32 kButton2 = 16;
/* void confirmEx (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in unsigned long buttonFlags, in wstring button0Title, in wstring button1Title, in wstring button2Title, in wstring checkMsg, inout boolean checkValue, out PRInt32 buttonPressed); */
NS_IMETHODIMP
nsCocoaBrowserService::ConfirmEx(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 buttonFlags,
const PRUnichar *button0Title,
const PRUnichar *button1Title,
const PRUnichar *button2Title,
const PRUnichar *checkMsg,
PRBool *checkValue, PRInt32 *buttonPressed)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSWindow* window = GetNSWindowForDOMWindow(parent);
NSString* btn1Str = GetButtonStringFromFlags(buttonFlags, kButton0, button0Title);
NSString* btn2Str = GetButtonStringFromFlags(buttonFlags, kButton1, button1Title);
NSString* btn3Str = GetButtonStringFromFlags(buttonFlags, kButton2, button2Title);
if (checkValue) {
BOOL valueBool = *checkValue ? YES : NO;
*buttonPressed = [controller confirmCheckEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str
checkMsg:msgStr checkValue:&valueBool];
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
else {
*buttonPressed = [controller confirmEx:window title:titleStr text:textStr
button1: btn1Str button2: btn2Str button3: btn3Str];
}
return NS_OK;
}
/* boolean prompt (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring value, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::Prompt(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **value,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* valueStr = [NSMutableString stringWithCharacters:*value length:(*value ? nsCRT::strlen(*value) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller prompt:window title:titleStr text:textStr promptText:valueStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [valueStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[valueStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*value = retStr;
return NS_OK;
}
/* boolean promptUsernameAndPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring username, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::PromptUsernameAndPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **username,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* userNameStr = [NSMutableString stringWithCharacters:*username length:(*username ? nsCRT::strlen(*username) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptUserNameAndPassword:window title:titleStr text:textStr userNameText:userNameStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [userNameStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[userNameStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*username = retStr;
length = [passwordStr length];
retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean promptPassword (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, inout wstring password, in wstring checkMsg, inout boolean checkValue); */
NS_IMETHODIMP
nsCocoaBrowserService::PromptPassword(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUnichar **password,
const PRUnichar *checkMsg,
PRBool *checkValue,
PRBool *_retval)
{
nsAlertController* controller = GetAlertController();
if (!controller) {
return NS_ERROR_FAILURE;
}
NSString* titleStr = [NSString stringWithCharacters:dialogTitle length:(dialogTitle ? nsCRT::strlen(dialogTitle) : 0)];
NSString* textStr = [NSString stringWithCharacters:text length:(text ? nsCRT::strlen(text) : 0)];
NSString* msgStr = [NSString stringWithCharacters:checkMsg length:(checkMsg ? nsCRT::strlen(checkMsg) : 0)];
NSMutableString* passwordStr = [NSMutableString stringWithCharacters:*password length:(*password ? nsCRT::strlen(*password) : 0)];
BOOL valueBool;
if (checkValue) {
valueBool = *checkValue ? YES : NO;
}
NSWindow* window = GetNSWindowForDOMWindow(parent);
*_retval = (PRBool)[controller promptPassword:window title:titleStr text:textStr passwordText:passwordStr checkMsg:msgStr checkValue:&valueBool doCheck:(checkValue != nsnull)];
if (checkValue) {
*checkValue = (valueBool == YES) ? PR_TRUE : PR_FALSE;
}
PRUint32 length = [passwordStr length];
PRUnichar* retStr = (PRUnichar*)nsMemory::Alloc((length + 1) * sizeof(PRUnichar));
[passwordStr getCharacters:retStr];
retStr[length] = PRUnichar(0);
*password = retStr;
return NS_OK;
}
/* boolean select (in nsIDOMWindow parent, in wstring dialogTitle, in wstring text, in PRUint32 count, [array, size_is (count)] in wstring selectList, out long outSelection); */
NS_IMETHODIMP
nsCocoaBrowserService::Select(nsIDOMWindow *parent,
const PRUnichar *dialogTitle,
const PRUnichar *text,
PRUint32 count,
const PRUnichar **selectList,
PRInt32 *outSelection,
PRBool *_retval)
{
#if DEBUG
NSLog(@"Uh-oh. Select has not been implemented.");
#endif
return NS_ERROR_NOT_IMPLEMENTED;
}
// Implementation of nsIWindowCreator
/* nsIWebBrowserChrome createChromeWindow (in nsIWebBrowserChrome parent, in PRUint32 chromeFlags); */