Change WebEngine API
[platform/core/uifw/dali-adaptor.git] / dali / internal / web-engine / common / web-engine-impl.h
1 #ifndef DALI_WEB_ENGINE_IMPL_H
2 #define DALI_WEB_ENGINE_IMPL_H
3
4 /*
5  * Copyright (c) 2018 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/public-api/object/base-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/web-engine.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-plugin.h>
27
28 namespace Dali
29 {
30
31 namespace Internal
32 {
33
34 namespace Adaptor
35 {
36
37 class WebEngine;
38
39 typedef IntrusivePtr< WebEngine > WebEnginePtr;
40
41 /**
42  * @brief WebEngine class is used for Web.
43  */
44 class WebEngine : public Dali::BaseObject
45 {
46 public:
47
48   /**
49    * @brief Creates a new WebEngine handle
50    *
51    * @return WebEngine pointer
52    */
53   static WebEnginePtr New();
54
55   /**
56    * @copydoc Dali::WebEngine::Create()
57    */
58   void Create( int width, int height, const std::string& locale, const std::string& timezoneId );
59
60   /**
61    * @copydoc Dali::WebEngine::Destroy()
62    */
63   void Destroy();
64
65   /**
66    * @copydoc Dali::WebEngine::GetNativeImageSource()
67    */
68   Dali::NativeImageInterfacePtr GetNativeImageSource();
69
70   /**
71    * @copydoc Dali::WebEngine::LoadUrl()
72    */
73   void LoadUrl( const std::string& url );
74
75   /**
76    * @copydoc Dali::WebEngine::GetUrl()
77    */
78   const std::string& GetUrl();
79
80   /**
81    * @copydoc Dali::WebEngine::LoadHTMLString()
82    */
83   void LoadHTMLString( const std::string& htmlString );
84
85   /**
86    * @copydoc Dali::WebEngine::Reload()
87    */
88   void Reload();
89
90   /**
91    * @copydoc Dali::WebEngine::StopLoading()
92    */
93   void StopLoading();
94
95   /**
96    * @copydoc Dali::WebEngine::CanGoForward()
97    */
98   bool CanGoForward();
99
100   /**
101    * @copydoc Dali::WebEngine::GoForward()
102    */
103   void GoForward();
104
105   /**
106    * @copydoc Dali::WebEngine::CanGoBack()
107    */
108   bool CanGoBack();
109
110   /**
111    * @copydoc Dali::WebEngine::GoBack()
112    */
113   void GoBack();
114
115   /**
116    * @copydoc Dali::WebEngine::EvaluateJavaScript()
117    */
118   void EvaluateJavaScript( const std::string& script );
119
120   /**
121    * @copydoc Dali::WebEngine::AddJavaScriptMessageHandler()
122    */
123   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler );
124
125   /**
126    * @copydoc Dali::WebEngine::ClearHistory()
127    */
128   void ClearHistory();
129
130   /**
131    * @copydoc Dali::WebEngine::ClearCache()
132    */
133   void ClearCache();
134
135   /**
136    * @copydoc Dali::WebEngine::SetSize()
137    */
138   void SetSize( int width, int height );
139
140   /**
141    * @copydoc Dali::WebEngine::SendTouchEvent()
142    */
143   bool SendTouchEvent( const Dali::TouchData& touch );
144
145   /**
146    * @copydoc Dali::WebEngine::SendKeyEvent()
147    */
148   bool SendKeyEvent( const Dali::KeyEvent& event );
149
150   /**
151    * @copydoc Dali::WebEngine::PageLoadStartedSignal()
152    */
153   Dali::WebEnginePlugin::WebEngineSignalType& PageLoadStartedSignal();
154
155   /**
156    * @copydoc Dali::WebEngine::PageLoadFinishedSignal()
157    */
158   Dali::WebEnginePlugin::WebEngineSignalType& PageLoadFinishedSignal();
159
160 private:
161
162   /**
163    * @brief Constructor.
164    */
165   WebEngine();
166
167   /**
168    * @brief Destructor.
169    */
170   virtual ~WebEngine();
171
172   // Undefined copy constructor
173   WebEngine( const WebEngine& WebEngine );
174
175   // Undefined assignment operator
176   WebEngine& operator=( const WebEngine& WebEngine );
177
178   /**
179    * @brief Initializes member data.
180    *
181    * @return Whether the initialization succeed or not.
182    */
183   bool Initialize();
184
185   /**
186    * @brief Initializes library handle by loading web engine plugin.
187    *
188    * @return Whether the initialization succeed or not.
189    */
190   bool InitializePluginHandle();
191
192 private:
193
194   Dali::WebEnginePlugin* mPlugin; ///< WebEnginePlugin instance
195   void* mHandle; ///< Handle for the loaded library
196
197   typedef Dali::WebEnginePlugin* (*CreateWebEngineFunction)();
198   typedef void (*DestroyWebEngineFunction)( Dali::WebEnginePlugin* plugin );
199
200   CreateWebEngineFunction mCreateWebEnginePtr;
201   DestroyWebEngineFunction mDestroyWebEnginePtr;
202 };
203
204 } // namespace Adaptor
205 } // namespace Internal
206
207 inline static Internal::Adaptor::WebEngine& GetImplementation( Dali::WebEngine& webEngine )
208 {
209   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
210
211   BaseObject& handle = webEngine.GetBaseObject();
212
213   return static_cast< Internal::Adaptor::WebEngine& >( handle );
214 }
215
216 inline static const Internal::Adaptor::WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
217 {
218   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
219
220   const BaseObject& handle = webEngine.GetBaseObject();
221
222   return static_cast< const Internal::Adaptor::WebEngine& >( handle );
223 }
224
225 } // namespace Dali;
226
227 #endif
228