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>
36 WebEngineManager& WebEngineManager::Get()
38 static WebEngineManager instance;
42 bool WebEngineManager::IsAvailable()
44 return Get().mWebEngineManagerAvailable;
47 WebEngineManager::WebEngineManager()
48 : mSlotDelegate(this),
49 mWebEngineManagerAvailable(true)
53 mWindow = ecore_evas_new("wayland_egl", 0, 0, 1, 1, 0);
55 Ewk_Context* context = ewk_context_default_get();
56 mWebEngineContext.reset(new TizenWebEngineContext(context));
58 Ewk_Cookie_Manager* manager = ewk_context_cookie_manager_get(context);
59 mWebEngineCookieManager.reset(new TizenWebEngineCookieManager(manager));
60 Dali::LifecycleController::Get().TerminateSignal().Connect(mSlotDelegate, &WebEngineManager::OnTerminated);
63 WebEngineManager::~WebEngineManager()
65 if(mWebEngineManagerAvailable)
67 // Call OnTerminated directly.
72 Ecore_Evas* WebEngineManager::GetWindow()
77 Dali::WebEngineContext* WebEngineManager::GetContext()
79 return mWebEngineContext.get();
82 Dali::WebEngineCookieManager* WebEngineManager::GetCookieManager()
84 return mWebEngineCookieManager.get();
87 void WebEngineManager::Add(Evas_Object* webView, Dali::WebEnginePlugin* engine)
89 mWebEngines[webView] = engine;
92 void WebEngineManager::Remove(Evas_Object* webView)
94 auto iter = mWebEngines.find(webView);
95 if(iter != mWebEngines.end())
97 mWebEngines.erase(iter);
101 Dali::WebEnginePlugin* WebEngineManager::Find(Evas_Object* webView)
103 auto iter = mWebEngines.find(webView);
104 if(iter != mWebEngines.end())
114 void WebEngineManager::OnTerminated()
116 // App is terminated. Now web engine is not available anymore.
117 mWebEngineManagerAvailable = false;
119 Dali::LifecycleController::Get().TerminateSignal().Disconnect(mSlotDelegate, &WebEngineManager::OnTerminated);
121 for(auto it = mWebEngines.begin(); it != mWebEngines.end(); it++)
124 auto webEnginePlugin = it->second;
127 webEnginePlugin->Destroy();
131 ecore_evas_free(mWindow);
133 // Release context and cookie manager before ewk_shutdown.
134 mWebEngineContext.reset();
135 mWebEngineCookieManager.reset();
139 DALI_LOG_RELEASE_INFO("#WebEngineManager is destroyed fully.\n");
142 } // namespace Plugin
145 extern "C" DALI_EXPORT_API Dali::WebEngineContext* GetWebEngineContext()
147 return Dali::Plugin::WebEngineManager::Get().GetContext();
150 extern "C" DALI_EXPORT_API Dali::WebEngineCookieManager* GetWebEngineCookieManager()
152 return Dali::Plugin::WebEngineManager::Get().GetCookieManager();