Add APIs for context menu into web view.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / toolkit-web-engine.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include "toolkit-timer.h"
19
20 #include <dali/devel-api/adaptor-framework/web-engine.h>
21 #include <dali/devel-api/adaptor-framework/web-engine-back-forward-list.h>
22 #include <dali/devel-api/adaptor-framework/web-engine-back-forward-list-item.h>
23 #include <dali/devel-api/adaptor-framework/web-engine-certificate.h>
24 #include <dali/devel-api/adaptor-framework/web-engine-console-message.h>
25 #include <dali/devel-api/adaptor-framework/web-engine-context.h>
26 #include <dali/devel-api/adaptor-framework/web-engine-context-menu.h>
27 #include <dali/devel-api/adaptor-framework/web-engine-context-menu-item.h>
28 #include <dali/devel-api/adaptor-framework/web-engine-cookie-manager.h>
29 #include <dali/devel-api/adaptor-framework/web-engine-form-repost-decision.h>
30 #include <dali/devel-api/adaptor-framework/web-engine-frame.h>
31 #include <dali/devel-api/adaptor-framework/web-engine-http-auth-handler.h>
32 #include <dali/devel-api/adaptor-framework/web-engine-load-error.h>
33 #include <dali/devel-api/adaptor-framework/web-engine-policy-decision.h>
34 #include <dali/devel-api/adaptor-framework/web-engine-request-interceptor.h>
35 #include <dali/devel-api/adaptor-framework/web-engine-security-origin.h>
36 #include <dali/devel-api/adaptor-framework/web-engine-settings.h>
37 #include <dali/public-api/adaptor-framework/native-image-source.h>
38 #include <dali/public-api/images/pixel-data.h>
39 #include <dali/public-api/object/any.h>
40 #include <dali/public-api/object/base-object.h>
41 #include <memory>
42 #include <string.h>
43 #include <toolkit-application.h>
44
45 namespace Dali
46 {
47
48 namespace Internal
49 {
50
51 namespace Adaptor
52 {
53
54 class WebEngine;
55 class MockWebEngineContext;
56
57 namespace
58 {
59
60 // Generally only one WebEngine instance exists.
61 // If > 1, a new web engine has been created by CreateWindowSignal.
62 static WebEngine* gInstance = nullptr;
63 static int gInstanceCount = 0;
64 static MockWebEngineContext* gWebEngineContextInstance = nullptr;
65
66 bool OnGoBack();
67 bool OnGoForward();
68 bool OnLoadUrl();
69 bool OnEvaluteJavaScript();
70 bool OnJavaScriptAlert();
71 bool OnJavaScriptConfirm();
72 bool OnJavaScriptPrompt();
73 bool OnScrollEdge();
74 bool OnScreenshotCaptured();
75 bool OnVideoPlaying();
76 bool OnGeolocationPermission();
77 bool OnClearHistory();
78 bool OnSecurityOriginAcquired();
79 bool OnStorageUsageAcquired();
80 bool OnFormPasswordAcquired();
81 bool OnDownloadStarted();
82 bool OnMimeOverridden();
83
84 static void ConnectToGlobalSignal( bool ( *func )() )
85 {
86   Dali::Timer timer = Dali::Timer::New( 0 );
87   timer.TickSignal().Connect( func );
88 }
89
90 static void DisconnectFromGlobalSignal( bool ( *func )() )
91 {
92   Dali::Timer timer = Dali::Timer::New( 0 );
93   timer.TickSignal().Disconnect( func );
94 }
95 } // namespace anonymous
96
97 class MockWebEngineContext : public Dali::WebEngineContext
98 {
99 public:
100   MockWebEngineContext()
101     : mockModel( Dali::WebEngineContext::CacheModel::DOCUMENT_VIEWER )
102   {
103   }
104
105   Dali::WebEngineContext::CacheModel GetCacheModel() const override
106   {
107     return mockModel;
108   }
109
110   void SetCacheModel( Dali::WebEngineContext::CacheModel cacheModel ) override
111   {
112     mockModel = cacheModel;
113   }
114
115   void SetProxyUri( const std::string& uri ) override
116   {
117   }
118
119   void SetDefaultProxyAuth( const std::string& username, const std::string& password ) override
120   {
121   }
122
123   void SetCertificateFilePath( const std::string& certificatePath ) override
124   {
125   }
126
127   void DeleteAllWebDatabase() override
128   {
129   }
130
131   bool GetWebDatabaseOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback)
132   {
133     if (callback)
134     {
135       ConnectToGlobalSignal(&OnSecurityOriginAcquired);
136       mSecurityOriginAcquiredCallback = callback;
137     }
138     return true;
139   }
140
141   bool DeleteWebDatabase(Dali::WebEngineSecurityOrigin& origin)
142   {
143     return true;
144   }
145
146   bool GetWebStorageOrigins(Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback callback)
147   {
148     if (callback)
149     {
150       ConnectToGlobalSignal(&OnSecurityOriginAcquired);
151       mSecurityOriginAcquiredCallback = callback;
152     }
153     return true;
154   }
155
156   bool GetWebStorageUsageForOrigin(Dali::WebEngineSecurityOrigin& origin, Dali::WebEngineContext::WebEngineStorageUsageAcquiredCallback callback) 
157   {
158     if (callback)
159     {
160       ConnectToGlobalSignal(&OnStorageUsageAcquired);
161       mStorageUsageAcquiredCallback = callback;
162     }
163     return true;
164   }
165
166   void DeleteAllWebStorage() override
167   {
168   }
169
170   bool DeleteWebStorageOrigin(Dali::WebEngineSecurityOrigin& origin)
171   {
172     return true;
173   }
174
175   void DeleteLocalFileSystem() override
176   {
177   }
178
179   void DisableCache( bool cacheDisabled ) override
180   {
181   }
182
183   void ClearCache() override
184   {
185   }
186
187   bool DeleteApplicationCache(Dali::WebEngineSecurityOrigin& origin)
188   {
189     return true;
190   }
191
192   void GetFormPasswordList(Dali::WebEngineContext::WebEngineFormPasswordAcquiredCallback callback)
193   {
194     if (callback)
195     {
196       ConnectToGlobalSignal(&OnFormPasswordAcquired);
197       mFormPasswordAcquiredCallback = callback;
198     }
199   }
200
201   void RegisterDownloadStartedCallback(Dali::WebEngineContext::WebEngineDownloadStartedCallback callback)
202   {
203     if (callback)
204     {
205       ConnectToGlobalSignal(&OnDownloadStarted);
206       mDownloadStartedCallback = callback;
207     }
208   }
209
210   void RegisterMimeOverriddenCallback(Dali::WebEngineContext::WebEngineMimeOverriddenCallback callback)
211   {
212     if (callback)
213     {
214       ConnectToGlobalSignal(&OnMimeOverridden);
215       mMimeOverriddenCallback = callback;
216     }
217   }
218
219 public:
220   Dali::WebEngineContext::WebEngineSecurityOriginAcquiredCallback mSecurityOriginAcquiredCallback;
221   Dali::WebEngineContext::WebEngineStorageUsageAcquiredCallback mStorageUsageAcquiredCallback;
222   Dali::WebEngineContext::WebEngineFormPasswordAcquiredCallback mFormPasswordAcquiredCallback;
223   Dali::WebEngineContext::WebEngineDownloadStartedCallback mDownloadStartedCallback;
224   Dali::WebEngineContext::WebEngineMimeOverriddenCallback mMimeOverriddenCallback;
225
226 private:
227   Dali::WebEngineContext::CacheModel mockModel;
228 };
229
230 class MockWebEngineSecurityOrigin : public Dali::WebEngineSecurityOrigin
231 {
232 public:
233   MockWebEngineSecurityOrigin()
234     : mockUrl("https://test.html")
235     , mockPotocol("https")
236   {
237   }
238
239   std::string GetHost() const
240   {
241     return mockUrl;
242   }
243
244   std::string GetProtocol() const
245   {
246     return mockPotocol;
247   }
248
249 private:
250   std::string mockUrl;
251   std::string mockPotocol;
252 };
253
254 class MockWebEngineCookieManager : public Dali::WebEngineCookieManager
255 {
256 public:
257   MockWebEngineCookieManager()
258     : mockCookieAcceptPolicy( Dali::WebEngineCookieManager::CookieAcceptPolicy::NO_THIRD_PARTY )
259   {
260   }
261
262   void SetCookieAcceptPolicy( Dali::WebEngineCookieManager::CookieAcceptPolicy policy ) override
263   {
264     mockCookieAcceptPolicy = policy;
265   }
266
267   Dali::WebEngineCookieManager::CookieAcceptPolicy GetCookieAcceptPolicy() const override
268   {
269     return mockCookieAcceptPolicy;
270   }
271
272   void ClearCookies() override
273   {
274   }
275
276   void SetPersistentStorage( const std::string& path, Dali::WebEngineCookieManager::CookiePersistentStorage storage ) override
277   {
278   }
279
280 private:
281   Dali::WebEngineCookieManager::CookieAcceptPolicy mockCookieAcceptPolicy;
282 };
283
284 class MockWebEngineBackForwardListItem : public Dali::WebEngineBackForwardListItem
285 {
286 public:
287   MockWebEngineBackForwardListItem()
288     : mockUrl( "http://url" ),
289       mockTitle( "title" ),
290       mockOriginalUrl( "http://originalurl" )
291   {
292   }
293
294   std::string GetUrl() const override
295   {
296     return mockUrl;
297   }
298
299   std::string GetTitle() const override
300   {
301     return mockTitle;
302   }
303
304   std::string GetOriginalUrl() const override
305   {
306     return mockOriginalUrl;
307   }
308
309 private:
310   std::string mockUrl;
311   std::string mockTitle;
312   std::string mockOriginalUrl;
313 };
314
315 class MockWebEngineBackForwardList : public Dali::WebEngineBackForwardList
316 {
317 public:
318   MockWebEngineBackForwardList()
319     : mockItem(),
320       pMockItem( &mockItem )
321   {
322   }
323
324   Dali::WebEngineBackForwardListItem& GetCurrentItem() const override
325   {
326     return *pMockItem;
327   }
328
329   Dali::WebEngineBackForwardListItem& GetItemAtIndex( uint32_t index ) const override
330   {
331     return *pMockItem;
332   }
333
334   uint32_t GetItemCount() const override
335   {
336     return 1;
337   }
338
339 private:
340   MockWebEngineBackForwardListItem mockItem;
341   WebEngineBackForwardListItem*    pMockItem;
342 };
343
344 class MockWebEngineCertificate : public Dali::WebEngineCertificate
345 {
346 public:
347   MockWebEngineCertificate()
348   {
349   }
350
351   void Allow(bool allowed) override
352   {
353   }
354
355   bool IsFromMainFrame() const override
356   {
357     return true;
358   }
359
360   std::string GetPem() const override
361   {
362     return "abc";
363   }
364
365   bool IsContextSecure() const override
366   {
367     return true;
368   }
369 };
370
371 class MockWebEngineHttpAuthHandler : public Dali::WebEngineHttpAuthHandler
372 {
373 public:
374   MockWebEngineHttpAuthHandler()
375   {
376   }
377
378   std::string GetRealm() const override
379   {
380     return "test";
381   }
382
383   void Suspend() override
384   {
385   }
386
387   void UseCredential(const std::string& user, const std::string& password) override
388   {
389   }
390
391   void CancelCredential() override
392   {
393   }
394 };
395
396 class MockWebEngineFormRepostDecision : public WebEngineFormRepostDecision
397 {
398 public:
399   MockWebEngineFormRepostDecision()
400   {
401   }
402
403   void Reply(bool allowed) override {}
404 };
405
406 class MockWebEngineFrame : public Dali::WebEngineFrame
407 {
408 public:
409   MockWebEngineFrame()
410   {
411   }
412
413   bool IsMainFrame() const override
414   {
415     return true;
416   }
417 };
418
419 class MockWebEnginePolicyDecision : public Dali::WebEnginePolicyDecision
420 {
421 public:
422   MockWebEnginePolicyDecision()
423   {
424   }
425
426   std::string GetUrl() const override
427   {
428     return "http://test.html";
429   }
430
431   std::string GetCookie() const override
432   {
433     return "test:abc";
434   }
435
436   Dali::WebEnginePolicyDecision::DecisionType GetDecisionType() const
437   {
438     return Dali::WebEnginePolicyDecision::DecisionType::USE;
439   }
440
441   std::string GetResponseMime() const
442   {
443     return "txt/xml";
444   }
445
446   int32_t GetResponseStatusCode() const
447   {
448     return 500;
449   }
450
451   Dali::WebEnginePolicyDecision::NavigationType GetNavigationType() const
452   {
453     return Dali::WebEnginePolicyDecision::NavigationType::LINK_CLICKED;
454   }
455
456   Dali::WebEngineFrame& GetFrame() const
457   {
458     return *(Dali::WebEngineFrame*)(&mockWebFrame);
459   }
460
461   std::string GetScheme() const
462   {
463     return "test";
464   }
465
466   bool Use()
467   {
468     return true;
469   }
470
471   bool Ignore()
472   {
473     return true;
474   }
475
476   bool Suspend()
477   {
478     return true;
479   }
480
481 private:
482   MockWebEngineFrame mockWebFrame;
483 };
484
485 class MockWebEngineRequestInterceptor : public WebEngineRequestInterceptor
486 {
487 public:
488   MockWebEngineRequestInterceptor()
489   {
490   }
491
492   std::string GetUrl() const override
493   {
494     return "http://test.html";
495   }
496
497   bool Ignore() override
498   {
499     return true;
500   }
501
502   bool SetResponseStatus(int statusCode, const std::string &customedStatusText) override
503   {
504     return true;
505   }
506
507   bool AddResponseHeader(const std::string &fieldName, const std::string &fieldValue) override
508   {
509     return true;
510   }
511
512   bool AddResponseBody(const std::string &body, uint32_t length) override
513   {
514     return true;
515   }
516 };
517
518 class MockWebEngineConsoleMessage : public Dali::WebEngineConsoleMessage
519 {
520 public:
521   MockWebEngineConsoleMessage()
522   {
523   }
524
525   std::string GetSource() const override
526   {
527     return "source";
528   }
529
530   uint32_t GetLine() const override
531   {
532     return 10;
533   }
534
535   SeverityLevel GetSeverityLevel() const override
536   {
537     return SeverityLevel::EMPTY;
538   }
539
540   std::string GetText() const override
541   {
542     return "This is a text.";
543   }
544 };
545
546 class MockWebEngineLoadError : public Dali::WebEngineLoadError
547 {
548 public:
549   MockWebEngineLoadError(const std::string& url)
550     : mockUrl(url)
551   {
552   }
553
554   std::string GetUrl() const override
555   {
556     return mockUrl;
557   }
558
559   ErrorCode GetCode() const override
560   {
561     return ErrorCode::UNKNOWN;
562   }
563
564   std::string GetDescription() const override
565   {
566     return "This is an error.";
567   }
568
569   ErrorType GetType() const override
570   {
571     return ErrorType::NONE;
572   }
573
574 private:
575   std::string mockUrl;
576 };
577
578 class MockWebEngineContextMenuItem : public Dali::WebEngineContextMenuItem
579 {
580 public:
581   MockWebEngineContextMenuItem()
582   {
583   }
584
585   ItemTag GetTag() const override
586   {
587     return ItemTag::NO_ACTION;
588   }
589
590   ItemType GetType() const override
591   {
592     return ItemType::ACTION;
593   }
594
595   bool IsEnabled() const override
596   {
597     return true;
598   }
599
600   std::string GetLinkUrl() const override
601   {
602     return "http://test.html";
603   }
604
605   std::string GetImageUrl() const override
606   {
607     return "http://test.jpg";
608   }
609
610   std::string GetTitle() const override
611   {
612     return "title";
613   }
614
615   std::unique_ptr<Dali::WebEngineContextMenu> GetParentMenu() const override
616   {
617     std::unique_ptr<Dali::WebEngineContextMenu> result;
618     return result;
619   }
620 };
621
622 class MockWebEngineContextMenu : public Dali::WebEngineContextMenu
623 {
624 public:
625   MockWebEngineContextMenu()
626   {
627   }
628
629   uint32_t GetItemCount() const override
630   {
631     return 1;
632   }
633
634   std::unique_ptr<Dali::WebEngineContextMenuItem> GetItemAt(uint32_t index) const override
635   {
636     std::unique_ptr<Dali::WebEngineContextMenuItem> webitem(new MockWebEngineContextMenuItem());
637     return webitem;
638   }
639
640   std::vector<std::unique_ptr<WebEngineContextMenuItem>> GetItemList() const override
641   {
642     std::vector<std::unique_ptr<WebEngineContextMenuItem>> result;
643     std::unique_ptr<Dali::WebEngineContextMenuItem> webitem(new MockWebEngineContextMenuItem());
644     result.push_back(std::move(webitem));
645     return result;
646   }
647
648   Dali::Vector2 GetPosition() const override
649   {
650     return Dali::Vector2(100, 100);
651   }
652
653   bool RemoveItem(WebEngineContextMenuItem& item) override
654   {
655     return true;
656   }
657
658   bool AppendItemAsAction(WebEngineContextMenuItem::ItemTag tag, const std::string& title, bool enabled) override
659   {
660     return true;
661   }
662
663   bool AppendItem(WebEngineContextMenuItem::ItemTag tag, const std::string& title, const std::string& iconFile, bool enabled) override
664   {
665     return true;
666   }
667
668   bool SelectItem(WebEngineContextMenuItem& item) override
669   {
670     return true;
671   }
672
673   bool Hide() override
674   {
675     return true;
676   }
677 };
678
679 class MockWebEngineSettings : public WebEngineSettings
680 {
681 public:
682   MockWebEngineSettings()
683     : mockDefaultFontSize( 16 ),
684       mockJavaScriptEnabled( true ),
685       mockAutoFittingEnabled ( true ),
686       mockPluginsEnabled ( true ),
687       mockPrivateBrowsingEnabled( true ),
688       mockLinkMagnifierEnabled( true ),
689       mockKeypadWithoutUserActionUsed( true ),
690       mockAutofillPasswordFormEnabled( true ),
691       mockFormCandidateDataEnabled( true ),
692       mockTextSelectionEnabled( true ),
693       mockTextAutosizingEnable( true ),
694       mockArrowScrollEnable( true ),
695       mockClipboardEnabled( true ),
696       mockImePanelEnabled( true ),
697       mockImageLoadedAutomatically( true ),
698       mockDefaultTextEncodingName()
699   {
700   }
701
702   uint32_t GetDefaultFontSize() const override
703   {
704     return mockDefaultFontSize;
705   }
706
707   void SetDefaultFontSize( uint32_t size ) override
708   {
709     mockDefaultFontSize = size;
710   }
711
712   bool IsJavaScriptEnabled() const override
713   {
714     return mockJavaScriptEnabled;
715   }
716
717   void EnableJavaScript( bool enabled ) override
718   {
719     mockJavaScriptEnabled = enabled;
720   }
721
722   bool IsAutoFittingEnabled() const override
723   {
724     return mockAutoFittingEnabled;
725   }
726
727   void EnableAutoFitting( bool enabled ) override
728   {
729     mockAutoFittingEnabled = enabled;
730   }
731
732   bool ArePluginsEnabled() const override
733   {
734     return mockPluginsEnabled;
735   }
736
737   void EnablePlugins( bool enabled ) override
738   {
739     mockPluginsEnabled = enabled;
740   }
741
742   bool IsPrivateBrowsingEnabled() const override
743   {
744     return mockPrivateBrowsingEnabled;
745   }
746
747   void EnablePrivateBrowsing( bool enabled ) override
748   {
749     mockPrivateBrowsingEnabled = enabled;
750   }
751
752   bool IsLinkMagnifierEnabled() const override
753   {
754     return mockLinkMagnifierEnabled;
755   }
756
757   void EnableLinkMagnifier( bool enabled ) override
758   {
759     mockLinkMagnifierEnabled = enabled;
760   }
761
762   bool IsKeypadWithoutUserActionUsed() const override
763   {
764     return mockKeypadWithoutUserActionUsed;
765   }
766
767   void UseKeypadWithoutUserAction( bool used ) override
768   {
769     mockKeypadWithoutUserActionUsed = used;
770   }
771
772   bool IsAutofillPasswordFormEnabled() const override
773   {
774     return mockAutofillPasswordFormEnabled;
775   }
776
777   void EnableAutofillPasswordForm( bool enabled ) override
778   {
779     mockAutofillPasswordFormEnabled = enabled;
780   }
781
782   bool IsFormCandidateDataEnabled() const override
783   {
784     return mockFormCandidateDataEnabled;
785   }
786
787   void EnableFormCandidateData( bool enabled ) override
788   {
789     mockFormCandidateDataEnabled = enabled;
790   }
791
792   bool IsTextSelectionEnabled() const override
793   {
794     return mockTextSelectionEnabled;
795   }
796
797   void EnableTextSelection( bool enabled ) override
798   {
799     mockTextSelectionEnabled = enabled;
800   }
801
802   bool IsTextAutosizingEnabled() const override
803   {
804     return mockTextAutosizingEnable;
805   }
806
807   void EnableTextAutosizing( bool enabled ) override
808   {
809     mockTextAutosizingEnable = enabled;
810   }
811
812   bool IsArrowScrollEnabled() const override
813   {
814     return mockArrowScrollEnable;
815   }
816
817   void EnableArrowScroll( bool enabled ) override
818   {
819     mockArrowScrollEnable = enabled;
820   }
821
822   bool IsClipboardEnabled() const override
823   {
824     return mockClipboardEnabled;
825   }
826
827   void EnableClipboard( bool enabled ) override
828   {
829     mockClipboardEnabled = enabled;
830   }
831
832   bool IsImePanelEnabled() const override
833   {
834     return mockImePanelEnabled;
835   }
836
837   void EnableImePanel( bool enabled ) override
838   {
839     mockImePanelEnabled = enabled;
840   }
841
842   bool AreImagesLoadedAutomatically() const override
843   {
844     return mockImageLoadedAutomatically;
845   }
846
847   void AllowImagesLoadAutomatically( bool automatic ) override
848   {
849     mockImageLoadedAutomatically = automatic;
850   }
851
852   std::string GetDefaultTextEncodingName() const override
853   {
854     return mockDefaultTextEncodingName;
855   }
856
857   void SetDefaultTextEncodingName( const std::string& defaultTextEncodingName ) override
858   {
859     mockDefaultTextEncodingName = defaultTextEncodingName;
860   }
861
862   void AllowMixedContents( bool allowed ) override
863   {
864   }
865
866   void EnableSpatialNavigation( bool enabled ) override
867   {
868   }
869
870   void EnableWebSecurity( bool enabled ) override
871   {
872   }
873
874   void EnableCacheBuilder( bool enabled ) override
875   {
876   }
877
878   void UseScrollbarThumbFocusNotifications( bool used ) override
879   {
880   }
881
882   void EnableDoNotTrack( bool enabled ) override
883   {
884   }
885
886   void AllowFileAccessFromExternalUrl( bool allowed ) override
887   {
888   }
889
890   void AllowScriptsOpenWindows( bool allowed ) override
891   {
892   }
893
894 private:
895   int mockDefaultFontSize;
896   bool mockJavaScriptEnabled;
897   bool mockAutoFittingEnabled;
898   bool mockPluginsEnabled;
899   bool mockPrivateBrowsingEnabled;
900   bool mockLinkMagnifierEnabled;
901   bool mockKeypadWithoutUserActionUsed;
902   bool mockAutofillPasswordFormEnabled;
903   bool mockFormCandidateDataEnabled;
904   bool mockTextSelectionEnabled;
905   bool mockTextAutosizingEnable;
906   bool mockArrowScrollEnable;
907   bool mockClipboardEnabled;
908   bool mockImePanelEnabled;
909   bool mockImageLoadedAutomatically;
910   std::string mockDefaultTextEncodingName;
911 };
912
913 class WebEngine: public Dali::BaseObject
914 {
915 public:
916
917   using JavaScriptEvaluatedResultCallback = std::function<void(const std::string&)>;
918
919   WebEngine()
920     : mUrl()
921     , mCurrentPlusOnePos( 0 )
922     , mUserAgent()
923     , mEvaluating( false )
924     , mScrollPosition( 0, 0 )
925     , mScrollSize( 500, 500 )
926     , mContentSize( 500, 500 )
927   {
928     gInstanceCount++;
929     if ( gInstanceCount == 1 ) // only first web engine need be saved.
930     {
931       gInstance = this;
932     }
933
934     mockWebEngineSettings = new MockWebEngineSettings();
935     MockWebEngineContext* engineContext = new MockWebEngineContext();
936     mockWebEngineContext = engineContext;
937     if ( gInstanceCount == 1 )
938     {
939       gWebEngineContextInstance = engineContext;
940     }
941     mockWebEngineCookieManager = new MockWebEngineCookieManager();
942     mockWebEngineBackForwardList = new MockWebEngineBackForwardList();
943   }
944
945   virtual ~WebEngine()
946   {
947     gInstanceCount--;
948     if( !gInstanceCount )
949     {
950       gInstance = 0;
951       gWebEngineContextInstance = 0;
952     }
953
954     delete mockWebEngineSettings;
955     delete mockWebEngineContext;
956     delete mockWebEngineCookieManager;
957     delete mockWebEngineBackForwardList;
958   }
959
960   Dali::WebEngineSettings& GetSettings() const
961   {
962     return *mockWebEngineSettings;
963   }
964
965   Dali::WebEngineContext& GetContext() const
966   {
967     return *mockWebEngineContext;
968   }
969
970   Dali::WebEngineCookieManager& GetCookieManager() const
971   {
972     return *mockWebEngineCookieManager;
973   }
974
975   Dali::WebEngineBackForwardList& GetBackForwardList() const
976   {
977     return *mockWebEngineBackForwardList;
978   }
979
980   void LoadUrl( const std::string& url )
981   {
982     mUrl = url;
983     ConnectToGlobalSignal( &OnLoadUrl );
984   }
985
986   const std::string& GetUrl() const
987   {
988     return mUrl;
989   }
990
991   std::string GetTitle() const
992   {
993     return std::string("title");
994   }
995
996   Dali::PixelData GetFavicon() const
997   {
998     uint8_t* faviconData = new uint8_t[ 16 ];
999
1000     faviconData[ 0 ] = 0xff;
1001     faviconData[ 1 ] = 0x00;
1002     faviconData[ 2 ] = 0x00;
1003     faviconData[ 3 ] = 0xff;
1004     faviconData[ 4 ] = 0xff;
1005     faviconData[ 5 ] = 0x00;
1006     faviconData[ 6 ] = 0x00;
1007     faviconData[ 7 ] = 0xff;
1008     faviconData[ 8 ] = 0xff;
1009     faviconData[ 9 ] = 0x00;
1010     faviconData[ 10 ] = 0x00;
1011     faviconData[ 11 ] = 0xff;
1012     faviconData[ 12 ] = 0xff;
1013     faviconData[ 13 ] = 0x00;
1014     faviconData[ 14 ] = 0x00;
1015     faviconData[ 15 ] = 0xff;
1016
1017     return Dali::PixelData::New( faviconData, 16, 2, 2,
1018                                  Dali::Pixel::Format::RGBA8888,
1019                                  Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
1020   }
1021
1022   bool CanGoForward() const
1023   {
1024     return mHistory.size() > mCurrentPlusOnePos;
1025   }
1026
1027   void GoForward()
1028   {
1029     ConnectToGlobalSignal( &OnGoForward );
1030   }
1031
1032   bool CanGoBack() const
1033   {
1034     return mCurrentPlusOnePos > 1;
1035   }
1036
1037   void GoBack()
1038   {
1039     ConnectToGlobalSignal( &OnGoBack );
1040   }
1041
1042   void EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
1043   {
1044     if( resultHandler )
1045     {
1046       if( !mEvaluating )
1047       {
1048         ConnectToGlobalSignal( &OnEvaluteJavaScript );
1049       }
1050       mResultCallbacks.push_back( resultHandler );
1051     }
1052   }
1053
1054   void RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
1055   {
1056     if ( callback )
1057     {
1058       ConnectToGlobalSignal( &OnJavaScriptAlert );
1059       mJavaScriptAlertCallback = callback;
1060     }
1061   }
1062
1063   void RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
1064   {
1065     if ( callback )
1066     {
1067       ConnectToGlobalSignal( &OnJavaScriptConfirm );
1068       mJavaScriptConfirmCallback = callback;
1069     }
1070   }
1071
1072   void RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
1073   {
1074     if ( callback )
1075     {
1076       ConnectToGlobalSignal( &OnJavaScriptPrompt );
1077       mJavaScriptPromptCallback = callback;
1078     }
1079   }
1080
1081   void ClearHistory()
1082   {
1083     ConnectToGlobalSignal( &OnClearHistory );
1084   }
1085
1086   const std::string& GetUserAgent() const
1087   {
1088     return mUserAgent;
1089   }
1090
1091   void SetUserAgent( const std::string& userAgent )
1092   {
1093     mUserAgent = userAgent;
1094   }
1095
1096   void ScrollBy( int dx, int dy )
1097   {
1098     mScrollPosition += Dali::Vector2( dx, dy );
1099     if ( mScrollPosition.y + mScrollSize.height > mContentSize.height )
1100     {
1101       ConnectToGlobalSignal( &OnScrollEdge );
1102     }
1103   }
1104
1105   bool ScrollEdgeBy( int dx, int dy )
1106   {
1107     mScrollPosition += Dali::Vector2( dx, dy );
1108     if ( mScrollPosition.y + mScrollSize.height > mContentSize.height )
1109     {
1110       ConnectToGlobalSignal( &OnScrollEdge );
1111     }
1112     return true;
1113   }
1114
1115   void SetScrollPosition( int x, int y )
1116   {
1117     mScrollPosition.x = x;
1118     mScrollPosition.y = y;
1119   }
1120
1121   Dali::Vector2 GetScrollPosition() const
1122   {
1123     return mScrollPosition;
1124   }
1125
1126   Dali::Vector2 GetScrollSize() const
1127   {
1128     return mScrollSize;
1129   }
1130
1131   Dali::Vector2 GetContentSize() const
1132   {
1133     return mContentSize;
1134   }
1135
1136   void SetPageZoomFactor(float zoomFactor)
1137   {
1138     mPageZoomFactor = zoomFactor;
1139   }
1140
1141   float GetPageZoomFactor() const
1142   {
1143     return mPageZoomFactor;
1144   }
1145
1146   void SetTextZoomFactor(float zoomFactor)
1147   {
1148     mTextZoomFactor = zoomFactor;
1149   }
1150
1151   float GetTextZoomFactor() const
1152   {
1153     return mTextZoomFactor;
1154   }
1155
1156   float GetLoadProgressPercentage() const
1157   {
1158     return 0.5f;
1159   }
1160
1161   void SetScaleFactor(float scaleFactor, Dali::Vector2 point)
1162   {
1163     mScaleFactor = scaleFactor;
1164   }
1165
1166   float GetScaleFactor() const
1167   {
1168     return mScaleFactor;
1169   }
1170
1171   Dali::PixelData GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor)
1172   {
1173     uint32_t bufferSize = viewArea.width * viewArea.height * 4 ;
1174     uint8_t* pixel = new uint8_t[ bufferSize ];
1175     memset(pixel, 0xff, bufferSize);
1176     return Dali::PixelData::New( pixel, bufferSize, viewArea.width, viewArea.height,
1177                                  Dali::Pixel::Format::RGBA8888,
1178                                  Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
1179   }
1180
1181   bool GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback)
1182   {
1183     if ( callback )
1184     {
1185       ConnectToGlobalSignal( &OnScreenshotCaptured );
1186       mScreenshotCapturedCallback = callback;
1187     }
1188     return true;
1189   }
1190
1191   bool CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
1192   {
1193     if ( callback )
1194     {
1195       ConnectToGlobalSignal( &OnVideoPlaying );
1196       mVideoPlayingCallback = callback;
1197     }
1198     return true;
1199   }
1200
1201   void RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
1202   {
1203     if ( callback )
1204     {
1205       ConnectToGlobalSignal( &OnGeolocationPermission );
1206       mGeolocationPermissionCallback = callback;
1207     }
1208   }
1209
1210   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadStartedSignal()
1211   {
1212     return mPageLoadStartedSignal;
1213   }
1214
1215   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadInProgressSignal()
1216   {
1217     return mPageLoadInProgressSignal;
1218   }
1219
1220   Dali::WebEnginePlugin::WebEnginePageLoadSignalType& PageLoadFinishedSignal()
1221   {
1222     return mPageLoadFinishedSignal;
1223   }
1224
1225   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& PageLoadErrorSignal()
1226   {
1227     return mPageLoadErrorSignal;
1228   }
1229
1230   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& ScrollEdgeReachedSignal()
1231   {
1232     return mScrollEdgeReachedSignal;
1233   }
1234
1235   Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& UrlChangedSignal()
1236   {
1237     return mUrlChangedSignal;
1238   }
1239
1240   Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& FormRepostDecisionSignal()
1241   {
1242     return mFormRepostDecisionSignal;
1243   }
1244
1245   Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& FrameRenderedSignal()
1246   {
1247     return mFrameRenderedSignal;
1248   }
1249
1250   Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& RequestInterceptorSignal()
1251   {
1252     return mRequestInterceptorSignal;
1253   }
1254
1255   Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& ConsoleMessageSignal()
1256   {
1257     return mConsoleMessageSignal;
1258   }
1259
1260   Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& PolicyDecisionSignal()
1261   {
1262     return mPolicyDecisionSignal;
1263   }
1264
1265   Dali::WebEnginePlugin::WebEngineCertificateSignalType& CertificateConfirmSignal()
1266   {
1267     return mCertificateConfirmSignal;
1268   }
1269
1270   Dali::WebEnginePlugin::WebEngineCertificateSignalType& SslCertificateChangedSignal()
1271   {
1272     return mSslCertificateChangedSignal;
1273   }
1274
1275   Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& HttpAuthHandlerSignal()
1276   {
1277     return mHttpAuthHandlerSignal;
1278   }
1279
1280   Dali::WebEnginePlugin::WebEngineContextMenuCustomizedSignalType& ContextMenuCustomizedSignal()
1281   {
1282     return mContextMenuCustomizedSignal;
1283   }
1284
1285   Dali::WebEnginePlugin::WebEngineContextMenuItemSelectedSignalType& ContextMenuItemSelectedSignal()
1286   {
1287     return mContextMenuItemSelectedSignal;
1288   }
1289
1290   std::string              mUrl;
1291   std::vector<std::string> mHistory;
1292   size_t                   mCurrentPlusOnePos;
1293   std::string              mUserAgent;
1294
1295   Dali::WebEnginePlugin::WebEnginePageLoadSignalType                mPageLoadStartedSignal;
1296   Dali::WebEnginePlugin::WebEnginePageLoadSignalType                mPageLoadInProgressSignal;
1297   Dali::WebEnginePlugin::WebEnginePageLoadSignalType                mPageLoadFinishedSignal;
1298   Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType           mPageLoadErrorSignal;
1299   Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType       mScrollEdgeReachedSignal;
1300   Dali::WebEnginePlugin::WebEngineUrlChangedSignalType              mUrlChangedSignal;
1301   Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType      mFormRepostDecisionSignal;
1302   Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType           mFrameRenderedSignal;
1303   Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType      mRequestInterceptorSignal;
1304   Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType          mConsoleMessageSignal;
1305   Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType          mPolicyDecisionSignal;
1306   Dali::WebEnginePlugin::WebEngineCertificateSignalType             mCertificateConfirmSignal;
1307   Dali::WebEnginePlugin::WebEngineCertificateSignalType             mSslCertificateChangedSignal;
1308   Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType         mHttpAuthHandlerSignal;
1309   Dali::WebEnginePlugin::WebEngineContextMenuCustomizedSignalType   mContextMenuCustomizedSignal;
1310   Dali::WebEnginePlugin::WebEngineContextMenuItemSelectedSignalType mContextMenuItemSelectedSignal;
1311
1312   bool  mEvaluating;
1313   float mPageZoomFactor;
1314   float mTextZoomFactor;
1315   float mScaleFactor;
1316
1317   Dali::Vector2             mScrollPosition;
1318   Dali::Vector2             mScrollSize;
1319   Dali::Vector2             mContentSize;
1320   WebEngineBackForwardList* mockWebEngineBackForwardList;
1321   WebEngineContext*         mockWebEngineContext;
1322   WebEngineCookieManager*   mockWebEngineCookieManager;
1323   WebEngineSettings*        mockWebEngineSettings;
1324
1325   std::vector<JavaScriptEvaluatedResultCallback>       mResultCallbacks;
1326   Dali::WebEnginePlugin::JavaScriptAlertCallback       mJavaScriptAlertCallback;
1327   Dali::WebEnginePlugin::JavaScriptConfirmCallback     mJavaScriptConfirmCallback;
1328   Dali::WebEnginePlugin::JavaScriptPromptCallback      mJavaScriptPromptCallback;
1329   Dali::WebEnginePlugin::ScreenshotCapturedCallback    mScreenshotCapturedCallback;
1330   Dali::WebEnginePlugin::VideoPlayingCallback          mVideoPlayingCallback;
1331   Dali::WebEnginePlugin::GeolocationPermissionCallback mGeolocationPermissionCallback;
1332 };
1333
1334
1335 namespace
1336 {
1337
1338 bool OnGoBack()
1339 {
1340   DisconnectFromGlobalSignal( &OnGoBack );
1341
1342   if( gInstance && gInstance->CanGoBack() )
1343   {
1344     gInstance->mCurrentPlusOnePos--;
1345   }
1346   return false;
1347 }
1348
1349 bool OnGoForward()
1350 {
1351   DisconnectFromGlobalSignal( &OnGoForward );
1352
1353   if( gInstance && gInstance->CanGoForward() )
1354   {
1355     gInstance->mCurrentPlusOnePos++;
1356   }
1357   return false;
1358 }
1359
1360 bool OnLoadUrl()
1361 {
1362   DisconnectFromGlobalSignal( &OnLoadUrl );
1363
1364   if( gInstance )
1365   {
1366     if( gInstance->mHistory.size() > gInstance->mCurrentPlusOnePos )
1367     {
1368       gInstance->mHistory.erase( gInstance->mHistory.begin() + gInstance->mCurrentPlusOnePos, gInstance->mHistory.end() );
1369     }
1370     gInstance->mHistory.push_back( gInstance->mUrl );
1371     gInstance->mCurrentPlusOnePos++;
1372     gInstance->mPageLoadStartedSignal.Emit( gInstance->mUrl );
1373     gInstance->mPageLoadInProgressSignal.Emit( gInstance->mUrl );
1374     gInstance->mPageLoadFinishedSignal.Emit( gInstance->mUrl );
1375     gInstance->mUrlChangedSignal.Emit( "http://new-test" );
1376
1377     std::shared_ptr<Dali::WebEngineFormRepostDecision> repostDecision(new MockWebEngineFormRepostDecision());
1378     gInstance->mFormRepostDecisionSignal.Emit(std::move(repostDecision));
1379     gInstance->mFrameRenderedSignal.Emit();
1380     std::shared_ptr<Dali::WebEngineRequestInterceptor> interceptor(new MockWebEngineRequestInterceptor());
1381     gInstance->mRequestInterceptorSignal.Emit(std::move(interceptor));
1382
1383     std::shared_ptr<Dali::WebEngineLoadError> error(new MockWebEngineLoadError(gInstance->mUrl));
1384     gInstance->mPageLoadErrorSignal.Emit(std::move(error));
1385     std::shared_ptr<Dali::WebEngineConsoleMessage> message(new MockWebEngineConsoleMessage());
1386     gInstance->mConsoleMessageSignal.Emit(std::move(message));
1387     std::shared_ptr<Dali::WebEnginePolicyDecision> policyDecision(new MockWebEnginePolicyDecision());
1388     gInstance->mPolicyDecisionSignal.Emit(std::move(policyDecision));
1389
1390     std::shared_ptr<Dali::WebEngineCertificate> certificate(new MockWebEngineCertificate());
1391     gInstance->mCertificateConfirmSignal.Emit(std::move(certificate));
1392     std::shared_ptr<Dali::WebEngineCertificate> sslCertificate(new MockWebEngineCertificate());
1393     gInstance->mSslCertificateChangedSignal.Emit(std::move(sslCertificate));
1394     std::shared_ptr<Dali::WebEngineHttpAuthHandler> handler(new MockWebEngineHttpAuthHandler());
1395     gInstance->mHttpAuthHandlerSignal.Emit(std::move(handler));
1396
1397     std::shared_ptr<Dali::WebEngineContextMenu> menu(new MockWebEngineContextMenu());
1398     gInstance->mContextMenuCustomizedSignal.Emit(std::move(menu));
1399     std::shared_ptr<Dali::WebEngineContextMenuItem> item(new MockWebEngineContextMenuItem());
1400     gInstance->mContextMenuItemSelectedSignal.Emit(std::move(item));
1401   }
1402   return false;
1403 }
1404
1405 bool OnScrollEdge()
1406 {
1407   DisconnectFromGlobalSignal( &OnScrollEdge );
1408
1409   if( gInstance )
1410   {
1411     gInstance->mScrollEdgeReachedSignal.Emit( Dali::WebEnginePlugin::ScrollEdge::BOTTOM );
1412   }
1413
1414   return false;
1415 }
1416
1417 bool OnEvaluteJavaScript()
1418 {
1419   DisconnectFromGlobalSignal( &OnEvaluteJavaScript );
1420
1421   if( gInstance )
1422   {
1423     for( auto& func : gInstance->mResultCallbacks )
1424     {
1425       func("undefined");
1426     }
1427     gInstance->mResultCallbacks.clear();
1428   }
1429   return false;
1430 }
1431
1432 bool OnJavaScriptAlert()
1433 {
1434   DisconnectFromGlobalSignal( &OnJavaScriptAlert );
1435   if ( gInstance )
1436   {
1437     gInstance->mJavaScriptAlertCallback( "this is an alert popup." );
1438   }
1439   return false;
1440 }
1441
1442 bool OnJavaScriptConfirm()
1443 {
1444   DisconnectFromGlobalSignal( &OnJavaScriptConfirm );
1445   if ( gInstance )
1446   {
1447     gInstance->mJavaScriptConfirmCallback( "this is a confirm popup." );
1448   }
1449   return false;
1450 }
1451
1452 bool OnJavaScriptPrompt()
1453 {
1454   DisconnectFromGlobalSignal( &OnJavaScriptPrompt );
1455   if ( gInstance )
1456   {
1457     gInstance->mJavaScriptPromptCallback( "this is a prompt pompt.", "" );
1458   }
1459   return false;
1460 }
1461
1462 bool OnScreenshotCaptured()
1463 {
1464   DisconnectFromGlobalSignal( &OnScreenshotCaptured );
1465   if ( gInstance )
1466   {
1467     uint8_t* pixel = new uint8_t[ 2 * 2 * 4 ];
1468     memset(pixel, 0xff, 2 * 2 * 4);
1469     Dali::PixelData data = Dali::PixelData::New( pixel, 2 * 2 * 4, 2, 2,
1470                                  Dali::Pixel::Format::RGBA8888,
1471                                  Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
1472     gInstance->mScreenshotCapturedCallback( data );
1473   }
1474   return false;
1475 }
1476
1477 bool OnVideoPlaying()
1478 {
1479   DisconnectFromGlobalSignal( &OnVideoPlaying );
1480   if ( gInstance )
1481   {
1482     gInstance->mVideoPlayingCallback( true );
1483   }
1484   return false;
1485 }
1486
1487 bool OnGeolocationPermission()
1488 {
1489   DisconnectFromGlobalSignal( &OnGeolocationPermission );
1490   if ( gInstance )
1491   {
1492     gInstance->mGeolocationPermissionCallback( "", "" );
1493   }
1494   return false;
1495 }
1496
1497 bool OnClearHistory()
1498 {
1499   DisconnectFromGlobalSignal( &OnClearHistory );
1500
1501   if( gInstance && gInstance->mCurrentPlusOnePos )
1502   {
1503     std::string url = gInstance->mHistory[ gInstance->mCurrentPlusOnePos - 1 ];
1504     std::vector< std::string >().swap( gInstance->mHistory );
1505     gInstance->mHistory.push_back( url );
1506     gInstance->mCurrentPlusOnePos = 1;
1507   }
1508   return false;
1509 }
1510
1511 bool OnSecurityOriginAcquired()
1512 {
1513   DisconnectFromGlobalSignal(&OnSecurityOriginAcquired);
1514   if (gWebEngineContextInstance)
1515   {
1516     std::vector<std::unique_ptr<Dali::WebEngineSecurityOrigin>> securityOriginList;
1517     std::unique_ptr<Dali::WebEngineSecurityOrigin> origin(new MockWebEngineSecurityOrigin());
1518     securityOriginList.push_back(std::move(origin));
1519     gWebEngineContextInstance->mSecurityOriginAcquiredCallback(securityOriginList);
1520   }
1521   return false;
1522 }
1523
1524 bool OnStorageUsageAcquired()
1525 {
1526   DisconnectFromGlobalSignal(&OnStorageUsageAcquired);
1527   if (gWebEngineContextInstance)
1528   {
1529     gWebEngineContextInstance->mStorageUsageAcquiredCallback(0);
1530   }
1531   return false;
1532 }
1533
1534 bool OnFormPasswordAcquired()
1535 {
1536   DisconnectFromGlobalSignal(&OnFormPasswordAcquired);
1537   if (gWebEngineContextInstance)
1538   {
1539     std::vector<std::unique_ptr<Dali::WebEngineContext::PasswordData>> formPasswordList;
1540     std::unique_ptr<Dali::WebEngineContext::PasswordData> data(new Dali::WebEngineContext::PasswordData());
1541     data->url = "http://test.html";
1542     data->useFingerprint = false;
1543     formPasswordList.push_back(std::move(data));
1544     gWebEngineContextInstance->mFormPasswordAcquiredCallback(formPasswordList);
1545   }
1546   return false;
1547 }
1548
1549 bool OnDownloadStarted()
1550 {
1551   DisconnectFromGlobalSignal(&OnDownloadStarted);
1552   if (gWebEngineContextInstance)
1553   {
1554     gWebEngineContextInstance->mDownloadStartedCallback("http://test.html");
1555   }
1556   return false;
1557 }
1558
1559 bool OnMimeOverridden()
1560 {
1561   DisconnectFromGlobalSignal(&OnMimeOverridden);
1562   if (gWebEngineContextInstance)
1563   {
1564     std::string newMime;
1565     gWebEngineContextInstance->mMimeOverriddenCallback("http://test.html", "txt/xml", newMime);
1566   }
1567   return false;
1568 }
1569
1570 } // namespace
1571
1572 inline WebEngine& GetImplementation( Dali::WebEngine& webEngine )
1573 {
1574   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
1575   BaseObject& handle = webEngine.GetBaseObject();
1576   return static_cast< Internal::Adaptor::WebEngine& >( handle );
1577 }
1578
1579 inline const WebEngine& GetImplementation( const Dali::WebEngine& webEngine )
1580 {
1581   DALI_ASSERT_ALWAYS( webEngine && "WebEngine handle is empty." );
1582   const BaseObject& handle = webEngine.GetBaseObject();
1583   return static_cast< const Internal::Adaptor::WebEngine& >( handle );
1584 }
1585
1586 } // namespace Adaptor
1587
1588 } // namespace Internal
1589
1590 // Dali::WebEngine Implementation
1591 WebEngine::WebEngine()
1592 {
1593 }
1594
1595 WebEngine::WebEngine( Internal::Adaptor::WebEngine* internal )
1596 : BaseHandle( internal )
1597 {
1598 }
1599
1600 WebEngine::~WebEngine()
1601 {
1602 }
1603
1604 WebEngine WebEngine::New()
1605 {
1606   Internal::Adaptor::WebEngine* baseObject = new Internal::Adaptor::WebEngine();
1607
1608   return WebEngine( baseObject );
1609 }
1610
1611 WebEngine::WebEngine( const WebEngine& WebEngine )
1612 : BaseHandle( WebEngine )
1613 {
1614 }
1615
1616 WebEngine& WebEngine::operator=( const WebEngine& webEngine )
1617 {
1618   BaseHandle::operator=( webEngine );
1619   return *this;
1620 }
1621
1622 WebEngine WebEngine::DownCast( BaseHandle handle )
1623 {
1624   return WebEngine( dynamic_cast< Internal::Adaptor::WebEngine* >( handle.GetObjectPtr() ) );
1625 }
1626
1627 void WebEngine::Create( int width, int height, const std::string& locale, const std::string& timezoneId )
1628 {
1629 }
1630
1631 void WebEngine::Create( int width, int height, int argc, char** argv )
1632 {
1633 }
1634
1635 void WebEngine::Destroy()
1636 {
1637 }
1638
1639 WebEngineSettings& WebEngine::GetSettings() const
1640 {
1641   return Internal::Adaptor::GetImplementation( *this ).GetSettings();
1642 }
1643
1644 WebEngineContext& WebEngine::GetContext() const
1645 {
1646   return Internal::Adaptor::GetImplementation( *this ).GetContext();
1647 }
1648
1649 WebEngineCookieManager& WebEngine::GetCookieManager() const
1650 {
1651   return Internal::Adaptor::GetImplementation( *this ).GetCookieManager();
1652 }
1653
1654 WebEngineBackForwardList& WebEngine::GetBackForwardList() const
1655 {
1656   return Internal::Adaptor::GetImplementation( *this ).GetBackForwardList();
1657 }
1658
1659 void WebEngine::LoadUrl( const std::string& url )
1660 {
1661   return Internal::Adaptor::GetImplementation( *this ).LoadUrl( url );
1662 }
1663
1664 std::string WebEngine::GetTitle() const
1665 {
1666   return Internal::Adaptor::GetImplementation( *this ).GetTitle();
1667 }
1668
1669 Dali::PixelData WebEngine::GetFavicon() const
1670 {
1671   return Internal::Adaptor::GetImplementation( *this ).GetFavicon();
1672 }
1673
1674 const std::string& WebEngine::GetUrl()
1675 {
1676   return Internal::Adaptor::GetImplementation( *this ).GetUrl();
1677 }
1678
1679 NativeImageInterfacePtr WebEngine::GetNativeImageSource()
1680 {
1681   Any source;
1682   Dali::NativeImageSourcePtr sourcePtr = Dali::NativeImageSource::New( source );
1683   return sourcePtr;
1684 }
1685
1686 void WebEngine::LoadHtmlString( const std::string& htmlString )
1687 {
1688 }
1689
1690 bool WebEngine::LoadHtmlStringOverrideCurrentEntry(const std::string& html, const std::string& basicUri, const std::string& unreachableUrl)
1691 {
1692   return true;
1693 }
1694
1695 bool WebEngine::LoadContents(const std::string& contents, uint32_t contentSize, const std::string& mimeType, const std::string& encoding, const std::string& baseUri)
1696 {
1697   return true;
1698 }
1699
1700 void WebEngine::Reload()
1701 {
1702 }
1703
1704 bool WebEngine::ReloadWithoutCache()
1705 {
1706   return true;
1707 }
1708
1709 void WebEngine::StopLoading()
1710 {
1711 }
1712
1713 void WebEngine::Suspend()
1714 {
1715 }
1716
1717 void WebEngine::Resume()
1718 {
1719 }
1720
1721 void WebEngine::SuspendNetworkLoading()
1722 {
1723 }
1724
1725 void WebEngine::ResumeNetworkLoading()
1726 {
1727 }
1728
1729 bool WebEngine::AddCustomHeader(const std::string& name, const std::string& value)
1730 {
1731   return true;
1732 }
1733
1734 bool WebEngine::RemoveCustomHeader(const std::string& name)
1735 {
1736   return true;
1737 }
1738
1739 uint32_t WebEngine::StartInspectorServer(uint32_t port)
1740 {
1741   return port;
1742 }
1743
1744 bool WebEngine::StopInspectorServer()
1745 {
1746   return true;
1747 }
1748
1749 bool WebEngine::CanGoForward()
1750 {
1751   return Internal::Adaptor::GetImplementation( *this ).CanGoForward();
1752 }
1753
1754 void WebEngine::GoForward()
1755 {
1756   Internal::Adaptor::GetImplementation( *this ).GoForward();
1757 }
1758
1759 bool WebEngine::CanGoBack()
1760 {
1761   return Internal::Adaptor::GetImplementation( *this ).CanGoBack();
1762 }
1763
1764 void WebEngine::GoBack()
1765 {
1766   Internal::Adaptor::GetImplementation( *this ).GoBack();
1767 }
1768
1769 void WebEngine::EvaluateJavaScript( const std::string& script, std::function< void( const std::string& ) > resultHandler )
1770 {
1771   Internal::Adaptor::GetImplementation( *this ).EvaluateJavaScript( script, resultHandler );
1772 }
1773
1774 void WebEngine::AddJavaScriptMessageHandler( const std::string& exposedObjectName, std::function< void(const std::string&) > handler )
1775 {
1776 }
1777
1778 void WebEngine::RegisterJavaScriptAlertCallback( Dali::WebEnginePlugin::JavaScriptAlertCallback callback )
1779 {
1780   Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptAlertCallback( callback );
1781 }
1782
1783 void WebEngine::JavaScriptAlertReply()
1784 {
1785 }
1786
1787 void WebEngine::RegisterJavaScriptConfirmCallback( Dali::WebEnginePlugin::JavaScriptConfirmCallback callback )
1788 {
1789   Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptConfirmCallback( callback );
1790 }
1791
1792 void WebEngine::JavaScriptConfirmReply( bool confirmed )
1793 {
1794 }
1795
1796 void WebEngine::RegisterJavaScriptPromptCallback( Dali::WebEnginePlugin::JavaScriptPromptCallback callback )
1797 {
1798   Internal::Adaptor::GetImplementation( *this ).RegisterJavaScriptPromptCallback( callback );
1799 }
1800
1801 void WebEngine::JavaScriptPromptReply( const std::string& result )
1802 {
1803 }
1804
1805 void WebEngine::ClearAllTilesResources()
1806 {
1807 }
1808
1809 void WebEngine::ClearHistory()
1810 {
1811   Internal::Adaptor::GetImplementation( *this ).ClearHistory();
1812 }
1813
1814 void WebEngine::SetScaleFactor(float scaleFactor, Dali::Vector2 point)
1815 {
1816   Internal::Adaptor::GetImplementation( *this ).SetScaleFactor(scaleFactor, point);
1817 }
1818
1819 float WebEngine::GetScaleFactor() const
1820 {
1821   return Internal::Adaptor::GetImplementation( *this ).GetScaleFactor();
1822 }
1823
1824 void WebEngine::ActivateAccessibility(bool activated)
1825 {
1826 }
1827
1828 bool WebEngine::HighlightText(const std::string& text, Dali::WebEnginePlugin::FindOption options, uint32_t maxMatchCount)
1829 {
1830   return true;
1831 }
1832
1833 void WebEngine::AddDynamicCertificatePath(const std::string& host, const std::string& certPath)
1834 {
1835 }
1836
1837 Dali::PixelData WebEngine::GetScreenshot(Dali::Rect<int> viewArea, float scaleFactor)
1838 {
1839   return Internal::Adaptor::GetImplementation( *this ).GetScreenshot(viewArea, scaleFactor);
1840 }
1841
1842 bool WebEngine::GetScreenshotAsynchronously(Dali::Rect<int> viewArea, float scaleFactor, Dali::WebEnginePlugin::ScreenshotCapturedCallback callback)
1843 {
1844   return Internal::Adaptor::GetImplementation( *this ).GetScreenshotAsynchronously(viewArea, scaleFactor, callback);
1845 }
1846
1847 bool WebEngine::CheckVideoPlayingAsynchronously(Dali::WebEnginePlugin::VideoPlayingCallback callback)
1848 {
1849   return Internal::Adaptor::GetImplementation( *this ).CheckVideoPlayingAsynchronously(callback);
1850 }
1851
1852 void WebEngine::RegisterGeolocationPermissionCallback(Dali::WebEnginePlugin::GeolocationPermissionCallback callback)
1853 {
1854   Internal::Adaptor::GetImplementation( *this ).RegisterGeolocationPermissionCallback(callback);
1855 }
1856
1857 const std::string& WebEngine::GetUserAgent() const
1858 {
1859   return Internal::Adaptor::GetImplementation( *this ).GetUserAgent();
1860 }
1861
1862 void WebEngine::SetUserAgent( const std::string& userAgent )
1863 {
1864   Internal::Adaptor::GetImplementation( *this ).SetUserAgent( userAgent );
1865 }
1866
1867 void WebEngine::ScrollBy( int dx, int dy )
1868 {
1869   Internal::Adaptor::GetImplementation( *this ).ScrollBy( dx, dy );
1870 }
1871
1872 bool WebEngine::ScrollEdgeBy( int dx, int dy )
1873 {
1874   return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeBy( dx, dy );
1875 }
1876
1877 void WebEngine::SetScrollPosition( int x, int y )
1878 {
1879   Internal::Adaptor::GetImplementation( *this ).SetScrollPosition( x, y );
1880 }
1881
1882 Dali::Vector2 WebEngine::GetScrollPosition() const
1883 {
1884   return Internal::Adaptor::GetImplementation( *this ).GetScrollPosition();
1885 }
1886
1887 Dali::Vector2 WebEngine::GetScrollSize() const
1888 {
1889   return Internal::Adaptor::GetImplementation( *this ).GetScrollSize();
1890 }
1891
1892 Dali::Vector2 WebEngine::GetContentSize() const
1893 {
1894   return Internal::Adaptor::GetImplementation( *this ).GetContentSize();
1895 }
1896
1897 void WebEngine::SetSize( int width, int height )
1898 {
1899 }
1900
1901 void WebEngine::SetDocumentBackgroundColor(Dali::Vector4 color)
1902 {
1903 }
1904
1905 void WebEngine::ClearTilesWhenHidden(bool cleared)
1906 {
1907 }
1908
1909 void WebEngine::SetTileCoverAreaMultiplier(float multiplier)
1910 {
1911 }
1912
1913 void WebEngine::EnableCursorByClient(bool enabled)
1914 {
1915 }
1916
1917 std::string WebEngine::GetSelectedText() const
1918 {
1919   return "test";
1920 }
1921
1922 bool WebEngine::SendTouchEvent( const TouchEvent& touch )
1923 {
1924   return true;
1925 }
1926
1927 bool WebEngine::SendKeyEvent( const KeyEvent& event )
1928 {
1929   return true;
1930 }
1931
1932 bool WebEngine::SendHoverEvent( const HoverEvent& event )
1933 {
1934   return true;
1935 }
1936
1937 bool WebEngine::SendWheelEvent( const WheelEvent& event )
1938 {
1939   return true;
1940 }
1941
1942 void WebEngine::SetFocus( bool focused )
1943 {
1944 }
1945
1946 void WebEngine::SetPageZoomFactor(float zoomFactor)
1947 {
1948   Internal::Adaptor::GetImplementation( *this ).SetPageZoomFactor(zoomFactor);
1949 }
1950
1951 float WebEngine::GetPageZoomFactor() const
1952 {
1953   return Internal::Adaptor::GetImplementation( *this ).GetPageZoomFactor();
1954 }
1955
1956 void WebEngine::SetTextZoomFactor(float zoomFactor)
1957 {
1958   Internal::Adaptor::GetImplementation( *this ).SetTextZoomFactor(zoomFactor);
1959 }
1960
1961 float WebEngine::GetTextZoomFactor() const
1962 {
1963   return Internal::Adaptor::GetImplementation( *this ).GetTextZoomFactor();
1964 }
1965
1966 float WebEngine::GetLoadProgressPercentage() const
1967 {
1968   return Internal::Adaptor::GetImplementation( *this ).GetLoadProgressPercentage();
1969 }
1970
1971 void WebEngine::UpdateDisplayArea( Dali::Rect< int > displayArea )
1972 {
1973 }
1974
1975 void WebEngine::EnableVideoHole( bool enabled )
1976 {
1977 }
1978
1979 void WebEngine::EnableMouseEvents( bool enabled )
1980 {
1981 }
1982
1983 void WebEngine::EnableKeyEvents( bool enabled )
1984 {
1985 }
1986
1987 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadStartedSignal()
1988 {
1989   return Internal::Adaptor::GetImplementation( *this ).PageLoadStartedSignal();
1990 }
1991
1992 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadInProgressSignal()
1993 {
1994   return Internal::Adaptor::GetImplementation( *this ).PageLoadInProgressSignal();
1995 }
1996
1997 Dali::WebEnginePlugin::WebEnginePageLoadSignalType& WebEngine::PageLoadFinishedSignal()
1998 {
1999   return Internal::Adaptor::GetImplementation( *this ).PageLoadFinishedSignal();
2000 }
2001
2002 Dali::WebEnginePlugin::WebEnginePageLoadErrorSignalType& WebEngine::PageLoadErrorSignal()
2003 {
2004   return Internal::Adaptor::GetImplementation( *this ).PageLoadErrorSignal();
2005 }
2006
2007 Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& WebEngine::ScrollEdgeReachedSignal()
2008 {
2009   return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeReachedSignal();
2010 }
2011
2012 Dali::WebEnginePlugin::WebEngineUrlChangedSignalType& WebEngine::UrlChangedSignal()
2013 {
2014   return Internal::Adaptor::GetImplementation( *this ).UrlChangedSignal();
2015 }
2016
2017 Dali::WebEnginePlugin::WebEngineFormRepostDecisionSignalType& WebEngine::FormRepostDecisionSignal()
2018 {
2019   return Internal::Adaptor::GetImplementation(*this).FormRepostDecisionSignal();
2020 }
2021
2022 Dali::WebEnginePlugin::WebEngineFrameRenderedSignalType& WebEngine::FrameRenderedSignal()
2023 {
2024   return Internal::Adaptor::GetImplementation(*this).FrameRenderedSignal();
2025 }
2026
2027 Dali::WebEnginePlugin::WebEngineRequestInterceptorSignalType& WebEngine::RequestInterceptorSignal()
2028 {
2029   return Internal::Adaptor::GetImplementation(*this).RequestInterceptorSignal();
2030 }
2031
2032 Dali::WebEnginePlugin::WebEngineConsoleMessageSignalType& WebEngine::ConsoleMessageSignal()
2033 {
2034   return Internal::Adaptor::GetImplementation(*this).ConsoleMessageSignal();
2035 }
2036
2037 Dali::WebEnginePlugin::WebEnginePolicyDecisionSignalType& WebEngine::PolicyDecisionSignal()
2038 {
2039   return Internal::Adaptor::GetImplementation(*this).PolicyDecisionSignal();
2040 }
2041
2042 Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::CertificateConfirmSignal()
2043 {
2044   return Internal::Adaptor::GetImplementation(*this).CertificateConfirmSignal();
2045 }
2046
2047 Dali::WebEnginePlugin::WebEngineCertificateSignalType& WebEngine::SslCertificateChangedSignal()
2048 {
2049   return Internal::Adaptor::GetImplementation(*this).SslCertificateChangedSignal();
2050 }
2051
2052 Dali::WebEnginePlugin::WebEngineHttpAuthHandlerSignalType& WebEngine::HttpAuthHandlerSignal()
2053 {
2054   return Internal::Adaptor::GetImplementation(*this).HttpAuthHandlerSignal();
2055 }
2056
2057 Dali::WebEnginePlugin::WebEngineContextMenuCustomizedSignalType& WebEngine::ContextMenuCustomizedSignal()
2058 {
2059   return Internal::Adaptor::GetImplementation( *this ).ContextMenuCustomizedSignal();
2060 }
2061
2062 Dali::WebEnginePlugin::WebEngineContextMenuItemSelectedSignalType& WebEngine::ContextMenuItemSelectedSignal()
2063 {
2064   return Internal::Adaptor::GetImplementation( *this ).ContextMenuItemSelectedSignal();
2065 }
2066
2067 } // namespace Dali;
2068