From 052a911d7da6bddeb2cefde37c8ab64af52bc4c3 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@18797224-902f-48f8-a5cc-f745e15eee43> Date: Tue, 7 Sep 2004 21:21:50 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create branch 'MOZILLA_1_7_BRANCH'. git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_7_BRANCH@161880 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/xbl/builtin/gtk2/Makefile.in | 35 + .../xbl/builtin/gtk2/platformHTMLBindings.xml | 110 ++ mozilla/intl/locale/idl/nsICollation.idl | 84 + .../modules/plugin/base/public/npruntime.h | 397 +++++ mozilla/modules/plugin/base/public/nptypes.h | 109 ++ .../modules/plugin/base/src/nsJSNPRuntime.cpp | 1360 +++++++++++++++++ .../modules/plugin/base/src/nsJSNPRuntime.h | 105 ++ .../base/public/nsIAuthPromptProvider.idl | 65 + .../security/nss/lib/ckfw/builtins/ckbiver.c | 58 + .../security/nss/lib/ckfw/builtins/nssckbi.rc | 97 ++ mozilla/widget/public/nsINativeKeyBindings.h | 80 + .../widget/src/gtk2/nsNativeKeyBindings.cpp | 296 ++++ mozilla/widget/src/gtk2/nsNativeKeyBindings.h | 93 ++ 13 files changed, 2889 insertions(+) create mode 100644 mozilla/content/xbl/builtin/gtk2/Makefile.in create mode 100644 mozilla/content/xbl/builtin/gtk2/platformHTMLBindings.xml create mode 100644 mozilla/intl/locale/idl/nsICollation.idl create mode 100644 mozilla/modules/plugin/base/public/npruntime.h create mode 100644 mozilla/modules/plugin/base/public/nptypes.h create mode 100644 mozilla/modules/plugin/base/src/nsJSNPRuntime.cpp create mode 100644 mozilla/modules/plugin/base/src/nsJSNPRuntime.h create mode 100644 mozilla/netwerk/base/public/nsIAuthPromptProvider.idl create mode 100644 mozilla/security/nss/lib/ckfw/builtins/ckbiver.c create mode 100644 mozilla/security/nss/lib/ckfw/builtins/nssckbi.rc create mode 100644 mozilla/widget/public/nsINativeKeyBindings.h create mode 100644 mozilla/widget/src/gtk2/nsNativeKeyBindings.cpp create mode 100644 mozilla/widget/src/gtk2/nsNativeKeyBindings.h diff --git a/mozilla/content/xbl/builtin/gtk2/Makefile.in b/mozilla/content/xbl/builtin/gtk2/Makefile.in new file mode 100644 index 00000000000..f3d36be824a --- /dev/null +++ b/mozilla/content/xbl/builtin/gtk2/Makefile.in @@ -0,0 +1,35 @@ +# +# 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) 1999 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 + +libs:: $(TARGETS) + $(INSTALL) $(srcdir)/platformHTMLBindings.xml $(DIST)/bin/res/builtin + +install:: platformHTMLBindings.xml + $(SYSINSTALL) $(IFLAGS1) $^ $(DESTDIR)$(mozappdir)/res/builtin diff --git a/mozilla/content/xbl/builtin/gtk2/platformHTMLBindings.xml b/mozilla/content/xbl/builtin/gtk2/platformHTMLBindings.xml new file mode 100644 index 00000000000..6e51523e767 --- /dev/null +++ b/mozilla/content/xbl/builtin/gtk2/platformHTMLBindings.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mozilla/intl/locale/idl/nsICollation.idl b/mozilla/intl/locale/idl/nsICollation.idl new file mode 100644 index 00000000000..b20445fdfd4 --- /dev/null +++ b/mozilla/intl/locale/idl/nsICollation.idl @@ -0,0 +1,84 @@ +/* -*- Mode: idl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * mozilla.org + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsILocale.idl" + +interface nsICollation; + +[scriptable, uuid(04971e14-d6b3-4ada-8cbb-c3a13842b349)] +interface nsICollationFactory : nsISupports { + nsICollation CreateCollation(in nsILocale locale); +}; + +[scriptable, uuid(b0132cc0-3786-4557-9874-910d7def5f93)] +interface nsICollation : nsISupports { + + // use the primary comparison for the given local - no flags + const long kCollationStrengthDefault = 0; + + // do not consider case differences when doing the comparison i.e. A=a) + const long kCollationCaseInsensitiveAscii = 1; + + // do not consider accent differences when doing the comparison a=á) + const long kCollationAccentInsenstive = 2; + + // case sensitive collation (default) + const long kCollationCaseSensitive = kCollationStrengthDefault; + + // case insensitive collation + const long kCollationCaseInSensitive = (kCollationCaseInsensitiveAscii | kCollationAccentInsenstive); + + // init this interface to a specified locale (should only be called by collation factory) + void initialize(in nsILocale locale); + + // compare two strings + // result is same as strcmp + long compareString(in long strength, in AString string1, in AString string2); + + // allocate sort key from input string + // returns newly allocated key, and its band its byte length + [noscript] void allocateRawSortKey(in long strength, + in AString stringIn, + [array,size_is(outLen)] out octet key, + out unsigned long outLen); + + // compare two sort keys + // length is a byte length, result is same as strcmp + [noscript] long compareRawSortKey([const,array,size_is(len1)] in octet key1, in unsigned long len1, + [const,array,size_is(len2)] in octet key2, in unsigned long len2); + +}; diff --git a/mozilla/modules/plugin/base/public/npruntime.h b/mozilla/modules/plugin/base/public/npruntime.h new file mode 100644 index 00000000000..2d1dc0253f4 --- /dev/null +++ b/mozilla/modules/plugin/base/public/npruntime.h @@ -0,0 +1,397 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * Copyright © 2004, Apple Computer, Inc. and The Mozilla Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the names of Apple Computer, Inc. ("Apple") or The Mozilla + * Foundation ("Mozilla") nor the names of their contributors may be used + * to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE, MOZILLA AND THEIR CONTRIBUTORS "AS + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE, MOZILLA OR + * THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Revision 1 (March 4, 2004): + * Initial proposal. + * + * Revision 2 (March 10, 2004): + * All calls into script were made asynchronous. Results are + * provided via the NPScriptResultFunctionPtr callback. + * + * Revision 3 (March 10, 2004): + * Corrected comments to not refer to class retain/release FunctionPtrs. + * + * Revision 4 (March 11, 2004): + * Added additional convenience NPN_SetExceptionWithUTF8(). + * Changed NPHasPropertyFunctionPtr and NPHasMethodFunctionPtr to take NPClass + * pointers instead of NPObject pointers. + * Added NPIsValidIdentifier(). + * + * Revision 5 (March 17, 2004): + * Added context parameter to result callbacks from ScriptObject functions. + * + * Revision 6 (March 29, 2004): + * Renamed functions implemented by user agent to NPN_*. Removed _ from + * type names. + * Renamed "JavaScript" types to "Script". + * + * Revision 7 (April 21, 2004): + * NPIdentifier becomes a void*, was int32_t + * Remove NP_IsValidIdentifier, renamed NP_IdentifierFromUTF8 to NP_GetIdentifier + * Added NPVariant and modified functions to use this new type. + * + * Revision 8 (July 9, 2004): + * Updated to joint Apple-Mozilla license. + * + */ +#ifndef _NP_RUNTIME_H_ +#define _NP_RUNTIME_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "nptypes.h" + +/* + This API is used to facilitate binding code written in C to script + objects. The API in this header does not assume the presence of a + user agent. That is, it can be used to bind C code to scripting + environments outside of the context of a user agent. + + However, the normal use of the this API is in the context of a + scripting environment running in a browser or other user agent. + In particular it is used to support the extended Netscape + script-ability API for plugins (NP-SAP). NP-SAP is an extension + of the Netscape plugin API. As such we have adopted the use of + the "NP" prefix for this API. + + The following NP{N|P}Variables were added to the Netscape plugin + API (in npapi.h): + + NPNVWindowNPObject + NPNVPluginElementNPObject + NPPVpluginScriptableNPObject + + These variables are exposed through NPN_GetValue() and + NPP_GetValue() (respectively) and are used to establish the + initial binding between the user agent and native code. The DOM + objects in the user agent can be examined and manipulated using + the NPN_ functions that operate on NPObjects described in this + header. + + To the extent possible the assumptions about the scripting + language used by the scripting environment have been minimized. +*/ + +#define NP_BEGIN_MACRO do { +#define NP_END_MACRO } while (0) + +/* + Objects (non-primitive data) passed between 'C' and script is + always wrapped in an NPObject. The 'interface' of an NPObject is + described by an NPClass. +*/ +typedef struct NPObject NPObject; +typedef struct NPClass NPClass; + +typedef char NPUTF8; +typedef struct _NPString { + const NPUTF8 *utf8characters; + uint32_t utf8length; +} NPString; + +typedef enum { + NPVariantType_Void, + NPVariantType_Null, + NPVariantType_Bool, + NPVariantType_Int32, + NPVariantType_Double, + NPVariantType_String, + NPVariantType_Object +} NPVariantType; + +typedef struct _NPVariant { + NPVariantType type; + union { + bool boolValue; + uint32_t intValue; + double doubleValue; + NPString stringValue; + NPObject *objectValue; + } value; +} NPVariant; + +/* + NPN_ReleaseVariantValue is called on all 'out' parameters + references. Specifically it is to be called on variants that own + their value, as is the case with all non-const NPVariant* + arguments after a successful call to any methods (except this one) + in this API. + + After calling NPN_ReleaseVariantValue, the type of the variant + will be NPVariantType_Void. +*/ +void NPN_ReleaseVariantValue(NPVariant *variant); + +#define NPVARIANT_IS_VOID(_v) ((_v).type == NPVariantType_Void) +#define NPVARIANT_IS_NULL(_v) ((_v).type == NPVariantType_Null) +#define NPVARIANT_IS_BOOLEAN(_v) ((_v).type == NPVariantType_Bool) +#define NPVARIANT_IS_INT32(_v) ((_v).type == NPVariantType_Int32) +#define NPVARIANT_IS_DOUBLE(_v) ((_v).type == NPVariantType_Double) +#define NPVARIANT_IS_STRING(_v) ((_v).type == NPVariantType_String) +#define NPVARIANT_IS_OBJECT(_v) ((_v).type == NPVariantType_Object) + +#define NPVARIANT_TO_BOOLEAN(_v) ((_v).value.boolValue) +#define NPVARIANT_TO_INT32(_v) ((_v).value.intValue) +#define NPVARIANT_TO_DOUBLE(_v) ((_v).value.doubleValue) +#define NPVARIANT_TO_STRING(_v) ((_v).value.stringValue) +#define NPVARIANT_TO_OBJECT(_v) ((_v).value.objectValue) + +#define VOID_TO_NPVARIANT(_v) \ +NP_BEGIN_MACRO \ + (_v).type = NPVariantType_Void; \ + (_v).value.objectValue = NULL; \ +NP_END_MACRO + +#define NULL_TO_NPVARIANT(_v) \ +NP_BEGIN_MACRO \ + (_v).type = NPVariantType_Null; \ + (_v).value.objectValue = NULL; \ +NP_END_MACRO + +#define BOOLEAN_TO_NPVARIANT(_val, _v) \ +NP_BEGIN_MACRO \ + (_v).type = NPVariantType_Bool; \ + (_v).value.boolValue = !!(_val); \ +NP_END_MACRO + +#define INT32_TO_NPVARIANT(_val, _v) \ +NP_BEGIN_MACRO \ + (_v).type = NPVariantType_Int32; \ + (_v).value.intValue = _val; \ +NP_END_MACRO + +#define DOUBLE_TO_NPVARIANT(_val, _v) \ +NP_BEGIN_MACRO \ + (_v).type = NPVariantType_Double; \ + (_v).value.doubleValue = _val; \ +NP_END_MACRO + +#define STRINGZ_TO_NPVARIANT(_val, _v) \ +NP_BEGIN_MACRO \ + (_v).type = NPVariantType_String; \ + NPString str = { _val, strlen(_val) }; \ + (_v).value.stringValue = str; \ +NP_END_MACRO + +#define STRINGN_TO_NPVARIANT(_val, _len, _v) \ +NP_BEGIN_MACRO \ + (_v).type = NPVariantType_String; \ + NPString str = { _val, _len }; \ + (_v).value.stringValue = str; \ +NP_END_MACRO + +#define OBJECT_TO_NPVARIANT(_val, _v) \ +NP_BEGIN_MACRO \ + (_v).type = NPVariantType_Object; \ + (_v).value.objectValue = _val; \ +NP_END_MACRO + + +/* + Type mappings (JavaScript types have been used for illustration + purposes): + + JavaScript to C (NPVariant with type:) + undefined NPVariantType_Void + null NPVariantType_Null + Boolean NPVariantType_Bool + Number NPVariantType_Double or NPVariantType_Int32 + String NPVariantType_String + Object NPVariantType_Object + + C (NPVariant with type:) to JavaScript + NPVariantType_Void undefined + NPVariantType_Null null + NPVariantType_Bool Boolean + NPVariantType_Int32 Number + NPVariantType_Double Number + NPVariantType_String String + NPVariantType_Object Object +*/ + +typedef void *NPIdentifier; + +/* + NPObjects have methods and properties. Methods and properties are + identified with NPIdentifiers. These identifiers may be reflected + in script. NPIdentifiers can be either strings or integers, IOW, + methods and properties can be identified by either strings or + integers (i.e. foo["bar"] vs foo[1]). NPIdentifiers can be + compared using ==. In case of any errors, the requested + NPIdentifier(s) will be NULL. +*/ +NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name); +void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, + NPIdentifier *identifiers); +NPIdentifier NPN_GetIntIdentifier(int32_t intid); +bool NPN_IdentifierIsString(NPIdentifier identifier); + +/* + The NPUTF8 returned from NPN_UTF8FromIdentifier SHOULD be freed. +*/ +NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier); + +/* + Get the integer represented by identifier. If identifier is not an + integer identifier, the behaviour is undefined. +*/ +int32_t NPN_IntFromIdentifier(NPIdentifier identifier); + +/* + NPObject behavior is implemented using the following set of + callback functions. + + The NPVariant *result argument of these functions (where + applicable) should be released using NPN_ReleaseVariantValue(). +*/ +typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp, NPClass *aClass); +typedef void (*NPDeallocateFunctionPtr)(NPObject *npobj); +typedef void (*NPInvalidateFunctionPtr)(NPObject *npobj); +typedef bool (*NPHasMethodFunctionPtr)(NPObject *npobj, NPIdentifier name); +typedef bool (*NPInvokeFunctionPtr)(NPObject *npobj, NPIdentifier name, + const NPVariant *args, uint32_t argCount, + NPVariant *result); +typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj, + const NPVariant *args, + uint32_t argCount, + NPVariant *result); +typedef bool (*NPHasPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name); +typedef bool (*NPGetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name, + NPVariant *result); +typedef bool (*NPSetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name, + const NPVariant *value); +typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj, + NPIdentifier name); + +/* + NPObjects returned by create, retain, invoke, and getProperty pass + a reference count to the caller. That is, the callee adds a + reference count which passes to the caller. It is the caller's + responsibility to release the returned object. + + NPInvokeFunctionPtr function may return 0 to indicate a void + result. + + NPInvalidateFunctionPtr is called by the scripting environment + when the native code is shutdown. Any attempt to message a + NPObject instance after the invalidate callback has been + called will result in undefined behavior, even if the native code + is still retaining those NPObject instances. (The runtime + will typically return immediately, with 0 or NULL, from an attempt + to dispatch to a NPObject, but this behavior should not be + depended upon.) +*/ +struct NPClass +{ + uint32_t structVersion; + NPAllocateFunctionPtr allocate; + NPDeallocateFunctionPtr deallocate; + NPInvalidateFunctionPtr invalidate; + NPHasMethodFunctionPtr hasMethod; + NPInvokeFunctionPtr invoke; + NPInvokeDefaultFunctionPtr invokeDefault; + NPHasPropertyFunctionPtr hasProperty; + NPGetPropertyFunctionPtr getProperty; + NPSetPropertyFunctionPtr setProperty; + NPRemovePropertyFunctionPtr removeProperty; +}; + +#define NP_CLASS_STRUCT_VERSION 1 + +struct NPObject { + NPClass *_class; + uint32_t referenceCount; + /* + * Additional space may be allocated here by types of NPObjects + */ +}; + +/* + If the class has an allocate function, NPN_CreateObject invokes + that function, otherwise a NPObject is allocated and + returned. This method will initialize the referenceCount member of + the NPObject to 1. +*/ +NPObject *NPN_CreateObject(NPP npp, NPClass *aClass); + +/* + Increment the NPObject's reference count. +*/ +NPObject *NPN_RetainObject(NPObject *npobj); + +/* + Decremented the NPObject's reference count. If the reference + count goes to zero, the class's destroy function is invoke if + specified, otherwise the object is freed directly. +*/ +void NPN_ReleaseObject(NPObject *npobj); + +/* + Functions to access script objects represented by NPObject. + + Calls to script objects are synchronous. If a function returns a + value, it will be supplied via the result NPVariant + argument. Successful calls will return true, false will be + returned in case of an error. + + Calls made from plugin code to script must be made from the thread + on which the plugin was initialized. +*/ + +bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, + const NPVariant *args, uint32_t argCount, NPVariant *result); +bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args, + uint32_t argCount, NPVariant *result); +bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script, + NPVariant *result); +bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, + NPVariant *result); +bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, + const NPVariant *value); +bool NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName); +bool NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName); +bool NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName); + +/* + NPN_SetException may be called to trigger a script exception upon + return from entry points into NPObjects. Typical usage: + + NPN_SetException (npobj, message); +*/ +void NPN_SetException(NPObject *npobj, const NPUTF8 *message); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/mozilla/modules/plugin/base/public/nptypes.h b/mozilla/modules/plugin/base/public/nptypes.h new file mode 100644 index 00000000000..ffeffee5c79 --- /dev/null +++ b/mozilla/modules/plugin/base/public/nptypes.h @@ -0,0 +1,109 @@ +/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * mozilla.org. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Johnny Stenback (Original author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* + * Header file for ensuring that C99 types ([u]int32_t and bool) are + * available. + */ + +#if defined(WIN32) || defined(OS2) + /* + * Win32 and OS/2 don't know C99, so define [u]int_32 here. The bool + * is predefined tho, both in C and C++. + */ + typedef int int32_t; + typedef unsigned int uint32_t; +#elif defined(_AIX) || defined(__sun) || defined(__osf__) || defined(IRIX) || defined(HPUX) + /* + * AIX and SunOS ship a inttypes.h header that defines [u]int32_t, + * but not bool for C. + */ + #include + + #ifndef __cplusplus + typedef int bool; + #endif +#elif defined(bsdi) || defined(FREEBSD) || defined(OPENBSD) + /* + * BSD/OS, FreeBSD, and OpenBSD ship sys/types.h that define int32_t and + * u_int32_t. + */ + #include + + /* + * BSD/OS ships no header that defines uint32_t, nor bool (for C) + * OpenBSD ships no header that defines uint32_t, but provides bool as a + * macro. + */ + #if defined(bsdi) || defined(OPENBSD) + typedef u_int32_t uint32_t; + + #if defined(bsdi) + #if !defined(__cplusplus) + typedef int bool; + #endif + #else /* OPENBSD is defined, so use its bool */ + #include + #endif + #else + /* + * FreeBSD defines uint32_t and bool. + */ + #include + #include + #endif +#elif defined(BEOS) + #include +#else + /* + * For those that ship a standard C99 stdint.h header file, include + * it. Can't do the same for stdbool.h tho, since some systems ship + * with a stdbool.h file that doesn't compile! + */ + #include + + #if !defined(__GNUC__) || (__GNUC__ > 2 || __GNUC_MINOR__ > 95) + #include + #else + /* + * GCC 2.91 can't deal with a typedef for bool, but a #define + * works. + */ + #define bool int + #endif +#endif diff --git a/mozilla/modules/plugin/base/src/nsJSNPRuntime.cpp b/mozilla/modules/plugin/base/src/nsJSNPRuntime.cpp new file mode 100644 index 00000000000..0fb1fc46e34 --- /dev/null +++ b/mozilla/modules/plugin/base/src/nsJSNPRuntime.cpp @@ -0,0 +1,1360 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsJSNPRuntime.h" +#include "ns4xPlugin.h" +#include "ns4xPluginInstance.h" +#include "nsIPluginInstancePeer2.h" +#include "nsPIPluginInstancePeer.h" +#include "nsIScriptGlobalObject.h" +#include "nsIScriptContext.h" +#include "nsIDocument.h" +#include "nsIJSRuntimeService.h" +#include "nsIJSContextStack.h" +#include "prmem.h" + +// Hash of JSObject wrappers that wraps JSObjects as NPObjects. There +// will be one wrapper per JSObject per plugin instance, i.e. if two +// plugins access the JSObject x, two wrappers for x will be +// created. This is needed to be able to properly drop the wrappers +// when a plugin is torn down in case there's a leak in the plugin (we +// don't want to leak the world just because a plugin leaks an +// NPObject). +static PLDHashTable sJSObjWrappers; + +// Hash of NPObject wrappers that wrap NPObjects as JSObjects. +static PLDHashTable sNPObjWrappers; + +// Global wrapper count. This includes JSObject wrappers *and* +// NPObject wrappers. When this count goes to zero, there are no more +// wrappers and we can kill off hash tables etc. +static PRInt32 sWrapperCount; + +// The JSRuntime. Used to unroot JSObjects when no JSContext is +// reachable. +static JSRuntime *sJSRuntime; + +// The JS context stack, we use this to push a plugin's JSContext onto +// while executing JS on the context. +static nsIJSContextStack *sContextStack; + +class AutoCXPusher +{ +public: + AutoCXPusher(JSContext *cx) + { + if (sContextStack) + sContextStack->Push(cx); + } + + ~AutoCXPusher() + { + if (sContextStack) + sContextStack->Pop(nsnull); + } +}; + +NPClass nsJSObjWrapper::sJSObjWrapperNPClass = + { + NP_CLASS_STRUCT_VERSION, + nsJSObjWrapper::NP_Allocate, + nsJSObjWrapper::NP_Deallocate, + nsJSObjWrapper::NP_Invalidate, + nsJSObjWrapper::NP_HasMethod, + nsJSObjWrapper::NP_Invoke, + nsJSObjWrapper::NP_InvokeDefault, + nsJSObjWrapper::NP_HasProperty, + nsJSObjWrapper::NP_GetProperty, + nsJSObjWrapper::NP_SetProperty, + nsJSObjWrapper::NP_RemoveProperty + }; + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp); + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_DelProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp); + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_SetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp); + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_GetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp); + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, + JSObject **objp); + +JS_STATIC_DLL_CALLBACK(void) +NPObjWrapper_Finalize(JSContext *cx, JSObject *obj); + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, + jsval *rval); + +static JSClass sNPObjectJSWrapperClass = + { + "NPObject JS wrapper class", JSCLASS_HAS_PRIVATE | JSCLASS_NEW_RESOLVE, + NPObjWrapper_AddProperty, NPObjWrapper_DelProperty, + NPObjWrapper_GetProperty, NPObjWrapper_SetProperty, JS_EnumerateStub, + (JSResolveOp)NPObjWrapper_NewResolve, JS_ConvertStub, + NPObjWrapper_Finalize, nsnull, nsnull, NPObjWrapper_Call, nsnull, nsnull, + nsnull + }; + + +static void +OnWrapperCreated() +{ + if (sWrapperCount++ == 0) { + static const char rtsvc_id[] = "@mozilla.org/js/xpc/RuntimeService;1"; + nsCOMPtr rtsvc(do_GetService(rtsvc_id)); + if (!rtsvc) + return; + + rtsvc->GetRuntime(&sJSRuntime); + NS_ASSERTION(sJSRuntime != nsnull, "no JSRuntime?!"); + + CallGetService("@mozilla.org/js/xpc/ContextStack;1", &sContextStack); + } +} + +static void +OnWrapperDestroyed() +{ + NS_ASSERTION(sWrapperCount, "Whaaa, unbalanced created/destroyed calls!"); + + if (--sWrapperCount == 0) { + if (sJSObjWrappers.ops) { + NS_ASSERTION(sJSObjWrappers.entryCount == 0, "Uh, hash not empty?"); + + // No more wrappers, and our hash was initalized. Finish the + // hash to prevent leaking it. + PL_DHashTableFinish(&sJSObjWrappers); + + sJSObjWrappers.ops = nsnull; + } + + if (sNPObjWrappers.ops) { + NS_ASSERTION(sNPObjWrappers.entryCount == 0, "Uh, hash not empty?"); + + // No more wrappers, and our hash was initalized. Finish the + // hash to prevent leaking it. + PL_DHashTableFinish(&sNPObjWrappers); + + sNPObjWrappers.ops = nsnull; + } + + // No more need for this. + sJSRuntime = nsnull; + + NS_IF_RELEASE(sContextStack); + } +} + +static JSContext * +GetJSContext(NPP npp) +{ + NS_ENSURE_TRUE(npp, nsnull); + + ns4xPluginInstance *inst = (ns4xPluginInstance *)npp->ndata; + NS_ENSURE_TRUE(inst, nsnull); + + nsCOMPtr pp(do_QueryInterface(inst->Peer())); + NS_ENSURE_TRUE(pp, nsnull); + + nsCOMPtr owner; + pp->GetOwner(getter_AddRefs(owner)); + NS_ENSURE_TRUE(owner, nsnull); + + nsCOMPtr doc; + owner->GetDocument(getter_AddRefs(doc)); + NS_ENSURE_TRUE(doc, nsnull); + + nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject(); + NS_ENSURE_TRUE(sgo, nsnull); + + nsIScriptContext *scx = sgo->GetContext(); + NS_ENSURE_TRUE(scx, nsnull); + + return (JSContext *)scx->GetNativeContext(); +} + + +static NPP +LookupNPP(NPObject *npobj); + + +static jsval +NPVariantToJSVal(NPP npp, JSContext *cx, const NPVariant *variant) +{ + switch (variant->type) { + case NPVariantType_Void : + return JSVAL_VOID; + case NPVariantType_Null : + return JSVAL_NULL; + case NPVariantType_Bool : + return BOOLEAN_TO_JSVAL(NPVARIANT_TO_BOOLEAN(*variant)); + case NPVariantType_Int32 : + return INT_TO_JSVAL(NPVARIANT_TO_INT32(*variant)); + case NPVariantType_Double : + { + jsval val; + if (::JS_NewNumberValue(cx, NPVARIANT_TO_DOUBLE(*variant), &val)) { + return val; + } + + break; + } + case NPVariantType_String : + { + const NPString *s = &NPVARIANT_TO_STRING(*variant); + PRUint32 len; + PRUnichar *p = + UTF8ToNewUnicode(nsDependentCString(s->utf8characters, s->utf8length), + &len); + + JSString *str = ::JS_NewUCString(cx, (jschar *)p, len); + + if (str) { + return STRING_TO_JSVAL(str); + } + + break; + } + case NPVariantType_Object: + { + if (npp) { + JSObject *obj = + nsNPObjWrapper::GetNewOrUsed(npp, cx, NPVARIANT_TO_OBJECT(*variant)); + + if (obj) { + return OBJECT_TO_JSVAL(obj); + } + } + + NS_ERROR("Error wrapping NPObject!"); + + break; + } + default: + NS_ERROR("Unknown NPVariant type!"); + } + + NS_ERROR("Unable to convert NPVariant to jsval!"); + + return JSVAL_VOID; +} + +bool +JSValToNPVariant(NPP npp, JSContext *cx, jsval val, NPVariant *variant) +{ + NS_ASSERTION(npp, "Must have an NPP to wrap a jsval!"); + + if (JSVAL_IS_PRIMITIVE(val)) { + if (val == JSVAL_VOID) { + VOID_TO_NPVARIANT(*variant); + } else if (JSVAL_IS_NULL(val)) { + NULL_TO_NPVARIANT(*variant); + } else if (JSVAL_IS_BOOLEAN(val)) { + BOOLEAN_TO_NPVARIANT(JSVAL_TO_BOOLEAN(val), *variant); + } else if (JSVAL_IS_INT(val)) { + INT32_TO_NPVARIANT(JSVAL_TO_INT(val), *variant); + } else if (JSVAL_IS_DOUBLE(val)) { + DOUBLE_TO_NPVARIANT(*JSVAL_TO_DOUBLE(val), *variant); + } else if (JSVAL_IS_STRING(val)) { + JSString *jsstr = JSVAL_TO_STRING(val); + nsDependentString str((PRUnichar *)::JS_GetStringChars(jsstr), + ::JS_GetStringLength(jsstr)); + + PRUint32 len; + char *p = ToNewUTF8String(str, &len); + + if (!p) { + return false; + } + + STRINGN_TO_NPVARIANT(p, len, *variant); + } else { + NS_ERROR("Unknown primitive type!"); + + return false; + } + + return true; + } + + NPObject *npobj = + nsJSObjWrapper::GetNewOrUsed(npp, cx, JSVAL_TO_OBJECT(val)); + if (!npobj) { + return false; + } + + // Pass over ownership of npobj to *variant + OBJECT_TO_NPVARIANT(npobj, *variant); + + return true; +} + +static void +ThrowJSException(JSContext *cx, const char *message) +{ + const char *ex = PeekException(); + + if (ex) { + nsAutoString ucex; + + if (message) { + AppendASCIItoUTF16(message, ucex); + + AppendASCIItoUTF16(" [plugin exception: ", ucex); + } + + AppendUTF8toUTF16(ex, ucex); + + if (message) { + AppendASCIItoUTF16("].", ucex); + } + + JSString *str = ::JS_NewUCStringCopyN(cx, (jschar *)ucex.get(), + ucex.Length()); + + if (str) { + ::JS_SetPendingException(cx, STRING_TO_JSVAL(str)); + } + + PopException(); + } else { + ::JS_ReportError(cx, message); + } +} + +static JSBool +ReportExceptionIfPending(JSContext *cx) +{ + const char *ex = PeekException(); + + if (!ex) { + return JS_TRUE; + } + + ThrowJSException(cx, nsnull); + + return JS_FALSE; +} + + +nsJSObjWrapper::nsJSObjWrapper(NPP npp) + : nsJSObjWrapperKey(nsnull, npp) +{ + OnWrapperCreated(); +} + +nsJSObjWrapper::~nsJSObjWrapper() +{ + // Invalidate first, since it relies on sJSRuntime and sJSObjWrappers. + NP_Invalidate(this); + + OnWrapperDestroyed(); +} + +// static +NPObject * +nsJSObjWrapper::NP_Allocate(NPP npp, NPClass *aClass) +{ + NS_ASSERTION(aClass == &sJSObjWrapperNPClass, + "Huh, wrong class passed to NP_Allocate()!!!"); + + return new nsJSObjWrapper(npp); +} + +// static +void +nsJSObjWrapper::NP_Deallocate(NPObject *npobj) +{ + // nsJSObjWrapper::~nsJSObjWrapper() will call NP_Invalidate(). + delete (nsJSObjWrapper *)npobj; +} + +// static +void +nsJSObjWrapper::NP_Invalidate(NPObject *npobj) +{ + nsJSObjWrapper *jsnpobj = (nsJSObjWrapper *)npobj; + + if (jsnpobj && jsnpobj->mJSObj) { + // Unroot the object's JSObject + ::JS_RemoveRootRT(sJSRuntime, &jsnpobj->mJSObj); + + if (sJSObjWrappers.ops) { + // Remove the wrapper from the hash + + nsJSObjWrapperKey key(jsnpobj->mJSObj, jsnpobj->mNpp); + PL_DHashTableOperate(&sJSObjWrappers, &key, PL_DHASH_REMOVE); + } + + // Forget our reference to the JSObject. + jsnpobj->mJSObj = nsnull; + } +} + +static JSBool +GetProperty(JSContext *cx, JSObject *obj, NPIdentifier identifier, jsval *rval) +{ + jsval id = (jsval)identifier; + + AutoCXPusher pusher(cx); + + if (JSVAL_IS_STRING(id)) { + JSString *str = JSVAL_TO_STRING(id); + + return ::JS_GetUCProperty(cx, obj, ::JS_GetStringChars(str), + ::JS_GetStringLength(str), rval); + } + + NS_ASSERTION(JSVAL_IS_INT(id), "id must be either string or int!\n"); + + return ::JS_GetElement(cx, obj, JSVAL_TO_INT(id), rval); +} + +// static +bool +nsJSObjWrapper::NP_HasMethod(NPObject *npobj, NPIdentifier identifier) +{ + NPP npp = NPPStack::Peek(); + JSContext *cx = GetJSContext(npp); + + if (!cx || !npobj) { + return PR_FALSE; + } + + nsJSObjWrapper *npjsobj = (nsJSObjWrapper *)npobj; + jsval v; + JSBool ok = GetProperty(cx, npjsobj->mJSObj, identifier, &v); + + return ok && !JSVAL_IS_PRIMITIVE(v) && + ::JS_ObjectIsFunction(cx, JSVAL_TO_OBJECT(v)); +} + +static bool +doInvoke(NPObject *npobj, NPIdentifier method, const NPVariant *args, + uint32_t argCount, NPVariant *result) +{ + NPP npp = NPPStack::Peek(); + JSContext *cx = GetJSContext(npp); + + if (!cx || !npobj || !result) { + // XXX: Throw null-ptr exception + + return PR_FALSE; + } + + // Initialize *result + VOID_TO_NPVARIANT(*result); + + nsJSObjWrapper *npjsobj = (nsJSObjWrapper *)npobj; + jsval fv; + + AutoCXPusher pusher(cx); + + if ((jsval)method != JSVAL_VOID) { + if (!GetProperty(cx, npjsobj->mJSObj, method, &fv) || + ::JS_TypeOfValue(cx, fv) != JSTYPE_FUNCTION) { + return PR_FALSE; + } + } else { + fv = OBJECT_TO_JSVAL(npjsobj->mJSObj); + } + + jsval jsargs_buf[8]; + jsval *jsargs = jsargs_buf; + + if (argCount > (sizeof(jsargs_buf) / sizeof(jsval))) { + // Our stack buffer isn't large enough to hold all arguments, + // malloc a buffer. + jsargs = (jsval *)PR_Malloc(argCount * sizeof(jsval)); + + if (!jsargs) { + // XXX: throw an OOM exception! + + return PR_FALSE; + } + } + + // Convert args + for (PRUint32 i = 0; i < argCount; ++i) { + jsargs[i] = NPVariantToJSVal(npp, cx, args + i); + } + + jsval v; + JSBool ok = ::JS_CallFunctionValue(cx, npjsobj->mJSObj, fv, argCount, jsargs, + &v); + + if (jsargs != jsargs_buf) + PR_Free(jsargs); + + if (ok) + ok = JSValToNPVariant(npp, cx, v, result); + + // return ok == JS_TRUE to quiet down compiler warning, even if + // return ok is what we really want. + return ok == JS_TRUE; +} + +// static +bool +nsJSObjWrapper::NP_Invoke(NPObject *npobj, NPIdentifier method, + const NPVariant *args, uint32_t argCount, + NPVariant *result) +{ + if ((jsval)method == JSVAL_VOID) { + return PR_FALSE; + } + + return doInvoke(npobj, method, args, argCount, result); +} + +// static +bool +nsJSObjWrapper::NP_InvokeDefault(NPObject *npobj, const NPVariant *args, + uint32_t argCount, NPVariant *result) +{ + return doInvoke(npobj, (NPIdentifier)JSVAL_VOID, args, argCount, result); +} + +// static +bool +nsJSObjWrapper::NP_HasProperty(NPObject *npobj, NPIdentifier identifier) +{ + NPP npp = NPPStack::Peek(); + JSContext *cx = GetJSContext(npp); + + if (!cx || !npobj) { + // XXX: Throw null ptr exception + + return PR_FALSE; + } + + nsJSObjWrapper *npjsobj = (nsJSObjWrapper *)npobj; + jsval id = (jsval)identifier; + JSBool found, ok = JS_FALSE; + + if (JSVAL_IS_STRING(id)) { + JSString *str = JSVAL_TO_STRING(id); + + ok = ::JS_HasUCProperty(cx, npjsobj->mJSObj, ::JS_GetStringChars(str), + ::JS_GetStringLength(str), &found); + } else { + NS_ASSERTION(JSVAL_IS_INT(id), "id must be either string or int!\n"); + + ok = ::JS_HasElement(cx, npjsobj->mJSObj, JSVAL_TO_INT(id), &found); + } + + return ok && found; +} + +// static +bool +nsJSObjWrapper::NP_GetProperty(NPObject *npobj, NPIdentifier identifier, + NPVariant *result) +{ + NPP npp = NPPStack::Peek(); + JSContext *cx = GetJSContext(npp); + + if (!cx || !npobj) + return PR_FALSE; + + nsJSObjWrapper *npjsobj = (nsJSObjWrapper *)npobj; + + AutoCXPusher pusher(cx); + + jsval v; + return (GetProperty(cx, npjsobj->mJSObj, identifier, &v) && + JSValToNPVariant(npp, cx, v, result)); +} + +// static +bool +nsJSObjWrapper::NP_SetProperty(NPObject *npobj, NPIdentifier identifier, + const NPVariant *value) +{ + NPP npp = NPPStack::Peek(); + JSContext *cx = GetJSContext(npp); + + if (!cx || !npobj) + return PR_FALSE; + + nsJSObjWrapper *npjsobj = (nsJSObjWrapper *)npobj; + jsval id = (jsval)identifier; + JSBool ok = JS_FALSE; + + AutoCXPusher pusher(cx); + + jsval v = NPVariantToJSVal(npp, cx, value); + + if (JSVAL_IS_STRING(id)) { + JSString *str = JSVAL_TO_STRING(id); + + ok = ::JS_SetUCProperty(cx, npjsobj->mJSObj, ::JS_GetStringChars(str), + ::JS_GetStringLength(str), &v); + } else { + NS_ASSERTION(JSVAL_IS_INT(id), "id must be either string or int!\n"); + + ok = ::JS_SetElement(cx, npjsobj->mJSObj, JSVAL_TO_INT(id), &v); + } + + // return ok == JS_TRUE to quiet down compiler warning, even if + // return ok is what we really want. + return ok == JS_TRUE; +} + +// static +bool +nsJSObjWrapper::NP_RemoveProperty(NPObject *npobj, NPIdentifier identifier) +{ + NPP npp = NPPStack::Peek(); + JSContext *cx = GetJSContext(npp); + + if (!cx || !npobj) + return PR_FALSE; + + nsJSObjWrapper *npjsobj = (nsJSObjWrapper *)npobj; + jsval id = (jsval)identifier; + JSBool ok = JS_FALSE; + + AutoCXPusher pusher(cx); + + if (JSVAL_IS_STRING(id)) { + JSString *str = JSVAL_TO_STRING(id); + + jsval unused; + ok = ::JS_DeleteUCProperty2(cx, npjsobj->mJSObj, ::JS_GetStringChars(str), + ::JS_GetStringLength(str), &unused); + } else { + NS_ASSERTION(JSVAL_IS_INT(id), "id must be either string or int!\n"); + + ok = ::JS_DeleteElement(cx, npjsobj->mJSObj, JSVAL_TO_INT(id)); + } + + // return ok == JS_TRUE to quiet down compiler warning, even if + // return ok is what we really want. + return ok == JS_TRUE; +} + +class JSObjWrapperHashEntry : public PLDHashEntryHdr +{ +public: + nsJSObjWrapper *mJSObjWrapper; +}; + + +PR_STATIC_CALLBACK(PLDHashNumber) +JSObjWrapperHash(PLDHashTable *table, const void *key) +{ + const nsJSObjWrapperKey *e = NS_STATIC_CAST(const nsJSObjWrapperKey *, key); + + return (PLDHashNumber)((PRWord)e->mJSObj ^ (PRWord)e->mNpp) >> 2; +} + +PR_STATIC_CALLBACK(const void *) +JSObjWrapperHashGetKey(PLDHashTable *table, PLDHashEntryHdr *entry) +{ + JSObjWrapperHashEntry *e = + NS_STATIC_CAST(JSObjWrapperHashEntry *, entry); + + return NS_STATIC_CAST(nsJSObjWrapperKey *, e->mJSObjWrapper); +} + +PR_STATIC_CALLBACK(PRBool) +JSObjWrapperHashMatchEntry(PLDHashTable *table, const PLDHashEntryHdr *entry, + const void *key) +{ + const nsJSObjWrapperKey *objWrapperKey = + NS_STATIC_CAST(const nsJSObjWrapperKey *, key); + const JSObjWrapperHashEntry *e = + NS_STATIC_CAST(const JSObjWrapperHashEntry *, entry); + + return (e->mJSObjWrapper->mJSObj == objWrapperKey->mJSObj && + e->mJSObjWrapper->mNpp == objWrapperKey->mNpp); +} + + +// Look up or create an NPObject that wraps the JSObject obj. + +// static +NPObject * +nsJSObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, JSObject *obj) +{ + if (!npp) { + NS_ERROR("Null NPP passed to nsJSObjWrapper::GetNewOrUsed()!"); + + return nsnull; + } + + if (!cx) { + cx = GetJSContext(npp); + + if (!cx) { + NS_ERROR("Unable to find a JSContext in " + "nsJSObjWrapper::GetNewOrUsed()!"); + + return nsnull; + } + } + + JSClass *clazz = JS_GET_CLASS(cx, obj); + + if (clazz == &sNPObjectJSWrapperClass) { + // obj is one of our own, its private data is the NPObject we're + // looking for. + + NPObject *npobj = (NPObject *)::JS_GetPrivate(cx, obj); + + return _retainobject(npobj); + } + + if (!sJSObjWrappers.ops) { + // No hash yet (or any more), initalize it. + + static PLDHashTableOps ops = + { + PL_DHashAllocTable, + PL_DHashFreeTable, + JSObjWrapperHashGetKey, + JSObjWrapperHash, + JSObjWrapperHashMatchEntry, + PL_DHashMoveEntryStub, + PL_DHashClearEntryStub, + PL_DHashFinalizeStub + }; + + if (!PL_DHashTableInit(&sJSObjWrappers, &ops, nsnull, + sizeof(JSObjWrapperHashEntry), 16)) { + NS_ERROR("Error initializing PLDHashTable!"); + + return nsnull; + } + } + + nsJSObjWrapperKey key(obj, npp); + + JSObjWrapperHashEntry *entry = + NS_STATIC_CAST(JSObjWrapperHashEntry *, + PL_DHashTableOperate(&sJSObjWrappers, &key, PL_DHASH_ADD)); + + if (PL_DHASH_ENTRY_IS_BUSY(entry) && entry->mJSObjWrapper) { + // Found a live nsJSObjWrapper, return it. + + return _retainobject(entry->mJSObjWrapper); + } + + // No existing nsJSObjWrapper, create one. + + nsJSObjWrapper *wrapper = + (nsJSObjWrapper *)_createobject(npp, &sJSObjWrapperNPClass); + + if (!wrapper) { + // OOM? Remove the stale entry from the hash. + + PL_DHashTableRawRemove(&sJSObjWrappers, entry); + + return nsnull; + } + + wrapper->mJSObj = obj; + + entry->mJSObjWrapper = wrapper; + + NS_ASSERTION(wrapper->mNpp == npp, "nsJSObjWrapper::mNpp not initialized!"); + + // Root the JSObject, its lifetime is now tied to that of the + // NPObject. + if (!::JS_AddNamedRoot(cx, &wrapper->mJSObj, "nsJSObjWrapper::mJSObject")) { + NS_ERROR("Failed to root JSObject!"); + + _releaseobject(wrapper); + + PL_DHashTableRawRemove(&sJSObjWrappers, entry); + + return nsnull; + } + + return wrapper; +} + +static NPObject * +GetNPObject(JSContext *cx, JSObject *obj) +{ + while (JS_GET_CLASS(cx, obj) != &sNPObjectJSWrapperClass) { + obj = ::JS_GetPrototype(cx, obj); + } + + if (!obj) { + return nsnull; + } + + return (NPObject *)::JS_GetPrivate(cx, obj); +} + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_AddProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + NPObject *npobj = GetNPObject(cx, obj); + + if (!npobj || !npobj->_class || !npobj->_class->hasProperty || + !npobj->_class->hasMethod) { + ThrowJSException(cx, "Bad NPObject as private data!"); + + return JS_FALSE; + } + + // We must permit methods here since JS_DefineUCFunction() will add + // the function as a property + if (!npobj->_class->hasProperty(npobj, (NPIdentifier)id) && + !npobj->_class->hasMethod(npobj, (NPIdentifier)id)) { + ThrowJSException(cx, "Trying to add unsupported property on scriptable " + "plugin object!"); + + return JS_FALSE; + } + + return ReportExceptionIfPending(cx); +} + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_DelProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + NPObject *npobj = GetNPObject(cx, obj); + + if (!npobj || !npobj->_class || !npobj->_class->hasProperty) { + ThrowJSException(cx, "Bad NPObject as private data!"); + + return JS_FALSE; + } + + if (!npobj->_class->hasProperty(npobj, (NPIdentifier)id)) { + ThrowJSException(cx, "Trying to remove unsupported property on scriptable " + "plugin object!"); + + return JS_FALSE; + } + + return ReportExceptionIfPending(cx); +} + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_SetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + NPObject *npobj = GetNPObject(cx, obj); + + if (!npobj || !npobj->_class || !npobj->_class->hasProperty || + !npobj->_class->setProperty) { + ThrowJSException(cx, "Bad NPObject as private data!"); + + return JS_FALSE; + } + + if (!npobj->_class->hasProperty(npobj, (NPIdentifier)id)) { + ThrowJSException(cx, "Trying to set unsupported property on scriptable " + "plugin object!"); + + return JS_FALSE; + } + + // Find out what plugin (NPP) is the owner of the object we're + // manipulating, and make it own any JSObject wrappers created here. + NPP npp = LookupNPP(npobj); + + if (!npp) { + ThrowJSException(cx, "No NPP found for NPObject!"); + + return JS_FALSE; + } + + NPVariant npv; + if (!JSValToNPVariant(npp, cx, *vp, &npv)) { + ThrowJSException(cx, "Error converting jsval to NPVariant!"); + + return JS_FALSE; + } + + JSBool ok = npobj->_class->setProperty(npobj, (NPIdentifier)id, &npv); + + // Release the variant + _releasevariantvalue(&npv); + + if (!ok) { + ThrowJSException(cx, "Error setting property on scriptable plugin " + "object!"); + + return JS_FALSE; + } + + return ReportExceptionIfPending(cx); +} + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_GetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp) +{ + NPObject *npobj = GetNPObject(cx, obj); + + if (!npobj || !npobj->_class || !npobj->_class->hasProperty || + !npobj->_class->hasMethod || !npobj->_class->getProperty) { + ThrowJSException(cx, "Bad NPObject as private data!"); + + return JS_FALSE; + } + + if (npobj->_class->hasProperty(npobj, (NPIdentifier)id)) { + NPVariant npv; + VOID_TO_NPVARIANT(npv); + + if (!npobj->_class->getProperty(npobj, (NPIdentifier)id, &npv)) { + ThrowJSException(cx, "Error setting property on scriptable plugin " + "object!"); + + return JS_FALSE; + } + + // Find out what plugin (NPP) is the owner of the object we're + // manipulating, and make it own any JSObject wrappers created + // here. + NPP npp = LookupNPP(npobj); + + if (!npp) { + ThrowJSException(cx, "No NPP found for NPObject!"); + + return JS_FALSE; + } + + *vp = NPVariantToJSVal(npp, cx, &npv); + + // *vp now owns the value, release our reference. + _releasevariantvalue(&npv); + + return JS_TRUE; + } + + if (!npobj->_class->hasMethod(npobj, (NPIdentifier)id)) { + ThrowJSException(cx, "Trying to get unsupported property on scriptable " + "plugin object!"); + + return JS_FALSE; + } + + return ReportExceptionIfPending(cx); +} + +JS_STATIC_DLL_CALLBACK(JSBool) +CallNPMethod(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, + jsval *rval) +{ + while (JS_GET_CLASS(cx, obj) != &sNPObjectJSWrapperClass) { + obj = ::JS_GetPrototype(cx, obj); + } + + if (!obj) { + ThrowJSException(cx, "NPMethod called on non-NPObject wrapped JSObject!"); + + return JS_FALSE; + } + + NPObject *npobj = (NPObject *)::JS_GetPrivate(cx, obj); + + if (!npobj || !npobj->_class || !npobj->_class->invoke) { + ThrowJSException(cx, "Bad NPObject as private data!"); + + return JS_FALSE; + } + + // Find out what plugin (NPP) is the owner of the object we're + // manipulating, and make it own any JSObject wrappers created here. + NPP npp = LookupNPP(npobj); + + if (!npp) { + ThrowJSException(cx, "Error finding NPP for NPObject!"); + + return JS_FALSE; + } + + NPVariant npargs_buf[8]; + NPVariant *npargs = npargs_buf; + + if (argc > (sizeof(npargs_buf) / sizeof(NPVariant))) { + // Our stack buffer isn't large enough to hold all arguments, + // malloc a buffer. + npargs = (NPVariant *)PR_Malloc(argc * sizeof(NPVariant)); + + if (!npargs) { + ThrowJSException(cx, "Out of memory!"); + + return JS_FALSE; + } + } + + // Convert arguments + PRUint32 i; + for (i = 0; i < argc; ++i) { + if (!JSValToNPVariant(npp, cx, argv[i], npargs + i)) { + ThrowJSException(cx, "Error converting jsvals to NPVariants!"); + + return JS_FALSE; + } + } + + NPVariant v; + VOID_TO_NPVARIANT(v); + + JSObject *funobj = JSVAL_TO_OBJECT(argv[-2]); + JSBool ok; + + if (funobj != obj) { + // A obj.function() style call is made, get the method name from + // the function object. + + JSFunction *fun = (JSFunction *)::JS_GetPrivate(cx, funobj); + jsval method = STRING_TO_JSVAL(::JS_GetFunctionId(fun)); + + ok = npobj->_class->invoke(npobj, (NPIdentifier)method, npargs, argc, &v); + } else { + // obj is a callable object that is being called, no method name + // available then. Invoke the default method. + + ok = npobj->_class->invokeDefault(npobj, npargs, argc, &v); + } + + // Release arguments. + for (i = 0; i < argc; ++i) { + _releasevariantvalue(npargs + i); + } + + if (npargs != npargs_buf) { + PR_Free(npargs); + } + + if (!ok) { + ThrowJSException(cx, "Error calling method on NPObject!"); + + return JS_FALSE; + } + + *rval = NPVariantToJSVal(npp, cx, &v); + + // *rval now owns the value, release our reference. + _releasevariantvalue(&v); + + return ReportExceptionIfPending(cx); +} + + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_NewResolve(JSContext *cx, JSObject *obj, jsval id, uintN flags, + JSObject **objp) +{ + NPObject *npobj = GetNPObject(cx, obj); + + if (!npobj || !npobj->_class || !npobj->_class->hasProperty || + !npobj->_class->hasMethod) { + ThrowJSException(cx, "Bad NPObject as private data!"); + + return JS_FALSE; + } + + if (npobj->_class->hasProperty(npobj, (NPIdentifier)id)) { + JSBool ok; + + if (JSVAL_IS_STRING(id)) { + JSString *str = JSVAL_TO_STRING(id); + + ok = ::JS_DefineUCProperty(cx, obj, ::JS_GetStringChars(str), + ::JS_GetStringLength(str), JSVAL_VOID, nsnull, + nsnull, JSPROP_ENUMERATE); + } else { + ok = ::JS_DefineElement(cx, obj, JSVAL_TO_INT(id), JSVAL_VOID, nsnull, + nsnull, JSPROP_ENUMERATE); + + } + + if (!ok) { + return JS_FALSE; + } + + *objp = obj; + } else if (npobj->_class->hasMethod(npobj, (NPIdentifier)id)) { + JSString *str = nsnull; + + if (JSVAL_IS_STRING(id)) { + str = JSVAL_TO_STRING(id); + } else { + NS_ASSERTION(JSVAL_IS_INT(id), "id must be either string or int!\n"); + + str = ::JS_ValueToString(cx, id); + + if (!str) { + // OOM. The JS engine throws exceptions for us in this case. + + return JS_FALSE; + } + } + + JSFunction *fnc = + ::JS_DefineUCFunction(cx, obj, ::JS_GetStringChars(str), + ::JS_GetStringLength(str), CallNPMethod, 0, + JSPROP_ENUMERATE); + + *objp = obj; + + return fnc != nsnull; + } + + return ReportExceptionIfPending(cx); +} + +JS_STATIC_DLL_CALLBACK(void) +NPObjWrapper_Finalize(JSContext *cx, JSObject *obj) +{ + NPObject *npobj = (NPObject *)::JS_GetPrivate(cx, obj); + + if (npobj) { + if (sNPObjWrappers.ops) { + PL_DHashTableOperate(&sNPObjWrappers, npobj, PL_DHASH_REMOVE); + } + + // Let go of our NPObject + _releaseobject(npobj); + } + + OnWrapperDestroyed(); +} + +JS_STATIC_DLL_CALLBACK(JSBool) +NPObjWrapper_Call(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, + jsval *rval) +{ + return CallNPMethod(cx, JSVAL_TO_OBJECT(argv[-2]), argc, argv, rval); +} + +class NPObjWrapperHashEntry : public PLDHashEntryHdr +{ +public: + NPObject *mNPObj; // Must be the first member for the PLDHash stubs to work + JSObject *mJSObj; + NPP mNpp; +}; + + +// Look up or create a JSObject that wraps the NPObject npobj. + +// static +JSObject * +nsNPObjWrapper::GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj) +{ + if (!npobj) { + NS_ERROR("Null NPObject passed to nsNPObjWrapper::GetNewOrUsed()!"); + + return nsnull; + } + + if (npobj->_class == &nsJSObjWrapper::sJSObjWrapperNPClass) { + // npobj is one of our own, return its existing JSObject. + + return ((nsJSObjWrapper *)npobj)->mJSObj; + } + + if (!npp) { + NS_ERROR("No npp passed to nsNPObjWrapper::GetNewOrUsed()!"); + + return nsnull; + } + + if (!sNPObjWrappers.ops) { + // No hash yet (or any more), initalize it. + + if (!PL_DHashTableInit(&sNPObjWrappers, PL_DHashGetStubOps(), nsnull, + sizeof(NPObjWrapperHashEntry), 16)) { + NS_ERROR("Error initializing PLDHashTable!"); + + return nsnull; + } + } + + NPObjWrapperHashEntry *entry = + NS_STATIC_CAST(NPObjWrapperHashEntry *, + PL_DHashTableOperate(&sNPObjWrappers, npobj, + PL_DHASH_ADD)); + + if (PL_DHASH_ENTRY_IS_BUSY(entry) && entry->mJSObj) { + // Found a live NPObject wrapper, return it. + return entry->mJSObj; + } + + entry->mNPObj = npobj; + entry->mNpp = npp; + + // No existing JSObject, create one. + + JSObject *obj = ::JS_NewObject(cx, &sNPObjectJSWrapperClass, nsnull, nsnull); + + if (!obj) { + // OOM? Remove the stale entry from the hash. + + PL_DHashTableRawRemove(&sJSObjWrappers, entry); + + return nsnull; + } + + OnWrapperCreated(); + + entry->mJSObj = obj; + + if (!::JS_SetPrivate(cx, obj, npobj)) { + NS_ERROR("Error setting private NPObject data in JS wrapper!"); + + PL_DHashTableRawRemove(&sJSObjWrappers, entry); + + return nsnull; + } + + // The new JSObject now holds on to npobj + _retainobject(npobj); + + return obj; +} + + +// PLDHashTable enumeration callbacks for destruction code. +PR_STATIC_CALLBACK(PLDHashOperator) +JSObjWrapperPluginDestroyedCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, + PRUint32 number, void *arg) +{ + JSObjWrapperHashEntry *entry = (JSObjWrapperHashEntry *)hdr; + + nsJSObjWrapper *npobj = entry->mJSObjWrapper; + + if (npobj->mNpp == arg) { + // Prevent invalidate() and _releaseobject() from touching the hash + // we're enumerating. + const PLDHashTableOps *ops = table->ops; + table->ops = nsnull; + + if (npobj->_class && npobj->_class->invalidate) { + npobj->_class->invalidate(npobj); + } + + _releaseobject(npobj); + + table->ops = ops; + + return PL_DHASH_REMOVE; + } + + return PL_DHASH_NEXT; +} + +PR_STATIC_CALLBACK(PLDHashOperator) +NPObjWrapperPluginDestroyedCallback(PLDHashTable *table, PLDHashEntryHdr *hdr, + PRUint32 number, void *arg) +{ + NPObjWrapperHashEntry *entry = (NPObjWrapperHashEntry *)hdr; + + if (entry->mNpp == arg) { + NPObject *npobj = entry->mNPObj; + + if (npobj->_class && npobj->_class->invalidate) { + npobj->_class->invalidate(npobj); + } + + // Force deallocation of plugin objects since the plugin they came + // from is being torn down. + if (npobj->_class && npobj->_class->deallocate) { + npobj->_class->deallocate(npobj); + } else { + PR_Free(npobj); + } + + JSContext *cx = GetJSContext((NPP)arg); + + ::JS_SetPrivate(cx, entry->mJSObj, nsnull); + + return PL_DHASH_REMOVE; + } + + return PL_DHASH_NEXT; +} + +// static +void +nsJSNPRuntime::OnPluginDestroy(NPP npp) +{ + if (sJSObjWrappers.ops) { + PL_DHashTableEnumerate(&sJSObjWrappers, + JSObjWrapperPluginDestroyedCallback, npp); + } + + if (sNPObjWrappers.ops) { + PL_DHashTableEnumerate(&sNPObjWrappers, + NPObjWrapperPluginDestroyedCallback, npp); + } +} + + +// Find the NPP for a NPObject. +static NPP +LookupNPP(NPObject *npobj) +{ + if (npobj->_class == &nsJSObjWrapper::sJSObjWrapperNPClass) { + NS_ERROR("NPP requested for NPObject of class " + "nsJSObjWrapper::sJSObjWrapperNPClass!\n"); + + return nsnull; + } + + + + NPObjWrapperHashEntry *entry = + NS_STATIC_CAST(NPObjWrapperHashEntry *, + PL_DHashTableOperate(&sNPObjWrappers, npobj, + PL_DHASH_ADD)); + + if (PL_DHASH_ENTRY_IS_FREE(entry)) { + return nsnull; + } + + NS_ASSERTION(entry->mNpp, "Live NPObject entry w/o an NPP!"); + + return entry->mNpp; +} diff --git a/mozilla/modules/plugin/base/src/nsJSNPRuntime.h b/mozilla/modules/plugin/base/src/nsJSNPRuntime.h new file mode 100644 index 00000000000..a432299ff5a --- /dev/null +++ b/mozilla/modules/plugin/base/src/nsJSNPRuntime.h @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsJSNPRuntime_h__ +#define nsJSNPRuntime_h__ + +#include "nscore.h" +#include "jsapi.h" +#include "npapi.h" +#include "npruntime.h" +#include "pldhash.h" + +class nsJSNPRuntime +{ +public: + static void OnPluginDestroy(NPP npp); +}; + +class nsJSObjWrapperKey +{ +public: + nsJSObjWrapperKey(JSObject *obj, NPP npp) + : mJSObj(obj), mNpp(npp) + { + } + + JSObject *mJSObj; + + const NPP mNpp; +}; + +class nsJSObjWrapper : public NPObject, + public nsJSObjWrapperKey +{ +public: + static NPObject *GetNewOrUsed(NPP npp, JSContext *cx, JSObject *obj); + +protected: + nsJSObjWrapper(NPP npp); + ~nsJSObjWrapper(); + + static NPObject * NP_Allocate(NPP npp, NPClass *aClass); + static void NP_Deallocate(NPObject *obj); + static void NP_Invalidate(NPObject *obj); + static bool NP_HasMethod(NPObject *, NPIdentifier identifier); + static bool NP_Invoke(NPObject *obj, NPIdentifier method, + const NPVariant *args, uint32_t argCount, + NPVariant *result); + static bool NP_InvokeDefault(NPObject *obj, const NPVariant *args, + uint32_t argCount, NPVariant *result); + static bool NP_HasProperty(NPObject * obj, NPIdentifier property); + static bool NP_GetProperty(NPObject *obj, NPIdentifier property, + NPVariant *result); + static bool NP_SetProperty(NPObject *obj, NPIdentifier property, + const NPVariant *value); + static bool NP_RemoveProperty(NPObject *obj, NPIdentifier property); + +public: + static NPClass sJSObjWrapperNPClass; +}; + +class nsNPObjWrapper +{ +public: + static JSObject *GetNewOrUsed(NPP npp, JSContext *cx, NPObject *npobj); +}; + +bool +JSValToNPVariant(NPP npp, JSContext *cx, jsval val, NPVariant *variant); + +#endif // nsJSNPRuntime_h__ diff --git a/mozilla/netwerk/base/public/nsIAuthPromptProvider.idl b/mozilla/netwerk/base/public/nsIAuthPromptProvider.idl new file mode 100644 index 00000000000..8fc045bfb88 --- /dev/null +++ b/mozilla/netwerk/base/public/nsIAuthPromptProvider.idl @@ -0,0 +1,65 @@ +/* -*- Mode: idl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * Vladimir Vukicevic + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsISupports.idl" + +interface nsIAuthPrompt; + +[scriptable, uuid(129d3bd5-8a26-4b0b-b8a0-19fdea029196)] +interface nsIAuthPromptProvider : nsISupports +{ + /** + * Normal (non-proxy) prompt request. + */ + const PRUint32 PROMPT_NORMAL = 0; + + /** + * Proxy auth request. + */ + const PRUint32 PROMPT_PROXY = 1; + + /** + * Request a nsIAuthPrompt interface for the given prompt reason; + * @throws NS_ERROR_NOT_AVAILABLE if no prompt is allowed or + * available for the given reason. + * + * @param aPromptReason The reason for the auth prompt; + * one of @PROMPT_NORMAL or @PROMPT_PROXY + * @returns a nsIAuthPrompt interface, or throws NS_ERROR_NOT_AVAILABLE + */ + nsIAuthPrompt getAuthPrompt(in PRUint32 aPromptReason); +}; diff --git a/mozilla/security/nss/lib/ckfw/builtins/ckbiver.c b/mozilla/security/nss/lib/ckfw/builtins/ckbiver.c new file mode 100644 index 00000000000..f9b1a87ce10 --- /dev/null +++ b/mozilla/security/nss/lib/ckfw/builtins/ckbiver.c @@ -0,0 +1,58 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Netscape security libraries. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +/* Library identity and versioning */ + +#include "nssckbi.h" + +#if defined(DEBUG) +#define _DEBUG_STRING " (debug)" +#else +#define _DEBUG_STRING "" +#endif + +/* + * Version information for the 'ident' and 'what commands + * + * NOTE: the first component of the concatenated rcsid string + * must not end in a '$' to prevent rcs keyword substitution. + */ +const char __nss_builtins_rcsid[] = "$Header: NSS Builtin Trusted Root CAs " + NSS_BUILTINS_LIBRARY_VERSION _DEBUG_STRING + " " __DATE__ " " __TIME__ " $"; +const char __nss_builtins_sccsid[] = "@(#)NSS Builtin Trusted Root CAs " + NSS_BUILTINS_LIBRARY_VERSION _DEBUG_STRING + " " __DATE__ " " __TIME__; diff --git a/mozilla/security/nss/lib/ckfw/builtins/nssckbi.rc b/mozilla/security/nss/lib/ckfw/builtins/nssckbi.rc new file mode 100644 index 00000000000..1ff4fa9c1ed --- /dev/null +++ b/mozilla/security/nss/lib/ckfw/builtins/nssckbi.rc @@ -0,0 +1,97 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the Netscape security libraries. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nssckbi.h" +#include + +#define MY_LIBNAME "nssckbi" +#define MY_FILEDESCRIPTION "NSS Builtin Trusted Root CAs" + +#ifdef _DEBUG +#define MY_DEBUG_STR " (debug)" +#define MY_FILEFLAGS_1 VS_FF_DEBUG +#else +#define MY_DEBUG_STR "" +#define MY_FILEFLAGS_1 0x0L +#endif +#if NSS_BETA +#define MY_FILEFLAGS_2 MY_FILEFLAGS_1|VS_FF_PRERELEASE +#else +#define MY_FILEFLAGS_2 MY_FILEFLAGS_1 +#endif + +#ifdef WINNT +#define MY_FILEOS VOS_NT_WINDOWS32 +#else +#define MY_FILEOS VOS__WINDOWS32 +#endif + +#define MY_INTERNAL_NAME MY_LIBNAME + +///////////////////////////////////////////////////////////////////////////// +// +// Version-information resource +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION NSS_BUILTINS_LIBRARY_VERSION_MAJOR,NSS_BUILTINS_LIBRARY_VERSION_MINOR,0,0 + PRODUCTVERSION NSS_BUILTINS_LIBRARY_VERSION_MAJOR,NSS_BUILTINS_LIBRARY_VERSION_MINOR,0,0 + FILEFLAGSMASK VS_FFI_FILEFLAGSMASK + FILEFLAGS MY_FILEFLAGS_2 + FILEOS MY_FILEOS + FILETYPE VFT_DLL + FILESUBTYPE 0x0L // not used + +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904B0" // Lang=US English, CharSet=Unicode + BEGIN + VALUE "CompanyName", "Netscape Communications Corporation\0" + VALUE "FileDescription", MY_FILEDESCRIPTION MY_DEBUG_STR "\0" + VALUE "FileVersion", NSS_BUILTINS_LIBRARY_VERSION "\0" + VALUE "InternalName", MY_INTERNAL_NAME "\0" + VALUE "LegalCopyright", "Copyright \251 1994-2001 Netscape Communications Corporation\0" + VALUE "OriginalFilename", MY_INTERNAL_NAME ".dll\0" + VALUE "ProductName", "Network Security Services\0" + VALUE "ProductVersion", NSS_BUILTINS_LIBRARY_VERSION "\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END diff --git a/mozilla/widget/public/nsINativeKeyBindings.h b/mozilla/widget/public/nsINativeKeyBindings.h new file mode 100644 index 00000000000..f41151877f0 --- /dev/null +++ b/mozilla/widget/public/nsINativeKeyBindings.h @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsINativeKeyBindings_h_ +#define nsINativeKeyBindings_h_ + +#include "nsISupports.h" + +#define NS_INATIVEKEYBINDINGS_IID \ +{0x606c54e7, 0x0593, 0x4750, {0x99, 0xd9, 0x4e, 0x1b, 0xcc, 0xec, 0x98, 0xd9}} + +#define NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX \ + "@mozilla.org/widget/native-key-bindings;1?type=" + +struct nsNativeKeyEvent +{ + PRUint32 keyCode; + PRUint32 charCode; + PRBool altKey; + PRBool ctrlKey; + PRBool shiftKey; + PRBool metaKey; +}; + +class nsINativeKeyBindings : public nsISupports +{ + public: + typedef void (*DoCommandCallback)(const char *, void*); + + NS_DEFINE_STATIC_IID_ACCESSOR(NS_INATIVEKEYBINDINGS_IID) + + virtual NS_HIDDEN_(PRBool) KeyDown(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, + void *aCallbackData) = 0; + + virtual NS_HIDDEN_(PRBool) KeyPress(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, + void *aCallbackData) = 0; + + virtual NS_HIDDEN_(PRBool) KeyUp(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, + void *aCallbackData) = 0; +}; + +#endif diff --git a/mozilla/widget/src/gtk2/nsNativeKeyBindings.cpp b/mozilla/widget/src/gtk2/nsNativeKeyBindings.cpp new file mode 100644 index 00000000000..7dcc3c7af99 --- /dev/null +++ b/mozilla/widget/src/gtk2/nsNativeKeyBindings.cpp @@ -0,0 +1,296 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "nsNativeKeyBindings.h" +#include "nsString.h" +#include "nsMemory.h" +#include "nsGtkKeyUtils.h" + +#include +#include +#include +#include + +static nsINativeKeyBindings::DoCommandCallback gCurrentCallback; +static void *gCurrentCallbackData; + +// Common GtkEntry and GtkTextView signals +static void +copy_clipboard_cb(GtkWidget *w, gpointer user_data) +{ + gCurrentCallback("cmd_copy", gCurrentCallbackData); + g_signal_stop_emission_by_name(w, "copy_clipboard"); +} + +static void +cut_clipboard_cb(GtkWidget *w, gpointer user_data) +{ + gCurrentCallback("cmd_cut", gCurrentCallbackData); + g_signal_stop_emission_by_name(w, "cut_clipboard"); +} + +// GTK distinguishes between display lines (wrapped, as they appear on the +// screen) and paragraphs, which are runs of text terminated by a newline. +// We don't have this distinction, so we always use editor's notion of +// lines, which are newline-terminated. + +static const char *const sDeleteCommands[][2] = { + // backward, forward + { "cmd_deleteCharBackward", "cmd_deleteCharForward" }, // CHARS + { "cmd_deleteWordBackward", "cmd_deleteWordForward" }, // WORD_ENDS + { "cmd_deleteWordBackward", "cmd_deleteWordForward" }, // WORDS + { "cmd_deleteToBeginningOfLine", "cmd_deleteToEndOfLine" }, // LINES + { "cmd_deleteToBeginningOfLine", "cmd_deleteToEndOfLine" }, // LINE_ENDS + { "cmd_deleteToBeginningOfLine", "cmd_deleteToEndOfLine" }, // PARAGRAPH_ENDS + { "cmd_deleteToBeginningOfLine", "cmd_deleteToEndOfLine" }, // PARAGRAPHS + // This deletes from the end of the previous word to the beginning of the + // next word, but only if the caret is not in a word. + // XXX need to implement in editor + { nsnull, nsnull } // WHITESPACE +}; + +static void +delete_from_cursor_cb(GtkWidget *w, GtkDeleteType del_type, + gint count, gpointer user_data) +{ + g_signal_stop_emission_by_name(w, "delete_from_cursor"); + + PRBool forward = count > 0; + if (PRUint32(del_type) >= NS_ARRAY_LENGTH(sDeleteCommands)) { + // unsupported deletion type + return; + } + + if (del_type == GTK_DELETE_WORDS) { + // This works like word_ends, except we first move the caret to the + // beginning/end of the current word. + if (forward) { + gCurrentCallback("cmd_wordNext", gCurrentCallbackData); + gCurrentCallback("cmd_wordPrevious", gCurrentCallbackData); + } else { + gCurrentCallback("cmd_wordPrevious", gCurrentCallbackData); + gCurrentCallback("cmd_wordNext", gCurrentCallbackData); + } + } else if (del_type == GTK_DELETE_DISPLAY_LINES || + del_type == GTK_DELETE_PARAGRAPHS) { + + // This works like display_line_ends, except we first move the caret to the + // beginning/end of the current line. + if (forward) { + gCurrentCallback("cmd_beginLine", gCurrentCallbackData); + } else { + gCurrentCallback("cmd_endLine", gCurrentCallbackData); + } + } + + const char *cmd = sDeleteCommands[del_type][forward]; + if (!cmd) + return; // unsupported command + + count = PR_ABS(count); + for (int i = 0; i < count; ++i) { + gCurrentCallback(cmd, gCurrentCallbackData); + } +} + +static const char *const sMoveCommands[][2][2] = { + // non-extend { backward, forward }, extend { backward, forward } + // GTK differentiates between logical position, which is prev/next, + // and visual position, which is always left/right. + // We should fix this to work the same way for RTL text input. + { // LOGICAL_POSITIONS + { "cmd_charPrevious", "cmd_charNext" }, + { "cmd_selectCharPrevious", "cmd_selectCharNext" } + }, + { // VISUAL_POSITIONS + { "cmd_charPrevious", "cmd_charNext" }, + { "cmd_selectCharPrevious", "cmd_selectCharNext" } + }, + { // WORDS + { "cmd_wordPrevious", "cmd_wordNext" }, + { "cmd_selectWordPrevious", "cmd_selectWordNext" } + }, + { // DISPLAY_LINES + { "cmd_linePrevious", "cmd_lineNext" }, + { "cmd_selectLinePrevious", "cmd_selectLineNext" } + }, + { // DISPLAY_LINE_ENDS + { "cmd_beginLine", "cmd_endLine" }, + { "cmd_selectBeginLine", "cmd_selectEndLine" } + }, + { // PARAGRAPHS + { "cmd_linePrevious", "cmd_lineNext" }, + { "cmd_selectLinePrevious", "cmd_selectLineNext" } + }, + { // PARAGRAPH_ENDS + { "cmd_beginLine", "cmd_endLine" }, + { "cmd_selectBeginLine", "cmd_selectEndLine" } + }, + { // PAGES + { "cmd_movePageUp", "cmd_movePageDown" }, + { "cmd_selectPageUp", "cmd_selectPageDown" } + }, + { // BUFFER_ENDS + { "cmd_moveTop", "cmd_moveBottom" }, + { "cmd_selectTop", "cmd_selectBottom" } + }, + { // HORIZONTAL_PAGES (unsupported) + { nsnull, nsnull }, + { nsnull, nsnull } + } +}; + +static void +move_cursor_cb(GtkWidget *w, GtkMovementStep step, gint count, + gboolean extend_selection, gpointer user_data) +{ + g_signal_stop_emission_by_name(w, "move_cursor"); + PRBool forward = count > 0; + if (PRUint32(step) >= NS_ARRAY_LENGTH(sMoveCommands)) { + // unsupported movement type + return; + } + + const char *cmd = sMoveCommands[step][extend_selection][forward]; + if (!cmd) + return; // unsupported command + + + count = PR_ABS(count); + for (int i = 0; i < count; ++i) { + gCurrentCallback(cmd, gCurrentCallbackData); + } +} + +static void +paste_clipboard_cb(GtkWidget *w, gpointer user_data) +{ + gCurrentCallback("cmd_paste", gCurrentCallbackData); + g_signal_stop_emission_by_name(w, "paste_clipboard"); +} + +// GtkTextView-only signals +static void +select_all_cb(GtkWidget *w, gboolean select, gpointer user_data) +{ + gCurrentCallback("cmd_selectAll", gCurrentCallbackData); + g_signal_stop_emission_by_name(w, "select_all"); +} + +void +nsNativeKeyBindings::Init(NativeKeyBindingsType aType) +{ + switch (aType) { + case eKeyBindings_Input: + mNativeTarget = gtk_entry_new(); + break; + case eKeyBindings_TextArea: + mNativeTarget = gtk_text_view_new(); + g_signal_connect(G_OBJECT(mNativeTarget), "select_all", + G_CALLBACK(select_all_cb), this); + break; + } + + g_signal_connect(G_OBJECT(mNativeTarget), "copy_clipboard", + G_CALLBACK(copy_clipboard_cb), this); + g_signal_connect(G_OBJECT(mNativeTarget), "cut_clipboard", + G_CALLBACK(cut_clipboard_cb), this); + g_signal_connect(G_OBJECT(mNativeTarget), "delete_from_cursor", + G_CALLBACK(delete_from_cursor_cb), this); + g_signal_connect(G_OBJECT(mNativeTarget), "move_cursor", + G_CALLBACK(move_cursor_cb), this); + g_signal_connect(G_OBJECT(mNativeTarget), "paste_clipboard", + G_CALLBACK(paste_clipboard_cb), this); +} + +nsNativeKeyBindings::~nsNativeKeyBindings() +{ + gtk_widget_destroy(mNativeTarget); +} + +NS_IMPL_ISUPPORTS1(nsNativeKeyBindings, nsINativeKeyBindings) + +PRBool +nsNativeKeyBindings::KeyDown(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, void *aCallbackData) +{ + return PR_FALSE; +} + +PRBool +nsNativeKeyBindings::KeyPress(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, void *aCallbackData) +{ + PRUint32 keyCode; + + if (aEvent.charCode != 0) + keyCode = gdk_unicode_to_keyval(aEvent.charCode); + else + keyCode = DOMKeyCodeToGdkKeyCode(aEvent.keyCode); + + int modifiers = 0; + if (aEvent.altKey) + modifiers |= GDK_MOD1_MASK; + if (aEvent.ctrlKey) + modifiers |= GDK_CONTROL_MASK; + if (aEvent.shiftKey) + modifiers |= GDK_SHIFT_MASK; + // we don't support meta + + gCurrentCallback = aCallback; + gCurrentCallbackData = aCallbackData; + + PRBool handled = PR_FALSE; + + if (gtk_bindings_activate(GTK_OBJECT(mNativeTarget), + keyCode, GdkModifierType(modifiers))) { + handled = PR_TRUE; + } + + gCurrentCallback = nsnull; + gCurrentCallbackData = nsnull; + + return handled; +} + +PRBool +nsNativeKeyBindings::KeyUp(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, void *aCallbackData) +{ + return PR_FALSE; +} diff --git a/mozilla/widget/src/gtk2/nsNativeKeyBindings.h b/mozilla/widget/src/gtk2/nsNativeKeyBindings.h new file mode 100644 index 00000000000..3baece47055 --- /dev/null +++ b/mozilla/widget/src/gtk2/nsNativeKeyBindings.h @@ -0,0 +1,93 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is Mozilla. + * + * The Initial Developer of the Original Code is + * IBM Corporation. + * Portions created by the Initial Developer are Copyright (C) 2004 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Brian Ryner + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsNativeKeyBindings_h_ +#define nsNativeKeyBindings_h_ + +// X.h defines KeyPress +#ifdef KeyPress +#undef KeyPress +#endif + +#include "nsINativeKeyBindings.h" +#include + +enum NativeKeyBindingsType { + eKeyBindings_Input, + eKeyBindings_TextArea +}; + +#define NS_NATIVEKEYBINDINGSINPUT_CID \ +{0x5c337258, 0xa580, 0x472e, {0x86, 0x15, 0xf2, 0x77, 0xdd, 0xc5, 0xbb, 0x06}} + +#define NS_NATIVEKEYBINDINGSINPUT_CONTRACTID \ +NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "input" + +#define NS_NATIVEKEYBINDINGSTEXTAREA_CID \ +{0x2a898043, 0x180f, 0x4c8b, {0x8e, 0x54, 0x41, 0x0c, 0x7a, 0x54, 0x0f, 0x27}} + +#define NS_NATIVEKEYBINDINGSTEXTAREA_CONTRACTID \ +NS_NATIVEKEYBINDINGS_CONTRACTID_PREFIX "textarea" + +class nsNativeKeyBindings : public nsINativeKeyBindings +{ +public: + NS_HIDDEN_(void) Init(NativeKeyBindingsType aType); + + NS_DECL_ISUPPORTS + + // nsINativeKeyBindings + virtual NS_HIDDEN_(PRBool) KeyDown(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, + void *aCallbackData); + + virtual NS_HIDDEN_(PRBool) KeyPress(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, + void *aCallbackData); + + virtual NS_HIDDEN_(PRBool) KeyUp(const nsNativeKeyEvent& aEvent, + DoCommandCallback aCallback, + void *aCallbackData); + +private: + ~nsNativeKeyBindings() NS_HIDDEN; + + GtkWidget *mNativeTarget; +}; + +#endif