Home | History | Annotate | Download | only in Plugins
      1 /*
      2  * Copyright (C) 2010 Apple 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 INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #ifndef NPRemoteObjectMap_h
     27 #define NPRemoteObjectMap_h
     28 
     29 #if ENABLE(PLUGIN_PROCESS)
     30 
     31 #include "Connection.h"
     32 #include <WebCore/npruntime.h>
     33 #include <wtf/HashMap.h>
     34 #include <wtf/HashSet.h>
     35 #include <wtf/RefCounted.h>
     36 
     37 namespace WebKit {
     38 
     39 class NPObjectMessageReceiver;
     40 class NPObjectProxy;
     41 class NPVariantData;
     42 class Plugin;
     43 
     44 class NPRemoteObjectMap : public RefCounted<NPRemoteObjectMap> {
     45 public:
     46     static PassRefPtr<NPRemoteObjectMap> create(CoreIPC::Connection*);
     47     ~NPRemoteObjectMap();
     48 
     49     // Creates an NPObjectProxy wrapper for the remote object with the given remote object ID.
     50     NPObject* createNPObjectProxy(uint64_t remoteObjectID, Plugin*);
     51     void npObjectProxyDestroyed(NPObject*);
     52 
     53     // Expose the given NPObject as a remote object. Returns the objectID.
     54     uint64_t registerNPObject(NPObject*, Plugin*);
     55     void unregisterNPObject(uint64_t);
     56 
     57     // Given an NPVariant, creates an NPVariantData object (a CoreIPC representation of an NPVariant).
     58     NPVariantData npVariantToNPVariantData(const NPVariant&, Plugin*);
     59 
     60     // Given an NPVariantData, creates an NPVariant object.
     61     NPVariant npVariantDataToNPVariant(const NPVariantData&, Plugin*);
     62 
     63     CoreIPC::Connection* connection() const { return m_connection; }
     64 
     65     void pluginDestroyed(Plugin*);
     66 
     67     CoreIPC::SyncReplyMode didReceiveSyncMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments, CoreIPC::ArgumentEncoder* reply);
     68 
     69 private:
     70     explicit NPRemoteObjectMap(CoreIPC::Connection*);
     71     CoreIPC::Connection* m_connection;
     72 
     73     // A map of NPObjectMessageReceiver classes, wrapping objects that we export to the
     74     // other end of the connection.
     75     HashMap<uint64_t, NPObjectMessageReceiver*> m_registeredNPObjects;
     76 
     77     // A set of NPObjectProxy objects associated with this map.
     78     HashSet<NPObjectProxy*> m_npObjectProxies;
     79 };
     80 
     81 } // namespace WebKit
     82 
     83 #endif // ENABLE(PLUGIN_PROCESS)
     84 
     85 #endif // NPRemoteObjectMap_h
     86