WebBackForwardListItem.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Copyright (C) 2010, 2011 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. #include "config.h"
  26. #include "WebBackForwardListItem.h"
  27. #include "DataReference.h"
  28. #include "WebCoreArgumentCoders.h"
  29. namespace WebKit {
  30. static uint64_t highestUsedItemID = 0;
  31. WebBackForwardListItem::WebBackForwardListItem(const String& originalURL, const String& url, const String& title, const uint8_t* backForwardData, size_t backForwardDataSize, uint64_t itemID)
  32. : m_originalURL(originalURL)
  33. , m_url(url)
  34. , m_title(title)
  35. , m_itemID(itemID)
  36. {
  37. if (m_itemID > highestUsedItemID)
  38. highestUsedItemID = m_itemID;
  39. setBackForwardData(backForwardData, backForwardDataSize);
  40. }
  41. WebBackForwardListItem::~WebBackForwardListItem()
  42. {
  43. }
  44. uint64_t WebBackForwardListItem::highedUsedItemID()
  45. {
  46. return highestUsedItemID;
  47. }
  48. void WebBackForwardListItem::setBackForwardData(const uint8_t* data, size_t size)
  49. {
  50. m_backForwardData.clear();
  51. m_backForwardData.reserveCapacity(size);
  52. m_backForwardData.append(data, size);
  53. }
  54. void WebBackForwardListItem::encode(CoreIPC::ArgumentEncoder& encoder) const
  55. {
  56. encoder << m_originalURL;
  57. encoder << m_url;
  58. encoder << m_title;
  59. encoder << m_itemID;
  60. encoder << CoreIPC::DataReference(m_backForwardData);
  61. }
  62. PassRefPtr<WebBackForwardListItem> WebBackForwardListItem::decode(CoreIPC::ArgumentDecoder& decoder)
  63. {
  64. String originalURL;
  65. if (!decoder.decode(originalURL))
  66. return 0;
  67. String url;
  68. if (!decoder.decode(url))
  69. return 0;
  70. String title;
  71. if (!decoder.decode(title))
  72. return 0;
  73. uint64_t itemID;
  74. if (!decoder.decode(itemID))
  75. return 0;
  76. CoreIPC::DataReference data;
  77. if (!decoder.decode(data))
  78. return 0;
  79. return create(originalURL, url, title, data.data(), data.size(), itemID);
  80. }
  81. } // namespace WebKit