15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved. 25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// found in the LICENSE file. 45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/* 65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Copyright (C) 2010 Apple Inc. All rights reserved. 75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * modification, are permitted provided that the following conditions 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * are met: 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * documentation and/or other materials provided with the distribution. 165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * THE POSSIBILITY OF SUCH DAMAGE. 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */ 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "PluginTest.h" 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string.h> 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using namespace std; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NPRuntimeRemoveProperty : public PluginTest { 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public: 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NPRuntimeRemoveProperty(NPP npp, const string& identifier) 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : PluginTest(npp, identifier) 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)private: 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) struct TestObject : Object<TestObject> { 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestObject() 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : m_lastRemovedProperty(0) 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool hasProperty(NPIdentifier propertyName) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (identifierIs(propertyName, "lastRemovedProperty")) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool getProperty(NPIdentifier propertyName, NPVariant* result) 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) assert(identifierIs(propertyName, "lastRemovedProperty")); 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!m_lastRemovedProperty) 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (pluginTest()->NPN_IdentifierIsString(m_lastRemovedProperty)) { 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) char* lastRemovedPropertyName = pluginTest()->NPN_UTF8FromIdentifier(m_lastRemovedProperty); 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) STRINGZ_TO_NPVARIANT(lastRemovedPropertyName, *result); 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int intIdentifier = pluginTest()->NPN_IntFromIdentifier(m_lastRemovedProperty); 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) DOUBLE_TO_NPVARIANT(intIdentifier, *result); 755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool removeProperty(NPIdentifier propertyName) 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_lastRemovedProperty = propertyName; 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NPIdentifier m_lastRemovedProperty; 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) struct PluginObject : Object<PluginObject> { 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) public: 905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) PluginObject() 915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : m_testObject(0) 925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual ~PluginObject() 965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (m_testObject) 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pluginTest()->NPN_ReleaseObject(m_testObject); 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool hasMethod(NPIdentifier methodName) 1025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (identifierIs(methodName, "testRemoveProperty")) 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool invoke(NPIdentifier methodName, const NPVariant* arguments, uint32_t argumentCount, NPVariant* result) 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) assert(identifierIs(methodName, "testRemoveProperty")); 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (argumentCount != 2) 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 1155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!NPVARIANT_IS_OBJECT(arguments[0])) 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 1185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!NPVARIANT_IS_STRING(arguments[1]) && !NPVARIANT_IS_DOUBLE(arguments[1])) 1205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NPIdentifier propertyName; 1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (NPVARIANT_IS_STRING(arguments[1])) { 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) string propertyNameString(arguments[1].value.stringValue.UTF8Characters, 1255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) arguments[1].value.stringValue.UTF8Length); 1265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) propertyName = pluginTest()->NPN_GetStringIdentifier(propertyNameString.c_str()); 1285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 1295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int32_t number = static_cast<int32_t>(arguments[1].value.doubleValue); 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) propertyName = pluginTest()->NPN_GetIntIdentifier(number); 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pluginTest()->NPN_RemoveProperty(NPVARIANT_TO_OBJECT(arguments[0]), propertyName); 1345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) VOID_TO_NPVARIANT(*result); 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool hasProperty(NPIdentifier propertyName) 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (identifierIs(propertyName, "testObject")) 1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return false; 1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool getProperty(NPIdentifier propertyName, NPVariant* result) 1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) { 1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) assert(identifierIs(propertyName, "testObject")); 1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!m_testObject) 1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) m_testObject = TestObject::create(pluginTest()); 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) OBJECT_TO_NPVARIANT(pluginTest()->NPN_RetainObject(m_testObject), *result); 1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return true; 1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) private: 1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NPObject* m_testObject; 1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) }; 1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual NPError NPP_GetValue(NPPVariable variable, void* value) OVERRIDE { 1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (variable != NPPVpluginScriptableNPObject) 1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NPERR_GENERIC_ERROR; 1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *(NPObject**)value = PluginObject::create(this); 1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NPERR_NO_ERROR; 1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)static PluginTest::Register<NPRuntimeRemoveProperty> npRuntimeRemoveProperty("npruntime-remove-property"); 174