InjectedBundleUserMessageCoders.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 InjectedBundleUserMessageCoders_h
  26. #define InjectedBundleUserMessageCoders_h
  27. #include "UserMessageCoders.h"
  28. #include "WebFrame.h"
  29. #include "WebPage.h"
  30. #include "WebPageGroupData.h"
  31. #include "WebPageGroupProxy.h"
  32. #include "WebProcess.h"
  33. #if PLATFORM(MAC)
  34. #include "ObjCObjectGraphCoders.h"
  35. #endif
  36. namespace WebKit {
  37. // Adds
  38. // - BundlePage -> Page
  39. // - BundleFrame -> Frame
  40. // - BundlePageGroup -> PageGroup
  41. class InjectedBundleUserMessageEncoder : public UserMessageEncoder<InjectedBundleUserMessageEncoder> {
  42. public:
  43. typedef UserMessageEncoder<InjectedBundleUserMessageEncoder> Base;
  44. InjectedBundleUserMessageEncoder(APIObject* root)
  45. : Base(root)
  46. {
  47. }
  48. void encode(CoreIPC::ArgumentEncoder& encoder) const
  49. {
  50. APIObject::Type type = APIObject::TypeNull;
  51. if (baseEncode(encoder, type))
  52. return;
  53. switch (type) {
  54. case APIObject::TypeBundlePage: {
  55. WebPage* page = static_cast<WebPage*>(m_root);
  56. encoder << page->pageID();
  57. break;
  58. }
  59. case APIObject::TypeBundleFrame: {
  60. WebFrame* frame = static_cast<WebFrame*>(m_root);
  61. encoder << frame->frameID();
  62. break;
  63. }
  64. case APIObject::TypeBundlePageGroup: {
  65. WebPageGroupProxy* pageGroup = static_cast<WebPageGroupProxy*>(m_root);
  66. encoder << pageGroup->pageGroupID();
  67. break;
  68. }
  69. #if PLATFORM(MAC)
  70. case APIObject::TypeObjCObjectGraph: {
  71. ObjCObjectGraph* objectGraph = static_cast<ObjCObjectGraph*>(m_root);
  72. encoder << InjectedBundleObjCObjectGraphEncoder(objectGraph);
  73. break;
  74. }
  75. #endif
  76. default:
  77. ASSERT_NOT_REACHED();
  78. break;
  79. }
  80. }
  81. };
  82. // Adds
  83. // - Page -> BundlePage
  84. // - Frame -> BundleFrame
  85. // - PageGroup -> BundlePageGroup
  86. class InjectedBundleUserMessageDecoder : public UserMessageDecoder<InjectedBundleUserMessageDecoder> {
  87. public:
  88. typedef UserMessageDecoder<InjectedBundleUserMessageDecoder> Base;
  89. InjectedBundleUserMessageDecoder(RefPtr<APIObject>& root)
  90. : Base(root)
  91. {
  92. }
  93. InjectedBundleUserMessageDecoder(InjectedBundleUserMessageDecoder&, RefPtr<APIObject>& root)
  94. : Base(root)
  95. {
  96. }
  97. static bool decode(CoreIPC::ArgumentDecoder& decoder, InjectedBundleUserMessageDecoder& coder)
  98. {
  99. APIObject::Type type = APIObject::TypeNull;
  100. if (!Base::baseDecode(decoder, coder, type))
  101. return false;
  102. if (coder.m_root || type == APIObject::TypeNull)
  103. return true;
  104. switch (type) {
  105. case APIObject::TypePage: {
  106. uint64_t pageID;
  107. if (!decoder.decode(pageID))
  108. return false;
  109. coder.m_root = WebProcess::shared().webPage(pageID);
  110. break;
  111. }
  112. case APIObject::TypeFrame: {
  113. uint64_t frameID;
  114. if (!decoder.decode(frameID))
  115. return false;
  116. coder.m_root = WebProcess::shared().webFrame(frameID);
  117. break;
  118. }
  119. case APIObject::TypePageGroup: {
  120. WebPageGroupData pageGroupData;
  121. if (!decoder.decode(pageGroupData))
  122. return false;
  123. coder.m_root = WebProcess::shared().webPageGroup(pageGroupData);
  124. break;
  125. }
  126. #if PLATFORM(MAC)
  127. case APIObject::TypeObjCObjectGraph: {
  128. RefPtr<ObjCObjectGraph> objectGraph;
  129. InjectedBundleObjCObjectGraphDecoder objectGraphDecoder(objectGraph, &WebProcess::shared());
  130. if (!decoder.decode(objectGraphDecoder))
  131. return false;
  132. coder.m_root = objectGraph.get();
  133. break;
  134. }
  135. #endif
  136. default:
  137. return false;
  138. }
  139. return true;
  140. }
  141. };
  142. } // namespace WebKit
  143. #endif // InjectedBundleUserMessageCoders_h