2 * Copyright (c) 2018 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.
19 #include <dali/internal/web-engine/common/web-engine-impl.h>
23 #include <dali/integration-api/debug.h>
24 #include <dali/public-api/adaptor-framework/native-image-source.h>
25 #include <dali/public-api/object/type-registry.h>
29 #include <dali/devel-api/adaptor-framework/environment-variable.h>
40 namespace // unnamed namespace
43 #define DALI_ENV_WEB_ENGINE_NAME "DALI_WEB_ENGINE_NAME"
45 const char* WEB_ENGINE_CHROMIUM_NAME( "chromium" );
46 const char* WEB_ENGINE_LITE_NAME( "lightweight" );
48 const char* WEB_ENGINE_PLUGIN_SO( "libdali-web-engine-plugin.so" );
49 const char* WEB_ENGINE_CHROMIUM_PLUGIN_SO( "libdali-web-engine-chromium-plugin.so" );
50 const char* WEB_ENGINE_LITE_PLUGIN_SO( "libdali-web-engine-lite-plugin.so" );
52 Dali::BaseHandle Create()
54 return Dali::WebEngine::New();
57 Dali::TypeRegistration type( typeid( Dali::WebEngine ), typeid( Dali::BaseHandle ), Create );
59 } // unnamed namespace
61 WebEnginePtr WebEngine::New()
64 WebEngine* engine = new WebEngine();
66 if ( !engine->Initialize() )
76 WebEngine::WebEngine()
79 mCreateWebEnginePtr( NULL ),
80 mDestroyWebEnginePtr( NULL )
84 WebEngine::~WebEngine()
88 if( mDestroyWebEnginePtr != NULL )
91 mDestroyWebEnginePtr( mPlugin );
98 bool WebEngine::Initialize()
102 const char* engineName = WEB_ENGINE_PLUGIN_SO;
103 const char* engineEnvName = EnvironmentVariable::GetEnvironmentVariable( DALI_ENV_WEB_ENGINE_NAME );
107 if( 0 == strcmp( engineEnvName, WEB_ENGINE_CHROMIUM_NAME ) )
109 engineName = WEB_ENGINE_CHROMIUM_PLUGIN_SO;
111 else if( 0 == strcmp( engineEnvName, WEB_ENGINE_LITE_NAME ) )
113 engineName = WEB_ENGINE_LITE_PLUGIN_SO;
117 mHandle = dlopen( engineName, RTLD_LAZY );
120 if( mHandle == NULL || error != NULL )
122 DALI_LOG_ERROR( "WebEngine::Initialize(), dlopen error: %s\n", error );
126 mCreateWebEnginePtr = reinterpret_cast< CreateWebEngineFunction >( dlsym( mHandle, "CreateWebEnginePlugin" ) );
127 if( mCreateWebEnginePtr == NULL )
129 DALI_LOG_ERROR( "Can't load symbol CreateWebEnginePlugin(), error: %s\n", error );
133 mPlugin = mCreateWebEnginePtr();
135 if( mPlugin == NULL )
137 DALI_LOG_ERROR( "Can't create the WebEnginePlugin object\n" );
141 mDestroyWebEnginePtr = reinterpret_cast< DestroyWebEngineFunction >( dlsym( mHandle, "DestroyWebEnginePlugin" ) );
143 if( mDestroyWebEnginePtr == NULL )
146 DALI_LOG_ERROR( "Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error );
153 void WebEngine::Create( int width, int height, const std::string& locale, const std::string& timezoneId )
155 if( mPlugin != NULL )
157 mPlugin->Create( width, height, locale, timezoneId );
161 void WebEngine::Destroy()
163 if( mPlugin != NULL )
169 Dali::NativeImageInterfacePtr WebEngine::GetNativeImageSource()
171 return mPlugin->GetNativeImageSource();
174 void WebEngine::LoadUrl( const std::string& url )
176 if( mPlugin != NULL )
178 mPlugin->LoadUrl( url );
182 const std::string& WebEngine::GetUrl()
184 static std::string emptyUrl;
185 return mPlugin ? mPlugin->GetUrl() : emptyUrl;
188 void WebEngine::LoadHTMLString( const std::string& htmlString )
190 if( mPlugin != NULL )
192 mPlugin->LoadHTMLString( htmlString );
196 void WebEngine::Reload()
198 if( mPlugin != NULL )
204 void WebEngine::StopLoading()
206 if( mPlugin != NULL )
208 mPlugin->StopLoading();
212 bool WebEngine::CanGoForward()
214 return mPlugin ? mPlugin->CanGoForward() : false;
217 void WebEngine::GoForward()
219 if( mPlugin != NULL )
221 mPlugin->GoForward();
225 bool WebEngine::CanGoBack()
227 return mPlugin ? mPlugin->CanGoBack() : false;
230 void WebEngine::GoBack()
232 if( mPlugin != NULL )
238 void WebEngine::EvaluateJavaScript( const std::string& script )
240 if( mPlugin != NULL )
242 mPlugin->EvaluateJavaScript( script );
246 void WebEngine::AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > cb )
248 if( mPlugin != NULL )
250 mPlugin->AddJavaScriptInterface( exposedObjectName, jsFunctionName, cb );
254 void WebEngine::RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName )
256 if( mPlugin != NULL )
258 mPlugin->RemoveJavascriptInterface( exposedObjectName, jsFunctionName );
262 void WebEngine::ClearHistory()
264 if( mPlugin != NULL )
266 mPlugin->ClearHistory();
270 void WebEngine::ClearCache()
272 if( mPlugin != NULL )
274 mPlugin->ClearCache();
278 void WebEngine::SetSize( int width, int height )
280 if( mPlugin != NULL )
282 mPlugin->SetSize( width, height );
286 bool WebEngine::SendTouchEvent( const Dali::TouchData& touch )
288 if( mPlugin != NULL )
290 return mPlugin->SendTouchEvent( touch );
296 bool WebEngine::SendKeyEvent( const Dali::KeyEvent& event )
298 if( mPlugin != NULL )
300 return mPlugin->SendKeyEvent( event );
306 Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadStartedSignal()
308 return mPlugin->PageLoadStartedSignal();
311 Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadFinishedSignal()
313 return mPlugin->PageLoadFinishedSignal();
316 } // namespace Adaptor;
317 } // namespace Internal;