Compare commits
13 Commits
less_stati
...
SDR_BRANCH
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ffb191c83 | ||
|
|
c1f01e46d5 | ||
|
|
ce340e35d3 | ||
|
|
d7d144afee | ||
|
|
a8fe1ddfbd | ||
|
|
1c9f7079b4 | ||
|
|
5d61efd096 | ||
|
|
6b5b2866e9 | ||
|
|
928e14859f | ||
|
|
a2d9adab4a | ||
|
|
c3508f9c29 | ||
|
|
2c17c30693 | ||
|
|
dad482a331 |
32
mozilla/extensions/psm-glue/Makefile.in
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 = public src res
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
BIN
mozilla/extensions/psm-glue/macbuild/PSMGlue.mcp
Normal file
BIN
mozilla/extensions/psm-glue/macbuild/psmglueIDL.mcp
Normal file
27
mozilla/extensions/psm-glue/makefile.win
Normal file
@@ -0,0 +1,27 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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=..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
DIRS = public src res
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
4
mozilla/extensions/psm-glue/public/MANIFEST
Normal file
@@ -0,0 +1,4 @@
|
||||
nsIPSMComponent.idl
|
||||
nsIPSMUIHandler.idl
|
||||
nsISecureBrowserUI.idl
|
||||
nsISSLSocketProvider.idl
|
||||
45
mozilla/extensions/psm-glue/public/Makefile.in
Normal file
@@ -0,0 +1,45 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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):
|
||||
# Hubbie Shaw
|
||||
# Doug Turner <dougt@netscape.com>
|
||||
# Terry Hayes <thayes@netscape.com>
|
||||
#
|
||||
|
||||
MODULE = psmglue
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIPSMComponent.idl \
|
||||
nsIPSMUIHandler.idl \
|
||||
nsISecureBrowserUI.idl \
|
||||
nsIPSMSocketInfo.idl \
|
||||
nsISSLSocketProvider.idl \
|
||||
nsISecretDecoderRing.idl \
|
||||
$(NULL)
|
||||
|
||||
PREF_JS_EXPORTS = $(srcdir)/psm-glue.js
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
53
mozilla/extensions/psm-glue/public/makefile.win
Normal file
@@ -0,0 +1,53 @@
|
||||
#!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):
|
||||
# Hubbie Shaw
|
||||
# Doug Turner <dougt@netscape.com>
|
||||
# Terry Hayes <thayes@netscape.com>
|
||||
#
|
||||
|
||||
MODULE = psmglue
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DLLNAME = psmglue
|
||||
PDBFILE = $(DLLNAME).pdb
|
||||
MAPFILE = $(DLLNAME).map
|
||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
XPIDL_INCLUDES=-I$(DEPTH)\..\mozilla\dist\idl
|
||||
|
||||
XPIDLSRCS= \
|
||||
.\nsIPSMComponent.idl \
|
||||
.\nsIPSMUIHandler.idl \
|
||||
.\nsISecureBrowserUI.idl \
|
||||
.\nsISSLSocketProvider.idl \
|
||||
.\nsIPSMSocketInfo.idl \
|
||||
.\nsISecretDecoderRing.idl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install::
|
||||
$(MAKE_INSTALL) .\psm-glue.js $(DIST)\bin\defaults\pref
|
||||
87
mozilla/extensions/psm-glue/public/nsIPSMComponent.idl
Normal file
@@ -0,0 +1,87 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
* Mitch Stoltz <mstoltz@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.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( );
|
||||
|
||||
/**
|
||||
* Display the Security Advisor. PickledStatus and hostName can be null.
|
||||
* If they are, the "Selected Info" dialog will be empty.
|
||||
*/
|
||||
|
||||
void displaySecurityAdvisor(in string pickledStatus, in string hostName);
|
||||
|
||||
/**
|
||||
* This will send PSM all preferences that we know about.
|
||||
*/
|
||||
void passPrefs();
|
||||
|
||||
/* Sig Verification Error Codes */
|
||||
const long VERIFY_OK = 0;
|
||||
const long VERIFY_NOSIG = -2;
|
||||
const long VERIFY_ERROR_UNKNOWN_CA = -8172;
|
||||
|
||||
/* Hash Algorithms (based on cmtcmn.h) */
|
||||
const short MD2 = 1;
|
||||
const short MD5 = 2;
|
||||
const short SHA1 = 3;
|
||||
const unsigned long MD2_LENGTH = 16;
|
||||
const unsigned long MD5_LENGTH = 16;
|
||||
const unsigned long SHA1_LENGTH = 20;
|
||||
const unsigned long MAX_HASH_LENGTH = SHA1_LENGTH;
|
||||
|
||||
/* 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, out long result);
|
||||
nsIPrincipal CreatePrincipalFromCert(in unsigned long certID);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define PSM_COMPONENT_PROGID "component://netscape/psm"
|
||||
#define PSM_COMPONENT_CLASSNAME "Mozilla PSM Component"
|
||||
%}
|
||||
|
||||
45
mozilla/extensions/psm-glue/public/nsIPSMSocketInfo.idl
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*- 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):
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{C++
|
||||
#include "cmtcmn.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
%}
|
||||
|
||||
[ptr] native psmtControlStar(CMT_CONTROL);
|
||||
[ptr] native cmSocketStar(CMSocket);
|
||||
[ptr] native nsFileDescStar(PRFileDesc);
|
||||
|
||||
[noscript, uuid(deeb8dfc-fb7a-11d3-ac84-00c04fa0d26b)]
|
||||
interface nsIPSMSocketInfo : nsISupports {
|
||||
|
||||
readonly attribute string hostName;
|
||||
readonly attribute psmtControlStar controlPtr;
|
||||
readonly attribute cmSocketStar socketPtr;
|
||||
readonly attribute nsFileDescStar fileDescPtr;
|
||||
|
||||
void getPickledStatus(out charStar pickledStatus);
|
||||
};
|
||||
|
||||
36
mozilla/extensions/psm-glue/public/nsIPSMUIHandler.idl
Normal file
@@ -0,0 +1,36 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* 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 wstring 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"
|
||||
%}
|
||||
35
mozilla/extensions/psm-glue/public/nsISSLSocketProvider.idl
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISocketProvider.idl"
|
||||
|
||||
[noscript, uuid(856a93d0-5415-11d3-bbc8-0000861d1237)]
|
||||
interface nsISSLSocketProvider : nsISocketProvider {
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_ISSLSOCKETPROVIDER_PROGID NS_NETWORK_SOCKET_PROGID_PREFIX "ssl"
|
||||
#define NS_ISSLSOCKETPROVIDER_CLASSNAME "Mozilla SSL Socket Provider Component"
|
||||
|
||||
%}
|
||||
63
mozilla/extensions/psm-glue/public/nsISecretDecoderRing.idl
Normal file
@@ -0,0 +1,63 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
* thayes@netscape.com
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/* Buffer type - for storing 8-bit octet values */
|
||||
[ptr] native buffer(unsigned char);
|
||||
|
||||
[scriptable, uuid(0EC80360-075C-11d4-9FD4-00C04F1B83D8)]
|
||||
interface nsISecretDecoderRing: nsISupports {
|
||||
|
||||
/* Encrypt a buffer - callable only from C++ */
|
||||
[noscript] long encrypt(in buffer data, in long dataLen, out buffer result);
|
||||
|
||||
/* Decrypt a buffer - callable only from C++ */
|
||||
[noscript] long decrypt(in buffer data, in long dataLen, out buffer result);
|
||||
|
||||
/* Encrypt nul-terminated string to BASE64 output */
|
||||
string encryptString(in string text);
|
||||
|
||||
/* Decrypt BASE64 input to nul-terminated string output */
|
||||
/* There is no check for embedded nul values in the decrypted output */
|
||||
string decryptString(in string crypt);
|
||||
|
||||
/* Prompt the user to change the password on the SDR key */
|
||||
void changePassword();
|
||||
|
||||
/* Logout of the security device that protects the SDR key */
|
||||
void logout();
|
||||
};
|
||||
|
||||
/*
|
||||
* Configuration interface for the Secret Decoder Ring
|
||||
* - this interface allows setting the window that will be
|
||||
* used as parent for dialog windows (such as password prompts)
|
||||
*/
|
||||
[scriptable, uuid(01D8C0F0-0CCC-11d4-9FDD-000064657374)]
|
||||
interface nsISecretDecoderRingConfig: nsISupports {
|
||||
void setWindow(in nsISupports w);
|
||||
};
|
||||
|
||||
|
||||
44
mozilla/extensions/psm-glue/public/nsISecureBrowserUI.idl
Normal file
@@ -0,0 +1,44 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#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);
|
||||
void displayPageInfoUI();
|
||||
};
|
||||
|
||||
%{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}}
|
||||
|
||||
%}
|
||||
11
mozilla/extensions/psm-glue/public/psm-glue.js
Normal file
@@ -0,0 +1,11 @@
|
||||
pref("general.useragent.security", "U");
|
||||
|
||||
pref("security.enable_ssl2", true);
|
||||
pref("security.enable_ssl3", true);
|
||||
pref("security.default_personal_cert", "Select Automatically");
|
||||
pref("security.ask_for_password", 0);
|
||||
pref("security.password_lifetime", 30);
|
||||
pref("security.warn_entering_secure", true);
|
||||
pref("security.warn_leaving_secure", true);
|
||||
pref("security.warn_viewing_mixed", true);
|
||||
pref("security.warn_submit_insecure", true);
|
||||
32
mozilla/extensions/psm-glue/res/Makefile.in
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 = content skin locale
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
1
mozilla/extensions/psm-glue/res/content/MANIFEST_GLOBAL
Normal file
@@ -0,0 +1 @@
|
||||
PSMTaskMenu.xul
|
||||
2
mozilla/extensions/psm-glue/res/content/MANIFEST_NAV
Normal file
@@ -0,0 +1,2 @@
|
||||
NavSecurityOverlay.xul
|
||||
NavSecurityUI.js
|
||||
43
mozilla/extensions/psm-glue/res/content/Makefile.in
Normal file
@@ -0,0 +1,43 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
NAVIGATOR_CONTENT_DIR = $(DIST)/bin/chrome/navigator/content/
|
||||
NAVIGATOR_EXPORT_CONTENT = \
|
||||
$(srcdir)/NavSecurityOverlay.xul \
|
||||
$(srcdir)/NavSecurityUI.js \
|
||||
$(NULL)
|
||||
|
||||
GLOBAL_CONTENT_DIR = $(DIST)/bin/chrome/global/content/
|
||||
GLOBAL_EXPORT_CONTENT = \
|
||||
$(srcdir)/PSMTaskMenu.xul \
|
||||
$(NULL)
|
||||
|
||||
install::
|
||||
$(INSTALL) $(NAVIGATOR_EXPORT_CONTENT) $(NAVIGATOR_CONTENT_DIR)
|
||||
$(INSTALL) $(GLOBAL_EXPORT_CONTENT) $(GLOBAL_CONTENT_DIR)
|
||||
@@ -0,0 +1,14 @@
|
||||
<?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>
|
||||
45
mozilla/extensions/psm-glue/res/content/NavSecurityUI.js
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*- 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);
|
||||
|
||||
var securityUI;
|
||||
|
||||
function SetSecurityButton()
|
||||
{
|
||||
dump("in SetSecurityButton\n");
|
||||
|
||||
var ui = Components.classes["component://netscape/secure_browser_ui"].createInstance();
|
||||
securityUI = ui.QueryInterface(Components.interfaces.nsSecureBrowserUI);
|
||||
|
||||
var button = document.getElementById('security-button');
|
||||
if (button && window.content)
|
||||
securityUI.init(window.content, button);
|
||||
}
|
||||
|
||||
function displayPageInfo()
|
||||
{
|
||||
if (securityUI)
|
||||
securityUI.displayPageInfoUI();
|
||||
}
|
||||
|
||||
|
||||
24
mozilla/extensions/psm-glue/res/content/PSMTaskMenu.xul
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://global/locale/PSMTaskMenu.dtd" >
|
||||
|
||||
<overlay id="psmTaskMenuID"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<html:script language="JavaScript">
|
||||
|
||||
function displaySecurityAdvisor()
|
||||
{
|
||||
var psm = Components.classes["component://netscape/psm"].getService();
|
||||
psm = psm.QueryInterface(Components.interfaces.nsIPSMComponent);
|
||||
psm.displaySecurityAdvisor( null, null );
|
||||
}
|
||||
|
||||
</html:script>
|
||||
|
||||
<menupopup id="personalManagers">
|
||||
<menuitem id="PSMMentItem" position="1" value="&PSMCmd.label;" oncommand="displaySecurityAdvisor()"/>
|
||||
</menupopup>
|
||||
|
||||
</overlay>
|
||||
37
mozilla/extensions/psm-glue/res/content/makefile.win
Normal file
@@ -0,0 +1,37 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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=..\..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) NavSecurityOverlay.xul $(DIST)\bin\chrome\navigator\content
|
||||
$(MAKE_INSTALL) NavSecurityUI.js $(DIST)\bin\chrome\navigator\content
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) PSMTaskMenu.xul $(DIST)\bin\chrome\global\content
|
||||
|
||||
clobber::
|
||||
$(RM) $(DIST)\bin\chrome\navigator\content\NavSecurityOverlay.xul
|
||||
$(RM) $(DIST)\bin\chrome\navigator\content\NavSecurityUI.js
|
||||
$(RM) $(DIST)\bin\chrome\global\content\PSMTaskMenu.xul
|
||||
|
||||
32
mozilla/extensions/psm-glue/res/locale/Makefile.in
Normal file
@@ -0,0 +1,32 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 = en-US
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
1
mozilla/extensions/psm-glue/res/locale/en-US/MANIFEST
Normal file
@@ -0,0 +1 @@
|
||||
PSMTaskMenu.dtd
|
||||
@@ -0,0 +1 @@
|
||||
security.properties
|
||||
44
mozilla/extensions/psm-glue/res/locale/en-US/Makefile.in
Normal file
@@ -0,0 +1,44 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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
|
||||
|
||||
EXPORT_RESOURCE_CONTENT = \
|
||||
$(srcdir)/PSMTaskMenu.dtd \
|
||||
$(NULL)
|
||||
|
||||
EXPORT_NAV_RESOURCE_CONTENT = \
|
||||
$(srcdir)/security.properties \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
install::
|
||||
$(INSTALL) $(EXPORT_RESOURCE_CONTENT) $(DIST)/bin/chrome/global/locale
|
||||
$(INSTALL) $(EXPORT_NAV_RESOURCE_CONTENT) $(DIST)/bin/chrome/navigator/locale
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<!ENTITY PSMCmd.label "Security Manager">
|
||||
36
mozilla/extensions/psm-glue/res/locale/en-US/makefile.win
Normal file
@@ -0,0 +1,36 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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=..\..\..\..\..
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
GLOBAL_DIST=$(DIST)\bin\chrome\global\locale
|
||||
NAV_DIST=$(DIST)\bin\chrome\navigator\locale
|
||||
|
||||
|
||||
install::
|
||||
$(MAKE_INSTALL) PSMTaskMenu.dtd $(GLOBAL_DIST)
|
||||
$(MAKE_INSTALL) security.properties $(NAV_DIST)
|
||||
|
||||
clobber::
|
||||
$(RM) -f $(DIST)\bin\chrome\global\locale\PSMTaskMenu.dtd
|
||||
$(RM) -f $(DIST)\bin\chrome\navigator\locale\security.properties
|
||||
@@ -0,0 +1,28 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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):
|
||||
#
|
||||
|
||||
Title=Security Warning
|
||||
MixedContentMessage=You have requested a secure document that contains some insecure information.
|
||||
LeaveSiteMessage=You have requested an insecure document. The document and any information you send back could be observed by a third party while in transit.
|
||||
EnterSiteMessage=You have requested a secure document. The document and any information you send back are encrypted for privacy while in transit.
|
||||
PostToInsecure=Although this document is secure, the information you have submitted is insecure and could be observed by a third party while in transit. If you are submitting passwords, credit card numbers, or other information you would like to keep private, it would be safer for you to cancel the submission.
|
||||
DontShowAgain=Show Me This Alert Next Time.
|
||||
FindText=Please find the Personal Security Manager application
|
||||
27
mozilla/extensions/psm-glue/res/locale/makefile.win
Normal file
@@ -0,0 +1,27 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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=..\..\..\..
|
||||
|
||||
DIRS=en-US
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
27
mozilla/extensions/psm-glue/res/makefile.win
Normal file
@@ -0,0 +1,27 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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=..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
DIRS = skin content locale
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
4
mozilla/extensions/psm-glue/res/skin/MANIFEST
Normal file
@@ -0,0 +1,4 @@
|
||||
lock.gif
|
||||
unlock.gif
|
||||
broken.gif
|
||||
NavSecurityOverlay.css
|
||||
39
mozilla/extensions/psm-glue/res/skin/Makefile.in
Normal file
@@ -0,0 +1,39 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
SKIN_DIR = $(DIST)/bin/chrome/navigator/skin/
|
||||
EXPORT_SKINS = \
|
||||
$(srcdir)/broken.gif \
|
||||
$(srcdir)/lock.gif \
|
||||
$(srcdir)/unlock.gif \
|
||||
$(srcdir)/NavSecurityOverlay.css \
|
||||
$(NULL)
|
||||
|
||||
install::
|
||||
$(INSTALL) $(EXPORT_SKINS) $(SKIN_DIR)
|
||||
15
mozilla/extensions/psm-glue/res/skin/NavSecurityOverlay.css
Normal file
@@ -0,0 +1,15 @@
|
||||
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");
|
||||
}
|
||||
BIN
mozilla/extensions/psm-glue/res/skin/broken.gif
Normal file
|
After Width: | Height: | Size: 88 B |
BIN
mozilla/extensions/psm-glue/res/skin/lock.gif
Normal file
|
After Width: | Height: | Size: 76 B |
41
mozilla/extensions/psm-glue/res/skin/makefile.win
Normal file
@@ -0,0 +1,41 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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=..\..\..\..
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install::
|
||||
$(MAKE_INSTALL) broken.gif $(DIST)\bin\chrome\navigator\skin
|
||||
$(MAKE_INSTALL) lock.gif $(DIST)\bin\chrome\navigator\skin
|
||||
$(MAKE_INSTALL) unlock.gif $(DIST)\bin\chrome\navigator\skin
|
||||
$(MAKE_INSTALL) NavSecurityOverlay.css $(DIST)\bin\chrome\navigator\skin
|
||||
|
||||
clobber::
|
||||
$(RM) $(DIST)\bin\chrome\navigator\skin\broken.gif
|
||||
$(RM) $(DIST)\bin\chrome\navigator\skin\lock.gif
|
||||
$(RM) $(DIST)\bin\chrome\navigator\skin\unlock.gif
|
||||
$(RM) $(DIST)\bin\chrome\navigator\skin\NavSecurityOverlay.css
|
||||
|
||||
|
||||
|
||||
BIN
mozilla/extensions/psm-glue/res/skin/unlock.gif
Normal file
|
After Width: | Height: | Size: 67 B |
63
mozilla/extensions/psm-glue/src/Makefile.in
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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):
|
||||
# Hubbie Shaw
|
||||
# Doug Turner <dougt@netscape.com>
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = psmglue
|
||||
|
||||
IS_COMPONENT = 1
|
||||
LIBRARY_NAME = psmglue
|
||||
|
||||
|
||||
CPPSRCS = \
|
||||
nsPSMComponent.cpp \
|
||||
nsPSMUICallbacks.cpp \
|
||||
nsSSLSocketProvider.cpp \
|
||||
nsPSMModule.cpp \
|
||||
nsSSLIOLayer.cpp \
|
||||
nsSecureBrowserUIImpl.cpp \
|
||||
nsSDR.cpp \
|
||||
$(NULL)
|
||||
|
||||
CSRCS = \
|
||||
nsPSMMutex.c \
|
||||
nsPSMShimLayer.c \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS = \
|
||||
$(MOZ_COMPONENT_LIBS) \
|
||||
-lcmt \
|
||||
-lprotocol \
|
||||
-lmozjs \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
INCLUDES += \
|
||||
-I$(srcdir) \
|
||||
$(NULL)
|
||||
68
mozilla/extensions/psm-glue/src/makefile.win
Normal file
@@ -0,0 +1,68 @@
|
||||
#!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):
|
||||
# Hubbie Shaw
|
||||
# Doug Turner <dougt@netscape.com>
|
||||
#
|
||||
|
||||
MODULE = psmglue
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DLLNAME = psmglue
|
||||
PDBFILE = $(DLLNAME).pdb
|
||||
MAPFILE = $(DLLNAME).map
|
||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
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)
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsPSMMutex.obj \
|
||||
.\$(OBJDIR)\nsPSMShimLayer.obj \
|
||||
.\$(OBJDIR)\nsPSMComponent.obj \
|
||||
.\$(OBJDIR)\nsPSMUICallbacks.obj \
|
||||
.\$(OBJDIR)\nsPSMModule.obj \
|
||||
.\$(OBJDIR)\nsSecureBrowserUIImpl.obj \
|
||||
.\$(OBJDIR)\nsSSLIOLayer.obj \
|
||||
.\$(OBJDIR)\nsSSLSocketProvider.obj \
|
||||
.\$(OBJDIR)\nsSDR.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
822
mozilla/extensions/psm-glue/src/nsPSMComponent.cpp
Normal file
@@ -0,0 +1,822 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
* Mitch Stoltz <mstoltz@netscape.com>
|
||||
*/
|
||||
|
||||
#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 "rsrcids.h"
|
||||
|
||||
#include "nsPSMMutex.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsICertificatePrincipal.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(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_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_THREADSAFE_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 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;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::PassPrefs()
|
||||
{
|
||||
// if we have not passed anything to psm yet, this function can just return.
|
||||
|
||||
if (!mControl)
|
||||
return NS_OK;
|
||||
|
||||
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 = 0; /* 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 = 30; /* 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))
|
||||
{
|
||||
NS_WITH_SERVICE(nsIStringBundleService, service, kCStringBundleServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsILocale* locale = nsnull;
|
||||
nsCOMPtr<nsIStringBundle> stringBundle;
|
||||
|
||||
rv = service->CreateBundle(SECURITY_STRING_BUNDLE_URL, locale, getter_AddRefs(stringBundle));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRUnichar *ptrv = nsnull;
|
||||
rv = stringBundle->GetStringFromName( NS_ConvertASCIItoUCS2("FindText").GetUnicode(), &ptrv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
handler->PromptForFile(ptrv, PSM_FILE_NAME, PR_TRUE, &filePath);
|
||||
|
||||
nsAllocator::Free(ptrv);
|
||||
|
||||
}
|
||||
if (! filePath)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mControl = CMT_EstablishControlConnection(filePath, &nsPSMShimTbl, &nsPSMMutexTbl);
|
||||
}
|
||||
|
||||
|
||||
if (!mControl || InitPSMUICallbacks(mControl) != PR_SUCCESS)
|
||||
goto failure;
|
||||
|
||||
nsFileSpec profileSpec;
|
||||
PRUnichar* profileName;
|
||||
|
||||
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;
|
||||
nsCAutoString profilenameC;
|
||||
profilenameC.AssignWithConversion(profileName);
|
||||
psmStatus = CMT_Hello( mControl,
|
||||
PROTOCOL_VERSION,
|
||||
profilenameC,
|
||||
(char*)profileSpec.GetNativePathCString());
|
||||
|
||||
if (psmStatus == CMTFailure)
|
||||
{
|
||||
PR_FREEIF(profileName);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (NS_FAILED(PassPrefs()))
|
||||
{
|
||||
PR_FREEIF(profileName);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
PR_FREEIF(profileName);
|
||||
|
||||
*_retval = mControl;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
failure:
|
||||
#ifdef DEBUG
|
||||
printf("*** Failure setting up Cartman! \n");
|
||||
#endif
|
||||
|
||||
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(const char *pickledStatus, const char *hostName)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
GetControlConnection( &controlConnection );
|
||||
if (DisplayPSMUIDialog(controlConnection, pickledStatus, hostName) == 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 aKeepCert,
|
||||
nsIPrincipal** aPrincipal,
|
||||
PRInt32* aVerifyError)
|
||||
{
|
||||
*aVerifyError = -1;
|
||||
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) return NS_ERROR_FAILURE;
|
||||
if (!isSigned)
|
||||
{
|
||||
*aPrincipal = nsnull;
|
||||
*aVerifyError = nsIPSMComponent::VERIFY_NOSIG;
|
||||
return NS_OK;
|
||||
}
|
||||
// SHA1 hash the plaintext to compare it to the signature
|
||||
CMUint32 hashId;
|
||||
CMT_HashCreate(controlConnection, nsIPSMComponent::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(nsIPSMComponent::SHA1_LENGTH);
|
||||
if (!hash) return NS_ERROR_OUT_OF_MEMORY;
|
||||
CMUint32 hashLen;
|
||||
result = CMT_HASH_End(controlConnection, hashId, hash,
|
||||
&hashLen, nsIPSMComponent::SHA1_LENGTH);
|
||||
NS_ASSERTION(hashLen == nsIPSMComponent::SHA1_LENGTH,
|
||||
"PSMComponent: Hash too short.");
|
||||
CMT_HASH_Destroy(controlConnection, hashId);
|
||||
if (result != CMTSuccess)
|
||||
{
|
||||
PR_FREEIF(hash);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
//-- Verify signature
|
||||
CMTItemStr hashItem;
|
||||
hashItem.data = hash;
|
||||
hashItem.len = hashLen;
|
||||
result = CMT_PKCS7VerifyDetachedSignature(controlConnection, contentInfo,
|
||||
6 /* =Object Signing Cert */,
|
||||
3 /* =SHA1 algorithm (MD5=2)*/,
|
||||
(CMUint32)aKeepCert,
|
||||
&hashItem, (CMInt32*)aVerifyError);
|
||||
PR_FREEIF(hash);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
//-- Did it verify?
|
||||
|
||||
if (*aVerifyError != 0)
|
||||
*aPrincipal = nsnull;
|
||||
else
|
||||
{
|
||||
//-- Generate a principal from the cert
|
||||
CMUint32 certID;
|
||||
result = CMT_GetRIDAttribute(controlConnection, contentInfo,
|
||||
SSM_FID_P7CINFO_SIGNER_CERT, &certID);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(CreatePrincipalFromCert(certID, aPrincipal)))
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
CMT_PKCS7DestroyContentInfo(controlConnection, contentInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::CreatePrincipalFromCert(PRUint32 aCertID, nsIPrincipal** aPrincipal)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
//-- Read cert ID
|
||||
CMTStatus result;
|
||||
|
||||
CMTItem fingerprint;
|
||||
result = CMT_GetStringAttribute(controlConnection, aCertID,
|
||||
SSM_FID_CERT_FINGERPRINT, &fingerprint);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
|
||||
//-- 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*)fingerprint.data,
|
||||
aPrincipal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
//-- Get common name and store it in the principal.
|
||||
// Using common name + organizational unit as the user-visible certificate name
|
||||
nsCOMPtr<nsICertificatePrincipal> certificate = do_QueryInterface(*aPrincipal, &rv);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
CMTItem common;
|
||||
result = CMT_GetStringAttribute(controlConnection, aCertID,
|
||||
SSM_FID_CERT_COMMON_NAME, &common);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
CMTItem subject;
|
||||
result = CMT_GetStringAttribute(controlConnection, aCertID,
|
||||
SSM_FID_CERT_SUBJECT_NAME, &subject);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCAutoString commonName;
|
||||
commonName = (char*)common.data;
|
||||
static const char orgUnitTag[] = " OU=";
|
||||
char* orgUnitPos = PL_strstr((char*)subject.data, orgUnitTag);
|
||||
if (orgUnitPos)
|
||||
{
|
||||
orgUnitPos += sizeof(orgUnitTag)-1;
|
||||
char* orgUnitEnd = PL_strchr(orgUnitPos, ',');
|
||||
PRInt32 orgUnitLen;
|
||||
if(orgUnitEnd)
|
||||
orgUnitLen = orgUnitEnd - orgUnitPos;
|
||||
else
|
||||
orgUnitLen = PL_strlen(orgUnitPos);
|
||||
commonName.Append(' ');
|
||||
commonName.Append(orgUnitPos, orgUnitLen);
|
||||
}
|
||||
char* commonChar = commonName.ToNewCString();
|
||||
if (!commonChar) return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = certificate->SetCommonName(commonChar);
|
||||
Recycle(commonChar);
|
||||
return rv;
|
||||
}
|
||||
|
||||
54
mozilla/extensions/psm-glue/src/nsPSMComponent.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
#define SECURITY_STRING_BUNDLE_URL "chrome://navigator/locale/security.properties"
|
||||
|
||||
#define NS_PSMCOMPONENT_CID {0xddcae170, 0x5412, 0x11d3, {0xbb, 0xc8, 0x00, 0x00, 0x86, 0x1d, 0x12, 0x37}}
|
||||
|
||||
// Implementation of the PSM 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;
|
||||
};
|
||||
86
mozilla/extensions/psm-glue/src/nsPSMModule.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#include "nsPSMUICallbacks.h"
|
||||
#include "nsPSMComponent.h"
|
||||
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsSecureBrowserUIImpl.h"
|
||||
|
||||
#include "nsSSLSocketProvider.h"
|
||||
|
||||
#include "nsSDR.h"
|
||||
|
||||
// Define SDR object constructor
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSecretDecoderRing, init)
|
||||
|
||||
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_SECURE_BROWSER_UI_CLASSNAME,
|
||||
NS_SECURE_BROWSER_UI_CID,
|
||||
NS_SECURE_BROWSER_UI_PROGID,
|
||||
nsSecureBrowserUIImpl::Create
|
||||
},
|
||||
|
||||
{
|
||||
NS_SECURE_BROWSER_DOCOBSERVER_CLASSNAME,
|
||||
NS_SECURE_BROWSER_DOCOBSERVER_CID,
|
||||
NS_SECURE_BROWSER_DOCOBSERVER_PROGID,
|
||||
nsSecureBrowserUIImpl::Create
|
||||
},
|
||||
|
||||
{
|
||||
NS_ISSLSOCKETPROVIDER_CLASSNAME,
|
||||
NS_SSLSOCKETPROVIDER_CID,
|
||||
NS_ISSLSOCKETPROVIDER_PROGID,
|
||||
nsSSLSocketProvider::Create
|
||||
},
|
||||
|
||||
{
|
||||
NS_SDR_CLASSNAME,
|
||||
NS_SDR_CID,
|
||||
NS_SDR_PROGID,
|
||||
nsSecretDecoderRingConstructor
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("PSMComponent", components);
|
||||
72
mozilla/extensions/psm-glue/src/nsPSMMutex.c
Normal file
@@ -0,0 +1,72 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "prmon.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
#include "nsPSMMutex.h"
|
||||
|
||||
static PRMonitor *_nsPSMMutexVar;
|
||||
|
||||
PRStatus
|
||||
nsPSMMutexInit()
|
||||
{
|
||||
if (!_nsPSMMutexVar)
|
||||
_nsPSMMutexVar = PR_NewMonitor();
|
||||
|
||||
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
|
||||
};
|
||||
39
mozilla/extensions/psm-glue/src/nsPSMMutex.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#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
|
||||
284
mozilla/extensions/psm-glue/src/nsPSMShimLayer.c
Normal file
@@ -0,0 +1,284 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#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 (!sock) return CMTFailure;
|
||||
|
||||
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;
|
||||
struct stat statbuf;
|
||||
|
||||
cmSock = (CMSocket *)sock;
|
||||
|
||||
if (!cmSock || !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;
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
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;
|
||||
|
||||
if (!socks) return NULL;
|
||||
|
||||
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;
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
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;
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
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);
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
rv = PR_Close(cmSock->fd);
|
||||
cmSock->fd = NULL;
|
||||
|
||||
PR_Free(cmSock);
|
||||
|
||||
return (PR_SUCCESS == rv) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
67
mozilla/extensions/psm-glue/src/nsPSMShimLayer.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSPSMSHIMLAYER_H_
|
||||
#define _NSPSMSHIMLAYER_H_
|
||||
|
||||
#include "cmtcmn.h"
|
||||
#include "prio.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
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_ */
|
||||
333
mozilla/extensions/psm-glue/src/nsPSMUICallbacks.cpp
Normal file
@@ -0,0 +1,333 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsIFilePicker.h"
|
||||
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsSSLIOLayer.h" // for SSMSTRING_PADDED_LENGTH
|
||||
#include "ssmdefs.h"
|
||||
#include "rsrcids.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, PRBool isModel,
|
||||
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;
|
||||
nsCOMPtr<nsIDOMWindow> hiddenWindow;
|
||||
JSContext *jsContext;
|
||||
|
||||
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = appShell->GetHiddenWindowAndJSContext( getter_AddRefs( hiddenWindow ),
|
||||
&jsContext );
|
||||
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
// Set up arguments for "window.open"
|
||||
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;
|
||||
hiddenWindow->Open(jsContext, argv, 3, &newWindow);
|
||||
newWindow->ResizeTo(width, height);
|
||||
JS_PopArguments(jsContext, stackPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMUIHandlerImpl::PromptForFile(const PRUnichar *prompt, const char *fileRegEx, PRBool shouldFileExist, char **outFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outFile);
|
||||
nsCOMPtr<nsIFilePicker> fp = do_CreateInstance("component://mozilla/filepicker");
|
||||
|
||||
if (!fp)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
|
||||
fp->Init(nsnull, prompt, nsIFilePicker::modeOpen);
|
||||
fp->SetFilters(nsIFilePicker::filterAll);
|
||||
fp->AppendFilter(NS_ConvertASCIItoUCS2(fileRegEx).GetUnicode(), NS_ConvertASCIItoUCS2(fileRegEx).GetUnicode());
|
||||
PRInt16 mode;
|
||||
nsresult rv = fp->Show(&mode);
|
||||
|
||||
if (NS_FAILED(rv) || (mode == nsIFilePicker::returnCancel))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
rv = fp->GetFile(getter_AddRefs(file));
|
||||
|
||||
if (file)
|
||||
file->GetPath(outFile);
|
||||
|
||||
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, const char *pickledStatus, const char *hostName)
|
||||
{
|
||||
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));
|
||||
|
||||
if (hostName)
|
||||
{
|
||||
// if there is a hostName, than this request is about
|
||||
// a webpage.
|
||||
data.hostname = (char*) hostName;
|
||||
data.infoContext = SSM_BROWSER;
|
||||
|
||||
if (pickledStatus)
|
||||
{
|
||||
CMTItem pickledResource = {0, NULL, 0};
|
||||
CMUint32 socketStatus = 0;
|
||||
|
||||
pickledResource.len = *(int*)(pickledStatus);
|
||||
pickledResource.data = (unsigned char*) PR_Malloc(SSMSTRING_PADDED_LENGTH(pickledResource.len));
|
||||
|
||||
if (! pickledResource.data) return PR_FAILURE;
|
||||
|
||||
memcpy(pickledResource.data, pickledStatus+sizeof(int), pickledResource.len);
|
||||
|
||||
/* Unpickle the SSL Socket Status */
|
||||
if (CMT_UnpickleResource( control,
|
||||
SSM_RESTYPE_SSL_SOCKET_STATUS,
|
||||
pickledResource,
|
||||
&socketStatus) == CMTSuccess)
|
||||
{
|
||||
data.infoContext = SSM_BROWSER;
|
||||
data.resID = socketStatus;
|
||||
}
|
||||
|
||||
PR_FREEIF(pickledResource.data);
|
||||
}
|
||||
}
|
||||
|
||||
/* 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, nsnull, width, height, PR_FALSE, (char*)urlItem.data, NULL);
|
||||
|
||||
//allocated by cmt, we can free with free:
|
||||
free(urlItem.data);
|
||||
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void* CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, PRBool isModal, 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(NS_ConvertASCIItoUCS2(prompt).GetUnicode(), NS_ConvertASCIItoUCS2(" ").GetUnicode(), &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(NS_ConvertASCIItoUCS2(prompt).GetUnicode(), fileRegEx, (PRBool)shouldFileExist, &filePath);
|
||||
|
||||
return filePath;
|
||||
}
|
||||
55
mozilla/extensions/psm-glue/src/nsPSMUICallbacks.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSPSMUICALLBACKS_H
|
||||
#define _NSPSMUICALLBACKS_H
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#include "nsIPSMUIHandler.h"
|
||||
|
||||
PRStatus InitPSMUICallbacks(PCMT_CONTROL gControl);
|
||||
PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, const char* pickledStatus, const char *hostName);
|
||||
|
||||
|
||||
#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
|
||||
310
mozilla/extensions/psm-glue/src/nsSDR.cpp
Normal file
@@ -0,0 +1,310 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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):
|
||||
* thayes@netscape.com
|
||||
*/
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "plstr.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "plbase64.h"
|
||||
|
||||
#include "nsISecretDecoderRing.h"
|
||||
|
||||
#include "cmtcmn.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
|
||||
#include "nsSDR.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSecretDecoderRing, nsISecretDecoderRing)
|
||||
|
||||
nsSecretDecoderRing::nsSecretDecoderRing()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
||||
mPSM = NULL;
|
||||
}
|
||||
|
||||
nsSecretDecoderRing::~nsSecretDecoderRing()
|
||||
{
|
||||
if (mPSM) mPSM->Release();
|
||||
}
|
||||
|
||||
/* Init the new instance */
|
||||
nsresult nsSecretDecoderRing::
|
||||
init()
|
||||
{
|
||||
nsresult rv;
|
||||
nsISupports *psm;
|
||||
|
||||
rv = nsServiceManager::GetService(kPSMComponentProgID, NS_GET_IID(nsIPSMComponent),
|
||||
&psm);
|
||||
if (rv != NS_OK) goto loser; /* Should promote error */
|
||||
|
||||
mPSM = (nsIPSMComponent *)psm;
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* [noscript] long encrypt (in buffer data, in long dataLen, out buffer result); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
Encrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 *_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
unsigned char *r = 0;
|
||||
CMT_CONTROL *control;
|
||||
CMTStatus status;
|
||||
CMUint32 cLen;
|
||||
|
||||
if (data == nsnull || result == nsnull || _retval == nsnull) {
|
||||
rv = NS_ERROR_INVALID_POINTER;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Check object initialization */
|
||||
NS_ASSERTION(mPSM != nsnull, "SDR object not initialized");
|
||||
if (mPSM == nsnull) { rv = NS_ERROR_NOT_INITIALIZED; goto loser; }
|
||||
|
||||
/* Get the control connect to use for the request */
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (rv != NS_OK) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }
|
||||
|
||||
status = CMT_SDREncrypt(control, (const unsigned char *)0, 0,
|
||||
data, dataLen, result, &cLen);
|
||||
if (status != CMTSuccess) { rv = NS_ERROR_FAILURE; goto loser; } /* XXX */
|
||||
|
||||
/* Copy returned data to nsAllocator buffer ? */
|
||||
*_retval = cLen;
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* [noscript] long decrypt (in buffer data, in long dataLen, out buffer result); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
Decrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 *_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
CMTStatus status;
|
||||
CMT_CONTROL *control;
|
||||
CMUint32 len;
|
||||
|
||||
if (data == nsnull || result == nsnull || _retval == nsnull) {
|
||||
rv = NS_ERROR_INVALID_POINTER;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Check object initialization */
|
||||
NS_ASSERTION(mPSM != nsnull, "SDR object not initialized");
|
||||
if (mPSM == nsnull) { rv = NS_ERROR_NOT_INITIALIZED; goto loser; }
|
||||
|
||||
/* Get the control connection */
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (rv != NS_OK) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }
|
||||
|
||||
/* Call PSM to decrypt the value */
|
||||
status = CMT_SDRDecrypt(control, data, dataLen, result, &len);
|
||||
if (status != CMTSuccess) { rv = NS_ERROR_FAILURE; goto loser; } /* Promote? */
|
||||
|
||||
/* Copy returned data to nsAllocator buffer ? */
|
||||
*_retval = len;
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* string encryptString (in string text); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
EncryptString(const char *text, char **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
unsigned char *encrypted = 0;
|
||||
PRInt32 eLen;
|
||||
|
||||
if (text == nsnull || _retval == nsnull) {
|
||||
rv = NS_ERROR_INVALID_POINTER;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = Encrypt((unsigned char *)text, PL_strlen(text), &encrypted, &eLen);
|
||||
if (rv != NS_OK) { goto loser; }
|
||||
|
||||
rv = encode(encrypted, eLen, _retval);
|
||||
|
||||
loser:
|
||||
if (encrypted) nsAllocator::Free(encrypted);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* string decryptString (in string crypt); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
DecryptString(const char *crypt, char **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
char *r = 0;
|
||||
unsigned char *decoded = 0;
|
||||
PRInt32 decodedLen;
|
||||
unsigned char *decrypted = 0;
|
||||
PRInt32 decryptedLen;
|
||||
|
||||
if (crypt == nsnull || _retval == nsnull) {
|
||||
rv = NS_ERROR_INVALID_POINTER;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = decode(crypt, &decoded, &decodedLen);
|
||||
if (rv != NS_OK) goto loser;
|
||||
|
||||
rv = Decrypt(decoded, decodedLen, &decrypted, &decryptedLen);
|
||||
if (rv != NS_OK) goto loser;
|
||||
|
||||
// Convert to NUL-terminated string
|
||||
r = (char *)nsAllocator::Alloc(decryptedLen+1);
|
||||
if (!r) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
|
||||
|
||||
memcpy(r, decrypted, decryptedLen);
|
||||
r[decryptedLen] = 0;
|
||||
|
||||
*_retval = r;
|
||||
r = 0;
|
||||
|
||||
loser:
|
||||
if (r) nsAllocator::Free(r);
|
||||
if (decrypted) nsAllocator::Free(decrypted);
|
||||
if (decoded) nsAllocator::Free(decoded);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* void changePassword(); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
ChangePassword()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* void logout(); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
Logout()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
CMTStatus status;
|
||||
CMT_CONTROL *control;
|
||||
|
||||
/* Check object initialization */
|
||||
NS_ASSERTION(mPSM != nsnull, "SDR object not initialized");
|
||||
if (mPSM == nsnull) { rv = NS_ERROR_NOT_INITIALIZED; goto loser; }
|
||||
|
||||
/* Get the control connection */
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (rv != NS_OK) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }
|
||||
|
||||
/* Call PSM to decrypt the value */
|
||||
status = CMT_LogoutAllTokens(control);
|
||||
if (status != CMTSuccess) { rv = NS_ERROR_FAILURE; goto loser; } /* Promote? */
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// Support routines
|
||||
|
||||
nsresult nsSecretDecoderRing::
|
||||
encode(const unsigned char *data, PRInt32 dataLen, char **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*_retval = PL_Base64Encode((const char *)data, dataLen, NULL);
|
||||
if (!*_retval) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
|
||||
#if 0
|
||||
nsresult rv = NS_OK;
|
||||
char *r = 0;
|
||||
|
||||
// Allocate space for encoded string (with NUL)
|
||||
r = (char *)nsAllocator::Alloc(dataLen+1);
|
||||
if (!r) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
|
||||
|
||||
memcpy(r, data, dataLen);
|
||||
r[dataLen] = 0;
|
||||
|
||||
*_retval = r;
|
||||
r = 0;
|
||||
|
||||
loser:
|
||||
if (r) nsAllocator::Free(r);
|
||||
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult nsSecretDecoderRing::
|
||||
decode(const char *data, unsigned char **result, PRInt32 * _retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 len = PL_strlen(data);
|
||||
int adjust = 0;
|
||||
|
||||
/* Compute length adjustment */
|
||||
if (data[len-1] == '=') {
|
||||
adjust++;
|
||||
if (data[len-2] == '=') adjust++;
|
||||
}
|
||||
|
||||
*result = (unsigned char *)PL_Base64Decode(data, len, NULL);
|
||||
if (!*result) { rv = NS_ERROR_ILLEGAL_VALUE; goto loser; }
|
||||
|
||||
*_retval = (len*3)/4 - adjust;
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
|
||||
#if 0
|
||||
nsresult rv = NS_OK;
|
||||
unsigned char *r = 0;
|
||||
PRInt32 rLen;
|
||||
|
||||
// Allocate space for decoded string (missing NUL)
|
||||
rLen = PL_strlen(data);
|
||||
r = (unsigned char *)nsAllocator::Alloc(rLen);
|
||||
if (!r) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
|
||||
|
||||
memcpy(r, data, rLen);
|
||||
|
||||
*result = r;
|
||||
r = 0;
|
||||
*_retval = rLen;
|
||||
|
||||
loser:
|
||||
if (r) nsAllocator::Free(r);
|
||||
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * nsSecretDecoderRing::kPSMComponentProgID = PSM_COMPONENT_PROGID;
|
||||
58
mozilla/extensions/psm-glue/src/nsSDR.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* -*- 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):
|
||||
* Terry Hayes <thayes@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSSDR_H_
|
||||
#define _NSSDR_H_
|
||||
|
||||
#include "nsISecretDecoderRing.h"
|
||||
|
||||
// ===============================================
|
||||
// nsSecretDecoderRing - implementation of nsISecretDecoderRing
|
||||
// ===============================================
|
||||
|
||||
#define NS_SDR_CLASSNAME "Secret Decoder Ring"
|
||||
#define NS_SDR_CID \
|
||||
{ 0xd9a0341, 0xce7, 0x11d4, { 0x9f, 0xdd, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
#define NS_SDR_PROGID "netscape.security.sdr"
|
||||
|
||||
class nsSecretDecoderRing : public nsISecretDecoderRing
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISECRETDECODERRING
|
||||
|
||||
nsSecretDecoderRing();
|
||||
virtual ~nsSecretDecoderRing();
|
||||
|
||||
nsresult init();
|
||||
|
||||
private:
|
||||
nsIPSMComponent *mPSM;
|
||||
|
||||
static const char *kPSMComponentProgID;
|
||||
|
||||
nsresult encode(const unsigned char *data, PRInt32 dataLen, char **_retval);
|
||||
nsresult decode(const char *data, unsigned char **result, PRInt32 * _retval);
|
||||
};
|
||||
|
||||
#endif /* _NSSDR_H_ */
|
||||
432
mozilla/extensions/psm-glue/src/nsSSLIOLayer.cpp
Normal file
@@ -0,0 +1,432 @@
|
||||
/* -*- 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 "nsString.h"
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#include "nsIPSMComponent.h"
|
||||
#include "nsIPSMSocketInfo.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
#include "nsSSLIOLayer.h"
|
||||
|
||||
static PRDescIdentity nsSSLIOLayerIdentity;
|
||||
static PRIOMethods nsSSLIOLayerMethods;
|
||||
static nsIPSMComponent* gPSMService = nsnull;
|
||||
|
||||
|
||||
|
||||
class nsPSMSocketInfo : public nsIPSMSocketInfo
|
||||
{
|
||||
public:
|
||||
nsPSMSocketInfo();
|
||||
~nsPSMSocketInfo();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPSMSOCKETINFO
|
||||
|
||||
// internal functions to psm-glue.
|
||||
nsresult SetSocketPtr(CMSocket *socketPtr);
|
||||
nsresult SetControlPtr(CMT_CONTROL *aControlPtr);
|
||||
nsresult SetFileDescPtr(PRFileDesc *aControlPtr);
|
||||
nsresult SetHostName(char *aHostName);
|
||||
|
||||
protected:
|
||||
CMT_CONTROL* mControl;
|
||||
CMSocket* mSocket;
|
||||
PRFileDesc* mFd;
|
||||
nsString mHostName;
|
||||
};
|
||||
|
||||
|
||||
static PRStatus PR_CALLBACK
|
||||
nsSSLIOLayerConnect(PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
|
||||
{
|
||||
nsresult result;
|
||||
PRStatus rv = PR_SUCCESS;
|
||||
CMTStatus status = CMTFailure;
|
||||
char* hostName;
|
||||
|
||||
/* Set the error in case of failure. */
|
||||
|
||||
PR_SetError(PR_UNKNOWN_ERROR, status);
|
||||
|
||||
if (!fd || !addr || !fd->secret)
|
||||
return PR_FAILURE;
|
||||
|
||||
if (gPSMService == nsnull)
|
||||
{
|
||||
result = nsServiceManager::GetService( PSM_COMPONENT_PROGID,
|
||||
NS_GET_IID(nsIPSMComponent),
|
||||
(nsISupports**)&gPSMService); //FIX leak one per app run
|
||||
if (NS_FAILED(result))
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
// Make the socket non-blocking...
|
||||
PRSocketOptionData opt;
|
||||
opt.option = PR_SockOpt_Nonblocking;
|
||||
opt.value.non_blocking = PR_FALSE;
|
||||
rv = PR_SetSocketOption(fd->lower, &opt);
|
||||
if (PR_SUCCESS != rv)
|
||||
return PR_FAILURE;
|
||||
|
||||
char ipBuffer[PR_NETDB_BUF_SIZE];
|
||||
rv = PR_NetAddrToString(addr, (char*)&ipBuffer, PR_NETDB_BUF_SIZE);
|
||||
if (rv != PR_SUCCESS)
|
||||
return PR_FAILURE;
|
||||
|
||||
if (addr->raw.family == PR_AF_INET6 && PR_IsNetAddrType(addr, PR_IpAddrV4Mapped))
|
||||
{
|
||||
/* Chop off the leading "::ffff:" */
|
||||
strcpy(ipBuffer, ipBuffer + 7);
|
||||
}
|
||||
|
||||
|
||||
CMSocket* cmsock = (CMSocket *)PR_Malloc(sizeof(CMSocket));
|
||||
if (!cmsock)
|
||||
return PR_FAILURE;
|
||||
|
||||
memset(cmsock, 0, sizeof(CMSocket));
|
||||
|
||||
CMT_CONTROL *control;
|
||||
result = gPSMService->GetControlConnection(&control);
|
||||
|
||||
if (result != PR_SUCCESS)
|
||||
{
|
||||
PR_FREEIF(cmsock)
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
cmsock->fd = fd->lower;
|
||||
cmsock->isUnix = PR_FALSE;
|
||||
|
||||
nsPSMSocketInfo *infoObject = (nsPSMSocketInfo *)fd->secret;
|
||||
|
||||
infoObject->GetHostName(&hostName);
|
||||
infoObject->SetControlPtr(control);
|
||||
infoObject->SetSocketPtr(cmsock);
|
||||
|
||||
status = CMT_OpenSSLConnection(control,
|
||||
cmsock,
|
||||
SSM_REQUEST_SSL_DATA_SSL,
|
||||
PR_ntohs(addr->inet.port),
|
||||
ipBuffer,
|
||||
(hostName ? hostName : ipBuffer),
|
||||
CM_FALSE,
|
||||
nsnull);
|
||||
if (CMTSuccess == status)
|
||||
{
|
||||
// since our stuff can block, what we want to do is return PR_FAILURE,
|
||||
// but set the nspr ERROR to BLOCK. This will put us into a select
|
||||
// q.
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, status);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
/* CMT_DestroyDataConnection(ctrl, sock); */
|
||||
/* need to strip our layer, pass result to DestroyDataConnection */
|
||||
/* which will clean up the CMT accounting of sock, then call our */
|
||||
/* shim layer to translate back to NSPR */
|
||||
|
||||
static PRStatus PR_CALLBACK
|
||||
nsSSLIOLayerClose(PRFileDesc *fd)
|
||||
{
|
||||
nsPSMSocketInfo *infoObject = (nsPSMSocketInfo *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (infoObject && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
CMT_CONTROL* control;
|
||||
CMSocket* socket;
|
||||
|
||||
infoObject->GetControlPtr(&control);
|
||||
infoObject->GetSocketPtr(&socket);
|
||||
|
||||
if (((PRStatus) CMT_GetSSLDataErrorCode(control, socket, &errorCode)) == PR_SUCCESS)
|
||||
{
|
||||
CMT_DestroyDataConnection(control, socket);
|
||||
NS_RELEASE(infoObject);
|
||||
fd->identity = PR_INVALID_IO_LAYER;
|
||||
}
|
||||
return (PRStatus)errorCode;
|
||||
}
|
||||
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
static PRInt32 PR_CALLBACK
|
||||
nsSSLIOLayerRead( PRFileDesc *fd, void *buf, PRInt32 amount)
|
||||
{
|
||||
if (!fd)
|
||||
return PR_FAILURE;
|
||||
|
||||
PRInt32 result = PR_Recv(fd, buf, amount, 0, PR_INTERVAL_MIN);
|
||||
|
||||
if (result > 0)
|
||||
return result;
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
PRErrorCode code = PR_GetError();
|
||||
|
||||
if (code == PR_IO_TIMEOUT_ERROR )
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
nsPSMSocketInfo *infoObject = (nsPSMSocketInfo *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (infoObject && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
|
||||
CMT_CONTROL* control;
|
||||
CMSocket* socket;
|
||||
|
||||
infoObject->GetControlPtr(&control);
|
||||
infoObject->GetSocketPtr(&socket);
|
||||
|
||||
CMT_GetSSLDataErrorCode(control, socket, &errorCode);
|
||||
|
||||
if (errorCode == PR_IO_TIMEOUT_ERROR)
|
||||
{
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
PR_SetError(0, 0);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static PRInt32 PR_CALLBACK
|
||||
nsSSLIOLayerWrite( PRFileDesc *fd, const void *buf, PRInt32 amount)
|
||||
{
|
||||
if (!fd)
|
||||
return PR_FAILURE;
|
||||
|
||||
PRInt32 result = PR_Send(fd, buf, amount, 0, PR_INTERVAL_MIN);
|
||||
|
||||
if (result > 0)
|
||||
return result;
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
PRErrorCode code = PR_GetError();
|
||||
|
||||
if (code == PR_IO_TIMEOUT_ERROR )
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
nsPSMSocketInfo *infoObject = (nsPSMSocketInfo *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (infoObject && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
CMT_CONTROL* control;
|
||||
CMSocket* socket;
|
||||
|
||||
infoObject->GetControlPtr(&control);
|
||||
infoObject->GetSocketPtr(&socket);
|
||||
|
||||
CMT_GetSSLDataErrorCode(control, socket, &errorCode);
|
||||
PR_SetError(0, 0);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsPSMSocketInfo::nsPSMSocketInfo()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mControl = nsnull;
|
||||
mSocket = nsnull;
|
||||
}
|
||||
|
||||
nsPSMSocketInfo::~nsPSMSocketInfo()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsPSMSocketInfo, nsIPSMSocketInfo);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetControlPtr(CMT_CONTROL * *aControlPtr)
|
||||
{
|
||||
*aControlPtr = mControl;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetControlPtr(CMT_CONTROL *aControlPtr)
|
||||
{
|
||||
mControl = aControlPtr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetSocketPtr(CMSocket * *socketPtr)
|
||||
{
|
||||
*socketPtr = mSocket;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetSocketPtr(CMSocket *socketPtr)
|
||||
{
|
||||
mSocket = socketPtr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetFileDescPtr(PRFileDesc * *aFilePtr)
|
||||
{
|
||||
*aFilePtr = mFd;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetFileDescPtr(PRFileDesc *aFilePtr)
|
||||
{
|
||||
mFd = aFilePtr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetHostName(char * *aHostName)
|
||||
{
|
||||
*aHostName = mHostName.ToNewCString();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetHostName(char *aHostName)
|
||||
{
|
||||
mHostName.AssignWithConversion(aHostName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetPickledStatus(char * *pickledStatusString)
|
||||
{
|
||||
*pickledStatusString = nsnull;
|
||||
|
||||
if (mSocket && mControl)
|
||||
{
|
||||
long level;
|
||||
CMTItem pickledStatus = {0, nsnull, 0};
|
||||
unsigned char* ret = nsnull;
|
||||
|
||||
if (CMT_GetSSLSocketStatus(mControl, mSocket, &pickledStatus, &level) == PR_FAILURE)
|
||||
return nsnull;
|
||||
|
||||
ret = (unsigned char*) PR_Malloc( (SSMSTRING_PADDED_LENGTH(pickledStatus.len) + sizeof(int)) );
|
||||
if (!ret)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*(int*)ret = pickledStatus.len;
|
||||
memcpy(ret+sizeof(int), pickledStatus.data, *(int*)ret);
|
||||
|
||||
PR_FREEIF(pickledStatus.data);
|
||||
|
||||
*pickledStatusString = (char*) ret;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSSLIOLayerNewSocket(const char* hostName, PRFileDesc **fd, nsISupports** info)
|
||||
{
|
||||
static PRBool firstTime = PR_TRUE;
|
||||
if (firstTime)
|
||||
{
|
||||
nsSSLIOLayerIdentity = PR_GetUniqueIdentity("Cartman layer");
|
||||
nsSSLIOLayerMethods = *PR_GetDefaultIOMethods();
|
||||
|
||||
nsSSLIOLayerMethods.connect = nsSSLIOLayerConnect;
|
||||
nsSSLIOLayerMethods.close = nsSSLIOLayerClose;
|
||||
nsSSLIOLayerMethods.read = nsSSLIOLayerRead;
|
||||
nsSSLIOLayerMethods.write = nsSSLIOLayerWrite;
|
||||
firstTime = PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
PRFileDesc * sock;
|
||||
PRFileDesc * layer;
|
||||
PRStatus rv;
|
||||
|
||||
/* Get a normal NSPR socket */
|
||||
sock = PR_NewTCPSocket();
|
||||
if (! sock) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
layer = PR_CreateIOLayerStub(nsSSLIOLayerIdentity, &nsSSLIOLayerMethods);
|
||||
if (! layer)
|
||||
{
|
||||
PR_Close(sock);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsPSMSocketInfo *infoObject = new nsPSMSocketInfo();
|
||||
if (!infoObject)
|
||||
{
|
||||
PR_Close(sock);
|
||||
// clean up IOLayerStub.
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_ADDREF(infoObject);
|
||||
infoObject->SetHostName((char*)hostName);
|
||||
layer->secret = (PRFilePrivate*) infoObject;
|
||||
rv = PR_PushIOLayer(sock, PR_GetLayersIdentity(sock), layer);
|
||||
|
||||
if (rv == PR_SUCCESS)
|
||||
{
|
||||
*fd = sock;
|
||||
*info = infoObject;
|
||||
NS_ADDREF(*info);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PR_Close(sock);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
37
mozilla/extensions/psm-glue/src/nsSSLIOLayer.h
Normal file
@@ -0,0 +1,37 @@
|
||||
/* -*- 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 _NSSSLIOLAYER_H
|
||||
#define _NSSSLIOLAYER_H
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prio.h"
|
||||
#include "nsIPSMSocketInfo.h"
|
||||
|
||||
// define taken from 4.x cartman glue code.
|
||||
#define SSMSTRING_PADDED_LENGTH(x) ((((x)+3)/4)*4)
|
||||
|
||||
nsresult nsSSLIOLayerNewSocket(const char* hostName, PRFileDesc **fd, nsISupports **securityInfo);
|
||||
|
||||
|
||||
|
||||
#endif /* _NSSSLIOLAYER_H */
|
||||
83
mozilla/extensions/psm-glue/src/nsSSLSocketProvider.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
/* -*- 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 "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsSSLSocketProvider.h"
|
||||
#include "nsSSLIOLayer.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsSSLSocketProvider::nsSSLSocketProvider()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSSLSocketProvider::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsSSLSocketProvider::~nsSSLSocketProvider()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsSSLSocketProvider, nsISocketProvider, nsISSLSocketProvider);
|
||||
|
||||
NS_METHOD
|
||||
nsSSLSocketProvider::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsSSLSocketProvider * inst;
|
||||
|
||||
if (NULL == aResult) {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
return rv;
|
||||
}
|
||||
*aResult = NULL;
|
||||
if (NULL != aOuter) {
|
||||
rv = NS_ERROR_NO_AGGREGATION;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_NEWXPCOM(inst, nsSSLSocketProvider);
|
||||
if (NULL == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
return rv;
|
||||
}
|
||||
NS_ADDREF(inst);
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSSLSocketProvider::NewSocket(const char *hostName, PRFileDesc **_result, nsISupports **securityInfo)
|
||||
{
|
||||
nsresult rv = nsSSLIOLayerNewSocket(hostName, _result, securityInfo);
|
||||
return (NS_FAILED(rv)) ? NS_ERROR_SOCKET_CREATE_FAILED : NS_OK;
|
||||
}
|
||||
54
mozilla/extensions/psm-glue/src/nsSSLSocketProvider.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- 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 _NSSSLSOCKETPROVIDER_H_
|
||||
#define _NSSSLSOCKETPROVIDER_H_
|
||||
|
||||
#include "nsISSLSocketProvider.h"
|
||||
|
||||
|
||||
/* 274418d0-5437-11d3-bbc8-0000861d1237 */
|
||||
#define NS_SSLSOCKETPROVIDER_CID { 0x274418d0, 0x5437, 0x11d3, {0xbb, 0xc8, 0x00, 0x00, 0x86, 0x1d, 0x12, 0x37}}
|
||||
|
||||
|
||||
class nsSSLSocketProvider : public nsISSLSocketProvider
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSISOCKETPROVIDER
|
||||
|
||||
NS_DECL_NSISSLSOCKETPROVIDER
|
||||
|
||||
// nsSSLSocketProvider methods:
|
||||
nsSSLSocketProvider();
|
||||
virtual ~nsSSLSocketProvider();
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif /* _NSSSLSOCKETPROVIDER_H_ */
|
||||
619
mozilla/extensions/psm-glue/src/nsSecureBrowserUIImpl.cpp
Normal file
@@ -0,0 +1,619 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsSecureBrowserUIImpl.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
#include "nsPSMComponent.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 "nsIWebProgress.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIPSMSocketInfo.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsICommonDialogs.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
#include "nsIFormSubmitObserver.h"
|
||||
|
||||
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
static NS_DEFINE_CID(kCommonDialogsCID, NS_CommonDialog_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"
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
//
|
||||
// Log module for nsSecureBroswerUI logging...
|
||||
//
|
||||
// To enable logging (see prlog.h for full details):
|
||||
//
|
||||
// set NSPR_LOG_MODULES=nsSecureBroswerUI:5
|
||||
// set NSPR_LOG_FILE=nspr.log
|
||||
//
|
||||
// this enables PR_LOG_DEBUG level information and places all output in
|
||||
// the file nspr.log
|
||||
//
|
||||
PRLogModuleInfo* gSecureDocLog = nsnull;
|
||||
#endif /* PR_LOGGING */
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsSecureBrowserUIImpl * inst;
|
||||
|
||||
if (NULL == aResult) {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
return rv;
|
||||
}
|
||||
*aResult = NULL;
|
||||
if (NULL != aOuter) {
|
||||
rv = NS_ERROR_NO_AGGREGATION;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_NEWXPCOM(inst, nsSecureBrowserUIImpl);
|
||||
if (NULL == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
return rv;
|
||||
}
|
||||
NS_ADDREF(inst);
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsSecureBrowserUIImpl::nsSecureBrowserUIImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
if (nsnull == gSecureDocLog) {
|
||||
gSecureDocLog = PR_NewLogModule("nsSecureBroswerUI");
|
||||
}
|
||||
#endif /* PR_LOGGING */
|
||||
|
||||
|
||||
mIsSecureDocument = mMixContentAlertShown = mIsDocumentBroken = PR_FALSE;
|
||||
mLastPSMStatus = nsnull;
|
||||
mCurrentURI = nsnull;
|
||||
mSecurityButton = nsnull;
|
||||
}
|
||||
|
||||
nsSecureBrowserUIImpl::~nsSecureBrowserUIImpl()
|
||||
{
|
||||
PR_FREEIF(mLastPSMStatus);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS4(nsSecureBrowserUIImpl,
|
||||
nsSecureBrowserUI,
|
||||
nsIWebProgressListener,
|
||||
nsIFormSubmitObserver,
|
||||
nsIObserver);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Init(nsIDOMWindow *window, nsIDOMElement *button)
|
||||
{
|
||||
mSecurityButton = button;
|
||||
mWindow = window;
|
||||
|
||||
nsresult rv = nsServiceManager::GetService( kPrefCID,
|
||||
NS_GET_IID(nsIPref),
|
||||
getter_AddRefs(mPref));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIStringBundleService, service, kCStringBundleServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsILocale* locale = nsnull;
|
||||
rv = service->CreateBundle(SECURITY_STRING_BUNDLE_URL, locale, getter_AddRefs(mStringBundle));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// hook up to the form post notifications:
|
||||
nsIObserverService *svc = 0;
|
||||
rv = nsServiceManager::GetService(NS_OBSERVERSERVICE_PROGID,
|
||||
NS_GET_IID(nsIObserverService),
|
||||
(nsISupports**)&svc );
|
||||
if ( NS_SUCCEEDED( rv ) && svc )
|
||||
{
|
||||
nsString topic; topic.AssignWithConversion(NS_FORMSUBMIT_SUBJECT);
|
||||
rv = svc->AddObserver( this, topic.GetUnicode());
|
||||
nsServiceManager::ReleaseService( NS_OBSERVERSERVICE_PROGID, svc );
|
||||
}
|
||||
|
||||
// hook up to the webprogress notifications.
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
|
||||
if (!sgo) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
if (!docShell) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIWebProgress> wp = do_QueryInterface(docShell);
|
||||
if (!wp) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
wp->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*,this));
|
||||
|
||||
// Set up stuff the first time the window loads:
|
||||
docShell->GetCurrentURI(getter_AddRefs(mCurrentURI));
|
||||
|
||||
return IsURLHTTPS(mCurrentURI, &mIsSecureDocument);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::DisplayPageInfoUI()
|
||||
{
|
||||
nsresult res;
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
nsXPIDLCString temp;
|
||||
mCurrentURI->GetHost(getter_Copies(temp));
|
||||
return psm->DisplaySecurityAdvisor(mLastPSMStatus, temp);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Observe(nsISupports*, const PRUnichar*, const PRUnichar*)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Notify(nsIContent* formNode, nsIDOMWindow* window, nsIURI* actionURL)
|
||||
{
|
||||
// Return NS_OK unless we want to prevent this form from submitting.
|
||||
if (!window || (mWindow.get() != window) || !actionURL) {
|
||||
return NS_OK;
|
||||
}
|
||||
PRBool okayToPost;
|
||||
nsresult res = CheckPost(actionURL, &okayToPost);
|
||||
|
||||
// Return NS_OK unless we want to prevent this form from submitting.
|
||||
if (NS_SUCCEEDED(res) && okayToPost)
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// nsIWebProgressListener
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::OnProgressChange(nsIChannel* aChannel,
|
||||
PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress,
|
||||
PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::OnChildProgressChange(nsIChannel* aChannel,
|
||||
PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::OnStatusChange(nsIChannel* aChannel,
|
||||
PRInt32 aProgressStatusFlags)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
if (aChannel == nsnull || !mSecurityButton || !mPref)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIURI> loadingURI;
|
||||
aChannel->GetURI(getter_AddRefs(loadingURI));
|
||||
|
||||
#if defined(DEBUG)
|
||||
nsXPIDLCString temp;
|
||||
loadingURI->GetSpec(getter_Copies(temp));
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: OnStatusChange: %x :%s\n", this, aProgressStatusFlags,(const char*)temp));
|
||||
#endif
|
||||
|
||||
if (aProgressStatusFlags & nsIWebProgress::flag_net_start)
|
||||
{
|
||||
// starting to load a webpage
|
||||
PR_FREEIF(mLastPSMStatus); mLastPSMStatus = nsnull;
|
||||
|
||||
mIsSecureDocument = mMixContentAlertShown = mIsDocumentBroken = PR_FALSE;
|
||||
|
||||
res = CheckProtocolContextSwitch( loadingURI, mCurrentURI);
|
||||
|
||||
}
|
||||
else if ((aProgressStatusFlags & nsIWebProgress::flag_net_stop) && mIsSecureDocument)
|
||||
{
|
||||
if (!mIsDocumentBroken) // and status is okay FIX
|
||||
{
|
||||
// qi for the psm information about this channel load.
|
||||
nsCOMPtr<nsISupports> info;
|
||||
aChannel->GetSecurityInfo(getter_AddRefs(info));
|
||||
nsCOMPtr<nsIPSMSocketInfo> psmInfo = do_QueryInterface(info);
|
||||
if ( psmInfo )
|
||||
{
|
||||
// Everything looks okay. Lets stash the picked status.
|
||||
PR_FREEIF(mLastPSMStatus);
|
||||
res = psmInfo->GetPickledStatus(&mLastPSMStatus);
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: Icon set to lock\n", this));
|
||||
res = mSecurityButton->SetAttribute( NS_ConvertASCIItoUCS2("level"), NS_ConvertASCIItoUCS2("high") );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: Icon set to broken\n", this));
|
||||
mIsDocumentBroken = PR_TRUE;
|
||||
res = mSecurityButton->SetAttribute( NS_ConvertASCIItoUCS2("level"), NS_ConvertASCIItoUCS2("broken") );
|
||||
}
|
||||
}
|
||||
else // if (aProgressStatusFlags == nsIWebProgress::flag_net_redirecting)
|
||||
{
|
||||
res = NS_ERROR_NOT_IMPLEMENTED;
|
||||
// xxx need to fix.
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::OnChildStatusChange(nsIChannel* aChannel, PRInt32 aProgressStatusFlags)
|
||||
{
|
||||
nsresult rv;
|
||||
if (aChannel == nsnull || !mSecurityButton || !mPref)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = aChannel->GetURI(getter_AddRefs(uri));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#if defined(DEBUG)
|
||||
nsXPIDLCString temp;
|
||||
uri->GetSpec(getter_Copies(temp));
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: OnChildStatusChange: %x :%s\n", this, aProgressStatusFlags,(const char*)temp));
|
||||
#endif
|
||||
|
||||
// don't need to do anything more if the page is broken or not secure...
|
||||
|
||||
if (!mIsSecureDocument || mIsDocumentBroken)
|
||||
return NS_OK;
|
||||
|
||||
if (aProgressStatusFlags & nsIWebProgress::flag_net_start)
|
||||
{ // check to see if we are going to mix content.
|
||||
return CheckMixedContext(uri);
|
||||
}
|
||||
|
||||
if (aProgressStatusFlags & nsIWebProgress::flag_net_stop)
|
||||
{
|
||||
if (1) // FIX status from the flag...
|
||||
{
|
||||
nsCOMPtr<nsISupports> info;
|
||||
aChannel->GetSecurityInfo(getter_AddRefs(info));
|
||||
nsCOMPtr<nsIPSMSocketInfo> psmInfo = do_QueryInterface(info, &rv);
|
||||
|
||||
// qi for the psm information about this channel load.
|
||||
if ( psmInfo )
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: OnChildStatusChange - Icon set to broken\n", this));
|
||||
mSecurityButton->SetAttribute( NS_ConvertASCIItoUCS2("level"), NS_ConvertASCIItoUCS2("broken") );
|
||||
mIsDocumentBroken = PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::OnLocationChange(nsIURI* aLocation)
|
||||
{
|
||||
mCurrentURI = aLocation;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserUIImpl::IsURLHTTPS(nsIURI* aURL, PRBool* value)
|
||||
{
|
||||
*value = PR_FALSE;
|
||||
|
||||
if (!aURL)
|
||||
return NS_OK;
|
||||
|
||||
char* scheme;
|
||||
aURL->GetScheme(&scheme);
|
||||
|
||||
if (scheme == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if ( PL_strncasecmp(scheme, "https", 5) == 0 )
|
||||
*value = PR_TRUE;
|
||||
|
||||
nsAllocator::Free(scheme);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void nsSecureBrowserUIImpl::GetBundleString(const nsString& name, nsString &outString)
|
||||
{
|
||||
if (mStringBundle && name.Length() > 0)
|
||||
{
|
||||
PRUnichar *ptrv = nsnull;
|
||||
if (NS_SUCCEEDED(mStringBundle->GetStringFromName(name.GetUnicode(), &ptrv)))
|
||||
outString = ptrv;
|
||||
else
|
||||
outString.SetLength(0);;
|
||||
|
||||
nsAllocator::Free(ptrv);
|
||||
}
|
||||
else
|
||||
{
|
||||
outString.SetLength(0);;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserUIImpl::CheckProtocolContextSwitch( nsIURI* newURI, nsIURI* oldURI)
|
||||
{
|
||||
nsresult res;
|
||||
PRBool isNewSchemeSecure, isOldSchemeSecure, boolpref;
|
||||
|
||||
res = IsURLHTTPS(oldURI, &isOldSchemeSecure);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
res = IsURLHTTPS(newURI, &isNewSchemeSecure);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
// Check to see if we are going from a secure page to and insecure page
|
||||
if ( !isNewSchemeSecure && isOldSchemeSecure)
|
||||
{
|
||||
mSecurityButton->RemoveAttribute( NS_ConvertASCIItoUCS2("level") );
|
||||
|
||||
if ((mPref->GetBoolPref(LEAVE_SITE_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref)
|
||||
{
|
||||
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
nsAutoString windowTitle, message, dontShowAgain;
|
||||
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("Title"), windowTitle);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("LeaveSiteMessage"), message);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("DontShowAgain"), dontShowAgain);
|
||||
|
||||
PRBool outCheckValue = PR_TRUE;
|
||||
dialog->AlertCheck(mWindow,
|
||||
windowTitle.GetUnicode(),
|
||||
message.GetUnicode(),
|
||||
dontShowAgain.GetUnicode(),
|
||||
&outCheckValue);
|
||||
|
||||
if (!outCheckValue)
|
||||
{
|
||||
mPref->SetBoolPref(LEAVE_SITE_PREF, PR_FALSE);
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
psm->PassPrefs();
|
||||
}
|
||||
}
|
||||
}
|
||||
// check to see if we are going from an insecure page to a secure one.
|
||||
else if (isNewSchemeSecure && !isOldSchemeSecure)
|
||||
{
|
||||
|
||||
if ((mPref->GetBoolPref(ENTER_SITE_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref)
|
||||
{
|
||||
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
nsAutoString windowTitle, message, dontShowAgain;
|
||||
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("Title"), windowTitle);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("EnterSiteMessage"), message);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("DontShowAgain"), dontShowAgain);
|
||||
|
||||
PRBool outCheckValue = PR_TRUE;
|
||||
dialog->AlertCheck(mWindow,
|
||||
windowTitle.GetUnicode(),
|
||||
message.GetUnicode(),
|
||||
dontShowAgain.GetUnicode(),
|
||||
&outCheckValue);
|
||||
|
||||
if (!outCheckValue)
|
||||
{
|
||||
mPref->SetBoolPref(ENTER_SITE_PREF, PR_FALSE);
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
psm->PassPrefs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mIsSecureDocument = isNewSchemeSecure;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserUIImpl::CheckMixedContext(nsIURI* nextURI)
|
||||
{
|
||||
PRBool secure;
|
||||
|
||||
nsresult rv = IsURLHTTPS(nextURI, &secure);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!secure && mIsSecureDocument)
|
||||
{
|
||||
mIsDocumentBroken = PR_TRUE;
|
||||
mSecurityButton->SetAttribute( NS_ConvertASCIItoUCS2("level"), NS_ConvertASCIItoUCS2("broken") );
|
||||
|
||||
if (!mPref) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool boolpref;
|
||||
if ((mPref->GetBoolPref(MIXEDCONTENT_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref && !mMixContentAlertShown)
|
||||
{
|
||||
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsAutoString windowTitle, message, dontShowAgain;
|
||||
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("Title"), windowTitle);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("MixedContentMessage"), message);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("DontShowAgain"), dontShowAgain);
|
||||
|
||||
PRBool outCheckValue = PR_TRUE;
|
||||
|
||||
dialog->AlertCheck(mWindow,
|
||||
windowTitle.GetUnicode(),
|
||||
message.GetUnicode(),
|
||||
dontShowAgain.GetUnicode(),
|
||||
&outCheckValue);
|
||||
|
||||
if (!outCheckValue)
|
||||
{
|
||||
mPref->SetBoolPref(MIXEDCONTENT_PREF, PR_FALSE);
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
psm->PassPrefs();
|
||||
}
|
||||
|
||||
|
||||
mMixContentAlertShown = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserUIImpl::CheckPost(nsIURI *actionURL, PRBool *okayToPost)
|
||||
{
|
||||
PRBool secure;
|
||||
|
||||
nsresult rv = IsURLHTTPS(actionURL, &secure);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!secure && mIsSecureDocument)
|
||||
{
|
||||
PRBool boolpref;
|
||||
|
||||
// posting to a non https URL.
|
||||
if ((mPref->GetBoolPref(INSECURE_SUBMIT_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref)
|
||||
{
|
||||
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsAutoString windowTitle, message, dontShowAgain;
|
||||
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("Title"), windowTitle);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("PostToInsecure"), message);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("DontShowAgain"), dontShowAgain);
|
||||
|
||||
PRBool outCheckValue = PR_TRUE;
|
||||
dialog->ConfirmCheck(mWindow,
|
||||
windowTitle.GetUnicode(),
|
||||
message.GetUnicode(),
|
||||
dontShowAgain.GetUnicode(),
|
||||
&outCheckValue,
|
||||
okayToPost);
|
||||
|
||||
if (!outCheckValue)
|
||||
{
|
||||
mPref->SetBoolPref(INSECURE_SUBMIT_PREF, PR_FALSE);
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
psm->PassPrefs();
|
||||
}
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
99
mozilla/extensions/psm-glue/src/nsSecureBrowserUIImpl.h
Normal file
@@ -0,0 +1,99 @@
|
||||
/* -*- 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):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#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 "nsIDOMWindow.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsIFormSubmitObserver.h"
|
||||
#include "nsIURI.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 nsSecureBrowserUIImpl : public nsSecureBrowserUI,
|
||||
public nsIWebProgressListener,
|
||||
public nsIFormSubmitObserver,
|
||||
public nsIObserver
|
||||
{
|
||||
public:
|
||||
|
||||
nsSecureBrowserUIImpl();
|
||||
virtual ~nsSecureBrowserUIImpl();
|
||||
|
||||
static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSSECUREBROWSERUI
|
||||
|
||||
|
||||
// nsIObserver
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindow* window, nsIURI *actionURL);
|
||||
|
||||
protected:
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> mWindow;
|
||||
nsCOMPtr<nsIDOMElement> mSecurityButton;
|
||||
nsCOMPtr<nsIDocumentLoaderObserver> mOldWebShellObserver;
|
||||
nsCOMPtr<nsIPref> mPref;
|
||||
nsCOMPtr<nsIStringBundle> mStringBundle;
|
||||
|
||||
nsCOMPtr<nsIURI> mCurrentURI;
|
||||
|
||||
PRBool mIsSecureDocument; // is https loaded
|
||||
PRBool mIsDocumentBroken; //
|
||||
PRBool mMixContentAlertShown;
|
||||
|
||||
char* mLastPSMStatus;
|
||||
|
||||
|
||||
void GetBundleString(const nsString& name, nsString &outString);
|
||||
|
||||
nsresult CheckProtocolContextSwitch( nsIURI* newURI, nsIURI* oldURI);
|
||||
nsresult CheckMixedContext(nsIURI* nextURI);
|
||||
nsresult CheckPost(nsIURI *actionURL, PRBool *okayToPost);
|
||||
nsresult IsURLHTTPS(nsIURI* aURL, PRBool *value);
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsSecureBrowserUIImpl_h_ */
|
||||
@@ -1,222 +0,0 @@
|
||||
#! gmake
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express oqr
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is Rhino code, released
|
||||
# May 6, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
# Alternatively, the contents of this file may be used under the
|
||||
# terms of the GNU Public License (the "GPL"), in which case the
|
||||
# provisions of the GPL are applicable instead of those above.
|
||||
# If you wish to allow use of your version of this file only
|
||||
# under the terms of the GPL and not to allow others to use your
|
||||
# version of this file under the NPL, indicate your decision by
|
||||
# deleting the provisions above and replace them with the notice
|
||||
# and other provisions required by the GPL. If you do not delete
|
||||
# the provisions above, a recipient may use your version of this
|
||||
# file under either the NPL or the GPL.
|
||||
|
||||
#
|
||||
# Makefile for javascript in java.
|
||||
#
|
||||
|
||||
# This makefile is intended for packaging releases, and probably isn't
|
||||
# suitable for production use - it doesn't attempt to do understand
|
||||
# java dependencies beyond the package level.
|
||||
#
|
||||
# The makefiles for the subdirectories included in this package are
|
||||
# intended to be called by this makefile with the proper CLASSDIR,
|
||||
# PATH_PREFIX etc. variables. Makefiles in subdirectories are
|
||||
# actually executed in the toplevel directory, with the PATH_PREFIX
|
||||
# variable set to the subdirectory where the makefile is located.
|
||||
#
|
||||
# Initial version courtesy Mike Ang.
|
||||
# Next version by Mike McCabe
|
||||
|
||||
# Don't include SHELL define (per GNU manual recommendation) because it
|
||||
# breaks WinNT (with GNU make) builds.
|
||||
# SHELL = /bin/sh
|
||||
|
||||
# Some things we might want to tweek.
|
||||
|
||||
CLASSDIR = classes
|
||||
|
||||
PACKAGE_NAME = org.mozilla.javascript
|
||||
PACKAGE_PATH = org/mozilla/javascript
|
||||
|
||||
# jar filenames and the directories that build them.
|
||||
JS_JAR = js.jar
|
||||
JS_DIR = $(PACKAGE_PATH)
|
||||
JSTOOLS_JAR = jstools.jar
|
||||
JSTOOLS_DIR = $(PACKAGE_PATH)/tools
|
||||
|
||||
JARS = $(JS_JAR) $(JSTOOLS_JAR)
|
||||
|
||||
# It's not polite to store toplevel files in a tarball or zip files.
|
||||
# What is the name of the toplevel directory to store files in?
|
||||
# XXX we should probably add versioning to this.
|
||||
DIST_DIR = jsjava
|
||||
|
||||
# XXX test this with sj
|
||||
# JAVAC = mgcj
|
||||
JAVAC=javac
|
||||
|
||||
# We don't define JFLAGS but we do export it to child
|
||||
# builds in case it's defined by the environment.
|
||||
# To build optimized (with javac) say 'make JFLAGS=-O'
|
||||
|
||||
GZIP = gzip
|
||||
ZIP = zip
|
||||
UNZIP = unzip
|
||||
|
||||
# JFLAGS="-O -g:none"
|
||||
|
||||
# Shouldn't need to change anything below here.
|
||||
|
||||
# For Windows NT builds (under GNU make).
|
||||
ifeq ($(OS_TARGET), WINNT)
|
||||
CLASSPATHSEP = '\\;'
|
||||
else
|
||||
CLASSPATHSEP = :
|
||||
endif
|
||||
|
||||
# Make compatibility - use these instead of gmake 'export VARIABLE'
|
||||
EXPORTS = CLASSDIR=$(CLASSDIR) JAVAC=$(JAVAC) JFLAGS=$(JFLAGS) SHELL=$(SHELL) \
|
||||
PACKAGE_PATH=$(PACKAGE_PATH) PACKAGE_NAME=$(PACKAGE_NAME)
|
||||
|
||||
helpmessage : FORCE
|
||||
@echo 'Targets include:'
|
||||
@echo ' all - make jars, examples'
|
||||
@echo ' jars - make js.jar, jstools.jar'
|
||||
@echo ' fast - quick-and-dirty "make jars", for development'
|
||||
@echo ' examples - build the .class files in the examples directory'
|
||||
@echo ' check - perform checks on the source.'
|
||||
@echo ' clean - remove intermediate files'
|
||||
@echo ' clobber - make clean, and remove .jar files'
|
||||
@echo ' zip - make a distribution .zip file'
|
||||
@echo ' zip-source - make a distribution .zip file, with source'
|
||||
@echo ' tar - make a distribution .tar.gz file'
|
||||
@echo ' tar-source - make a distribution .tar.gz, with source'
|
||||
@echo
|
||||
@echo 'Define OS_TARGET to "WINNT" to build on Windows NT with GNU make.'
|
||||
@echo
|
||||
@echo 'The make-based build system does not include graphical'
|
||||
@echo 'debugger or Bean Scripting Framework support. To build with'
|
||||
@echo 'these, use the Ant build tool.'
|
||||
@echo
|
||||
@echo 'Ant is available at http://jakarta.apache.org/ant/'
|
||||
|
||||
all : jars examples
|
||||
|
||||
jars : $(JARS)
|
||||
|
||||
fast : fast_$(JS_JAR) $(JSTOOLS_JAR)
|
||||
|
||||
# Always call the sub-Makefile - which may decide that the jar is up to date.
|
||||
$(JS_JAR) : FORCE
|
||||
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(@) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JS_DIR) \
|
||||
CLASSPATH=.
|
||||
|
||||
fast_$(JS_JAR) :
|
||||
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(JS_JAR) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JS_DIR) \
|
||||
CLASSPATH=. \
|
||||
fast
|
||||
|
||||
$(JSTOOLS_JAR) : $(JS_JAR) FORCE
|
||||
$(MAKE) -f $(JSTOOLS_DIR)/Makefile JAR=$(@) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JSTOOLS_DIR) \
|
||||
CLASSPATH=./$(JS_JAR)$(CLASSPATHSEP).
|
||||
|
||||
examples : $(JS_JAR) FORCE
|
||||
$(MAKE) -f examples/Makefile $(EXPORTS) \
|
||||
PATH_PREFIX=examples \
|
||||
CLASSPATH=./$(JS_JAR)
|
||||
|
||||
# We ask the subdirs to update their MANIFESTs
|
||||
MANIFEST : FORCE
|
||||
$(MAKE) -f $(JS_DIR)/Makefile JAR=$(JS_JAR) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JS_DIR) $(JS_DIR)/MANIFEST
|
||||
$(MAKE) -f $(JSTOOLS_DIR)/Makefile JAR=$(JSTOOLS_JAR) $(EXPORTS) \
|
||||
PATH_PREFIX=$(JSTOOLS_DIR) $(JSTOOLS_DIR)/MANIFEST
|
||||
$(MAKE) -f examples/Makefile $(EXPORTS) \
|
||||
PATH_PREFIX=examples examples/MANIFEST
|
||||
# so ls below always has something to work on
|
||||
touch MANIFEST
|
||||
# examples/Makefile doesn't get included in the
|
||||
# MANIFEST file, (which is used to create the non-source distribution) so
|
||||
# we include it here.
|
||||
cat examples/MANIFEST $(JS_DIR)/MANIFEST \
|
||||
$(JSTOOLS_DIR)/MANIFEST \
|
||||
| xargs ls MANIFEST README.html \
|
||||
$(JARS) \
|
||||
Makefile examples/Makefile \
|
||||
> $(@)
|
||||
|
||||
# Make a MANIFEST file containing only the binaries and documentation.
|
||||
# This could be abstracted further...
|
||||
MANIFEST_binonly : MANIFEST
|
||||
cat examples/MANIFEST \
|
||||
| xargs ls $(JARS) README.html MANIFEST > MANIFEST
|
||||
|
||||
# A subroutine - not intended to be called from outside the makefile.
|
||||
do_zip :
|
||||
# Make sure we get a fresh one
|
||||
- rm -r $(DIST_DIR)
|
||||
- mkdir $(DIST_DIR)
|
||||
- rm $(DIST_DIR).zip
|
||||
cat MANIFEST | xargs $(ZIP) -0 -q $(DIST_DIR).zip
|
||||
mv $(DIST_DIR).zip $(DIST_DIR)
|
||||
cd $(DIST_DIR) ; \
|
||||
$(UNZIP) -q $(DIST_DIR).zip ; \
|
||||
rm $(DIST_DIR).zip
|
||||
$(ZIP) -r -9 -q $(DIST_DIR).zip $(DIST_DIR)
|
||||
- rm -r $(DIST_DIR)
|
||||
|
||||
zip : check jars examples MANIFEST_binonly do_zip
|
||||
|
||||
zip-source : check jars examples MANIFEST do_zip
|
||||
|
||||
# A subroutine - not intended to be called from outside the makefile.
|
||||
do_tar :
|
||||
- rm -r $(DIST_DIR)
|
||||
- mkdir $(DIST_DIR)
|
||||
- rm $(DIST_DIR).tar $(DIST_DIR).tar.gz
|
||||
cat MANIFEST | xargs tar cf $(DIST_DIR).tar
|
||||
mv $(DIST_DIR).tar $(DIST_DIR)
|
||||
cd $(DIST_DIR) ; \
|
||||
tar xf $(DIST_DIR).tar ; \
|
||||
rm $(DIST_DIR).tar
|
||||
tar cf $(DIST_DIR).tar $(DIST_DIR)
|
||||
- rm -r $(DIST_DIR)
|
||||
$(GZIP) -9 $(DIST_DIR).tar
|
||||
|
||||
tar: check jars examples MANIFEST_binonly do_tar
|
||||
|
||||
tar-source : check jars examples MANIFEST do_tar
|
||||
|
||||
# These commands just get passed to the respective sub-Makefiles.
|
||||
clean clobber check:
|
||||
$(MAKE) -f $(JS_DIR)/Makefile $(EXPORTS) JAR=$(JS_JAR) \
|
||||
PATH_PREFIX=$(JS_DIR) $(@)
|
||||
$(MAKE) -f $(JSTOOLS_DIR)/Makefile $(EXPORTS) JAR=$(JSTOOLS_JAR) \
|
||||
PATH_PREFIX=$(JSTOOLS_DIR) $(@)
|
||||
$(MAKE) -f examples/Makefile $(EXPORTS) PATH_PREFIX=examples $(@)
|
||||
|
||||
#emulate .PHONY
|
||||
FORCE :
|
||||
@@ -1,46 +0,0 @@
|
||||
<html>
|
||||
<!--
|
||||
- The contents of this file are subject to the Netscape 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/NPL/
|
||||
-
|
||||
- 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 Rhino code, released
|
||||
- May 6, 1999.
|
||||
-
|
||||
- The Initial Developer of the Original Code is Netscape
|
||||
- Communications Corporation. Portions created by Netscape are
|
||||
- Copyright (C) 1998-1999 Netscape Communications Corporation. All
|
||||
- Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
- Norris Boyd
|
||||
-
|
||||
- Alternatively, the contents of this file may be used under the
|
||||
- terms of the GNU Public License (the "GPL"), in which case the
|
||||
- provisions of the GPL are applicable instead of those above.
|
||||
- If you wish to allow use of your version of this file only
|
||||
- under the terms of the GPL and not to allow others to use your
|
||||
- version of this file under the NPL, indicate your decision by
|
||||
- deleting the provisions above and replace them with the notice
|
||||
- and other provisions required by the GPL. If you do not delete
|
||||
- the provisions above, a recipient may use your version of this
|
||||
- file under either the NPL or the GPL.
|
||||
-->
|
||||
<body>
|
||||
<h1>
|
||||
<span CLASS=LXRSHORTDESC>
|
||||
Rhino: JavaScript in Java<p>
|
||||
</span>
|
||||
</h1>
|
||||
<span CLASS=LXRLONGDESC>
|
||||
Rhino is an implementation of JavaScript in Java. Documentation can be found
|
||||
<a href="http://www.mozilla.org/js/rhino/rhino.html">here</a>.
|
||||
</span>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,22 +0,0 @@
|
||||
apiClasses=\
|
||||
src/org/mozilla/javascript/ClassDefinitionException.java,\
|
||||
src/org/mozilla/javascript/ClassOutput.java,\
|
||||
src/org/mozilla/javascript/Context.java,\
|
||||
src/org/mozilla/javascript/ContextListener.java,\
|
||||
src/org/mozilla/javascript/EcmaError.java,\
|
||||
src/org/mozilla/javascript/ErrorReporter.java,\
|
||||
src/org/mozilla/javascript/Function.java,\
|
||||
src/org/mozilla/javascript/FunctionObject.java,\
|
||||
src/org/mozilla/javascript/ImporterTopLevel.java,\
|
||||
src/org/mozilla/javascript/JavaScriptException.java,\
|
||||
src/org/mozilla/javascript/NotAFunctionException.java,\
|
||||
src/org/mozilla/javascript/PropertyException.java,\
|
||||
src/org/mozilla/javascript/Script.java,\
|
||||
src/org/mozilla/javascript/Scriptable.java,\
|
||||
src/org/mozilla/javascript/ScriptableObject.java,\
|
||||
src/org/mozilla/javascript/SecuritySupport.java,\
|
||||
src/org/mozilla/javascript/WrapHandler.java,\
|
||||
src/org/mozilla/javascript/Wrapper.java,\
|
||||
src/org/mozilla/javascript/Synchronizer.java,\
|
||||
src/org/mozilla/javascript/serialize/ScriptableInputStream.java,\
|
||||
src/org/mozilla/javascript/serialize/ScriptableOutputStream.java
|
||||
@@ -1 +0,0 @@
|
||||
This version was built on @datestamp@.
|
||||
@@ -1,131 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
Build file for Rhino using Ant (see http://jakarta.apache.org/ant/index.html)
|
||||
Requires Ant version 1.2 or later
|
||||
-->
|
||||
<project name="Rhino" default="default" basedir=".">
|
||||
|
||||
<target name="properties">
|
||||
<property name="name" value="rhino"/>
|
||||
<property name="Name" value="Rhino"/>
|
||||
<property name="version" value="1_5R4pre"/>
|
||||
<property name="rhino.jar" value="js.jar"/>
|
||||
|
||||
<property name="debug" value="off"/>
|
||||
|
||||
<property name="src.dir" value="src"/>
|
||||
<property name="toolsrc.dir" value="toolsrc"/>
|
||||
<property name="src.examples" value="examples"/>
|
||||
|
||||
<property name="build.dir" value="./build"/>
|
||||
<property name="build.dest" value="${build.dir}/classes"/>
|
||||
|
||||
<property name="dist.name" value="rhino${version}"/>
|
||||
<property name="dist.dir" value="${build.dir}/${dist.name}"/>
|
||||
<property name="dist.src" value="${dist.dir}/src"/>
|
||||
<property name="dist.toolsrc" value="${dist.dir}/toolsrc"/>
|
||||
<property name="dist.examples" value="${dist.dir}/examples"/>
|
||||
<property name="dist.docs" value="${dist.dir}/docs"/>
|
||||
<property name="dist.apidocs" value="${dist.docs}/apidocs"/>
|
||||
<property name="dist.file" value="rhino${version}.zip"/>
|
||||
|
||||
<property file="apiClasses.properties"/>
|
||||
<property name="docsrc.dir" value="docs"/>
|
||||
<property name="dist.docsrc.dir" value="${src.dir}/docs"/>
|
||||
</target>
|
||||
|
||||
<target name="init" depends="properties">
|
||||
</target>
|
||||
|
||||
<target name="prepare" depends="init">
|
||||
<mkdir dir="${build.dir}"/>
|
||||
<mkdir dir="${build.dest}"/>
|
||||
<mkdir dir="${dist.dir}"/>
|
||||
<mkdir dir="${dist.src}"/>
|
||||
<mkdir dir="${dist.toolsrc}"/>
|
||||
<mkdir dir="${dist.examples}"/>
|
||||
<mkdir dir="${dist.docs}"/>
|
||||
<mkdir dir="${dist.apidocs}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile-src" depends="prepare">
|
||||
<ant dir="${src.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile-toolsrc" depends="prepare">
|
||||
<ant dir="${toolsrc.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="compile-src,compile-toolsrc"/>
|
||||
|
||||
<target name="jar" depends="compile">
|
||||
<jar jarfile="${dist.dir}/${rhino.jar}"
|
||||
basedir="${build.dest}"
|
||||
manifest="${src.dir}/manifest" />
|
||||
</target>
|
||||
|
||||
<target name="jar-src" depends="compile-src">
|
||||
<jar jarfile="${dist.dir}/${rhino.jar}"
|
||||
basedir="${build.dest}"
|
||||
manifest="${src.dir}/manifest" />
|
||||
</target>
|
||||
|
||||
<target name="copy-examples" depends="prepare">
|
||||
<copy todir="${dist.examples}">
|
||||
<fileset dir="${src.examples}" includes="*.java,*.js,*.html" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="copy-misc" depends="prepare">
|
||||
<tstamp/>
|
||||
<filter token="datestamp" value="${TODAY}"/>
|
||||
<copy todir="${dist.dir}" filtering="yes">
|
||||
<fileset dir=".">
|
||||
<patternset>
|
||||
<include name="build.xml"/>
|
||||
<include name="apiClasses.properties"/>
|
||||
<include name="build-date"/>
|
||||
</patternset>
|
||||
</fileset>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="copy-all" depends="copy-examples,copy-misc">
|
||||
</target>
|
||||
|
||||
<target name="copy-docs" depends="prepare">
|
||||
<echo message="copy from ${docsrc.dir}"/>
|
||||
<copy todir="${dist.docs}">
|
||||
<fileset dir="${docsrc.dir}"
|
||||
includes="**/*.html,**/*.jpg,**/*.gif" />
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="javadoc" depends="compile,copy-docs">
|
||||
<javadoc sourcefiles="${apiClasses}"
|
||||
sourcepath="${src.dir}"
|
||||
destdir="${dist.apidocs}"
|
||||
overview="${dist.docs}/api.html"
|
||||
version="true"
|
||||
author="true"
|
||||
public="true"
|
||||
windowtitle="${Name}" />
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="copy-all,javadoc,jar">
|
||||
<delete file="${dist.file}" />
|
||||
<zip zipfile="${dist.file}"
|
||||
basedir="${build.dir}"
|
||||
includes="**"
|
||||
excludes="classes/**" />
|
||||
</target>
|
||||
|
||||
<target name="default">
|
||||
<echo>
|
||||
**** Building core only; for full distribution build, try "ant dist".
|
||||
</echo>
|
||||
<antcall target="jar-src"/>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
@@ -1,161 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
|
||||
<META NAME="Generator" CONTENT="Microsoft Word 97">
|
||||
<TITLE>1</TITLE>
|
||||
</HEAD>
|
||||
<BODY>
|
||||
|
||||
<OL>
|
||||
|
||||
<B><FONT FACE="Arial" SIZE=5 COLOR="#000080"><LI>Using the Rhino JavaScript Debugger</LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The Mozilla Rhino JavaScript engine includes a source-level debugger for debugging JavaScript scripts. The debugger is itself a Java program which you may run as</P>
|
||||
</FONT><FONT FACE="Arial" SIZE=2><P ALIGN="JUSTIFY">java org.mozilla.javascript.tools.debugger.JSDebugger [options] [filename.js] [script-arguments]</P>
|
||||
</FONT><FONT SIZE=2><P ALIGN="JUSTIFY">where the options are the same as the shell.</P>
|
||||
<OL>
|
||||
|
||||
<LI><A NAME="_Toc502165108"></FONT><B><FONT FACE="Arial" SIZE=4 COLOR="#000080">Features</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The Rhino JavaScript Debugger can debug scripts running in multiple threads and provides facilities to set and clear breakpoints, control execution, view variables, and evaluate arbitrary JavaScript code in the current scope of an executing script.</P>
|
||||
<OL>
|
||||
|
||||
<LI><A NAME="_Toc502165109"></FONT><B><FONT FACE="Arial" COLOR="#000080">Console Window</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The debugger redirects the </FONT><FONT FACE="Arial" SIZE=2>System.out</FONT><FONT SIZE=2>, </FONT><FONT FACE="Arial" SIZE=2>System.in</FONT><FONT SIZE=2>, and </FONT><FONT FACE="Arial" SIZE=2>System.err</FONT><FONT SIZE=2> streams to an internal JavaScript console window which provides an editable command line for you to enter JavaScript code and view system output. The console window maintains a history of the commands you have entered. You may move backward and forward through the history list by pressing the Up/Down arrow keys on the keyboard.</P>
|
||||
<LI><A NAME="_Toc502165110"></FONT><B><FONT FACE="Arial" COLOR="#000080">Opening Scripts</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">You may select the <B><I>File->Open</B></I> menu item on the menu bar to load JavaScript scripts contained in files. This action will display a file-selection dialog box prompting you for the location of a script to load. The selected file will be compiled and displayed in a new window.</P>
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Running Scripts</LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">You may select the <B><I>File->Run</B></I> menu item on the menu bar to execute JavaScript scripts contained in files. This action will display a file-selection dialog box prompting you for the location of a script to execute. The loaded script will be run in a new thread and control will be given to the debugger on its first instruction.</P>
|
||||
<LI><A NAME="_Toc502165111"></FONT><B><FONT FACE="Arial" COLOR="#000080">Controlling Execution</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The debugger provides the following facilities for you to control the execution of scripts you are debugging:</P>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Step Into</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To single step entering any function calls, you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Step Into </B></I>menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Step Into</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the F11 key on the keyboard</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">Execution will resume. If the current line in the script contains a function call control will return to the debugger upon entry into the function. Otherwise control will return to the debugger at the next line in the current function.</P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Step Over</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To single step to the next line in the current function, you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Step Over</B></I> menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Step Over</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the F7 key on the keyboard</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">Execution will resume but control will return to the debugger at the next line in the current function or top-level script.</P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Step Out</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To continue execution until the current function returns you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Step Out</B></I> menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Step Out</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the F8 key on the keyboard</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">Execution will resume until the current function returns or a breakpoint is hit.</P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Go</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To resume execution of a script you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Go</B></I> menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Go</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the F5 key on the keyboard</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">Execution will resume until a breakpoint is hit or the script completes.</P>
|
||||
<P ALIGN="JUSTIFY"> </P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>Break</LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">To stop all running scripts and give control to the debugger you may do any of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Select the <B><I>Debug->Break</B></I> menu item on the menu bar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the <B><I>Break</B></I> button on the toolbar</LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Press the Pause/Break key on the keyboard</LI></P></UL>
|
||||
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
<LI><A NAME="_Toc502165112"></FONT><B><FONT FACE="Arial" COLOR="#000080">Moving Up and Down the Stack</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The lower-left (dockable) pane in the debugger main window contains a combo-box labeled "Context:" which displays the current stack of the executing script. You may move up and down the stack by selecting an entry in the combo-box. When you select a stack frame the variables and watch windows are updated to reflect the names and values of the variables visible at that scope.</P>
|
||||
<LI><A NAME="_Toc502165113"></FONT><B><FONT FACE="Arial" COLOR="#000080">Setting and Clearing Breakpoints</A></LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The main desktop of the debugger contains file windows which display the contents of each script you are debugging. You may set a breakpoint in a script by doing one of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Place the cursor on the line at which you want to set a breakpoint and right-click with the mouse. This action will display a pop-up menu. Select the <B><I>Set Breakpoint</B></I> menu item. </LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Simply single-click on the line number of the line at which you want to set a breakpoint.</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">If the selected line contains executable code a red dot will appear next to the line number and a breakpoint will be set at that location.</P>
|
||||
<P ALIGN="JUSTIFY">You may set clear breakpoint in a script by doing one of the following:</P>
|
||||
|
||||
<UL>
|
||||
<P ALIGN="JUSTIFY"><LI>Place the cursor on the line at which you want to clear a breakpoint and right-click with the mouse. This action will display a pop-up menu. Select the <B><I>Clear Breakpoint</B></I> menu item. </LI></P>
|
||||
<P ALIGN="JUSTIFY"><LI>Simply single-click on the red dot or the line number of the line at which you want to clear a breakpoint.</LI></P></UL>
|
||||
|
||||
<P ALIGN="JUSTIFY">The red dot will disappear and the breakpoint at that location will be cleared.</P>
|
||||
<OL>
|
||||
<OL>
|
||||
<OL>
|
||||
|
||||
<LI><A NAME="_Toc502165114"></FONT><B><FONT FACE="Arial" COLOR="#000080">Viewing Variables</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The lower-left (dockable) pane in the debugger main window contains a tab-pane with two tabs, labeled "this" and "Locals". Each pane contains a tree-table which displays the properties of the current object and currently visible local variables, respectively. </P>
|
||||
<OL>
|
||||
|
||||
</FONT><B><FONT FACE="Arial" COLOR="#000080"><LI>This</LI></OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The properties of the current object are displayed in the <B><I>this</B></I> table. If a property is itself a JavaScript object the property may be expanded to show its sub-properties. The <B><I>this</B></I> table is updated each time control returns to the debugger or when you change the stack location in the <B><I>Context:</B></I> window.</P>
|
||||
<LI><A NAME="_Toc502165115"></FONT><B><FONT FACE="Arial" COLOR="#000080">Locals</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The local variables of the current function are displayed in the <B><I>Locals</B></I> table. If a variable is itself a JavaScript object the variable may be expanded to show its sub-properties. The <B><I>Locals</B></I> table is updated each time control returns to the debugger or when you change the stack location in the <B><I>Context:</B></I> window</P>
|
||||
<LI><A NAME="_Toc502165116"></FONT><B><FONT FACE="Arial" COLOR="#000080">Watch Window</A></LI>
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">You may enter arbitrary JavaScript expressions in the <B><I>Watch:</B></I> table located in the lower-right (dockable) pane in the debugger main window. The expressions you enter are reevaluated in the current scope and their current values displayed each time control returns to the debugger or when you change the stack location in the <B><I>Context:</B></I> window.</P>
|
||||
<LI><A NAME="_Toc502165117"></FONT><B><FONT FACE="Arial" COLOR="#000080">Evaluation Window</A></LI></OL>
|
||||
</OL>
|
||||
</OL>
|
||||
|
||||
</B></FONT><FONT SIZE=2><P ALIGN="JUSTIFY">The <B><I>Evaluate</B></I> pane located in the lower-right (dockable) pane in the debugger main window contains an editable command line where you may enter arbitrary JavaScript code. The code is evaluated in the context of the current stack frame. The window maintains a history of the commands you have entered. You may move backward or forward through the history by pressing the Up/Down arrow keys on the keyboard. </P>
|
||||
</FONT></BODY>
|
||||
</HTML>
|
||||
@@ -1,137 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
|
||||
<title>JavaScript API</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Rhino API Reference.</h1></center>
|
||||
|
||||
<h4>
|
||||
The Control API</h4>
|
||||
These APIs provide methods for controlling the actions of JavaScript in
|
||||
a host environment.
|
||||
<ul>
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Context.html">Context</a> - Represents
|
||||
the runtime context of an executing script. Has methods to associate the
|
||||
JavaScript evaluation engine with a Java thread, set attributes of the
|
||||
engine, and compile and evaluate scripts.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/ContextListener.html">ContextListener</a>
|
||||
- Allows embeddings to be notified of the creation, entering, exiting,
|
||||
and releasing of Contexts. </li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Script.html">Script</a> - The result of
|
||||
compiling a JavaScript script. Also encapsulates script execution.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/ErrorReporter.html">ErrorReporter</a> -
|
||||
This interface can be implemented to control the actions the JavaScript
|
||||
engine takes when it encounters errors.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
|
||||
- Optional support routines that must be provided by embeddings implementing
|
||||
security controls on scripts.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Wrapper.html">Wrapper</a> - Interface implemented
|
||||
by objects wrapping other objects. Provides a method for recovering the
|
||||
wrapped value.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/WrapHandler.html">WrapHandler</a> - Interface
|
||||
embedders can implement in order to control the way Java objects are wrapped
|
||||
for use by JavaScript.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/ClassOutput.html">ClassOutput</a> - Interface
|
||||
embedders can implement in order to control the placement of generated
|
||||
class bytecodes.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/serialize/ScriptableOutputStream.html">ScriptableOutputStream</a> - This stream can be used to serialize JavaScript objects and functions.
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/serialize/ScriptableInputStream.html">ScriptableInputStream</a> - This stream can be used to deserialize JavaScript objects and functions.
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<h4>
|
||||
The Host Object API</h4>
|
||||
These APIs provide support for adding objects specific to a particular
|
||||
embedding of JavaScript in a host environment. Note that if you just want
|
||||
to script existing Java classes, you should just use <a href="http://developer.netscape.com/library/documentation/communicator/jsguide4/livecon.htm">LiveConnect</a>.
|
||||
It is also helpful to understand some of the implementation of the <a href="runtime.html">runtime</a>.
|
||||
<ul>
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Scriptable.html">Scriptable</a> - All JavaScript
|
||||
objects must implement this interface. Provides methods to access properties
|
||||
and attributes of those properties, as well as other services required
|
||||
of JavaScript objects.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/Function.html">Function</a> - All JavaScript
|
||||
functions must implement this interface. Extends Scriptable, adding methods
|
||||
to support invocation.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/ScriptableObject.html">ScriptableObject</a>
|
||||
- A default implementation of Scriptable that may be extended. Implements
|
||||
property and attribute storage and lookup and other default JavaScript
|
||||
object behavior.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/FunctionObject.html">FunctionObject</a>
|
||||
- An implementation of Function that allows Java methods and constructors
|
||||
to be used as JavaScript function objects.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/ImporterTopLevel.html">ImporterTopLevel</a>
|
||||
- Allows embeddings to use the importClass and importPackage functions.</li>
|
||||
</ul>
|
||||
|
||||
<h4>
|
||||
Exceptions</h4>
|
||||
These exceptions are thrown by JavaScript.
|
||||
<ul>
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/JavaScriptException.html">JavaScriptException</a>
|
||||
- Thrown from within JavaScript by the JavaScript 'throw' statement, or
|
||||
by LiveConnect calls from JavaScript into Java. Wraps a JavaScript value.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/ClassDefinitionException.html">ClassDefinitionException</a>
|
||||
- Thrown if errors are detected while attempting to define a host object
|
||||
from a Java class.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/PropertyException.html">PropertyException</a>
|
||||
- Thrown if errors are detected while attempting to define a property of
|
||||
a host object from a Java class or method, or if a property is not found.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/NotAFunctionException.html">NotAFunctionException</a>
|
||||
- Thrown when attempting to call an object that is not a function.</li>
|
||||
|
||||
<li>
|
||||
<a href="org/mozilla/javascript/EvaluatorException.html">EvaluatorException</a>
|
||||
- An exception thrown when an error is detected during the execution of
|
||||
a script. The default error reporter will throw EvaluatorExceptions when
|
||||
an error is encountered.</li>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="overview-summary.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,43 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java, BSF, Apache">
|
||||
<title>Rhino and BSF</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<script src="owner.js"></script>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Using Rhino with BSF and Apache</h1></center>
|
||||
<script>document.write(owner());</script>
|
||||
|
||||
<br><script>
|
||||
var d = new Date(document.lastModified);
|
||||
document.write((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
|
||||
document.write('<br>');
|
||||
</script>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br>The <a href="http://oss.software.ibm.com/developerworks/projects/bsf">Bean
|
||||
Scripting Framework</a> (or BSF) was originally developed by IBM and now
|
||||
published as open source. It provides a framework for using a number of
|
||||
scripting languages with Java. Rhino is one of the supported languages.
|
||||
<p>This framework has been embedded in a number of open source projects,
|
||||
including the XSL processor <a href="http://xml.apache.org/xalan/index.html">Xalan</a>
|
||||
and the XML/Java build tool <a href="http://jakarta.apache.org/ant/index.html">Ant</a>.
|
||||
<p>You can download a version of <tt>bsf.jar</tt> from <a href="http://oss.software.ibm.com/developerworks/projects/bsf">http://oss.software.ibm.com/developerworks/projects/bsf</a>
|
||||
that includes the <tt>com.ibm.bsf.engines.javascript.JavaScriptEngine</tt>
|
||||
class. The current version is 2.2 release candidate at the time of this
|
||||
writing. This version thus supports JavaScript through Rhino when used
|
||||
with the <tt>js.jar</tt> file from either <tt>rhino15R1.zip</tt> or <tt>rhinoTip.zip</tt>.
|
||||
<p>See <a href="http://xml.apache.org/xalan/extensions.html#ex-basic">Xalan-Java
|
||||
Extensions</a> for more information on adding JavaScript to XSL and the
|
||||
<a href="http://jakarta.apache.org/ant/jakarta-ant/docs/#script">Script
|
||||
task</a> for using scripting in Ant build files.
|
||||
<p><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,24 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Change Log</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Change Log for Significant Rhino Changes</h1></center>
|
||||
This is a log of significant changes since the release of Rhino 1.5 Release
|
||||
3.
|
||||
<p><i>None yet!</i>
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><br>
|
||||
<a href="index.html">back to top</a></h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,98 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Debugger API for Rhino</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<h1><center>Debugger API for Rhino</center></h1>
|
||||
<p>
|
||||
<font color="red"><center>This release of the Debugger API should be considered to be of Beta quality.</center></font>
|
||||
<p>
|
||||
The Debugger API for Rhino consists of a set of Java interfaces
|
||||
which describes a high level debugger API and a default implementation of that
|
||||
API.
|
||||
<p>
|
||||
Most of the API is in the <code>com.netscape.javascript.debug</code> package. It is built
|
||||
upon low-level support built into the core engine in <code>com.netscape.javascript</code>.
|
||||
<p>
|
||||
The <code>com.netscape.javascript.debug</code> package includes an implementation of the Debugger API
|
||||
interfaces outlined below. The class <code>com.netscape.javascript.debug.DebugManager.java</code>
|
||||
implements the <a href="com/netscape/javascript/debug/IDebugManager.html">IDebugManager</a>
|
||||
interface and <code>com.netscape.javascript.debug.SourceTextManagerImpl.java</code> implements
|
||||
the <a href="com/netscape/javascript/SourceTextManager.html">SourceTextManager</a> interface.
|
||||
<p>
|
||||
The class <code>com.netscape.javascript.tools.shell.Main.java</code> provides an
|
||||
example which invokes the Debugger API.
|
||||
<p>
|
||||
<hr>
|
||||
<p>
|
||||
The core interface of the API is <a href="com/netscape/javascript/debug/IDebugManager.html">IDebugManager</a>.
|
||||
This interface provide the central point for interacting with the debug system.
|
||||
It supports the setting of the following hooks:
|
||||
<ul>
|
||||
<li><a href="com/netscape/javascript/debug/IInterruptHook.html">IInterruptHook</a> for immediate interrupt.
|
||||
<li><a href="com/netscape/javascript/debug/IInstructionHook.html">IInstructionHook</a> for breakpoints.
|
||||
<li><a href="com/netscape/javascript/debug/IDebugBreakHook.html">IDebugBreakHook</a> for breaking on errors.
|
||||
<li><a href="com/netscape/javascript/debug/IErrorReporter.html">IErrorReporter</a> for hooking into the error reporter system.
|
||||
<li><a href="com/netscape/javascript/debug/IScriptHook.html">IScriptHook</a> for notification of script and function load and unload.
|
||||
</ul>
|
||||
Customers of the Debugger API can provide implementations of these hook
|
||||
interfaces which can be passed to the <i>IDebugManager</i> in order receive
|
||||
notification of the various events within the core JavaScript engine.
|
||||
<p>
|
||||
When hooks are called they are passed appropriate objects which are implemented
|
||||
by the Debugger API to describe such things as <i>stack frames</i>,
|
||||
<i> program counter locations</i>, etc. The interfaces for these objects are:
|
||||
<ul>
|
||||
<li><a href="com/netscape/javascript/debug/IThreadState.html">IThreadState</a> representing the state of the stopped thread.
|
||||
<li><a href="com/netscape/javascript/debug/IStackFrame.html">IStackFrame</a> representing a stack frame.
|
||||
<li><a href="com/netscape/javascript/debug/IPC.html">IPC</a> representing a program counter location.
|
||||
<li><a href="com/netscape/javascript/debug/IScript.html">IScript</a> representing a compiled JavaScript script or function.
|
||||
<li><a href="com/netscape/javascript/debug/ISourceLocation.html">ISourceLocation</a> representing a location in the souce code.
|
||||
</ul>
|
||||
<p>
|
||||
<hr>
|
||||
<p>
|
||||
<a href="com/netscape/javascript/SourceTextManager.html">SourceTextManager</a>
|
||||
is an interface used to supply a centralized location from which a debugger
|
||||
client can access JavaScript source. It supports capturing source as it is
|
||||
parsed by <i>Rhino</i>. Alternately, source can be fed to it by the
|
||||
embedding; e.g. in a browser embedding where the JavaScript code is just a
|
||||
part of the html source the browser can feed the entire source to the
|
||||
<i>SourceTextManager</i> so that a debugger can 'see' the whole source and
|
||||
not just the part that is fed to the JavaScript compiler.
|
||||
<p>
|
||||
<a href="com/netscape/javascript/SourceTextItem.html">SourceTextItem</a> is an
|
||||
interface representing a single 'block' of source code text (typically this
|
||||
is an entire source file). This may be pure JavaScript source, or may include
|
||||
JavaScript source embedded in html or whatever. The point is that this is the
|
||||
text that a debugger should show to a user while debugging the JavaScript code.
|
||||
This interface supports incrementally updated content. This is specifically
|
||||
useful in browser embeddings where text is received in blocks. In fact, in a
|
||||
browser it is possible that some of the source on a page may be compiled
|
||||
and run even before the entire content of the page has been received from a
|
||||
server.
|
||||
<p>
|
||||
<hr>
|
||||
<p>
|
||||
<a href="com/netscape/javascript/debug/ILaunchableDebugger.html">ILaunchableDebugger</a>
|
||||
is an interface that abstractly represents a debugger user interface. It is
|
||||
defined to allow an embedding to request that a debugger be launched without
|
||||
requiring that the embedding be coupled at compile time to a particular debugger
|
||||
implementation.
|
||||
<p>
|
||||
<hr>
|
||||
<h3>Limitations and unimplemented features</h3>
|
||||
<ul>
|
||||
<li>Data Watchpoints are not implemented.
|
||||
<li>Catching exceptions thrown in JavaScript code is not implemented.
|
||||
<li>Per context hooking is not implemented.
|
||||
<li>Setting the debug level to any non-zero value forces the optimization level to zero.
|
||||
<li>Tracking of calls to plain Java methods from JavaScript is not implemented.
|
||||
<li>Running at debug level >= 6 causes JIT errors with the Symantec JVM (but no other JVMs)
|
||||
<li>The Debug API has not been rigorously tested.
|
||||
</ul>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><A HREF="overview-summary.html">back to top</A>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,241 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; I) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java, Debugger">
|
||||
<title>Rhino Debugger</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<script src="owner.js">
|
||||
|
||||
</script>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Rhino JavaScript Debugger</h1></center>
|
||||
Christopher Oliver
|
||||
<br><script>document.write(owner());</script>
|
||||
|
||||
<br>6/28/2001
|
||||
<center>
|
||||
<hr WIDTH="100%"></center>
|
||||
The Rhino JavaScript debugger is a GUI that allows debugging of interpreted
|
||||
JavaScript scripts run in Rhino. Note that this debugger <i>will not</i>
|
||||
work with JavaScript scripts run in the mozilla browser since Rhino is
|
||||
not the engine used in such environments.
|
||||
<p><img SRC="jsdebug.jpg" height=460 width=600>
|
||||
<p>Current limitations:
|
||||
<ul>
|
||||
<li>
|
||||
Requires JDK 1.2 or greater</li>
|
||||
|
||||
<li>
|
||||
Requires js.jar from rhinoTip.zip</li>
|
||||
|
||||
<li>
|
||||
No breakpoint menu</li>
|
||||
</ul>
|
||||
<b><font face="Arial"><font color="#000080"><font size=+2>Using the Rhino
|
||||
JavaScript Debugger</font></font></font></b>
|
||||
<p><font size=-1>The Mozilla Rhino JavaScript engine includes a source-level
|
||||
debugger for debugging JavaScript scripts. The debugger is itself a Java
|
||||
program which you may run as</font>
|
||||
<ol><font face="Arial"><font size=-1>java org.mozilla.javascript.tools.debugger.Main
|
||||
[options] [filename.js] [script-arguments]</font></font></ol>
|
||||
<font size=-1>where the options are the same as the shell.</font>
|
||||
<p><font size=-1>The Rhino JavaScript Debugger can debug scripts running
|
||||
in multiple threads and provides facilities to set and clear breakpoints,
|
||||
control execution, view variables, and evaluate arbitrary JavaScript code
|
||||
in the current scope of an executing script.</font>
|
||||
<p><a NAME="_Toc502165109"></a><b><font face="Arial"><font color="#000080"><font size=-1>Console
|
||||
Window</font></font></font></b>
|
||||
<br><font size=-1>The debugger redirects the <font face="Arial">System.out</font>,
|
||||
<font face="Arial">System.in</font>,
|
||||
and <font face="Arial">System.err</font> streams to an internal JavaScript
|
||||
console window which provides an editable command line for you to enter
|
||||
JavaScript code and view system output. The console window maintains a
|
||||
history of the commands you have entered. You may move backward and forward
|
||||
through the history list by pressing the Up/Down arrow keys on the keyboard.</font>
|
||||
<br><a NAME="_Toc502165110"></a><b><font face="Arial"><font color="#000080"><font size=-1>Opening
|
||||
Scripts</font></font></font></b>
|
||||
<br><font size=-1>You may select the <b><i>File->Open</i></b> menu item
|
||||
on the menu bar to load JavaScript scripts contained in files. This action
|
||||
will display a file-selection dialog box prompting you for the location
|
||||
of a script to load. The selected file will be compiled and displayed in
|
||||
a new window.</font>
|
||||
<br><a NAME="_RunningScripts"></a><b><font face="Arial"><font color="#000080"><font size=-1>Running
|
||||
Scripts</font></font></font></b>
|
||||
<br><font size=-1>You may select the <b><i>File->Run</i></b> menu item
|
||||
on the menu bar to execute JavaScript scripts contained in files. This
|
||||
action will display a file-selection dialog box prompting you for the location
|
||||
of a script to execute. The loaded script will be run in a new thread and
|
||||
control will be given to the debugger on its first instruction.</font>
|
||||
<p><a NAME="_Toc502165111"></a><b><font face="Arial"><font color="#000080"><font size=+1>Controlling
|
||||
Execution</font></font></font></b>
|
||||
<br><font size=-1>The debugger provides the following facilities for you
|
||||
to control the execution of scripts you are debugging:</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Step Into</font></font></b>
|
||||
<br><font size=-1>To single step entering any function calls, you may do
|
||||
any of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Step Into </i></b>menu item on the
|
||||
menu bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Step Into</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the F11 key on the keyboard</font></li>
|
||||
</ul>
|
||||
<font size=-1>Execution will resume. If the current line in the script
|
||||
contains a function call control will return to the debugger upon entry
|
||||
into the function. Otherwise control will return to the debugger at the
|
||||
next line in the current function.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Step Over</font></font></b>
|
||||
<br><font size=-1>To single step to the next line in the current function,
|
||||
you may do any of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Step Over</i></b> menu item on the
|
||||
menu bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Step Over</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the F7 key on the keyboard</font></li>
|
||||
</ul>
|
||||
<font size=-1>Execution will resume but control will return to the debugger
|
||||
at the next line in the current function or top-level script.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Step Out</font></font></b>
|
||||
<br><font size=-1>To continue execution until the current function returns
|
||||
you may do any of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Step Out</i></b> menu item on the
|
||||
menu bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Step Out</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the F8 key on the keyboard</font></li>
|
||||
</ul>
|
||||
<font size=-1>Execution will resume until the current function returns
|
||||
or a breakpoint is hit.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Go</font></font></b>
|
||||
<br><font size=-1>To resume execution of a script you may do any of the
|
||||
following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Go</i></b> menu item on the menu
|
||||
bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Go</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the F5 key on the keyboard</font></li>
|
||||
</ul>
|
||||
<font size=-1>Execution will resume until a breakpoint is hit or the script
|
||||
completes.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Break</font></font></b>
|
||||
<br><font size=-1>To stop all running scripts and give control to the debugger
|
||||
you may do any of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Select the <b><i>Debug->Break</i></b> menu item on the menu
|
||||
bar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the <b><i>Break</i></b> button on the toolbar</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Press the Pause/Break key on the keyboard</font></li>
|
||||
</ul>
|
||||
<a NAME="_RunningScripts"></a><b><font face="Arial"><font color="#000080"><font size=-1>Break
|
||||
on Exceptions</font></font></font></b>
|
||||
<br><font size=-1>To give control to the debugger whenever a JavaScript
|
||||
is exception is thrown select the <b><i>Debug->Break on Exceptions</i></b>
|
||||
checkbox from the menu bar. Whenever a JavaScript exception is thrown
|
||||
by a script a message dialog will be displayed and control will be given
|
||||
to the debugger at the location the exception is raised.</font>
|
||||
<p><a NAME="_Toc502165112"></a><b><font face="Arial"><font color="#000080">Moving
|
||||
Up and Down the Stack</font></font></b>
|
||||
<br><font size=-1>The lower-left (dockable) pane in the debugger main window
|
||||
contains a combo-box labeled "Context:" which displays the current stack
|
||||
of the executing script. You may move up and down the stack by selecting
|
||||
an entry in the combo-box. When you select a stack frame the variables
|
||||
and watch windows are updated to reflect the names and values of the variables
|
||||
visible at that scope.</font>
|
||||
<p><a NAME="_Toc502165113"></a><b><font face="Arial"><font color="#000080">Setting
|
||||
and Clearing Breakpoints</font></font></b>
|
||||
<br><font size=-1>The main desktop of the debugger contains file windows
|
||||
which display the contents of each script you are debugging. You may set
|
||||
a breakpoint in a script by doing one of the following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Place the cursor on the line at which you want to set a breakpoint
|
||||
and right-click with the mouse. This action will display a pop-up menu.
|
||||
Select the <b><i>Set Breakpoint</i></b> menu item.</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Simply single-click on the line number of the line at which
|
||||
you want to set a breakpoint.</font></li>
|
||||
</ul>
|
||||
<font size=-1>If the selected line contains executable code a red dot will
|
||||
appear next to the line number and a breakpoint will be set at that location.</font>
|
||||
<p><font size=-1>You may clear breakpoint in a script by doing one of the
|
||||
following:</font>
|
||||
<ul>
|
||||
<li>
|
||||
<font size=-1>Place the cursor on the line at which you want to clear a
|
||||
breakpoint and right-click with the mouse. This action will display a pop-up
|
||||
menu. Select the <b><i>Clear Breakpoint</i></b> menu item.</font></li>
|
||||
|
||||
<li>
|
||||
<font size=-1>Simply single-click on the red dot or the line number of
|
||||
the line at which you want to clear a breakpoint.</font></li>
|
||||
</ul>
|
||||
<font size=-1>The red dot will disappear and the breakpoint at that location
|
||||
will be cleared.</font>
|
||||
<p><a NAME="_Toc502165114"></a><b><font face="Arial"><font color="#000080"><font size=+1>Viewing
|
||||
Variables</font></font></font></b>
|
||||
<br><font size=-1>The lower-left (dockable) pane in the debugger main window
|
||||
contains a tab-pane with two tabs, labeled "this" and "Locals". Each pane
|
||||
contains a tree-table which displays the properties of the current object
|
||||
and currently visible local variables, respectively.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">This</font></font></b>
|
||||
<br><font size=-1>The properties of the current object are displayed in
|
||||
the
|
||||
<b><i>this</i></b> table. If a property is itself a JavaScript object
|
||||
the property may be expanded to show its sub-properties. The <b><i>this</i></b>
|
||||
table is updated each time control returns to the debugger or when you
|
||||
change the stack location in the <b><i>Context:</i></b> window.</font>
|
||||
<p><b><font face="Arial"><font color="#000080">Locals</font></font></b>
|
||||
<br><font size=-1>The local variables of the current function are displayed
|
||||
in the <b><i>Locals</i></b> table. If a variable is itself a JavaScript
|
||||
object the variable may be expanded to show its sub-properties. The <b><i>Locals</i></b>
|
||||
table is updated each time control returns to the debugger or when you
|
||||
change the stack location in the <b><i>Context:</i></b> window</font>
|
||||
<p><a NAME="_Toc502165116"></a><b><font face="Arial"><font color="#000080">Watch
|
||||
Window</font></font></b>
|
||||
<br><font size=-1>You may enter arbitrary JavaScript expressions in the
|
||||
<b><i>Watch:</i></b>
|
||||
table located in the lower-right (dockable) pane in the debugger main window.
|
||||
The expressions you enter are re-evaluated in the current scope and their
|
||||
current values displayed each time control returns to the debugger or when
|
||||
you change the stack location in the <b><i>Context:</i></b> window.</font>
|
||||
<p><a NAME="_Toc502165117"></a><b><font face="Arial"><font color="#000080">Evaluation
|
||||
Window</font></font></b>
|
||||
<br><font size=-1>The <b><i>Evaluate</i></b> pane located in the lower-right
|
||||
(dockable) pane in the debugger main window contains an editable command
|
||||
line where you may enter arbitrary JavaScript code. The code is evaluated
|
||||
in the context of the current stack frame. The window maintains a history
|
||||
of the commands you have entered. You may move backward or forward through
|
||||
the history by pressing the Up/Down arrow keys on the keyboard.</font>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,166 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Rhino Documentation</title>
|
||||
</head>
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<center>
|
||||
<h1> Rhino Documentation</h1>
|
||||
</center>
|
||||
<b><i><font size="+1">General</font></i></b>
|
||||
<table width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><a href="overview.html">Overview</a>
|
||||
</td>
|
||||
<td>An overview of the JavaScript language and of Rhino.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="limits.html">Requirements and Limitations</a>
|
||||
</td>
|
||||
<td>What you must have to run Rhino; what Rhino cannot do.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="rhino15R3.html">What's new in 1.5R3</a>
|
||||
</td>
|
||||
<td>Changes since 1.5R2.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="debugger.html">Rhino Debugger</a>
|
||||
</td>
|
||||
<td>A debugger for debugging JavaScript running in Rhino.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="opt.html">Optimization</a>
|
||||
</td>
|
||||
<td>Details on the various optimization levels.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="http://sourceforge.net/projects/jscorba">JS/CORBA Adapter</a>
|
||||
</td>
|
||||
<td>Provides a mechanism for arbitrary JavaScript objects to interact
|
||||
with each other transparently in a distributed JavaScript system using CORBA.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="bsf.html">Using Rhino with BSF and Apache</a>
|
||||
</td>
|
||||
<td>How to use Rhino with apps that support BSF.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="changes.html">Recent Changes</a>
|
||||
</td>
|
||||
<td>Describes recent changes to Rhino.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="faq.html">FAQ</a>
|
||||
</td>
|
||||
<td>Answers to frequently asked questions about Rhino.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="http://industry.java.sun.com/javaone/99/event/0,1768,629,00.html">
|
||||
1999 JavaOne session on Rhino</a>
|
||||
</td>
|
||||
<td>A talk on Rhino with slides. Also see the <a href="javaone.html">followup</a>
|
||||
.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td valign="Top"><a href="http://www.ociweb.com/jnb/archive/jnbMar2001.html">
|
||||
Scripting Languages for Java</a>
|
||||
<br>
|
||||
</td>
|
||||
<td valign="Top">An article comparing and contrasting Rhino and Jython.<br>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p><b><i><font size="+1">Writing Scripts</font></i></b>
|
||||
<table width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><a href="scriptjava.html">Scripting Java</a>
|
||||
</td>
|
||||
<td>How to use Rhino to script Java classes.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="perf.html">Performance Hints</a>
|
||||
</td>
|
||||
<td>Some tips on writing faster JavaScript code.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="tools.html">Tools</a>
|
||||
</td>
|
||||
<td>Some tools for developing JavaScript scripts.</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
|
||||
<p><b><i><font size="+1">Embedding Rhino</font></i></b>
|
||||
<table width="100%">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><a href="tutorial.html">Embedding tutorial</a>
|
||||
</td>
|
||||
<td>A short tutorial on how to embed Rhino into your application.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="apidocs/index.html">API javadoc Reference</a>
|
||||
</td>
|
||||
<td>An annotated outline of the programming interface to Rhino (tip only).</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="scopes.html">Scopes and Contexts</a>
|
||||
</td>
|
||||
<td>Describes how to use scopes and contexts for the best performance
|
||||
and flexibility, with an eye toward multithreaded environments.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="serialization.html">Serialization</a>
|
||||
</td>
|
||||
<td>How to serialize JavaScript objects and functions in Rhino.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="runtime.html">Runtime</a>
|
||||
</td>
|
||||
<td>A brief description of the JavaScript runtime.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="footprint.html">Small Footprint</a>
|
||||
</td>
|
||||
<td>Hints for those interested in small-footprint embeddings.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="examples.html">Examples</a>
|
||||
</td>
|
||||
<td>A set of examples showing how to control the JavaScript engine and
|
||||
build JavaScript host objects.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><font color="#000000"><a href="http://www.mozilla.org/js/tests/library.html">
|
||||
Testing</a>
|
||||
</font></td>
|
||||
<td>How to run the JavaScript test suite.</td>
|
||||
</tr>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
|
||||
<h3>
|
||||
<hr width="100%"><a href="index.html">back to top</a>
|
||||
</h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,88 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
<title>Rhino Downloads</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center><b><font size="+3">Rhino Downloads</font></b></center>
|
||||
|
||||
<p>Rhino is available for download both in source and compiled form. </p>
|
||||
<h3> Binaries</h3>
|
||||
You can download binaries (JAR files) from <a href="ftp://ftp.mozilla.org/pub/js/">
|
||||
ftp://ftp.mozilla.org/pub/js/</a>
|
||||
. Rhino 1.5 Release 2 is the last qualified release. It is also possible to
|
||||
download the latest rhino build that reflects newer features and bug fixes,
|
||||
but has not been fully qualified. These zip files also include the source.
|
||||
<p>If you are looking for <tt>js.jar</tt> for XSLT or for IBM's Bean Scripting
|
||||
Framework (BSF), download one of the zip files below and unzip it. </p>
|
||||
<ul>
|
||||
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhino15R3-rc2.zip">Rhino 1.5R3
|
||||
(release candidate 2).</a>
|
||||
</li>
|
||||
|
||||
<ul>
|
||||
<li> <i><font size="-1"><a href="rhino15R3.html">Description of changes
|
||||
from 1.5R2</a>
|
||||
</font></i>.</li>
|
||||
|
||||
</ul>
|
||||
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhino15R2.zip">Rhino 1.5R2.</a>
|
||||
</li>
|
||||
|
||||
<ul>
|
||||
<li> <i><font size="-1"><a href="rhino15R2.html">Description of changes
|
||||
from 1.5R1</a>
|
||||
</font></i>.</li>
|
||||
|
||||
</ul>
|
||||
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhino15R1.zip">Rhino 1.5R1.</a>
|
||||
</li>
|
||||
|
||||
<ul>
|
||||
<li> <i><font size="-1"><a href="rhino15R1.html">Description of changes
|
||||
from 1.4R3</a>
|
||||
</font></i>.</li>
|
||||
|
||||
</ul>
|
||||
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhino14R3.zip">Rhino 1.4 Release
|
||||
3</a>
|
||||
.</li>
|
||||
<li> <a href="ftp://ftp.mozilla.org/pub/js/rhinoLatest.zip">Latest Rhino
|
||||
builds</a>
|
||||
.</li>
|
||||
|
||||
<ul>
|
||||
<li> <i><font size="-1"><a href="changes.html">Description of changes from
|
||||
1.5R3</a>
|
||||
</font></i>.</li>
|
||||
|
||||
</ul>
|
||||
|
||||
</ul>
|
||||
|
||||
<h3> Source</h3>
|
||||
The source code for Rhino is available under <a href="http://www.mozilla.org/NPL/">
|
||||
NPL 1.1</a>
|
||||
. In addition to getting the source from the zip files above, the source
|
||||
code for Rhino can be found in the CVS tree at mozilla/js/rhino. See
|
||||
<a href="http://www.mozilla.org/cvs.html">source code via cvs</a>
|
||||
for details on how to set up CVS, define your CVSROOT, and login. Once you've
|
||||
done that, just execute the command
|
||||
<pre> cvs co mozilla/js/rhino</pre>
|
||||
to get the tip source.
|
||||
<p>The current tip can also be viewed using LXR at <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/">
|
||||
http://lxr.mozilla.org/mozilla/source/js/rhino/</a>
|
||||
. </p>
|
||||
<p> </p>
|
||||
<hr width="100%"><a href="index.html">back to top</a>
|
||||
<br>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,278 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Generator" content="Microsoft Word 97">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
|
||||
<title>Embedding ‘Scripting Host’ in Business Applications</title>
|
||||
</head>
|
||||
<body link="#0000FF">
|
||||
<b><font face="Arial"><font size=-1>Embedding
|
||||
‘Scripting Host’ in Business Applications</font></font></b>
|
||||
<p><b><font face="Arial"><font size=-1>Madhukumar Seshadri, <a href="http://www.cognizant.com)/">www.cognizant.com</a></font></font></b>
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>With web browsers, continuing to rule
|
||||
the human interface for applications, creating value by being ubiquitous,
|
||||
few adoptions of rich technology that’s getting brewed underneath, will
|
||||
help designing business applications even though most of the current ones
|
||||
are made with bird’s eye of the underlying technologies.</font></font>
|
||||
<p><font face="Arial"><font size=-1>JavaScript is a scripting language
|
||||
invented and developed by Netscape. The language was primarily designed
|
||||
for creating lightweight programming for web browser extensions by exposing
|
||||
the Document Object Model of an HTML page to the scripts. JavaScript is
|
||||
becoming object oriented and getting adopted for server-side scripting.</font></font>
|
||||
<p><font face="Arial"><font size=-1>JavaScript is also becoming a standard
|
||||
in the scripting world as Netscape is working closely with ECMA (European
|
||||
Computer Manufacturers Association) to make it as a standard scripting
|
||||
language for the script world. The standards are published as ECMA Script.</font></font>
|
||||
<p><font face="Arial"><font size=-1>JavaScript originally designed for
|
||||
exposing the DOM (Document Object Model) standardized by World Wide Web
|
||||
consortium (W3C), to help web page designers to control and manipulate
|
||||
the pages dynamically. ‘JavaScript’ engines were embedded in the browsers
|
||||
and they execute those portions of the code embedded in the HTML pages.</font></font>
|
||||
<p><font face="Arial"><font size=-1>In short, JavaScript engine embedded
|
||||
in the browser allowed extensions or manipulations for DOM Object run time
|
||||
for the HTML page by executing the ‘scripts’ associated with them. In other
|
||||
words, browser exposes its DOM object for the page to scripts for extensions
|
||||
and dynamic manipulations of the same, using a language that the script
|
||||
interpreter understands.</font></font>
|
||||
<p><font face="Arial"><font size=-1>Can I do the same for my application
|
||||
by exposing my custom business objects written in my middle-tier? Can I
|
||||
allow user to my write JavaScript extensions for my objects and also be
|
||||
host for executing those scripts?</font></font>
|
||||
<p><font face="Arial"><font size=-1>JavaScript host runs times are available
|
||||
as binaries written in major languages. Check out <a href="http://www.mozilla.org/js">www.mozilla.org/js</a>.
|
||||
Spider Monkey and Rhino are open source JavaScripting engines available
|
||||
from mozilla.</font></font>
|
||||
<p><font face="Arial"><font size=-1>Microsoft implementation of ECMA Script
|
||||
(ECMA Script is based on core JavaScript, created by Netscape) is called
|
||||
JScript. Microsoft binaries of jscript engine can be downloaded from http://msdn.microsoft.com/scripting/.</font></font>
|
||||
<p><font face="Arial"><font size=-1>This document doesn’t explain the JavaScript
|
||||
language in detail but explains how these scripting engines can be used
|
||||
as host to expose business objects in the middle-tier and how the user
|
||||
of these applications can extend it if needed using JavaScript.</font></font>
|
||||
<p><font face="Arial"><font size=-1>The scripting engine Rhino (<a href="http://www.mozilla.org/js)">www.mozilla.org/rhino)</a>,
|
||||
a javascript engine purely written in Java is one that I am going to use
|
||||
for the testing the above.</font></font>
|
||||
<p><font face="Arial"><font size=-1>Let us set some simple goals,</font></font>
|
||||
<ul>
|
||||
<li>
|
||||
<font face="Arial"><font size=-1>Execute a plain ‘JavaScript’ code and
|
||||
use static Java object</font></font></li>
|
||||
|
||||
<li>
|
||||
<font face="Arial"><font size=-1>Instantiate external objects (written
|
||||
in Java) from the script and use them within the script</font></font></li>
|
||||
</ul>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>Let us write a simple Javscript to
|
||||
test the above set goals,</font></font>
|
||||
<p><font face="Arial"><font size=-1><b>Fig 1</b> – jshosttest.js</font></font>
|
||||
<p><b><i><font face="Arial"><font size=-1>/* Test 1 */</font></font></i></b>
|
||||
<br><b><i><font face="Arial"><font size=-1>/* Use a static Java Object
|
||||
in the script */</font></font></i></b>
|
||||
<p><font face="Arial"><font size=-1>function test1() {</font></font>
|
||||
<br><font face="Arial"><font size=-1> var str;</font></font>
|
||||
<br><font face="Arial"><font size=-1> str = '"Hello World";</font></font>
|
||||
<br><font face="Arial"><font size=-1> return str;</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>var str = test1( );</font></font>
|
||||
<br><font face="Arial"><font size=-1>//out is expected to be Java Object
|
||||
exposed to the script scope</font></font>
|
||||
<br><font face="Arial"><font size=-1>out.println ("JavaScript - Test 1
|
||||
- " + str);</font></font>
|
||||
<p><b><i><font face="Arial"><font size=-1>/* Test 2 */</font></font></i></b>
|
||||
<p><b><i><font face="Arial"><font size=-1>/* Instantiate a Javaobject for
|
||||
this scope and use it */</font></font></i></b>
|
||||
<p><font face="Arial"><font size=-1>function test2(){</font></font>
|
||||
<br><font face="Arial"><font size=-1> // create a Java
|
||||
string buffer object from JavaScript and use its java instance</font></font>
|
||||
<br><font face="Arial"><font size=-1> // This uses an
|
||||
another Java object created for creating new objects within Java and</font></font>
|
||||
<br><font face="Arial"><font size=-1> // brings the same
|
||||
for JavaScript execution scope</font></font>
|
||||
<br><font face="Arial"><font size=-1> // Refer _create.java
|
||||
for more information</font></font>
|
||||
<br><font face="Arial"><font size=-1> create.getInstance("java.lang.StringBuffer","buffer");</font></font>
|
||||
<br><font face="Arial"><font size=-1> //JavaScript refers
|
||||
the java object instance as ‘buffer’</font></font>
|
||||
<br><font face="Arial"><font size=-1> out.println(buffer.toString());</font></font>
|
||||
<br> <font face="Arial"><font size=-1>buffer.append("I
|
||||
am a javaobject dynamically created and executed in JavaScript");</font></font>
|
||||
<br> <font face="Arial"><font size=-1>return buffer.toString();</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>var str = test2();</font></font>
|
||||
<br><font face="Arial"><font size=-1>out.println("From JavaScript - Test
|
||||
2 " + str);</font></font>
|
||||
<p><font face="Arial"><font size=-1>Let us write a simple Javahost Object
|
||||
using the Rhino engine to execute the above script,</font></font>
|
||||
<p><b><font face="Arial"><font size=-1>Fig 2.1 - JSHost.java</font></font></b>
|
||||
<p><font face="Arial"><font size=-1>/**</font></font>
|
||||
<br><font face="Arial"><font size=-1>* @author Madhukumar Seshadri</font></font>
|
||||
<br><font face="Arial"><font size=-1>* @version</font></font>
|
||||
<br><font face="Arial"><font size=-1>*/</font></font>
|
||||
<p><font face="Arial"><font size=-1>import org.mozilla.javascript.*;</font></font>
|
||||
<br><font face="Arial"><font size=-1>import java.io.*;</font></font>
|
||||
<br><font face="Arial"><font size=-1>import java.lang.*;</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>// import com.xxx.xxx.*;</font></font></i>
|
||||
<p><font face="Arial"><font size=-1>public class JSHost extends Object
|
||||
{</font></font>
|
||||
<br><font face="Arial"><font size=-1> /** Creates new
|
||||
JSHost */</font></font>
|
||||
<br><font face="Arial"><font size=-1> public JSHost()
|
||||
{</font></font>
|
||||
<br><font face="Arial"><font size=-1> }</font></font>
|
||||
<p><i><font face="Arial"><font size=-1> /*** Executes
|
||||
.js file ***/</font></font></i>
|
||||
<br><font face="Arial"><font size=-1> public Object executeJS
|
||||
(String jsfname){</font></font>
|
||||
<br><font face="Arial"><font size=-1> //You can also
|
||||
use evaluateReader</font></font>
|
||||
<br><font face="Arial"><font size=-1> File fp = new File(jsfname);</font></font>
|
||||
<br><font face="Arial"><font size=-1> String str_buff
|
||||
=null;</font></font>
|
||||
<br><font face="Arial"><font size=-1> try {</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
FileReader fr = new FileReader(jsfname);</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
int length = (int) fp.length();</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
char cbuff[] = new char[(char)length];</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
fr.read(cbuff);</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
str_buff = new String(cbuff);</font></font>
|
||||
<br><font face="Arial"><font size=-1> } catch(Exception
|
||||
e) {</font></font>
|
||||
<br><font face="Arial"><font size=-1>
|
||||
e.printStackTrace();</font></font>
|
||||
<br><font face="Arial"><font size=-1> }</font></font>
|
||||
<p><font face="Arial"><font size=-1> //Execute the .js
|
||||
file content</font></font>
|
||||
<br><font face="Arial"><font size=-1> return executeJSSource(str_buff);</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><i><font face="Arial"><font size=-1>/*** Executes javascript source
|
||||
***/</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>public Object executeJSSource (String
|
||||
jsbuff){</font></font>
|
||||
<br><font face="Arial"><font size=-1>Object any=null;</font></font>
|
||||
<br><font face="Arial"><font size=-1>try{</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>//Enter the Context</font></font></i>
|
||||
<br><font face="Arial"><font size=-1><i>// Refer </i><u><font color="#0000FF">http://www.mozilla.org/js/rhino/tutorial.html</font></u></font></font>
|
||||
<br><font face="Arial"><font size=-1>Context context = Context.enter();</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>// Get the execution scope</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>Scriptable scope = context.initStandardObjects(null);</font></font>
|
||||
<p><i><font face="Arial"><font size=-1>//----------- For Test 1 - Get System.out
|
||||
in scope</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>//Scriptable jObj1 = Context.toObject(System.out,
|
||||
scope);</font></font>
|
||||
<br><font face="Arial"><font size=-1>scope.put("out", scope, jObj1);</font></font>
|
||||
<p><i><font face="Arial"><font size=-1>//------------ For Test 2 - Instantiate
|
||||
Create Object and get that in scope</font></font></i>
|
||||
<br><i><font face="Arial"><font size=-1>//Allow JScript to create Java
|
||||
Objects</font></font></i>
|
||||
<br><i><font face="Arial"><font size=-1>//Bring the _create object to context</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>_create create = new _create( );</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>//Register this context and scope
|
||||
to this create object instance</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>create.registerContext(context,scope);</font></font>
|
||||
<br><font face="Arial"><font size=-1>//Scriptable jObj2 = Context.toObject(_create,
|
||||
scope);</font></font>
|
||||
<br><font face="Arial"><font size=-1>scope.put("create",scope,create);</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>//Evaluate (or execute js)</font></font></i>
|
||||
<br><font face="Arial"><font size=-1><i>//Refer </i><u><font color="#0000FF">http://www.mozilla.org/js/rhino/tutorial.html</font></u></font></font>
|
||||
<br><font face="Arial"><font size=-1>any = context.evaluateString(scope,
|
||||
jsbuff, "", 1, null);</font></font>
|
||||
<br><i><font face="Arial"><font size=-1>//Exit the Context</font></font></i>
|
||||
<br><font face="Arial"><font size=-1>context.exit( );</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>catch ( JavaScriptException jse) {</font></font>
|
||||
<br><font face="Arial"><font size=-1>jse.printStackTrace();</font></font>
|
||||
<br><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>return any;</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>Let us write a class for creating new
|
||||
Java objects and bringing them to this script execution scope,</font></font>
|
||||
<p><b><font face="Arial"><font size=-1>Fig 2.2 – _create.java</font></font></b>
|
||||
<p><i><font face="Arial"><font size=-1>/**</font></font></i>
|
||||
<p><i><font face="Arial"><font size=-1>* @author Madhukumar</font></font></i>
|
||||
<p><i><font face="Arial"><font size=-1>*/</font></font></i>
|
||||
<p><font face="Arial"><font size=-1>import java.lang.Class;</font></font>
|
||||
<p><font face="Arial"><font size=-1>import org.mozilla.javascript.*;</font></font>
|
||||
<p><font face="Arial"><font size=-1>public class _create extends Object
|
||||
{</font></font>
|
||||
<p><font face="Arial"><font size=-1>static Context ptr = null;</font></font>
|
||||
<p><font face="Arial"><font size=-1>static Scriptable scope =null;</font></font>
|
||||
<p><font face="Arial"><font size=-1>public _create () { }</font></font>
|
||||
<p><font face="Arial"><font size=-1>public void registerContext(Context
|
||||
cptr, Scriptable sc){</font></font>
|
||||
<p><font face="Arial"><font size=-1>ptr = cptr;</font></font>
|
||||
<p><font face="Arial"><font size=-1>scope = sc;</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>public void getInstance(String classname,String
|
||||
jsclassname) {</font></font>
|
||||
<p><font face="Arial"><font size=-1>Object any=null;</font></font>
|
||||
<p><font face="Arial"><font size=-1>try {</font></font>
|
||||
<p><font face="Arial"><font size=-1>Class thisclass = Class.forName(classname);</font></font>
|
||||
<p><font face="Arial"><font size=-1>any = thisclass.newInstance();</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>catch(Exception e){</font></font>
|
||||
<p><font face="Arial"><font size=-1>e.printStackTrace();</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>if( ptr != null) {</font></font>
|
||||
<p><font face="Arial"><font size=-1>if (scope !=null) {</font></font>
|
||||
<p><i><font face="Arial"><font size=-1>//register created object for this
|
||||
execution scope</font></font></i>
|
||||
<p><font face="Arial"><font size=-1>scope.put(jsclassname,scope,any);</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>It is time to test the code, so let
|
||||
us write a small object that will use the JSHost object,</font></font>
|
||||
<p><b><font face="Arial"><font size=-1>Fig 3 - JSHosttest.java</font></font></b>
|
||||
<p><font face="Arial"><font size=-1>/**</font></font>
|
||||
<p><font face="Arial"><font size=-1>* @author Madhukumar</font></font>
|
||||
<p><font face="Arial"><font size=-1>* @version</font></font>
|
||||
<p><font face="Arial"><font size=-1>*/</font></font>
|
||||
<p><font face="Arial"><font size=-1>public class JSHosttest extends Object
|
||||
{</font></font>
|
||||
<p><font face="Arial"><font size=-1>/** Creates new JSHostTest*/</font></font>
|
||||
<p><font face="Arial"><font size=-1>public JSHosttest() {</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>public static void main (String args[]){</font></font>
|
||||
<p><font face="Arial"><font size=-1>if (args.length < 1) {</font></font>
|
||||
<p><font face="Arial"><font size=-1>System.out.println("Usage - Java JSHosttest.class
|
||||
<js source file>");</font></font>
|
||||
<p><font face="Arial"><font size=-1>return;</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>JSHost jsh = new JSHost();</font></font>
|
||||
<p><font face="Arial"><font size=-1>System.out.println("Executing JavaScript
|
||||
file - " + args[0]);</font></font>
|
||||
<p><font face="Arial"><font size=-1>Object result = jsh.executeJS(args[0]);</font></font>
|
||||
<p><font face="Arial"><font size=-1>if (result instanceof String){</font></font>
|
||||
<p><font face="Arial"><font size=-1>System.out.println("Results - " + result);</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<p><font face="Arial"><font size=-1>}</font></font>
|
||||
<br>
|
||||
<br>
|
||||
<p><font face="Arial"><font size=-1>For more explanations on the code execution,
|
||||
please refer embedding tutorial <a href="http://www.mozilla.org/js/rhino/tutorial.html">http://www.mozilla.org/js/rhino/tutorial.html</a>
|
||||
and for all documentation and examples on Rhino visit <a href="http://www.mozilla.org/rhino/doc.html">http://www.mozilla.org/rhino/doc.html</a>.</font></font>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,89 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
|
||||
<title>Rhino Examples</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Rhino Examples</h1></center>
|
||||
Examples have been provided that show how to control the JavaScript engine
|
||||
and to implement scriptable host objects. All the examples are in the cvs
|
||||
tree at <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/">mozilla/js/rhino/examples</a></tt>.
|
||||
<br>
|
||||
<h2>
|
||||
Sample Scripts</h2>
|
||||
The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/unique.js">unique.js</a></tt>
|
||||
script allows printing unique lines from a file.
|
||||
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/liveConnect.js">liveConnect.js</a></tt>
|
||||
script shows a sample usage of LiveConnect (Java-to-JavaScript connectivity).
|
||||
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/jsdoc.js">jsdoc.js</a></tt>
|
||||
script is a JavaScript analog to Java's <tt>javadoc</tt>. It makes heavy
|
||||
use of regular expressions.
|
||||
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/checkParam.js">checkParam.js</a></tt>
|
||||
script is a useful tool to check that <tt>@param</tt> tags in Java documentation
|
||||
comments match the parameters in the corresponding Java method.
|
||||
<p>The <tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/enum.js">enum.js</a></tt>
|
||||
script is a good example of using a JavaAdapter to implement a Java interface
|
||||
using a JavaScript object.
|
||||
<p>The <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/NervousText.js">NervousText.js</a>
|
||||
script is a JavaScript implementation of the famous NervousText applet
|
||||
using JavaScript compiled to Java classes using <a href="jsc.html">jsc</a>.
|
||||
It can be run in the HTML page <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/NervousText.html">NervousText.html</a>.
|
||||
<br>
|
||||
<h2>
|
||||
Controlling the JavaScript Engine</h2>
|
||||
|
||||
<h4>
|
||||
The RunScript class</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript.java">RunScript.java</a></tt>
|
||||
is a simple program that executes a script from the command line.
|
||||
<h4>
|
||||
The Control class</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Control.java">Control.java</a></tt>
|
||||
is a program that executes a simple script and then manipulates the result.
|
||||
<h4>
|
||||
JavaScript Shell</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Shell.java">Shell.java</a></tt>
|
||||
is a program that executes JavaScript programs; it is a simplified version
|
||||
of the shell in the <tt>tools</tt> package. The programs may be specified
|
||||
as files on the command line or by typing interactively while the shell
|
||||
is running.
|
||||
<h4>
|
||||
<b>Multithreaded Script Execution</b></h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/DynamicScopes.java">DynamicScopes.java</a></tt>
|
||||
is a program that creates a single global scope object and then shares
|
||||
it across multiple threads. Sharing the global scope allows both information
|
||||
to be shared across threads, and amortizes the cost of Context.initStandardObjects
|
||||
by only performing that expensive operation once.
|
||||
<br>
|
||||
<h2>
|
||||
Implementing Host Objects</h2>
|
||||
First check out the <a href="http://www.mozilla.org/rhino/tutorial.html">tutorial</a>
|
||||
if you haven't already.
|
||||
<h4>
|
||||
The Foo class - Extending ScriptableObject</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Foo.java">Foo.java</a></tt>
|
||||
is a simple JavaScript host object that includes a property with an associated
|
||||
action and a variable argument method.
|
||||
<br>
|
||||
<h4>
|
||||
The Matrix class - Implementing Scriptable</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Matrix.java">Matrix.java</a></tt>
|
||||
provides a simple multidimensional array by implementing the Scriptable
|
||||
interface.
|
||||
<br>
|
||||
<h4>
|
||||
The File class - An advanced example</h4>
|
||||
<tt><a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/File.java">File.java</a></tt>
|
||||
extends ScriptableObject to provide a means of reading and writing files
|
||||
from JavaScript. A more involved example of host object definition.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,52 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Rhino FAQ</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<script src="owner.js"></script>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Frequently Asked Questions about Rhino</h1></center>
|
||||
<script>document.write(owner());</script>
|
||||
|
||||
<br><script>
|
||||
var d = new Date(document.lastModified);
|
||||
document.write((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
|
||||
document.write('<br>');
|
||||
</script>
|
||||
|
||||
<center>
|
||||
<hr WIDTH="100%"></center>
|
||||
|
||||
<p><b><font size=+2>Q</font>.</b> <i>How do I create a Java array from
|
||||
JavaScript?</i>
|
||||
<p><b><font size=+2>A.</font></b> You must use Java reflection. For instance,
|
||||
to create an array of java.lang.String of length five, do
|
||||
<blockquote><tt>var stringArray = java.lang.reflect.Array.newInstance(java.lang.String,
|
||||
5);</tt></blockquote>
|
||||
Then if you wish to assign the string "hi" to the first element, simply
|
||||
execute <tt>stringArray[0] = "hi"</tt>.
|
||||
<p>Creating arrays of primitive types is slightly different: you must use
|
||||
the TYPE field. For example, creating an array of seven ints can be done
|
||||
with the code
|
||||
<blockquote><tt>var intArray = java.lang.reflect.Array.newInstance(java.lang.Integer.TYPE,
|
||||
7);</tt></blockquote>
|
||||
|
||||
<p><br><b><font size=+2>Q</font>.</b> <i>When I try to execute a script
|
||||
I get the exception </i><tt>Required security context missing</tt><i>.
|
||||
What's going on?</i>
|
||||
<p><b><font size=+2>A.</font></b> You've likely missed placing the <tt>Security.properties</tt>
|
||||
file in your class path at <tt>org.mozilla.javascript.resources</tt>.
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><br>
|
||||
<a href="index.html">back to top</a></h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,48 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; U) [Netscape]">
|
||||
<title>Small Footprint</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Small Footprint</h1></center>
|
||||
A few changes can be made to reduce the footprint of Rhino for embeddings
|
||||
where space is at a premium. On a recent build, Rhino consumed 355,883
|
||||
bytes of space for uncompressed class files. With various changes that
|
||||
number can be reduced to 281,455 bytes.
|
||||
<br>
|
||||
<h3>
|
||||
Tools</h3>
|
||||
Most embeddings won't need any of the classes in <tt>org.mozilla.javascript.tools</tt>
|
||||
or any of its subpackages.
|
||||
<br>
|
||||
<h3>
|
||||
Regular Expressions</h3>
|
||||
The package <tt>org.mozilla.javascript.regexp</tt> can be removed. Rhino
|
||||
will continue to run, although it will not be able to execute any regular
|
||||
expression matches. This change saves 37,792 bytes of class files.
|
||||
<br>
|
||||
<h3>
|
||||
JavaAdapter</h3>
|
||||
Implementing the JavaAdapter functionality requires the ability to generate
|
||||
classes on the fly. Removing <tt>org.mozilla.javascript.JavaAdapter</tt> and all
|
||||
the classes in package <tt>org.mozilla.classfile</tt> will disable this
|
||||
functionality, but Rhino will otherwise run correctly. These changes save
|
||||
36,636 bytes.
|
||||
<br>
|
||||
<h3>
|
||||
Optimizer</h3>
|
||||
It is possible to run Rhino with interpreter mode only, allowing you to remove
|
||||
classes for classfile generation. Remove the classes in packages
|
||||
<tt>org.mozilla.classfile</tt> and <tt>org.mozilla.javascript.optimizer</tt>.
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,44 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
<title>Help with Rhino</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center><b><font size=+3>Help with Rhino</font></b></center>
|
||||
<script src="owner.js"></script>
|
||||
|
||||
<p>Have a question that you can't find answer to in the <a href="doc.html">documentation</a>?
|
||||
Here are some additional resources for help:
|
||||
<br>
|
||||
<h3>
|
||||
<font size=+1>Newsgroup and Mail Gateway</font></h3>
|
||||
The <a href="news:netscape.public.mozilla.jseng">netscape.public.mozilla.jseng</a>
|
||||
newsgroup answers questions about both Rhino and the C implementation of
|
||||
JavaScript. You can get to the newsgroup through a mail gateway. Send a
|
||||
message with the subject "subscribe" to <a href="mailto:mozilla-jseng-request@mozilla.org?subject=subscribe">mozilla-jseng-request@mozilla.org</a>.
|
||||
To post messages, send mail to <a href="mailto:mozilla-jseng@mozilla.org">mozilla-jseng@mozilla.org</a>.
|
||||
To unsubscribe, mail with "unsubscribe" in the subject to <a href="mailto:mozilla-jseng-request@mozilla.org?subject=unsubscribe">mozilla-jseng-request@mozilla.org</a>.
|
||||
<p>
|
||||
To view archived messages, try <a href="http://groups.google.com/groups?q=netscape.public.mozilla.jseng&hl=en&lr=&safe=off&site=groups">Google groups</a> or
|
||||
other newsgroup services.
|
||||
<h3>
|
||||
Bug System</h3>
|
||||
Use <a href="http://bugzilla.mozilla.org/enter_bug.cgi?product=Rhino">Bugzilla</a>
|
||||
to enter bugs against Rhino. Note that Rhino has its own product category.
|
||||
<br>
|
||||
<h3>
|
||||
Module Owner</h3>
|
||||
The module owner, <script>document.write(owner());</script>
|
||||
, can
|
||||
be mailed for help as well, although he may copy his response to the newsgroup
|
||||
to help others.
|
||||
<p>
|
||||
<hr WIDTH="100%"><a href="index.html">back to top</a>
|
||||
<br>
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,45 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<title>Rhino History</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center><b><font size=+3>Rhino History</font></b></center>
|
||||
|
||||
<p>Rhino gets its name from the animal on the cover of the <a href="http://www.ora.com/">O'Reilly</a>
|
||||
book about JavaScript.
|
||||
<p>The Rhino project was started at Netscape in Fall 1997. At the time,
|
||||
Netscape was planning to produce a version of Navigator written entirely
|
||||
in Java and so it needed an implementation of JavaScript written in Java.
|
||||
When Netscape stopped work on "Javagator", as it was called, somehow Rhino
|
||||
escaped the axe (rumor had it that the executives "forgot" it existed).
|
||||
Since then, a couple of major companies (including Sun) have licensed Rhino
|
||||
for use in their products and paid Netscape to do so, allowing us to continue
|
||||
work on it. Now Rhino is planned to be part of several server products
|
||||
from Netscape as well.
|
||||
<p>Originally, Rhino compiled all JavaScript code to Java bytecodes in
|
||||
generated classfiles. This produced the best performance (often beating
|
||||
the C implementation of JavaScript when run on a JIT), but suffered from
|
||||
two faults. First, compilation time was long since generating Java bytecodes
|
||||
and loading the generated classes was a heavyweight process. Also, the
|
||||
implementation effectively leaked memory since most JVMs don't really collect
|
||||
unused classes or the strings that are interned as a result of loading
|
||||
a class file.
|
||||
<p>So in Fall of 1998, Rhino added an interpretive mode. The classfile
|
||||
generation code was moved to an optional, dynamically-loaded package. Compilation
|
||||
is faster and when scripts are no longer in use they can be collected like
|
||||
any other Java object.
|
||||
<p>Rhino was released to mozilla.org in April of 1998. Originally Rhino
|
||||
classfile generation had been held back from release. However the licensees
|
||||
of Rhino have now agreed to release all of Rhino to open source, including
|
||||
class file generation. Since its release to open source, Rhino has found
|
||||
a variety of <a href="users.html">uses</a> and an increasing
|
||||
number of people have contributed to the code.
|
||||
<p>
|
||||
<hr WIDTH="100%"><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,75 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java, Mozilla">
|
||||
<title>Rhino - JavaScript for Java</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Rhino: JavaScript for Java</h1></center>
|
||||
|
||||
<center><img SRC="rhino50.jpg" height=200 width=398></center>
|
||||
|
||||
<hr WIDTH="100%">Rhino is an open-source implementation of JavaScript written
|
||||
entirely in Java. It is typically embedded into Java applications to provide
|
||||
scripting to end users.
|
||||
<table WIDTH="100%" >
|
||||
<tr>
|
||||
<td>
|
||||
<div align=right><b><a href="download.html">Downloads</a></b></div>
|
||||
</td>
|
||||
|
||||
<td>How to get source and binaries.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<div align=right><b><a href="doc.html">Documentation</a></b></div>
|
||||
</td>
|
||||
|
||||
<td>Information on Rhino for script writers and embedders.</td>
|
||||
</tr>
|
||||
|
||||
<!--
|
||||
<tr>
|
||||
<td>
|
||||
<div align=right><b><a href="users.html">Users</a></b></div>
|
||||
</td>
|
||||
|
||||
<td>How people are using Rhino.</td>
|
||||
</tr>
|
||||
-->
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<div align=right><b><a href="history.html">History</a></b></div>
|
||||
</td>
|
||||
|
||||
<td>The ancestry of the beast.</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<div align=right><b><a href="help.html">Help</a></b></div>
|
||||
</td>
|
||||
|
||||
<td>Some resources if you get stuck.</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<hr WIDTH="100%"><font size=-1>Module owner </font><script src="owner.js"></script>
|
||||
<script>document.write(owner());</script>
|
||||
|
||||
<br><font size=-1>Rhino image courtesy of Paul Houle.</font><!---
|
||||
Add reference to
|
||||
http://www.javaworld.com/jw-08-1999/jw-08-howto.html
|
||||
and
|
||||
http://www.javaworld.com/javaworld/jw-09-1999/jw-09-howto.html
|
||||
--->
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,66 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.6 [en] (WinNT; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Followup to JavaOne</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Followup to JavaOne session on Rhino</h1></center>
|
||||
This page is intended to follow up on the <a href="http://www.javasoft.com/javaone/">JavaOne</a>
|
||||
session on <a href="http://industry.java.sun.com/javaone/99/event/0,1768,629,00.html">"Rhino:
|
||||
JavaScript for the Java Platform"</a>. I hope it will be useful whether
|
||||
or not you actually attended the talk.
|
||||
<br>
|
||||
<h2>
|
||||
Slides</h2>
|
||||
<a href="http://industry.java.sun.com/javaone/99/pdfs/e629.pdf">Slides</a>
|
||||
(PDF file, 1112246 bytes) can be downloaded from Sun's site.
|
||||
<br>
|
||||
<br>
|
||||
<h2>
|
||||
More on Q & A</h2>
|
||||
Following the talk there was an excellent question and answer session where
|
||||
many attendees asked good questions and offered useful suggestions. I'll
|
||||
follow up on some of those here. I'll start a thread on the newsgroup <a href="news://news.mozilla.org/netscape.public.mozilla.jseng">netscape.public.mozilla.jseng</a>
|
||||
so people can ask addition questions or comments there.
|
||||
<h3>
|
||||
Java classes visible to scripts</h3>
|
||||
One attendee raised the point that many embeddings may not want scripts
|
||||
to be able to access all Java classes. This is an excellent point, and
|
||||
I've implemented an addition to the <a href="../js/rhino/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
|
||||
class that allows embedders to choose which classes are exposed to scripts.
|
||||
<h3>
|
||||
Easier "importing" of Java classes</h3>
|
||||
Another attendee suggested that the current method of referring to Java
|
||||
classes (like <tt>java.lang.String</tt> or <tt>Packages.org.mozilla.javascript.Context</tt>)
|
||||
could be improved. I've implemented a set of changes that make importing
|
||||
easier, but I'm not convinced that adding them is the right thing to do
|
||||
due to some drawbacks.
|
||||
<p>To see what I've done, take a look at the javadoc for the <a href="../js/rhino/org/mozilla/javascript/ImporterTopLevel.html">ImporterTopLevel</a>
|
||||
class. You'll see that it's now possible to make function calls to "import"
|
||||
Java classes so that they can be referred to without qualification. I didn't
|
||||
use the word "import" because that's a keyword in JavaScript.
|
||||
<p>There are a few drawbacks to this implemenation. First, there is a runtime
|
||||
cost associated with every lookup of a top-level variable. The problem
|
||||
is that it's not possible to use the Java runtime to determine the set
|
||||
of classes from a given package. Instead, importing the package "java.util"
|
||||
saves the package name in a special list and every access to the global
|
||||
scope that fails to find a matching variable causes the runtime to see
|
||||
if there is a class by that name in the "java.util" package. Even for lookups
|
||||
that succeed there is an additional method call.
|
||||
<p>Another drawback to this implementation is namespace pollution: now
|
||||
"importClass" and "importPackage" have special meaning. It's still possible
|
||||
to substitute your own variables for these functions, but it's still possible
|
||||
that program behavior could change.
|
||||
<p>So I'm interested in people's opinion: Is this benefit worth the costs?
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,82 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Compiler</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
JavaScript Compiler</h1></center>
|
||||
The JavaScript compiler translates JavaScript source into Java class files.
|
||||
The resulting Java class files can then be loaded and executed at another
|
||||
time, providing a convenient method for transfering JavaScript, and for
|
||||
avoiding translation cost.
|
||||
<p>Note that the top-level functions available to the shell (such as <tt>print</tt>)
|
||||
are <i>not</i> available to compiled scripts when they are run outside
|
||||
the shell.
|
||||
<br>
|
||||
<h2>
|
||||
Invoking the Compiler</h2>
|
||||
<tt>java org.mozilla.javascript.tools.jsc.Main</tt> [<i>options</i>] <i>file1</i><tt>.js</tt>
|
||||
[<i>file2</i><tt>.js</tt>...]
|
||||
<p>where <i>options</i> are:
|
||||
<p><tt>-extends <i>java-class-name</i></tt>
|
||||
<blockquote>Specifies that a java class extending the Java class <i>java-class-name</i>
|
||||
should be generated from the incoming JavaScript source file. Each global
|
||||
function in the source file is made a method of the generated class, overriding
|
||||
any methods in the base class by the same name.</blockquote>
|
||||
<tt>-implements <i>java-intf-name</i></tt>
|
||||
<blockquote>Specifies that a java class implementing the Java interface
|
||||
<i><tt>java-intf-name</tt></i>
|
||||
should be generated from the incoming JavaScript source file. Each global
|
||||
function in the source file is made a method of the generated class, implementing
|
||||
any methods in the interface by the same name.</blockquote>
|
||||
<tt>-debug</tt>
|
||||
<br><tt>-g</tt>
|
||||
<ul>Specifies that debug information should be generated. May not be combined
|
||||
with optimization at an <i>optLevel</i> greater than zero.</ul>
|
||||
<tt>-nosource</tt>
|
||||
<ul>Does not save the source in the class file. Functions and scripts compiled
|
||||
this way cannot be decompiled. This option can be used to avoid distributing
|
||||
source or simply to save space in the resulting class file.</ul>
|
||||
<tt>-o </tt><i>outputFile</i>
|
||||
<ul>Writes the class file to the given file (which should end in <tt>.class</tt>).
|
||||
The string <i>outputFile</i> must be a writable filename.</ul>
|
||||
<tt>-opt </tt><i>optLevel</i>
|
||||
<br><tt>-O</tt> <i>optLevel</i>
|
||||
<ul>Optimizes at level <i>optLevel</i>, which must be an integer between
|
||||
-1 and 9. See <a href="opt.html">Optimization</a> for more details. If
|
||||
<i>optLevel</i>
|
||||
is greater than zero, <tt>-debug</tt> may not be specified.</ul>
|
||||
<tt>-package</tt> <i>packageName</i>
|
||||
<ul>Specifies the package to generate the class into. The string <i>packageName</i>
|
||||
must be composed of valid identifier characters optionally separated by
|
||||
periods.</ul>
|
||||
<tt>-version </tt><i>versionNumber</i>
|
||||
<ul>Specifies the language version to compile with. The string <i>versionNumber</i>
|
||||
must be one of <tt>100</tt>, <tt>110</tt>, <tt>120</tt>, <tt>130</tt>,
|
||||
or <tt>140</tt>. See <a href="overview.html#versions">JavaScript Language
|
||||
Versions</a> for more information on language versions.</ul>
|
||||
|
||||
<h2>
|
||||
Examples</h2>
|
||||
<tt>$ cat test.js</tt>
|
||||
<br><tt>java.lang.System.out.println("hi, mom!");</tt>
|
||||
<br><tt>$ java org.mozilla.javascript.tools.jsc.Main test.js</tt>
|
||||
<br><tt>$ ls *.class</tt>
|
||||
<br><tt>test.class</tt>
|
||||
<br><tt>$ java test</tt>
|
||||
<br><tt>hi, mom!</tt>
|
||||
<p><tt>$ java org.mozilla.javascript.tools.jsc.Main -extends java.applet.Applet
|
||||
\</tt>
|
||||
<br><tt> -implements java.lang.Runnable NervousText.js</tt>
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 60 KiB |
@@ -1,86 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Requirements and Limitations</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Requirements and Limitations</h1></center>
|
||||
|
||||
<h2>
|
||||
<b>Requirements</b></h2>
|
||||
Rhino requires version 1.1 or greater of Java.
|
||||
<p>To use the JavaAdapter feature or an optimization level of 0 or greater,
|
||||
Rhino must be running under a security manager that allows the definition
|
||||
of class loaders.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<h2>
|
||||
<b>Limitations</b></h2>
|
||||
|
||||
<h3>
|
||||
<b>Platforms and </b>JITs</h3>
|
||||
Many platforms and JREs have problems converting decimal numbers to and
|
||||
from strings. These errors are usually boundary case errors and will show
|
||||
up as test failures in section 7.7.3.
|
||||
<p>Windows versions of the Symantec JIT prior to 3.00.029(i) will report
|
||||
internal errors for some generated class files.
|
||||
<p>On the Symantec JIT and the AIX JVM, accessing a static field of a class
|
||||
that has not yet loaded may not give the correct value of the field. For
|
||||
example, accessing
|
||||
<tt>java.io.File.separatorChar</tt> before <tt>java.io.File</tt>
|
||||
has been loaded will return a value of 0. (This is a bug in the JIT; accessing
|
||||
the field should cause the class to be loaded.)
|
||||
<p>The AIX Java version "JDK 1.1.6 IBM build a116-19980924 (JIT enabled:
|
||||
jitc)" core dumps running several classes generated by Rhino. It also has
|
||||
errors in java.lang.Math.pow that are reflected as failures in the JavaScript
|
||||
Math object's pow method.
|
||||
<p>IBM Java for Linux version "JDK 1.1.8 IBM build l118-19991013 (JIT enabled:
|
||||
jitc)" has errors in java.lang.Math.pow that are reflected as test failures
|
||||
in the JavaScript Math object's pow method.
|
||||
<p>Solaris JDK 1.1.6 has errors in java.lang.Math.atan2 that are reflected
|
||||
as test failures in the JavaScript Math object's atan2 method.
|
||||
<br>
|
||||
<h3>
|
||||
<b>LiveConnect</b></h3>
|
||||
If a JavaObject's field's name collides with that of a method, the value
|
||||
of that field is retrieved lazily, and can be counter-intuitively affected
|
||||
by later assignments:
|
||||
<blockquote><tt>javaObj.fieldAndMethod = 5;</tt>
|
||||
<br><tt>var field = javaObj.fieldAndMethod;</tt>
|
||||
<br><tt>javaObj.fieldAndMethod = 7;</tt>
|
||||
<br><tt>// now, field == 7</tt></blockquote>
|
||||
You can work around this by forcing the field value to be converted to
|
||||
a JavaScript type when you take its value:
|
||||
<blockquote><tt>javaObj.fieldAndMethod = 5;</tt>
|
||||
<br><tt>var field = javaObj.fieldAndMethod + 0; // force conversion now</tt>
|
||||
<br><tt>javaObj.fieldAndMethod = 7;</tt>
|
||||
<br><tt>// now, field == 5</tt></blockquote>
|
||||
|
||||
<h3>
|
||||
<b>JSObject</b></h3>
|
||||
Rhino does NOT support the <tt>netscape.javascript.JSObject</tt> class.
|
||||
<br>
|
||||
<h3>
|
||||
<b>Date object</b></h3>
|
||||
The JavaScript Date object depends on time facilities of the underlying
|
||||
Java runtime to determine daylight savings time dates. Earlier JRE versions
|
||||
may report a date for the daylight savings changeover that is a week off.
|
||||
JRE 1.1.6 reports the correct date.
|
||||
<p>Under the 1.1.6 JRE, evaluating <tt>(new Date(1998, 9, 25, 2)).toString()</tt>
|
||||
returns:
|
||||
<pre> Sun Oct 25 02:00:00 GMT-0800 (PST) 1998</pre>
|
||||
Earlier versions may return:
|
||||
<pre> Sun Oct 25 02:00:00 GMT-0700 (PDT) 1998</pre>
|
||||
(the JRE doesn't report the changeover until Nov. 1.)
|
||||
<p>The Microsoft SDK 3.1 for Java also exhibits this problem.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="rhino.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 19 KiB |
@@ -1,68 +0,0 @@
|
||||
<HTML>
|
||||
<HEAD>
|
||||
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
|
||||
<META NAME="Author" CONTENT="Norris Boyd">
|
||||
<META NAME="GENERATOR" CONTENT="Mozilla/4.05 [en] (WinNT; U) [Netscape]">
|
||||
<TITLE>Optimization</TITLE>
|
||||
</HEAD>
|
||||
<BODY BGCOLOR="#FFFFFF">
|
||||
|
||||
<CENTER>
|
||||
<H1>
|
||||
Optimization</H1></CENTER>
|
||||
|
||||
<H2>
|
||||
Optimization settings</H2>
|
||||
<P>The currently supported optimization settings are:</P>
|
||||
|
||||
<P><B>-1</B>
|
||||
|
||||
<P><B></B>Interpretive mode is always
|
||||
used. The compilation time is minimized at the expense of runtime performance.
|
||||
No class files are generated, which may improve memory usage depending on your
|
||||
system.
|
||||
<p>
|
||||
If the optimization package is not available, then optimization acts as if it is always -1.
|
||||
</P>
|
||||
|
||||
<P><B>0</B>
|
||||
|
||||
<P><B></B>No optimizations are
|
||||
performed. The bytecode compiler runs fastest in this mode, but the generated byte code
|
||||
is less efficient.</P>
|
||||
|
||||
<P><B>1-9</B>
|
||||
|
||||
<P>All optimizations are performed. Simple data & type
|
||||
flow analysis is performed to determine which JavaScript variables can be
|
||||
allocated to Java VM registers, and which variables are used only as Numbers.
|
||||
Local common sub-expressions are collapsed (currently this only happens for
|
||||
property lookup, but in the future more expressions may be optimized). All local
|
||||
variables and parameters are allocated to Java VM registers. Function call
|
||||
targets are speculatively pre-cached (based on the name used in the source) so
|
||||
that dispatching can be direct, pending runtime confirmation of the actual
|
||||
target. Arguments are passed as Object/Number pairs to reduce conversion
|
||||
overhead.</P>
|
||||
|
||||
<P>Note:
|
||||
<OL>
|
||||
<LI>
|
||||
Some language features (indirect calls to eval, use
|
||||
of the arguments property of function objects) were previously not supported
|
||||
in higher optimization levels. These features have been removed from the
|
||||
language in ECMA, so higher optimization levels are now conformant.
|
||||
|
||||
<LI>
|
||||
Future versions may allocate more aggressive
|
||||
optimizations to higher optimization levels. For compatibility with future
|
||||
versions, use level 1. For maximal optimization, use level 9, but retest
|
||||
your application when upgrading to new versions.</LI>
|
||||
</OL>
|
||||
|
||||
|
||||
<P>
|
||||
<HR WIDTH="100%">
|
||||
<BR><A HREF="index.html">back to top</A>
|
||||
<br>
|
||||
</BODY>
|
||||
</HTML>
|
||||
@@ -1,149 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Overview</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Rhino Overview</h1></center>
|
||||
|
||||
<h3>
|
||||
Overview of Rhino</h3>
|
||||
Most people who have used JavaScript before have done so by adding scripts
|
||||
to their HTML web pages. However, Rhino is an implementation of the core
|
||||
language only and doesn't contain objects or methods for manipulating HTML
|
||||
documents.
|
||||
<p>Rhino contains
|
||||
<ul>
|
||||
<li>
|
||||
All the features of JavaScript 1.5</li>
|
||||
|
||||
<li>
|
||||
<a href="http://developer.netscape.com/library/documentation/communicator/jsguide4/livecon.htm">LiveConnect</a>
|
||||
-- allows direct scripting of Java</li>
|
||||
|
||||
<li>
|
||||
A JavaScript shell for executing JavaScript scripts</li>
|
||||
|
||||
<li>
|
||||
A JavaScript compiler to transform JavaScript source files into Java class
|
||||
files</li>
|
||||
</ul>
|
||||
|
||||
<h3>
|
||||
Language</h3>
|
||||
The JavaScript language itself is standardized by Standard ECMA-262 <i>ECMAScript:
|
||||
A general purpose, cross-platform programming language</i>. Rhino 1.5 implements
|
||||
JavaScript 1.5, which conforms to Edition 3 of the Standard. The Standard
|
||||
may be <a href="http://www.ecma.ch/stand/ecma-262.htm">downloaded</a> or
|
||||
obtained by mail from ECMA, 114 Rue du Rhône, CH1204 Geneva, Switzerland.
|
||||
<p>In addition, Rhino has implemented JavaAdapters, which allows JavaScript
|
||||
to implement any Java interface or extend any Java class with a JavaScript
|
||||
object. See the <tt>enum.js</tt> example for more information.
|
||||
<p>Numerous books and tutorials on JavaScript are available.
|
||||
<br>
|
||||
<br>
|
||||
<h3>
|
||||
Deprecated Language Features</h3>
|
||||
Several language features introduced in JavaScript 1.2 are now deprecated.
|
||||
These features allow "computational reflection": that is, the ability for
|
||||
a script to determine and influence aspects of the way it is evaluated.
|
||||
These features are generally not broadly useful, yet they impose significant
|
||||
constraints on implementations that hamper or prevent optimization. The
|
||||
deprecated features are the <tt>__proto__</tt> and <tt>__parent__</tt>
|
||||
properties, and the constructors <tt>With</tt>, <tt>Closure</tt>, and <tt>Call</tt>.
|
||||
Attempts to invoke these constructors with the language version 1.4 will
|
||||
result in an error. For other versions, a warning will be generated.
|
||||
<br>
|
||||
<br>
|
||||
<h3>
|
||||
Internationalization</h3>
|
||||
The messages reported by the JavaScript engine are by default retrieved
|
||||
from the property file <tt>org/mozilla/javascript/resources/Messages.properties</tt>.
|
||||
If other properties files with extensions corresponding to the current
|
||||
locale exist, they will be used instead.
|
||||
<br>
|
||||
<br>
|
||||
<h3>
|
||||
<a NAME="versions"></a>JavaScript Language Versions</h3>
|
||||
Some behavior in the JavaScript engine is dependent on the language version.
|
||||
In browser embeddings, this language version is selected using the LANGUAGE
|
||||
attribute of the SCRIPT tag with values such as "JavaScript1.2".
|
||||
<p>Version 1.3 and greater are ECMA conformant.
|
||||
<p><b>Operators <tt>==</tt> and <tt>!=</tt></b>
|
||||
<p>Version 1.2 only uses strict equality for the == and != operators. In
|
||||
version 1.3 and greater, == and != have the same meanings as ECMA. The
|
||||
operators === and !== use strict equality in all versions.
|
||||
<p><b>ToBoolean</b>
|
||||
<p><tt>Boolean(new Boolean(false))</tt> is false for all versions before
|
||||
1.3. It is true (and thus ECMA conformant) for version 1.3 and greater.
|
||||
<p><b>Array.prototype.toString and Object.prototype.toString</b>
|
||||
<p>Version 1.2 only returns array or object literal notation ("[1,2,3]"
|
||||
or "{a:1, b:2}" for example). In version 1.3 and greater these functions
|
||||
are ECMA conformant.
|
||||
<p><b>Array constructor</b>
|
||||
<p><tt>Array(i)</tt> for a number argument <tt>i</tt> constructs an array
|
||||
with a single element equal to <tt>i</tt> for version 1.2 only. Otherwise
|
||||
the ECMA conformant version is used (an array is constructed with no elements
|
||||
but with length property equal to <tt>i</tt>).
|
||||
<p><b>String.prototype.substring</b>
|
||||
<p>For version 1.2 only, the two arguments are not swapped if the first
|
||||
argument is less than the second one. All other versions are ECMA compliant.
|
||||
<p><b>String.prototype.split</b>
|
||||
<p>For version 1.2 only, split performs the Perl4 special case when given
|
||||
a single space character as an argument (skips leading whitespace, and
|
||||
splits on whitespace). All other versions split on the space character
|
||||
proper as specified by ECMA.
|
||||
<br>
|
||||
<br>
|
||||
<h3>
|
||||
Security</h3>
|
||||
The security features in Rhino provide the ability to track the origin
|
||||
of a piece of code (and any pieces of code that it may in turn generate).
|
||||
These features allow for the implementation of a traditional URL-based
|
||||
security policy for JavaScript as in Netscape Navigator. Embeddings that
|
||||
trust the JavaScript code they execute may ignore the security features.
|
||||
<p>Embeddings that run untrusted JavaScript code must do two things to
|
||||
enable the security features. First, every <tt>Context</tt> that is created
|
||||
must be supplied an instance of an object that implements the <tt>SecuritySupport</tt>
|
||||
interface. This will provide Rhino the support functionality it needs to
|
||||
perform security-related tasks.
|
||||
<p>Second, the value of the property <tt>security.requireSecurityDomain</tt>
|
||||
should be changed to <tt>true</tt> in the resource bundle <tt>org.mozilla.javascript.resources.Security</tt>.
|
||||
The value of this property can be determined at runtime by calling the
|
||||
<tt>isSecurityDomainRequired</tt>
|
||||
method of <tt>Context</tt>. Setting this property to true requires that
|
||||
any calls that compile or evaluate JavaScript must supply a security domain
|
||||
object of any object type that will be used to identify JavaScript code.
|
||||
In a typical client embedding, this object might be a string with the URL
|
||||
of the server that supplied the script, or an object that contains a representation
|
||||
of the signers of a piece of code for certificate-based security policies.
|
||||
<p>When JavaScript code attempts a restricted action, the security domain
|
||||
can be retrieved in the following manner. The class context should be obtained
|
||||
from the security manager (see <tt>java.lang.SecurityManager.getClassContext()</tt>).
|
||||
Then, the class of the code that called to request the restricted action
|
||||
can be obtained by looking an appropriate index into the class context
|
||||
array. If the caller is JavaScript the class obtained may be one of two
|
||||
types. First, it may be the class of the interpreter if interpretive mode
|
||||
is in effect. Second, it may be a generated class if classfile generation
|
||||
is supported. An embedding can distinguish the two cases by calling <tt>isInterpreterClass()</tt>
|
||||
in the <tt>Context</tt> class. If it is the interpreter class, call the
|
||||
getInterpreterSecurityDomain() method of Context to obtain the security
|
||||
domain of the currently executing interpreted script or function. Otherwise,
|
||||
it must be a generated class, and an embedding can call <tt>getSecurityDomain()</tt>
|
||||
in the class implementing
|
||||
<tt>SecuritySupport</tt>. When the class was
|
||||
defined and loaded, the appropriate security domain was associated with
|
||||
it, and can be retrieved by calling this method. Once the security domain
|
||||
has been determined, an embedding can perform whatever checks are appropriate
|
||||
to determine whether access should be allowed.
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,3 +0,0 @@
|
||||
function owner() {
|
||||
return '<a href="mailto:nboyd'+'@'+ 'atg.com">Norris Boyd</a>'
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.5 [en]C-NSCP (WinNT; I) [Netscape]">
|
||||
<title>Performance Hints</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Performance Hints</h1></center>
|
||||
<h3>
|
||||
<tt>var</tt> Statements</h3>Use <tt>var</tt> statements when possible. Not only is it good
|
||||
programming practice, it can speed up your code by allowing the compiler to
|
||||
generate special code to access the variables. For example, you could rewrite
|
||||
<p><tt>function sum(a) {</tt>
|
||||
<br><tt> result = 0;</tt>
|
||||
<br><tt> for (i=0; i <
|
||||
a.length; i++)</tt>
|
||||
<br><tt> result += a[i];</tt>
|
||||
<br><tt> return result;</tt>
|
||||
<br><tt>}</tt>
|
||||
<p>as
|
||||
<p><tt>function sum(a) {</tt>
|
||||
<br><tt> var result = 0;</tt>
|
||||
<br><tt> for (var i=0; i
|
||||
< a.length; i++)</tt>
|
||||
<br><tt> result += a[i];</tt>
|
||||
<br><tt> return result;</tt>
|
||||
<br><tt>}</tt>
|
||||
<p>This is not equivalent code because the second version does
|
||||
not modify global variables <tt>result</tt> and <tt>i</tt>. However, if you don't intend for any other function to
|
||||
access these variables, then storing them globally is probably wrong anyway
|
||||
(what if you called another function that had a loop like the one in <tt>sum</tt>!).
|
||||
<br>
|
||||
<h3>
|
||||
Arrays</h3>Use the forms of the Array constructor that
|
||||
specify a size or take a list of initial elements. For example, the code
|
||||
<p><tt>var a = new Array();</tt>
|
||||
<br><tt>for (var i=0; i < n; i++)</tt>
|
||||
<br><tt> a[i] = i;</tt>
|
||||
<p>could be sped up by changing the constructor call to <tt>new Array(n)</tt>. A constructor call like that indicates to
|
||||
the runtime that a Java array should be used for the first <i>n</i> entries of the array. Similarly,
|
||||
<tt>new
|
||||
Array("a", "b", "c")</tt> or <tt>["a", "b", "c"]</tt> will cause a 3-element
|
||||
Java array to be allocated to hold the contents of the JavaScript array.
|
||||
<br>
|
||||
<br>
|
||||
<h3>
|
||||
<tt>eval</tt> and <tt>new Function</tt></h3>Avoid calling <tt>eval</tt> when
|
||||
possible. Calls to <tt>eval</tt> are slow because the script
|
||||
being executed must be compiled. Constructing a new function object can be slow
|
||||
for the same reason, while function expressions are more efficient because the
|
||||
function can be compiled. For example, the code
|
||||
<p><tt>function MyObject(a) {</tt>
|
||||
<br><tt> this.s = a;</tt>
|
||||
<br><tt> this.toString = new
|
||||
Function("return this.s");</tt>
|
||||
<br><tt>}</tt>
|
||||
<p>could be written more efficiently as
|
||||
<p><tt>function MyObject(a) {</tt>
|
||||
<br><tt> this.s = a;</tt>
|
||||
<br><tt> this.toString =
|
||||
function () { return this.s }</tt>
|
||||
<br><tt>}</tt>
|
||||
<p>Beginning with Rhino 1.4 Release 2, code
|
||||
passed to eval and new Function will be interpreted rather than compiled to
|
||||
class files.
|
||||
<br> </p>
|
||||
<h3>
|
||||
with</h3>Using the <tt>with</tt>
|
||||
statement prevents the compiler from generating code for fast access to local
|
||||
variables. You're probably better off explicitly accessing any properties of the
|
||||
object.
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
<br>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,162 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>What's New in Rhino 1.5</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
What's New in Rhino 1.5 Release 1</h1></center>
|
||||
|
||||
<h2>
|
||||
ECMA 262 Edition 3 Conformance</h2>
|
||||
Rhino 1.5 implements JavaScript 1.5, which conforms to ECMA 262 Edition
|
||||
3 (sometimes referred to as "ECMAScript"). Edition 3 standardized several
|
||||
features of JavaScript that were present in JavaScript 1.4, including:
|
||||
<ul>
|
||||
<li>
|
||||
regular expressions</li>
|
||||
|
||||
<li>
|
||||
<tt>switch</tt> statements</li>
|
||||
|
||||
<li>
|
||||
<tt>do</tt>...<tt>while</tt> loops</li>
|
||||
|
||||
<li>
|
||||
statement labels and labelled <tt>break</tt> and <tt>continue</tt></li>
|
||||
|
||||
<li>
|
||||
object literals</li>
|
||||
|
||||
<li>
|
||||
nested functions</li>
|
||||
|
||||
<li>
|
||||
exception handling</li>
|
||||
|
||||
<li>
|
||||
the <tt>instanceof</tt> operator</li>
|
||||
|
||||
<li>
|
||||
the <tt>in</tt> operator</li>
|
||||
</ul>
|
||||
In addition, new features were added to Edition 3 and JavaScript 1.5, including:
|
||||
<ul>
|
||||
<li>
|
||||
Perl 5 regular expressions, including operators like greedy quantifiers</li>
|
||||
|
||||
<li>
|
||||
errors as exceptions</li>
|
||||
|
||||
<li>
|
||||
number formatting (<tt>Number.prototype.toFixed</tt>, <tt>Number.prototype.toExponential</tt>,
|
||||
and <tt>Number.prototype.toGeneral</tt>)</li>
|
||||
</ul>
|
||||
|
||||
<h2>
|
||||
Changes since Rhino 1.4 Release 3</h2>
|
||||
Other significant changes to Rhino since the initial release to open source
|
||||
(1.4 Release 3) are listed below. Bug fixes won't be mentioned here, just
|
||||
API changes or significant functionality changes.
|
||||
<h3>
|
||||
Compilation mode</h3>
|
||||
Rhino has two modes of execution available. Interpretive mode has an interpreter
|
||||
loop implemented in Java. Compilation mode compiles JavaScript code to
|
||||
Java bytecodes in class files. This compilation can be done as part of
|
||||
script evaluation using the same APIs already available for the interpreter,
|
||||
or in a separate compile-time step. The code for the interpreter is located
|
||||
in the <tt>org.mozilla.javascript.optimizer</tt> package.
|
||||
<br>
|
||||
<h3>
|
||||
JavaScript Compiler</h3>
|
||||
The distribution now contains an extra class that can be invoked from the
|
||||
command line. This is <tt>jsc</tt>, the JavaScript compiler. This tool
|
||||
can be used to create Java classes from JavaScript. Options exist to allow
|
||||
creation of Java classes that implement arbitrary interfaces and extend
|
||||
arbitrary base classes, allowing JavaScript scripts to implement important
|
||||
protocols like applets and servlets. See <a href="http://www.mozilla.org/rhino/jsc.html">http://www.mozilla.org/rhino/jsc.html</a>.
|
||||
<br>
|
||||
<h3>
|
||||
LiveConnect 3</h3>
|
||||
Rhino now supports the LiveConnect 3 specification, or LC3. The most notable
|
||||
change is support for overloaded method resolution. See <a href="http://www.mozilla.org/js/liveconnect/lc3_proposal.html">LiveConnect
|
||||
Release 3 Goals/Features</a>.
|
||||
<br>
|
||||
<h3>
|
||||
JavaBeans properties reflected as Java properties</h3>
|
||||
Java classes with getFoo/setFoo methods will have a "foo" property in the
|
||||
JavaScript reflection. Boolean methods are also reflected.
|
||||
<br>
|
||||
<h3>
|
||||
Dynamic scope support</h3>
|
||||
Rhino 1.5 implements support for dynamic scopes, which are particularly
|
||||
useful for multithreaded environments like server embeddings.
|
||||
<br>
|
||||
<h3>
|
||||
New semantics for <tt>ScriptableObject.defineClass</tt></h3>
|
||||
The old rules for defining JavaScript objects using a Java class were getting
|
||||
baroque. Those rules are still supported, but a cleaner definition is now
|
||||
supported. See the <a href="http://www.mozilla.org/js/rhino/org/mozilla/javascript/ScriptableObject.html#defineClass(org.mozilla.javascript.Scriptable, java.lang.Class)">javadoc</a>
|
||||
for details.
|
||||
<br>
|
||||
<h3>
|
||||
Support for the Java 2 <tt>-jar</tt> option</h3>
|
||||
It's now possible to start the shell using the new <tt>-jar</tt> option
|
||||
in Java 2.
|
||||
<br>
|
||||
<h3>
|
||||
Shell changes</h3>
|
||||
Two changes here: addition of the "environment" and "history" top-level
|
||||
variables.
|
||||
<br>
|
||||
<h3>
|
||||
Java classes visible to scripts</h3>
|
||||
An attendee at JavaOne raised the point that many embeddings may not want
|
||||
scripts to be able to access all Java classes. This is an excellent point,
|
||||
and I've implemented an addition to the <a href="../js/rhino/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
|
||||
interface that allows embedders to choose which classes are exposed to
|
||||
scripts.
|
||||
<br>
|
||||
<h3>
|
||||
SecuritySupport and JavaAdapter</h3>
|
||||
Andrew Wason pointed a problem with the new JavaAdapter feature (which
|
||||
allows JavaScript objects to implement arbitrary Java interfaces by generating
|
||||
class files). It didn't support the <a href="../js/rhino/org/mozilla/javascript/SecuritySupport.html">SecuritySupport</a>
|
||||
interface, which allows Rhino to delegate the creation of classes from
|
||||
byte arrays to a routine provided by the embedding. This ability is important
|
||||
from a security standpoint because class creation is considered a privileged
|
||||
action.
|
||||
<p>I've checked in changes that fix this problem. If a SecuritySupport
|
||||
class is specified when a Context is created, uses of JavaAdapter will
|
||||
will delegate class creation to the SecuritySupport class.
|
||||
<br>
|
||||
<h3>
|
||||
Context.exit()</h3>
|
||||
Context.exit() has been changed from an instance method to a static method.
|
||||
This makes it match the Context.enter() method, which is also static. See
|
||||
the <a href="http://www.mozilla.org/js/rhino/org/mozilla/javascript/Context.html#exit()">javadoc</a>
|
||||
for more information on its operation.
|
||||
<br>
|
||||
<h3>
|
||||
Context.enter(Context)</h3>
|
||||
A new overloaded form of Context.enter has been added. Without the addition
|
||||
of this method it was not possible to attach an existing context to a thread.
|
||||
See the <a href="http://www.mozilla.org/js/rhino/org/mozilla/javascript/Context.html#enter(org.mozilla.javascript.Context)">javadoc</a>
|
||||
for more information on its operation.
|
||||
<br>
|
||||
<h3>
|
||||
Listeners for Context</h3>
|
||||
Context now supports property change listeners for a couple of its properties.
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><br>
|
||||
<a href="index.html">back to top</a></h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,84 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Rhino 1.5 Release 2</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
What's New in Rhino 1.5 Release 2</h1></center>
|
||||
This is a log of significant changes since the release of Rhino 1.5 Release
|
||||
1.
|
||||
<br>
|
||||
<h2>
|
||||
Graphical debugger</h2>
|
||||
Thanks to a contribution by Christopher Oliver, Rhino now has a graphical
|
||||
debugger. See <a href="debugger.html">Rhino Debugger</a> for more details.
|
||||
<br>
|
||||
<h2>
|
||||
Footprint reductions</h2>
|
||||
Igor Bukanov has provided a wealth of changes to reduce the number and
|
||||
size of objects required by Rhino. In particular, he introduced a new way
|
||||
to represent the built-in objects like Date and RegExp that reduces the
|
||||
amount of memory required and speeds up <tt>Context.initStandardObjects</tt>.
|
||||
<br>
|
||||
<h2>
|
||||
Interpreted mode performance improvements</h2>
|
||||
Igor Bukanov also made a number of improvements to interpreter mode performance.
|
||||
<br>
|
||||
<h2>
|
||||
JS/CORBA Adapter</h2>
|
||||
Matthias Radestock wrote a module that allows JavaScript code to interact
|
||||
with CORBA. See <a href="http://sourceforge.net/projects/jscorba">http://sourceforge.net/projects/jscorba</a>
|
||||
for more details.
|
||||
<br>
|
||||
<h2>
|
||||
Directory restructuring and Ant buildfile</h2>
|
||||
I've restructured the the Rhino directory and written an <a href="http://jakarta.apache.org/ant/index.html">Ant</a>
|
||||
buildfile. This should make building easier and more consistent with other
|
||||
open source Java projects.
|
||||
<br>
|
||||
<h2>
|
||||
FlattenedObject deprecated</h2>
|
||||
I wrote FlattenedObject to provide a means for dealing with JavaScript
|
||||
<br>objects in prototype chains. Where Scriptable defines the primitive
|
||||
<br>operations, FlattenedObject defines the aggregate operations of
|
||||
<br>manipulating properties that may be defined in an object or in an object
|
||||
<br>reachable by a succession of getPrototype calls.
|
||||
<p>However, I now believe that I designed FlattenedObject poorly. Perhaps
|
||||
<br>it should have been a clue that I was never satisfied with the name:
|
||||
if
|
||||
<br>it's hard to express the name of the object it may mean the function
|
||||
the
|
||||
<br>object is supposed to fulfill is not well defined either. The problem
|
||||
is
|
||||
<br>that it is inefficient since it requires an extra object creation,
|
||||
and
|
||||
<br>balky because of that extra level of wrapping.
|
||||
<p>So I've checked in changes that deprecate FlattenedObject. I've
|
||||
<br>introduced new static methods in ScriptableObject (thanks to
|
||||
<br>beard@netscape.com for the idea) that replace the functionality. These
|
||||
<br>methods perform the get, put, and delete operations on a Scriptable
|
||||
<br>object passed in without the overhead of creating a new object.
|
||||
<h2>
|
||||
WrapHandler interface</h2>
|
||||
Embeddings that wish to provide their own custom wrappings for Java objects
|
||||
may implement this interface and
|
||||
<br>call Context.setWrapHandler. See WrapHandler javadoc.
|
||||
<br>
|
||||
<h2>
|
||||
ClassOutput interface</h2>
|
||||
An interface embedders can implement in order to control the placement
|
||||
of generated class bytecodes. See the javadoc.
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><br>
|
||||
<a href="index.html">back to top</a></h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,63 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]">
|
||||
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Change Log</title>
|
||||
</head>
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<center>
|
||||
<h1> Change Log for Significant Rhino Changes</h1>
|
||||
</center>
|
||||
This is a log of significant changes since the release of Rhino 1.5 Release
|
||||
2.
|
||||
<p> </p>
|
||||
<h3> </h3>
|
||||
<h3>Serialization</h3>
|
||||
See the <a href="serialization.html">serialization documentation</a>
|
||||
.<br>
|
||||
<br>
|
||||
<h3>Class writer API changes</h3>
|
||||
Courtesy of Kemal Bayram.<br>
|
||||
<br>
|
||||
"The biggest change I've made is the replacement of ClassOutput with<br>
|
||||
ClassRepository that has the single method:<br>
|
||||
<br>
|
||||
public boolean storeClass(String className, byte[] classBytes,<br>
|
||||
|
||||
boolean isTopLevel) throws IOException;<br>
|
||||
<br>
|
||||
This interface allows any arbitary storage method, such as a<br>
|
||||
Hashtable/Map. In addition it also allows you to specify whether a<br>
|
||||
class should be loaded, via returning true or false. You can still
|
||||
use<br>
|
||||
ClassOutput as I've coded an internal wrapper.<br>
|
||||
<br>
|
||||
With this interface it has also been possible to strip out the file<br>
|
||||
saving code from Codegen and OptClassNameHelper. The file<br>
|
||||
saving code is now an inner class FileClassRepository in Context. As<br>
|
||||
a consequence of this I've stripped out some methods from ClassNameHelper.<br>
|
||||
The resulting code is much more cleaner then before hand and everything<br>
|
||||
still works as per usual.<br>
|
||||
<br>
|
||||
Other small additions are:<br>
|
||||
o Annonymous functions are now named class$1 instead of class1<br>
|
||||
o get/setClassName added to ClassNameHelper exposed in Context.
|
||||
"<br>
|
||||
<br>
|
||||
<h3>Bunches of bug fixes and optimizations from Igor Bukanov and others</h3>
|
||||
See the CVS logs<br>
|
||||
<h3>
|
||||
<hr width="100%"><br>
|
||||
<a href="index.html">back to top</a>
|
||||
</h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 6.6 KiB |
@@ -1,138 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Runtime</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
The JavaScript Runtime</h1></center>
|
||||
|
||||
<h3>
|
||||
Interpretation</h3>
|
||||
Beginning with Rhino 1.4 Release 2, an interpretive mode is supported.
|
||||
When scripts are compiled in interpretive mode, an internal representation
|
||||
of the compiled form is created and stored rather than generating a Java
|
||||
class. Execution proceeds by evaluating this compiled form using support
|
||||
routines in Rhino.
|
||||
<h3>
|
||||
Compilation to Java Bytecodes</h3>
|
||||
For improved performance, Rhino may compile JavaScript scripts to Java
|
||||
bytecodes. The generated bytecodes in turn depend upon runtime support
|
||||
routines. Each JavaScript script or function is compiled to a separate
|
||||
class.
|
||||
<p>Compilation of JavaScript source to class files is supported. It is
|
||||
possible to specify the class files as well as the packages to generate
|
||||
into.
|
||||
<h3>
|
||||
Types and Values</h3>
|
||||
There are six fundamental types in JavaScript. These types are implemented
|
||||
with the following Java types and values:
|
||||
<br>
|
||||
<br>
|
||||
<center><table BORDER COLS=2 WIDTH="75%" >
|
||||
<tr>
|
||||
<td><i>JavaScript fundamental type</i></td>
|
||||
|
||||
<td><i>Java type</i></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Undefined</td>
|
||||
|
||||
<td>A singleton object defined by <tt>Context.getUndefinedType()</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Null</td>
|
||||
|
||||
<td><tt>null</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Boolean</td>
|
||||
|
||||
<td><tt>java.lang.Boolean</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Number</td>
|
||||
|
||||
<td><tt>java.lang.Number</tt>, that is, any of <tt>java.lang.Byte</tt>,<tt>
|
||||
java.lang.Short</tt>,<tt> java.lang.Integer</tt>,<tt> java.lang.Float</tt>,
|
||||
or <tt>java.lang.Double. Not java.lang.Long, since a double representation
|
||||
of a long may lose precision.</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>String</td>
|
||||
|
||||
<td><tt>java.lang.String</tt></td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>Object</td>
|
||||
|
||||
<td><tt>org.mozilla.javascript.Scriptable</tt></td>
|
||||
</tr>
|
||||
</table></center>
|
||||
|
||||
<p>In addition, ECMA refers to objects that implement [[Call]] as functions.
|
||||
These object types are represented by implementing the Function interface.
|
||||
<p>Since JavaScript is a dynamically typed language, the static Java type
|
||||
of a JavaScript value is <tt>java.lang.Object</tt>.
|
||||
<p>The behavior of the JavaScript engine is undefined if a value of any
|
||||
type other than the ones described above is introduced into JavaScript.
|
||||
(This caveat does not apply to scripts that use LiveConnect; the Java values
|
||||
are wrapped and unwrapped as appropriate to conform to the above type constraints.)
|
||||
<br>
|
||||
<h3>
|
||||
Property Access</h3>
|
||||
Properties in JavaScript objects may be accessed using either string or
|
||||
numeric identifiers. Conceptually, all accessors are converted to strings
|
||||
in order to perform the lookup of the property in the object. However,
|
||||
this is not the implementation used in practice because a number to string
|
||||
conversion is too expensive to be performed on every array access.
|
||||
<p>Instead, every property accessor method in <a href="org/mozilla/javascript/Scriptable.html">Scriptable</a>
|
||||
(<tt>has</tt>, <tt>get</tt>, <tt>set</tt>, <tt>remove</tt>, <tt>getAttributes</tt>,
|
||||
and <tt>setAttributes</tt>) has overloaded forms that take either a <tt>String</tt>
|
||||
or an <tt>int</tt> argument. It is the responsibility of the caller to
|
||||
invoke the appropriate overloaded form. For example, evaluating the expression
|
||||
<tt>obj["3"]</tt>
|
||||
will invoke the get(int, Scriptable) method even though the property name
|
||||
was presented in the script as a string. Similarly, values of numbers that
|
||||
do not fix in integers (like 1.1 and 0x100000000) must be converted to
|
||||
strings.
|
||||
<br>
|
||||
<h3>
|
||||
Defining Host Objects</h3>
|
||||
Host objects are JavaScript objects that provide special access to the
|
||||
host environment. For example, in a browser environment, the Window and
|
||||
Document objects are host objects.
|
||||
<p>The easiest way to define new host objects is by using <a href="org/mozilla/javascript/ScriptableObject.html#defineClass(org.mozilla.javascript.Scriptable, java.lang.Class)">ScriptableObject.defineClass()</a>.
|
||||
This method defines a set of JavaScript objects using a Java class. Several
|
||||
of the <a href="examples.html">examples</a> define host objects this way.
|
||||
<p>If the services provided by defineClass are insufficient, try other
|
||||
methods of
|
||||
<a href="org/mozilla/javascript/ScriptableObject.html">ScriptableObject</a>
|
||||
and
|
||||
<a href="org/mozilla/javascript/FunctionObject.html">FunctionObject</a>,
|
||||
such as <tt>defineProperty</tt> and <tt>defineFunctionProperties</tt>.
|
||||
<br>
|
||||
<br>
|
||||
<h3>
|
||||
Contexts and Threads</h3>
|
||||
Every thread that executes JavaScript must have an associated Context.
|
||||
Multiple threads (with multiple associated Contexts) may act upon the same
|
||||
set of objects. Any host objects that are defined are responsible for any
|
||||
sychronization required to run safely from multiple threads.
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 80 KiB |
@@ -1,176 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
|
||||
<meta name="GENERATOR" content="Mozilla/4.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Scopes and Contexts</title>
|
||||
</head>
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<script src="owner.js"></script>
|
||||
<center>
|
||||
<h1> Scopes and Contexts</h1>
|
||||
</center>
|
||||
|
||||
<script>document.write(owner());</script> <br>
|
||||
<script>
|
||||
var d = new Date(document.lastModified);
|
||||
document.write((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
|
||||
document.write('<br>');
|
||||
</script>
|
||||
<center>
|
||||
<hr width="100%"></center>
|
||||
|
||||
<p>Before using Rhino in a concurrent environment, it is important to understand
|
||||
the distinction between Contexts and scopes. Both are required to execute
|
||||
scripts, but they play different roles. Simple embeddings of Rhino probably
|
||||
won't need any of the information here, but more complicated embeddings can
|
||||
gain performance and flexibility from the techniques described below. <br>
|
||||
</p>
|
||||
<h2> Contexts</h2>
|
||||
The Rhino Context object is used to store thread-specific information about
|
||||
the execution environment. There should be one and only one Context associated
|
||||
with each thread that will be executing JavaScript.
|
||||
<p>To associate the current thread with a Context, simply call the <tt>enter</tt>
|
||||
method of Context: </p>
|
||||
<pre> Context cx = Context.enter();</pre>
|
||||
Once you are done with execution, simply exit the Context:
|
||||
<pre> Context.exit();</pre>
|
||||
These calls will work properly even if there is already a Context associated
|
||||
with the current thread. That context will be returned and an internal counter
|
||||
incremented. Only when the counter reaches zero will it be disassociated from
|
||||
the thread.
|
||||
<p>Remember to put the <tt>exit()</tt> call in a <tt>finally</tt> block if
|
||||
you're executing code that could throw an exception. <br>
|
||||
</p>
|
||||
<h2> Scopes</h2>
|
||||
A scope is a set of JavaScript objects. Execution of scripts requires a scope
|
||||
for top-level script variable storage as well as a place to find standard
|
||||
objects like <tt>Function</tt> and <tt>Object</tt>.
|
||||
<p>It's important to understand that a scope is independent of the Context
|
||||
that created it. You can create a scope using one Context and then evaluate
|
||||
a script using that scope and another Context (either by exiting the current
|
||||
context and entering another, or by executing on a different thread). You
|
||||
can even execute scripts on multiple threads simultaneously in the same scope.
|
||||
Rhino guarantees that accesses to properties of JavaScript objects are atomic
|
||||
across threads, but doesn't make any more guarantees for scripts executing
|
||||
in the same scope at the same time. If two scripts use the same scope simultaneously,
|
||||
the scripts are responsible for coordinating any accesses to shared variables.
|
||||
</p>
|
||||
<p>A top-level scope is created by calling <tt>Context.initStandardObjects</tt>
|
||||
to create all the standard objects: </p>
|
||||
<pre> Scriptable scope = cx.initStandardObjects(null);</pre>
|
||||
The easiest way to embed Rhino is just to create a new scope this way whenever
|
||||
you need one. However, <tt>initStandardObjects</tt> is an expensive method
|
||||
to call and it allocates a fair amount of memory. We'll see below that there
|
||||
are ways to share a scope created this way among multiple scopes and threads.
|
||||
<br>
|
||||
|
||||
<h2> Name Lookup</h2>
|
||||
So how are scopes used to look up names? In general, variables are looked
|
||||
up by starting at the current variable object (which is different depending
|
||||
on what code is being executed in the program), traversing its prototype chain,
|
||||
and then traversing the parent chain. In the diagram below, the order in
|
||||
which the six objects are traversed is indicated.
|
||||
<center>
|
||||
<p><img src="lookup.gif" height="194" width="500">
|
||||
<br>
|
||||
<i><font size="-1">Order of lookups in a two-deep scope chain with prototypes.</font></i></p>
|
||||
</center>
|
||||
|
||||
<p>For a more concrete example, let's consider the following script: </p>
|
||||
<blockquote><tt>var g = 7;</tt> <br>
|
||||
<tt>function f(a) {</tt> <br>
|
||||
<tt> var v = 8;</tt> <br>
|
||||
<tt> x = v + a;</tt> <br>
|
||||
<tt>}</tt> <br>
|
||||
<tt>f(6);</tt></blockquote>
|
||||
We have a top-level variable <tt>g</tt>, and the call to <tt>f</tt> will
|
||||
create a new top-level variable <tt>x</tt>. All top-level variables are properties
|
||||
of the scope object. When we start executing <tt>f</tt>, the scope chain
|
||||
will start with the function's activation object and will end with the top-level
|
||||
scope (see diagram below). The activation object has two properties, 'a'
|
||||
for the argument, and 'v' for the variable. The top-level scope has properties
|
||||
for the variable <tt>g</tt> and the function <tt>f</tt>.
|
||||
<center>
|
||||
<p><img src="scopes.gif" height="496" width="820">
|
||||
<br>
|
||||
<i><font size="-1">An example scope chain for a simple script.</font></i></p>
|
||||
</center>
|
||||
|
||||
<p>When the statement <tt>x = v + a;</tt> is executed, the scope chain is
|
||||
traversed looking for a 'x' property. When none is found, a new property 'x'
|
||||
is created in the top-level scope. </p>
|
||||
<h2> Sharing Scopes</h2>
|
||||
JavaScript is a language that uses delegation rather than traditional class-based
|
||||
inheritance. This is a large topic in itself, but for our purposes it gives
|
||||
us an easy way to share a set of read-only variables across multiple scopes.
|
||||
To do this we set an object's prototype. When accessing a property of an object
|
||||
in JavaScript, the object is first searched for a property with the given
|
||||
name. If none is found, the object's prototype is searched. This continues
|
||||
until either the object is found or the end of the prototype chain is reached.
|
||||
<p>So to share information across multiple scopes, we first create the object
|
||||
we wish to share. Typically this object will have been created with <tt>initStandardObjects</tt>
|
||||
and may also have additional objects specific to the embedding. Then all
|
||||
we need to do is create a new object and call its <tt>setPrototype</tt> method
|
||||
to set the prototype to the shared object, and the parent of the new scope
|
||||
to null: </p>
|
||||
<pre> Scriptable newScope = cx.newObject(sharedScope);<br> newScope.setPrototype(sharedScope);<br> newScope.setParentScope(null);<br></pre>
|
||||
The call to <tt>newObject</tt> simply creates a new JavaScript object with
|
||||
no properties. It uses the <tt>sharedScope</tt> passed in to initialize the
|
||||
prototype with the standard <tt>Object.prototype</tt> value.
|
||||
<p>We can now use <tt>newScope</tt> as a scope for calls to evaluate scripts.
|
||||
Let's call this scope the <i>instance scope</i>. Any top-level functions or
|
||||
variables defined in the script will end up as properties of the instance
|
||||
scope. Uses of standard objects like <tt>Function</tt>, <tt>String</tt>, or
|
||||
<tt>RegExp</tt> will find the definitions in the shared scope. Multiple
|
||||
instance scopes can be defined and have their own variables for scripts yet
|
||||
share the definitions in the shared scope. These multiple instance scopes
|
||||
can be used concurrently. <br>
|
||||
</p>
|
||||
<h2> Dynamic Scopes</h2>
|
||||
There's one problem with the setup outlined above. Calls to functions in
|
||||
JavaScript use <i>static scope</i>, which means that variables are first looked
|
||||
up in the function and then, if not found there, in the lexically enclosing
|
||||
scope. This causes problems if functions you define in your shared scope
|
||||
need access to variables you define in your instance scope.
|
||||
<p>With Rhino 1.5, it is possible to compile functions to use <i>dynamic
|
||||
scope</i>. With dynamic scope, functions look at the top-level scope of the
|
||||
calling function rather than their lexical scope. So we can store information
|
||||
that varies across scopes in the instance scope yet still share functions
|
||||
that manipulate that information reside in the shared scope. </p>
|
||||
<p>The <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/DynamicScopes.java">
|
||||
DynamicScopes example</a>
|
||||
illustrates all the points discussed above. <br>
|
||||
<br>
|
||||
</p>
|
||||
<h2> More on Scopes</h2>
|
||||
The key things to determine in setting up scopes for your application are
|
||||
<br>
|
||||
(1) What scope should global variables be created in when your script executes
|
||||
an assignment to an undefined variable, and <br>
|
||||
(2) What variables should your script have access to when it references a
|
||||
variable?
|
||||
<p>The answer to (1) determines which scope should be the ultimate parent
|
||||
scope: Rhino follows the parent chain up to the top and places the variable
|
||||
there. After you've constructed your parent scope chain, the answer to question
|
||||
(2) may indicate that there are additional scopes that need to be searched
|
||||
that are not in your parent scope chain. You can add these as prototypes
|
||||
of scopes in your parent scope chain. When Rhino looks up a variable, it
|
||||
starts in the current scope, walks the prototype chain, then goes to the
|
||||
parent scope and its prototype chain, until there are no more parent scopes
|
||||
left. <br>
|
||||
</p>
|
||||
<h3>
|
||||
<hr width="100%"><br>
|
||||
<a href="index.html">back to top</a>
|
||||
</h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 53 B |
@@ -1,199 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en] (WinNT; U) [Netscape]">
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Scripting Java</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
<script src="owner.js"></script>
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
Scripting Java</h1></center>
|
||||
<script>document.write(owner());</script>
|
||||
|
||||
<br><script>
|
||||
var d = new Date(document.lastModified);
|
||||
document.write((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
|
||||
document.write('<br>');
|
||||
</script>
|
||||
|
||||
<center>
|
||||
<hr WIDTH="100%"></center>
|
||||
|
||||
<p>It's possible to use Rhino just for scripting Java. You don't have to
|
||||
write any additional Java code; just use the existing Rhino shell and then
|
||||
make calls into Java.
|
||||
<br>
|
||||
<h2>
|
||||
Rhino Shell</h2>
|
||||
The Rhino shell allows you to run scripts from files or interactively at
|
||||
a command line.
|
||||
<p>If you download the zip file for rhino, it will contain a single JAR
|
||||
file, <tt>js.jar</tt>. If you add the JAR file to your class path, you
|
||||
can start the Rhino shell using the command
|
||||
<pre> java org.mozilla.javascript.tools.shell.Main</pre>
|
||||
or if you have Java 2 (JDK 1.2), you can avoid changing your classpath
|
||||
and simply use the command
|
||||
<pre> java -jar js.jar</pre>
|
||||
Unfortunately the <tt>-jar</tt> option to <tt>java</tt> will overwrite
|
||||
your existing classpath. The shell's interactive mode is a good way to
|
||||
begin exploring Rhino.
|
||||
<p><i>Note: Earlier versions of Rhino have two JAR files, js.jar and jstools.jar,
|
||||
and don't support the -jar option. Both JAR files must be added to the
|
||||
class path to start the shell</i>.
|
||||
<p>You can execute a JavaScript file by putting the file name as an argument
|
||||
to the shell class:
|
||||
<pre> java org.mozilla.javascript.tools.shell.Main myScript.js</pre>
|
||||
There are a number of options for evaluating scripts using the shell. See
|
||||
the <a href="http://www.mozilla.org/rhino/shell.html">command description</a>
|
||||
for more information.
|
||||
<br>
|
||||
<h2>
|
||||
LiveConnect: Communicating with Java from JavaScript</h2>
|
||||
If you are planning to script Java using Rhino, you'll want to use LiveConnect,
|
||||
which allows you to create Java classes and call Java methods from within
|
||||
JavaScript. For example, here's a log from an interactive session. If you
|
||||
type it in, you'll see a window with a button filling it.
|
||||
<center>
|
||||
<p><img SRC="scriptjavaframe.jpg" height=100 width=200>
|
||||
<br><i><font size=-1>A Java frame created from the Rhino shell.</font></i></center>
|
||||
|
||||
<pre>$ java org.mozilla.javascript.tools.shell.Main
|
||||
js> importPackage(java.awt);
|
||||
js> frame = new Frame("JavaScript")
|
||||
java.awt.Frame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,resizable,title=JavaScript]
|
||||
js> frame.show()
|
||||
js> frame.setSize(new Dimension(200,100))
|
||||
js> button = new Button("OK")
|
||||
java.awt.Button[button0,0,0,0x0,invalid,label=OK]
|
||||
js> frame.add(button)
|
||||
java.awt.Button[button0,0,0,0x0,invalid,label=OK]
|
||||
js> frame.show()
|
||||
js> quit()
|
||||
$</pre>
|
||||
If you wish to load classes from JavaScript that aren't in the <tt>java</tt>
|
||||
package, you'll need to prefix the package name with "<tt>Packages.</tt>".
|
||||
For example:
|
||||
<pre>$ java org.mozilla.javascript.tools.shell.Main
|
||||
js> cx = Packages.org.mozilla.javascript.Context.enter()
|
||||
org.mozilla.javascript.Context@25980b44
|
||||
js> cx.evaluateString(this, "3+2", null, 0, null)
|
||||
5.0
|
||||
js> quit()
|
||||
$</pre>
|
||||
|
||||
<h2>
|
||||
Accessing JavaBean Properties</h2>
|
||||
Java classes can define JavaBean properties using getter and setter methods.
|
||||
For example, the following class defines two properties:
|
||||
<p><tt>public class Me {</tt>
|
||||
<br><tt> public int getAge() { return age; }</tt>
|
||||
<br><tt> public void setAge(int anAge) { age = anAge;
|
||||
}</tt>
|
||||
<br><tt> public String getSex() { return "male"; }</tt>
|
||||
<br><tt> private int age;</tt>
|
||||
<br><tt>};</tt>
|
||||
<p>The two properties defined are <i>age</i> and <i>sex</i>. The <i>sex</i>
|
||||
property is read-only: it has no setter.
|
||||
<p>Using Rhino we can access the bean properties as if they where JavaScript
|
||||
properties. We can also continue to call the methods that define the property.
|
||||
<p><tt>js> me = new Packages.Me();</tt>
|
||||
<br><tt>Me@93</tt>
|
||||
<br><tt>js> me.getSex()</tt>
|
||||
<br><tt>male</tt>
|
||||
<br><tt>js> me.sex</tt>
|
||||
<br><tt>male</tt>
|
||||
<br><tt>js> me.age = 33;</tt>
|
||||
<br><tt>33</tt>
|
||||
<br><tt>js> me.age</tt>
|
||||
<br><tt>33</tt>
|
||||
<br><tt>js> me.getAge()</tt>
|
||||
<br><tt>33</tt>
|
||||
<br><tt>js></tt>
|
||||
<p>Since the <i>sex</i> property is read-only, we are not allowed to write
|
||||
to it.
|
||||
<p><i>Note: JavaBean reflection is not available in versions of Rhino before
|
||||
1.5.</i>
|
||||
<br><tt></tt>
|
||||
<h2>
|
||||
Importing Java Classes and Packages</h2>
|
||||
Above we saw the use of the <tt>importPackage</tt> function to import all
|
||||
the classes from a particular Java package. There is also <tt>importClass</tt>,
|
||||
which imports a single class:
|
||||
<pre>$ java org.mozilla.javascript.tools.shell.Main
|
||||
js> importClass(Packages.org.mozilla.javascript.Context)
|
||||
js> cx = Context.enter()
|
||||
org.mozilla.javascript.Context@25980d62
|
||||
js> cx.evaluateString(this, "3+2", null, 0, null)
|
||||
5.0
|
||||
js> quit()
|
||||
$</pre>
|
||||
|
||||
<h2>
|
||||
Extending Java Classes and Implementing Java Interfaces with JavaScript</h2>
|
||||
Starting from the example above of creating a Java frame using JavaScript,
|
||||
we can add a listener for the button. Once we call <tt>addActionListener</tt>
|
||||
we can then click on the button to get the current date printed out:
|
||||
<pre>$ java org.mozilla.javascript.tools.shell.Main
|
||||
js> importPackage(java.awt);
|
||||
js> frame = new Frame("JavaScript")
|
||||
java.awt.Frame[frame0,0,0,0x0,invalid,hidden,layout=java.awt.BorderLayout,resizable,title=JavaScript]
|
||||
js> button = new Button("OK")
|
||||
java.awt.Button[button0,0,0,0x0,invalid,label=OK]
|
||||
js> frame.setSize(new Dimension(200,100))
|
||||
js> frame.add(button)
|
||||
java.awt.Button[button0,0,0,0x0,invalid,label=OK]
|
||||
js> frame.show()
|
||||
js> function printDate() { print(new Date()) }
|
||||
js> printDate()
|
||||
Wed Mar 15 15:42:20 GMT-0800 (PST) 2000
|
||||
js> o = { actionPerformed: printDate }
|
||||
[object Object]
|
||||
js> o.actionPerformed()
|
||||
Wed Mar 15 15:42:39 GMT-0800 (PST) 2000
|
||||
js> buttonListener = java.awt.event.ActionListener(o)
|
||||
adapter0@6acc0f66
|
||||
js> button.addActionListener(buttonListener)
|
||||
js> Wed Mar 15 15:43:05 GMT-0800 (PST) 2000
|
||||
Wed Mar 15 15:43:05 GMT-0800 (PST) 2000
|
||||
Wed Mar 15 15:43:08 GMT-0800 (PST) 2000
|
||||
quit()
|
||||
$</pre>
|
||||
When we type <tt>buttonListener = java.awt.event.ActionListener(o)</tt>,
|
||||
Rhino actually creates a new Java class that implements <tt>ActionListener</tt>
|
||||
and forwards calls from that class to the JavaScript object. So when you
|
||||
click on the button, the <tt>printDate</tt> method is called.
|
||||
<br>
|
||||
<h2>
|
||||
JavaAdapter constructor</h2>
|
||||
Another way to create a JavaAdapter is to call the JavaAdapter constructor
|
||||
explicitly. Using the JavaAdapter constructor gives you additional features
|
||||
that cannot be had by "constructing" a Java interface as was done above.
|
||||
<p>Instead of writing
|
||||
<pre> buttonListener = java.awt.event.ActionListener(o)</pre>
|
||||
above we can also write
|
||||
<pre> buttonListener = new JavaAdapter(java.awt.event.ActionListener, o)</pre>
|
||||
which is equivalent. If we also wanted to extend class <tt>Foo</tt>, while
|
||||
also implementing <tt>java.lang.Runnable</tt>, we would write
|
||||
<pre> buttonListener = new JavaAdapter(Packages.Foo,
|
||||
java.awt.event.ActionListener,
|
||||
java.lang.Runnable, o)</pre>
|
||||
In general the syntax is
|
||||
<p> <tt>new JavaAdapter(</tt><i>java-class</i>, [<i>java-class</i>,
|
||||
...] <i>javascript-object</i><tt>)</tt>
|
||||
<p>where at most one <i>java-class</i> is a Java class and the remaining
|
||||
<i>java-class</i>es
|
||||
are interfaces. The result will be a Java adapter that extends any specified
|
||||
Java class, implements the Java interfaces, and forwards any calls to the
|
||||
methods of the <i>javascript-object</i>.
|
||||
<h3>
|
||||
|
||||
<hr WIDTH="100%"><br>
|
||||
<a href="index.html">back to top</a></h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
Before Width: | Height: | Size: 4.0 KiB |
@@ -1,122 +0,0 @@
|
||||
<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
|
||||
<meta name="GENERATOR" content="Mozilla/4.72 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
|
||||
<meta name="KeyWords" content="Rhino, JavaScript, Java">
|
||||
<title>Serialization</title>
|
||||
</head>
|
||||
<body bgcolor="#ffffff">
|
||||
|
||||
<script src="owner.js"></script>
|
||||
<center>
|
||||
<h1>Serialization</h1>
|
||||
</center>
|
||||
|
||||
<script>document.write(owner());</script> <br>
|
||||
<script>
|
||||
var d = new Date(document.lastModified);
|
||||
document.write((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
|
||||
document.write('<br>');
|
||||
</script>
|
||||
<center>
|
||||
<hr width="100%"></center>
|
||||
|
||||
<p>Beginning with Rhino 1.5 Release 3 it is possible to serialize JavaScript
|
||||
objects, including functions and scripts. However, serialization of
|
||||
code in compilation mode has some significant limitations.. Serialization
|
||||
provides a way to save the state of an object and write it out to a file
|
||||
or send it across a network connection. <br>
|
||||
</p>
|
||||
<h2>Simple serialization example</h2>
|
||||
The Rhino shell has two new top-level functions, serialize and deserialize.
|
||||
They're intended mainly as examples of the use of serialization:<br>
|
||||
<pre>$ java org.mozilla.javascript.tools.shell.Main<br>js> function f() { return 3; }<br>js> serialize(f, "f.ser")<br>js> quit()<br><br>$ java org.mozilla.javascript.tools.shell.Main<br>js> f = deserialize("f.ser")<br><br>function f() {<br> return 3;<br>}<br><br>js> f()<br>3<br>js></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
<pre></pre>
|
||||
Here we see a simple case of a function being serialized to a file and then
|
||||
read into a new instance of Rhino and called. <br>
|
||||
<br>
|
||||
<h2>Rhino serialization APIs</h2>
|
||||
Two new classes, ScriptableOutputStream and ScriptableInputStream, were introduced
|
||||
to handle serialization of Rhino classes. These classes extend ObjectOutputStream
|
||||
and ObjectInputStream respectively. Writing an object to a file can be done
|
||||
in a few lines of Java code:<br>
|
||||
<pre>FileOutputStream fos = new FileOutputStream(filename);<br>ScriptableOutputStream out = new ScriptableOutputStream(fos, scope);<br>out.writeObject(obj);<br>out.close();</pre>
|
||||
<p>Here filename is the file to write to, obj is the object or function to
|
||||
write, and scope is the top-level scope containing obj. </p>
|
||||
<p>Reading the serialized object back into memory is similarly simple:</p>
|
||||
<pre>FileInputStream fis = new FileInputStream(filename);<br>ObjectInputStream in = new ScriptableInputStream(fis, scope);<br>Object deserialized = in.readObject();<br>in.close();<br></pre>
|
||||
<p>Again, we need the scope to create our serialization stream class. </p>
|
||||
<p>So why do we need these specialized stream classes instead of simply using
|
||||
ObjectOutputStream and ObjectInputStream? To understand the answer we must
|
||||
know what goes on behind the scenes when Rhino serializes objects. </p>
|
||||
<h2>How Rhino serialization works</h2>
|
||||
By default, Java serialization of an object also serializes objects that
|
||||
are referred to by that object. Upon deserialization the initial object and
|
||||
the objects it refers to are all created and the references between the objects
|
||||
are resolved. <br>
|
||||
<br>
|
||||
However, for JavaScript this creates a problem. JavaScript objects contain
|
||||
references to prototypes and to parent scopes. Default serialization would
|
||||
serialize the object or function we desired but would also serialize Object.prototype
|
||||
or even possibly the entire top-level scope and everything it refers to!
|
||||
We want to be able to serialize a JavaScript object and then deserialize
|
||||
it into a new scope and have all of the references from the deserialized
|
||||
object to prototypes and parent scopes resolved correctly to refer to objects
|
||||
in the new scope. <br>
|
||||
<br>
|
||||
ScriptableOutputStream takes a scope as a parameter to its constructor. If
|
||||
in the process of serialization it encounters a reference to the scope it
|
||||
will serialize a marker that will be resolved to the new scope upon deserialization.
|
||||
It is also possible to add names of objects to a list in the ScriptableOutputStream
|
||||
object. These objects will also be saved as markers upon serialization and
|
||||
resolved in the new scope upon deserialization. Use the addExcludedName method
|
||||
of ScriptableOutputStream to add new names. By default, ScriptableOutputStream
|
||||
excludes all the names defined using Context.initStandardObjects.<br>
|
||||
<br>
|
||||
If you are using Rhino serialization in an environment where you always define,
|
||||
say, a constructor "Foo", you should add the following code before calling
|
||||
writeObject:<br>
|
||||
<pre>out.addExcludedName("Foo");<br>out.addExcludedName("Foo.prototype");<br></pre>
|
||||
This code will prevent Foo and Foo.prototype from being serialized and will
|
||||
cause references to Foo or Foo.prototype to be resolved to the objects in
|
||||
the new scope upon deserialization. Exceptions will be thrown if Foo or Foo.prototype
|
||||
cannot be found the scopes used in either ScriptableOutputStream or ScriptableInputStream.<br>
|
||||
<br>
|
||||
<h2>Rhino serialization in compilation mode</h2>
|
||||
Serialization works well with objects and with functions and scripts in
|
||||
interpretive mode. However, you can run into problems with serialization
|
||||
of compiled functions and scripts:<br>
|
||||
<pre>$ cat test.js<br>function f() { return 3; }<br>serialize(f, "f.ser");<br>g = deserialize("f.ser");<br>print(g());<br>$ java org.mozilla.javascript.tools.shell.Main -opt -1 test.js<br>3<br>$ java org.mozilla.javascript.tools.shell.Main test.js<br>js: uncaught JavaScript exception: java.lang.ClassNotFoundException: c1<br></pre>
|
||||
<p>The problem is that Java serialization has no built-in way to serialize
|
||||
Java classes themselves. (It might be possible to save the Java bytecodes
|
||||
in an array and then load the class upon deserialization, but at best that
|
||||
would eat up a lot of memory for just this feature.) One way around this
|
||||
is to compile the functions using the jsc tool: </p>
|
||||
<pre>$ cat f.js<br>function f() { return 3; }<br>$ java -classpath js.jar org.mozilla.javascript.tools.jsc.Main f.js<br>$ cat test2.js<br>loadClass("f");<br>serialize(f, "f.ser");<br>g = deserialize("f.ser");<br>print(g());<br>$ java -classpath 'js.jar;.' org.mozilla.javascript.tools.shell.Main test2.js<br>3<br></pre>
|
||||
<p> Now the function f is compiled to a Java class, but that class is
|
||||
then made available in the classpath so serialization works. This isn't that
|
||||
interesting an example since compiling a function to a class and then loading
|
||||
it accomplishes the same as serializing an interpreted function, but it becomes
|
||||
more relevant if you wish to serialize JavaScript objects that have references
|
||||
to compiled functions. </p>
|
||||
<h3>
|
||||
<hr width="100%"><br>
|
||||
<a href="index.html">back to top</a>
|
||||
</h3>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,128 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Shell</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
JavaScript Shell</h1></center>
|
||||
The JavaScript shell provides a simple way to run scripts in batch mode
|
||||
or an interactive environment for exploratory programming.
|
||||
<h2>
|
||||
Invoking the Shell</h2>
|
||||
<tt>java org.mozilla.javascript.tools.shell.Main</tt> [<i>options</i>]
|
||||
<i>file</i><tt>.js
|
||||
[<i>script-arguments</i>]</tt>
|
||||
<p>where <i>options</i> are:
|
||||
<p><tt>-e </tt><i>script-source</i>
|
||||
<blockquote>Executes <i>script-source</i> as a JavaScript script.</blockquote>
|
||||
<tt>-f </tt><i>script-filename</i>
|
||||
<blockquote>Reads filename specified by <i>script-filename</i> and executes
|
||||
it as a JavaScript script.</blockquote>
|
||||
<tt>-opt </tt><i>optLevel</i>
|
||||
<br><tt>-O</tt> <i>optLevel</i>
|
||||
<ul>Optimizes at level <i>optLevel</i>, which must be an integer between
|
||||
0 and 9. See <a href="opt.html">Optimization</a> for more details.</ul>
|
||||
<tt>-version </tt><i>versionNumber</i>
|
||||
<ul>Specifies the language version to compile with. The string <i>versionNumber</i>
|
||||
must be one of <tt>100</tt>, <tt>110</tt>, <tt>120</tt>, <tt>130</tt>,
|
||||
or <tt>140</tt>. See <a href="overview.html#versions">JavaScript Language
|
||||
Versions</a> for more information on language versions.</ul>
|
||||
|
||||
<h2>
|
||||
Predefined Properties</h2>
|
||||
Scripts executing in the shell have access to some additional properties
|
||||
of the top-level object.
|
||||
<br>
|
||||
<h4>
|
||||
arguments</h4>
|
||||
|
||||
<blockquote>The <tt>arguments</tt> object is an array containing the strings
|
||||
of all the arguments given at the command line when the shell was invoked.</blockquote>
|
||||
|
||||
<h4>
|
||||
help()</h4>
|
||||
|
||||
<blockquote>Executing the help function will print usage and help messages.</blockquote>
|
||||
|
||||
<h4>
|
||||
defineClass(<i>className</i>)</h4>
|
||||
|
||||
<blockquote>Define an extension using the Java class named with the string
|
||||
argument <i>className</i>. Uses ScriptableObject.defineClass() to define
|
||||
the extension.</blockquote>
|
||||
|
||||
<h4>
|
||||
load([<i>filename</i>, ...])</h4>
|
||||
|
||||
<blockquote>Load JavaScript source files named by string arguments. If
|
||||
multiple arguments are given, each file is read in and executed in turn.</blockquote>
|
||||
|
||||
<h4>
|
||||
loadClass(<i>className</i>)</h4>
|
||||
|
||||
<blockquote>Load and execute the class named by the string argument <i>className</i>.
|
||||
The class must be a class that implements the Script interface, as will
|
||||
any script compiled by <a href="jsc.html">jsc</a>.</blockquote>
|
||||
|
||||
<h4>
|
||||
print([<i>expr</i> ...])</h4>
|
||||
|
||||
<blockquote>Evaluate and print expressions. Evaluates each expression,
|
||||
converts the result to a string, and prints it.</blockquote>
|
||||
|
||||
<h4>
|
||||
quit()</h4>
|
||||
|
||||
<blockquote>Quit shell. The shell will also quit in interactive mode if
|
||||
an end-of-file character is typed at the prompt.</blockquote>
|
||||
|
||||
<h4>
|
||||
version([<i>number</i>])</h4>
|
||||
|
||||
<blockquote>Get or set JavaScript version number. If no argument is supplied,
|
||||
the current version number is returned. If an argument is supplied, it
|
||||
is expected to be one of <tt>100</tt>, <tt>110</tt>, <tt>120</tt>, <tt>130,</tt>
|
||||
or <tt>140</tt> to indicate JavaScript version 1.0, 1.1, 1.2, 1.3, or 1.4
|
||||
respectively.</blockquote>
|
||||
|
||||
<h2>
|
||||
Example</h2>
|
||||
Here the shell is invoked three times from the command line. (The system
|
||||
command prompt is shown as <tt>$</tt>.) The first invocation executes a
|
||||
script specified on the command line itself. The next invocation has no
|
||||
arguments, so the shell goes into interactive mode, reading and evaluating
|
||||
each line as it is typed in. Finally, the last invocation executes a script
|
||||
from a file and accesses arguments to the script itself.
|
||||
<p><tt>$ java org.mozilla.javascript.tools.shell.Main -e print('hi')</tt>
|
||||
<p><tt>hi</tt>
|
||||
<p><tt>$ java org.mozilla.javascript.tools.shell.Main</tt>
|
||||
<p><tt>js> print('hi')</tt>
|
||||
<br><tt>hi</tt>
|
||||
<br><tt>js> 6*7</tt>
|
||||
<br><tt>42</tt>
|
||||
<br><tt>js> function f() {</tt>
|
||||
<br><tt> return a;</tt>
|
||||
<br><tt>}</tt>
|
||||
<br><tt>js> var a = 34;</tt>
|
||||
<br><tt>js> f()</tt>
|
||||
<br><tt>34</tt>
|
||||
<br><tt>js> quit()</tt>
|
||||
<p><tt>$ cat echo.js</tt>
|
||||
<br><tt>for (i in arguments) {</tt>
|
||||
<br><tt> print(arguments[i])</tt>
|
||||
<br><tt>}</tt>
|
||||
<br><tt>$ java org.mozilla.javascript.tools.shell.Main echo.js foo bar</tt>
|
||||
<p><tt>foo</tt>
|
||||
<br><tt>bar</tt>
|
||||
<p><tt>$</tt>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,31 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Author" content="Norris Boyd">
|
||||
<meta name="GENERATOR" content="Mozilla/4.7 [en]C-NSCP (WinNT; U) [Netscape]">
|
||||
<title>JavaScript Tools</title>
|
||||
</head>
|
||||
<body bgcolor="#FFFFFF">
|
||||
|
||||
<center>
|
||||
<h1>
|
||||
JavaScript Tools</h1></center>
|
||||
|
||||
<h2>
|
||||
JavaScript shell</h2>
|
||||
The <a href="shell.html">JavaScript shell</a> allows for interactive and
|
||||
batch execution of JavaScript scripts.
|
||||
<br>
|
||||
<br>
|
||||
<br>
|
||||
<h2>
|
||||
JavaScript compiler</h2>
|
||||
The <a href="jsc.html">JavaScript compiler</a> translates JavaScript source
|
||||
into Java class files.
|
||||
<br>
|
||||
<p>
|
||||
<hr WIDTH="100%">
|
||||
<br><a href="index.html">back to top</a>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,336 +0,0 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
||||
<meta name="Generator" content="Microsoft Word 97">
|
||||
<meta name="GENERATOR" content="Mozilla/4.75 [en] (WinNT; U) [Netscape]">
|
||||
<title>Embedding Rhino</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<center><font size=+4>Tutorial: Embedding Rhino</font></center>
|
||||
|
||||
<p>Embedding Rhino can be done simply with good results. With more effort
|
||||
on the part of the embedder, the objects exposed to scripts can be customized
|
||||
further.
|
||||
<p>This tutorial leads you through the steps from a simple embedding to
|
||||
more customized, complex embeddings. Fully compilable examples are provided
|
||||
along the way.
|
||||
<p>The examples live in the <tt>rhino/examples</tt> directory in the distribution
|
||||
and in <tt>mozilla/js/rhino/examples</tt> in cvs. This document will link
|
||||
to them using <a href="http://lxr.mozilla.org/">lxr</a>.
|
||||
<p>In this document, JavaScript code will be in <font color="#006600">green</font>,
|
||||
Java code will be in <font color="#006600">green</font>, and shell logs
|
||||
will be in <font color="#663366">purple</font>.
|
||||
<h3>
|
||||
<font size=+3>Contents</font></h3>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#RunScript">RunScript: A simple embedding</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#EnteringContext">Entering a Context</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#initializing">Initializing standard objects</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Collecting">Collecting the arguments</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Evaluating">Evaluating a script</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Print">Print the result</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Exit">Exit the Context</a></font></li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Expose">Expose Java APIs</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#UseJava">Use Java APIs</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#ImplementingInterfaces">Implementing interfaces</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#AddJava">Add Java objects</a></font></li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#UsingJSObjs">Using JavaScript objects from Java</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#UsingJSvars">Using JavaScript variables</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#CallingJSfuns">Calling JavaScript functions</a></font></li>
|
||||
</ul>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#JavaScriptHostObjects">JavaScript host objects</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#DefiningHostObjects">Defining Host Objects</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Counter">Counter example</a></font></li>
|
||||
|
||||
<ul>
|
||||
<li>
|
||||
<font size=+1><a href="#CounterCtors">Counter's constructors</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#classname">Class name</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#Dynamic">Dynamic properties</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#DefiningMethods">Defining JavaScript "methods"</a></font></li>
|
||||
|
||||
<li>
|
||||
<font size=+1><a href="#AddingCounter">Adding Counter to RunScript</a></font></li>
|
||||
</ul>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
<hr WIDTH="100%">
|
||||
<br><a NAME="RunScript"></a><font size=+3>RunScript: A simple embedding</font>
|
||||
<p>About the simplest embedding of Rhino possible is the <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript.java">RunScript
|
||||
example</a>. All it does it read a script from the command line, execute
|
||||
it, and print a result.
|
||||
<p>Here's an example use of RunScript from a shell command line:
|
||||
<blockquote>
|
||||
<pre><font color="#663366">$ java RunScript 'Math.cos(Math.PI)'
|
||||
-1
|
||||
$ java RunScript 'function f(x){return x+1} f(7)'
|
||||
8</font></pre>
|
||||
</blockquote>
|
||||
Note that you'll have to have both the Rhino classes and the RunScript
|
||||
example class file in the classpath. Let's step through the body of <tt>main</tt>
|
||||
one line at time.
|
||||
<p><a NAME="EnteringContext"></a><font size=+2>Entering a Context</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre><font color="#006600">Context cx = Context.enter();</font></pre>
|
||||
</blockquote>
|
||||
Creates and enters a <tt>Context. </tt>A <tt>Context</tt> stores information
|
||||
about the execution environment of a script.
|
||||
<br>
|
||||
<p><a NAME="initializing"></a><font size=+2>Initializing standard objects</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre><font color="#006600">Scriptable scope = cx.initStandardObjects(null);</font></pre>
|
||||
</blockquote>
|
||||
Initializes the standard objects (<tt>Object</tt>,
|
||||
<tt>Function</tt>, etc.)
|
||||
This must be done before scripts can be executed. The <tt>null</tt> parameter
|
||||
tells <tt>initStandardObjects</tt> to create and return a scope object
|
||||
that we use in later calls.
|
||||
<p><a NAME="Collecting"></a><font size=+2>Collecting the arguments</font>
|
||||
<p>This code is standard Java and not specific to Rhino. It just collects
|
||||
all the arguments and concatenates them together.
|
||||
<blockquote><tt><font color="#006600">String s = "";</font></tt>
|
||||
<br><tt><font color="#006600">for (int i=0; i < args.length; i++)</font></tt>
|
||||
<br><tt><font color="#006600"> s += args[i];</font></tt></blockquote>
|
||||
|
||||
<p><br><a NAME="Evaluating"></a><font size=+2>Evaluating a script</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre><font color="#006600">Object result = cx.evaluateString(scope, s, "<cmd>", 1, null);</font></pre>
|
||||
</blockquote>
|
||||
uses the Context <tt>cx</tt> to evaluate a string. Evaluation of the script
|
||||
looks up variables in <tt>scope</tt>, and errors will be reported with
|
||||
the filename <tt><cmd></tt> and line number 1.
|
||||
<br>
|
||||
<p><a NAME="Print"></a><font size=+2>Print the result</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre><font color="#006600">System.out.println(cx.toString(result));</font></pre>
|
||||
</blockquote>
|
||||
prints the result of evaluating the script (contained in the variable <tt>result</tt>).
|
||||
<tt>result</tt>
|
||||
could be a string, JavaScript object, or other values..The
|
||||
<tt>toString</tt>
|
||||
method converts any JavaScript value to a string.
|
||||
<br>
|
||||
<p><a NAME="Exit"></a><font size=+2>Exit the Context</font>
|
||||
<p>The code
|
||||
<blockquote>
|
||||
<pre><font color="#006600">Context.exit();</font></pre>
|
||||
</blockquote>
|
||||
exits the Context. This removes the association between the Context and
|
||||
the current thread and is an essential cleanup action. There should be
|
||||
a call to <tt>exit</tt> for every call to <tt>enter</tt>.
|
||||
<br>
|
||||
<dir> </dir>
|
||||
<a NAME="Expose"></a><font size=+3>Expose Java APIs</font>
|
||||
<p><a NAME="UseJava"></a><font size=+2>Use Java APIs</font>
|
||||
<p>No additional code in the embedding needed! The JavaScript feature called
|
||||
<i>LiveConnect</i>
|
||||
allows JavaScript programs to interact with Java objects:
|
||||
<dir><tt><font color="#663366">$ java RunScript 'java.lang.System.out.println(3)'</font></tt>
|
||||
<br><tt><font color="#663366">3.0</font></tt>
|
||||
<br><tt><font color="#663366">undefined</font></tt></dir>
|
||||
<a NAME="ImplementingInterfaces"></a><font size=+2>Implementing interfaces</font>
|
||||
<p>Using Rhino, JavaScript objects can implement arbitrary Java interfaces.
|
||||
There's no Java code to write--it's part of Rhino's LiveConnect implementation.
|
||||
For example, we can see how to implement java.lang.Runnable in a Rhino
|
||||
shell session:
|
||||
<blockquote>
|
||||
<pre><font color="#663366">js> obj = { run: function() { print('hi'); } }
|
||||
[object Object]
|
||||
js> obj.run()
|
||||
hi
|
||||
js> r = new java.lang.Runnable(obj);
|
||||
[object Object]
|
||||
js> t = new java.lang.Thread(r)
|
||||
Thread[Thread-0,5,main]
|
||||
js> t.start()
|
||||
hi</font></pre>
|
||||
</blockquote>
|
||||
<a NAME="AddJava"></a><font size=+2>Add Java objects</font>
|
||||
<p>The next example is <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript2.java">RunScript2</a>.
|
||||
This is the same as RunScript, but with the addition of two extra lines
|
||||
of code:
|
||||
<dir><tt><font color="#006600">Scriptable jsArgs = Context.toObject(System.out,
|
||||
scope);</font></tt>
|
||||
<br><tt><font color="#006600">scope.put("out", scope, jsArgs);</font></tt></dir>
|
||||
These lines add a global variable <tt>out</tt> that is a JavaScript reflection
|
||||
of the <tt>System.out</tt> variable:
|
||||
<dir><tt><font color="#663366">$ java RunScript2 'out.println(42)'</font></tt>
|
||||
<br><tt><font color="#663366">42.0</font></tt>
|
||||
<br><tt><font color="#663366">undefined</font></tt></dir>
|
||||
|
||||
<p><br><a NAME="UsingJSObjs"></a><font size=+3>Using JavaScript objects
|
||||
from Java</font>
|
||||
<p>After evaluating a script it's possible to query the scope for variables
|
||||
and functions, extracting values and calling JavaScript functions. This
|
||||
is illustrated in the <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript3.java">RunScript3</a>
|
||||
example. This example adds the ability to print the value of variable <tt>x</tt>
|
||||
and the result of calling function <tt>f</tt>. Both <tt>x</tt> and <tt>f</tt>
|
||||
are expected to be defined by the evaluated script. For example,
|
||||
<blockquote><tt><font color="#663366">$ java RunScript3 'x = 7'</font></tt>
|
||||
<br><tt><font color="#663366">x = 7</font></tt>
|
||||
<br><tt><font color="#663366">f is undefined or not a function.</font></tt>
|
||||
<br><tt><font color="#663366">$ java RunScript3 'function f(a) { return
|
||||
a; }'</font></tt>
|
||||
<br><tt><font color="#663366">x is not defined.</font></tt>
|
||||
<br><tt><font color="#663366">f('my args') = my arg</font></tt>
|
||||
<br><tt><font color="#663366"></font></tt> </blockquote>
|
||||
<a NAME="UsingJSvars"></a><font size=+2>Using JavaScript variables</font>
|
||||
<p>To print out the value of <tt>x</tt>, we add the following code.
|
||||
<dir><tt><font color="#006600">Object x = scope.get("x", scope);</font></tt>
|
||||
<br><tt><font color="#006600">if (x == Scriptable.NOT_FOUND)</font></tt>
|
||||
<br><tt><font color="#006600"> System.out.println("x
|
||||
is not defined.");</font></tt>
|
||||
<br><tt><font color="#006600">else</font></tt>
|
||||
<br><tt><font color="#006600"> System.out.println("x
|
||||
= " + Context.toString(x));</font></tt>
|
||||
<br><tt><font color="#006600"></font></tt> </dir>
|
||||
<a NAME="CallingJSfuns"></a><font size=+2>Calling JavaScript functions</font>
|
||||
<p>To get the function <tt>f</tt>, call it, and print the result, we add
|
||||
this code:
|
||||
<dir><tt><font color="#006600">Object f = scope.get("f", scope);</font></tt>
|
||||
<br><tt><font color="#006600">if (!(f instanceof Function))</font></tt>
|
||||
<br><tt><font color="#006600"> System.out.println("f
|
||||
is undefined or not a function.");</font></tt>
|
||||
<br><tt><font color="#006600">else {</font></tt>
|
||||
<br><tt><font color="#006600"> Object functionArgs[]
|
||||
= { "my arg" };</font></tt>
|
||||
<br><tt><font color="#006600"> Object result = ((Function)
|
||||
f).call(cx, scope, scope, functionArgs);</font></tt>
|
||||
<br><tt><font color="#006600"> System.out.println("f('my
|
||||
args') = " + Context.toString(result));</font></tt>
|
||||
<br><tt><font color="#006600">}</font></tt></dir>
|
||||
|
||||
<p><br><a NAME="JavaScriptHostObjects"></a><font size=+3>JavaScript host
|
||||
objects</font>
|
||||
<p><a NAME="DefiningHostObjects"></a><font size=+2>Defining Host Objects</font>
|
||||
<p>Custom host objects can implement special JavaScript features like dynamic
|
||||
properties.
|
||||
<p><a NAME="Counter"></a><font size=+2>Counter example</font>
|
||||
<p>The <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/Counter.java">Counter
|
||||
example</a> is a simple host object. We'll go through it method by method
|
||||
below.
|
||||
<p>It's easy to try out new host object classes in the shell using its
|
||||
built-in <tt>defineClass</tt> function. We'll see how to add it to RunScript
|
||||
later. (Note that because the <tt>java -jar</tt> option preempts the rest
|
||||
of the classpath, we can't use that and access the <tt>Counter</tt> class.)
|
||||
<blockquote>
|
||||
<pre><font color="#663366">$ java -cp 'js.jar;examples' org.mozilla.javascript.tools.shell.Main
|
||||
js> defineClass("Counter")
|
||||
js> c = new Counter(7)
|
||||
[object Counter]
|
||||
js> c.count
|
||||
7
|
||||
js> c.count
|
||||
8
|
||||
js> c.count
|
||||
9
|
||||
js> c.resetCount()
|
||||
js> c.count
|
||||
0</font></pre>
|
||||
</blockquote>
|
||||
<a NAME="CounterCtors"></a><font size=+2>Counter's constructors</font>
|
||||
<p>The zero-argument constructor is used by Rhino runtime to create instances.
|
||||
For the counter example, no initialization work is needed, so the implementation
|
||||
is empty.
|
||||
<dir><tt><font color="#006600">public Counter () { }</font></tt></dir>
|
||||
The method <tt>jsConstructor</tt> defines the JavaScript constructor that
|
||||
was called with the expression <tt>new Counter(7)</tt> in the JavaScript
|
||||
code above.
|
||||
<dir><tt><font color="#006600">public void jsConstructor(int a) { count
|
||||
= a; }</font></tt></dir>
|
||||
<a NAME="classname"></a><font size=+2>Class name</font>
|
||||
<p>The class name is defined by the <tt>getClassName</tt> method. This
|
||||
is used to determine the name of the constructor.
|
||||
<dir><tt><font color="#006600">public String getClassName() { return "Counter";
|
||||
}</font></tt></dir>
|
||||
<a NAME="Dynamic"></a><font size=+2>Dynamic properties</font>
|
||||
<p>Dynamic properties are defined by methods beginning with <tt>jsGet_</tt>
|
||||
or <tt>jsSet_</tt>. The method <tt>jsGet_count</tt> defines the <i>count</i>
|
||||
property.
|
||||
<dir><tt><font color="#006600">public int jsGet_count() { return count++;
|
||||
}</font></tt></dir>
|
||||
The expression <tt>c.count</tt> in the JavaScript code above results in
|
||||
a call to this method.
|
||||
<p><a NAME="DefiningMethods"></a><font size=+2>Defining JavaScript "methods"</font>
|
||||
<p>Methods can be defined using the <tt>jsFunction_ prefix</tt>. Here we
|
||||
define <tt>resetCount</tt> for JavaScript.
|
||||
<dir><tt><font color="#006600">public void jsFunction_resetCount() { count
|
||||
= 0; }</font></tt></dir>
|
||||
The call <tt>c.resetCount()</tt> above calls this method.
|
||||
<p><a NAME="AddingCounter"></a><font size=+2>Adding Counter to RunScript</font>
|
||||
<p>Now take a look at the <a href="http://lxr.mozilla.org/mozilla/source/js/rhino/examples/RunScript4.java">RunScript4
|
||||
example</a>. It's the same as RunScript except for two additions. The method
|
||||
<tt>ScriptableObject.defineClass</tt>
|
||||
uses a Java class to define the Counter "class" in the top-level scope:
|
||||
<dir><tt><font color="#006600">ScriptableObject.defineClass(scope, Counter.class);</font></tt></dir>
|
||||
Now we can reference the <tt>Counter</tt> object from our script:
|
||||
<dir><tt><font color="#663366">$ java RunScript4 'c = new Counter(3); c.count;
|
||||
c.count;'</font></tt>
|
||||
<br><tt><font color="#663366">4</font></tt></dir>
|
||||
It also creates a new instance of the <tt>Counter</tt> object from within
|
||||
our Java code, constructing it with the value 7, and assigning it to the
|
||||
top-level variable <tt>myCounter</tt>:
|
||||
<dir><tt><font color="#006600">Object[] arg = { new Integer(7) };</font></tt>
|
||||
<br><tt><font color="#006600">Scriptable myCounter = cx.newObject(scope,
|
||||
"Counter", arg);</font></tt>
|
||||
<br><tt><font color="#006600">scope.put("myCounter", scope, myCounter);</font></tt></dir>
|
||||
Now we can reference the <tt>myCounter</tt> object from our script:
|
||||
<dir><tt><font color="#663366">$ java RunScript3 'RunScript4 'myCounter.count;
|
||||
myCounter.count'</font></tt>
|
||||
<br><tt><font color="#663366">8</font></tt></dir>
|
||||
|
||||
</body>
|
||||
</html>
|
||||