1/* 2 * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef npruntime_priv_h 27#define npruntime_priv_h 28 29#include <bindings/npruntime.h> 30 31#ifdef __cplusplus 32extern "C" { 33#endif 34 35/* 36 _NPN_InitializeVariantWithStringCopy() will copy string data. The string data 37 will be deallocated by calls to NPReleaseVariantValue(). 38*/ 39void _NPN_InitializeVariantWithStringCopy(NPVariant*, const NPString*); 40void _NPN_DeallocateObject(NPObject*); 41 42// The following routines allow the browser to aggressively cleanup NPObjects 43// on a per plugin basis. All NPObjects used through the NPRuntime API should 44// be "registered" while they are alive. After an object has been 45// deleted, it is possible for Javascript to have a reference to that object 46// which has not yet been garbage collected. Javascript access to NPObjects 47// will reference this registry to determine if the object is accessible or 48// not. 49 50// Windows introduces an additional complication for objects created by the 51// plugin. Plugins load inside of a DLL. Each DLL has it's own heap. If 52// the browser unloads the plugin DLL, all objects created within the DLL's 53// heap instantly become invalid. Normally, when WebKit drops the reference 54// on the top-level plugin object, it tells the plugin manager that the 55// plugin can be destroyed, which can unload the DLL. So, we must eliminate 56// all pointers to any object ever created by the plugin. 57 58// We generally associate NPObjects with an owner. The owner of an NPObject 59// is an NPObject which, when destroyed, also destroys all objects it owns. 60// For example, if an NPAPI plugin creates 10 sub-NPObjects, all 11 objects 61// (the NPAPI plugin + its 10 sub-objects) should become inaccessible 62// simultaneously. 63 64// The ownership hierarchy is flat, and not a tree. Imagine the following 65// object creation: 66// PluginObject 67// | 68// +-- Creates -----> Object1 69// | 70// +-- Creates -----> Object2 71// 72// PluginObject will be the "owner" for both Object1 and Object2. 73 74// Register an NPObject with the runtime. If the owner is NULL, the 75// object is treated as an owning object. If owner is not NULL, 76// this object will be registered as owned by owner's top-level owner. 77void _NPN_RegisterObject(NPObject*, NPObject* owner); 78 79// Unregister an NPObject with the runtime. If obj is an owning 80// object, this call will also unregister all of the owned objects. 81void _NPN_UnregisterObject(NPObject*); 82 83// Check to see if an object is registered with the runtime. 84// Return true if registered, false otherwise. 85bool _NPN_IsAlive(NPObject*); 86 87#ifdef __cplusplus 88} /* end extern "C" */ 89#endif 90 91#endif // npruntime_priv_h 92