123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- /*
- * 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 "config.h"
- #include "NPObjectMessageReceiver.h"
- #if ENABLE(PLUGIN_PROCESS)
- #include "NPIdentifierData.h"
- #include "NPRemoteObjectMap.h"
- #include "NPRuntimeUtilities.h"
- #include "NPVariantData.h"
- namespace WebKit {
- PassOwnPtr<NPObjectMessageReceiver> NPObjectMessageReceiver::create(NPRemoteObjectMap* npRemoteObjectMap, Plugin* plugin, uint64_t npObjectID, NPObject* npObject)
- {
- return adoptPtr(new NPObjectMessageReceiver(npRemoteObjectMap, plugin, npObjectID, npObject));
- }
- NPObjectMessageReceiver::NPObjectMessageReceiver(NPRemoteObjectMap* npRemoteObjectMap, Plugin* plugin, uint64_t npObjectID, NPObject* npObject)
- : m_npRemoteObjectMap(npRemoteObjectMap)
- , m_plugin(plugin)
- , m_npObjectID(npObjectID)
- , m_npObject(npObject)
- {
- retainNPObject(m_npObject);
- }
- NPObjectMessageReceiver::~NPObjectMessageReceiver()
- {
- m_npRemoteObjectMap->unregisterNPObject(m_npObjectID);
- 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], m_plugin));
- 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, m_plugin);
- }
- // 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], m_plugin));
- 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, m_plugin);
- }
- // 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;
- VOID_TO_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, m_plugin);
- // 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, m_plugin);
- // 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], m_plugin));
- 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, m_plugin);
- }
- // 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)
|