Update wrt-plugins-common_0.3.53
[framework/web/wrt-plugins-common.git] / src / js-overlay / js_iframe_support.cpp
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       IFrameSupport.cpp
19  * @author     Grzegorz Krawczyk (g.krawczyk@samsung.com)
20  * @version    0.1
21  * @brief
22  */
23
24 #include <dpl/foreach.h>
25 #include <dpl/assert.h>
26 #include <dpl/log/log.h>
27 #include <js_iframe_support.h>
28
29 namespace WrtPlugins {
30 namespace W3C {
31
32 IFrameSupport::IFramesContainer IFrameSupport::m_iframesObject =
33     IFrameSupport::IFramesContainer();
34
35
36 void IFrameSupport::RegisterWidget(java_script_context_t global_context,
37                                    js_object_instance_t iframe,
38                                    js_object_instance_t object)
39 {
40     LogDebug("New widget instance registered");
41     LogDebug("iframe: " << iframe );
42     LogDebug("object: " << object );
43     getIFrameData(static_cast<JSObjectRef>(iframe))->widget =
44         static_cast<JSObjectRef>(object);
45 }
46
47 void IFrameSupport::RegisterAddEventListener(java_script_context_t global_context,
48                                              js_object_instance_t iframe,
49                                              js_object_instance_t object)
50 {
51     LogDebug("New addEventListener instance registered");
52     LogDebug("iframe: " << iframe );
53     LogDebug("object: " << object );
54     getIFrameData(static_cast<JSObjectRef>(iframe))->addEventListener
55         = static_cast<JSObjectRef>(object);
56 }
57
58 JSObjectRef IFrameSupport::getIFrameObjectForWidget(JSObjectRef widgetObject)
59 {
60     FOREACH(it, m_iframesObject)
61     {
62         if(it->second->widget == widgetObject)
63         {
64             LogDebug("iframe found");
65             return it->first;
66         }
67     }
68     LogDebug("Iframe not found");
69     return NULL;
70 }
71
72 IFrameDataPtr IFrameSupport::getIFrameData(JSObjectRef iframe)
73 {
74     auto it = m_iframesObject.find(iframe);
75     if(it != m_iframesObject.end()){
76         return it->second;
77     }
78
79     return m_iframesObject[iframe] = IFrameDataPtr(new IFrameData());
80 }
81
82 }
83 }