2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef InjectedBundleUserMessageCoders_h
27 #define InjectedBundleUserMessageCoders_h
29 #include "UserMessageCoders.h"
32 #include "WebPageGroupData.h"
33 #include "WebPageGroupProxy.h"
34 #include "WebProcess.h"
39 // - BundlePage -> Page
40 // - BundleFrame -> Frame
41 // - BundlePageGroup -> PageGroup
43 class InjectedBundleUserMessageEncoder : public UserMessageEncoder<InjectedBundleUserMessageEncoder> {
45 typedef UserMessageEncoder<InjectedBundleUserMessageEncoder> Base;
47 InjectedBundleUserMessageEncoder(APIObject* root)
52 void encode(CoreIPC::ArgumentEncoder* encoder) const
54 APIObject::Type type = APIObject::TypeNull;
55 if (baseEncode(encoder, type))
59 case APIObject::TypeBundlePage: {
60 WebPage* page = static_cast<WebPage*>(m_root);
61 encoder->encode(page->pageID());
64 case APIObject::TypeBundleFrame: {
65 WebFrame* frame = static_cast<WebFrame*>(m_root);
66 encoder->encode(frame->frameID());
69 case APIObject::TypeBundlePageGroup: {
70 WebPageGroupProxy* pageGroup = static_cast<WebPageGroupProxy*>(m_root);
71 encoder->encode(pageGroup->pageGroupID());
82 // - Page -> BundlePage
83 // - Frame -> BundleFrame
84 // - PageGroup -> BundlePageGroup
86 class InjectedBundleUserMessageDecoder : public UserMessageDecoder<InjectedBundleUserMessageDecoder> {
88 typedef UserMessageDecoder<InjectedBundleUserMessageDecoder> Base;
90 InjectedBundleUserMessageDecoder(RefPtr<APIObject>& root)
95 InjectedBundleUserMessageDecoder(InjectedBundleUserMessageDecoder&, RefPtr<APIObject>& root)
100 static bool decode(CoreIPC::ArgumentDecoder* decoder, InjectedBundleUserMessageDecoder& coder)
102 APIObject::Type type = APIObject::TypeNull;
103 if (!Base::baseDecode(decoder, coder, type))
106 if (coder.m_root || type == APIObject::TypeNull)
110 case APIObject::TypePage: {
112 if (!decoder->decode(pageID))
114 coder.m_root = WebProcess::shared().webPage(pageID);
117 case APIObject::TypeFrame: {
119 if (!decoder->decode(frameID))
121 coder.m_root = WebProcess::shared().webFrame(frameID);
124 case APIObject::TypePageGroup: {
125 WebPageGroupData pageGroupData;
126 if (!decoder->decode(pageGroupData))
128 coder.m_root = WebProcess::shared().webPageGroup(pageGroupData);
139 } // namespace WebKit
141 #endif // InjectedBundleUserMessageCoders_h