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 "PluginObject.h" 335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using namespace std; 355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Passing null for our NPP_GetValue function pointer should not crash. 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class NullNPPGetValuePointer : public PluginTest { 395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)public: 405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NullNPPGetValuePointer(NPP, const string& identifier); 415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)private: 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual NPError NPP_Destroy(NPSavedData**) OVERRIDE; 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual NPError NPP_GetValue(NPPVariable, void* value) OVERRIDE; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) NPP_GetValueProcPtr m_originalNPPGetValuePointer; 475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}; 485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)static PluginTest::Register<NullNPPGetValuePointer> registrar("null-npp-getvalue-pointer"); 505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)NullNPPGetValuePointer::NullNPPGetValuePointer(NPP npp, const string& identifier) 525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : PluginTest(npp, identifier) 535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) , m_originalNPPGetValuePointer(pluginFunctions->getvalue) 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){ 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Be sneaky and null out the getvalue pointer the browser is holding. This simulates a plugin 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // that doesn't implement NPP_GetValue (like Shockwave Director 10.3 on Windows). Note that if 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // WebKit copies the NPPluginFuncs struct this technique will have no effect and WebKit will 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // call into our NPP_GetValue implementation. 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pluginFunctions->getvalue = 0; 605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)NPError NullNPPGetValuePointer::NPP_Destroy(NPSavedData**) 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){ 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Set the NPP_GetValue pointer back the way it was before we mucked with it so we don't mess 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // up future uses of the plugin module. 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pluginFunctions->getvalue = m_originalNPPGetValuePointer; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NPERR_NO_ERROR; 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)NPError NullNPPGetValuePointer::NPP_GetValue(NPPVariable, void*) 715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles){ 725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) pluginLog(m_npp, "NPP_GetValue was called but should not have been. Maybe WebKit copied the NPPluginFuncs struct, which would invalidate this test."); 735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return NPERR_GENERIC_ERROR; 745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 75