diff options
author | Feng Qian <> | 2009-04-10 18:11:29 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-10 18:11:29 -0700 |
commit | 8f72e70a9fd78eec56623b3a62e68f16b7b27e28 (patch) | |
tree | 181bf9a400c30a1bf34ea6d72560e8d00111d549 /WebCore/bridge | |
parent | 7ed56f225e0ade046e1c2178977f72b2d896f196 (diff) | |
download | external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.zip external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.gz external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.bz2 |
AI 145796: Land the WebKit merge @r42026.
Automated import of CL 145796
Diffstat (limited to 'WebCore/bridge')
-rw-r--r-- | WebCore/bridge/IdentifierRep.cpp | 111 | ||||
-rw-r--r-- | WebCore/bridge/IdentifierRep.h | 74 | ||||
-rw-r--r-- | WebCore/bridge/NP_jsobject.cpp | 70 | ||||
-rw-r--r-- | WebCore/bridge/c/c_instance.cpp | 11 | ||||
-rw-r--r-- | WebCore/bridge/c/c_utility.cpp | 2 | ||||
-rw-r--r-- | WebCore/bridge/c/c_utility.h | 18 | ||||
-rw-r--r-- | WebCore/bridge/jni/jni_jsobject.mm | 8 | ||||
-rw-r--r-- | WebCore/bridge/npapi.h | 33 | ||||
-rw-r--r-- | WebCore/bridge/npruntime.cpp | 97 | ||||
-rw-r--r-- | WebCore/bridge/npruntime_internal.h | 1 | ||||
-rw-r--r-- | WebCore/bridge/qt/qt_instance.cpp | 21 | ||||
-rw-r--r-- | WebCore/bridge/qt/qt_instance.h | 10 | ||||
-rw-r--r-- | WebCore/bridge/qt/qt_runtime.cpp | 39 | ||||
-rw-r--r-- | WebCore/bridge/testbindings.mm | 2 |
14 files changed, 322 insertions, 175 deletions
diff --git a/WebCore/bridge/IdentifierRep.cpp b/WebCore/bridge/IdentifierRep.cpp new file mode 100644 index 0000000..11560e3 --- /dev/null +++ b/WebCore/bridge/IdentifierRep.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2009 Apple Inc. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. OR + * 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. + */ + +#include "config.h" +#include "IdentifierRep.h" + +#include "PlatformString.h" +#include <runtime/UString.h> +#include <wtf/HashMap.h> +#include <wtf/StdLibExtras.h> + +using namespace JSC; + +namespace WebCore { + +typedef HashSet<IdentifierRep*> IdentifierSet; + +static IdentifierSet& identifierSet() +{ + DEFINE_STATIC_LOCAL(IdentifierSet, identifierSet, ()); + return identifierSet; +} + +typedef HashMap<int, IdentifierRep*> IntIdentifierMap; + +static IntIdentifierMap& intIdentifierMap() +{ + DEFINE_STATIC_LOCAL(IntIdentifierMap, intIdentifierMap, ()); + return intIdentifierMap; +} + +IdentifierRep* IdentifierRep::get(int intID) +{ + if (intID == 0 || intID == -1) { + static IdentifierRep* negativeOneAndZeroIdentifiers[2]; + + IdentifierRep* identifier = negativeOneAndZeroIdentifiers[intID + 1]; + if (!identifier) { + identifier = new IdentifierRep(intID); + + negativeOneAndZeroIdentifiers[intID + 1] = identifier; + } + + return identifier; + } + + pair<IntIdentifierMap::iterator, bool> result = intIdentifierMap().add(intID, 0); + if (result.second) { + ASSERT(!result.first->second); + result.first->second = new IdentifierRep(intID); + + identifierSet().add(result.first->second); + } + + return result.first->second; +} + +typedef HashMap<RefPtr<JSC::UString::Rep>, IdentifierRep*> StringIdentifierMap; + +static StringIdentifierMap& stringIdentifierMap() +{ + DEFINE_STATIC_LOCAL(StringIdentifierMap, stringIdentifierMap, ()); + return stringIdentifierMap; +} + +IdentifierRep* IdentifierRep::get(const char* name) +{ + ASSERT(name); + if (!name) + return 0; + + UString string = String::fromUTF8WithLatin1Fallback(name, strlen(name)); + pair<StringIdentifierMap::iterator, bool> result = stringIdentifierMap().add(string.rep(), 0); + if (result.second) { + ASSERT(!result.first->second); + result.first->second = new IdentifierRep(name); + + identifierSet().add(result.first->second); + } + + return result.first->second; +} + +bool IdentifierRep::isValid(IdentifierRep* identifier) +{ + return identifierSet().contains(identifier); +} + +} // namespace WebCore diff --git a/WebCore/bridge/IdentifierRep.h b/WebCore/bridge/IdentifierRep.h new file mode 100644 index 0000000..8e0e0d9 --- /dev/null +++ b/WebCore/bridge/IdentifierRep.h @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2009 Apple Inc. 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. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. OR + * 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. + */ + +#ifndef IdentifierRep_h +#define IdentifierRep_h + +#include <wtf/Assertions.h> +#include <string.h> + +namespace WebCore { + +class IdentifierRep { +public: + static IdentifierRep* get(int); + static IdentifierRep* get(const char*); + + static bool isValid(IdentifierRep*); + + bool isString() const { return m_isString; } + + int number() const { return m_isString ? 0 : m_value.m_number; } + const char* string() const { return m_isString ? m_value.m_string : 0; } + +private: + IdentifierRep(int number) + : m_isString(false) + { + m_value.m_number = number; + } + + IdentifierRep(const char* name) + : m_isString(true) + { + m_value.m_string = strdup(name); + } + + ~IdentifierRep() + { + // IdentifierReps should never be deleted. + ASSERT_NOT_REACHED(); + } + + union { + const char* m_string; + int m_number; + } m_value; + bool m_isString; +}; + +} // namespace WebCore + +#endif // IdentifierRep_h diff --git a/WebCore/bridge/NP_jsobject.cpp b/WebCore/bridge/NP_jsobject.cpp index 45f9f6d..9a9cfc3 100644 --- a/WebCore/bridge/NP_jsobject.cpp +++ b/WebCore/bridge/NP_jsobject.cpp @@ -36,6 +36,7 @@ #endif // ANDROID_NPN_SETEXCEPTION #include "c_utility.h" #include "c_instance.h" +#include "IdentifierRep.h" #include "npruntime_impl.h" #include "npruntime_priv.h" #include "runtime_root.h" @@ -47,10 +48,9 @@ #include <runtime/Completion.h> #include <runtime/Completion.h> -using WebCore::String; -using WebCore::StringSourceProvider; using namespace JSC; using namespace JSC::Bindings; +using namespace WebCore; static void getListFromVariantArgs(ExecState* exec, const NPVariant* args, unsigned argCount, RootObject* rootObject, ArgList& aList) { @@ -125,9 +125,9 @@ bool _NPN_InvokeDefault(NPP, NPObject* o, const NPVariant* args, uint32_t argCou ArgList argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); - globalObject->startTimeoutCheck(); + globalObject->globalData()->timeoutChecker.start(); JSValuePtr resultV = call(exec, function, callType, callData, function, argList); - globalObject->stopTimeoutCheck(); + globalObject->globalData()->timeoutChecker.stop(); // Convert and return the result of the function call. convertValueToNPVariant(exec, resultV, result); @@ -146,8 +146,8 @@ bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant* if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); - PrivateIdentifier* i = static_cast<PrivateIdentifier*>(methodName); - if (!i->isString) + IdentifierRep* i = static_cast<IdentifierRep*>(methodName); + if (!i->isString()) return false; // Special case the "eval" method. @@ -165,7 +165,7 @@ bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant* return false; ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(false); - JSValuePtr function = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string)); + JSValuePtr function = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); CallData callData; CallType callType = function.getCallData(callData); if (callType == CallTypeNone) @@ -175,9 +175,9 @@ bool _NPN_Invoke(NPP npp, NPObject* o, NPIdentifier methodName, const NPVariant* ArgList argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); - globalObject->startTimeoutCheck(); + globalObject->globalData()->timeoutChecker.start(); JSValuePtr resultV = call(exec, function, callType, callData, obj->imp, argList); - globalObject->stopTimeoutCheck(); + globalObject->globalData()->timeoutChecker.stop(); // Convert and return the result of the function call. convertValueToNPVariant(exec, resultV, result); @@ -205,9 +205,9 @@ bool _NPN_Evaluate(NPP, NPObject* o, NPString* s, NPVariant* variant) JSLock lock(false); String scriptString = convertNPStringToUTF16(s); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); - globalObject->startTimeoutCheck(); + globalObject->globalData()->timeoutChecker.start(); Completion completion = JSC::evaluate(globalObject->globalExec(), globalObject->globalScopeChain(), makeSource(scriptString)); - globalObject->stopTimeoutCheck(); + globalObject->globalData()->timeoutChecker.stop(); ComplType type = completion.complType(); JSValuePtr result; @@ -237,14 +237,14 @@ bool _NPN_GetProperty(NPP, NPObject* o, NPIdentifier propertyName, NPVariant* va return false; ExecState* exec = rootObject->globalObject()->globalExec(); - PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName); + IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); JSLock lock(false); JSValuePtr result; - if (i->isString) - result = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string)); + if (i->isString()) + result = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); else - result = obj->imp->get(exec, i->value.number); + result = obj->imp->get(exec, i->number()); convertValueToNPVariant(exec, result, variant); exec->clearException(); @@ -272,13 +272,13 @@ bool _NPN_SetProperty(NPP, NPObject* o, NPIdentifier propertyName, const NPVaria ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(false); - PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName); + IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); - if (i->isString) { + if (i->isString()) { PutPropertySlot slot; - obj->imp->put(exec, identifierFromNPIdentifier(i->value.string), convertNPVariantToValue(exec, variant, rootObject), slot); + obj->imp->put(exec, identifierFromNPIdentifier(i->string()), convertNPVariantToValue(exec, variant, rootObject), slot); } else - obj->imp->put(exec, i->value.number, convertNPVariantToValue(exec, variant, rootObject)); + obj->imp->put(exec, i->number(), convertNPVariantToValue(exec, variant, rootObject)); exec->clearException(); return true; } @@ -299,24 +299,24 @@ bool _NPN_RemoveProperty(NPP, NPObject* o, NPIdentifier propertyName) return false; ExecState* exec = rootObject->globalObject()->globalExec(); - PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName); - if (i->isString) { - if (!obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->value.string))) { + IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); + if (i->isString()) { + if (!obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->string()))) { exec->clearException(); return false; } } else { - if (!obj->imp->hasProperty(exec, i->value.number)) { + if (!obj->imp->hasProperty(exec, i->number())) { exec->clearException(); return false; } } JSLock lock(false); - if (i->isString) - obj->imp->deleteProperty(exec, identifierFromNPIdentifier(i->value.string)); + if (i->isString()) + obj->imp->deleteProperty(exec, identifierFromNPIdentifier(i->string())); else - obj->imp->deleteProperty(exec, i->value.number); + obj->imp->deleteProperty(exec, i->number()); exec->clearException(); return true; @@ -334,15 +334,15 @@ bool _NPN_HasProperty(NPP, NPObject* o, NPIdentifier propertyName) return false; ExecState* exec = rootObject->globalObject()->globalExec(); - PrivateIdentifier* i = static_cast<PrivateIdentifier*>(propertyName); + IdentifierRep* i = static_cast<IdentifierRep*>(propertyName); JSLock lock(false); - if (i->isString) { - bool result = obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->value.string)); + if (i->isString()) { + bool result = obj->imp->hasProperty(exec, identifierFromNPIdentifier(i->string())); exec->clearException(); return result; } - bool result = obj->imp->hasProperty(exec, i->value.number); + bool result = obj->imp->hasProperty(exec, i->number()); exec->clearException(); return result; } @@ -358,8 +358,8 @@ bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName) if (o->_class == NPScriptObjectClass) { JavaScriptObject* obj = reinterpret_cast<JavaScriptObject*>(o); - PrivateIdentifier* i = static_cast<PrivateIdentifier*>(methodName); - if (!i->isString) + IdentifierRep* i = static_cast<IdentifierRep*>(methodName); + if (!i->isString()) return false; RootObject* rootObject = obj->rootObject; @@ -368,7 +368,7 @@ bool _NPN_HasMethod(NPP, NPObject* o, NPIdentifier methodName) ExecState* exec = rootObject->globalObject()->globalExec(); JSLock lock(false); - JSValuePtr func = obj->imp->get(exec, identifierFromNPIdentifier(i->value.string)); + JSValuePtr func = obj->imp->get(exec, identifierFromNPIdentifier(i->string())); exec->clearException(); return !func.isUndefined(); } @@ -451,9 +451,9 @@ bool _NPN_Construct(NPP, NPObject* o, const NPVariant* args, uint32_t argCount, ArgList argList; getListFromVariantArgs(exec, args, argCount, rootObject, argList); ProtectedPtr<JSGlobalObject> globalObject = rootObject->globalObject(); - globalObject->startTimeoutCheck(); + globalObject->globalData()->timeoutChecker.start(); JSValuePtr resultV = construct(exec, constructor, constructType, constructData, argList); - globalObject->stopTimeoutCheck(); + globalObject->globalData()->timeoutChecker.stop(); // Convert and return the result. convertValueToNPVariant(exec, resultV, result); diff --git a/WebCore/bridge/c/c_instance.cpp b/WebCore/bridge/c/c_instance.cpp index 3e6f6d6..24b881f 100644 --- a/WebCore/bridge/c/c_instance.cpp +++ b/WebCore/bridge/c/c_instance.cpp @@ -32,6 +32,7 @@ #include "c_class.h" #include "c_runtime.h" #include "c_utility.h" +#include "IdentifierRep.h" #include "npruntime_impl.h" #include "runtime_root.h" #include <runtime/ArgList.h> @@ -45,6 +46,8 @@ #include <wtf/StringExtras.h> #include <wtf/Vector.h> +using namespace WebCore; + namespace JSC { namespace Bindings { @@ -265,12 +268,12 @@ void CInstance::getPropertyNames(ExecState* exec, PropertyNameArray& nameArray) } for (uint32_t i = 0; i < count; i++) { - PrivateIdentifier* identifier = static_cast<PrivateIdentifier*>(identifiers[i]); + IdentifierRep* identifier = static_cast<IdentifierRep*>(identifiers[i]); - if (identifier->isString) - nameArray.add(identifierFromNPIdentifier(identifier->value.string)); + if (identifier->isString()) + nameArray.add(identifierFromNPIdentifier(identifier->string())); else - nameArray.add(Identifier::from(exec, identifier->value.number)); + nameArray.add(Identifier::from(exec, identifier->number())); } // FIXME: This should really call NPN_MemFree but that's in WebKit diff --git a/WebCore/bridge/c/c_utility.cpp b/WebCore/bridge/c/c_utility.cpp index 1f5ff6c..352163c 100644 --- a/WebCore/bridge/c/c_utility.cpp +++ b/WebCore/bridge/c/c_utility.cpp @@ -139,7 +139,7 @@ JSValuePtr convertNPVariantToValue(ExecState* exec, const NPVariant* variant, Ro String convertNPStringToUTF16(const NPString* string) { - return convertUTF8ToUTF16WithLatin1Fallback(string->UTF8Characters, string->UTF8Length); + return String::fromUTF8WithLatin1Fallback(string->UTF8Characters, string->UTF8Length); } Identifier identifierFromNPIdentifier(const NPUTF8* name) diff --git a/WebCore/bridge/c/c_utility.h b/WebCore/bridge/c/c_utility.h index 2efc66c..bd25e80 100644 --- a/WebCore/bridge/c/c_utility.h +++ b/WebCore/bridge/c/c_utility.h @@ -46,29 +46,11 @@ class RootObject; typedef uint16_t NPUTF16; -enum NP_ValueType { - NP_NumberValueType, - NP_StringValueType, - NP_BooleanValueType, - NP_NullValueType, - NP_UndefinedValueType, - NP_ObjectValueType, - NP_InvalidValueType -}; - WebCore::String convertNPStringToUTF16(const NPString *string); void convertValueToNPVariant(ExecState*, JSValuePtr, NPVariant* result); JSValuePtr convertNPVariantToValue(ExecState*, const NPVariant*, RootObject*); Identifier identifierFromNPIdentifier(const NPUTF8* name); -struct PrivateIdentifier { - union { - const NPUTF8* string; - int32_t number; - } value; - bool isString; -}; - } } #endif // ENABLE(NETSCAPE_PLUGIN_API) diff --git a/WebCore/bridge/jni/jni_jsobject.mm b/WebCore/bridge/jni/jni_jsobject.mm index 301d672..3689840 100644 --- a/WebCore/bridge/jni/jni_jsobject.mm +++ b/WebCore/bridge/jni/jni_jsobject.mm @@ -302,9 +302,9 @@ jobject JavaJSObject::call(jstring methodName, jobjectArray args) const // Call the function object. ArgList argList; getListFromJArray(exec, args, argList); - rootObject->globalObject()->startTimeoutCheck(); + rootObject->globalObject()->globalData()->timeoutChecker.start(); JSValuePtr result = JSC::call(exec, function, callType, callData, _imp, argList); - rootObject->globalObject()->stopTimeoutCheck(); + rootObject->globalObject()->globalData()->timeoutChecker.stop(); return convertValueToJObject(result); } @@ -321,9 +321,9 @@ jobject JavaJSObject::eval(jstring script) const if (!rootObject) return 0; - rootObject->globalObject()->startTimeoutCheck(); + rootObject->globalObject()->globalData()->timeoutChecker.start(); Completion completion = JSC::evaluate(rootObject->globalObject()->globalExec(), rootObject->globalObject()->globalScopeChain(), makeSource(JavaString(script))); - rootObject->globalObject()->stopTimeoutCheck(); + rootObject->globalObject()->globalData()->timeoutChecker.stop(); ComplType type = completion.complType(); if (type == Normal) { diff --git a/WebCore/bridge/npapi.h b/WebCore/bridge/npapi.h index e098fe0..43b701b 100644 --- a/WebCore/bridge/npapi.h +++ b/WebCore/bridge/npapi.h @@ -108,9 +108,7 @@ /*----------------------------------------------------------------------*/ #define NP_VERSION_MAJOR 0 -#define NP_VERSION_MINOR 20 - - +#define NP_VERSION_MINOR 24 /*----------------------------------------------------------------------*/ /* Definition of Basic Types */ @@ -343,13 +341,16 @@ typedef enum { */ NPPVpluginWantsAllNetworkStreams = 18, + NPPVpluginPrivateModeBool = 19, + + /* Checks to see if the plug-in would like the browser to load the "src" attribute. */ + NPPVpluginCancelSrcStream = 20, + #ifdef XP_MACOSX /* Used for negotiating drawing models */ NPPVpluginDrawingModel = 1000, /* Used for negotiating event models */ NPPVpluginEventModel = 1001, - /* The plug-in text input vtable */ - NPPVpluginTextInputFuncs = 1002, /* In the NPDrawingModelCoreAnimation drawing model, the browser asks the plug-in for a Core Animation layer. */ NPPVpluginCoreAnimationLayer = 1003 #endif @@ -383,7 +384,9 @@ typedef enum { /* Get the NPObject wrapper for the plugins DOM element. */ NPNVPluginElementNPObject = 16, - NPNVSupportsWindowless = 17 + NPNVSupportsWindowless = 17, + + NPNVprivateModeBool = 18 #ifdef XP_MACOSX , NPNVpluginDrawingModel = 1000 /* The NPDrawingModel specified by the plugin */ @@ -400,7 +403,6 @@ typedef enum { #endif , NPNVsupportsCocoaBool = 3001 /* TRUE if the browser supports the Cocoa event model */ - , NPNVbrowserTextInputFuncs = 1002 /* The browser text input vtable */ #endif /* XP_MACOSX */ #ifdef ANDROID @@ -408,6 +410,11 @@ typedef enum { #endif } NPNVariable; +typedef enum { + NPNURLVCookie = 501, + NPNURLVProxy +} NPNURLVariable; + /* * The type of a NPWindow - it specifies the type of the data structure * returned in the window field. @@ -457,6 +464,7 @@ typedef enum { NPCocoaEventFocusChanged, NPCocoaEventWindowFocusChanged, NPCocoaEventScrollWheel, + NPCocoaEventTextInput } NPCocoaEventType; typedef struct _NPNSString NPNSString; @@ -493,7 +501,10 @@ typedef struct _NPCocoaEvent { } draw; struct { NPBool hasFocus; - } focus; + } focus; + struct { + NPNSString *text; + } text; } data; } NPCocoaEvent; @@ -734,7 +745,11 @@ typedef struct NP_Port #define NPVERS_HAS_RESPONSE_HEADERS 17 #define NPVERS_HAS_NPOBJECT_ENUM 18 #define NPVERS_HAS_PLUGIN_THREAD_ASYNC_CALL 19 -#define NPVERS_MACOSX_HAS_EVENT_MODELS 20 +#define NPVERS_HAS_ALL_NETWORK_STREAMS 20 +#define NPVERS_HAS_URL_AND_AUTH_INFO 21 +#define NPVERS_HAS_PRIVATE_MODE 22 +#define NPVERS_MACOSX_HAS_EVENT_MODELS 23 +#define NPVERS_HAS_CANCEL_SRC_STREAM 24 /*----------------------------------------------------------------------*/ /* Function Prototypes */ diff --git a/WebCore/bridge/npruntime.cpp b/WebCore/bridge/npruntime.cpp index bb31c6e..ab67076 100644 --- a/WebCore/bridge/npruntime.cpp +++ b/WebCore/bridge/npruntime.cpp @@ -27,6 +27,7 @@ #if ENABLE(NETSCAPE_PLUGIN_API) +#include "IdentifierRep.h" #include "npruntime_internal.h" #include "npruntime_impl.h" #include "npruntime_priv.h" @@ -38,52 +39,11 @@ #include <wtf/HashMap.h> using namespace JSC::Bindings; - -typedef HashMap<RefPtr<JSC::UString::Rep>, PrivateIdentifier*> StringIdentifierMap; - -static StringIdentifierMap* getStringIdentifierMap() -{ - static StringIdentifierMap* stringIdentifierMap = 0; - if (!stringIdentifierMap) - stringIdentifierMap = new StringIdentifierMap; - return stringIdentifierMap; -} - -typedef HashMap<int, PrivateIdentifier*> IntIdentifierMap; - -static IntIdentifierMap* getIntIdentifierMap() -{ - static IntIdentifierMap* intIdentifierMap = 0; - if (!intIdentifierMap) - intIdentifierMap = new IntIdentifierMap; - return intIdentifierMap; -} +using namespace WebCore; NPIdentifier _NPN_GetStringIdentifier(const NPUTF8* name) { - ASSERT(name); - - if (name) { - PrivateIdentifier* identifier = 0; - - JSC::JSLock lock(false); - - identifier = getStringIdentifierMap()->get(identifierFromNPIdentifier(name).ustring().rep()); - if (identifier == 0) { - identifier = (PrivateIdentifier*)malloc(sizeof(PrivateIdentifier)); - if (!identifier) - CRASH(); - // We never release identifier names, so this dictionary will grow, as will - // the memory for the identifier name strings. - identifier->isString = true; - identifier->value.string = strdup(name); - - getStringIdentifierMap()->set(identifierFromNPIdentifier(name).ustring().rep(), identifier); - } - return (NPIdentifier)identifier; - } - - return 0; + return static_cast<NPIdentifier>(IdentifierRep::get(name)); } void _NPN_GetStringIdentifiers(const NPUTF8** names, int32_t nameCount, NPIdentifier* identifiers) @@ -91,65 +51,34 @@ void _NPN_GetStringIdentifiers(const NPUTF8** names, int32_t nameCount, NPIdenti ASSERT(names); ASSERT(identifiers); - if (names && identifiers) + if (names && identifiers) { for (int i = 0; i < nameCount; i++) identifiers[i] = _NPN_GetStringIdentifier(names[i]); + } } NPIdentifier _NPN_GetIntIdentifier(int32_t intid) { - PrivateIdentifier* identifier; - - if (intid == 0 || intid == -1) { - static PrivateIdentifier* negativeOneAndZeroIdentifiers[2]; - - identifier = negativeOneAndZeroIdentifiers[intid + 1]; - if (!identifier) { - identifier = (PrivateIdentifier*)malloc(sizeof(PrivateIdentifier)); - if (!identifier) - CRASH(); - identifier->isString = false; - identifier->value.number = intid; - - negativeOneAndZeroIdentifiers[intid + 1] = identifier; - } - } else { - identifier = getIntIdentifierMap()->get(intid); - if (!identifier) { - identifier = (PrivateIdentifier*)malloc(sizeof(PrivateIdentifier)); - if (!identifier) - CRASH(); - // We never release identifier names, so this dictionary will grow. - identifier->isString = false; - identifier->value.number = intid; - - getIntIdentifierMap()->set(intid, identifier); - } - } - return (NPIdentifier)identifier; + return static_cast<NPIdentifier>(IdentifierRep::get(intid)); } bool _NPN_IdentifierIsString(NPIdentifier identifier) { - PrivateIdentifier* i = (PrivateIdentifier*)identifier; - return i->isString; + return static_cast<IdentifierRep*>(identifier)->isString(); } NPUTF8 *_NPN_UTF8FromIdentifier(NPIdentifier identifier) { - PrivateIdentifier* i = (PrivateIdentifier*)identifier; - if (!i->isString || !i->value.string) - return NULL; - - return (NPUTF8 *)strdup(i->value.string); + const char* string = static_cast<IdentifierRep*>(identifier)->string(); + if (!string) + return 0; + + return strdup(string); } int32_t _NPN_IntFromIdentifier(NPIdentifier identifier) { - PrivateIdentifier* i = (PrivateIdentifier*)identifier; - if (i->isString) - return 0; - return i->value.number; + return static_cast<IdentifierRep*>(identifier)->number(); } void NPN_InitializeVariantWithStringCopy(NPVariant* variant, const NPString* value) diff --git a/WebCore/bridge/npruntime_internal.h b/WebCore/bridge/npruntime_internal.h index 5ccdecd..736a7f1 100644 --- a/WebCore/bridge/npruntime_internal.h +++ b/WebCore/bridge/npruntime_internal.h @@ -47,4 +47,5 @@ #undef Bool #undef FontChange #undef GrayScale + #undef NormalState #endif diff --git a/WebCore/bridge/qt/qt_instance.cpp b/WebCore/bridge/qt/qt_instance.cpp index 0848463..d2a9cc6 100644 --- a/WebCore/bridge/qt/qt_instance.cpp +++ b/WebCore/bridge/qt/qt_instance.cpp @@ -98,12 +98,13 @@ void QtRuntimeObjectImp::removeFromCache() } // QtInstance -QtInstance::QtInstance(QObject* o, PassRefPtr<RootObject> rootObject) +QtInstance::QtInstance(QObject* o, PassRefPtr<RootObject> rootObject, QScriptEngine::ValueOwnership ownership) : Instance(rootObject) , m_class(0) , m_object(o) , m_hashkey(o) , m_defaultMethod(0) + , m_ownership(ownership) { } @@ -121,9 +122,23 @@ QtInstance::~QtInstance() delete f; } m_fields.clear(); + + if (m_object) { + switch (m_ownership) { + case QScriptEngine::QtOwnership: + break; + case QScriptEngine::AutoOwnership: + if (m_object->parent()) + break; + // fall through! + case QScriptEngine::ScriptOwnership: + delete m_object; + break; + } + } } -PassRefPtr<QtInstance> QtInstance::getQtInstance(QObject* o, PassRefPtr<RootObject> rootObject) +PassRefPtr<QtInstance> QtInstance::getQtInstance(QObject* o, PassRefPtr<RootObject> rootObject, QScriptEngine::ValueOwnership ownership) { JSLock lock(false); @@ -132,7 +147,7 @@ PassRefPtr<QtInstance> QtInstance::getQtInstance(QObject* o, PassRefPtr<RootObje return instance; } - RefPtr<QtInstance> ret = QtInstance::create(o, rootObject); + RefPtr<QtInstance> ret = QtInstance::create(o, rootObject, ownership); cachedInstances.insert(o, ret.get()); return ret.release(); diff --git a/WebCore/bridge/qt/qt_instance.h b/WebCore/bridge/qt/qt_instance.h index 4cfaff8..526adb4 100644 --- a/WebCore/bridge/qt/qt_instance.h +++ b/WebCore/bridge/qt/qt_instance.h @@ -20,6 +20,7 @@ #ifndef BINDINGS_QT_INSTANCE_H_ #define BINDINGS_QT_INSTANCE_H_ +#include <QtScript/qscriptengine.h> #include "runtime.h" #include "runtime_root.h" #include <qpointer.h> @@ -59,7 +60,7 @@ public: QObject* getObject() const { return m_object; } - static PassRefPtr<QtInstance> getQtInstance(QObject*, PassRefPtr<RootObject>); + static PassRefPtr<QtInstance> getQtInstance(QObject*, PassRefPtr<RootObject>, QScriptEngine::ValueOwnership ownership); virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&); virtual void put(JSObject*, ExecState*, const Identifier&, JSValuePtr, PutPropertySlot&); @@ -67,14 +68,14 @@ public: static QtInstance* getInstance(JSObject*); private: - static PassRefPtr<QtInstance> create(QObject *instance, PassRefPtr<RootObject> rootObject) + static PassRefPtr<QtInstance> create(QObject *instance, PassRefPtr<RootObject> rootObject, QScriptEngine::ValueOwnership ownership) { - return adoptRef(new QtInstance(instance, rootObject)); + return adoptRef(new QtInstance(instance, rootObject, ownership)); } friend class QtClass; friend class QtField; - QtInstance(QObject*, PassRefPtr<RootObject>); // Factory produced only.. + QtInstance(QObject*, PassRefPtr<RootObject>, QScriptEngine::ValueOwnership ownership); // Factory produced only.. mutable QtClass* m_class; QPointer<QObject> m_object; QObject* m_hashkey; @@ -82,6 +83,7 @@ private: mutable QHash<QString, QtField*> m_fields; mutable QSet<JSValuePtr> m_children; mutable QtRuntimeMetaMethod* m_defaultMethod; + QScriptEngine::ValueOwnership m_ownership; }; } // namespace Bindings diff --git a/WebCore/bridge/qt/qt_runtime.cpp b/WebCore/bridge/qt/qt_runtime.cpp index 282de42..31b343e 100644 --- a/WebCore/bridge/qt/qt_runtime.cpp +++ b/WebCore/bridge/qt/qt_runtime.cpp @@ -24,7 +24,9 @@ #include "DateMath.h" #include "DatePrototype.h" #include "FunctionPrototype.h" +#include "Interpreter.h" #include "JSArray.h" +#include "JSByteArray.h" #include "JSDOMBinding.h" #include "JSGlobalObject.h" #include "JSLock.h" @@ -95,7 +97,8 @@ typedef enum { QObj, Object, Null, - RTArray + RTArray, + JSByteArray } JSRealType; #if defined(QTWK_RUNTIME_CONVERSION_DEBUG) || defined(QTWK_RUNTIME_MATCH_DEBUG) @@ -120,6 +123,8 @@ static JSRealType valueRealType(ExecState* exec, JSValuePtr val) return Boolean; else if (val.isNull()) return Null; + else if (isJSByteArray(&exec->globalData(), val)) + return JSByteArray; else if (val.isObject()) { JSObject *object = val.toObject(exec); if (object->inherits(&RuntimeArray::s_info)) // RuntimeArray 'inherits' from Array, but not in C++ @@ -190,6 +195,9 @@ QVariant convertValueToQVariant(ExecState* exec, JSValuePtr value, QMetaType::Ty case QObj: hint = QMetaType::QObjectStar; break; + case JSByteArray: + hint = QMetaType::QByteArray; + break; case Array: case RTArray: hint = QMetaType::QVariantList; @@ -425,12 +433,18 @@ QVariant convertValueToQVariant(ExecState* exec, JSValuePtr value, QMetaType::Ty } case QMetaType::QByteArray: { - UString ustring = value.toString(exec); - ret = QVariant(QString::fromUtf16((const ushort*)ustring.rep()->data(),ustring.size()).toLatin1()); - if (type == String) - dist = 5; - else - dist = 10; + if (type == JSByteArray) { + WTF::ByteArray* arr = asByteArray(value)->storage(); + ret = QVariant(QByteArray(reinterpret_cast<const char*>(arr->data()), arr->length())); + dist = 0; + } else { + UString ustring = value.toString(exec); + ret = QVariant(QString::fromUtf16((const ushort*)ustring.rep()->data(),ustring.size()).toLatin1()); + if (type == String) + dist = 5; + else + dist = 10; + } break; } @@ -822,14 +836,15 @@ JSValuePtr convertQVariantToValue(ExecState* exec, PassRefPtr<RootObject> root, } if (type == QMetaType::QByteArray) { - QByteArray ba = variant.value<QByteArray>(); - UString ustring(ba.constData()); - return jsString(exec, ustring); + QByteArray qtByteArray = variant.value<QByteArray>(); + WTF::RefPtr<WTF::ByteArray> wtfByteArray = WTF::ByteArray::create(qtByteArray.length()); + qMemCopy(wtfByteArray->data(), qtByteArray.constData(), qtByteArray.length()); + return new (exec) JSC::JSByteArray(exec, JSC::JSByteArray::createStructure(jsNull()), wtfByteArray.get()); } if (type == QMetaType::QObjectStar || type == QMetaType::QWidgetStar) { QObject* obj = variant.value<QObject*>(); - return QtInstance::getQtInstance(obj, root)->createRuntimeObject(exec); + return QtInstance::getQtInstance(obj, root, QScriptEngine::QtOwnership)->createRuntimeObject(exec); } if (type == QMetaType::QVariantMap) { @@ -1678,7 +1693,7 @@ void QtConnectionObject::execute(void **argv) if (m_funcObject->inherits(&JSFunction::info)) { JSFunction* fimp = static_cast<JSFunction*>(m_funcObject.get()); - JSObject* qt_sender = QtInstance::getQtInstance(sender(), ro)->createRuntimeObject(exec); + JSObject* qt_sender = QtInstance::getQtInstance(sender(), ro, QScriptEngine::QtOwnership)->createRuntimeObject(exec); JSObject* wrapper = new (exec) JSObject(JSObject::createStructure(jsNull())); PutPropertySlot slot; wrapper->put(exec, Identifier(exec, "__qt_sender__"), qt_sender, slot); diff --git a/WebCore/bridge/testbindings.mm b/WebCore/bridge/testbindings.mm index 9215c48..ca70e17 100644 --- a/WebCore/bridge/testbindings.mm +++ b/WebCore/bridge/testbindings.mm @@ -103,7 +103,7 @@ } /* -- (id)invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)args; +- (id)invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)args { NSLog (@"Call to undefined method %@", name); NSLog (@"%d args\n", [args count]); |