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