61672c7624bb199efe716c9ff4c3f789f4f9fd31
[platform/framework/web/web-provider.git] / src / Plugin / AppBoxPlugin / AppBoxManager.cpp
1 /*
2  * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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    AppBoxManager.cpp
18  * @author  Yunchan Cho (yunchan.cho@samsung.com)
19  */
20 #include <core_module.h>
21 #include <Plugin/IBoxPluginFactory.h>
22 #include <Core/BoxData.h>
23 #include <Core/BoxManager.h>
24 #include <Core/IBox.h>
25 #include "AppBoxObserver.h"
26 #include "AppBoxManager.h"
27
28 static const std::string bundlePath("/usr/lib/libwrt-injected-bundle.so");
29
30 AppBoxManager::AppBoxManager(IBoxPluginFactoryPtr factory)
31     : BoxManager(factory)
32 {
33     bool ret = WRT::CoreModuleSingleton::Instance().Init();
34     if (!ret) {
35         throw; // throw exeception
36     }
37     m_defaultEwkContext.reset(
38                 ewk_context_new_with_injected_bundle_path(bundlePath.c_str()));
39     AppBoxObserver::Instance()->initialize();
40 }
41
42 AppBoxManager::~AppBoxManager()
43 {
44     AppBoxObserver::Instance()->shutdown();
45     WRT::CoreModuleSingleton::Instance().Terminate();
46 }
47
48 bool AppBoxManager::requestAddBox(BoxInfoPtr boxInfo, EwkContextPtr ewkContext)
49 {
50     ewkContext = getAvailableEwkContext();
51     if (!BoxManager::requestAddBox(boxInfo, ewkContext)) {
52         return false;
53     }
54
55     insertContextMap(ewkContext, boxInfo->instanceId);
56     return true;
57 }
58
59 bool AppBoxManager::requestRemoveBox(std::string& instanceId)
60 {
61     if (!BoxManager::requestRemoveBox(instanceId)) {
62         return false;
63     }
64
65     eraseContextMap(instanceId);
66     return true; 
67 }
68
69 EwkContextPtr AppBoxManager::getAvailableEwkContext()
70 {
71     // TODO make proper Ewk_Context instance, and update context map 
72     // std::shared_ptr<Ewk_Context> context(
73     //                      ewk_context_new(), 
74     //                      BoxManager::deleteDefaultEwkContext);
75     
76     return m_defaultEwkContext;
77 }
78
79 void AppBoxManager::insertContextMap(EwkContextPtr ewkContext, std::string& instanceId)
80 {
81     // not implemented
82 }
83
84 void AppBoxManager::eraseContextMap(std::string& instanceId)
85 {
86     // not implemented
87 }