[Release] livebox.web-provider-1.46
[platform/framework/web/web-provider.git] / src / Plugin / AppBoxPlugin / AppBoxManager.cpp
index 539b956..ea71ad1 100644 (file)
@@ -1,11 +1,11 @@
 /*
  * 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
  *
- *        http://www.tizenopensource.org/license
+ *        http://floralicense.org/license/
  *
  *    Unless required by applicable law or agreed to in writing, software
  *    distributed under the License is distributed on an "AS IS" BASIS,
  * @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)
@@ -34,8 +37,6 @@ AppBoxManager::AppBoxManager(IBoxPluginFactoryPtr factory)
     if (!ret) {
         throw; // throw exeception
     }
-    m_defaultEwkContext.reset(
-                ewk_context_new_with_injected_bundle_path(bundlePath.c_str()));
     AppBoxObserver::Instance()->initialize();
 }
 
@@ -47,12 +48,30 @@ AppBoxManager::~AppBoxManager()
 
 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;
 }
 
@@ -62,26 +81,22 @@ bool AppBoxManager::requestRemoveBox(std::string& instanceId)
         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);
 }