upload tizen1.0 source
[framework/web/wrt-plugins-common.git] / src / standards / W3C / Widget / AddEventListenerSupport.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       AddEventListenerSupport.h
19  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
20  * @version    0.1
21  * @brief
22  */
23
24 #ifndef _WRT_PLUGINS_SRC_W3C_WIDGET_ADDEVENTLISTENERSUPPORT_H_
25 #define _WRT_PLUGINS_SRC_W3C_WIDGET_ADDEVENTLISTENERSUPPORT_H_
26
27 #include <map>
28 #include <list>
29 #include <memory>
30 #include <JavaScriptCore/JavaScript.h>
31 #include <StorageEvent/IStorageEvent.h>
32
33 namespace WrtPlugins {
34 namespace W3C {
35
36 class AddEventListenerSupport
37 {
38   public:
39     static void initializeContext(JSContextRef context);
40
41     static bool isInitialized();
42
43     static JSValueRef AddEventListener(JSContextRef context,
44                                        JSObjectRef object,
45                                        JSObjectRef thisObject,
46                                        size_t argumentCount,
47                                        const JSValueRef arguments[],
48                                        JSValueRef* exception);
49
50     static void CallListenersFromDifferentIFrames(
51         JSObjectRef iframe,
52         const WrtDeviceApis::StorageEvent::Api::IStorageEventPtr& event);
53
54   private:
55     struct CallbackData{
56         JSObjectRef object;
57         JSObjectRef thisObject;
58     };
59
60     typedef std::list<CallbackData> Listeners;
61     typedef std::shared_ptr<Listeners> ListenersPtr;
62
63     //first-iframe, 2nd - listeners list
64     typedef std::map<JSObjectRef, ListenersPtr> IFramesListeners;
65
66     static JSContextRef m_context;
67     static IFramesListeners m_listeners;
68
69   private:
70     static ListenersPtr getIFrameListeners(JSObjectRef iframe);
71 };
72
73 }
74 }
75
76 #endif