/*
* Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
*
- * Licensed under the Flora License, Version 1.0 (the "License");
+ * Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* @file AppBoxManager.cpp
* @author Yunchan Cho (yunchan.cho@samsung.com)
*/
+#include <map>
#include <core_module.h>
#include <Plugin/IBoxPluginFactory.h>
#include <Core/BoxData.h>
#include <Core/BoxManager.h>
#include <Core/IBox.h>
+#include <Core/Util/Log.h>
+#include <API/web_provider_livebox_info.h>
#include "AppBoxObserver.h"
#include "AppBoxManager.h"
-static const std::string bundlePath("/usr/lib/wrt-wk2-bundles/libwrt-wk2-bundle.so");
+static const std::string bundlePath("/usr/lib/libwrt-injected-bundle.so");
AppBoxManager::AppBoxManager(IBoxPluginFactoryPtr factory)
: BoxManager(factory)
if (!ret) {
throw; // throw exeception
}
- m_defaultEwkContext.reset(
- ewk_context_new_with_injected_bundle_path(bundlePath.c_str()));
AppBoxObserver::Instance()->initialize();
}
bool AppBoxManager::requestAddBox(BoxInfoPtr boxInfo, EwkContextPtr ewkContext)
{
- ewkContext = getAvailableEwkContext();
+
+ const char* appId =
+ web_provider_livebox_get_app_id(boxInfo->boxId.c_str());
+
+ if (!appId) {
+ LogD("no appid of %s", boxInfo->boxId.c_str());
+ return false;
+ }
+
+ std::string appIdStr(appId);
+ delete appId;
+
+ auto it = m_ewkContextMap.find(appIdStr);
+ if (it == m_ewkContextMap.end()) {
+ ewkContext = getAvailableEwkContext();
+ insertContextMap(appIdStr, ewkContext);
+ } else {
+ ewkContext = it->second;
+ }
+
if (!BoxManager::requestAddBox(boxInfo, ewkContext)) {
return false;
}
- insertContextMap(ewkContext, boxInfo->instanceId);
return true;
}
return false;
}
- eraseContextMap(instanceId);
return true;
}
EwkContextPtr AppBoxManager::getAvailableEwkContext()
{
- // TODO make proper Ewk_Context instance, and update context map
- // std::shared_ptr<Ewk_Context> context(
- // ewk_context_new(),
- // BoxManager::deleteDefaultEwkContext);
-
- return m_defaultEwkContext;
+ return EwkContextPtr(
+ ewk_context_new_with_injected_bundle_path(bundlePath.c_str()),
+ BoxManager::EwkContextDeleter());
}
-void AppBoxManager::insertContextMap(EwkContextPtr ewkContext, std::string& instanceId)
+void AppBoxManager::insertContextMap(std::string& appId, EwkContextPtr ewkContext)
{
- // not implemented
+ m_ewkContextMap.insert(EwkContextMapPair(appId, ewkContext));
}
-void AppBoxManager::eraseContextMap(std::string& instanceId)
+void AppBoxManager::eraseContextMap(std::string& appId)
{
- // not implemented
+ m_ewkContextMap.erase(appId);
}