1/*
2 * Copyright (C) 2012 Google 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "config.h"
32#include "WebDeliveredIntentClient.h"
33
34#include "DeliveredIntent.h"
35#include "SerializedScriptValue.h"
36#include "platform/WebSerializedScriptValue.h"
37
38namespace WebKit {
39
40#if ENABLE(WEB_INTENTS)
41class DeliveredIntentClientImpl : public WebCore::DeliveredIntentClient {
42public:
43 DeliveredIntentClientImpl(WebDeliveredIntentClient* owner) : m_owner(owner) { }
44 virtual ~DeliveredIntentClientImpl() { }
45
46 virtual void postResult(PassRefPtr<WebCore::SerializedScriptValue> data)
47 {
48 m_owner->postResult(data);
49 }
50
51 virtual void postFailure(PassRefPtr<WebCore::SerializedScriptValue> data)
52 {
53 m_owner->postFailure(data);
54 }
55
56 void abandon()
57 {
58 m_owner = 0;
59 }
60
61private:
62 WebDeliveredIntentClient* m_owner;
63};
64#endif
65
66WebDeliveredIntentClient::WebDeliveredIntentClient(const WebString& action, const WebString& type, const WebString& serializedData)
67{
68 m_action = action;
69 m_type = type;
70 m_data = serializedData;
71#if ENABLE(WEB_INTENTS)
72 RefPtr<DeliveredIntentClientImpl> client(new DeliveredIntentClientImpl(this));
73 m_intentClient = client;
74#endif
75}
76
77void WebDeliveredIntentClient::reset()
78{
79 m_action = "";
80 m_type = "";
81 m_data = "";
82#if ENABLE(WEB_INTENTS)
83 m_intentClient->abandon();
84 m_intentClient.reset();
85#endif
86}
87
88bool WebDeliveredIntentClient::isNull() const
89{
90 return false;
91}
92
93bool WebDeliveredIntentClient::equals(const WebDeliveredIntentClient& other) const
94{
95 if (m_action != other.m_action || m_type != other.m_type || m_data != other.m_data)
96 return false;
97
98#if ENABLE(WEB_INTENTS)
99 return (m_intentClient.get() == other.m_intentClient.get());
100#else
101 return true;
102#endif
103}
104
105void WebDeliveredIntentClient::assign(const WebDeliveredIntentClient& other)
106{
107 m_action = other.m_action;
108 m_type = other.m_type;
109 m_data = other.m_data;
110#if ENABLE(WEB_INTENTS)
111 m_intentClient = other.m_intentClient;
112#endif
113}
114
115void WebDeliveredIntentClient::setIntentData(const WebString& action, const WebString& type, const WebString& serializedData)
116{
117 m_action = action;
118 m_type = type;
119 m_data = serializedData;
120}
121
122WebString WebDeliveredIntentClient::action() const
123{
124 return m_action;
125}
126
127WebString WebDeliveredIntentClient::type() const
128{
129 return m_type;
130}
131
132WebString WebDeliveredIntentClient::data() const
133{
134 return m_data;
135}
136
137void WebDeliveredIntentClient::postResult(const WebSerializedScriptValue& data)
138{
139 // notify data.toString();
140}
141
142void WebDeliveredIntentClient::postFailure(const WebSerializedScriptValue& data)
143{
144 // notify data.toString();
145}
146
147void WebDeliveredIntentClient::setAsClient(WebCore::DeliveredIntent* intent) const
148{
149#if ENABLE(WEB_INTENTS)
150 intent->setClient(m_intentClient.get());
151#endif
152}
153
154} // namespace WebKit