зеркало из https://github.com/mozilla/gecko-dev.git
removing netwerk/security. It is not longer here. Look at the code in
/extensions/psm-glue. r=pavlov.
This commit is contained in:
Родитель
7695f01a74
Коммит
dd70019193
|
@ -1 +0,0 @@
|
||||||
Makefile
|
|
|
@ -1,33 +0,0 @@
|
||||||
#
|
|
||||||
# The contents of this file are subject to the Mozilla Public
|
|
||||||
# License Version 1.1 (the "License"); you may not use this file
|
|
||||||
# except in compliance with the License. You may obtain a copy of
|
|
||||||
# the License at http://www.mozilla.org/MPL/
|
|
||||||
#
|
|
||||||
# Software distributed under the License is distributed on an "AS
|
|
||||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
# implied. See the License for the specific language governing
|
|
||||||
# rights and limitations under the License.
|
|
||||||
#
|
|
||||||
# The Original Code is mozilla.org code.
|
|
||||||
#
|
|
||||||
# The Initial Developer of the Original Code is Netscape
|
|
||||||
# Communications Corporation. Portions created by Netscape are
|
|
||||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
# Rights Reserved.
|
|
||||||
#
|
|
||||||
# Contributor(s):
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
DEPTH = ../..
|
|
||||||
topsrcdir = @top_srcdir@
|
|
||||||
srcdir = @srcdir@
|
|
||||||
VPATH = @srcdir@
|
|
||||||
|
|
||||||
include $(DEPTH)/config/autoconf.mk
|
|
||||||
|
|
||||||
DIRS = browser psm
|
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
Makefile
|
|
|
@ -1,2 +0,0 @@
|
||||||
NavSecurityOverlay.xul
|
|
||||||
NavSecurityUI.js
|
|
|
@ -1,4 +0,0 @@
|
||||||
lock.gif
|
|
||||||
unlock.gif
|
|
||||||
broken.gif
|
|
||||||
NavSecurityOverlay.css
|
|
|
@ -1,67 +0,0 @@
|
||||||
#
|
|
||||||
# The contents of this file are subject to the Mozilla Public
|
|
||||||
# License Version 1.1 (the "License"); you may not use this file
|
|
||||||
# except in compliance with the License. You may obtain a copy of
|
|
||||||
# the License at http://www.mozilla.org/MPL/
|
|
||||||
#
|
|
||||||
# Software distributed under the License is distributed on an "AS
|
|
||||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
# implied. See the License for the specific language governing
|
|
||||||
# rights and limitations under the License.
|
|
||||||
#
|
|
||||||
# The Original Code is mozilla.org code.
|
|
||||||
#
|
|
||||||
# The Initial Developer of the Original Code is Netscape
|
|
||||||
# Communications Corporation. Portions created by Netscape are
|
|
||||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
# Rights Reserved.
|
|
||||||
#
|
|
||||||
# Contributor(s):
|
|
||||||
#
|
|
||||||
|
|
||||||
DEPTH = ../../..
|
|
||||||
topsrcdir = @top_srcdir@
|
|
||||||
srcdir = @srcdir@
|
|
||||||
VPATH = @srcdir@
|
|
||||||
|
|
||||||
include $(DEPTH)/config/autoconf.mk
|
|
||||||
|
|
||||||
MODULE = secureui
|
|
||||||
|
|
||||||
IS_COMPONENT = 1
|
|
||||||
LIBRARY_NAME = secureui
|
|
||||||
|
|
||||||
CPPSRCS = \
|
|
||||||
nsSecureBrowserUIImpl.cpp \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
EXTRA_DSO_LDOPTS = -L$(DIST)/lib -lxpcom
|
|
||||||
|
|
||||||
XPIDLSRCS = \
|
|
||||||
nsSecureBrowserUI.idl \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
|
||||||
|
|
||||||
SKIN_DIR = $(DIST)/bin/chrome/navigator/skin/default/
|
|
||||||
EXPORT_SKINS = \
|
|
||||||
$(srcdir)/broken.gif \
|
|
||||||
$(srcdir)/lock.gif \
|
|
||||||
$(srcdir)/unlock.gif \
|
|
||||||
$(srcdir)/NavSecurityOverlay.css \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
CONTENT_DIR = $(DIST)/bin/chrome/navigator/content/default/
|
|
||||||
EXPORT_CONTENT = \
|
|
||||||
$(srcdir)/NavSecurityOverlay.xul \
|
|
||||||
$(srcdir)/NavSecurityUI.js \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
install::
|
|
||||||
$(INSTALL) $(EXPORT_SKINS) $(SKIN_DIR)
|
|
||||||
$(INSTALL) $(EXPORT_CONTENT) $(CONTENT_DIR)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
titledbutton#security-button {
|
|
||||||
list-style-image:url("chrome://navigator/skin/unlock.gif");
|
|
||||||
}
|
|
||||||
|
|
||||||
titledbutton#security-button[level="high"] {
|
|
||||||
list-style-image:url("chrome://navigator/skin/lock.gif");
|
|
||||||
}
|
|
||||||
|
|
||||||
titledbutton#security-button[level="low"] {
|
|
||||||
list-style-image:url("chrome://navigator/skin/lock.gif");
|
|
||||||
}
|
|
||||||
|
|
||||||
titledbutton#security-button[level="broken"] {
|
|
||||||
list-style-image:url("chrome://navigator/skin/broken.gif");
|
|
||||||
}
|
|
|
@ -1,14 +0,0 @@
|
||||||
<?xml version="1.0"?>
|
|
||||||
|
|
||||||
<overlay id="NavSecurityOverlay"
|
|
||||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
|
||||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
|
||||||
|
|
||||||
<?xml-stylesheet href="chrome://navigator/skin/NavSecurityOverlay.css" type="text/css"?>
|
|
||||||
<html:script language="JavaScript" src="chrome://navigator/content/NavSecurityUI.js" />
|
|
||||||
|
|
||||||
<box id="state-box">
|
|
||||||
<titledbutton id="security-button" class="borderless" align="left" onclick="displayPageInfo()"/>
|
|
||||||
</box>
|
|
||||||
|
|
||||||
</overlay>
|
|
|
@ -1,44 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
window.addEventListener("load", SetSecurityButton, false);
|
|
||||||
|
|
||||||
function SetSecurityButton()
|
|
||||||
{
|
|
||||||
dump("in SetSecurityButton\n");
|
|
||||||
|
|
||||||
var ui = Components.classes["component://netscape/secure_browser_ui"].getService();
|
|
||||||
ui = ui.QueryInterface(Components.interfaces.nsSecureBrowserUI);
|
|
||||||
|
|
||||||
var button = document.getElementById('security-button');
|
|
||||||
if (button && window.content)
|
|
||||||
ui.init(window.content, button);
|
|
||||||
}
|
|
||||||
|
|
||||||
function displayPageInfo()
|
|
||||||
{
|
|
||||||
var psm = Components.classes["component://netscape/psm"].getService();
|
|
||||||
psm = psm.QueryInterface(Components.interfaces.nsIPSMComponent);
|
|
||||||
psm.DisplaySecurityAdvisor( null );
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
Двоичные данные
netwerk/security/browser/broken.gif
Двоичные данные
netwerk/security/browser/broken.gif
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 88 B |
Двоичные данные
netwerk/security/browser/lock.gif
Двоичные данные
netwerk/security/browser/lock.gif
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 76 B |
|
@ -1,72 +0,0 @@
|
||||||
#!nmake
|
|
||||||
#
|
|
||||||
# The contents of this file are subject to the Mozilla Public
|
|
||||||
# License Version 1.1 (the "License"); you may not use this file
|
|
||||||
# except in compliance with the License. You may obtain a copy of
|
|
||||||
# the License at http://www.mozilla.org/MPL/
|
|
||||||
#
|
|
||||||
# Software distributed under the License is distributed on an "AS
|
|
||||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
# implied. See the License for the specific language governing
|
|
||||||
# rights and limitations under the License.
|
|
||||||
#
|
|
||||||
# The Original Code is mozilla.org code.
|
|
||||||
#
|
|
||||||
# The Initial Developer of the Original Code is Netscape
|
|
||||||
# Communications Corporation. Portions created by Netscape are
|
|
||||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
# Rights Reserved.
|
|
||||||
#
|
|
||||||
# Contributor(s):
|
|
||||||
#
|
|
||||||
|
|
||||||
MODULE = secureui
|
|
||||||
|
|
||||||
DEPTH=..\..\..
|
|
||||||
IGNORE_MANIFEST=1
|
|
||||||
|
|
||||||
DLLNAME = secureui
|
|
||||||
PDBFILE = $(DLLNAME).pdb
|
|
||||||
MAPFILE = $(DLLNAME).map
|
|
||||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
|
||||||
MAKE_OBJ_TYPE = DLL
|
|
||||||
|
|
||||||
include <$(DEPTH)/config/config.mak>
|
|
||||||
|
|
||||||
LINCS = $(LINCS) \
|
|
||||||
-I$(PUBLIC) \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LLIBS = \
|
|
||||||
$(LIBNSPR) \
|
|
||||||
$(DIST)\lib\xpcom.lib \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
OBJS = \
|
|
||||||
.\$(OBJDIR)\nsSecureBrowserUIImpl.obj \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
XPIDL_INCLUDES=-I$(DEPTH)\..\mozilla\dist\idl
|
|
||||||
|
|
||||||
XPIDLSRCS= \
|
|
||||||
.\nsSecureBrowserUI.idl \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
include <$(DEPTH)\config\rules.mak>
|
|
||||||
|
|
||||||
install:: $(DLL)
|
|
||||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
|
||||||
$(MAKE_INSTALL) broken.gif $(DIST)\bin\chrome\navigator\skin\default
|
|
||||||
$(MAKE_INSTALL) lock.gif $(DIST)\bin\chrome\navigator\skin\default
|
|
||||||
$(MAKE_INSTALL) unlock.gif $(DIST)\bin\chrome\navigator\skin\default
|
|
||||||
$(MAKE_INSTALL) NavSecurityOverlay.xul $(DIST)\bin\chrome\navigator\content\default
|
|
||||||
$(MAKE_INSTALL) NavSecurityUI.js $(DIST)\bin\chrome\navigator\content\default
|
|
||||||
$(MAKE_INSTALL) NavSecurityOverlay.css $(DIST)\bin\chrome\navigator\skin\default
|
|
||||||
|
|
||||||
clobber::
|
|
||||||
rm $(DIST)\bin\components\$(DLLNAME).dll
|
|
||||||
rm $(DIST)\bin\chrome\navigator\skin\default\broken.gif
|
|
||||||
rm $(DIST)\bin\chrome\navigator\skin\default\lock.gif
|
|
||||||
rm $(DIST)\bin\chrome\navigator\skin\default\unlock.gif
|
|
||||||
rm $(DIST)\bin\chrome\navigator\content\default\NavSecurityOverlay.xul
|
|
||||||
rm $(DIST)\bin\chrome\navigator\skin\default\NavSecurityOverlay.css
|
|
|
@ -1,41 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nsISupports.idl"
|
|
||||||
|
|
||||||
interface nsIDOMWindow;
|
|
||||||
interface nsIDOMElement;
|
|
||||||
|
|
||||||
[scriptable, uuid(081e31e0-a144-11d3-8c7c-00609792278c)]
|
|
||||||
interface nsSecureBrowserUI : nsISupports
|
|
||||||
{
|
|
||||||
void init(in nsIDOMWindow window, in nsIDOMElement button);
|
|
||||||
};
|
|
||||||
|
|
||||||
%{C++
|
|
||||||
#define NS_SECURE_BROWSER_UI_PROGID "component://netscape/secure_browser_ui"
|
|
||||||
#define NS_SECURE_BROWSER_UI_CLASSNAME "Mozilla Secure Browser UI Handler"
|
|
||||||
|
|
||||||
#define NS_SECURE_BROWSER_UI_CID \
|
|
||||||
{ 0x10fe7ea0, 0xa10a, 0x11d3, {0x8c, 0x7c, 0x00, 0x60, 0x97, 0x92, 0x27, 0x8c}}
|
|
||||||
|
|
||||||
%}
|
|
|
@ -1,503 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nsSecureBrowserUI.h"
|
|
||||||
#include "nsSecureBrowserUIImpl.h"
|
|
||||||
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsIServiceManager.h"
|
|
||||||
|
|
||||||
#include "nsIScriptGlobalObject.h"
|
|
||||||
#include "nsIObserverService.h"
|
|
||||||
#include "nsIDocumentLoader.h"
|
|
||||||
#include "nsCURILoader.h"
|
|
||||||
#include "nsIDocShell.h"
|
|
||||||
#include "nsIDocumentViewer.h"
|
|
||||||
#include "nsCURILoader.h"
|
|
||||||
#include "nsIDocument.h"
|
|
||||||
#include "nsIDOMHTMLDocument.h"
|
|
||||||
#include "nsIDOMXULDocument.h"
|
|
||||||
#include "nsIDOMElement.h"
|
|
||||||
#include "nsIDOMWindow.h"
|
|
||||||
#include "nsIChannel.h"
|
|
||||||
|
|
||||||
#include "nsIURI.h"
|
|
||||||
|
|
||||||
#include "prmem.h"
|
|
||||||
|
|
||||||
#include "nsIModule.h"
|
|
||||||
#include "nsIGenericFactory.h"
|
|
||||||
|
|
||||||
#include "nsINetSupportDialogService.h"
|
|
||||||
#include "nsIPrompt.h"
|
|
||||||
#include "nsIPref.h"
|
|
||||||
|
|
||||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
|
||||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
|
||||||
|
|
||||||
|
|
||||||
#define ENTER_SITE_PREF "security.warn_entering_secure"
|
|
||||||
#define LEAVE_SITE_PREF "security.warn_leaving_secure"
|
|
||||||
#define MIXEDCONTENT_PREF "security.warn_viewing_mixed"
|
|
||||||
#define INSECURE_SUBMIT_PREF "security.warn_submit_insecure"
|
|
||||||
|
|
||||||
|
|
||||||
nsSecureBrowserUIImpl* nsSecureBrowserUIImpl::mInstance = nsnull;
|
|
||||||
|
|
||||||
nsSecureBrowserUIImpl::nsSecureBrowserUIImpl()
|
|
||||||
{
|
|
||||||
NS_INIT_REFCNT();
|
|
||||||
}
|
|
||||||
|
|
||||||
nsSecureBrowserUIImpl::~nsSecureBrowserUIImpl()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS1(nsSecureBrowserUIImpl, nsSecureBrowserUI);
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsSecureBrowserUIImpl::CreateSecureBrowserUI(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
|
||||||
{
|
|
||||||
if (!aResult) {
|
|
||||||
return NS_ERROR_INVALID_POINTER;
|
|
||||||
}
|
|
||||||
if (aOuter) {
|
|
||||||
*aResult = nsnull;
|
|
||||||
return NS_ERROR_NO_AGGREGATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInstance == nsnull)
|
|
||||||
{
|
|
||||||
mInstance = new nsSecureBrowserUIImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInstance == nsnull)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
nsresult rv = mInstance->QueryInterface(aIID, aResult);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
{
|
|
||||||
*aResult = nsnull;
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsSecureBrowserUIImpl::Init(nsIDOMWindow *window, nsIDOMElement *button)
|
|
||||||
{
|
|
||||||
|
|
||||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
|
|
||||||
if (sgo)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDocShell> docShell;
|
|
||||||
|
|
||||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
|
||||||
if (docShell)
|
|
||||||
{
|
|
||||||
nsSecureBrowserObserver *sbo = new nsSecureBrowserObserver();
|
|
||||||
if (sbo)
|
|
||||||
{
|
|
||||||
NS_ADDREF(sbo);
|
|
||||||
return sbo->Init(button, docShell); // does the window delete us when it close?
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsSecureBrowserObserver::nsSecureBrowserObserver()
|
|
||||||
{
|
|
||||||
NS_INIT_REFCNT();
|
|
||||||
mIsSecureDocument = mMixContentAlertShown = mIsDocumentBroken = PR_FALSE;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
nsSecureBrowserObserver::~nsSecureBrowserObserver()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS1(nsSecureBrowserObserver, nsIDocumentLoaderObserver);
|
|
||||||
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsSecureBrowserObserver::Init(nsIDOMElement *button, nsIDocShell* content)
|
|
||||||
{
|
|
||||||
if (!button || !content)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
mSecurityButton = button;
|
|
||||||
content->GetDocLoaderObserver(getter_AddRefs(mOldWebShellObserver));
|
|
||||||
content->SetDocLoaderObserver(this);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsSecureBrowserObserver::OnStartDocumentLoad(nsIDocumentLoader* aLoader,
|
|
||||||
nsIURI* aURL,
|
|
||||||
const char* aCommand)
|
|
||||||
{
|
|
||||||
nsresult res;
|
|
||||||
|
|
||||||
if (mOldWebShellObserver)
|
|
||||||
{
|
|
||||||
mOldWebShellObserver->OnStartDocumentLoad(aLoader, aURL, aCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!mSecurityButton)
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
if (!aURL || !aLoader)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
|
|
||||||
mIsSecureDocument = mMixContentAlertShown = mIsDocumentBroken = PR_FALSE;
|
|
||||||
|
|
||||||
// check to see that we are going to load the same
|
|
||||||
// kind of URL (scheme) as we just loaded.
|
|
||||||
|
|
||||||
|
|
||||||
PRBool isOldSchemeSecure;
|
|
||||||
res = IsSecureDocumentLoad(aLoader, &isOldSchemeSecure);
|
|
||||||
if (NS_FAILED(res))
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
PRBool isNewSchemeSecure;
|
|
||||||
res = IsSecureUrl(PR_FALSE, aURL, &isNewSchemeSecure);
|
|
||||||
if (NS_FAILED(res))
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
#if DEBUG_dougt
|
|
||||||
printf("[StartPageLoad] isOldSchemeSecure = %d isNewSchemeSecure = %d\n", isOldSchemeSecure, isNewSchemeSecure);
|
|
||||||
#endif
|
|
||||||
// if we are going from a secure page to and insecure page
|
|
||||||
if ( !isNewSchemeSecure && isOldSchemeSecure)
|
|
||||||
{
|
|
||||||
#if DEBUG_dougt
|
|
||||||
printf("change lock icon to unlock - new document\n");
|
|
||||||
#endif
|
|
||||||
mSecurityButton->RemoveAttribute( "level" );
|
|
||||||
|
|
||||||
|
|
||||||
PRBool boolpref;
|
|
||||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res);
|
|
||||||
if (NS_FAILED(res))
|
|
||||||
return res;
|
|
||||||
|
|
||||||
if ((prefs->GetBoolPref(LEAVE_SITE_PREF, &boolpref) != 0))
|
|
||||||
boolpref = PR_TRUE;
|
|
||||||
|
|
||||||
if (boolpref)
|
|
||||||
{
|
|
||||||
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &res);
|
|
||||||
if (NS_FAILED(res))
|
|
||||||
return res;
|
|
||||||
|
|
||||||
dialog->Alert(nsString("You are leaving a secure document").GetUnicode()); // fix localize!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// if we are going from an insecure page to a secure one.
|
|
||||||
else if (isNewSchemeSecure && !isOldSchemeSecure)
|
|
||||||
{
|
|
||||||
PRBool boolpref;
|
|
||||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res);
|
|
||||||
if (NS_FAILED(res))
|
|
||||||
return res;
|
|
||||||
|
|
||||||
if ((prefs->GetBoolPref(ENTER_SITE_PREF, &boolpref) != 0))
|
|
||||||
boolpref = PR_TRUE;
|
|
||||||
|
|
||||||
if (boolpref)
|
|
||||||
{
|
|
||||||
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &res);
|
|
||||||
if (NS_FAILED(res))
|
|
||||||
return res;
|
|
||||||
|
|
||||||
dialog->Alert(nsString("You are entering a secure document").GetUnicode()); // fix localize!
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mIsSecureDocument = isNewSchemeSecure;
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsSecureBrowserObserver::OnEndDocumentLoad(nsIDocumentLoader* aLoader,
|
|
||||||
nsIChannel* channel,
|
|
||||||
nsresult aStatus)
|
|
||||||
{
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
if (mOldWebShellObserver)
|
|
||||||
{
|
|
||||||
mOldWebShellObserver->OnEndDocumentLoad(aLoader, channel, aStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mIsSecureDocument)
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
if (!mSecurityButton)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
#if DEBUG_dougt
|
|
||||||
printf("[EndPageLoad] mIsSecureDocument = %d aStatus = %d mIsDocumentBroken = %d\n", mIsSecureDocument, aStatus, mIsDocumentBroken);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ( NS_SUCCEEDED(aStatus) && !mIsDocumentBroken )
|
|
||||||
{
|
|
||||||
#if DEBUG_dougt
|
|
||||||
printf("change lock icon to secure \n");
|
|
||||||
#endif
|
|
||||||
rv = mSecurityButton->SetAttribute( "level", nsString("high") );
|
|
||||||
mIsSecureDocument = PR_TRUE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#if DEBUG_dougt
|
|
||||||
printf("change lock icon to broken\n");
|
|
||||||
#endif
|
|
||||||
rv = mSecurityButton->SetAttribute( "level", nsString("broken") );
|
|
||||||
mIsSecureDocument = PR_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsSecureBrowserObserver::OnStartURLLoad(nsIDocumentLoader* loader,
|
|
||||||
nsIChannel* channel)
|
|
||||||
{
|
|
||||||
if (mOldWebShellObserver)
|
|
||||||
{
|
|
||||||
mOldWebShellObserver->OnStartURLLoad(loader, channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG_dougt
|
|
||||||
printf("[StartURLLoad] mIsSecureDocument = %d\n", mIsSecureDocument);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
PRBool secure;
|
|
||||||
nsresult rv = IsSecureChannelLoad(channel, &secure);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
if (mIsSecureDocument && !secure)
|
|
||||||
{
|
|
||||||
mIsDocumentBroken = PR_TRUE;
|
|
||||||
|
|
||||||
// nsCOMPtr<nsIURI> uri;
|
|
||||||
// channel->GetURI(getter_AddRefs(uri));
|
|
||||||
|
|
||||||
// uri->SetSpec("chrome://navigator/skin/insecureLink.gif"); //fix
|
|
||||||
|
|
||||||
nsresult res;
|
|
||||||
|
|
||||||
PRBool boolpref;
|
|
||||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res);
|
|
||||||
if (NS_FAILED(res))
|
|
||||||
return res;
|
|
||||||
|
|
||||||
if ((prefs->GetBoolPref(MIXEDCONTENT_PREF, &boolpref) != 0))
|
|
||||||
boolpref = PR_TRUE;
|
|
||||||
|
|
||||||
if (boolpref && !mMixContentAlertShown)
|
|
||||||
{
|
|
||||||
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &res);
|
|
||||||
if (NS_FAILED(res))
|
|
||||||
return res;
|
|
||||||
|
|
||||||
dialog->Alert(nsString("There is mixed content on this page").GetUnicode()); // fix localize!
|
|
||||||
mMixContentAlertShown = PR_TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsSecureBrowserObserver::OnProgressURLLoad(nsIDocumentLoader* loader,
|
|
||||||
nsIChannel* channel,
|
|
||||||
PRUint32 aProgress,
|
|
||||||
PRUint32 aProgressMax)
|
|
||||||
{
|
|
||||||
if (mOldWebShellObserver)
|
|
||||||
{
|
|
||||||
mOldWebShellObserver->OnProgressURLLoad(loader, channel, aProgress, aProgressMax);
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsSecureBrowserObserver::OnStatusURLLoad(nsIDocumentLoader* loader,
|
|
||||||
nsIChannel* channel,
|
|
||||||
nsString& aMsg)
|
|
||||||
{
|
|
||||||
if (mOldWebShellObserver)
|
|
||||||
{
|
|
||||||
mOldWebShellObserver->OnStatusURLLoad(loader, channel, aMsg);
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsSecureBrowserObserver::OnEndURLLoad(nsIDocumentLoader* loader,
|
|
||||||
nsIChannel* channel,
|
|
||||||
nsresult aStatus)
|
|
||||||
{
|
|
||||||
if (mOldWebShellObserver)
|
|
||||||
{
|
|
||||||
mOldWebShellObserver->OnEndURLLoad(loader, channel, aStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if DEBUG_dougt
|
|
||||||
printf("[OnEndURLLoad] mIsSecureDocument = %d aStatus = %d\n", mIsSecureDocument, aStatus);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ( mIsSecureDocument && NS_FAILED(aStatus))
|
|
||||||
{
|
|
||||||
#if DEBUG_dougt
|
|
||||||
printf("change lock icon to broken\n");
|
|
||||||
#endif
|
|
||||||
mSecurityButton->SetAttribute( "level", nsString("broken") );
|
|
||||||
mIsDocumentBroken = PR_TRUE;
|
|
||||||
}
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
// fileSecure flag determines if we should include file: and other local protocols.
|
|
||||||
nsresult
|
|
||||||
nsSecureBrowserObserver::IsSecureUrl(PRBool fileSecure, nsIURI* aURL, PRBool* value)
|
|
||||||
{
|
|
||||||
*value = PR_FALSE;
|
|
||||||
|
|
||||||
if (!aURL)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
#if DEBUG_dougt
|
|
||||||
char* string;
|
|
||||||
aURL->GetSpec(&string);
|
|
||||||
printf("[ensuring channel]: %s\n", string);
|
|
||||||
nsAllocator::Free(string);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
char* scheme;
|
|
||||||
aURL->GetScheme(&scheme);
|
|
||||||
|
|
||||||
if (scheme == nsnull)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
if ( (strncmp(scheme, "https", 5) == 0) ||
|
|
||||||
(fileSecure &&
|
|
||||||
(strncmp(scheme, "file", 4) == 0) ))
|
|
||||||
*value = PR_TRUE;
|
|
||||||
|
|
||||||
nsAllocator::Free(scheme);
|
|
||||||
return NS_OK;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsresult nsSecureBrowserObserver::IsSecureDocumentLoad(nsIDocumentLoader* loader, PRBool *value)
|
|
||||||
{
|
|
||||||
if (!loader)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
|
||||||
nsresult rv = GetURIFromDocumentLoader(loader, getter_AddRefs(uri));
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
return IsSecureUrl(PR_FALSE, uri, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult nsSecureBrowserObserver::IsSecureChannelLoad(nsIChannel* channel, PRBool *value)
|
|
||||||
{
|
|
||||||
if (!channel)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
|
||||||
nsresult rv = channel->GetURI(getter_AddRefs(uri));
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
return IsSecureUrl(PR_TRUE, uri, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsSecureBrowserObserver::GetURIFromDocumentLoader(nsIDocumentLoader* aLoader, nsIURI** uri)
|
|
||||||
{
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
if (aLoader == nsnull)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
nsCOMPtr<nsISupports> cont;
|
|
||||||
rv = aLoader->GetContainer(getter_AddRefs(cont));
|
|
||||||
if (NS_FAILED(rv) || (cont == nsnull))
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(cont));
|
|
||||||
NS_ENSURE_TRUE(docShell, NS_ERROR_FAILURE);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIContentViewer> cv;
|
|
||||||
rv = docShell->GetContentViewer(getter_AddRefs(cv));
|
|
||||||
if (NS_FAILED(rv) || (cv == nsnull))
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(cv));
|
|
||||||
NS_ENSURE_TRUE(docViewer, NS_ERROR_FAILURE);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> doc;
|
|
||||||
rv = docViewer->GetDocument(*getter_AddRefs(doc));
|
|
||||||
if (NS_FAILED(rv) || (doc == nsnull))
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
*uri = doc->GetDocumentURL();
|
|
||||||
if (!*uri)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static nsModuleComponentInfo components[] =
|
|
||||||
{
|
|
||||||
{ NS_SECURE_BROWSER_UI_CLASSNAME,
|
|
||||||
NS_SECURE_BROWSER_UI_CID,
|
|
||||||
NS_SECURE_BROWSER_UI_PROGID,
|
|
||||||
nsSecureBrowserUIImpl::CreateSecureBrowserUI
|
|
||||||
},
|
|
||||||
|
|
||||||
{ NS_SECURE_BROWSER_DOCOBSERVER_CLASSNAME,
|
|
||||||
NS_SECURE_BROWSER_DOCOBSERVER_CID,
|
|
||||||
NS_SECURE_BROWSER_DOCOBSERVER_PROGID,
|
|
||||||
nsSecureBrowserUIImpl::CreateSecureBrowserUI
|
|
||||||
},
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
NS_IMPL_NSGETMODULE("nsSecureBrowserUIImpl", components)
|
|
||||||
|
|
|
@ -1,92 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef nsSecureBrowserUIImpl_h_
|
|
||||||
#define nsSecureBrowserUIImpl_h_
|
|
||||||
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsXPIDLString.h"
|
|
||||||
#include "nsString.h"
|
|
||||||
#include "nsIObserver.h"
|
|
||||||
#include "nsIDocumentLoaderObserver.h"
|
|
||||||
#include "nsIDOMElement.h"
|
|
||||||
#include "nsSecureBrowserUI.h"
|
|
||||||
#include "nsIDocShell.h"
|
|
||||||
|
|
||||||
#define NS_SECURE_BROWSER_DOCOBSERVER_CLASSNAME "Mozilla Secure Browser Doc Observer"
|
|
||||||
|
|
||||||
#define NS_SECURE_BROWSER_DOCOBSERVER_CID \
|
|
||||||
{0x97c06c30, 0xa145, 0x11d3, \
|
|
||||||
{0x8c, 0x7c, 0x00, 0x60, 0x97, 0x92, 0x27, 0x8c}}
|
|
||||||
|
|
||||||
#define NS_SECURE_BROWSER_DOCOBSERVER_PROGID "component://netscape/secure_browser_docobserver"
|
|
||||||
|
|
||||||
|
|
||||||
class nsSecureBrowserObserver : public nsIDocumentLoaderObserver
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
nsSecureBrowserObserver();
|
|
||||||
virtual ~nsSecureBrowserObserver();
|
|
||||||
|
|
||||||
nsresult Init(nsIDOMElement *button, nsIDocShell* content);
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
|
|
||||||
// nsIDocumentLoaderObserver
|
|
||||||
NS_DECL_NSIDOCUMENTLOADEROBSERVER
|
|
||||||
|
|
||||||
static nsresult IsSecureDocumentLoad(nsIDocumentLoader* loader, PRBool *value);
|
|
||||||
static nsresult IsSecureChannelLoad(nsIChannel* channel, PRBool *value);
|
|
||||||
static nsresult IsSecureUrl(PRBool fileSecure, nsIURI* aURL, PRBool *value);
|
|
||||||
static nsresult GetURIFromDocumentLoader(nsIDocumentLoader* aLoader, nsIURI** uri);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMElement> mSecurityButton;
|
|
||||||
nsCOMPtr<nsIDocumentLoaderObserver> mOldWebShellObserver;
|
|
||||||
|
|
||||||
PRBool mIsSecureDocument; // is https loaded
|
|
||||||
PRBool mIsDocumentBroken; //
|
|
||||||
PRBool mMixContentAlertShown;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class nsSecureBrowserUIImpl : public nsSecureBrowserUI
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
nsSecureBrowserUIImpl();
|
|
||||||
virtual ~nsSecureBrowserUIImpl();
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
NS_DECL_NSSECUREBROWSERUI
|
|
||||||
|
|
||||||
static NS_METHOD CreateSecureBrowserUI(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
static nsSecureBrowserUIImpl* mInstance;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#endif /* nsSecureBrowserUIImpl_h_ */
|
|
Двоичные данные
netwerk/security/browser/unlock.gif
Двоичные данные
netwerk/security/browser/unlock.gif
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 67 B |
|
@ -1,31 +0,0 @@
|
||||||
#!nmake
|
|
||||||
#
|
|
||||||
# The contents of this file are subject to the Mozilla Public
|
|
||||||
# License Version 1.1 (the "License"); you may not use this file
|
|
||||||
# except in compliance with the License. You may obtain a copy of
|
|
||||||
# the License at http://www.mozilla.org/MPL/
|
|
||||||
#
|
|
||||||
# Software distributed under the License is distributed on an "AS
|
|
||||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
# implied. See the License for the specific language governing
|
|
||||||
# rights and limitations under the License.
|
|
||||||
#
|
|
||||||
# The Original Code is mozilla.org code.
|
|
||||||
#
|
|
||||||
# The Initial Developer of the Original Code is Netscape
|
|
||||||
# Communications Corporation. Portions created by Netscape are
|
|
||||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
# Rights Reserved.
|
|
||||||
#
|
|
||||||
# Contributor(s):
|
|
||||||
# Doug Turner 7/29/99
|
|
||||||
#
|
|
||||||
|
|
||||||
DEPTH = ..\..
|
|
||||||
|
|
||||||
DIRS= \
|
|
||||||
browser \
|
|
||||||
psm \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
include <$(DEPTH)\config\rules.mak>
|
|
|
@ -1,2 +0,0 @@
|
||||||
Makefile
|
|
||||||
_xpidlgen
|
|
|
@ -1,56 +0,0 @@
|
||||||
#
|
|
||||||
# The contents of this file are subject to the Mozilla Public
|
|
||||||
# License Version 1.1 (the "License"); you may not use this file
|
|
||||||
# except in compliance with the License. You may obtain a copy of
|
|
||||||
# the License at http://www.mozilla.org/MPL/
|
|
||||||
#
|
|
||||||
# Software distributed under the License is distributed on an "AS
|
|
||||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
# implied. See the License for the specific language governing
|
|
||||||
# rights and limitations under the License.
|
|
||||||
#
|
|
||||||
# The Original Code is mozilla.org code.
|
|
||||||
#
|
|
||||||
# The Initial Developer of the Original Code is Netscape
|
|
||||||
# Communications Corporation. Portions created by Netscape are
|
|
||||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
# Rights Reserved.
|
|
||||||
#
|
|
||||||
# Contributor(s):
|
|
||||||
#
|
|
||||||
|
|
||||||
DEPTH = ../../..
|
|
||||||
topsrcdir = @top_srcdir@
|
|
||||||
srcdir = @srcdir@
|
|
||||||
VPATH = @srcdir@
|
|
||||||
|
|
||||||
include $(DEPTH)/config/autoconf.mk
|
|
||||||
|
|
||||||
MODULE = psmcomp
|
|
||||||
|
|
||||||
IS_COMPONENT = 1
|
|
||||||
LIBRARY_NAME = psmcomp
|
|
||||||
|
|
||||||
CPPSRCS = \
|
|
||||||
nsPSMComponent.cpp \
|
|
||||||
nsPSMModule.cpp \
|
|
||||||
nsPSMUICallbacks.cpp \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
CSRCS = \
|
|
||||||
nsPSMMutex.c \
|
|
||||||
nsPSMShimLayer.c \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
XPIDLSRCS = \
|
|
||||||
nsIPSMComponent.idl \
|
|
||||||
nsIPSMUIHandler.idl \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
EXTRA_DSO_LDOPTS = -L$(DIST)/lib -lcmt -lxpcom -lprotocol $(MOZ_REGISTRY_LIBS)
|
|
||||||
|
|
||||||
include $(topsrcdir)/config/rules.mk
|
|
||||||
|
|
||||||
INCLUDES += \
|
|
||||||
-I$(srcdir) \
|
|
||||||
$(NULL)
|
|
|
@ -1,84 +0,0 @@
|
||||||
#!nmake
|
|
||||||
#
|
|
||||||
# The contents of this file are subject to the Mozilla Public
|
|
||||||
# License Version 1.1 (the "License"); you may not use this file
|
|
||||||
# except in compliance with the License. You may obtain a copy of
|
|
||||||
# the License at http://www.mozilla.org/MPL/
|
|
||||||
#
|
|
||||||
# Software distributed under the License is distributed on an "AS
|
|
||||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
# implied. See the License for the specific language governing
|
|
||||||
# rights and limitations under the License.
|
|
||||||
#
|
|
||||||
# The Original Code is mozilla.org code.
|
|
||||||
#
|
|
||||||
# The Initial Developer of the Original Code is Netscape
|
|
||||||
# Communications Corporation. Portions created by Netscape are
|
|
||||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
# Rights Reserved.
|
|
||||||
#
|
|
||||||
# Contributor(s):
|
|
||||||
#
|
|
||||||
|
|
||||||
MODULE = psmcomp
|
|
||||||
|
|
||||||
DEPTH=..\..\..
|
|
||||||
IGNORE_MANIFEST=1
|
|
||||||
|
|
||||||
DLLNAME = psmcomp
|
|
||||||
PDBFILE = $(DLLNAME).pdb
|
|
||||||
MAPFILE = $(DLLNAME).map
|
|
||||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
|
||||||
MAKE_OBJ_TYPE = DLL
|
|
||||||
|
|
||||||
include <$(DEPTH)/config/config.mak>
|
|
||||||
|
|
||||||
EXPORTS= \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LINCS = $(LINCS) \
|
|
||||||
-I$(PUBLIC) \
|
|
||||||
-I$(PUBLIC)/security \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LLIBS = \
|
|
||||||
$(LIBNSPR) \
|
|
||||||
$(DIST)\lib\neckobase_s.lib \
|
|
||||||
$(DIST)\lib\xpcom.lib \
|
|
||||||
$(DIST)\lib\js3250.lib \
|
|
||||||
$(DIST)\lib\cmt.lib \
|
|
||||||
$(DIST)\lib\protocol.lib \
|
|
||||||
$(DIST)\lib\mozreg.lib \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
LIBRARY_NAME=neckopsm_s
|
|
||||||
|
|
||||||
OBJS = \
|
|
||||||
.\$(OBJDIR)\nsPSMMutex.obj \
|
|
||||||
.\$(OBJDIR)\nsPSMShimLayer.obj \
|
|
||||||
.\$(OBJDIR)\nsPSMComponent.obj \
|
|
||||||
.\$(OBJDIR)\nsPSMUICallbacks.obj \
|
|
||||||
.\$(OBJDIR)\nsPSMModule.obj \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
XPIDL_INCLUDES=-I$(DEPTH)\..\mozilla\dist\idl
|
|
||||||
|
|
||||||
XPIDLSRCS= \
|
|
||||||
.\nsIPSMComponent.idl \
|
|
||||||
.\nsIPSMUIHandler.idl \
|
|
||||||
$(NULL)
|
|
||||||
|
|
||||||
#NO_GEN_XPT=1
|
|
||||||
|
|
||||||
include <$(DEPTH)\config\rules.mak>
|
|
||||||
|
|
||||||
install:: $(DLL)
|
|
||||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
|
||||||
|
|
||||||
# temporary we need to export this static library to
|
|
||||||
# deal with gSocketFuncs in CMT lib being global
|
|
||||||
install:: $(LIBRARY)
|
|
||||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
|
||||||
|
|
||||||
clobber::
|
|
||||||
-$(RM_R) $(OBJDIR) $(XPIDL_GEN_DIR)
|
|
|
@ -1,68 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nsISupports.idl"
|
|
||||||
//#include "nsIPrincipal.idl"
|
|
||||||
interface nsIPrincipal;
|
|
||||||
|
|
||||||
%{C++
|
|
||||||
#include "cmtcmn.h"
|
|
||||||
%}
|
|
||||||
|
|
||||||
[ptr] native nsCMTControlStar(CMT_CONTROL);
|
|
||||||
|
|
||||||
[scriptable, uuid(9e482670-5412-11d3-bbc8-0000861d1237)]
|
|
||||||
interface nsIPSMComponent : nsISupports
|
|
||||||
{
|
|
||||||
|
|
||||||
[noscript] nsCMTControlStar GetControlConnection( );
|
|
||||||
void DisplaySecurityAdvisor();
|
|
||||||
|
|
||||||
/* Secure Hashing functions */
|
|
||||||
void hashBegin(in unsigned long alg, out unsigned long id);
|
|
||||||
void hashUpdate(in unsigned long id, in string buf, in unsigned long buflen);
|
|
||||||
void hashEnd(in unsigned long id, out string hash, out unsigned long hashlen,
|
|
||||||
in unsigned long maxLen);
|
|
||||||
|
|
||||||
/* Signature Verification functions */
|
|
||||||
void verifyRSABegin(out unsigned long id);
|
|
||||||
void verifyRSAUpdate(in unsigned long id, in string buf,
|
|
||||||
in unsigned long buflen);
|
|
||||||
void verifyRSAEnd(in unsigned long id, in string plaintext,
|
|
||||||
in unsigned long plaintextLen,
|
|
||||||
in boolean keepCert, out nsIPrincipal principal);
|
|
||||||
};
|
|
||||||
|
|
||||||
%{C++
|
|
||||||
#define PSM_COMPONENT_PROGID "component://netscape/psm"
|
|
||||||
#define PSM_COMPONENT_CLASSNAME "Mozilla PSM Component"
|
|
||||||
|
|
||||||
/* Hash Algorithms (based on cmtcmn.h) */
|
|
||||||
#define PSM_HASH_MD2 1
|
|
||||||
#define PSM_HASH_MD2_LENGTH 16
|
|
||||||
#define PSM_HASH_MD5 2
|
|
||||||
#define PSM_HASH_MD5_LENGTH 16
|
|
||||||
#define PSM_HASH_SHA1 3
|
|
||||||
#define PSM_HASH_SHA1_LENGTH 20
|
|
||||||
#define PSM_HASH_MAX_LENGTH PSM_HASH_SHA1_LENGTH
|
|
||||||
%}
|
|
||||||
|
|
|
@ -1,35 +0,0 @@
|
||||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is the Mozilla browser.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications, Inc. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
* Doug Turner <dougt@netscape.com>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nsISupports.idl"
|
|
||||||
|
|
||||||
[scriptable, uuid(d92be9b0-601b-11d3-8c4a-000064657374)]
|
|
||||||
interface nsIPSMUIHandler : nsISupports
|
|
||||||
{
|
|
||||||
void DisplayURI(in long width, in long height, in string urlStr);
|
|
||||||
void PromptForFile(in string prompt, in string fileRegEx, in boolean shouldFileExist, out string outFile);
|
|
||||||
};
|
|
||||||
|
|
||||||
%{C++
|
|
||||||
#define PSM_UI_HANLDER_PROGID "component://netscape/psm/ui"
|
|
||||||
#define PSM_UI_HANLDER_CLASSNAME "Mozilla PSM UI Handler"
|
|
||||||
%}
|
|
|
@ -1,737 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nsProxiedService.h"
|
|
||||||
#include "nsPSMUICallbacks.h"
|
|
||||||
#include "VerReg.h"
|
|
||||||
|
|
||||||
#include "nspr.h"
|
|
||||||
#include "nsPSMComponent.h"
|
|
||||||
|
|
||||||
#include "nsCRT.h"
|
|
||||||
|
|
||||||
#include "nsIPref.h"
|
|
||||||
#include "nsIProfile.h"
|
|
||||||
#include "nsILocalFile.h"
|
|
||||||
#ifdef XP_MAC
|
|
||||||
#include "nsILocalFileMac.h"
|
|
||||||
#endif
|
|
||||||
#include "nsSpecialSystemDirectory.h"
|
|
||||||
|
|
||||||
#include "nsPSMMutex.h"
|
|
||||||
#include "nsPSMShimLayer.h"
|
|
||||||
#include "nsPSMUICallbacks.h"
|
|
||||||
|
|
||||||
#include "nsSecureBrowserUI.h"
|
|
||||||
#include "nsIDocumentLoaderObserver.h"
|
|
||||||
#include "nsIScriptSecurityManager.h"
|
|
||||||
|
|
||||||
#define PSM_VERSION_REG_KEY "/Netscape/Personal Security Manager"
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define PSM_FILE_NAME "psm.exe"
|
|
||||||
#elif XP_UNIX
|
|
||||||
#define PSM_FILE_NAME "start-psm"
|
|
||||||
#define PSM_FILE_LOCATION "/opt/netscape/security/start-psm"
|
|
||||||
#else
|
|
||||||
#define PSM_FILE_NAME "psm"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
|
|
||||||
|
|
||||||
|
|
||||||
nsPSMComponent* nsPSMComponent::mInstance = nsnull;
|
|
||||||
|
|
||||||
nsPSMComponent::nsPSMComponent()
|
|
||||||
{
|
|
||||||
NS_INIT_REFCNT();
|
|
||||||
mControl = nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsPSMComponent::~nsPSMComponent()
|
|
||||||
{
|
|
||||||
if (mControl)
|
|
||||||
{
|
|
||||||
CMT_CloseControlConnection(mControl);
|
|
||||||
mControl = nsnull;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::CreatePSMComponent(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
|
||||||
{
|
|
||||||
if (!aResult) {
|
|
||||||
return NS_ERROR_INVALID_POINTER;
|
|
||||||
}
|
|
||||||
if (aOuter) {
|
|
||||||
*aResult = nsnull;
|
|
||||||
return NS_ERROR_NO_AGGREGATION;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInstance == nsnull)
|
|
||||||
{
|
|
||||||
mInstance = new nsPSMComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mInstance == nsnull)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
nsresult rv = mInstance->QueryInterface(aIID, aResult);
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
{
|
|
||||||
*aResult = nsnull;
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* nsISupports Implementation for the class */
|
|
||||||
NS_IMPL_ISUPPORTS1 (nsPSMComponent, nsIPSMComponent);
|
|
||||||
|
|
||||||
#define INIT_NUM_PREFS 100
|
|
||||||
/* preference types */
|
|
||||||
#define STRING_PREF 0
|
|
||||||
#define BOOL_PREF 1
|
|
||||||
#define INT_PREF 2
|
|
||||||
|
|
||||||
|
|
||||||
/* resizable list struct that contains pref items */
|
|
||||||
typedef struct CMSetPrefList {
|
|
||||||
int n; /* number of filled items */
|
|
||||||
int capacity; /* allocated memory */
|
|
||||||
CMTSetPrefElement* list; /* actual list */
|
|
||||||
} CMSetPrefList;
|
|
||||||
|
|
||||||
static void get_pack_bool_pref(nsIPref *prefManager, char* key, CMTSetPrefElement* list, int* n)
|
|
||||||
{
|
|
||||||
PRBool boolpref;
|
|
||||||
|
|
||||||
list[*n].key = nsCRT::strdup(key);
|
|
||||||
list[*n].type = BOOL_PREF;
|
|
||||||
|
|
||||||
if ((prefManager->GetBoolPref(key, &boolpref) != 0) || boolpref)
|
|
||||||
{
|
|
||||||
list[*n].value = nsCRT::strdup("true");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
list[*n].value = nsCRT::strdup("false");
|
|
||||||
}
|
|
||||||
|
|
||||||
(*n)++; /* increment the counter after done packing */
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
|
||||||
|
|
||||||
static void SaveAllPrefs(int number, CMTSetPrefElement* list)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIPref> prefManager;
|
|
||||||
|
|
||||||
nsresult res = nsServiceManager::GetService(kPrefCID,
|
|
||||||
nsIPref::GetIID(),
|
|
||||||
getter_AddRefs(prefManager));
|
|
||||||
|
|
||||||
if (NS_FAILED(res) || !prefManager)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int i;
|
|
||||||
int intval;
|
|
||||||
|
|
||||||
for (i = 0; i < number; i++)
|
|
||||||
{
|
|
||||||
if (list[i].key == nsnull)
|
|
||||||
{
|
|
||||||
/* misconfigured item: next */
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (list[i].type)
|
|
||||||
{
|
|
||||||
case 0: /* string type */
|
|
||||||
prefManager->SetCharPref(list[i].key, list[i].value);
|
|
||||||
break;
|
|
||||||
case 1: /* boolean type */
|
|
||||||
if (strcmp(list[i].value, "true") == 0) {
|
|
||||||
prefManager->SetBoolPref(list[i].key, (PRBool)1);
|
|
||||||
}
|
|
||||||
else if (strcmp(list[i].value, "false") == 0) {
|
|
||||||
prefManager->SetBoolPref(list[i].key, (PRBool)0);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
intval = atoi(list[i].value);
|
|
||||||
prefManager->SetIntPref(list[i].key, intval);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsresult
|
|
||||||
nsPSMComponent::PassAllPrefs()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
nsresult rv = NS_ERROR_FAILURE;
|
|
||||||
char* strpref = NULL;
|
|
||||||
int intpref;
|
|
||||||
PRBool boolpref;
|
|
||||||
CMSetPrefList prefs = {0};
|
|
||||||
CMTSetPrefElement* list = NULL;
|
|
||||||
|
|
||||||
char* pickAuto = "Select Automatically";
|
|
||||||
char* alwaysAsk = "Ask Every Time";
|
|
||||||
|
|
||||||
nsCOMPtr<nsIPref> prefManager;
|
|
||||||
|
|
||||||
nsresult res = nsServiceManager::GetService(kPrefCID,
|
|
||||||
nsIPref::GetIID(),
|
|
||||||
getter_AddRefs(prefManager));
|
|
||||||
|
|
||||||
if (NS_OK != res)
|
|
||||||
{
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* allocate memory for list */
|
|
||||||
prefs.n = 0; /* counter */
|
|
||||||
prefs.capacity = INIT_NUM_PREFS;
|
|
||||||
prefs.list = (CMTSetPrefElement*) new char[(INIT_NUM_PREFS * sizeof(CMTSetPrefElement))];
|
|
||||||
|
|
||||||
if (prefs.list == NULL)
|
|
||||||
{
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* shorthand */
|
|
||||||
list = prefs.list;
|
|
||||||
|
|
||||||
/* get preferences */
|
|
||||||
get_pack_bool_pref(prefManager, "security.enable_ssl2", (CMTSetPrefElement*)list, &(prefs.n));
|
|
||||||
get_pack_bool_pref(prefManager, "security.enable_ssl3", (CMTSetPrefElement*)list, &(prefs.n));
|
|
||||||
|
|
||||||
/* this pref is a boolean pref in nature but a string pref for
|
|
||||||
* historical reason
|
|
||||||
*/
|
|
||||||
|
|
||||||
list[prefs.n].key = nsCRT::strdup("security.default_personal_cert");
|
|
||||||
list[prefs.n].type = STRING_PREF;
|
|
||||||
|
|
||||||
if ((prefManager->CopyCharPref(list[prefs.n].key, &strpref) == 0) && (strcmp(strpref, pickAuto) == 0))
|
|
||||||
{
|
|
||||||
list[prefs.n].value = nsCRT::strdup(pickAuto);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* although one could choose a specific cert for client auth in
|
|
||||||
* Nova, that mode is deprecated with PSM and mapped to ASK
|
|
||||||
*/
|
|
||||||
list[prefs.n].value = nsCRT::strdup(alwaysAsk);
|
|
||||||
}
|
|
||||||
|
|
||||||
prefs.n++;
|
|
||||||
if (strpref != NULL)
|
|
||||||
{
|
|
||||||
nsCRT::free(strpref);
|
|
||||||
}
|
|
||||||
|
|
||||||
list[prefs.n].key = nsCRT::strdup("security.default_mail_cert");
|
|
||||||
list[prefs.n].type = STRING_PREF;
|
|
||||||
if (prefManager->CopyCharPref(list[prefs.n].key, &list[prefs.n].value) != 0)
|
|
||||||
{
|
|
||||||
list[prefs.n].value = NULL;
|
|
||||||
}
|
|
||||||
prefs.n++;
|
|
||||||
|
|
||||||
list[prefs.n].key = nsCRT::strdup("security.ask_for_password");
|
|
||||||
list[prefs.n].type = INT_PREF;
|
|
||||||
if (prefManager->GetIntPref(list[prefs.n].key, &intpref) != 0)
|
|
||||||
{
|
|
||||||
intpref = 2; /* default */
|
|
||||||
}
|
|
||||||
|
|
||||||
list[prefs.n].value = PR_smprintf("%d", intpref);
|
|
||||||
prefs.n++;
|
|
||||||
|
|
||||||
list[prefs.n].key = nsCRT::strdup("security.password_lifetime");
|
|
||||||
list[prefs.n].type = INT_PREF;
|
|
||||||
if (prefManager->GetIntPref(list[prefs.n].key, &intpref) != 0)
|
|
||||||
{
|
|
||||||
intpref = 480; /* default */
|
|
||||||
}
|
|
||||||
|
|
||||||
list[prefs.n].value = PR_smprintf("%d", intpref);
|
|
||||||
prefs.n++;
|
|
||||||
|
|
||||||
/* OCSP preferences */
|
|
||||||
/* XXX since these are the new ones added by PSM, we will be more
|
|
||||||
* error-tolerant in fetching them
|
|
||||||
*/
|
|
||||||
if (prefManager->GetBoolPref("security.OCSP.enabled", &boolpref) == 0)
|
|
||||||
{
|
|
||||||
if (boolpref)
|
|
||||||
{
|
|
||||||
list[prefs.n].value = nsCRT::strdup("true");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
list[prefs.n].value = nsCRT::strdup("false");
|
|
||||||
}
|
|
||||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.enabled");
|
|
||||||
list[prefs.n].type = BOOL_PREF;
|
|
||||||
prefs.n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prefManager->GetBoolPref("security.OCSP.useDefaultResponder", &boolpref) == 0)
|
|
||||||
{
|
|
||||||
if (boolpref)
|
|
||||||
{
|
|
||||||
list[prefs.n].value = nsCRT::strdup("true");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
list[prefs.n].value = nsCRT::strdup("false");
|
|
||||||
}
|
|
||||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.useDefaultResponder");
|
|
||||||
list[prefs.n].type = BOOL_PREF;
|
|
||||||
prefs.n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prefManager->CopyCharPref("security.OCSP.URL", &strpref) == 0)
|
|
||||||
{
|
|
||||||
list[prefs.n].value = strpref;
|
|
||||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.URL");
|
|
||||||
list[prefs.n].type = STRING_PREF;
|
|
||||||
prefs.n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prefManager->CopyCharPref("security.OCSP.signingCA", &strpref) == 0)
|
|
||||||
{
|
|
||||||
list[prefs.n].value = strpref;
|
|
||||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.signingCA");
|
|
||||||
list[prefs.n].type = STRING_PREF;
|
|
||||||
prefs.n++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now application-specific preferences */
|
|
||||||
/* get navigator preferences */
|
|
||||||
get_pack_bool_pref(prefManager, "security.warn_entering_secure", (CMTSetPrefElement*)list, &prefs.n);
|
|
||||||
get_pack_bool_pref(prefManager, "security.warn_leaving_secure", (CMTSetPrefElement*)list, &prefs.n);
|
|
||||||
get_pack_bool_pref(prefManager, "security.warn_viewing_mixed", (CMTSetPrefElement*)list, &prefs.n);
|
|
||||||
get_pack_bool_pref(prefManager, "security.warn_submit_insecure", (CMTSetPrefElement*)list, &prefs.n);
|
|
||||||
|
|
||||||
// Add any other prefs here such as ldap or mail/news.
|
|
||||||
|
|
||||||
CMT_SetSavePrefsCallback(mControl, (savePrefsCallback_fn)SaveAllPrefs);
|
|
||||||
|
|
||||||
if (CMT_PassAllPrefs(mControl, prefs.n, (CMTSetPrefElement*)prefs.list) != CMTSuccess)
|
|
||||||
{
|
|
||||||
goto loser;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = NS_OK; /* success */
|
|
||||||
loser:
|
|
||||||
/* clean out memory for prefs */
|
|
||||||
for (i = 0; i < prefs.n; i++)
|
|
||||||
{
|
|
||||||
if (prefs.list[i].key != NULL)
|
|
||||||
{
|
|
||||||
nsCRT::free(prefs.list[i].key);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prefs.list[i].value != NULL)
|
|
||||||
{
|
|
||||||
nsCRT::free(prefs.list[i].value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prefs.list != NULL)
|
|
||||||
{
|
|
||||||
delete(prefs.list);
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::GetControlConnection( CMT_CONTROL * *_retval )
|
|
||||||
{
|
|
||||||
nsresult rv;
|
|
||||||
*_retval = nsnull;
|
|
||||||
if (mControl)
|
|
||||||
{
|
|
||||||
*_retval = mControl;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
else /* initialize mutex, sock table, etc. */
|
|
||||||
{
|
|
||||||
|
|
||||||
if (nsPSMMutexInit() != PR_SUCCESS)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
mControl = CMT_ControlConnect(&nsPSMMutexTbl, &nsPSMShimTbl);
|
|
||||||
|
|
||||||
if (mControl == nsnull)
|
|
||||||
{
|
|
||||||
//Try to find it.
|
|
||||||
int err;
|
|
||||||
char filepath[MAXREGPATHLEN];
|
|
||||||
|
|
||||||
err = VR_GetPath(PSM_VERSION_REG_KEY, sizeof(filepath), filepath);
|
|
||||||
if ( err == REGERR_OK )
|
|
||||||
{
|
|
||||||
nsFileSpec psmSpec(filepath);
|
|
||||||
psmSpec += PSM_FILE_NAME;
|
|
||||||
|
|
||||||
if (psmSpec.Exists())
|
|
||||||
{
|
|
||||||
mControl = CMT_EstablishControlConnection((char *)psmSpec.GetNativePathCString(), &nsPSMShimTbl, &nsPSMMutexTbl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef XP_MAC
|
|
||||||
if (mControl == nsnull)
|
|
||||||
{
|
|
||||||
nsSpecialSystemDirectory sysDir(nsSpecialSystemDirectory::OS_CurrentProcessDirectory);
|
|
||||||
nsFileSpec spec = sysDir;
|
|
||||||
|
|
||||||
spec += "psm/";
|
|
||||||
spec += PSM_FILE_NAME;
|
|
||||||
|
|
||||||
if (spec.Exists())
|
|
||||||
{
|
|
||||||
mControl = CMT_EstablishControlConnection((char *)spec.GetNativePathCString(), &nsPSMShimTbl, &nsPSMMutexTbl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (mControl == nsnull)
|
|
||||||
{
|
|
||||||
// Attempt to locate "Personal Security Manager" in "Essential Files".
|
|
||||||
nsCOMPtr<nsILocalFile> aPSMApp = do_CreateInstance(NS_LOCAL_FILE_PROGID, &rv);
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsILocalFileMac> psmAppMacFile = do_QueryInterface(aPSMApp, &rv);
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
{
|
|
||||||
rv = psmAppMacFile->InitFindingAppByCreatorCode('nPSM');
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
{
|
|
||||||
rv = psmAppMacFile->LaunchAppWithDoc(nsnull, PR_TRUE);
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
{
|
|
||||||
const PRUint32 kMaxWaitTicks = 180; // max 3 seconds
|
|
||||||
PRUint32 endTicks = ::TickCount() + kMaxWaitTicks;
|
|
||||||
|
|
||||||
do
|
|
||||||
{
|
|
||||||
EventRecord theEvent;
|
|
||||||
WaitNextEvent(0, &theEvent, 5, NULL);
|
|
||||||
mControl = CMT_ControlConnect(&nsPSMMutexTbl, &nsPSMShimTbl);
|
|
||||||
} while (!mControl && (::TickCount() < endTicks));
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
NS_ASSERTION(NS_SUCCEEDED(rv), "Launching Personal Security Manager failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef XP_UNIX
|
|
||||||
if (mControl == nsnull)
|
|
||||||
{
|
|
||||||
nsFileSpec psmSpec(PSM_FILE_LOCATION);
|
|
||||||
if (psmSpec.Exists())
|
|
||||||
{
|
|
||||||
mControl = CMT_EstablishControlConnection(PSM_FILE_LOCATION, &nsPSMShimTbl, &nsPSMMutexTbl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (mControl == nsnull)
|
|
||||||
{
|
|
||||||
char* filePath = nsnull;
|
|
||||||
|
|
||||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
|
||||||
if(NS_SUCCEEDED(rv))
|
|
||||||
handler->PromptForFile("Please find the Personal Security Manager application", PSM_FILE_NAME, PR_TRUE, &filePath);
|
|
||||||
if (! filePath)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
mControl = CMT_EstablishControlConnection(filePath, &nsPSMShimTbl, &nsPSMMutexTbl);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!mControl || InitPSMUICallbacks(mControl) != PR_SUCCESS)
|
|
||||||
goto failure;
|
|
||||||
|
|
||||||
nsFileSpec profileSpec;
|
|
||||||
char* profileName = nsnull;
|
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &rv);
|
|
||||||
if (NS_FAILED(rv)) goto failure;
|
|
||||||
|
|
||||||
rv = profile->GetCurrentProfileDir(&profileSpec);
|
|
||||||
if (NS_FAILED(rv)) goto failure;;
|
|
||||||
|
|
||||||
rv = profile->GetCurrentProfile(&profileName);
|
|
||||||
if (NS_FAILED(rv)) goto failure;
|
|
||||||
|
|
||||||
CMTStatus psmStatus;
|
|
||||||
|
|
||||||
psmStatus = CMT_Hello( mControl,
|
|
||||||
PROTOCOL_VERSION,
|
|
||||||
profileName,
|
|
||||||
(char*)profileSpec.GetNativePathCString());
|
|
||||||
|
|
||||||
if (psmStatus == CMTFailure)
|
|
||||||
{
|
|
||||||
PR_FREEIF(profileName);
|
|
||||||
goto failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NS_FAILED(PassAllPrefs()))
|
|
||||||
{
|
|
||||||
PR_FREEIF(profileName);
|
|
||||||
goto failure;
|
|
||||||
}
|
|
||||||
|
|
||||||
PR_FREEIF(profileName);
|
|
||||||
|
|
||||||
*_retval = mControl;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
failure:
|
|
||||||
|
|
||||||
printf("*** Failure setting up Cartman! \n");
|
|
||||||
|
|
||||||
if (mControl)
|
|
||||||
{
|
|
||||||
CMT_CloseControlConnection(mControl);
|
|
||||||
mControl = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO we need to unregister our UI callback BEFORE destroying our mutex.
|
|
||||||
// nsPSMMutexDestroy();
|
|
||||||
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::DisplaySecurityAdvisor()
|
|
||||||
{
|
|
||||||
CMT_CONTROL *controlConnection;
|
|
||||||
GetControlConnection( &controlConnection );
|
|
||||||
if (DisplayPSMUIDialog(controlConnection, nsnull) == PR_SUCCESS)
|
|
||||||
return NS_OK;
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------
|
|
||||||
// Secure Hash Functions
|
|
||||||
//-----------------------------------------
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::HashBegin(PRUint32 alg, PRUint32* id)
|
|
||||||
{
|
|
||||||
CMT_CONTROL *controlConnection;
|
|
||||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
if(CMT_HashCreate(controlConnection, alg, (CMUint32*)id) != CMTSuccess)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
if(CMT_HASH_Begin(controlConnection, *id) != CMTSuccess)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::HashUpdate(PRUint32 id, const char* buf, PRUint32 buflen)
|
|
||||||
{
|
|
||||||
CMT_CONTROL *controlConnection;
|
|
||||||
|
|
||||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
if (CMT_HASH_Update(controlConnection, id,
|
|
||||||
(const unsigned char*)buf, buflen) != CMTSuccess)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::HashEnd(PRUint32 id, char** hash, PRUint32* hashlen,
|
|
||||||
PRUint32 maxLen)
|
|
||||||
{
|
|
||||||
if (!hash)
|
|
||||||
return NS_ERROR_ILLEGAL_VALUE;
|
|
||||||
|
|
||||||
CMT_CONTROL *controlConnection;
|
|
||||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
if(CMT_HASH_End(controlConnection, id, (unsigned char*)*hash,
|
|
||||||
(CMUint32*)hashlen, maxLen) != CMTSuccess)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
CMT_HASH_Destroy(controlConnection, id);
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------
|
|
||||||
// Signature Verification Functions
|
|
||||||
//-----------------------------------------
|
|
||||||
PR_STATIC_CALLBACK(void)
|
|
||||||
UselessPK7DataSink(void* arg, const char* buf, CMUint32 len)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::VerifyRSABegin(PRUint32* id)
|
|
||||||
{
|
|
||||||
if (!id)
|
|
||||||
return NS_ERROR_ILLEGAL_VALUE;
|
|
||||||
|
|
||||||
CMT_CONTROL *controlConnection;
|
|
||||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
CMInt32* blah = nsnull;
|
|
||||||
CMTStatus result = CMT_PKCS7DecoderStart(controlConnection, nsnull /*?*/,
|
|
||||||
(CMUint32*)id, blah,
|
|
||||||
UselessPK7DataSink, nsnull);
|
|
||||||
if (result == CMTSuccess)
|
|
||||||
return NS_OK;
|
|
||||||
else
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::VerifyRSAUpdate(PRUint32 id, const char* buf, PRUint32 buflen)
|
|
||||||
{
|
|
||||||
CMT_CONTROL *controlConnection;
|
|
||||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
CMTStatus result = CMT_PKCS7DecoderUpdate(controlConnection, id, buf, buflen);
|
|
||||||
if (result == CMTSuccess)
|
|
||||||
return NS_OK;
|
|
||||||
else
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMComponent::VerifyRSAEnd(PRUint32 id, const char* plaintext,
|
|
||||||
PRUint32 plaintextLen,
|
|
||||||
PRBool keepCert, nsIPrincipal** aPrincipal)
|
|
||||||
{
|
|
||||||
CMT_CONTROL *controlConnection;
|
|
||||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
CMUint32 contentInfo;
|
|
||||||
CMTStatus result = CMT_PKCS7DecoderFinish(controlConnection,
|
|
||||||
id, &contentInfo);
|
|
||||||
if (result != CMTSuccess)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
//-- Make sure a signature is present
|
|
||||||
CMInt32 isSigned;
|
|
||||||
result = CMT_GetNumericAttribute(controlConnection, contentInfo,
|
|
||||||
SSM_FID_P7CINFO_IS_SIGNED, &isSigned);
|
|
||||||
if (result != CMTSuccess || !isSigned)
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
// SHA1 hash the plaintext to compare it to the signature
|
|
||||||
CMUint32 hashId;
|
|
||||||
CMT_HashCreate(controlConnection, PSM_HASH_SHA1, &hashId);
|
|
||||||
CMT_HASH_Begin(controlConnection, hashId);
|
|
||||||
result = CMT_HASH_Update(controlConnection, hashId,
|
|
||||||
(const unsigned char*)plaintext, plaintextLen);
|
|
||||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
|
||||||
|
|
||||||
unsigned char* hash = (unsigned char*)PR_MALLOC(PSM_HASH_SHA1_LENGTH);
|
|
||||||
if (!hash) return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
CMUint32 hashLen;
|
|
||||||
result = CMT_HASH_End(controlConnection, hashId, hash,
|
|
||||||
&hashLen, PSM_HASH_SHA1_LENGTH);
|
|
||||||
NS_ASSERTION(hashLen == PSM_HASH_SHA1_LENGTH,
|
|
||||||
"PSMComponent: Hash too short.");
|
|
||||||
CMT_HASH_Destroy(controlConnection, hashId);
|
|
||||||
if (result != CMTSuccess)
|
|
||||||
{
|
|
||||||
PR_FREEIF(hash);
|
|
||||||
return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
//-- Verify signature
|
|
||||||
CMInt32 ok;
|
|
||||||
CMTItemStr item;
|
|
||||||
item.data = hash;
|
|
||||||
item.len = hashLen;
|
|
||||||
result = CMT_PKCS7VerifyDetachedSignature(controlConnection, contentInfo,
|
|
||||||
6 /* =Object Sining Cert */,
|
|
||||||
3 /* =SHA1 algorithm (MD5=2)*/,
|
|
||||||
(CMUint32)keepCert,
|
|
||||||
&item, &ok);
|
|
||||||
PR_FREEIF(hash);
|
|
||||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
|
||||||
//-- Did it verify?
|
|
||||||
|
|
||||||
if (ok != 0)
|
|
||||||
*aPrincipal = nsnull;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//-- Read cert info
|
|
||||||
CMInt32 cert;
|
|
||||||
result = CMT_GetNumericAttribute(controlConnection, contentInfo,
|
|
||||||
SSM_FID_P7CINFO_SIGNER_CERT, &cert);
|
|
||||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
|
||||||
CMTItemStr issuer;
|
|
||||||
result = CMT_GetStringAttribute(controlConnection, cert,
|
|
||||||
SSM_FID_CERT_ISSUER_NAME, &issuer);
|
|
||||||
CMTItemStr serial;
|
|
||||||
result = CMT_GetStringAttribute(controlConnection, cert,
|
|
||||||
SSM_FID_CERT_SERIAL_NUMBER, &serial);
|
|
||||||
//-- Get a principal
|
|
||||||
nsresult rv;
|
|
||||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
|
||||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv)
|
|
||||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
|
||||||
rv = secMan->GetCertificatePrincipal((char*)issuer.data,
|
|
||||||
(char*)serial.data, aPrincipal);
|
|
||||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
result = CMT_PKCS7DestroyContentInfo(controlConnection, contentInfo);
|
|
||||||
|
|
||||||
if(result != CMTSuccess) return NS_ERROR_FAILURE;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nscore.h"
|
|
||||||
#include "nsIPSMComponent.h"
|
|
||||||
|
|
||||||
#define NS_PSMCOMPONENT_CID {0xddcae170, 0x5412, 0x11d3, {0xbb, 0xc8, 0x00, 0x00, 0x86, 0x1d, 0x12, 0x37}}
|
|
||||||
|
|
||||||
// Implementation of the PSM app shell component interface.
|
|
||||||
class nsPSMComponent : public nsIPSMComponent
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_PSMCOMPONENT_CID );
|
|
||||||
|
|
||||||
nsPSMComponent();
|
|
||||||
virtual ~nsPSMComponent();
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
|
|
||||||
NS_DECL_NSIPSMCOMPONENT
|
|
||||||
|
|
||||||
static NS_METHOD CreatePSMComponent(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
PCMT_CONTROL mControl;
|
|
||||||
|
|
||||||
nsCOMPtr<nsISupports> mSecureBrowserIU;
|
|
||||||
static nsPSMComponent* mInstance;
|
|
||||||
nsresult PassAllPrefs();
|
|
||||||
};
|
|
|
@ -1,42 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nsIModule.h"
|
|
||||||
#include "nsIGenericFactory.h"
|
|
||||||
|
|
||||||
#include "nsPSMUICallbacks.h"
|
|
||||||
#include "nsPSMComponent.h"
|
|
||||||
|
|
||||||
static nsModuleComponentInfo components[] =
|
|
||||||
{
|
|
||||||
{ PSM_COMPONENT_CLASSNAME,
|
|
||||||
NS_PSMCOMPONENT_CID,
|
|
||||||
PSM_COMPONENT_PROGID,
|
|
||||||
nsPSMComponent::CreatePSMComponent},
|
|
||||||
|
|
||||||
{ PSM_UI_HANLDER_CLASSNAME,
|
|
||||||
NS_PSMUIHANDLER_CID,
|
|
||||||
PSM_UI_HANLDER_PROGID,
|
|
||||||
nsPSMUIHandlerImpl::CreatePSMUIHandler}
|
|
||||||
};
|
|
||||||
|
|
||||||
NS_IMPL_NSGETMODULE("PSMComponent", components);
|
|
|
@ -1,72 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "prmon.h"
|
|
||||||
#include "prtypes.h"
|
|
||||||
|
|
||||||
#include "nsPSMMutex.h"
|
|
||||||
|
|
||||||
static PRMonitor *_nsPSMMutexVar;
|
|
||||||
|
|
||||||
PRStatus
|
|
||||||
nsPSMMutexInit()
|
|
||||||
{
|
|
||||||
if (!_nsPSMMutexVar)
|
|
||||||
_nsPSMMutexVar = PR_NewMonitor();
|
|
||||||
else
|
|
||||||
printf("PSMMutex warning got called twice\n");
|
|
||||||
|
|
||||||
return _nsPSMMutexVar ? PR_SUCCESS : PR_FAILURE;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRStatus
|
|
||||||
nsPSMMutexDestroy()
|
|
||||||
{
|
|
||||||
if (!_nsPSMMutexVar)
|
|
||||||
return PR_FAILURE;
|
|
||||||
|
|
||||||
PR_Wait(_nsPSMMutexVar, PR_INTERVAL_NO_TIMEOUT);
|
|
||||||
|
|
||||||
PR_DestroyMonitor(_nsPSMMutexVar);
|
|
||||||
return PR_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
nsPSMMutexLock(CMTMutexPointer *p)
|
|
||||||
{
|
|
||||||
PR_EnterMonitor(*(PRMonitor **)p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
nsPSMMutexUnlock(CMTMutexPointer *p)
|
|
||||||
{
|
|
||||||
PR_ExitMonitor(*(PRMonitor **)p);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMT_MUTEX nsPSMMutexTbl =
|
|
||||||
{
|
|
||||||
&_nsPSMMutexVar,
|
|
||||||
(CMTMutexFunction)nsPSMMutexLock,
|
|
||||||
(CMTMutexFunction)nsPSMMutexUnlock
|
|
||||||
};
|
|
|
@ -1,37 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _NSPSMMUTEX_H
|
|
||||||
#define _NSPSMMUTEX_H
|
|
||||||
|
|
||||||
#include "cmtcmn.h"
|
|
||||||
|
|
||||||
PR_BEGIN_EXTERN_C
|
|
||||||
|
|
||||||
PR_EXTERN(CMT_MUTEX) nsPSMMutexTbl;
|
|
||||||
|
|
||||||
PR_EXTERN(PRStatus) nsPSMMutexInit(void);
|
|
||||||
PR_EXTERN(PRStatus) nsPSMMutexDestroy(void);
|
|
||||||
|
|
||||||
PR_END_EXTERN_C
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,267 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nspr.h"
|
|
||||||
#include "nsPSMShimLayer.h"
|
|
||||||
|
|
||||||
#ifdef XP_UNIX
|
|
||||||
#include <sys/stat.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define NSPSMSHIMMAXFD 50
|
|
||||||
|
|
||||||
CMT_SocketFuncs nsPSMShimTbl =
|
|
||||||
{
|
|
||||||
nsPSMShimGetSocket,
|
|
||||||
nsPSMShimConnect,
|
|
||||||
nsPSMShimVerifyUnixSocket,
|
|
||||||
nsPSMShimSend,
|
|
||||||
nsPSMShimSelect,
|
|
||||||
nsPSMShimReceive,
|
|
||||||
nsPSMShimShutdown,
|
|
||||||
nsPSMShimClose
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
CMTSocket
|
|
||||||
nsPSMShimGetSocket(int unixSock)
|
|
||||||
{
|
|
||||||
PRStatus rv;
|
|
||||||
PRFileDesc *fd;
|
|
||||||
CMSocket *sock;
|
|
||||||
|
|
||||||
|
|
||||||
if (unixSock)
|
|
||||||
{
|
|
||||||
#ifndef XP_UNIX
|
|
||||||
return NULL;
|
|
||||||
#else
|
|
||||||
fd = PR_OpenTCPSocket(AF_UNIX);
|
|
||||||
PR_ASSERT(fd);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
PRSocketOptionData sockopt;
|
|
||||||
|
|
||||||
fd = PR_NewTCPSocket();
|
|
||||||
PR_ASSERT(fd);
|
|
||||||
|
|
||||||
/* disable Nagle algorithm delay for control sockets */
|
|
||||||
sockopt.option = PR_SockOpt_NoDelay;
|
|
||||||
sockopt.value.no_delay = PR_TRUE;
|
|
||||||
|
|
||||||
rv = PR_SetSocketOption(fd, &sockopt);
|
|
||||||
PR_ASSERT(PR_SUCCESS == rv);
|
|
||||||
}
|
|
||||||
|
|
||||||
sock = (CMSocket *)PR_Malloc(sizeof(CMSocket));
|
|
||||||
|
|
||||||
if (sock == NULL)
|
|
||||||
return sock;
|
|
||||||
|
|
||||||
sock->fd = fd;
|
|
||||||
sock->isUnix = unixSock;
|
|
||||||
|
|
||||||
memset(&sock->netAddr, 0, sizeof(PRNetAddr));
|
|
||||||
|
|
||||||
return (CMTSocket)sock;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMTStatus
|
|
||||||
nsPSMShimConnect(CMTSocket sock, short port, char *path)
|
|
||||||
{
|
|
||||||
PRStatus err;
|
|
||||||
PRErrorCode errcode;
|
|
||||||
CMTStatus rv = CMTSuccess;
|
|
||||||
CMSocket *cmSock = (CMSocket *)sock;
|
|
||||||
|
|
||||||
if (cmSock->isUnix)
|
|
||||||
{
|
|
||||||
#ifndef XP_UNIX
|
|
||||||
return CMTFailure;
|
|
||||||
#else
|
|
||||||
int pathLen;
|
|
||||||
if (!path)
|
|
||||||
{
|
|
||||||
return CMTFailure;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check buffer overrun */
|
|
||||||
pathLen = strlen(path)+1;
|
|
||||||
|
|
||||||
pathLen = pathLen < sizeof(cmSock->netAddr.local.path)
|
|
||||||
? pathLen : sizeof(cmSock->netAddr.local.path);
|
|
||||||
|
|
||||||
memcpy(&cmSock->netAddr.local.path, path, pathLen);
|
|
||||||
cmSock->netAddr.local.family = PR_AF_LOCAL;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
else /* cmSock->isUnix */
|
|
||||||
{
|
|
||||||
cmSock->netAddr.inet.family = PR_AF_INET;
|
|
||||||
cmSock->netAddr.inet.port = PR_htons(port);
|
|
||||||
cmSock->netAddr.inet.ip = PR_htonl(PR_INADDR_LOOPBACK);
|
|
||||||
}
|
|
||||||
|
|
||||||
err = PR_Connect( cmSock->fd, &cmSock->netAddr, PR_INTERVAL_MAX );
|
|
||||||
|
|
||||||
if (err == PR_FAILURE)
|
|
||||||
{
|
|
||||||
errcode = PR_GetError();
|
|
||||||
|
|
||||||
/* TODO: verify PR_INVALID_ARGUMENT_ERROR continue with connect */
|
|
||||||
|
|
||||||
switch (errcode)
|
|
||||||
{
|
|
||||||
case PR_IS_CONNECTED_ERROR:
|
|
||||||
rv = CMTSuccess;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case PR_IN_PROGRESS_ERROR:
|
|
||||||
case PR_IO_TIMEOUT_ERROR:
|
|
||||||
#ifdef WIN32
|
|
||||||
case PR_WOULD_BLOCK_ERROR:
|
|
||||||
case PR_INVALID_ARGUMENT_ERROR:
|
|
||||||
#endif
|
|
||||||
default:
|
|
||||||
rv = CMTFailure;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMTStatus
|
|
||||||
nsPSMShimVerifyUnixSocket(CMTSocket sock)
|
|
||||||
{
|
|
||||||
#ifndef XP_UNIX
|
|
||||||
return CMTFailure;
|
|
||||||
#else
|
|
||||||
|
|
||||||
int rv;
|
|
||||||
CMSocket *cmSock = (CMSocket *)sock;
|
|
||||||
struct stat statbuf;
|
|
||||||
|
|
||||||
if (!cmSock->isUnix)
|
|
||||||
return CMTFailure;
|
|
||||||
|
|
||||||
rv = stat(cmSock->netAddr.local.path, &statbuf);
|
|
||||||
if (rv < 0 || statbuf.st_uid != geteuid() )
|
|
||||||
{
|
|
||||||
PR_Close(cmSock->fd);
|
|
||||||
cmSock->fd = NULL;
|
|
||||||
PR_Free(cmSock);
|
|
||||||
return CMTFailure;
|
|
||||||
}
|
|
||||||
return CMTSuccess;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
nsPSMShimSend(CMTSocket sock, void *buffer, size_t length)
|
|
||||||
{
|
|
||||||
PRInt32 total;
|
|
||||||
CMSocket *cmSock = (CMSocket *)sock;
|
|
||||||
|
|
||||||
total = PR_Send(cmSock->fd, buffer, length, 0, PR_INTERVAL_NO_TIMEOUT);
|
|
||||||
|
|
||||||
/* TODO: for now, return 0 if there's an error */
|
|
||||||
return (total < 0) ? 0 : total;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
CMTSocket
|
|
||||||
nsPSMShimSelect(CMTSocket *socks, int numsocks, int poll)
|
|
||||||
{
|
|
||||||
CMSocket **sockArr = (CMSocket **)socks;
|
|
||||||
PRPollDesc readPDs[NSPSMSHIMMAXFD];
|
|
||||||
PRIntervalTime timeout;
|
|
||||||
PRInt32 cnt;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
memset(readPDs, 0, sizeof(readPDs));
|
|
||||||
|
|
||||||
PR_ASSERT(NSPSMSHIMMAXFD >= numsocks);
|
|
||||||
|
|
||||||
for (i=0; i<numsocks; i++)
|
|
||||||
{
|
|
||||||
readPDs[i].fd = sockArr[i]->fd;
|
|
||||||
readPDs[i].in_flags = PR_POLL_READ;
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout = poll ? PR_INTERVAL_NO_WAIT : PR_INTERVAL_NO_TIMEOUT;
|
|
||||||
|
|
||||||
cnt = PR_Poll(readPDs, numsocks, timeout);
|
|
||||||
|
|
||||||
/* Figure out which socket was selected */
|
|
||||||
if (cnt > 0)
|
|
||||||
{
|
|
||||||
for (i=0; i<numsocks; i++)
|
|
||||||
{
|
|
||||||
if (readPDs[i].out_flags & PR_POLL_READ)
|
|
||||||
{
|
|
||||||
return (CMTSocket)sockArr[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t
|
|
||||||
nsPSMShimReceive(CMTSocket sock, void *buffer, size_t bufSize)
|
|
||||||
{
|
|
||||||
PRInt32 total;
|
|
||||||
CMSocket *cmSock = (CMSocket *)sock;
|
|
||||||
|
|
||||||
total = PR_Recv(cmSock->fd, buffer, bufSize, 0, PR_INTERVAL_NO_TIMEOUT);
|
|
||||||
|
|
||||||
/* TODO: for now, return 0 if there's an error */
|
|
||||||
return (total < 0) ? 0 : total;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMTStatus
|
|
||||||
nsPSMShimShutdown(CMTSocket sock)
|
|
||||||
{
|
|
||||||
CMSocket *cmSock = (CMSocket*)sock;
|
|
||||||
PRStatus rv = PR_Shutdown(cmSock->fd, PR_SHUTDOWN_SEND);
|
|
||||||
return (PR_SUCCESS == rv) ? CMTSuccess : CMTFailure;
|
|
||||||
}
|
|
||||||
|
|
||||||
CMTStatus
|
|
||||||
nsPSMShimClose(CMTSocket sock)
|
|
||||||
{
|
|
||||||
CMSocket *cmSock = (CMSocket*)sock;
|
|
||||||
PRStatus rv = PR_SUCCESS;
|
|
||||||
PR_ASSERT(cmSock);
|
|
||||||
|
|
||||||
rv = PR_Close(cmSock->fd);
|
|
||||||
cmSock->fd = NULL;
|
|
||||||
|
|
||||||
/* TODO: release ref on control connection */
|
|
||||||
PR_Free(cmSock);
|
|
||||||
|
|
||||||
return (PR_SUCCESS == rv) ? CMTSuccess : CMTFailure;
|
|
||||||
}
|
|
|
@ -1,65 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _NSPSMSHIMLAYER_H_
|
|
||||||
#define _NSPSMSHIMLAYER_H_
|
|
||||||
|
|
||||||
#include "cmtcmn.h"
|
|
||||||
|
|
||||||
PR_BEGIN_EXTERN_C
|
|
||||||
|
|
||||||
/* TODO: make sure CMSocket is cleaned up */
|
|
||||||
typedef struct CMSocket {
|
|
||||||
PRFileDesc *fd;
|
|
||||||
PRBool isUnix;
|
|
||||||
PRNetAddr netAddr;
|
|
||||||
} CMSocket;
|
|
||||||
|
|
||||||
PR_EXTERN(CMT_SocketFuncs) nsPSMShimTbl;
|
|
||||||
|
|
||||||
PR_EXTERN(CMTSocket)
|
|
||||||
nsPSMShimGetSocket(int unixSock);
|
|
||||||
|
|
||||||
PR_EXTERN(CMTStatus)
|
|
||||||
nsPSMShimConnect(CMTSocket sock, short port, char *path);
|
|
||||||
|
|
||||||
PR_EXTERN(CMTStatus)
|
|
||||||
nsPSMShimVerifyUnixSocket(CMTSocket sock);
|
|
||||||
|
|
||||||
PR_EXTERN(size_t)
|
|
||||||
nsPSMShimSend(CMTSocket sock, void *buffer, size_t length);
|
|
||||||
|
|
||||||
PR_EXTERN(CMTSocket)
|
|
||||||
nsPSMShimSelect(CMTSocket *socks, int numsocks, int poll);
|
|
||||||
|
|
||||||
PR_EXTERN(size_t)
|
|
||||||
nsPSMShimReceive(CMTSocket sock, void *buffer, size_t bufSize);
|
|
||||||
|
|
||||||
PR_EXTERN(CMTStatus)
|
|
||||||
nsPSMShimShutdown(CMTSocket sock);
|
|
||||||
|
|
||||||
PR_EXTERN(CMTStatus)
|
|
||||||
nsPSMShimClose(CMTSocket sock);
|
|
||||||
|
|
||||||
PR_END_EXTERN_C
|
|
||||||
|
|
||||||
#endif /* _NSPSMSHIMLAYER_H_ */
|
|
|
@ -1,303 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "nsProxiedService.h"
|
|
||||||
#include "nsIEventQueueService.h"
|
|
||||||
#include "nsPSMUICallbacks.h"
|
|
||||||
|
|
||||||
#include "nsINetSupportDialogService.h"
|
|
||||||
#include "nsIFileSpecWithUI.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "nsAppShellCIDs.h"
|
|
||||||
#include "prprf.h"
|
|
||||||
|
|
||||||
// Interfaces Needed
|
|
||||||
#include "nsIAppShellService.h"
|
|
||||||
#include "nsIDocShell.h"
|
|
||||||
#include "nsIDOMWindow.h"
|
|
||||||
#include "nsIInterfaceRequestor.h"
|
|
||||||
#include "nsIPrompt.h"
|
|
||||||
#include "nsIScriptGlobalObject.h"
|
|
||||||
#include "nsIURL.h"
|
|
||||||
#include "nsIXULWindow.h"
|
|
||||||
|
|
||||||
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
|
||||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
|
||||||
|
|
||||||
|
|
||||||
// Happy callbacks
|
|
||||||
static char * PromptUserCallback(void *arg, char *prompt, int isPasswd);
|
|
||||||
static char * FilePathPromptCallback(void *arg, char *prompt, char *fileRegEx, CMUint32 shouldFileExist);
|
|
||||||
static void ApplicationFreeCallback(char *userInput);
|
|
||||||
static void * CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, char* urlStr, void *data);
|
|
||||||
extern "C" void CARTMAN_UIEventLoop(void *data);
|
|
||||||
|
|
||||||
|
|
||||||
/* nsISupports Implementation for the class */
|
|
||||||
NS_IMPL_ISUPPORTS1(nsPSMUIHandlerImpl, nsIPSMUIHandler)
|
|
||||||
|
|
||||||
NS_METHOD
|
|
||||||
nsPSMUIHandlerImpl::DisplayURI(PRInt32 width, PRInt32 height, const char *urlStr)
|
|
||||||
{
|
|
||||||
nsresult rv;
|
|
||||||
|
|
||||||
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
|
||||||
if (NS_SUCCEEDED(rv))
|
|
||||||
{
|
|
||||||
// get a parent window for the new browser window
|
|
||||||
nsCOMPtr<nsIXULWindow> parent;
|
|
||||||
appShell->GetHiddenWindow(getter_AddRefs(parent));
|
|
||||||
|
|
||||||
// convert it to a DOMWindow
|
|
||||||
nsCOMPtr<nsIDocShell> docShell;
|
|
||||||
if (parent)
|
|
||||||
{
|
|
||||||
parent->GetDocShell(getter_AddRefs(docShell));
|
|
||||||
}
|
|
||||||
nsCOMPtr<nsIDOMWindow> domParent(do_GetInterface(docShell));
|
|
||||||
nsCOMPtr<nsIScriptGlobalObject> sgo(do_QueryInterface(domParent));
|
|
||||||
|
|
||||||
nsCOMPtr<nsIScriptContext> context;
|
|
||||||
if (sgo)
|
|
||||||
{
|
|
||||||
sgo->GetContext(getter_AddRefs(context));
|
|
||||||
}
|
|
||||||
if (context)
|
|
||||||
{
|
|
||||||
JSContext *jsContext = (JSContext*)context->GetNativeContext();
|
|
||||||
if (jsContext)
|
|
||||||
{
|
|
||||||
void *stackPtr;
|
|
||||||
|
|
||||||
char buffer[256];
|
|
||||||
PR_snprintf(buffer,
|
|
||||||
sizeof(buffer),
|
|
||||||
"menubar=no,height=%d,width=%d",
|
|
||||||
height,
|
|
||||||
width );
|
|
||||||
|
|
||||||
jsval *argv = JS_PushArguments(jsContext, &stackPtr, "sss", urlStr, "_blank", buffer);
|
|
||||||
if (argv)
|
|
||||||
{
|
|
||||||
// open the window
|
|
||||||
nsIDOMWindow *newWindow;
|
|
||||||
domParent->Open(jsContext, argv, 3, &newWindow);
|
|
||||||
newWindow->ResizeTo(width, height);
|
|
||||||
JS_PopArguments(jsContext, stackPtr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_IMETHODIMP
|
|
||||||
nsPSMUIHandlerImpl::PromptForFile(const char *prompt, const char *fileRegEx, PRBool shouldFileExist, char **outFile)
|
|
||||||
{
|
|
||||||
NS_ENSURE_ARG_POINTER(outFile);
|
|
||||||
nsIFileSpecWithUI* file = NS_CreateFileSpecWithUI();
|
|
||||||
|
|
||||||
if (file == nsnull)
|
|
||||||
return NS_ERROR_NULL_POINTER;
|
|
||||||
|
|
||||||
nsresult rv = file->ChooseInputFile(prompt,
|
|
||||||
nsIFileSpecWithUI::eAllFiles | nsIFileSpecWithUI::eExtraFilter,
|
|
||||||
fileRegEx, // FIX name?
|
|
||||||
fileRegEx);
|
|
||||||
|
|
||||||
if (NS_FAILED(rv))
|
|
||||||
return rv;
|
|
||||||
|
|
||||||
rv = file->GetNativePath(outFile);
|
|
||||||
|
|
||||||
NS_RELEASE(file);
|
|
||||||
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
NS_METHOD
|
|
||||||
nsPSMUIHandlerImpl::CreatePSMUIHandler(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
if ( aResult )
|
|
||||||
{
|
|
||||||
/* Allocate new find component object. */
|
|
||||||
nsPSMUIHandlerImpl *component = new nsPSMUIHandlerImpl();
|
|
||||||
if ( component )
|
|
||||||
{
|
|
||||||
/* Allocated OK, do query interface to get proper */
|
|
||||||
/* pointer and increment refcount. */
|
|
||||||
rv = component->QueryInterface( aIID, aResult );
|
|
||||||
if ( NS_FAILED( rv ) )
|
|
||||||
{
|
|
||||||
/* refcount still at zero, delete it here. */
|
|
||||||
delete component;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rv = NS_ERROR_NULL_POINTER;
|
|
||||||
}
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern "C" void CARTMAN_UIEventLoop(void *data)
|
|
||||||
{
|
|
||||||
CMT_EventLoop((PCMT_CONTROL)data);
|
|
||||||
}
|
|
||||||
|
|
||||||
PRStatus InitPSMUICallbacks(PCMT_CONTROL control)
|
|
||||||
{
|
|
||||||
if (!control)
|
|
||||||
return PR_FAILURE;
|
|
||||||
|
|
||||||
CMT_SetPromptCallback(control, (promptCallback_fn)PromptUserCallback, nsnull);
|
|
||||||
CMT_SetAppFreeCallback(control, (applicationFreeCallback_fn) ApplicationFreeCallback);
|
|
||||||
CMT_SetFilePathPromptCallback(control, (filePathPromptCallback_fn) FilePathPromptCallback, nsnull);
|
|
||||||
|
|
||||||
if (CMT_SetUIHandlerCallback(control, (uiHandlerCallback_fn) CartmanUIHandler, NULL) != CMTSuccess)
|
|
||||||
return PR_FAILURE;
|
|
||||||
|
|
||||||
PR_CreateThread(PR_USER_THREAD,
|
|
||||||
CARTMAN_UIEventLoop,
|
|
||||||
control,
|
|
||||||
PR_PRIORITY_NORMAL,
|
|
||||||
PR_GLOBAL_THREAD,
|
|
||||||
PR_UNJOINABLE_THREAD,
|
|
||||||
0);
|
|
||||||
|
|
||||||
return PR_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, void *arg)
|
|
||||||
{
|
|
||||||
CMUint32 advRID = 0;
|
|
||||||
CMInt32 width = 0;
|
|
||||||
CMInt32 height = 0;
|
|
||||||
CMTItem urlItem = {0, NULL, 0};
|
|
||||||
CMTStatus rv = CMTSuccess;
|
|
||||||
CMTItem advisorContext = {0, NULL, 0};
|
|
||||||
void * pwin;
|
|
||||||
|
|
||||||
CMTSecurityAdvisorData data;
|
|
||||||
memset(&data, '\0', sizeof(CMTSecurityAdvisorData));
|
|
||||||
|
|
||||||
/* Create a Security Advisor context object. */
|
|
||||||
rv = CMT_SecurityAdvisor(control, &data, &advRID);
|
|
||||||
|
|
||||||
if (rv != CMTSuccess)
|
|
||||||
return PR_FAILURE;
|
|
||||||
|
|
||||||
/* Get the URL, width, height, etc. from the advisor context. */
|
|
||||||
rv = CMT_GetStringAttribute(control,
|
|
||||||
advRID,
|
|
||||||
SSM_FID_SECADVISOR_URL,
|
|
||||||
&urlItem);
|
|
||||||
|
|
||||||
if ((rv != CMTSuccess) || (!urlItem.data))
|
|
||||||
return PR_FAILURE;
|
|
||||||
|
|
||||||
rv = CMT_GetNumericAttribute(control,
|
|
||||||
advRID,
|
|
||||||
SSM_FID_SECADVISOR_WIDTH,
|
|
||||||
&width);
|
|
||||||
if (rv != CMTSuccess)
|
|
||||||
return PR_FAILURE;
|
|
||||||
|
|
||||||
rv = CMT_GetNumericAttribute(control,
|
|
||||||
advRID,
|
|
||||||
SSM_FID_SECADVISOR_HEIGHT,
|
|
||||||
&height);
|
|
||||||
if (rv != CMTSuccess)
|
|
||||||
return PR_FAILURE;
|
|
||||||
|
|
||||||
/* Fire the URL up in a window of its own. */
|
|
||||||
pwin = CartmanUIHandler(advRID, arg, width, height, (char*)urlItem.data, NULL);
|
|
||||||
return PR_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void* CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, char* urlStr, void *data)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
|
|
||||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
|
||||||
|
|
||||||
if(NS_SUCCEEDED(rv))
|
|
||||||
handler->DisplayURI(width, height, urlStr);
|
|
||||||
|
|
||||||
return nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
char * PromptUserCallback(void *arg, char *prompt, int isPasswd)
|
|
||||||
{
|
|
||||||
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
PRUnichar *password;
|
|
||||||
PRInt32 value;
|
|
||||||
|
|
||||||
NS_WITH_PROXIED_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, NS_UI_THREAD_EVENTQ, &rv);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
rv = dialog->PromptPassword(nsString(prompt).GetUnicode(), nsnull /* window title */, &password, &value);
|
|
||||||
|
|
||||||
if (NS_SUCCEEDED(rv)) {
|
|
||||||
nsString a(password);
|
|
||||||
char* str = a.ToNewCString();
|
|
||||||
Recycle(password);
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nsnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ApplicationFreeCallback(char *userInput)
|
|
||||||
{
|
|
||||||
nsAllocator::Free(userInput);
|
|
||||||
}
|
|
||||||
|
|
||||||
char * FilePathPromptCallback(void *arg, char *prompt, char *fileRegEx, CMUint32 shouldFileExist)
|
|
||||||
{
|
|
||||||
nsresult rv = NS_OK;
|
|
||||||
|
|
||||||
char* filePath = nsnull;
|
|
||||||
|
|
||||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
|
||||||
|
|
||||||
if(NS_SUCCEEDED(rv))
|
|
||||||
handler->PromptForFile(prompt, fileRegEx, (PRBool)shouldFileExist, &filePath);
|
|
||||||
|
|
||||||
return filePath;
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
||||||
*
|
|
||||||
* The contents of this file are subject to the Mozilla Public
|
|
||||||
* License Version 1.1 (the "License"); you may not use this file
|
|
||||||
* except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at http://www.mozilla.org/MPL/
|
|
||||||
*
|
|
||||||
* Software distributed under the License is distributed on an "AS
|
|
||||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
||||||
* implied. See the License for the specific language governing
|
|
||||||
* rights and limitations under the License.
|
|
||||||
*
|
|
||||||
* The Original Code is mozilla.org code.
|
|
||||||
*
|
|
||||||
* The Initial Developer of the Original Code is Netscape
|
|
||||||
* Communications Corporation. Portions created by Netscape are
|
|
||||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
||||||
* Rights Reserved.
|
|
||||||
*
|
|
||||||
* Contributor(s):
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _NSPSMUICALLBACKS_H
|
|
||||||
#define _NSPSMUICALLBACKS_H
|
|
||||||
|
|
||||||
#include "prtypes.h"
|
|
||||||
#include "nsIPSMUIHandler.h"
|
|
||||||
|
|
||||||
PR_BEGIN_EXTERN_C
|
|
||||||
|
|
||||||
#include "cmtcmn.h" /* fix */
|
|
||||||
#include "cmtjs.h"
|
|
||||||
|
|
||||||
PRStatus InitPSMUICallbacks(PCMT_CONTROL gControl);
|
|
||||||
PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, void *arg);
|
|
||||||
|
|
||||||
PR_END_EXTERN_C
|
|
||||||
|
|
||||||
#define NS_PSMUIHANDLER_CID {0x15944e30, 0x601e, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
|
|
||||||
|
|
||||||
class nsPSMUIHandlerImpl : public nsIPSMUIHandler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
|
|
||||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_PSMUIHANDLER_CID );
|
|
||||||
|
|
||||||
/* ctor/dtor */
|
|
||||||
nsPSMUIHandlerImpl() { NS_INIT_REFCNT(); }
|
|
||||||
virtual ~nsPSMUIHandlerImpl() { }
|
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
|
||||||
NS_DECL_NSIPSMUIHANDLER
|
|
||||||
|
|
||||||
static NS_METHOD CreatePSMUIHandler(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
Загрузка…
Ссылка в новой задаче