[Release] wrt-plugins-common_0.3.89
[platform/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 <JavaScriptCore/JSContextRef.h>
33 #include <StorageEvent/IStorageEvent.h>
34 #include <TizenServiceEvent/ITizenServiceEvent.h>
35 #include <js_overlay_types.h>
36 #include <JSObject.h>
37
38 // import temporarily from JSContextRefPrivate.h
39 extern "C" JSGlobalContextRef JSContextGetGlobalContext(JSContextRef ctx);
40
41 namespace WrtPlugins {
42 namespace W3C {
43 class AddEventListenerSupport
44 {
45   public:
46     static JSValueRef AddEventListener(JSContextRef context,
47                                        JSObjectRef object,
48                                        JSObjectRef thisObject,
49                                        size_t argumentCount,
50                                        const JSValueRef arguments[],
51                                        JSValueRef* exception);
52
53     static void RemoveIFrame(JSObjectPtr iframe);
54
55     static void CallStorageListenersFromDifferentIFrames(
56         JSObjectRef iframe,
57         const WrtDeviceApis::StorageEvent::Api::IStorageEventPtr& event);
58
59     static void CallCustomEventListenersFromIFrame(
60         JSObjectRef iframe,
61         CustomEventType eventType,
62         JSObjectRef eventObject);
63
64   private:
65
66     struct CallbackData {
67         CustomEventType eventType;
68         JSObjectRef object;
69         JSObjectRef thisObject;
70         JSContextRef context;
71     };
72
73     typedef std::list<CallbackData> Listeners;
74     typedef std::shared_ptr<Listeners> ListenersPtr;
75
76     //first-iframe, 2nd - listeners list
77     typedef std::map<JSObjectRef, ListenersPtr> IFramesListeners;
78
79     static IFramesListeners m_listeners;
80
81   private:
82     static ListenersPtr getIFrameListeners(JSObjectRef iframe);
83 };
84 }
85 }
86
87 #endif