Merge "fix: use EINA_* booleans instread of TRUE/FALSE" into tizen
[platform/framework/web/wrt.git] / src / view / webkit / injected-bundle / page_global_context_container.cpp
1 /*
2  * Copyright (c) 2013 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  * @file page_global_context_container.cpp
18  * @author Tomasz Iwanek (t.iwanek@smasung.com)
19  * @brief Declares container for global context that holds its references
20  */
21 #include "page_global_context_container.h"
22
23 #include <dpl/foreach.h>
24
25 PageGlobalContextContainer::PageGlobalContextContainer()
26 {
27 }
28
29 PageGlobalContextContainer::~PageGlobalContextContainer()
30 {
31     FOREACH(iter, m_map)
32     {
33         JSGlobalContextRelease(iter->second);
34     }
35 }
36
37 void PageGlobalContextContainer::insertContextForPage(WKBundlePageRef page, JSGlobalContextRef context)
38 {
39     PageGlobalContext::iterator iter = m_map.find(page);
40     if(iter != m_map.end())
41     {
42         JSGlobalContextRelease(m_map[page]);
43     }
44     JSGlobalContextRetain(context);
45     m_map[page] = context;
46 }
47
48 void PageGlobalContextContainer::removeContextForPage(WKBundlePageRef page)
49 {
50     PageGlobalContext::iterator iter = m_map.find(page);
51     if(iter != m_map.end())
52     {
53         JSGlobalContextRelease(m_map[page]);
54     }
55     m_map.erase(iter);
56 }
57
58 JSGlobalContextRef PageGlobalContextContainer::getContextForPage(WKBundlePageRef page) const
59 {
60     return m_map.find(page)->second;
61 }
62
63 PageGlobalContextContainer::const_iterator PageGlobalContextContainer::begin() const
64 {
65     return m_map.begin();
66 }
67 PageGlobalContextContainer::const_iterator PageGlobalContextContainer::find(WKBundlePageRef ref) const
68 {
69     return m_map.find(ref);
70 }
71 PageGlobalContextContainer::const_iterator PageGlobalContextContainer::end() const
72 {
73     return m_map.end();
74 }