[webkit-changes] cvs commit: JavaScriptCore/bindings/jni
jni_class.cpp jni_class.h jni_instance.cpp jni_instance.h
Geoffrey
ggaren at opensource.apple.com
Wed Aug 10 13:51:01 PDT 2005
ggaren 05/08/10 13:51:00
Modified: . ChangeLog
bindings/jni jni_class.cpp jni_class.h jni_instance.cpp
jni_instance.h
Log:
Bug #:
Revision Changes Path
1.783 +31 -0 JavaScriptCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/JavaScriptCore/ChangeLog,v
retrieving revision 1.782
retrieving revision 1.783
diff -u -r1.782 -r1.783
--- ChangeLog 8 Aug 2005 21:14:53 -0000 1.782
+++ ChangeLog 10 Aug 2005 20:50:59 -0000 1.783
@@ -1,3 +1,34 @@
+2005-08-10 Geoffrey Garen <ggaren at apple.com>
+
+ -fixed <rdar://problem/4151132> REGRESSION: Some applet liveconnect calls
+ throws privilege exception.
+
+ Reviewed by richard and mjs.
+
+ -I removed the global static JavaClass cache, since it violated Java
+ security to cache classes between websites and applets.
+
+ * bindings/jni/jni_class.cpp:
+ -removed global static cache dictionary
+ -instance constructor and destructor now do the work that used to
+ be done by static factory methods
+ -removed obsolete functions
+ (JavaClass::JavaClass):
+ (JavaClass::~JavaClass):
+ * bindings/jni/jni_class.h:
+ -removed obsolete function declarations
+ -made copying private since it's unused and it's also not clear
+ excatly how copying would work with Java security
+ -made default construction private since it's meaningless
+ * bindings/jni/jni_instance.cpp:
+ -removed obsolete functions
+ (JavaInstance::~JavaInstance):
+ (JavaInstance::getClass):
+ * bindings/jni/jni_instance.h:
+ -made copying private since it's unused and it's also not clear
+ excatly how copying would work with Java security
+ -made default construction private since it's meaningless
+
2005-08-08 Geoffrey Garen <ggaren at apple.com>
-fixed crash caused by fix for http://bugzilla.opendarwin.org/show_bug.cgi?id=4313
1.14 +19 -84 JavaScriptCore/bindings/jni/jni_class.cpp
Index: jni_class.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/bindings/jni/jni_class.cpp,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- jni_class.cpp 1 Oct 2004 00:24:39 -0000 1.13
+++ jni_class.cpp 10 Aug 2005 20:51:00 -0000 1.14
@@ -29,10 +29,21 @@
using namespace KJS::Bindings;
-void JavaClass::_commonInit (jobject aClass)
+JavaClass::JavaClass (jobject anInstance)
{
- long i;
+ jobject aClass = callJNIObjectMethod(anInstance, "getClass", "()Ljava/lang/Class;");
+
+ if (!aClass) {
+ fprintf (stderr, "%s: unable to call getClass on instance %p\n", __PRETTY_FUNCTION__, anInstance);
+ return;
+ }
+
+ jstring className = (jstring)callJNIObjectMethod(aClass, "getName", "()Ljava/lang/String;");
+ const char *classNameC = getCharactersFromJString (className);
+ _name = strdup (classNameC);
+ releaseCharactersForJString(className, classNameC);
+ long i;
JNIEnv *env = getJNIEnv();
// Get the fields
@@ -65,7 +76,7 @@
CFRelease (methodName);
env->DeleteLocalRef (aJMethod);
}
-
+
// Get the constructors
jarray constructors = (jarray)callJNIObjectMethod (aClass, "getConstructors", "()[Ljava/lang/reflect/Constructor;");
_numConstructors = env->GetArrayLength (constructors);
@@ -77,86 +88,11 @@
}
}
-JavaClass::JavaClass (const char *className)
-{
- JNIEnv *env = getJNIEnv();
-
- _name = strdup (className);
-
- // Get the class
- jclass aClass = env->FindClass(_name);
- if (!aClass){
- fprintf (stderr, "%s: unable to find class %s\n", __PRETTY_FUNCTION__, _name);
- return;
- }
-
- _commonInit (aClass);
-
- env->DeleteLocalRef (aClass);
-}
-
-JavaClass::JavaClass (jobject aClass)
-{
- _name = 0;
- _commonInit (aClass);
-}
-
-static CFMutableDictionaryRef classesByName = 0;
-
-static void _createClassesByNameIfNecessary()
-{
- if (classesByName == 0)
- classesByName = CFDictionaryCreateMutable (NULL, 0, &kCFTypeDictionaryKeyCallBacks, NULL);
-}
-
-JavaClass *JavaClass::classForName (const char *name)
-{
- _createClassesByNameIfNecessary();
-
- CFStringRef stringName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
- JavaClass *aClass = (JavaClass *)CFDictionaryGetValue(classesByName, stringName);
- if (aClass == NULL) {
- aClass = new JavaClass (name);
- CFDictionaryAddValue (classesByName, stringName, aClass);
- }
- CFRelease (stringName);
-
- return aClass;
-}
-
-void JavaClass::setClassName (const char *n)
-{
- free ((void *)_name);
- _name = strdup(n);
-}
-
-JavaClass *JavaClass::classForInstance (jobject instance)
-{
- _createClassesByNameIfNecessary();
-
- jobject classOfInstance = callJNIObjectMethod(instance, "getClass", "()Ljava/lang/Class;");
-
- if (!classOfInstance) {
- fprintf (stderr, "%s: unable to call getClass on instance %p\n", __PRETTY_FUNCTION__, instance);
- return 0;
- }
-
- jstring className = (jstring)callJNIObjectMethod(classOfInstance, "getName", "()Ljava/lang/String;");
-
- const char *classNameC = getCharactersFromJString (className);
-
- CFStringRef stringName = CFStringCreateWithCString(NULL, classNameC, kCFStringEncodingASCII);
- JavaClass *aClass = (JavaClass *)CFDictionaryGetValue(classesByName, stringName);
- if (aClass == NULL) {
- aClass = new JavaClass (classOfInstance);
- aClass->setClassName(classNameC);
- CFDictionaryAddValue (classesByName, stringName, aClass);
- }
- CFRelease (stringName);
-
- releaseCharactersForJString(className, classNameC);
-
- return aClass;
+JavaClass::~JavaClass () {
+ free((void *)_name);
+ CFRelease (_fields);
+ CFRelease (_methods);
+ delete [] _constructors;
}
MethodList JavaClass::methodsNamed(const char *name, Instance *instance) const
@@ -169,7 +105,6 @@
return MethodList();
}
-
Field *JavaClass::fieldNamed(const char *name, Instance *instance) const
{
CFStringRef fieldName = CFStringCreateWithCString(NULL, name, kCFStringEncodingASCII);
1.10 +6 -57 JavaScriptCore/bindings/jni/jni_class.h
Index: jni_class.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/bindings/jni/jni_class.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- jni_class.h 1 Oct 2004 00:24:39 -0000 1.9
+++ jni_class.h 10 Aug 2005 20:51:00 -0000 1.10
@@ -38,63 +38,9 @@
class JavaClass : public Class
{
- // Use the public static factory methods to get instances of JavaClass.
-
-protected:
- void _commonInit (jobject aClass);
-
- JavaClass (const char *name);
-
- JavaClass (jobject aClass);
-
public:
- // Return the cached JavaClass from the class of the jobject.
- static JavaClass *classForInstance (jobject anInstance);
-
- // Return the cached JavaClass of the specified name.
- static JavaClass *classForName (const char *name);
-
- void _commonDelete() {
- free((void *)_name);
- CFRelease (_fields);
- CFRelease (_methods);
- delete [] _constructors;
- }
-
- ~JavaClass () {
- _commonDelete();
- }
-
- void _commonCopy(const JavaClass &other) {
- long i;
-
- _name = strdup (other._name);
-
- _methods = CFDictionaryCreateCopy (NULL, other._methods);
- _fields = CFDictionaryCreateCopy (NULL, other._fields);
-
- _numConstructors = other._numConstructors;
- _constructors = new JavaConstructor[_numConstructors];
- for (i = 0; i < _numConstructors; i++) {
- _constructors[i] = other._constructors[i];
- }
- }
-
- JavaClass (const JavaClass &other)
- : Class() {
- _commonCopy (other);
- };
-
- JavaClass &operator=(const JavaClass &other)
- {
- if (this == &other)
- return *this;
-
- _commonDelete();
- _commonCopy (other);
-
- return *this;
- }
+ JavaClass (jobject anInstance);
+ ~JavaClass ();
virtual const char *name() const { return _name; };
@@ -108,12 +54,15 @@
virtual long numConstructors() const { return _numConstructors; };
- void setClassName(const char *n);
bool isNumberClass() const;
bool isBooleanClass() const;
bool isStringClass() const;
private:
+ JavaClass (); // prevent default construction
+ JavaClass (const JavaClass &other); // prevent copying
+ JavaClass &operator=(const JavaClass &other); // prevent copying
+
const char *_name;
CFDictionaryRef _fields;
CFDictionaryRef _methods;
1.28 +2 -10 JavaScriptCore/bindings/jni/jni_instance.cpp
Index: jni_instance.cpp
===================================================================
RCS file: /cvs/root/JavaScriptCore/bindings/jni/jni_instance.cpp,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- jni_instance.cpp 8 Aug 2005 21:14:54 -0000 1.27
+++ jni_instance.cpp 10 Aug 2005 20:51:00 -0000 1.28
@@ -51,17 +51,9 @@
JavaInstance::~JavaInstance ()
{
_instance->deref();
+ delete _class;
}
-
-JavaInstance::JavaInstance (const JavaInstance &other) : Instance()
-{
- _instance = other._instance;
- _instance->ref();
- // Classes are kept around forever.
- _class = other._class;
-};
-
#define NUM_LOCAL_REFS 64
void JavaInstance::begin()
@@ -77,7 +69,7 @@
Class *JavaInstance::getClass() const
{
if (_class == 0)
- _class = JavaClass::classForInstance (_instance->_instance);
+ _class = new JavaClass (_instance->_instance);
return _class;
}
1.19 +4 -17 JavaScriptCore/bindings/jni/jni_instance.h
Index: jni_instance.h
===================================================================
RCS file: /cvs/root/JavaScriptCore/bindings/jni/jni_instance.h,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- jni_instance.h 8 Aug 2005 04:07:24 -0000 1.18
+++ jni_instance.h 10 Aug 2005 20:51:00 -0000 1.19
@@ -70,23 +70,6 @@
virtual Class *getClass() const;
- JavaInstance (const JavaInstance &other);
-
- JavaInstance &operator=(const JavaInstance &other){
- if (this == &other)
- return *this;
-
- JObjectWrapper *_oldInstance = _instance;
- _instance = other._instance;
- _instance->ref();
- _oldInstance->deref();
-
- // Classes are kept around forever.
- _class = other._class;
-
- return *this;
- };
-
virtual void begin();
virtual void end();
@@ -103,6 +86,10 @@
ValueImp *booleanValue() const;
private:
+ JavaInstance (); // prevent default construction
+ JavaInstance (JavaInstance &); // prevent copying
+ JavaInstance &operator=(JavaInstance &); // prevent copying
+
JObjectWrapper *_instance;
mutable JavaClass *_class;
};
More information about the webkit-changes
mailing list