Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / js-overlay / js_overlay_addEventListener.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  *
18  * @file       js_overlay_addEventListener.h
19  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
20  * @author     Yunchan Cho (yunchan.cho@samsung.com)
21  * @version    0.1
22  * @brief
23  */
24
25 #ifndef _WRT_PLUGINS_SRC_W3C_WIDGET_ADDEVENTLISTENERSUPPORT_H_
26 #define _WRT_PLUGINS_SRC_W3C_WIDGET_ADDEVENTLISTENERSUPPORT_H_
27
28 #include <map>
29 #include <list>
30 #include <memory>
31 #include <JavaScriptCore/JavaScript.h>
32 #include <StorageEvent/IStorageEvent.h>
33 #include <TizenServiceEvent/ITizenServiceEvent.h>
34 #include <js_overlay_types.h>
35
36 namespace WrtPlugins {
37 namespace W3C {
38
39 class AddEventListenerSupport
40 {
41   public:
42     static void initialize(JSContextRef context);
43     static void deinitialize();
44
45     static bool isInitialized();
46
47     static JSValueRef AddEventListener(JSContextRef context,
48                                        JSObjectRef object,
49                                        JSObjectRef thisObject,
50                                        size_t argumentCount,
51                                        const JSValueRef arguments[],
52                                        JSValueRef* exception);
53
54     static void CallStorageListenersFromDifferentIFrames(
55         JSObjectRef iframe,
56         const WrtDeviceApis::StorageEvent::Api::IStorageEventPtr& event);
57
58     static void CallServiceListenersFromIFrame(
59         JSObjectRef iframe,
60         const WrtDeviceApis::TizenServiceEvent::Api::ITizenServiceEventPtr& event);
61
62   private:
63
64     struct CallbackData{
65         CustomEventType eventType; 
66         JSObjectRef object;
67         JSObjectRef thisObject;
68     };
69
70     typedef std::list<CallbackData> Listeners;
71     typedef std::shared_ptr<Listeners> ListenersPtr;
72
73     //first-iframe, 2nd - listeners list
74     typedef std::map<JSObjectRef, ListenersPtr> IFramesListeners;
75
76     static JSContextRef m_context;
77     static IFramesListeners m_listeners;
78
79   private:
80     static ListenersPtr getIFrameListeners(JSObjectRef iframe);
81 };
82
83 }
84 }
85
86 #endif