Initialize Tizen 2.3
[framework/web/wrt-plugins-common.git] / src_wearable / plugin-loading / plugin_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  * @file    plugin_iframe_support.cpp
18  * @version 1.0
19  * @brief
20  */
21
22 #include "plugin_iframe_support.h"
23
24 #include <algorithm>
25 #include <dpl/foreach.h>
26 #include <dpl/log/secure_log.h>
27
28 void IframesSupport::registerDeclaration(
29     const JSObjectDeclarationPtr& declaration)
30 {
31     _D("Registration iframes-supported plugins %s", declaration->getName().c_str());
32
33     if (declaration->getParentName().find('.') != std::string::npos) {
34         _E("The object will not be loaded to iframes");
35         return;
36     }
37     m_iframesObjects.push_back(declaration);
38 }
39
40 void IframesSupport::registerIframe(const JSObjectPtr& iframe)
41 {
42     _D("LoadedIframes size: %d", m_loadedIframes.size() );
43
44     m_loadedIframes.insert(iframe);
45 }
46
47 void IframesSupport::unregisterIframe(const JSObjectPtr& iframe)
48 {
49     _D("LoadedIframes size: %d", m_loadedIframes.size() );
50
51     auto it_loaded = std::find_if(m_loadedIframes.begin(),
52                                   m_loadedIframes.end(),
53                                   std::bind2nd(EqualToJSObjectPtr(), iframe));
54     //object not found, so thats the new iframe
55     if (it_loaded == m_loadedIframes.end()) {
56         _D("Nothing to unregister");
57         return;
58     }
59
60     m_loadedIframes.erase(it_loaded);
61 }
62
63 bool IframesSupport::hasIframes() const
64 {
65     return !m_loadedIframes.empty();
66 }
67
68 IframesSupport::DeclarationsList IframesSupport::getIframeObjects() const
69 {
70     return m_iframesObjects;
71 }
72
73 void IframesSupport::clean()
74 {
75     m_iframesObjects.clear();
76     m_loadedIframes.clear();
77 }