2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "tizen-web-engine-manager.h"
20 #include "tizen-web-engine-context.h"
21 #include "tizen-web-engine-cookie-manager.h"
23 #include <Elementary.h>
25 #include <dali/devel-api/adaptor-framework/lifecycle-controller.h>
26 #include <dali/integration-api/debug.h>
28 #include <ewk_context.h>
29 #include <ewk_context_internal.h>
39 WebEngineManager& WebEngineManager::Get()
41 static WebEngineManager instance;
45 bool WebEngineManager::IsAvailable()
47 return Get().mWebEngineManagerAvailable;
50 WebEngineManager::WebEngineManager()
51 : mSlotDelegate(this),
52 mWebEngineManagerAvailable(true)
54 DALI_LOG_RELEASE_INFO("#WebEngineManager is created.\n");
58 mWindow = ecore_evas_new("wayland_shm", 0, 0, 1, 1, 0);
60 Ewk_Context* context = ewk_context_default_get();
61 mWebEngineContext.reset(new TizenWebEngineContext(context));
63 Ewk_Cookie_Manager* manager = ewk_context_cookie_manager_get(context);
64 mWebEngineCookieManager.reset(new TizenWebEngineCookieManager(manager));
65 Dali::LifecycleController::Get().TerminateSignal().Connect(mSlotDelegate, &WebEngineManager::OnTerminated);
67 DALI_LOG_RELEASE_INFO("#WebEngineManager is created fully.\n");
70 WebEngineManager::~WebEngineManager()
72 if(mWebEngineManagerAvailable)
76 // Call OnTerminated directly.
79 catch(std::invalid_argument const& ex)
81 DALI_LOG_RELEASE_INFO("Failed to destroy web engine:%s!\n", ex.what());
86 Ecore_Evas* WebEngineManager::GetWindow()
91 Dali::WebEngineContext* WebEngineManager::GetContext()
93 return mWebEngineContext.get();
96 Dali::WebEngineCookieManager* WebEngineManager::GetCookieManager()
98 return mWebEngineCookieManager.get();
101 void WebEngineManager::Add(Evas_Object* webView, Dali::WebEnginePlugin* engine)
103 mWebEngines[webView] = engine;
106 void WebEngineManager::Remove(Evas_Object* webView)
108 auto iter = mWebEngines.find(webView);
109 if(iter != mWebEngines.end())
111 mWebEngines.erase(iter);
115 Dali::WebEnginePlugin* WebEngineManager::Find(Evas_Object* webView)
117 auto iter = mWebEngines.find(webView);
118 if(iter != mWebEngines.end())
125 Evas_Object* WebEngineManager::Find(Dali::WebEnginePlugin* plugin)
127 for(auto it = mWebEngines.begin(); it != mWebEngines.end(); it++)
129 if (it->second == plugin)
137 void WebEngineManager::OnTerminated()
139 // Ignore duplicated termination
140 if(DALI_UNLIKELY(!mWebEngineManagerAvailable))
144 DALI_LOG_RELEASE_INFO("#WebEngineManager is destroyed.\n");
146 // App is terminated. Now web engine is not available anymore.
147 mWebEngineManagerAvailable = false;
149 for(auto it = mWebEngines.begin(); it != mWebEngines.end(); it++)
152 auto webEnginePlugin = it->second;
155 webEnginePlugin->Destroy();
159 ecore_evas_free(mWindow);
161 // Release context and cookie manager before ewk_shutdown.
162 mWebEngineContext.reset();
163 mWebEngineCookieManager.reset();
167 DALI_LOG_RELEASE_INFO("#WebEngineManager is destroyed fully.\n");
170 } // namespace Plugin
173 extern "C" DALI_EXPORT_API Dali::WebEngineContext* GetWebEngineContext()
175 return Dali::Plugin::WebEngineManager::Get().GetContext();
178 extern "C" DALI_EXPORT_API Dali::WebEngineCookieManager* GetWebEngineCookieManager()
180 return Dali::Plugin::WebEngineManager::Get().GetCookieManager();