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 NPVariantData_h
27#define NPVariantData_h
28
29#if ENABLE(NETSCAPE_PLUGIN_API)
30
31#include <wtf/text/CString.h>
32
33namespace IPC {
34    class ArgumentDecoder;
35    class ArgumentEncoder;
36}
37
38namespace WebKit {
39
40class NPVariantData {
41public:
42    enum Type {
43        Void,
44        Null,
45        Bool,
46        Int32,
47        Double,
48        String,
49        LocalNPObjectID,
50        RemoteNPObjectID,
51    };
52    NPVariantData();
53
54    static NPVariantData makeVoid();
55    static NPVariantData makeNull();
56    static NPVariantData makeBool(bool value);
57    static NPVariantData makeInt32(int32_t value);
58    static NPVariantData makeDouble(double value);
59    static NPVariantData makeString(const char* string, unsigned length);
60    static NPVariantData makeLocalNPObjectID(uint64_t value);
61    static NPVariantData makeRemoteNPObjectID(uint64_t value);
62
63    Type type() const { return static_cast<Type>(m_type); }
64
65    bool boolValue() const
66    {
67        ASSERT(type() == NPVariantData::Bool);
68        return m_boolValue;
69    }
70
71    int32_t int32Value() const
72    {
73        ASSERT(type() == NPVariantData::Int32);
74        return m_int32Value;
75    }
76
77    double doubleValue() const
78    {
79        ASSERT(type() == NPVariantData::Double);
80        return m_doubleValue;
81    }
82
83    const CString& stringValue() const
84    {
85        ASSERT(type() == NPVariantData::String);
86        return m_stringValue;
87    }
88
89    uint64_t localNPObjectIDValue() const
90    {
91        ASSERT(type() == NPVariantData::LocalNPObjectID);
92        return m_localNPObjectIDValue;
93    }
94
95    uint64_t remoteNPObjectIDValue() const
96    {
97        ASSERT(type() == NPVariantData::RemoteNPObjectID);
98        return m_remoteNPObjectIDValue;
99    }
100
101    void encode(IPC::ArgumentEncoder&) const;
102    static bool decode(IPC::ArgumentDecoder&, NPVariantData&);
103
104private:
105    uint32_t m_type;
106    bool m_boolValue;
107    int32_t m_int32Value;
108    double m_doubleValue;
109    CString m_stringValue;
110    uint64_t m_localNPObjectIDValue;
111    uint64_t m_remoteNPObjectIDValue;
112};
113
114} // namespace WebKit
115
116#endif // ENABLE(NETSCAPE_PLUGIN_API)
117
118#endif // NPVariantData_h
119