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>
38 // @todo : If we make this value as member of WebEngineManager, we got crashed due to 'elm_init' symbol found failed.
39 static bool gWebEngineManagerAvailable = true; // Default as true
42 WebEngineManager& WebEngineManager::Get()
44 static WebEngineManager instance;
48 bool WebEngineManager::IsAvailable()
50 return gWebEngineManagerAvailable;
53 WebEngineManager::WebEngineManager()
56 DALI_LOG_RELEASE_INFO("#WebEngineManager is created.\n");
60 mWindow = ecore_evas_new("wayland_egl", 0, 0, 1, 1, 0);
62 Ewk_Context* context = ewk_context_default_get();
63 mWebEngineContext.reset(new TizenWebEngineContext(context));
65 Ewk_Cookie_Manager* manager = ewk_context_cookie_manager_get(context);
66 mWebEngineCookieManager.reset(new TizenWebEngineCookieManager(manager));
67 Dali::LifecycleController::Get().TerminateSignal().Connect(mSlotDelegate, &WebEngineManager::OnTerminated);
69 DALI_LOG_RELEASE_INFO("#WebEngineManager is created fully.\n");
72 WebEngineManager::~WebEngineManager()
74 if(gWebEngineManagerAvailable)
76 // Call OnTerminated directly.
81 Ecore_Evas* WebEngineManager::GetWindow()
86 Dali::WebEngineContext* WebEngineManager::GetContext()
88 return mWebEngineContext.get();
91 Dali::WebEngineCookieManager* WebEngineManager::GetCookieManager()
93 return mWebEngineCookieManager.get();
96 void WebEngineManager::Add(Evas_Object* webView, Dali::WebEnginePlugin* engine)
98 mWebEngines[webView] = engine;
101 void WebEngineManager::Remove(Evas_Object* webView)
103 auto iter = mWebEngines.find(webView);
104 if(iter != mWebEngines.end())
106 mWebEngines.erase(iter);
110 Dali::WebEnginePlugin* WebEngineManager::Find(Evas_Object* webView)
112 auto iter = mWebEngines.find(webView);
113 if(iter != mWebEngines.end())
123 void WebEngineManager::OnTerminated()
125 // Ignore duplicated termination
126 if(DALI_UNLIKELY(!gWebEngineManagerAvailable))
130 DALI_LOG_RELEASE_INFO("#WebEngineManager is destroyed.\n");
132 // App is terminated. Now web engine is not available anymore.
133 gWebEngineManagerAvailable = false;
135 for(auto it = mWebEngines.begin(); it != mWebEngines.end(); it++)
138 auto webEnginePlugin = it->second;
141 webEnginePlugin->Destroy();
145 ecore_evas_free(mWindow);
147 // Release context and cookie manager before ewk_shutdown.
148 mWebEngineContext.reset();
149 mWebEngineCookieManager.reset();
153 DALI_LOG_RELEASE_INFO("#WebEngineManager is destroyed fully.\n");
156 } // namespace Plugin
159 extern "C" DALI_EXPORT_API Dali::WebEngineContext* GetWebEngineContext()
161 return Dali::Plugin::WebEngineManager::Get().GetContext();
164 extern "C" DALI_EXPORT_API Dali::WebEngineCookieManager* GetWebEngineCookieManager()
166 return Dali::Plugin::WebEngineManager::Get().GetCookieManager();