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>
36 namespace // unnamed namespace
39 const char* WEB_ENGINE_LITE_PLUGIN_SO( "libdali-web-engine-lite-plugin.so" );
41 Dali::BaseHandle Create()
43 return Dali::WebEngine::New();
46 Dali::TypeRegistration type( typeid( Dali::WebEngine ), typeid( Dali::BaseHandle ), Create );
48 } // unnamed namespace
50 WebEnginePtr WebEngine::New()
52 WebEngine* engine = new WebEngine();
54 if ( engine->Initialize() )
56 return WebEnginePtr( engine );
61 return WebEnginePtr();
64 WebEngine::WebEngine()
67 mCreateWebEnginePtr( NULL ),
68 mDestroyWebEnginePtr( NULL )
72 WebEngine::~WebEngine()
76 if( mDestroyWebEnginePtr != NULL )
79 mDestroyWebEnginePtr( mPlugin );
86 bool WebEngine::Initialize()
90 mHandle = dlopen( WEB_ENGINE_LITE_PLUGIN_SO, RTLD_LAZY );
93 if( mHandle == NULL || error != NULL )
95 DALI_LOG_ERROR( "WebEngine::Initialize(), dlopen error: %s\n", error );
99 mCreateWebEnginePtr = reinterpret_cast< CreateWebEngineFunction >( dlsym( mHandle, "CreateWebEnginePlugin" ) );
100 if( mCreateWebEnginePtr == NULL )
102 DALI_LOG_ERROR( "Can't load symbol CreateWebEnginePlugin(), error: %s\n", error );
106 mPlugin = mCreateWebEnginePtr();
108 if( mPlugin == NULL )
110 DALI_LOG_ERROR( "Can't create the WebEnginePlugin object\n" );
114 mDestroyWebEnginePtr = reinterpret_cast< DestroyWebEngineFunction >( dlsym( mHandle, "DestroyWebEnginePlugin" ) );
116 if( mDestroyWebEnginePtr == NULL )
119 DALI_LOG_ERROR( "Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error );
126 void WebEngine::Create( int width, int height, const std::string& locale, const std::string& timezoneId )
128 if( mPlugin != NULL )
130 mPlugin->Create( width, height, locale, timezoneId );
134 void WebEngine::Destroy()
136 if( mPlugin != NULL )
142 Dali::NativeImageInterfacePtr WebEngine::GetNativeImageSource()
144 return mPlugin->GetNativeImageSource();
147 void WebEngine::LoadUrl( const std::string& url )
149 if( mPlugin != NULL )
151 mPlugin->LoadUrl( url );
155 const std::string& WebEngine::GetUrl()
157 static std::string emptyUrl;
158 return mPlugin ? mPlugin->GetUrl() : emptyUrl;
161 void WebEngine::LoadHTMLString( const std::string& htmlString )
163 if( mPlugin != NULL )
165 mPlugin->LoadHTMLString( htmlString );
169 void WebEngine::Reload()
171 if( mPlugin != NULL )
177 void WebEngine::StopLoading()
179 if( mPlugin != NULL )
181 mPlugin->StopLoading();
185 bool WebEngine::CanGoForward()
187 return mPlugin ? mPlugin->CanGoForward() : false;
190 void WebEngine::GoForward()
192 if( mPlugin != NULL )
194 mPlugin->GoForward();
198 bool WebEngine::CanGoBack()
200 return mPlugin ? mPlugin->CanGoBack() : false;
203 void WebEngine::GoBack()
205 if( mPlugin != NULL )
211 void WebEngine::EvaluateJavaScript( const std::string& script )
213 if( mPlugin != NULL )
215 mPlugin->EvaluateJavaScript( script );
219 void WebEngine::AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > cb )
221 if( mPlugin != NULL )
223 mPlugin->AddJavaScriptInterface( exposedObjectName, jsFunctionName, cb );
227 void WebEngine::RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName )
229 if( mPlugin != NULL )
231 mPlugin->RemoveJavascriptInterface( exposedObjectName, jsFunctionName );
235 void WebEngine::ClearHistory()
237 if( mPlugin != NULL )
239 mPlugin->ClearHistory();
243 void WebEngine::ClearCache()
245 if( mPlugin != NULL )
247 mPlugin->ClearCache();
251 void WebEngine::SetSize( int width, int height )
253 if( mPlugin != NULL )
255 mPlugin->SetSize( width, height );
259 bool WebEngine::SendTouchEvent( const Dali::TouchData& touch )
261 if( mPlugin != NULL )
263 return mPlugin->SendTouchEvent( touch );
269 bool WebEngine::SendKeyEvent( const Dali::KeyEvent& event )
271 if( mPlugin != NULL )
273 return mPlugin->SendKeyEvent( event );
279 Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadStartedSignal()
281 return mPlugin->PageLoadStartedSignal();
284 Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadFinishedSignal()
286 return mPlugin->PageLoadFinishedSignal();
289 } // namespace Adaptor;
290 } // namespace Internal;