311d847307a936002e83590b559087f9d71145fb
[platform/framework/web/wrt-plugins-common.git] / src / 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
27 void IframesSupport::registerDeclaration(
28     const JSObjectDeclarationPtr& declaration)
29 {
30     LogDebug("Registration iframes-supported plugins " <<
31              declaration->getName());
32
33     if(declaration->getParentName().find('.') != std::string::npos)
34     {
35         LogWarning("The object will not be loaded to iframes");
36         return;
37     }
38     m_iframesObjects.push_back(declaration);
39 }
40
41 void IframesSupport::registerIframe(const JSObjectPtr& iframe){
42     LogDebug("LoadedIframes size: " << m_loadedIframes.size() );
43
44     m_loadedIframes.insert(iframe);
45 }
46
47 void IframesSupport::unregisterIframe(const JSObjectPtr& iframe){
48     LogDebug("LoadedIframes size: " << m_loadedIframes.size() );
49
50     auto it_loaded = std::find_if(m_loadedIframes.begin(),
51             m_loadedIframes.end(),
52             std::bind2nd(EqualToJSObjectPtr(), iframe));
53     //object not found, so thats the new iframe
54     if(it_loaded == m_loadedIframes.end()){
55         LogDebug("Nothing to unregister");
56         return;
57     }
58
59     m_loadedIframes.erase(it_loaded);
60 }
61
62 bool IframesSupport::hasIframes() const
63 {
64     return !m_loadedIframes.empty();
65 }
66
67 IframesSupport::DeclarationsList IframesSupport::getIframeObjects() const
68 {
69     return m_iframesObjects;
70 }
71
72 void IframesSupport::clean()
73 {
74     m_iframesObjects.clear();
75     m_loadedIframes.clear();
76 }