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_PLUGIN_SO( "libdali-web-engine-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()
53 WebEngine* engine = new WebEngine();
55 if ( !engine->Initialize() )
65 WebEngine::WebEngine()
68 mCreateWebEnginePtr( NULL ),
69 mDestroyWebEnginePtr( NULL )
73 WebEngine::~WebEngine()
77 if( mDestroyWebEnginePtr != NULL )
80 mDestroyWebEnginePtr( mPlugin );
87 bool WebEngine::Initialize()
91 mHandle = dlopen( WEB_ENGINE_PLUGIN_SO, RTLD_LAZY );
94 if( mHandle == NULL || error != NULL )
96 DALI_LOG_ERROR( "WebEngine::Initialize(), dlopen error: %s\n", error );
100 mCreateWebEnginePtr = reinterpret_cast< CreateWebEngineFunction >( dlsym( mHandle, "CreateWebEnginePlugin" ) );
101 if( mCreateWebEnginePtr == NULL )
103 DALI_LOG_ERROR( "Can't load symbol CreateWebEnginePlugin(), error: %s\n", error );
107 mPlugin = mCreateWebEnginePtr();
109 if( mPlugin == NULL )
111 DALI_LOG_ERROR( "Can't create the WebEnginePlugin object\n" );
115 mDestroyWebEnginePtr = reinterpret_cast< DestroyWebEngineFunction >( dlsym( mHandle, "DestroyWebEnginePlugin" ) );
117 if( mDestroyWebEnginePtr == NULL )
120 DALI_LOG_ERROR( "Can't load symbol DestroyWebEnginePlugin(), error: %s\n", error );
127 void WebEngine::Create( int width, int height, const std::string& locale, const std::string& timezoneId )
129 if( mPlugin != NULL )
131 mPlugin->Create( width, height, locale, timezoneId );
135 void WebEngine::Destroy()
137 if( mPlugin != NULL )
143 Dali::NativeImageInterfacePtr WebEngine::GetNativeImageSource()
145 return mPlugin->GetNativeImageSource();
148 void WebEngine::LoadUrl( const std::string& url )
150 if( mPlugin != NULL )
152 mPlugin->LoadUrl( url );
156 const std::string& WebEngine::GetUrl()
158 static std::string emptyUrl;
159 return mPlugin ? mPlugin->GetUrl() : emptyUrl;
162 void WebEngine::LoadHTMLString( const std::string& htmlString )
164 if( mPlugin != NULL )
166 mPlugin->LoadHTMLString( htmlString );
170 void WebEngine::Reload()
172 if( mPlugin != NULL )
178 void WebEngine::StopLoading()
180 if( mPlugin != NULL )
182 mPlugin->StopLoading();
186 bool WebEngine::CanGoForward()
188 return mPlugin ? mPlugin->CanGoForward() : false;
191 void WebEngine::GoForward()
193 if( mPlugin != NULL )
195 mPlugin->GoForward();
199 bool WebEngine::CanGoBack()
201 return mPlugin ? mPlugin->CanGoBack() : false;
204 void WebEngine::GoBack()
206 if( mPlugin != NULL )
212 void WebEngine::EvaluateJavaScript( const std::string& script )
214 if( mPlugin != NULL )
216 mPlugin->EvaluateJavaScript( script );
220 void WebEngine::AddJavaScriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName, std::function< std::string(const std::string&) > cb )
222 if( mPlugin != NULL )
224 mPlugin->AddJavaScriptInterface( exposedObjectName, jsFunctionName, cb );
228 void WebEngine::RemoveJavascriptInterface( const std::string& exposedObjectName, const std::string& jsFunctionName )
230 if( mPlugin != NULL )
232 mPlugin->RemoveJavascriptInterface( exposedObjectName, jsFunctionName );
236 void WebEngine::ClearHistory()
238 if( mPlugin != NULL )
240 mPlugin->ClearHistory();
244 void WebEngine::ClearCache()
246 if( mPlugin != NULL )
248 mPlugin->ClearCache();
252 void WebEngine::SetSize( int width, int height )
254 if( mPlugin != NULL )
256 mPlugin->SetSize( width, height );
260 bool WebEngine::SendTouchEvent( const Dali::TouchData& touch )
262 if( mPlugin != NULL )
264 return mPlugin->SendTouchEvent( touch );
270 bool WebEngine::SendKeyEvent( const Dali::KeyEvent& event )
272 if( mPlugin != NULL )
274 return mPlugin->SendKeyEvent( event );
280 Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadStartedSignal()
282 return mPlugin->PageLoadStartedSignal();
285 Dali::WebEnginePlugin::WebEngineSignalType& WebEngine::PageLoadFinishedSignal()
287 return mPlugin->PageLoadFinishedSignal();
290 } // namespace Adaptor;
291 } // namespace Internal;