Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_mobile / js-overlay / deprecated / 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 IFrameSupport::IFramesContainer IFrameSupport::m_iframesObject =
32     IFrameSupport::IFramesContainer();
33
34 void IFrameSupport::RegisterWidget(java_script_context_t /*global_context*/,
35                                    js_object_instance_t iframe,
36                                    js_object_instance_t object)
37 {
38     LogDebug("New widget instance registered");
39     LogDebug("iframe: " << iframe);
40     LogDebug("object: " << object);
41     getIFrameData(static_cast<JSObjectRef>(iframe))->widget =
42         static_cast<JSObjectRef>(object);
43 }
44
45 void IFrameSupport::RegisterAddEventListener(
46     java_script_context_t /*global_context*/,
47     js_object_instance_t iframe,
48     js_object_instance_t object)
49 {
50     LogDebug("New addEventListener instance registered");
51     LogDebug("iframe: " << iframe);
52     LogDebug("object: " << object);
53     getIFrameData(static_cast<JSObjectRef>(iframe))->addEventListener
54         = static_cast<JSObjectRef>(object);
55 }
56
57 JSObjectRef IFrameSupport::getIFrameObjectForWidget(JSObjectRef widgetObject)
58 {
59     FOREACH(it, m_iframesObject)
60     {
61         if (it->second->widget == widgetObject) {
62             LogDebug("iframe found");
63             return it->first;
64         }
65     }
66     LogDebug("Iframe not found");
67     return NULL;
68 }
69
70 IFrameDataPtr IFrameSupport::getIFrameData(JSObjectRef iframe)
71 {
72     auto it = m_iframesObject.find(iframe);
73     if (it != m_iframesObject.end()) {
74         return it->second;
75     }
76
77     return m_iframesObject[iframe] = IFrameDataPtr(new IFrameData());
78 }
79 }
80 }