Apply to remove download listener before deleting _WebImpl
[framework/osp/web.git] / src / controls / FWebCtrl_WebEventArg.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file                FWebCtrl_WebEventArg.cpp
20  * @brief               The file contains the definition of _WebEventArg class.
21  *
22  * The file contains the definition of _WebEventArg class.
23  */
24 #include <new>
25 #include <FBaseInteger.h>
26 #include <FBaseSysLog.h>
27 #include "FWebCtrl_WebEventArg.h"
28
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32
33
34 namespace Tizen {  namespace Web { namespace Controls
35 {
36
37
38 //// _WebEventArg /////////////
39 _WebEventArg::_WebEventArg(int eventType, const Tizen::Base::String& message)
40         : __eventType(eventType)
41         , __message(message)
42 {
43 }
44
45
46 _WebEventArg::~_WebEventArg(void)
47 {
48 }
49
50
51 int
52 _WebEventArg::GetEventType(void) const
53 {
54         return __eventType;
55 }
56
57
58 int
59 _WebEventArg::GetEventGroup(void) const
60 {
61         return (0xf00 & __eventType);
62 }
63
64
65 Tizen::Base::String
66 _WebEventArg::GetEventMessage(void) const
67 {
68         return __message;
69 }
70
71
72 //// _JsBridgeArg/////////////
73 _JsBridgeArg::_JsBridgeArg(void)
74         : _WebEventArg(WEB_EVENT_DELIVER_JSBRIDGE_REQUEST, L"")
75         , __pJsonText(null)
76 {
77 }
78
79
80 _JsBridgeArg::~_JsBridgeArg(void)
81 {
82 }
83
84
85 result
86 _JsBridgeArg::Construct(const char* pJsonText)
87 {
88         SysTryReturnResult(NID_WEB_CTRL, pJsonText, E_INVALID_ARG, "[%s] Invalid argument(s) is used. json text is null." , GetErrorMessage(E_INVALID_ARG));
89
90         result r = E_SUCCESS;
91         int length = 0;
92
93         std::unique_ptr<Tizen::Base::ByteBuffer> pNewJsonText(new (std::nothrow) ByteBuffer());
94         SysTryReturn(NID_WEB_CTRL, pNewJsonText.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
95         
96         length = strlen(pJsonText);
97         r = pNewJsonText->Construct(length);
98         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to construct bytebuffer for jsonText.", GetErrorMessage(r));
99
100         r = pNewJsonText->SetArray(reinterpret_cast< const byte* >(pJsonText), 0, length);
101         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Failed to set json text to ByteBuffer. ", GetErrorMessage(r));
102
103         __pJsonText = std::move(pNewJsonText);
104         
105         return r;
106 }
107
108
109 const Tizen::Base::ByteBuffer*
110 _JsBridgeArg::GetJsonData(void) const
111 {
112         return __pJsonText.get();
113 }
114
115
116 _LoadingEventArg::_LoadingEventArg(int loadingEvent)
117         : _WebEventArg(loadingEvent, L"")
118         , __pEventInfo(null)
119 {
120 }
121
122
123 _LoadingEventArg::~_LoadingEventArg(void)
124 {
125 }
126
127
128 result
129 _LoadingEventArg::SetEventInfo(EventInfoKey key, const Tizen::Base::Object& value)
130 {
131         result r = E_SUCCESS;
132         
133         std::unique_ptr<Integer> pKey(new (std::nothrow) Integer(key));
134         SysTryReturn(NID_WEB_CTRL, pKey.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
135
136         if (__pEventInfo.get() == null)
137         {
138                 std::unique_ptr<HashMap, AllElementsDeleter> pEventInfo(new (std::nothrow) HashMap());
139                 SysTryReturn(NID_WEB_CTRL, pEventInfo.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
140
141                 r = pEventInfo->Construct();
142                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
143
144                 __pEventInfo = std::move(pEventInfo);
145         }       
146
147         r = __pEventInfo->Add(*pKey.get(), value);
148         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
149         
150         pKey.release();
151
152         return r;
153
154 }
155
156
157 const Tizen::Base::Object*
158 _LoadingEventArg::GetEventInfo(EventInfoKey key) const
159 {
160         SysTryReturn(NID_WEB_CTRL, __pEventInfo.get(), null, E_OBJ_NOT_FOUND, "[%s] The required instance is not available.", GetErrorMessage(E_OBJ_NOT_FOUND));
161         Integer int_key(key);
162
163         return __pEventInfo->GetValue(int_key);
164 }
165
166
167 _WebDownloadEventArg::_WebDownloadEventArg(int webDonwloadEvent)
168         : _WebEventArg(webDonwloadEvent, L"")
169         , __pEventInfo(null)
170 {
171 }
172
173
174 _WebDownloadEventArg::~_WebDownloadEventArg(void)
175 {
176 }
177
178
179 result
180 _WebDownloadEventArg::SetEventInfo(EventInfoKey key, const Tizen::Base::Object& value)
181 {
182         result r = E_SUCCESS;
183         
184         std::unique_ptr<Integer> pKey(new (std::nothrow) Integer(key));
185         SysTryReturn(NID_WEB_CTRL, pKey.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
186
187         if (__pEventInfo.get() == null)
188         {
189                 std::unique_ptr<HashMap, AllElementsDeleter> pEventInfo(new (std::nothrow) HashMap());
190                 SysTryReturn(NID_WEB_CTRL, pEventInfo.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
191
192                 r = pEventInfo->Construct();
193                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
194
195                 __pEventInfo = std::move(pEventInfo);
196         }       
197
198         r = __pEventInfo->Add(*pKey.get(), value);
199         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
200         
201         pKey.release();
202
203         return r;
204 }
205
206
207 const Tizen::Base::Object*
208 _WebDownloadEventArg::GetEventInfo(EventInfoKey key) const
209 {
210         SysTryReturn(NID_WEB_CTRL, __pEventInfo.get(), null, E_OBJ_NOT_FOUND, "[%s] The required instance is not available.", GetErrorMessage(E_OBJ_NOT_FOUND));
211         Integer int_key(key);
212
213         return __pEventInfo->GetValue(int_key);
214 }
215
216
217 _WebUiEventArg::_WebUiEventArg(int webUiEvent)
218         : _WebEventArg(webUiEvent, L"")
219         , __pEventInfo(null)
220 {
221 }
222
223
224 _WebUiEventArg::~_WebUiEventArg(void)
225 {
226 }
227
228
229 result
230 _WebUiEventArg::SetEventInfo(EventInfoKey key, const Tizen::Base::Object& value)
231 {
232         result r = E_SUCCESS;
233         
234         std::unique_ptr<Integer> pKey(new (std::nothrow) Integer(key));
235         SysTryReturn(NID_WEB_CTRL, pKey.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
236
237         if (__pEventInfo.get() == null)
238         {
239                 std::unique_ptr<HashMap, AllElementsDeleter> pEventInfo(new (std::nothrow) HashMap());
240                 SysTryReturn(NID_WEB_CTRL, pEventInfo.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
241
242                 r = pEventInfo->Construct();
243                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
244
245                 __pEventInfo = std::move(pEventInfo);
246         }       
247
248         r = __pEventInfo->Add(*pKey.get(), value);
249         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
250         
251         pKey.release();
252
253         return r;
254 }
255
256
257 const Tizen::Base::Object*
258 _WebUiEventArg::GetEventInfo(EventInfoKey key) const
259 {
260         SysTryReturn(NID_WEB_CTRL, __pEventInfo.get(), null, E_OBJ_NOT_FOUND, "[%s] The required instance is not available.", GetErrorMessage(E_OBJ_NOT_FOUND));
261         Integer int_key(key);
262
263         return __pEventInfo->GetValue(int_key);
264 }
265
266
267 _TextSearchEventArg::_TextSearchEventArg(int textSearchEvent)
268         : _WebEventArg(textSearchEvent, L"")
269         , __pEventInfo(null)
270 {
271 }
272
273
274 _TextSearchEventArg::~_TextSearchEventArg(void)
275 {
276 }
277
278
279 result
280 _TextSearchEventArg::SetEventInfo(EventInfoKey key, const Tizen::Base::Object& value)
281 {
282         result r = E_SUCCESS;
283         
284         std::unique_ptr<Integer> pKey(new (std::nothrow) Integer(key));
285         SysTryReturn(NID_WEB_CTRL, pKey.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
286
287         if (__pEventInfo.get() == null)
288         {
289                 std::unique_ptr<HashMap, AllElementsDeleter> pEventInfo(new (std::nothrow) HashMap());
290                 SysTryReturn(NID_WEB_CTRL, pEventInfo.get(), E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed", GetErrorMessage(E_OUT_OF_MEMORY));
291
292                 r = pEventInfo->Construct();
293                 SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
294
295                 __pEventInfo = std::move(pEventInfo);
296         }       
297
298         r = __pEventInfo->Add(*pKey.get(), value);
299         SysTryReturn(NID_WEB_CTRL, r == E_SUCCESS, r, r, "[%s] Propagating.", GetErrorMessage(r));
300         
301         pKey.release();
302
303         return r;
304 }
305
306
307 const Tizen::Base::Object*
308 _TextSearchEventArg::GetEventInfo(EventInfoKey key) const
309 {
310         SysTryReturn(NID_WEB_CTRL, __pEventInfo.get(), null, E_OBJ_NOT_FOUND, "[%s] The required instance is not available.", GetErrorMessage(E_OBJ_NOT_FOUND));
311         Integer int_key(key);
312
313         return __pEventInfo->GetValue(int_key);
314 }
315
316
317 }}} // Tizen::Web::Controls