Implement navigation decision policy.
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / web-view / web-view-impl.h
1 #ifndef DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
2 #define DALI_TOOLKIT_INTERNAL_WEB_VIEW_H
3
4 /*
5  * Copyright (c) 2020 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 <memory>
23 #include <dali/devel-api/adaptor-framework/web-engine.h>
24 #include <dali/public-api/images/image-operations.h>
25 #include <dali/public-api/object/property-notification.h>
26
27 // INTERNAL INCLUDES
28 #include <dali-toolkit/devel-api/controls/web-view/web-view.h>
29 #include <dali-toolkit/devel-api/visual-factory/visual-base.h>
30 #include <dali-toolkit/public-api/controls/control-impl.h>
31 #include <dali-toolkit/public-api/controls/image-view/image-view.h>
32
33 namespace Dali
34 {
35
36 namespace Toolkit
37 {
38
39 class KeyEvent;
40 class TouchEvent;
41 class WebBackForwardList;
42 class WebContext;
43 class WebCookieManager;
44 class WebSettings;
45 class WebView;
46
47 namespace Internal
48 {
49
50 class WebView : public Control
51 {
52 protected:
53
54   WebView();
55
56   WebView( const std::string& locale, const std::string& timezoneId );
57
58   WebView( int argc, char** argv );
59
60   virtual ~WebView();
61
62 public:
63
64   /**
65    * @copydoc Dali::Toolkit::WebView::New()
66    */
67   static Toolkit::WebView New();
68
69   /**
70    * @copydoc Dali::Toolkit::WebView::New( const std::string&, const std::string& )
71    */
72   static Toolkit::WebView New( const std::string& locale, const std::string& timezoneId );
73
74   /**
75    * @brief Get settings of WebEngine.
76    */
77   Dali::Toolkit::WebSettings* GetSettings() const;
78
79   /**
80    * @brief Get context of WebEngine.
81    */
82   Dali::Toolkit::WebContext* GetContext() const;
83
84   /**
85    * @brief Get cookie manager of WebEngine.
86    */
87   Dali::Toolkit::WebCookieManager* GetCookieManager() const;
88
89   /**
90    * @brief Get WebBackForwardList of WebEngine.
91    */
92   Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
93
94   /**
95    * @copydoc Dali::Toolkit::WebView::New( int, char** )
96    */
97   static Toolkit::WebView New( int argc, char** argv );
98
99   /**
100    * @brief Get favicon of web page.
101    *
102    * @return Handle to a favicon
103    */
104   Dali::Toolkit::ImageView GetFavicon() const;
105
106   /**
107    * @copydoc Dali::Toolkit::WebView::LoadUrl()
108    */
109   void LoadUrl( const std::string& url );
110
111   /**
112    * @copydoc Dali::WebEngine::LoadHTMLString()
113    */
114   void LoadHtmlString( const std::string& htmlString );
115
116   /**
117    * @copydoc Dali::Toolkit::WebView::Reload()
118    */
119   void Reload();
120
121   /**
122    * @copydoc Dali::Toolkit::WebView::StopLoading()
123    */
124   void StopLoading();
125
126   /**
127    * @copydoc Dali::Toolkit::WebView::StopLoading()
128    */
129   void Suspend();
130
131   /**
132    * @copydoc Dali::Toolkit::WebView::Resume()
133    */
134   void Resume();
135
136   /**
137    * @copydoc Dali::Toolkit::WebView::ScrollBy()
138    */
139   void ScrollBy( int deltaX, int deltaY );
140
141   /**
142    * @copydoc Dali::Toolkit::WebView::CanGoForward()
143    */
144   bool CanGoForward();
145
146   /**
147    * @copydoc Dali::Toolkit::WebView::GoForward()
148    */
149   void GoForward();
150
151   /**
152    * @copydoc Dali::Toolkit::WebView::CanGoBack()
153    */
154   bool CanGoBack();
155
156   /**
157    * @copydoc Dali::Toolkit::WebView::GoBack()
158    */
159   void GoBack();
160
161   /**
162    * @copydoc Dali::Toolkit::WebView::EvaluateJavaScript()
163    */
164   void EvaluateJavaScript( const std::string& script, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback resultHandler );
165
166   /**
167    * @copydoc Dali::Toolkit::WebView::AddJavaScriptMessageHandler()
168    */
169   void AddJavaScriptMessageHandler( const std::string& exposedObjectName, Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback handler );
170
171   /**
172    * @brief Clears all tiles resources of Web.
173    */
174   void ClearAllTilesResources();
175
176   /**
177    * @copydoc Dali::Toolkit::WebView::ClearHistory()
178    */
179   void ClearHistory();
180
181   /**
182    * @copydoc Dali::Toolkit::WebView::SetTtsFocus()
183    */
184   void SetTtsFocus(bool focused);
185
186   /**
187    * @copydoc Dali::Toolkit::WebView::RegisterPageLoadStartedCallback()
188    */
189   void RegisterPageLoadStartedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
190
191   /**
192    * @copydoc Dali::Toolkit::WebView::RegisterPageLoadFinishedCallback()
193    */
194   void RegisterPageLoadFinishedCallback(Dali::WebEnginePlugin::WebEnginePageLoadCallback callback);
195
196   /**
197    * @copydoc Dali::Toolkit::WebView::RegisterPageLoadErrorCallback()
198    */
199   void RegisterPageLoadErrorCallback(Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback callback);
200
201   /**
202    * @copydoc Dali::Toolkit::WebView::RegisterScrollEdgeReachedCallback()
203    */
204   void RegisterScrollEdgeReachedCallback(Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback callback);
205
206   /**
207    * @copydoc Dali::Toolkit::WebView::RegisterNavigationPolicyDecidedCallback()
208    */
209   void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
210
211   /**
212    * @copydoc Dali::Toolkit::WebView::GetPlainTextAsynchronously()
213    */
214   void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
215
216 public: // Properties
217
218   /**
219    * @brief Called when a property of an object of this type is set.
220    *
221    * @param[in] object The object whose property is set.
222    * @param[in] index The property index.
223    * @param[in] value The new property value.
224    */
225   static void SetProperty( Dali::BaseObject* object, Dali::Property::Index index, const Dali::Property::Value& value );
226
227   /**
228    * @brief Called to retrieve a property of an object of this type.
229    *
230    * @param[in] object The object whose property is to be retrieved.
231    * @param[in] index The property index.
232    * @return The current value of the property.
233    */
234   static Dali::Property::Value GetProperty( Dali::BaseObject* object, Dali::Property::Index propertyIndex );
235
236 private: // From Control
237
238   /**
239    * @copydoc Toolkit::Control::OnInitialize()
240    */
241   void OnInitialize() override;
242
243   /**
244    * @copydoc Toolkit::Control::GetNaturalSize
245    */
246   Vector3 GetNaturalSize() override;
247
248   /**
249    * Signal occurs when the Web View has been touched.
250    * @param[in] actor The Actor Touched
251    * @param[in] touch The Touch Data.
252    * @return Whether to consume event or not.
253    */
254   bool OnTouchEvent( Actor actor, const Dali::TouchEvent& touch );
255
256   /**
257    * @copydoc Toolkit::Control::OnKeyEvent()
258    */
259   bool OnKeyEvent( const Dali::KeyEvent& event ) override;
260
261   /**
262    * @copydoc Toolkit::Control::OnKeyInputFocusGained()
263    */
264   void OnKeyInputFocusGained() override;
265
266   /**
267    * @copydoc Toolkit::Control::OnKeyInputFocusLost()
268    */
269   void OnKeyInputFocusLost() override;
270
271   /**
272    * @copydoc Toolkit::Control::OnSceneConnection()
273    */
274   void OnSceneConnection( int depth ) override;
275
276 private:
277
278   // Undefined
279   WebView( const WebView& webView );
280
281   WebView& operator=( const WebView& webView );
282
283   /**
284    * @brief Sets an absolute scroll of the given view.
285    * @param[in] x The coordinate x of scroll
286    * @param[in] y The coordinate y of scroll
287    */
288   void SetScrollPosition( int x, int y );
289
290   /**
291    * @brief Gets the current scroll position of the given view.
292    * @param[out] x The coordinate x of scroll
293    * @param[out] y The coordinate y of scroll
294    */
295   void GetScrollPosition( int& x, int& y ) const;
296
297   /**
298    * @brief Gets the possible scroll size of the given view.
299    * @param[out] width The width of scroll size
300    * @param[out] height The height of scroll size
301    */
302   void GetScrollSize( int& width, int& height ) const;
303
304   /**
305    * @brief Gets the last known content's size.
306    * @param[out] width The width of content's size
307    * @param[out] height The height of content's size
308    */
309   void GetContentSize( int& width, int& height ) const;
310
311   /**
312    * @brief Returns the title of the Web.
313    *
314    * @return The title of web page
315    */
316   std::string GetTitle() const;
317
318   /**
319    * @brief Get user agent string.
320    * @return The string value of user agent
321    */
322   const std::string& GetUserAgent() const;
323
324   /**
325    * @brief Set user agent string.
326    * @param[in] userAgent The string value of user agent
327    */
328   void SetUserAgent( const std::string& userAgent );
329
330   /**
331    * @brief Updates display area of web view.
332    * @param[in] source The soource triggers Notification.
333    */
334   void UpdateDisplayArea( Dali::PropertyNotification& source );
335
336   /**
337    * @brief Enable/Disable video hole for video playing.
338    * @param[in] enabled True if video hole is enabled, false otherwise.
339    */
340   void EnableVideoHole( bool enabled );
341
342   /**
343    * @brief Enable blend mode.
344    * @param[in] blendEnabled True if turn on blend mode, false otherwise.
345    */
346   void EnableBlendMode( bool blendEnabled );
347
348 private:
349
350   std::string                                        mUrl;
351   Dali::Toolkit::Visual::Base                        mVisual;
352   Dali::Size                                         mWebViewSize;
353   Dali::WebEngine                                    mWebEngine;
354
355   std::unique_ptr<Dali::Toolkit::WebContext>         mWebContext;
356   std::unique_ptr<Dali::Toolkit::WebCookieManager>   mWebCookieManager;
357   std::unique_ptr<Dali::Toolkit::WebSettings>        mWebSettings;
358   std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
359
360   Dali::PropertyNotification                         mPositionUpdateNotification;
361   Dali::PropertyNotification                         mSizeUpdateNotification;
362   Dali::PropertyNotification                         mScaleUpdateNotification;
363   bool                                               mVideoHoleEnabled;
364   Dali::Rect< int >                                  mWebViewArea;
365 };
366
367 } // namespace Internal
368
369 inline Toolkit::Internal::WebView& GetImpl( Toolkit::WebView& handle )
370 {
371   DALI_ASSERT_ALWAYS( handle );
372   Dali::RefObject& impl = handle.GetImplementation();
373   return static_cast< Toolkit::Internal::WebView& >( impl );
374 }
375
376 inline const Toolkit::Internal::WebView& GetImpl( const Toolkit::WebView& handle )
377 {
378   DALI_ASSERT_ALWAYS( handle );
379   const Dali::RefObject& impl = handle.GetImplementation();
380   return static_cast< const Toolkit::Internal::WebView& >( impl );
381 }
382
383 } // namespace Toolkit
384
385 } // namespace Dali
386
387 #endif // DALI_TOOLKIT_INTERNAL_WEB_VIEW_H