diff options
author | Ben Murdoch <benm@google.com> | 2011-05-13 16:23:25 +0100 |
---|---|---|
committer | Ben Murdoch <benm@google.com> | 2011-05-16 11:35:02 +0100 |
commit | 65f03d4f644ce73618e5f4f50dd694b26f55ae12 (patch) | |
tree | f478babb801e720de7bfaee23443ffe029f58731 /Source/WebKit2/Shared/Plugins | |
parent | 47de4a2fb7262c7ebdb9cd133ad2c54c187454d0 (diff) | |
download | external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.zip external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.gz external_webkit-65f03d4f644ce73618e5f4f50dd694b26f55ae12.tar.bz2 |
Merge WebKit at r75993: Initial merge by git.
Change-Id: I602bbdc3974787a3b0450456a30a7868286921c3
Diffstat (limited to 'Source/WebKit2/Shared/Plugins')
19 files changed, 2545 insertions, 0 deletions
diff --git a/Source/WebKit2/Shared/Plugins/NPIdentifierData.cpp b/Source/WebKit2/Shared/Plugins/NPIdentifierData.cpp new file mode 100644 index 0000000..51dd6be --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPIdentifierData.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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. + */ + +#if ENABLE(PLUGIN_PROCESS) + +#include "NPIdentifierData.h" + +#include "ArgumentDecoder.h" +#include "ArgumentEncoder.h" +#include "NotImplemented.h" +#include "WebCoreArgumentCoders.h" +#include <WebCore/IdentifierRep.h> + +using namespace WebCore; + +namespace WebKit { + +NPIdentifierData::NPIdentifierData() + : m_isString(false) + , m_number(0) +{ +} + + +NPIdentifierData NPIdentifierData::fromNPIdentifier(NPIdentifier npIdentifier) +{ + NPIdentifierData npIdentifierData; + + IdentifierRep* identifierRep = static_cast<IdentifierRep*>(npIdentifier); + npIdentifierData.m_isString = identifierRep->isString(); + + if (npIdentifierData.m_isString) + npIdentifierData.m_string = identifierRep->string(); + else + npIdentifierData.m_number = identifierRep->number(); + + return npIdentifierData; +} + +NPIdentifier NPIdentifierData::createNPIdentifier() const +{ + if (m_isString) + return static_cast<NPIdentifier>(IdentifierRep::get(m_string.data())); + + return static_cast<NPIdentifier>(IdentifierRep::get(m_number)); +} + +void NPIdentifierData::encode(CoreIPC::ArgumentEncoder* encoder) const +{ + encoder->encode(m_isString); + if (m_isString) + encoder->encode(m_string); + else + encoder->encodeInt32(m_number); +} + +bool NPIdentifierData::decode(CoreIPC::ArgumentDecoder* decoder, NPIdentifierData& result) +{ + if (!decoder->decode(result.m_isString)) + return false; + + if (result.m_isString) + return decoder->decode(result.m_string); + + return decoder->decodeInt32(result.m_number); +} + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) diff --git a/Source/WebKit2/Shared/Plugins/NPIdentifierData.h b/Source/WebKit2/Shared/Plugins/NPIdentifierData.h new file mode 100644 index 0000000..dbe979e --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPIdentifierData.h @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 NPIdentifierData_h +#define NPIdentifierData_h + +#if ENABLE(PLUGIN_PROCESS) + +#include <WebCore/npruntime.h> +#include <wtf/text/CString.h> + +namespace CoreIPC { + class ArgumentDecoder; + class ArgumentEncoder; +} + +namespace WebKit { + +// The CoreIPC representation of an NPIdentifier. + +class NPIdentifierData { +public: + NPIdentifierData(); + + static NPIdentifierData fromNPIdentifier(NPIdentifier); + NPIdentifier createNPIdentifier() const; + + void encode(CoreIPC::ArgumentEncoder*) const; + static bool decode(CoreIPC::ArgumentDecoder*, NPIdentifierData&); + +private: + bool m_isString; + CString m_string; + int m_number; +}; + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) + +#endif // NPIdentifierData_h diff --git a/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.cpp b/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.cpp new file mode 100644 index 0000000..013d849 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.cpp @@ -0,0 +1,245 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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. + */ + +#if ENABLE(PLUGIN_PROCESS) + +#include "NPObjectMessageReceiver.h" + +#include "NPIdentifierData.h" +#include "NPRemoteObjectMap.h" +#include "NPRuntimeUtilities.h" +#include "NPVariantData.h" + +// FIXME: This code shouldn't know about NPJSObject. +#include "NPJSObject.h" + +namespace WebKit { + +PassOwnPtr<NPObjectMessageReceiver> NPObjectMessageReceiver::create(NPRemoteObjectMap* npRemoteObjectMap, uint64_t npObjectID, NPObject* npObject) +{ + return adoptPtr(new NPObjectMessageReceiver(npRemoteObjectMap, npObjectID, npObject)); +} + +NPObjectMessageReceiver::NPObjectMessageReceiver(NPRemoteObjectMap* npRemoteObjectMap, uint64_t npObjectID, NPObject* npObject) + : m_npRemoteObjectMap(npRemoteObjectMap) + , m_npObjectID(npObjectID) + , m_npObject(npObject) + , m_shouldReleaseObjectWhenInvalidating(!NPJSObject::isNPJSObject(npObject)) +{ + retainNPObject(m_npObject); +} + +NPObjectMessageReceiver::~NPObjectMessageReceiver() +{ + m_npRemoteObjectMap->unregisterNPObject(m_npObjectID); + + // If we're invalidating the remote object map, we don't always want to release the underlying NPObject. + // One example of this is NPJSObjects in the Web process, which have already been deallocated by the plug-in view. + // FIXME: This is not the ideal way to handle this. Maybe NPObjectMessageReceiver should be notified somehow when the underlying + // NPObject is deallocated. + if (m_npRemoteObjectMap->isInvalidating() && !m_shouldReleaseObjectWhenInvalidating) + return; + + releaseNPObject(m_npObject); +} + +void NPObjectMessageReceiver::deallocate() +{ + delete this; +} + +void NPObjectMessageReceiver::hasMethod(const NPIdentifierData& methodNameData, bool& returnValue) +{ + if (!m_npObject->_class->hasMethod) { + returnValue = false; + return; + } + + returnValue = m_npObject->_class->hasMethod(m_npObject, methodNameData.createNPIdentifier()); +} + +void NPObjectMessageReceiver::invoke(const NPIdentifierData& methodNameData, const Vector<NPVariantData>& argumentsData, bool& returnValue, NPVariantData& resultData) +{ + if (!m_npObject->_class->invoke) { + returnValue = false; + return; + } + + Vector<NPVariant> arguments; + for (size_t i = 0; i < argumentsData.size(); ++i) + arguments.append(m_npRemoteObjectMap->npVariantDataToNPVariant(argumentsData[i])); + + NPVariant result; + VOID_TO_NPVARIANT(result); + + returnValue = m_npObject->_class->invoke(m_npObject, methodNameData.createNPIdentifier(), arguments.data(), arguments.size(), &result); + if (returnValue) { + // Convert the NPVariant to an NPVariantData. + resultData = m_npRemoteObjectMap->npVariantToNPVariantData(result); + } + + // Release all arguments. + for (size_t i = 0; i < argumentsData.size(); ++i) + releaseNPVariantValue(&arguments[i]); + + // And release the result. + releaseNPVariantValue(&result); +} + +void NPObjectMessageReceiver::invokeDefault(const Vector<NPVariantData>& argumentsData, bool& returnValue, NPVariantData& resultData) +{ + if (!m_npObject->_class->invokeDefault) { + returnValue = false; + return; + } + + Vector<NPVariant> arguments; + for (size_t i = 0; i < argumentsData.size(); ++i) + arguments.append(m_npRemoteObjectMap->npVariantDataToNPVariant(argumentsData[i])); + + NPVariant result; + VOID_TO_NPVARIANT(result); + + returnValue = m_npObject->_class->invokeDefault(m_npObject, arguments.data(), arguments.size(), &result); + if (returnValue) { + // Convert the NPVariant to an NPVariantData. + resultData = m_npRemoteObjectMap->npVariantToNPVariantData(result); + } + + // Release all arguments. + for (size_t i = 0; i < argumentsData.size(); ++i) + releaseNPVariantValue(&arguments[i]); + + // And release the result. + releaseNPVariantValue(&result); +} + +void NPObjectMessageReceiver::hasProperty(const NPIdentifierData& propertyNameData, bool& returnValue) +{ + if (!m_npObject->_class->hasProperty) { + returnValue = false; + return; + } + + returnValue = m_npObject->_class->hasProperty(m_npObject, propertyNameData.createNPIdentifier()); +} + +void NPObjectMessageReceiver::getProperty(const NPIdentifierData& propertyNameData, bool& returnValue, NPVariantData& resultData) +{ + if (!m_npObject->_class->getProperty) { + returnValue = false; + return; + } + + NPVariant result; + returnValue = m_npObject->_class->getProperty(m_npObject, propertyNameData.createNPIdentifier(), &result); + if (!returnValue) + return; + + // Convert the NPVariant to an NPVariantData. + resultData = m_npRemoteObjectMap->npVariantToNPVariantData(result); + + // And release the result. + releaseNPVariantValue(&result); +} + +void NPObjectMessageReceiver::setProperty(const NPIdentifierData& propertyNameData, const NPVariantData& propertyValueData, bool& returnValue) +{ + if (!m_npObject->_class->setProperty) { + returnValue = false; + return; + } + + NPVariant propertyValue = m_npRemoteObjectMap->npVariantDataToNPVariant(propertyValueData); + + // Set the property. + returnValue = m_npObject->_class->setProperty(m_npObject, propertyNameData.createNPIdentifier(), &propertyValue); + + // And release the value. + releaseNPVariantValue(&propertyValue); +} + +void NPObjectMessageReceiver::removeProperty(const NPIdentifierData& propertyNameData, bool& returnValue) +{ + if (!m_npObject->_class->removeProperty) { + returnValue = false; + return; + } + + returnValue = m_npObject->_class->removeProperty(m_npObject, propertyNameData.createNPIdentifier()); +} + +void NPObjectMessageReceiver::enumerate(bool& returnValue, Vector<NPIdentifierData>& identifiersData) +{ + if (!NP_CLASS_STRUCT_VERSION_HAS_ENUM(m_npObject->_class) || !m_npObject->_class->enumerate) { + returnValue = false; + return; + } + + NPIdentifier* identifiers = 0; + uint32_t identifierCount = 0; + + returnValue = m_npObject->_class->enumerate(m_npObject, &identifiers, &identifierCount); + if (!returnValue) + return; + + for (uint32_t i = 0; i < identifierCount; ++i) + identifiersData.append(NPIdentifierData::fromNPIdentifier(identifiers[i])); + + npnMemFree(identifiers); +} + +void NPObjectMessageReceiver::construct(const Vector<NPVariantData>& argumentsData, bool& returnValue, NPVariantData& resultData) +{ + if (!NP_CLASS_STRUCT_VERSION_HAS_CTOR(m_npObject->_class) || !m_npObject->_class->construct) { + returnValue = false; + return; + } + + Vector<NPVariant> arguments; + for (size_t i = 0; i < argumentsData.size(); ++i) + arguments.append(m_npRemoteObjectMap->npVariantDataToNPVariant(argumentsData[i])); + + NPVariant result; + VOID_TO_NPVARIANT(result); + + returnValue = m_npObject->_class->construct(m_npObject, arguments.data(), arguments.size(), &result); + if (returnValue) { + // Convert the NPVariant to an NPVariantData. + resultData = m_npRemoteObjectMap->npVariantToNPVariantData(result); + } + + // Release all arguments. + for (size_t i = 0; i < argumentsData.size(); ++i) + releaseNPVariantValue(&arguments[i]); + + // And release the result. + releaseNPVariantValue(&result); +} + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) + diff --git a/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.h b/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.h new file mode 100644 index 0000000..cfb66e1 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.h @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 NPObjectMessageReceiver_h +#define NPObjectMessageReceiver_h + +#if ENABLE(PLUGIN_PROCESS) + +#include "Connection.h" +#include <WebCore/npruntime.h> +#include <wtf/Noncopyable.h> +#include <wtf/PassOwnPtr.h> + +namespace WebKit { + +class NPIdentifierData; +class NPRemoteObjectMap; +class NPVariantData; + +class NPObjectMessageReceiver { + WTF_MAKE_NONCOPYABLE(NPObjectMessageReceiver); + +public: + static PassOwnPtr<NPObjectMessageReceiver> create(NPRemoteObjectMap* npRemoteObjectMap, uint64_t npObjectID, NPObject* npObject); + ~NPObjectMessageReceiver(); + + CoreIPC::SyncReplyMode didReceiveSyncNPObjectMessageReceiverMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*); + + NPObject* npObject() const { return m_npObject; } + +private: + NPObjectMessageReceiver(NPRemoteObjectMap* npRemoteObjectMap, uint64_t npObjectID, NPObject* npObject); + + // Message handlers. + void deallocate(); + void hasMethod(const NPIdentifierData&, bool& returnValue); + void invoke(const NPIdentifierData&, const Vector<NPVariantData>& argumentsData, bool& returnValue, NPVariantData& resultData); + void invokeDefault(const Vector<NPVariantData>& argumentsData, bool& returnValue, NPVariantData& resultData); + void hasProperty(const NPIdentifierData&, bool& returnValue); + void getProperty(const NPIdentifierData&, bool& returnValue, NPVariantData& resultData); + void setProperty(const NPIdentifierData&, const NPVariantData& propertyValueData, bool& returnValue); + void removeProperty(const NPIdentifierData&, bool& returnValue); + void enumerate(bool& returnValue, Vector<NPIdentifierData>& identifiersData); + void construct(const Vector<NPVariantData>& argumentsData, bool& returnValue, NPVariantData& resultData); + + NPRemoteObjectMap* m_npRemoteObjectMap; + uint64_t m_npObjectID; + NPObject* m_npObject; + bool m_shouldReleaseObjectWhenInvalidating; +}; + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) + + +#endif // NPObjectMessageReceiver_h diff --git a/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.messages.in b/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.messages.in new file mode 100644 index 0000000..d81ffc4 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPObjectMessageReceiver.messages.in @@ -0,0 +1,38 @@ +# Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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. + +#if ENABLE(PLUGIN_PROCESS) + +messages -> NPObjectMessageReceiver { + Deallocate() -> () + HasMethod(WebKit::NPIdentifierData methodName) -> (bool returnValue) + Invoke(WebKit::NPIdentifierData methodName, Vector<WebKit::NPVariantData> argumentsData) -> (bool returnValue, WebKit::NPVariantData resultData) + InvokeDefault(Vector<WebKit::NPVariantData> argumentsData) -> (bool returnValue, WebKit::NPVariantData resultData) + HasProperty(WebKit::NPIdentifierData propertyName) -> (bool returnValue) + GetProperty(WebKit::NPIdentifierData propertyName) -> (bool returnValue, WebKit::NPVariantData resultData) + SetProperty(WebKit::NPIdentifierData propertyName, WebKit::NPVariantData propertyValueData) -> (bool returnValue) + RemoveProperty(WebKit::NPIdentifierData propertyName) -> (bool returnValue) + Enumerate() -> (bool returnValue, Vector<WebKit::NPIdentifierData> identifiersData) + Construct(Vector<WebKit::NPVariantData> argumentsData) -> (bool returnValue, WebKit::NPVariantData resultData) +} + +#endif diff --git a/Source/WebKit2/Shared/Plugins/NPObjectProxy.cpp b/Source/WebKit2/Shared/Plugins/NPObjectProxy.cpp new file mode 100644 index 0000000..e7fc47f --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPObjectProxy.cpp @@ -0,0 +1,340 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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. + */ + +#if ENABLE(PLUGIN_PROCESS) + +#include "NPObjectProxy.h" + +#include "ArgumentCoders.h" +#include "Connection.h" +#include "NPIdentifierData.h" +#include "NPObjectMessageReceiverMessages.h" +#include "NPRemoteObjectMap.h" +#include "NPRuntimeUtilities.h" +#include "NPVariantData.h" + +namespace WebKit { + +NPObjectProxy* NPObjectProxy::create(NPRemoteObjectMap* npRemoteObjectMap, uint64_t npObjectID) +{ + NPObjectProxy* npObjectProxy = toNPObjectProxy(createNPObject(0, npClass())); + npObjectProxy->initialize(npRemoteObjectMap, npObjectID); + + return npObjectProxy; +} + +NPObjectProxy::NPObjectProxy() + : m_npRemoteObjectMap(0) + , m_npObjectID(0) +{ +} + +NPObjectProxy::~NPObjectProxy() +{ + if (!m_npRemoteObjectMap) + return; + + m_npRemoteObjectMap->npObjectProxyDestroyed(this); + m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::Deallocate(), Messages::NPObjectMessageReceiver::Deallocate::Reply(), m_npObjectID); +} + +bool NPObjectProxy::isNPObjectProxy(NPObject* npObject) +{ + return npObject->_class == npClass(); +} + +void NPObjectProxy::invalidate() +{ + ASSERT(m_npRemoteObjectMap); + + m_npRemoteObjectMap = 0; +} + +void NPObjectProxy::initialize(NPRemoteObjectMap* npRemoteObjectMap, uint64_t npObjectID) +{ + ASSERT(!m_npRemoteObjectMap); + ASSERT(!m_npObjectID); + + ASSERT(npRemoteObjectMap); + ASSERT(npObjectID); + + m_npRemoteObjectMap = npRemoteObjectMap; + m_npObjectID = npObjectID; +} + +bool NPObjectProxy::hasMethod(NPIdentifier methodName) +{ + if (!m_npRemoteObjectMap) + return false; + + NPIdentifierData methodNameData = NPIdentifierData::fromNPIdentifier(methodName); + + bool returnValue = false; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::HasMethod(methodNameData), Messages::NPObjectMessageReceiver::HasMethod::Reply(returnValue), m_npObjectID)) + return false; + + return returnValue; +} + +bool NPObjectProxy::invoke(NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) +{ + if (!m_npRemoteObjectMap) + return false; + + NPIdentifierData methodNameData = NPIdentifierData::fromNPIdentifier(methodName); + Vector<NPVariantData> argumentsData; + for (uint32_t i = 0; i < argumentCount; ++i) + argumentsData.append(m_npRemoteObjectMap->npVariantToNPVariantData(arguments[i])); + + bool returnValue = false; + NPVariantData resultData; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::Invoke(methodNameData, argumentsData), Messages::NPObjectMessageReceiver::Invoke::Reply(returnValue, resultData), m_npObjectID)) + return false; + + if (!returnValue) + return false; + + *result = m_npRemoteObjectMap->npVariantDataToNPVariant(resultData); + return true; +} + +bool NPObjectProxy::invokeDefault(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) +{ + if (!m_npRemoteObjectMap) + return false; + + Vector<NPVariantData> argumentsData; + for (uint32_t i = 0; i < argumentCount; ++i) + argumentsData.append(m_npRemoteObjectMap->npVariantToNPVariantData(arguments[i])); + + bool returnValue = false; + NPVariantData resultData; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::InvokeDefault(argumentsData), Messages::NPObjectMessageReceiver::InvokeDefault::Reply(returnValue, resultData), m_npObjectID)) + return false; + + if (!returnValue) + return false; + + *result = m_npRemoteObjectMap->npVariantDataToNPVariant(resultData); + return true; +} + +bool NPObjectProxy::hasProperty(NPIdentifier propertyName) +{ + if (!m_npRemoteObjectMap) + return false; + + NPIdentifierData propertyNameData = NPIdentifierData::fromNPIdentifier(propertyName); + + bool returnValue = false; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::HasProperty(propertyNameData), Messages::NPObjectMessageReceiver::HasProperty::Reply(returnValue), m_npObjectID)) + return false; + + return returnValue; +} + +bool NPObjectProxy::getProperty(NPIdentifier propertyName, NPVariant* result) +{ + if (!m_npRemoteObjectMap) + return false; + + NPIdentifierData propertyNameData = NPIdentifierData::fromNPIdentifier(propertyName); + + bool returnValue = false; + NPVariantData resultData; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::GetProperty(propertyNameData), Messages::NPObjectMessageReceiver::GetProperty::Reply(returnValue, resultData), m_npObjectID)) + return false; + + if (!returnValue) + return false; + + *result = m_npRemoteObjectMap->npVariantDataToNPVariant(resultData); + return true; +} + +bool NPObjectProxy::setProperty(NPIdentifier propertyName, const NPVariant* value) +{ + if (!m_npRemoteObjectMap) + return false; + + NPIdentifierData propertyNameData = NPIdentifierData::fromNPIdentifier(propertyName); + NPVariantData propertyValueData = m_npRemoteObjectMap->npVariantToNPVariantData(*value); + + bool returnValue = false; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::SetProperty(propertyNameData, propertyValueData), Messages::NPObjectMessageReceiver::SetProperty::Reply(returnValue), m_npObjectID)) + return false; + + return returnValue; +} + +bool NPObjectProxy::removeProperty(NPIdentifier propertyName) +{ + if (!m_npRemoteObjectMap) + return false; + + NPIdentifierData propertyNameData = NPIdentifierData::fromNPIdentifier(propertyName); + + bool returnValue = false; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::RemoveProperty(propertyNameData), Messages::NPObjectMessageReceiver::RemoveProperty::Reply(returnValue), m_npObjectID)) + return false; + + return returnValue; +} + +bool NPObjectProxy::enumerate(NPIdentifier** identifiers, uint32_t* identifierCount) +{ + if (!m_npRemoteObjectMap) + return false; + + bool returnValue; + Vector<NPIdentifierData> identifiersData; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::Enumerate(), Messages::NPObjectMessageReceiver::Enumerate::Reply(returnValue, identifiersData), m_npObjectID)) + return false; + + if (!returnValue) + return false; + + NPIdentifier* nameIdentifiers = npnMemNewArray<NPIdentifier>(identifiersData.size()); + + for (size_t i = 0; i < identifiersData.size(); ++i) + nameIdentifiers[i] = identifiersData[i].createNPIdentifier(); + + *identifiers = nameIdentifiers; + *identifierCount = identifiersData.size(); + return true; +} + +bool NPObjectProxy::construct(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) +{ + if (!m_npRemoteObjectMap) + return false; + + Vector<NPVariantData> argumentsData; + for (uint32_t i = 0; i < argumentCount; ++i) + argumentsData.append(m_npRemoteObjectMap->npVariantToNPVariantData(arguments[i])); + + bool returnValue = false; + NPVariantData resultData; + + if (!m_npRemoteObjectMap->connection()->sendSync(Messages::NPObjectMessageReceiver::Construct(argumentsData), Messages::NPObjectMessageReceiver::Construct::Reply(returnValue, resultData), m_npObjectID)) + return false; + + if (!returnValue) + return false; + + *result = m_npRemoteObjectMap->npVariantDataToNPVariant(resultData); + return true; +} + +NPClass* NPObjectProxy::npClass() +{ + static NPClass npClass = { + NP_CLASS_STRUCT_VERSION, + NP_Allocate, + NP_Deallocate, + 0, + NP_HasMethod, + NP_Invoke, + NP_InvokeDefault, + NP_HasProperty, + NP_GetProperty, + NP_SetProperty, + NP_RemoveProperty, + NP_Enumerate, + NP_Construct + }; + + return &npClass; +} + +NPObject* NPObjectProxy::NP_Allocate(NPP npp, NPClass*) +{ + ASSERT_UNUSED(npp, !npp); + + return new NPObjectProxy; +} + +void NPObjectProxy::NP_Deallocate(NPObject* npObject) +{ + NPObjectProxy* npObjectProxy = toNPObjectProxy(npObject); + delete npObjectProxy; +} + +bool NPObjectProxy::NP_HasMethod(NPObject* npObject, NPIdentifier methodName) +{ + return toNPObjectProxy(npObject)->hasMethod(methodName); +} + +bool NPObjectProxy::NP_Invoke(NPObject* npObject, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) +{ + return toNPObjectProxy(npObject)->invoke(methodName, arguments, argumentCount, result); +} + +bool NPObjectProxy::NP_InvokeDefault(NPObject* npObject, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) +{ + return toNPObjectProxy(npObject)->invokeDefault(arguments, argumentCount, result); +} + +bool NPObjectProxy::NP_HasProperty(NPObject* npObject, NPIdentifier propertyName) +{ + return toNPObjectProxy(npObject)->hasProperty(propertyName); +} + +bool NPObjectProxy::NP_GetProperty(NPObject* npObject, NPIdentifier propertyName, NPVariant* result) +{ + return toNPObjectProxy(npObject)->getProperty(propertyName, result); +} + +bool NPObjectProxy::NP_SetProperty(NPObject* npObject, NPIdentifier propertyName, const NPVariant* value) +{ + return toNPObjectProxy(npObject)->setProperty(propertyName, value); +} + +bool NPObjectProxy::NP_RemoveProperty(NPObject* npObject, NPIdentifier propertyName) +{ + return toNPObjectProxy(npObject)->removeProperty(propertyName); +} + +bool NPObjectProxy::NP_Enumerate(NPObject* npObject, NPIdentifier** identifiers, uint32_t* identifierCount) +{ + return toNPObjectProxy(npObject)->enumerate(identifiers, identifierCount); +} + +bool NPObjectProxy::NP_Construct(NPObject* npObject, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) +{ + return toNPObjectProxy(npObject)->construct(arguments, argumentCount, result); +} + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) diff --git a/Source/WebKit2/Shared/Plugins/NPObjectProxy.h b/Source/WebKit2/Shared/Plugins/NPObjectProxy.h new file mode 100644 index 0000000..e4c00c5 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPObjectProxy.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 NPObjectProxy_h +#define NPObjectProxy_h + +#if ENABLE(PLUGIN_PROCESS) + +#include <WebCore/npruntime.h> +#include <wtf/Noncopyable.h> + +namespace WebKit { + +class NPRemoteObjectMap; + +class NPObjectProxy : public NPObject { + WTF_MAKE_NONCOPYABLE(NPObjectProxy); + +public: + static NPObjectProxy* create(NPRemoteObjectMap* npRemoteObjectMap, uint64_t npObjectID); + + static bool isNPObjectProxy(NPObject*); + + static NPObjectProxy* toNPObjectProxy(NPObject* npObject) + { + ASSERT(isNPObjectProxy(npObject)); + return static_cast<NPObjectProxy*>(npObject); + } + + uint64_t npObjectID() const { return m_npObjectID; } + + void invalidate(); + +private: + NPObjectProxy(); + ~NPObjectProxy(); + + void initialize(NPRemoteObjectMap* npRemoteObjectMap, uint64_t npObjectID); + + bool hasMethod(NPIdentifier methodName); + bool invoke(NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result); + bool invokeDefault(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result); + bool hasProperty(NPIdentifier propertyName); + bool getProperty(NPIdentifier propertyName, NPVariant* result); + bool setProperty(NPIdentifier propertyName, const NPVariant* value); + bool removeProperty(NPIdentifier propertyName); + bool enumerate(NPIdentifier** identifiers, uint32_t* identifierCount); + bool construct(const NPVariant* arguments, uint32_t argumentCount, NPVariant* result); + + static NPClass* npClass(); + static NPObject* NP_Allocate(NPP, NPClass*); + static void NP_Deallocate(NPObject*); + static bool NP_HasMethod(NPObject*, NPIdentifier methodName); + static bool NP_Invoke(NPObject*, NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result); + static bool NP_InvokeDefault(NPObject*, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result); + static bool NP_HasProperty(NPObject*, NPIdentifier propertyName); + static bool NP_GetProperty(NPObject*, NPIdentifier propertyName, NPVariant* result); + static bool NP_SetProperty(NPObject*, NPIdentifier propertyName, const NPVariant* value); + static bool NP_RemoveProperty(NPObject*, NPIdentifier propertyName); + static bool NP_Enumerate(NPObject*, NPIdentifier** identifiers, uint32_t* identifierCount); + static bool NP_Construct(NPObject*, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result); + + NPRemoteObjectMap* m_npRemoteObjectMap; + uint64_t m_npObjectID; +}; + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) + +#endif // NPObjectProxy_h diff --git a/Source/WebKit2/Shared/Plugins/NPRemoteObjectMap.cpp b/Source/WebKit2/Shared/Plugins/NPRemoteObjectMap.cpp new file mode 100644 index 0000000..5fea618 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPRemoteObjectMap.cpp @@ -0,0 +1,221 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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. + */ + +#if ENABLE(PLUGIN_PROCESS) + +#include "NPRemoteObjectMap.h" + +#include "NPObjectMessageReceiver.h" +#include "NPObjectProxy.h" +#include "NPRuntimeUtilities.h" +#include "NPVariantData.h" +#include "NotImplemented.h" +#include <wtf/OwnPtr.h> + +namespace WebKit { + +static uint64_t generateNPObjectID() +{ + static uint64_t generateNPObjectID; + return ++generateNPObjectID; +} + +PassRefPtr<NPRemoteObjectMap> NPRemoteObjectMap::create(CoreIPC::Connection* connection) +{ + return adoptRef(new NPRemoteObjectMap(connection)); +} + +NPRemoteObjectMap::NPRemoteObjectMap(CoreIPC::Connection* connection) + : m_connection(connection) + , m_isInvalidating(false) +{ +} + +NPRemoteObjectMap::~NPRemoteObjectMap() +{ + ASSERT(m_npObjectProxies.isEmpty()); + ASSERT(m_registeredNPObjects.isEmpty()); +} + +NPObject* NPRemoteObjectMap::createNPObjectProxy(uint64_t remoteObjectID) +{ + NPObjectProxy* npObjectProxy = NPObjectProxy::create(this, remoteObjectID); + + m_npObjectProxies.add(npObjectProxy); + + return npObjectProxy; +} + +void NPRemoteObjectMap::npObjectProxyDestroyed(NPObject* npObject) +{ + ASSERT(NPObjectProxy::isNPObjectProxy(npObject)); + ASSERT(m_npObjectProxies.contains(npObject)); + + m_npObjectProxies.remove(npObject); +} + +uint64_t NPRemoteObjectMap::registerNPObject(NPObject* npObject) +{ + uint64_t npObjectID = generateNPObjectID(); + m_registeredNPObjects.set(npObjectID, NPObjectMessageReceiver::create(this, npObjectID, npObject).leakPtr()); + + return npObjectID; +} + +void NPRemoteObjectMap::unregisterNPObject(uint64_t npObjectID) +{ + m_registeredNPObjects.remove(npObjectID); +} + +NPVariantData NPRemoteObjectMap::npVariantToNPVariantData(const NPVariant& variant) +{ + switch (variant.type) { + case NPVariantType_Void: + return NPVariantData::makeVoid(); + + case NPVariantType_Null: + return NPVariantData::makeNull(); + + case NPVariantType_Bool: + return NPVariantData::makeBool(variant.value.boolValue); + + case NPVariantType_Int32: + return NPVariantData::makeInt32(variant.value.intValue); + + case NPVariantType_Double: + return NPVariantData::makeDouble(variant.value.doubleValue); + + case NPVariantType_String: + return NPVariantData::makeString(variant.value.stringValue.UTF8Characters, variant.value.stringValue.UTF8Length); + + case NPVariantType_Object: { + NPObject* npObject = variant.value.objectValue; + if (NPObjectProxy::isNPObjectProxy(npObject)) { + NPObjectProxy* npObjectProxy = NPObjectProxy::toNPObjectProxy(npObject); + + uint64_t npObjectID = npObjectProxy->npObjectID(); + + // FIXME: Under some circumstances, this might leak the NPObjectProxy object. + // Figure out how to avoid that. + retainNPObject(npObjectProxy); + return NPVariantData::makeRemoteNPObjectID(npObjectID); + } + + uint64_t npObjectID = registerNPObject(npObject); + return NPVariantData::makeLocalNPObjectID(npObjectID); + } + + } + + ASSERT_NOT_REACHED(); + return NPVariantData::makeVoid(); +} + +NPVariant NPRemoteObjectMap::npVariantDataToNPVariant(const NPVariantData& npVariantData) +{ + NPVariant npVariant; + + switch (npVariantData.type()) { + case NPVariantData::Void: + VOID_TO_NPVARIANT(npVariant); + break; + case NPVariantData::Null: + NULL_TO_NPVARIANT(npVariant); + break; + case NPVariantData::Bool: + BOOLEAN_TO_NPVARIANT(npVariantData.boolValue(), npVariant); + break; + case NPVariantData::Int32: + INT32_TO_NPVARIANT(npVariantData.int32Value(), npVariant); + break; + case NPVariantData::Double: + DOUBLE_TO_NPVARIANT(npVariantData.doubleValue(), npVariant); + break; + case NPVariantData::String: { + NPString npString = createNPString(npVariantData.stringValue()); + STRINGN_TO_NPVARIANT(npString.UTF8Characters, npString.UTF8Length, npVariant); + break; + } + case NPVariantData::LocalNPObjectID: { + uint64_t npObjectID = npVariantData.localNPObjectIDValue(); + ASSERT(npObjectID); + + NPObjectMessageReceiver* npObjectMessageReceiver = m_registeredNPObjects.get(npObjectID); + if (!npObjectMessageReceiver) { + ASSERT_NOT_REACHED(); + VOID_TO_NPVARIANT(npVariant); + break; + } + + NPObject* npObject = npObjectMessageReceiver->npObject(); + ASSERT(npObject); + + retainNPObject(npObject); + OBJECT_TO_NPVARIANT(npObject, npVariant); + break; + } + case NPVariantData::RemoteNPObjectID: { + NPObject* npObjectProxy = createNPObjectProxy(npVariantData.remoteNPObjectIDValue()); + OBJECT_TO_NPVARIANT(npObjectProxy, npVariant); + break; + } + } + + return npVariant; +} + +void NPRemoteObjectMap::invalidate() +{ + ASSERT(!m_isInvalidating); + + m_isInvalidating = true; + + Vector<NPObjectMessageReceiver*> messageReceivers; + copyValuesToVector(m_registeredNPObjects, messageReceivers); + + // Now delete all the receivers. + deleteAllValues(messageReceivers); + + ASSERT(m_registeredNPObjects.isEmpty()); + + for (HashSet<NPObject*>::const_iterator it = m_npObjectProxies.begin(), end = m_npObjectProxies.end(); it != end; ++it) + NPObjectProxy::toNPObjectProxy(*it)->invalidate(); + m_npObjectProxies.clear(); + + m_isInvalidating = false; +} + +CoreIPC::SyncReplyMode NPRemoteObjectMap::didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply) +{ + NPObjectMessageReceiver* messageReceiver = m_registeredNPObjects.get(arguments->destinationID()); + if (!messageReceiver) + return CoreIPC::AutomaticReply; + + return messageReceiver->didReceiveSyncNPObjectMessageReceiverMessage(connection, messageID, arguments, reply); +} + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) diff --git a/Source/WebKit2/Shared/Plugins/NPRemoteObjectMap.h b/Source/WebKit2/Shared/Plugins/NPRemoteObjectMap.h new file mode 100644 index 0000000..ff0bbbb --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPRemoteObjectMap.h @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 NPRemoteObjectMap_h +#define NPRemoteObjectMap_h + +#if ENABLE(PLUGIN_PROCESS) + +#include "Connection.h" +#include <WebCore/npruntime.h> +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> +#include <wtf/RefCounted.h> + +namespace WebKit { + +class NPObjectMessageReceiver; +class NPObjectProxy; +class NPVariantData; + +class NPRemoteObjectMap : public RefCounted<NPRemoteObjectMap> { +public: + static PassRefPtr<NPRemoteObjectMap> create(CoreIPC::Connection*); + ~NPRemoteObjectMap(); + + // Creates an NPObjectProxy wrapper for the remote object with the given remote object ID. + NPObject* createNPObjectProxy(uint64_t remoteObjectID); + void npObjectProxyDestroyed(NPObject*); + + // Expose the given NPObject as a remote object. Returns the objectID. + uint64_t registerNPObject(NPObject*); + void unregisterNPObject(uint64_t); + + // Given an NPVariant, creates an NPVariantData object (a CoreIPC representation of an NPVariant). + NPVariantData npVariantToNPVariantData(const NPVariant&); + + // Given an NPVariantData, creates an NPVariant object. + NPVariant npVariantDataToNPVariant(const NPVariantData&); + + CoreIPC::Connection* connection() const { return m_connection; } + bool isInvalidating() const { return m_isInvalidating; } + + void invalidate(); + + CoreIPC::SyncReplyMode didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply); + +private: + explicit NPRemoteObjectMap(CoreIPC::Connection*); + CoreIPC::Connection* m_connection; + + bool m_isInvalidating; + + // A map of NPObjectMessageReceiver classes, wrapping objects that we export to the + // other end of the connection. + HashMap<uint64_t, NPObjectMessageReceiver*> m_registeredNPObjects; + + // A set of NPObjectProxy objects associated with this map. + HashSet<NPObject*> m_npObjectProxies; +}; + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) + +#endif // NPRemoteObjectMap_h diff --git a/Source/WebKit2/Shared/Plugins/NPVariantData.cpp b/Source/WebKit2/Shared/Plugins/NPVariantData.cpp new file mode 100644 index 0000000..b100589 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPVariantData.cpp @@ -0,0 +1,190 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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. + */ + +#if ENABLE(PLUGIN_PROCESS) + +#include "NPVariantData.h" + +#include "ArgumentDecoder.h" +#include "ArgumentEncoder.h" +#include "NotImplemented.h" +#include "WebCoreArgumentCoders.h" + +namespace WebKit { + +NPVariantData::NPVariantData() + : m_type(NPVariantData::Void) + , m_boolValue(false) + , m_int32Value(0) + , m_doubleValue(0) + , m_localNPObjectIDValue(0) + , m_remoteNPObjectIDValue(0) +{ +} + +NPVariantData NPVariantData::makeVoid() +{ + return NPVariantData(); +} + +NPVariantData NPVariantData::makeNull() +{ + NPVariantData npVariantData; + + npVariantData.m_type = NPVariantData::Null; + + return npVariantData; +} + +NPVariantData NPVariantData::makeBool(bool value) +{ + NPVariantData npVariantData; + + npVariantData.m_type = NPVariantData::Bool; + npVariantData.m_boolValue = value; + + return npVariantData; +} + +NPVariantData NPVariantData::makeInt32(int32_t value) +{ + NPVariantData npVariantData; + + npVariantData.m_type = NPVariantData::Int32; + npVariantData.m_int32Value = value; + + return npVariantData; +} + +NPVariantData NPVariantData::makeDouble(double value) +{ + NPVariantData npVariantData; + + npVariantData.m_type = NPVariantData::Double; + npVariantData.m_doubleValue = value; + + return npVariantData; +} + +NPVariantData NPVariantData::makeString(const char* string, unsigned length) +{ + NPVariantData npVariantData; + + npVariantData.m_type = NPVariantData::String; + npVariantData.m_stringValue = CString(string, length); + + return npVariantData; +} + +NPVariantData NPVariantData::makeLocalNPObjectID(uint64_t value) +{ + NPVariantData npVariantData; + + npVariantData.m_type = NPVariantData::LocalNPObjectID; + npVariantData.m_localNPObjectIDValue = value; + + return npVariantData; +} + +NPVariantData NPVariantData::makeRemoteNPObjectID(uint64_t value) +{ + NPVariantData npVariantData; + + npVariantData.m_type = NPVariantData::RemoteNPObjectID; + npVariantData.m_remoteNPObjectIDValue = value; + + return npVariantData; +} + +void NPVariantData::encode(CoreIPC::ArgumentEncoder* encoder) const +{ + encoder->encode(m_type); + + switch (type()) { + case NPVariantData::Void: + case NPVariantData::Null: + break; + case NPVariantData::Bool: + encoder->encode(boolValue()); + break; + case NPVariantData::Int32: + encoder->encode(int32Value()); + break; + case NPVariantData::Double: + encoder->encode(doubleValue()); + break; + case NPVariantData::String: + encoder->encode(stringValue()); + break; + case NPVariantData::LocalNPObjectID: + encoder->encode(localNPObjectIDValue()); + break; + case NPVariantData::RemoteNPObjectID: + encoder->encode(remoteNPObjectIDValue()); + break; + } +} + +bool NPVariantData::decode(CoreIPC::ArgumentDecoder* decoder, NPVariantData& result) +{ + uint32_t type; + if (!decoder->decode(type)) + return false; + + // We special-case LocalNPObjectID and RemoteNPObjectID here so a LocalNPObjectID is + // decoded as a RemoteNPObjectID and vice versa. + // This is done because the type is from the perspective of the other connection, and + // thus we have to adjust it to match our own perspective. + if (type == NPVariantData::LocalNPObjectID) + type = NPVariantData::RemoteNPObjectID; + else if (type == NPVariantData::RemoteNPObjectID) + type = NPVariantData::LocalNPObjectID; + + result.m_type = type; + + switch (result.m_type) { + case NPVariantData::Void: + case NPVariantData::Null: + return true; + case NPVariantData::Bool: + return decoder->decode(result.m_boolValue); + case NPVariantData::Int32: + return decoder->decode(result.m_int32Value); + case NPVariantData::Double: + return decoder->decode(result.m_doubleValue); + case NPVariantData::String: + return decoder->decode(result.m_stringValue); + case NPVariantData::LocalNPObjectID: + return decoder->decode(result.m_localNPObjectIDValue); + case NPVariantData::RemoteNPObjectID: + return decoder->decode(result.m_remoteNPObjectIDValue); + } + + return false; +} + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) diff --git a/Source/WebKit2/Shared/Plugins/NPVariantData.h b/Source/WebKit2/Shared/Plugins/NPVariantData.h new file mode 100644 index 0000000..805640e --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/NPVariantData.h @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 NPVariantData_h +#define NPVariantData_h + +#if ENABLE(PLUGIN_PROCESS) + +#include <wtf/text/CString.h> + +namespace CoreIPC { + class ArgumentDecoder; + class ArgumentEncoder; +} + +namespace WebKit { + +// The CoreIPC representation of an NPVariant. + +class NPVariantData { +public: + enum Type { + Void, + Null, + Bool, + Int32, + Double, + String, + LocalNPObjectID, + RemoteNPObjectID, + }; + NPVariantData(); + + static NPVariantData makeVoid(); + static NPVariantData makeNull(); + static NPVariantData makeBool(bool value); + static NPVariantData makeInt32(int32_t value); + static NPVariantData makeDouble(double value); + static NPVariantData makeString(const char* string, unsigned length); + static NPVariantData makeLocalNPObjectID(uint64_t value); + static NPVariantData makeRemoteNPObjectID(uint64_t value); + + Type type() const { return static_cast<Type>(m_type); } + + bool boolValue() const + { + ASSERT(type() == NPVariantData::Bool); + return m_boolValue; + } + + int32_t int32Value() const + { + ASSERT(type() == NPVariantData::Int32); + return m_int32Value; + } + + double doubleValue() const + { + ASSERT(type() == NPVariantData::Double); + return m_doubleValue; + } + + const CString& stringValue() const + { + ASSERT(type() == NPVariantData::String); + return m_stringValue; + } + + uint64_t localNPObjectIDValue() const + { + ASSERT(type() == NPVariantData::LocalNPObjectID); + return m_localNPObjectIDValue; + } + + uint64_t remoteNPObjectIDValue() const + { + ASSERT(type() == NPVariantData::RemoteNPObjectID); + return m_remoteNPObjectIDValue; + } + + void encode(CoreIPC::ArgumentEncoder*) const; + static bool decode(CoreIPC::ArgumentDecoder*, NPVariantData&); + +private: + uint32_t m_type; + bool m_boolValue; + int32_t m_int32Value; + double m_doubleValue; + CString m_stringValue; + uint64_t m_localNPObjectIDValue; + uint64_t m_remoteNPObjectIDValue; +}; + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) + +#endif // NPVariantData_h diff --git a/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.cpp b/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.cpp new file mode 100644 index 0000000..fec00b3 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.cpp @@ -0,0 +1,173 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 "NetscapePluginModule.h" + +#include "Module.h" +#include "NetscapeBrowserFuncs.h" +#include <wtf/PassOwnPtr.h> + +namespace WebKit { + +static Vector<NetscapePluginModule*>& initializedNetscapePluginModules() +{ + DEFINE_STATIC_LOCAL(Vector<NetscapePluginModule*>, initializedNetscapePluginModules, ()); + return initializedNetscapePluginModules; +} + +NetscapePluginModule::NetscapePluginModule(const String& pluginPath) + : m_pluginPath(pluginPath) + , m_isInitialized(false) + , m_pluginCount(0) + , m_shutdownProcPtr(0) + , m_pluginFuncs() +{ +} + +NetscapePluginModule::~NetscapePluginModule() +{ + ASSERT(initializedNetscapePluginModules().find(this) == notFound); +} + +void NetscapePluginModule::pluginCreated() +{ + if (!m_pluginCount) { + // Load the plug-in module if necessary. + load(); + } + + m_pluginCount++; +} + +void NetscapePluginModule::pluginDestroyed() +{ + ASSERT(m_pluginCount > 0); + m_pluginCount--; + + if (!m_pluginCount) { + shutdown(); + unload(); + } +} + +void NetscapePluginModule::shutdown() +{ + ASSERT(m_isInitialized); + + m_shutdownProcPtr(); + + m_isInitialized = false; + + size_t pluginModuleIndex = initializedNetscapePluginModules().find(this); + ASSERT(pluginModuleIndex != notFound); + + initializedNetscapePluginModules().remove(pluginModuleIndex); +} + +PassRefPtr<NetscapePluginModule> NetscapePluginModule::getOrCreate(const String& pluginPath) +{ + // First, see if we already have a module with this plug-in path. + for (size_t i = 0; i < initializedNetscapePluginModules().size(); ++i) { + NetscapePluginModule* pluginModule = initializedNetscapePluginModules()[i]; + + if (pluginModule->m_pluginPath == pluginPath) + return pluginModule; + } + + RefPtr<NetscapePluginModule> pluginModule(adoptRef(new NetscapePluginModule(pluginPath))); + + // Try to load and initialize the plug-in module. + if (!pluginModule->load()) + return 0; + + return pluginModule.release(); +} + +bool NetscapePluginModule::load() +{ + if (m_isInitialized) { + ASSERT(initializedNetscapePluginModules().find(this) != notFound); + return true; + } + + if (!tryLoad()) { + unload(); + return false; + } + + m_isInitialized = true; + + ASSERT(initializedNetscapePluginModules().find(this) == notFound); + initializedNetscapePluginModules().append(this); + + determineQuirks(); + + return true; +} + +bool NetscapePluginModule::tryLoad() +{ + m_module = adoptPtr(new Module(m_pluginPath)); + if (!m_module->load()) + return false; + + NP_InitializeFuncPtr initializeFuncPtr = m_module->functionPointer<NP_InitializeFuncPtr>("NP_Initialize"); + if (!initializeFuncPtr) + return false; + + NP_GetEntryPointsFuncPtr getEntryPointsFuncPtr = m_module->functionPointer<NP_GetEntryPointsFuncPtr>("NP_GetEntryPoints"); + if (!getEntryPointsFuncPtr) + return false; + + m_shutdownProcPtr = m_module->functionPointer<NPP_ShutdownProcPtr>("NP_Shutdown"); + if (!m_shutdownProcPtr) + return false; + + m_pluginFuncs.size = sizeof(NPPluginFuncs); + m_pluginFuncs.version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; + + // On Mac, NP_Initialize must be called first, then NP_GetEntryPoints. On Windows, the order is + // reversed. Failing to follow this order results in crashes (e.g., in Silverlight on Mac and + // in Flash and QuickTime on Windows). +#if PLATFORM(MAC) + if (initializeFuncPtr(netscapeBrowserFuncs()) != NPERR_NO_ERROR || getEntryPointsFuncPtr(&m_pluginFuncs) != NPERR_NO_ERROR) + return false; +#elif PLATFORM(WIN) + if (getEntryPointsFuncPtr(&m_pluginFuncs) != NPERR_NO_ERROR || initializeFuncPtr(netscapeBrowserFuncs()) != NPERR_NO_ERROR) + return false; +#endif + + return true; +} + +void NetscapePluginModule::unload() +{ + ASSERT(!m_isInitialized); + + m_module = 0; +} + +} // namespace WebKit + diff --git a/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h b/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h new file mode 100644 index 0000000..a245b11 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/Netscape/NetscapePluginModule.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 NetscapePluginModule_h +#define NetscapePluginModule_h + +#include "Module.h" +#include "PluginQuirks.h" +#include <WebCore/npfunctions.h> +#include <wtf/RefCounted.h> +#include <wtf/text/WTFString.h> + +// FIXME: We should not include PluginInfoStore.h here. Instead, +// PluginInfoStore::Plugin should be moved out into its own header which we can +// put in Shared/Plugins. +#include "PluginInfoStore.h" + +namespace WebKit { + +class NetscapePluginModule : public RefCounted<NetscapePluginModule> { +public: + static PassRefPtr<NetscapePluginModule> getOrCreate(const String& pluginPath); + ~NetscapePluginModule(); + + const NPPluginFuncs& pluginFuncs() const { return m_pluginFuncs; } + + void pluginCreated(); + void pluginDestroyed(); + + static bool getPluginInfo(const String& pluginPath, PluginInfoStore::Plugin&); + + const PluginQuirks& pluginQuirks() const { return m_pluginQuirks; } + +private: + explicit NetscapePluginModule(const String& pluginPath); + + void determineQuirks(); + + bool tryLoad(); + bool load(); + void unload(); + + void shutdown(); + + String m_pluginPath; + bool m_isInitialized; + unsigned m_pluginCount; + + PluginQuirks m_pluginQuirks; + + NPP_ShutdownProcPtr m_shutdownProcPtr; + NPPluginFuncs m_pluginFuncs; + + OwnPtr<Module> m_module; +}; + +} // namespace WebKit + +#endif // NetscapePluginModule_h diff --git a/Source/WebKit2/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm b/Source/WebKit2/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm new file mode 100644 index 0000000..6ecacf0 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/Netscape/mac/NetscapePluginModuleMac.mm @@ -0,0 +1,338 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 "NetscapePluginModule.h" + +#include <WebCore/WebCoreNSStringExtras.h> +#include <wtf/HashSet.h> + +using namespace WebCore; + +namespace WebKit { + +static bool getPluginArchitecture(CFBundleRef bundle, cpu_type_t& pluginArchitecture) +{ + RetainPtr<CFArrayRef> pluginArchitecturesArray(AdoptCF, CFBundleCopyExecutableArchitectures(bundle)); + if (!pluginArchitecturesArray) + return false; + + // Turn the array into a set. + HashSet<unsigned> architectures; + for (CFIndex i = 0, numPluginArchitectures = CFArrayGetCount(pluginArchitecturesArray.get()); i < numPluginArchitectures; ++i) { + CFNumberRef number = static_cast<CFNumberRef>(CFArrayGetValueAtIndex(pluginArchitecturesArray.get(), i)); + + SInt32 architecture; + if (!CFNumberGetValue(number, kCFNumberSInt32Type, &architecture)) + continue; + architectures.add(architecture); + } + +#ifdef __x86_64__ + // We only support 64-bit Intel plug-ins on 64-bit Intel. + if (architectures.contains(kCFBundleExecutableArchitectureX86_64)) { + pluginArchitecture = CPU_TYPE_X86_64; + return true; + } + + // We also support 32-bit Intel plug-ins on 64-bit Intel. + if (architectures.contains(kCFBundleExecutableArchitectureI386)) { + pluginArchitecture = CPU_TYPE_X86; + return true; + } +#elif defined(__i386__) + // We only support 32-bit Intel plug-ins on 32-bit Intel. + if (architectures.contains(kCFBundleExecutableArchitectureI386)) { + pluginArchitecture = CPU_TYPE_X86; + return true; + } +#elif defined(__ppc64__) + // We only support 64-bit PPC plug-ins on 64-bit PPC. + if (architectures.contains(kCFBundleExecutableArchitecturePPC64)) { + pluginArchitecture = CPU_TYPE_POWERPC64; + return true; + } +#elif defined(__ppc__) + // We only support 32-bit PPC plug-ins on 32-bit PPC. + if (architectures.contains(kCFBundleExecutableArchitecturePPC)) { + pluginArchitecture = CPU_TYPE_POWERPC; + return true; + } +#else +#error "Unhandled architecture" +#endif + + return false; +} + +static bool getPluginInfoFromPropertyLists(CFBundleRef bundle, PluginInfo& pluginInfo) +{ + // FIXME: Handle WebPluginMIMETypesFilenameKey. + + CFDictionaryRef mimeTypes = static_cast<CFDictionaryRef>(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginMIMETypes"))); + if (!mimeTypes || CFGetTypeID(mimeTypes) != CFDictionaryGetTypeID()) + return false; + + // Get the plug-in name. + CFStringRef pluginName = static_cast<CFStringRef>(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginName"))); + if (pluginName && CFGetTypeID(pluginName) == CFStringGetTypeID()) + pluginInfo.name = pluginName; + + // Get the plug-in description. + CFStringRef pluginDescription = static_cast<CFStringRef>(CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("WebPluginDescription"))); + if (pluginDescription && CFGetTypeID(pluginDescription) == CFStringGetTypeID()) + pluginInfo.desc = pluginDescription; + + // Get the MIME type mapping dictionary. + CFIndex numMimeTypes = CFDictionaryGetCount(mimeTypes); + Vector<CFStringRef> mimeTypesVector(numMimeTypes); + Vector<CFDictionaryRef> mimeTypeInfoVector(numMimeTypes); + CFDictionaryGetKeysAndValues(mimeTypes, reinterpret_cast<const void**>(mimeTypesVector.data()), reinterpret_cast<const void**>(mimeTypeInfoVector.data())); + + for (CFIndex i = 0; i < numMimeTypes; ++i) { + MimeClassInfo mimeClassInfo; + + // If this MIME type is invalid, ignore it. + CFStringRef mimeType = mimeTypesVector[i]; + if (!mimeType || CFGetTypeID(mimeType) != CFStringGetTypeID() || CFStringGetLength(mimeType) == 0) + continue; + + // If this MIME type doesn't have a valid info dictionary, ignore it. + CFDictionaryRef mimeTypeInfo = mimeTypeInfoVector[i]; + if (!mimeTypeInfo || CFGetTypeID(mimeTypeInfo) != CFDictionaryGetTypeID()) + continue; + + // Get the MIME type description. + CFStringRef mimeTypeDescription = static_cast<CFStringRef>(CFDictionaryGetValue(mimeTypeInfo, CFSTR("WebPluginTypeDescription"))); + if (mimeTypeDescription && CFGetTypeID(mimeTypeDescription) != CFStringGetTypeID()) + mimeTypeDescription = 0; + + mimeClassInfo.type = String(mimeType).lower(); + mimeClassInfo.desc = mimeTypeDescription; + + // Now get the extensions for this MIME type. + CFIndex numExtensions = 0; + CFArrayRef extensionsArray = static_cast<CFArrayRef>(CFDictionaryGetValue(mimeTypeInfo, CFSTR("WebPluginExtensions"))); + if (extensionsArray && CFGetTypeID(extensionsArray) == CFArrayGetTypeID()) + numExtensions = CFArrayGetCount(extensionsArray); + + for (CFIndex i = 0; i < numExtensions; ++i) { + CFStringRef extension = static_cast<CFStringRef>(CFArrayGetValueAtIndex(extensionsArray, i)); + if (!extension || CFGetTypeID(extension) != CFStringGetTypeID()) + continue; + + mimeClassInfo.extensions.append(String(extension).lower()); + } + + // Add this MIME type. + pluginInfo.mimes.append(mimeClassInfo); + } + + return true; +} + +class ResourceMap { +public: + explicit ResourceMap(CFBundleRef bundle) + : m_bundle(bundle) + , m_currentResourceFile(CurResFile()) + , m_bundleResourceMap(CFBundleOpenBundleResourceMap(m_bundle)) + { + UseResFile(m_bundleResourceMap); + } + + ~ResourceMap() + { + // Close the resource map. + CFBundleCloseBundleResourceMap(m_bundle, m_bundleResourceMap); + + // And restore the old resource. + UseResFile(m_currentResourceFile); + } + + bool isValid() const { return m_bundleResourceMap != -1; } + +private: + CFBundleRef m_bundle; + ResFileRefNum m_currentResourceFile; + ResFileRefNum m_bundleResourceMap; +}; + +static bool getStringListResource(ResID resourceID, Vector<String>& stringList) { + Handle stringListHandle = Get1Resource('STR#', resourceID); + if (!stringListHandle || !*stringListHandle) + return false; + + // Get the string list size. + Size stringListSize = GetHandleSize(stringListHandle); + if (stringListSize < static_cast<Size>(sizeof(UInt16))) + return false; + + CFStringEncoding stringEncoding = stringEncodingForResource(stringListHandle); + + unsigned char* ptr = reinterpret_cast<unsigned char*>(*stringListHandle); + unsigned char* end = ptr + stringListSize; + + // Get the number of strings in the string list. + UInt16 numStrings = *reinterpret_cast<UInt16*>(ptr); + ptr += sizeof(UInt16); + + for (UInt16 i = 0; i < numStrings; ++i) { + // We're past the end of the string, bail. + if (ptr >= end) + return false; + + // Get the string length. + unsigned char stringLength = *ptr++; + + RetainPtr<CFStringRef> cfString(AdoptCF, CFStringCreateWithBytesNoCopy(kCFAllocatorDefault, ptr, stringLength, stringEncoding, false, kCFAllocatorNull)); + if (!cfString.get()) + return false; + + stringList.append(cfString.get()); + ptr += stringLength; + } + + if (ptr != end) + return false; + + return true; +} + +static const ResID PluginNameOrDescriptionStringNumber = 126; +static const ResID MIMEDescriptionStringNumber = 127; +static const ResID MIMEListStringStringNumber = 128; + +static bool getPluginInfoFromCarbonResources(CFBundleRef bundle, PluginInfo& pluginInfo) +{ + ResourceMap resourceMap(bundle); + if (!resourceMap.isValid()) + return false; + + // Get the description and name string list. + Vector<String> descriptionAndName; + if (!getStringListResource(PluginNameOrDescriptionStringNumber, descriptionAndName)) + return false; + + // Get the MIME types and extensions string list. This list needs to be a multiple of two. + Vector<String> mimeTypesAndExtensions; + if (!getStringListResource(MIMEListStringStringNumber, mimeTypesAndExtensions)) + return false; + + if (mimeTypesAndExtensions.size() % 2) + return false; + + size_t numMimeTypes = mimeTypesAndExtensions.size() / 2; + + // Now get the MIME type descriptions string list. This string list needs to be the same length as the number of MIME types. + Vector<String> mimeTypeDescriptions; + if (!getStringListResource(MIMEDescriptionStringNumber, mimeTypeDescriptions)) + return false; + + if (mimeTypeDescriptions.size() != numMimeTypes) + return false; + + // Add all MIME types. + for (size_t i = 0; i < mimeTypesAndExtensions.size() / 2; ++i) { + MimeClassInfo mimeClassInfo; + + const String& mimeType = mimeTypesAndExtensions[i * 2]; + const String& description = mimeTypeDescriptions[i]; + + mimeClassInfo.type = mimeType.lower(); + mimeClassInfo.desc = description; + + Vector<String> extensions; + mimeTypesAndExtensions[i * 2 + 1].split(',', extensions); + + for (size_t i = 0; i < extensions.size(); ++i) + mimeClassInfo.extensions.append(extensions[i].lower()); + + pluginInfo.mimes.append(mimeClassInfo); + } + + // Set the description and name if they exist. + if (descriptionAndName.size() > 0) + pluginInfo.desc = descriptionAndName[0]; + if (descriptionAndName.size() > 1) + pluginInfo.name = descriptionAndName[1]; + + return true; +} + +bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginInfoStore::Plugin& plugin) +{ + RetainPtr<CFStringRef> bundlePath(AdoptCF, pluginPath.createCFString()); + RetainPtr<CFURLRef> bundleURL(AdoptCF, CFURLCreateWithFileSystemPath(kCFAllocatorDefault, bundlePath.get(), kCFURLPOSIXPathStyle, false)); + + // Try to initialize the bundle. + RetainPtr<CFBundleRef> bundle(AdoptCF, CFBundleCreate(kCFAllocatorDefault, bundleURL.get())); + if (!bundle) + return false; + + // Check if this bundle is an NPAPI plug-in. + UInt32 packageType = 0; + CFBundleGetPackageInfo(bundle.get(), &packageType, 0); + if (packageType != FOUR_CHAR_CODE('BRPL')) + return false; + + // Check that the architecture is valid. + cpu_type_t pluginArchitecture = 0; + if (!getPluginArchitecture(bundle.get(), pluginArchitecture)) + return false; + + // Check that there's valid info for this plug-in. + if (!getPluginInfoFromPropertyLists(bundle.get(), plugin.info) && + !getPluginInfoFromCarbonResources(bundle.get(), plugin.info)) + return false; + + plugin.path = pluginPath; + plugin.pluginArchitecture = pluginArchitecture; + plugin.bundleIdentifier = CFBundleGetIdentifier(bundle.get()); + plugin.versionNumber = CFBundleGetVersionNumber(bundle.get()); + + RetainPtr<CFStringRef> filename(AdoptCF, CFURLCopyLastPathComponent(bundleURL.get())); + plugin.info.file = filename.get(); + + if (plugin.info.name.isNull()) + plugin.info.name = plugin.info.file; + if (plugin.info.desc.isNull()) + plugin.info.desc = plugin.info.file; + + return true; +} + +void NetscapePluginModule::determineQuirks() +{ + PluginInfoStore::Plugin plugin; + if (!getPluginInfo(m_pluginPath, plugin)) + return; + + if (plugin.bundleIdentifier == "com.macromedia.Flash Player.plugin") { + // Flash requires that the return value of getprogname() be "WebKitPluginHost". + m_pluginQuirks.add(PluginQuirks::PrognameShouldBeWebKitPluginHost); + } +} + +} // namespace WebKit diff --git a/Source/WebKit2/Shared/Plugins/Netscape/win/NetscapePluginModuleWin.cpp b/Source/WebKit2/Shared/Plugins/Netscape/win/NetscapePluginModuleWin.cpp new file mode 100644 index 0000000..f969ba4 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/Netscape/win/NetscapePluginModuleWin.cpp @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 "NetscapePluginModule.h" + +#include <WebCore/FileSystem.h> +#include <wtf/OwnArrayPtr.h> + +using namespace WebCore; + +namespace WebKit { + +static String getVersionInfo(const LPVOID versionInfoData, const String& info) +{ + LPVOID buffer; + UINT bufferLength; + String subInfo = "\\StringfileInfo\\040904E4\\" + info; + if (!::VerQueryValueW(versionInfoData, const_cast<UChar*>(subInfo.charactersWithNullTermination()), &buffer, &bufferLength) || !bufferLength) + return String(); + + // Subtract 1 from the length; we don't want the trailing null character. + return String(reinterpret_cast<UChar*>(buffer), bufferLength - 1); +} + +static uint64_t fileVersion(DWORD leastSignificant, DWORD mostSignificant) +{ + ULARGE_INTEGER version; + version.LowPart = leastSignificant; + version.HighPart = mostSignificant; + return version.QuadPart; +} + +bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginInfoStore::Plugin& plugin) +{ + String pathCopy = pluginPath; + DWORD versionInfoSize = ::GetFileVersionInfoSizeW(pathCopy.charactersWithNullTermination(), 0); + if (!versionInfoSize) + return false; + + OwnArrayPtr<char> versionInfoData(new char[versionInfoSize]); + if (!::GetFileVersionInfoW(pathCopy.charactersWithNullTermination(), 0, versionInfoSize, versionInfoData.get())) + return false; + + String name = getVersionInfo(versionInfoData.get(), "ProductName"); + String description = getVersionInfo(versionInfoData.get(), "FileDescription"); + if (name.isNull() || description.isNull()) + return false; + + VS_FIXEDFILEINFO* info; + UINT infoSize; + if (!::VerQueryValueW(versionInfoData.get(), L"\\", reinterpret_cast<void**>(&info), &infoSize) || infoSize < sizeof(VS_FIXEDFILEINFO)) + return false; + + Vector<String> types; + getVersionInfo(versionInfoData.get(), "MIMEType").split('|', types); + Vector<String> extensionLists; + getVersionInfo(versionInfoData.get(), "FileExtents").split('|', extensionLists); + Vector<String> descriptions; + getVersionInfo(versionInfoData.get(), "FileOpenName").split('|', descriptions); + + Vector<MimeClassInfo> mimes(types.size()); + for (size_t i = 0; i < types.size(); i++) { + String type = types[i].lower(); + String description = i < descriptions.size() ? descriptions[i] : ""; + String extensionList = i < extensionLists.size() ? extensionLists[i] : ""; + + Vector<String> extensionsVector; + extensionList.split(',', extensionsVector); + + // Get rid of the extension list that may be at the end of the description string. + int pos = description.find("(*"); + if (pos != -1) { + // There might be a space that we need to get rid of. + if (pos > 1 && description[pos - 1] == ' ') + pos--; + description = description.left(pos); + } + + mimes[i].type = type; + mimes[i].desc = description; + mimes[i].extensions.swap(extensionsVector); + } + + plugin.path = pluginPath; + plugin.info.desc = description; + plugin.info.name = name; + plugin.info.file = pathGetFileName(pluginPath); + plugin.info.mimes.swap(mimes); + plugin.fileVersion = fileVersion(info->dwFileVersionLS, info->dwFileVersionMS); + + return true; +} + +void NetscapePluginModule::determineQuirks() +{ +} + +} // namespace WebKit + diff --git a/Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp b/Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp new file mode 100644 index 0000000..a02cdad --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/Netscape/x11/NetscapePluginModuleX11.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 "NetscapePluginModule.h" + +#include "PluginDatabase.h" +#include "PluginPackage.h" + +using namespace WebCore; + +namespace WebKit { + +bool NetscapePluginModule::getPluginInfo(const String& pluginPath, PluginInfoStore::Plugin& plugin) +{ + // We are loading the plugin here since it does not seem to be a standardized way to + // get the needed informations from a UNIX plugin without loading it. + + RefPtr<PluginPackage> package = PluginPackage::createPackage(pluginPath, 0 /*lastModified*/); + if (!package) + return false; + + plugin.path = pluginPath; + plugin.info.desc = package->description(); + plugin.info.file = package->fileName(); + + const MIMEToDescriptionsMap& descriptions = package->mimeToDescriptions(); + const MIMEToExtensionsMap& extensions = package->mimeToExtensions(); + MIMEToDescriptionsMap::const_iterator descEnd = descriptions.end(); + plugin.info.mimes.reserveCapacity(descriptions.size()); + unsigned i = 0; + for (MIMEToDescriptionsMap::const_iterator it = descriptions.begin(); it != descEnd; ++it) { + plugin.info.mimes.uncheckedAppend(MimeClassInfo()); + MimeClassInfo& mime = plugin.info.mimes[i++]; + mime.type = it->first; + mime.desc = it->second; + MIMEToExtensionsMap::const_iterator extensionIt = extensions.find(it->first); + ASSERT(extensionIt != extensions.end()); + mime.extensions = extensionIt->second; + } + + package->unload(); + return true; +} + +void NetscapePluginModule::determineQuirks() +{ +} + +} // namespace WebKit diff --git a/Source/WebKit2/Shared/Plugins/PluginProcessCreationParameters.cpp b/Source/WebKit2/Shared/Plugins/PluginProcessCreationParameters.cpp new file mode 100644 index 0000000..90bbf07 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/PluginProcessCreationParameters.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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. + */ + +#if ENABLE(PLUGIN_PROCESS) + +#include "PluginProcessCreationParameters.h" + +#include "ArgumentCoders.h" + +namespace WebKit { + +PluginProcessCreationParameters::PluginProcessCreationParameters() +{ +} + +void PluginProcessCreationParameters::encode(CoreIPC::ArgumentEncoder* encoder) const +{ + encoder->encode(pluginPath); + +#if PLATFORM(MAC) + encoder->encode(acceleratedCompositingPort); +#endif +} + +bool PluginProcessCreationParameters::decode(CoreIPC::ArgumentDecoder* decoder, PluginProcessCreationParameters::PluginProcessCreationParameters& result) +{ + if (!decoder->decode(result.pluginPath)) + return false; + +#if PLATFORM(MAC) + if (!decoder->decode(result.acceleratedCompositingPort)) + return false; +#endif + + return true; +} + + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) diff --git a/Source/WebKit2/Shared/Plugins/PluginProcessCreationParameters.h b/Source/WebKit2/Shared/Plugins/PluginProcessCreationParameters.h new file mode 100644 index 0000000..1aeef01 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/PluginProcessCreationParameters.h @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 PluginProcessCreationParameters_h +#define PluginProcessCreationParameters_h + +#if ENABLE(PLUGIN_PROCESS) + +#include <wtf/text/WTFString.h> + +#if PLATFORM(MAC) +#include "MachPort.h" +#endif + +namespace CoreIPC { + class ArgumentDecoder; + class ArgumentEncoder; +} + +namespace WebKit { + +struct PluginProcessCreationParameters { + PluginProcessCreationParameters(); + + void encode(CoreIPC::ArgumentEncoder*) const; + static bool decode(CoreIPC::ArgumentDecoder*, PluginProcessCreationParameters&); + + String pluginPath; + +#if PLATFORM(MAC) + CoreIPC::MachPort acceleratedCompositingPort; +#endif +}; + +} // namespace WebKit + +#endif // ENABLE(PLUGIN_PROCESS) + +#endif // PluginProcessCreationParameters_h diff --git a/Source/WebKit2/Shared/Plugins/PluginQuirks.h b/Source/WebKit2/Shared/Plugins/PluginQuirks.h new file mode 100644 index 0000000..8dd3a74 --- /dev/null +++ b/Source/WebKit2/Shared/Plugins/PluginQuirks.h @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2010 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 INC. AND ITS 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 INC. OR ITS 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 PluginQuirks_h +#define PluginQuirks_h + +namespace WebKit { + +class PluginQuirks { +public: + enum PluginQuirk { + // Mac specific quirks: +#if PLATFORM(MAC) + // The plug-in wants the call to getprogame() to return "WebKitPluginHost". + // Adobe Flash Will not handle key down events otherwise. + PrognameShouldBeWebKitPluginHost, +#endif + + NumPluginQuirks + }; + + PluginQuirks() + : m_quirks(0) + { + COMPILE_ASSERT(sizeof(m_quirks) * 8 >= NumPluginQuirks, not_enough_room_for_quirks); + } + + void add(PluginQuirk quirk) + { + ASSERT(quirk >= 0); + ASSERT(quirk < NumPluginQuirks); + + m_quirks |= (1 << quirk); + } + + bool contains(PluginQuirk quirk) const + { + return m_quirks & (1 << quirk); + } + +private: + uint32_t m_quirks; +}; + +} // namespace WebKit + +#endif // PluginQuirkSet_h |