NPVariantData.h 3.6 KB

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