Revert "[M120 Migration]Fix for crash during chrome exit"
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / eweb_view.h
1 // Copyright 2014 Samsung Electronics. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef EWEB_VIEW_H
6 #define EWEB_VIEW_H
7
8 #include <map>
9 #include <string>
10 #include <Evas.h>
11 #include <locale.h>
12 #include <vector>
13
14 #include "base/containers/id_map.h"
15 #include "base/functional/callback.h"
16 #include "base/synchronization/waitable_event.h"
17 #include "browser/input_picker/input_picker.h"
18 #include "content/browser/select_picker/select_picker_base.h"
19 #include "content/browser/selection/selection_controller_efl.h"
20 #include "content/browser/web_contents/web_contents_view_aura.h"
21 #include "content/browser/web_contents/web_contents_view_aura_helper_efl.h"
22 #include "content/common/input/event_with_latency_info.h"
23 #include "content/public/browser/context_menu_params.h"
24 #include "content/public/browser/navigation_controller.h"
25 #include "content/public/browser/web_contents_delegate.h"
26 #include "content/public/browser/webview_delegate.h"
27 #include "content/public/common/input_event_ack_state.h"
28 #include "content_browser_client_efl.h"
29 #include "context_menu_controller_efl.h"
30 #include "eweb_context.h"
31 #include "eweb_view_callbacks.h"
32 #include "file_chooser_controller_efl.h"
33 #include "permission_popup_manager.h"
34 #include "popup_controller_efl.h"
35 #include "private/ewk_auth_challenge_private.h"
36 #include "private/ewk_back_forward_list_private.h"
37 #include "private/ewk_history_private.h"
38 #include "private/ewk_hit_test_private.h"
39 #include "private/ewk_settings_private.h"
40 #include "private/ewk_web_application_icon_data_private.h"
41 #include "public/ewk_hit_test_internal.h"
42 #include "public/ewk_touch_internal.h"
43 #include "public/ewk_view_product.h"
44 #include "scroll_detector.h"
45 #include "third_party/blink/public/common/context_menu_data/menu_item_info.h"
46 #include "third_party/blink/public/mojom/choosers/file_chooser.mojom.h"
47 #include "third_party/blink/public/mojom/choosers/popup_menu.mojom.h"
48 #include "ui/aura/window_tree_host.h"
49 #include "ui/gfx/geometry/point.h"
50 #include "ui/gfx/geometry/size.h"
51 #include "web_contents_delegate_efl.h"
52 #if defined(TIZEN_PEPPER_EXTENSIONS)
53 #include "ewk_extension_system_delegate.h"
54 #include "public/ewk_value_product.h"
55 #endif
56
57 #if BUILDFLAG(IS_TIZEN_TV)
58 #include "third_party/blink/public/common/mediastream/media_devices.h"
59 #endif
60
61 namespace aura {
62 namespace client {
63 class FocusClient;
64 class WindowParentingClient;
65 }  // namespace client
66 }  // namespace aura
67
68 namespace base {
69 class FilePath;
70 }
71
72 namespace content {
73 class RenderFrameHost;
74 class RenderViewHost;
75 class RenderWidgetHostViewAura;
76 class WebContentsDelegateEfl;
77 class WebContentsViewAura;
78 class ContextMenuControllerEfl;
79 class PopupControllerEfl;
80 class DateTimeChooserEfl;
81 class InputPicker;
82 class GinNativeBridgeDispatcherHost;
83 class NavigationHandle;
84 }
85
86 class ErrorParams;
87 class _Ewk_App_Control;
88 class _Ewk_Policy_Decision;
89 class _Ewk_Hit_Test;
90 class Ewk_Context;
91 class _Ewk_Quota_Permission_Request;
92
93 #if BUILDFLAG(IS_TIZEN_TV)
94 struct _Ewk_File_Chooser_Request;
95 #endif
96
97 #if defined(TIZEN_ATK_SUPPORT)
98 class EWebAccessibility;
99 #endif
100
101 template <typename CallbackPtr, typename CallbackParameter>
102 class WebViewCallback {
103  public:
104   WebViewCallback() { Set(nullptr, nullptr); }
105
106   void Set(CallbackPtr cb, void* data) {
107     callback_ = cb;
108     user_data_ = data;
109   }
110
111   bool IsCallbackSet() const { return callback_; }
112
113   Eina_Bool Run(Evas_Object* webview,
114                 CallbackParameter param,
115                 Eina_Bool* callback_result) {
116     CHECK(callback_result);
117     if (IsCallbackSet()) {
118       *callback_result = callback_(webview, param, user_data_);
119       return true;
120     }
121     return false;
122   }
123
124   void Run(Evas_Object* webview, CallbackParameter param) {
125     if (IsCallbackSet())
126       callback_(webview, param, user_data_);
127   }
128
129  private:
130   CallbackPtr callback_;
131   void* user_data_;
132 };
133
134 template <typename CallbackReturnValue,
135           typename CallbackPtr,
136           typename CallbackParameter>
137 class WebViewCallbackWithReturnValue {
138  public:
139   WebViewCallbackWithReturnValue() { Set(nullptr, nullptr); }
140
141   void Set(CallbackPtr cb, void* data) {
142     callback_ = cb;
143     user_data_ = data;
144   }
145
146   /* LCOV_EXCL_START */
147   bool IsCallbackSet() const { return callback_; }
148
149   CallbackReturnValue Run(Evas_Object* webview, CallbackParameter param) {
150     if (IsCallbackSet())
151       return callback_(webview, param, user_data_);
152
153     return {};
154   }
155   /* LCOV_EXCL_STOP */
156
157  private:
158   CallbackPtr callback_;
159   void* user_data_;
160 };
161
162 template <typename CallbackPtr, typename... CallbackParameter>
163 class WebViewErrorPageLoadCallback {
164  public:
165   WebViewErrorPageLoadCallback() { Set(nullptr, nullptr); }
166
167   void Set(CallbackPtr cb, void* data) {
168     callback_ = cb;
169     user_data_ = data;
170   }
171
172   bool IsCallbackSet() const { return callback_; }
173
174   void Run(Evas_Object* webview, CallbackParameter... param) {
175     if (IsCallbackSet())
176       callback_(webview, param..., user_data_);
177   }
178
179  private:
180   CallbackPtr callback_;
181   void* user_data_;
182 };
183
184 template <typename CallbackPtr, typename... CallbackParameter>
185 class WebViewExceededQuotaCallback {
186  public:
187   WebViewExceededQuotaCallback() { Set(nullptr, nullptr); }
188
189   void Set(CallbackPtr cb, void* data) {
190     callback_ = cb;
191     user_data_ = data;
192   }
193
194   bool IsCallbackSet() const { return callback_; }
195
196   /* LCOV_EXCL_START */
197   void Run(Evas_Object* webview, CallbackParameter... param) {
198     if (IsCallbackSet())
199       callback_(webview, param..., user_data_);
200   }
201   /* LCOV_EXCL_STOP */
202
203  private:
204   CallbackPtr callback_;
205   void* user_data_;
206 };
207
208 class BackgroundColorGetCallback {
209  public:
210   BackgroundColorGetCallback(Ewk_View_Background_Color_Get_Callback func,
211                              void* user_data)
212       : func_(func), user_data_(user_data) {}
213
214   void Run(Evas_Object* webview, int r, int g, int b, int a) {
215     if (func_)
216       func_(webview, r, g, b, a, user_data_);
217   }
218
219  private:
220   Ewk_View_Background_Color_Get_Callback func_;
221   void* user_data_;
222 };
223
224 class WebApplicationIconUrlGetCallback {
225  public:
226   WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
227                                    void* user_data)
228       : func_(func), user_data_(user_data) {}
229   void Run(const std::string& url) {
230     if (func_) {
231       (func_)(url.c_str(), user_data_);
232     }
233   }
234
235  private:
236   Ewk_Web_App_Icon_URL_Get_Callback func_;
237   void* user_data_;
238 };
239
240 class WebApplicationIconUrlsGetCallback {
241  public:
242   WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
243                                     void* user_data)
244       : func_(func), user_data_(user_data) {}
245   void Run(const std::map<std::string, std::string>& urls) {
246     if (func_) {
247       Eina_List* list = NULL;
248       for (std::map<std::string, std::string>::const_iterator it = urls.begin();
249            it != urls.end(); ++it) {
250         _Ewk_Web_App_Icon_Data* data =
251             ewkWebAppIconDataCreate(it->first, it->second);
252         list = eina_list_append(list, data);
253       }
254       (func_)(list, user_data_);
255     }
256   }
257
258  private:
259   Ewk_Web_App_Icon_URLs_Get_Callback func_;
260   void* user_data_;
261 };
262
263 class WebApplicationCapableGetCallback {
264  public:
265   WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
266                                    void* user_data)
267       : func_(func), user_data_(user_data) {}
268   void Run(bool capable) {
269     if (func_) {
270       (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
271     }
272   }
273
274  private:
275   Ewk_Web_App_Capable_Get_Callback func_;
276   void* user_data_;
277 };
278
279 class DidChangeThemeColorCallback {
280  public:
281   DidChangeThemeColorCallback() : callback_(nullptr), user_data_(nullptr) {}
282   void Set(Ewk_View_Did_Change_Theme_Color_Callback callback, void* user_data) {
283     callback_ = callback;
284     user_data_ = user_data;
285   }
286   void Run(Evas_Object* o, const SkColor& color) {
287     if (callback_)
288       callback_(o, SkColorGetR(color), SkColorGetG(color), SkColorGetB(color),
289                 SkColorGetA(color), user_data_);
290   }
291
292  private:
293   Ewk_View_Did_Change_Theme_Color_Callback callback_;
294   void* user_data_;
295 };
296
297 #if BUILDFLAG(IS_TIZEN_TV)
298 class GetMediaDeviceCallback {
299  public:
300   GetMediaDeviceCallback() : func_(nullptr), user_data_(nullptr) {}
301
302   void Set(Ewk_Media_Device_List_Get_Callback func, void* user_data) {
303     func_ = func;
304     user_data_ = user_data;
305   }
306
307   void Run(EwkMediaDeviceInfo* device_list, int size) {
308     if (func_) {
309       (func_)(device_list, size, user_data_);
310     }
311   }
312
313  private:
314   Ewk_Media_Device_List_Get_Callback func_;
315   void* user_data_;
316 };
317 #endif
318
319 #if BUILDFLAG(IS_TIZEN_TV)
320 class IsVideoPlayingCallback {
321  public:
322   IsVideoPlayingCallback(Ewk_Is_Video_Playing_Callback func, void* user_data)
323       : func_(func), user_data_(user_data) {}
324   void Run(Evas_Object* obj, bool isplaying) {
325     if (func_) {
326       (func_)(obj, isplaying ? EINA_TRUE : EINA_FALSE, user_data_);
327     }
328   }
329
330  private:
331   Ewk_Is_Video_Playing_Callback func_;
332   void* user_data_;
333 };
334 #endif
335
336 class WebViewAsyncRequestHitTestDataCallback;
337 class JavaScriptDialogManagerEfl;
338 class PermissionPopupManager;
339
340 class EWebView {
341  public:
342   static EWebView* FromEwkView(Evas_Object* ewk_view);
343
344   EWebView(Ewk_Context*, Evas_Object* smart_object);
345   ~EWebView();
346
347   // initialize data members and activate event handlers.
348   // call this once after created and before use
349   void Initialize();
350
351   bool CreateNewWindow(content::WebViewDelegate::WebContentsCreateCallback);
352   static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
353
354   content::WebContentsViewAura* wcva() const;
355   content::RenderWidgetHostViewAura* rwhva() const;
356   Ewk_Context* context() const { return context_.get(); }
357   Evas_Object* ewk_view() const { return ewk_view_; }
358   Evas_Object* efl_main_layout() const { return efl_main_layout_; }
359   Evas_Object* GetElmWindow() const;
360   Evas* GetEvas() const { return evas_object_evas_get(ewk_view_); }
361   PermissionPopupManager* GetPermissionPopupManager() const {
362     return permission_popup_manager_.get();
363   }
364
365   content::WebContents& web_contents() const { return *web_contents_.get(); }
366   content::WebContentsViewAura* GetWebContentsViewAura() const;
367
368 #if defined(TIZEN_ATK_SUPPORT)
369   EWebAccessibility& eweb_accessibility() const {
370     return *eweb_accessibility_.get();
371   }
372 #endif
373
374   template <EWebViewCallbacks::CallbackType callbackType>
375   EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
376     return EWebViewCallbacks::CallBack<callbackType>(ewk_view_);
377   }
378
379   // ewk_view api
380   void SetURL(const GURL& url, bool from_api = false);
381   const GURL& GetURL() const;
382   const GURL& GetOriginalURL() const;
383   void Reload();
384   void ReloadBypassingCache();
385   Eina_Bool CanGoBack();
386   Eina_Bool CanGoForward();
387   Eina_Bool HasFocus() const;
388   void SetFocus(Eina_Bool focus);
389   Eina_Bool GoBack();
390   Eina_Bool GoForward();
391   void Suspend();
392   void Resume();
393   void Stop();
394 #if BUILDFLAG(IS_TIZEN_TV)
395   void SetFloatVideoWindowState(bool enabled);
396   void NotifyDownloadableFontInfo(const char* scheme_id_uri,
397                                   const char* value,
398                                   const char* data,
399                                   int type);
400   std::vector<std::string> NotifyPlaybackState(int state,
401                                                int player_id,
402                                                const char* url,
403                                                const char* mime_type);
404   void SuspendNetworkLoading();
405   void ResumeNetworkLoading();
406   void NotifyAudioTracksCount(int player_id, unsigned audio_tracks_count);
407 #endif // IS_TIZEN_TV
408   void SetSessionTimeout(uint64_t timeout);
409   double GetTextZoomFactor() const;
410   void SetTextZoomFactor(double text_zoom_factor);
411   double GetPageZoomFactor() const;
412   void SetPageZoomFactor(double page_zoom_factor);
413   void ExecuteEditCommand(const char* command, const char* value);
414 #if BUILDFLAG(IS_TIZEN)
415   void EnterDragState();
416 #endif
417   void SetOrientation(int orientation);
418   int GetOrientation();
419   bool TouchEventsEnabled() const;
420   void SetTouchEventsEnabled(bool enabled);
421   bool MouseEventsEnabled() const;
422   void SetMouseEventsEnabled(bool enabled);
423   void SendKeyEvent(Evas_Object* ewk_view, void* key_event, bool is_press);
424   bool SetKeyEventsEnabled(bool enabled);
425   void HandleTouchEvents(Ewk_Touch_Event_Type type,
426                          const Eina_List* points,
427                          const Evas_Modifier* modifiers);
428   void Show();
429   void Hide();
430   bool ExecuteJavaScript(const char* script,
431                          Ewk_View_Script_Execute_Callback callback,
432                          void* userdata);
433   bool SetUserAgent(const char* userAgent);
434   bool SetUserAgentAppName(const char* application_name);
435 #if BUILDFLAG(IS_TIZEN)
436   bool SetPrivateBrowsing(bool incognito);
437   bool GetPrivateBrowsing() const;
438 #endif
439   const char* GetUserAgent() const;
440   const char* GetUserAgentAppName() const;
441   const char* CacheSelectedText();
442   Ewk_Settings* GetSettings() { return settings_.get(); }
443   _Ewk_Frame* GetMainFrame();
444   void UpdateWebKitPreferences();
445   void LoadHTMLString(const char* html,
446                       const char* base_uri,
447                       const char* unreachable_uri);
448   void LoadPlainTextString(const char* plain_text);
449
450   void LoadHTMLStringOverridingCurrentEntry(const char* html,
451                                             const char* base_uri,
452                                             const char* unreachable_url);
453   void LoadData(const char* data,
454                 size_t size,
455                 const char* mime_type,
456                 const char* encoding,
457                 const char* base_uri,
458                 const char* unreachable_uri = NULL,
459                 bool should_replace_current_entry = false);
460   void InvokeLoadError(const GURL& url, int error_code, bool is_cancellation);
461
462   void SetViewAuthCallback(Ewk_View_Authentication_Callback callback,
463                            void* user_data);
464   void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
465                           const GURL& url,
466                           const std::string& realm);
467   void Find(const char* text, Ewk_Find_Options);
468   void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
469   void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
470   void HandlePopupMenu(std::vector<blink::mojom::MenuItemPtr> items,
471                        int selectedIndex,
472                        bool multiple,
473                        const gfx::Rect& bounds);
474   void HidePopupMenu();
475   void DidSelectPopupMenuItems(std::vector<int>& indices);
476   void DidCancelPopupMenu();
477   void HandleLongPressGesture(const content::ContextMenuParams&);
478   void ShowContextMenu(const content::ContextMenuParams&);
479   void CancelContextMenu(int request_id);
480   void SetScale(double scale_factor);
481   void SetScaleChangedCallback(Ewk_View_Scale_Changed_Callback callback,
482                                void* user_data);
483
484   bool GetScrollPosition(int* x, int* y) const;
485   void SetScroll(int x, int y);
486   void UrlRequestSet(const char* url,
487                      content::NavigationController::LoadURLType loadtype,
488                      Eina_Hash* headers,
489                      const char* body);
490
491   SelectPickerBase* GetSelectPicker() const { return select_picker_.get(); }
492   content::SelectionControllerEfl* GetSelectionController() const;
493   content::PopupControllerEfl* GetPopupController() const {
494     return popup_controller_.get();
495   }
496   ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
497   void MoveCaret(const gfx::Point& point);
498   void SelectFocusedLink();
499   bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
500   Eina_Bool ClearSelection();
501
502   // Callback OnCopyFromBackingStore will be called once we get the snapshot
503   // from render
504   void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
505
506   void OnFocusIn();
507   void OnFocusOut();
508
509   void UpdateContextMenu(bool is_password_input);
510   void RenderViewReady();
511
512   /**
513    * Creates a snapshot of given rectangle from EWebView
514    *
515    * @param rect rectangle of EWebView which will be taken into snapshot
516    * @param scale_factor scale factor
517    * @return created snapshot or NULL if error occured.
518    * @note ownership of snapshot is passed to caller
519    */
520   Evas_Object* GetSnapshot(Eina_Rectangle rect, float scale_factor);
521
522   bool GetSnapshotAsync(Eina_Rectangle rect,
523                         Ewk_Web_App_Screenshot_Captured_Callback callback,
524                         void* user_data,
525                         float scale_factor);
526   void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision,
527                                     bool* defer);
528   void InvokePolicyNavigationCallback(const NavigationPolicyParams& params,
529                                       bool* handled);
530   void UseSettingsFont();
531
532   _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
533   Eina_Bool AsyncRequestHitTestDataAt(int x,
534                                       int y,
535                                       Ewk_Hit_Test_Mode mode,
536                                       Ewk_View_Hit_Test_Request_Callback,
537                                       void* user_data);
538   _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
539                                                  int y,
540                                                  Ewk_Hit_Test_Mode mode);
541   Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
542       int x,
543       int y,
544       Ewk_Hit_Test_Mode mode,
545       Ewk_View_Hit_Test_Request_Callback,
546       void* user_data);
547   void DispatchAsyncHitTestData(const Hit_Test_Params& params,
548                                 int64_t request_id);
549   void UpdateHitTestData(const Hit_Test_Params& params);
550
551   int current_find_request_id() const { return current_find_request_id_; }
552   bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
553   void InvokePlainTextGetCallback(const std::string& content_text,
554                                   int plain_text_get_callback_id);
555   int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
556                                      void* user_data);
557   void SetViewGeolocationPermissionCallback(
558       Ewk_View_Geolocation_Permission_Callback callback,
559       void* user_data);
560   bool InvokeViewGeolocationPermissionCallback(
561       _Ewk_Geolocation_Permission_Request*
562           geolocation_permission_request_context,
563       Eina_Bool* result);
564   void SetViewUserMediaPermissionCallback(
565       Ewk_View_User_Media_Permission_Callback callback,
566       void* user_data);
567   bool InvokeViewUserMediaPermissionCallback(
568       _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
569       Eina_Bool* result);
570   void SetViewUserMediaPermissionQueryCallback(
571       Ewk_View_User_Media_Permission_Query_Callback callback,
572       void* user_data);
573   Ewk_User_Media_Permission_Query_Result
574   InvokeViewUserMediaPermissionQueryCallback(
575       _Ewk_User_Media_Permission_Query* user_media_permission_query_context);
576
577   void SetViewLoadErrorPageCallback(Ewk_View_Error_Page_Load_Callback callback,
578                                     void* user_data);
579   const char* InvokeViewLoadErrorPageCallback(const GURL& url,
580                                               int error_code,
581                                               bool is_cancellation);
582   bool IsLoadErrorPageCallbackSet() const;
583   void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
584                                    void* user_data);
585   bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
586                                       Eina_Bool* result);
587 #if BUILDFLAG(IS_TIZEN_TV)
588   void SetViewSmartrcMicNotificationCallback(
589       Ewk_View_SmartRC_Mic_Notification_Callback callback,
590       void* user_data);
591   void ShowMicOpenedNotification(bool show);
592 #endif
593   void DidChangeContentsSize(int width, int height);
594   const Eina_Rectangle GetContentsSize() const;
595   void GetScrollSize(int* w, int* h);
596   void StopFinding();
597   void SetProgressValue(double progress);
598   double GetProgressValue();
599   const char* GetTitle();
600   bool SaveAsPdf(int width, int height, const std::string& file_name);
601   void BackForwardListClear();
602   _Ewk_Back_Forward_List* GetBackForwardList() const;
603   void InvokeBackForwardListChangedCallback();
604   _Ewk_History* GetBackForwardHistory() const;
605   bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
606                         void* userData);
607   bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
608                         void* userData);
609   bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
610                          void* userData);
611   void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
612   void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
613                                       int callbackId);
614   void InvokeWebAppIconUrlsGetCallback(
615       const std::map<std::string, std::string>& iconUrls,
616       int callbackId);
617   void SetNotificationPermissionCallback(
618       Ewk_View_Notification_Permission_Callback callback,
619       void* user_data);
620   bool IsNotificationPermissionCallbackSet() const;
621   bool InvokeNotificationPermissionCallback(
622       Ewk_Notification_Permission_Request* request);
623
624   bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
625   void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
626   bool SavePageAsMHTML(const std::string& path,
627                        Ewk_View_Save_Page_Callback callback,
628                        void* user_data);
629   bool IsFullscreen();
630   void ExitFullscreen();
631   double GetScale();
632   void DidChangePageScaleFactor(double scale_factor);
633   void SetScaledContentsSize();
634   void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
635                                   void* user_data);
636   void JavaScriptAlertReply();
637   void SetJavaScriptConfirmCallback(
638       Ewk_View_JavaScript_Confirm_Callback callback,
639       void* user_data);
640   void JavaScriptConfirmReply(bool result);
641   void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
642                                    void* user_data);
643   void JavaScriptPromptReply(const char* result);
644   void set_renderer_crashed();
645   void GetPageScaleRange(double* min_scale, double* max_scale);
646   bool SetDrawsTransparentBackground(bool enabled);
647   bool GetDrawsTransparentBackground();
648   bool SetBackgroundColor(int red, int green, int blue, int alpha);
649   bool GetBackgroundColor(Ewk_View_Background_Color_Get_Callback callback,
650                           void* user_data);
651   void OnGetBackgroundColor(int callback_id, SkColor bg_color);
652
653   void GetSessionData(const char** data, unsigned* length) const;
654   bool RestoreFromSessionData(const char* data, unsigned length);
655   void ShowFileChooser(scoped_refptr<content::FileSelectListener> listener,
656                        const blink::mojom::FileChooserParams&);
657   void SetBrowserFont();
658   bool IsDragging() const;
659
660   void RequestColorPicker(int r, int g, int b, int a);
661   bool SetColorPickerColor(int r, int g, int b, int a);
662   void InputPickerShow(ui::TextInputType input_type,
663                        double input_value,
664                        content::DateTimeChooserEfl* date_time_chooser);
665
666   void ShowContentsDetectedPopup(const char*);
667
668   // Returns TCP port number with Inspector, or 0 if error.
669   int StartInspectorServer(int port = 0);
670   bool StopInspectorServer();
671
672   void LoadNotFoundErrorPage(const std::string& invalidUrl);
673   static std::string GetPlatformLocale();
674   bool GetLinkMagnifierEnabled() const;
675   void SetLinkMagnifierEnabled(bool enabled);
676
677   bool GetHorizontalPanningHold() const;
678   void SetHorizontalPanningHold(bool hold);
679   bool GetVerticalPanningHold() const;
680   void SetVerticalPanningHold(bool hold);
681
682   bool GetRotationChanged() { return rotation_changed_; }
683   void SetRotationChanged(bool change) { rotation_changed_ = change; }
684
685   void SetQuotaPermissionRequestCallback(
686       Ewk_Quota_Permission_Request_Callback callback,
687       void* user_data);
688 #if !defined(EWK_BRINGUP)  // FIXME: m114 bringup
689   void InvokeQuotaPermissionRequest(
690       _Ewk_Quota_Permission_Request* request,
691       content::QuotaPermissionContext::PermissionCallback cb);
692   void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
693                          bool allow);
694   void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
695   void SetViewMode(blink::WebViewMode view_mode);
696 #endif
697   gfx::Point GetContextMenuPosition() const;
698
699   content::ContextMenuControllerEfl* GetContextMenuController() {
700     return context_menu_.get();
701   }
702
703   bool SetMainFrameScrollbarVisible(bool visible);
704   bool GetMainFrameScrollbarVisible(
705       Ewk_View_Main_Frame_Scrollbar_Visible_Get_Callback callback,
706       void* user_data);
707   void InvokeMainFrameScrollbarVisibleCallback(int callback_id, bool visible);
708
709   void ResetContextMenuController();
710   Eina_Bool AddJavaScriptMessageHandler(Evas_Object* view,
711                                         Ewk_View_Script_Message_Cb callback,
712                                         std::string name);
713
714   content::GinNativeBridgeDispatcherHost* GetGinNativeBridgeDispatcherHost()
715       const {
716     return gin_native_bridge_dispatcher_host_.get();
717   }
718   bool SetPageVisibility(Ewk_Page_Visibility_State page_visibility_state);
719
720   void SetExceededIndexedDatabaseQuotaCallback(
721       Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback,
722       void* user_data);
723   void InvokeExceededIndexedDatabaseQuotaCallback(const GURL& origin,
724                                                   int64_t current_quota);
725   void ExceededIndexedDatabaseQuotaReply(bool allow);
726
727 #if defined(TIZEN_VIDEO_HOLE)
728   void EnableVideoHoleSupport();
729 #endif
730
731 #if defined(TIZEN_TBM_SUPPORT)
732   void SetOffscreenRendering(bool enable);
733 #endif
734
735   /// ---- Event handling
736   bool HandleShow();
737   bool HandleHide();
738   bool HandleMove(int x, int y);
739   bool HandleResize(int width, int height);
740   bool HandleTextSelectionDown(int x, int y);
741   bool HandleTextSelectionUp(int x, int y);
742
743   void HandleRendererProcessCrash();
744   void InvokeWebProcessCrashedCallback();
745
746   void HandleTapGestureForSelection(bool is_content_editable);
747   void HandleZoomGesture(blink::WebGestureEvent& event);
748   void ClosePage();
749
750   void RequestManifest(Ewk_View_Request_Manifest_Callback callback,
751                        void* user_data);
752   void DidRespondRequestManifest(_Ewk_View_Request_Manifest* manifest,
753                                  Ewk_View_Request_Manifest_Callback callback,
754                                  void* user_data);
755
756   void SetBeforeUnloadConfirmPanelCallback(
757       Ewk_View_Before_Unload_Confirm_Panel_Callback callback,
758       void* user_data);
759   void ReplyBeforeUnloadConfirmPanel(Eina_Bool result);
760   void SyncAcceptLanguages(const std::string& accept_languages);
761
762 #if BUILDFLAG(IS_TIZEN_TV)
763   //Browser edge scroll
764   bool EdgeScrollBy(int delta_x, int delta_y);
765   void GetMousePosition(gfx::Point&);
766   void InvokeEdgeScrollByCallback(const gfx::Point&, bool);
767   // notify web browser video playing status
768   bool IsVideoPlaying(Ewk_Is_Video_Playing_Callback callback, void* user_data);
769   void InvokeIsVideoPlayingCallback(bool is_playing, int callback_id);
770   void InvokeScrollbarThumbFocusChangedCallback(
771       Ewk_Scrollbar_Orientation orientation,
772       bool focused);
773 #endif
774
775   void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
776                       const gfx::Vector2dF& latest_overscroll_delta);
777
778   bool SetVisibility(bool enable);
779   void SetDoNotTrack(Eina_Bool);
780
781 #if defined(TIZEN_ATK_SUPPORT)
782   void UpdateSpatialNavigationStatus(Eina_Bool enable);
783   void UpdateAccessibilityStatus(Eina_Bool enable);
784
785   bool CheckLazyInitializeAtk() {
786     return is_initialized_ && lazy_initialize_atk_;
787   }
788   void InitAtk();
789   bool GetAtkStatus();
790 #endif
791 #if defined(TIZEN_PEPPER_EXTENSIONS)
792   void InitializePepperExtensionSystem();
793   EwkExtensionSystemDelegate* GetExtensionDelegate();
794   void SetWindowId();
795   void SetPepperExtensionWidgetInfo(Ewk_Value widget_pepper_ext_info);
796   void SetPepperExtensionCallback(Generic_Sync_Call_Callback cb, void* data);
797   void RegisterPepperExtensionDelegate();
798   void UnregisterPepperExtensionDelegate();
799 #endif
800
801   bool ShouldIgnoreNavigation(content::NavigationHandle* navigation_handle);
802
803 #if BUILDFLAG(IS_TIZEN_TV)
804   void DrawLabel(Evas_Object* image, Eina_Rectangle rect);
805   void DeactivateAtk(bool deactivated);
806   void ClearLabels();
807   void AddDynamicCertificatePath(const std::string& host,
808                                  const std::string& cert_path);
809
810   bool SetMixedContents(bool allow);
811   void ClearAllTilesResources();
812   bool UseEarlyRWI() { return use_early_rwi_; }
813   bool RWIInfoShowed() { return rwi_info_showed_; }
814   GURL RWIURL() { return rwi_gurl_; }
815   void OnDialogClosed();
816   void NotifyMediaStateChanged(uint32_t type,
817                                uint32_t previous,
818                                uint32_t current);
819   void SetHighBitRate(Eina_Bool is_high_bitrate);
820   bool IsHighBitRate() const { return is_high_bitrate_; }
821   void NotifyFirstTimeStamp(unsigned long long timestamp,
822                             int time_base_num,
823                             int time_base_den);
824   void NotifyPESData(const std::string& buf,
825                      unsigned int len,
826                      int media_position);
827   void SetPreferSubtitleLang(const char* lang_list);
828   void NotifySubtitleState(int state, double time_stamp);
829   void NotifySubtitlePlay(int active_track_id,
830                           const char* url,
831                           const char* lang);
832   void NotifySubtitleData(int track_id,
833                           double time_stamp,
834                           const std::string& data,
835                           unsigned int size);
836   void UpdateCurrentTime(double current_time);
837   void UpdateEventData(void* data);
838   double GetCurrentTime() { return current_time_; }
839   void GetMediaDeviceList(Ewk_Media_Device_List_Get_Callback callback,
840                           void* userData);
841   using MediaDeviceEnumeration =
842       std::array<blink::WebMediaDeviceInfoArray, NUM_MEDIA_DEVICE_TYPES>;
843   void OnDeviceListed(const MediaDeviceEnumeration& devices);
844   void SetTranslatedURL(const char* url);
845   void NotifyParentalRatingInfo(const char* info, const char* url);
846   void SetParentalRatingResult(const char* info, bool is_pass);
847   void OnMouseLongPressed(int x, int y);
848   void OnMouseDown(int x, int y);
849   bool OnMouseUp();
850   void OnMouseMove();
851 #endif  // IS_TIZEN_TV
852
853   void SetDidChangeThemeColorCallback(
854       Ewk_View_Did_Change_Theme_Color_Callback callback,
855       void* user_data);
856   void DidChangeThemeColor(const SkColor& color);
857
858   void OnSelectionRectReceived(const gfx::Rect& selection_rect) const;
859
860  private:
861   static void NativeViewResize(void* data,
862                                Evas* e,
863                                Evas_Object* obj,
864                                void* event_info);
865   void InitializeContent();
866   void InitializeWindowTreeHost();
867   void SendDelayedMessages(content::RenderViewHost* render_view_host);
868
869   void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
870   Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
871       int x,
872       int y,
873       Ewk_Hit_Test_Mode mode,
874       WebViewAsyncRequestHitTestDataCallback* cb);
875
876 #if BUILDFLAG(IS_TIZEN_TV)
877   void InitInspectorServer();
878
879   void RunPendingSetFocus(Eina_Bool focus);
880   void SetFocusInternal(Eina_Bool focus);
881 #endif
882
883   JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
884
885   // Changes viewport without resizing Evas_Object representing webview
886   // and its corresponding RWHV to let Blink renders custom viewport
887   // while showing picker.
888   void AdjustViewPortHeightToPopupMenu(bool is_popup_menu_visible);
889
890   void ShowContextMenuInternal(const content::ContextMenuParams&);
891
892   void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
893
894   void ChangeScroll(int& x, int& y);
895   void ScrollFocusedNodeIntoView();
896
897   void GenerateMHTML(Ewk_View_Save_Page_Callback callback,
898                      void* user_data,
899                      const base::FilePath& file_path);
900   void MHTMLGenerated(Ewk_View_Save_Page_Callback callback,
901                       void* user_data,
902                       const base::FilePath& file_path,
903                       int64_t file_size);
904
905   static void VisibleContentChangedCallback(void* user_data,
906                                             Evas_Object* object,
907                                             void* event_info);
908
909   static void OnCustomScrollBeginCallback(void* user_data,
910                                           Evas_Object* object,
911                                           void* event_info);
912
913   static void OnCustomScrollEndCallback(void* user_data,
914                                         Evas_Object* object,
915                                         void* event_info);
916   void UpdateContextMenuWithParams(const content::ContextMenuParams& params);
917
918   static Eina_Bool DelayedPopulateAndShowContextMenu(void* data);
919
920   scoped_refptr<Ewk_Context> context_;
921   std::unique_ptr<content::WebContents> web_contents_;
922   std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
923   std::unique_ptr<content::WebViewDelegate> webview_delegate_;
924   std::string pending_url_request_;
925   std::unique_ptr<Ewk_Settings> settings_;
926   std::unique_ptr<_Ewk_Frame> frame_;
927   std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
928   Evas_Object* ewk_view_;
929   Evas_Object* efl_main_layout_;
930   bool key_events_enabled_ = true;
931   bool rotation_changed_ = false;
932   bool mouse_events_enabled_;
933   double text_zoom_factor_;
934   mutable std::string user_agent_;
935   mutable std::string user_agent_app_name_;
936   std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
937   std::string selected_text_cached_;
938
939   std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
940 #if BUILDFLAG(IS_TIZEN_TV)
941   std::unique_ptr<_Ewk_File_Chooser_Request> file_chooser_request_;
942 #else
943   std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
944 #endif
945   std::unique_ptr<content::PopupControllerEfl> popup_controller_;
946   std::u16string previous_text_;
947   int current_find_request_id_;
948   static int find_request_id_counter_;
949
950   typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
951       EwkViewPlainTextGetCallback;
952   base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
953
954   typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
955       MHTMLCallbackDetails;
956   base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
957
958 #if BUILDFLAG(IS_TIZEN_TV)
959   base::IDMap<IsVideoPlayingCallback*> is_video_playing_callback_map_;
960 #endif
961
962   typedef WebViewCallback<Ewk_View_Main_Frame_Scrollbar_Visible_Get_Callback,
963                           bool>
964       MainFrameScrollbarVisibleGetCallback;
965   base::IDMap<MainFrameScrollbarVisibleGetCallback*>
966       main_frame_scrollbar_visible_callback_map_;
967
968   base::IDMap<BackgroundColorGetCallback*> background_color_get_callback_map_;
969
970 #if BUILDFLAG(IS_TIZEN_TV)
971   GetMediaDeviceCallback device_cb_;
972 #endif
973
974   gfx::Size contents_size_;
975   double progress_;
976   mutable std::string title_;
977   Hit_Test_Params hit_test_params_;
978   base::WaitableEvent hit_test_completion_;
979   double page_scale_factor_;
980   double x_delta_;
981   double y_delta_;
982
983   WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
984                   _Ewk_Geolocation_Permission_Request*>
985       geolocation_permission_cb_;
986   WebViewCallback<Ewk_View_User_Media_Permission_Callback,
987                   _Ewk_User_Media_Permission_Request*>
988       user_media_permission_cb_;
989   WebViewCallbackWithReturnValue<Ewk_User_Media_Permission_Query_Result,
990                                  Ewk_View_User_Media_Permission_Query_Callback,
991                                  _Ewk_User_Media_Permission_Query*>
992       user_media_permission_query_cb_;
993   WebViewErrorPageLoadCallback<Ewk_View_Error_Page_Load_Callback,
994                                Ewk_Error*,
995                                Ewk_Error_Page*>
996       load_error_page_cb_;
997   WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
998       unfocus_allow_cb_;
999 #if BUILDFLAG(IS_TIZEN_TV)
1000   WebViewCallback<Ewk_View_SmartRC_Mic_Notification_Callback, bool>
1001       smartrc_mic_notification_cb_;
1002 #endif
1003   WebViewCallback<Ewk_View_Notification_Permission_Callback,
1004                   Ewk_Notification_Permission_Request*>
1005       notification_permission_callback_;
1006   WebViewCallback<Ewk_Quota_Permission_Request_Callback,
1007                   const _Ewk_Quota_Permission_Request*>
1008       quota_request_callback_;
1009   WebViewCallback<Ewk_View_Authentication_Callback, _Ewk_Auth_Challenge*>
1010       authentication_cb_;
1011   WebViewCallback<Ewk_View_Scale_Changed_Callback, double> scale_changed_cb_;
1012
1013   std::unique_ptr<content::InputPicker> input_picker_;
1014
1015   DidChangeThemeColorCallback did_change_theme_color_callback_;
1016
1017   base::IDMap<WebApplicationIconUrlGetCallback*>
1018       web_app_icon_url_get_callback_map_;
1019   base::IDMap<WebApplicationIconUrlsGetCallback*>
1020       web_app_icon_urls_get_callback_map_;
1021   base::IDMap<WebApplicationCapableGetCallback*>
1022       web_app_capable_get_callback_map_;
1023   std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
1024   std::unique_ptr<ScrollDetector> scroll_detector_;
1025
1026   // Manages injecting native objects.
1027   std::unique_ptr<content::GinNativeBridgeDispatcherHost>
1028       gin_native_bridge_dispatcher_host_;
1029
1030   WebViewExceededQuotaCallback<
1031       Ewk_View_Exceeded_Indexed_Database_Quota_Callback,
1032       Ewk_Security_Origin*,
1033       long long>
1034       exceeded_indexed_db_quota_callback_;
1035   std::unique_ptr<Ewk_Security_Origin> exceeded_indexed_db_quota_origin_;
1036 #if !defined(EWK_BRINGUP)  // FIXME: m114 bringup
1037   std::map<const _Ewk_Quota_Permission_Request*,
1038            content::QuotaPermissionContext::PermissionCallback>
1039       quota_permission_request_map_;
1040 #endif
1041 #if BUILDFLAG(IS_TIZEN)
1042   blink::mojom::FileChooserParams::Mode filechooser_mode_ =
1043       blink::mojom::FileChooserParams::Mode::kOpen;
1044   Ecore_Event_Handler* window_rotate_handler_ = nullptr;
1045 #endif
1046
1047   bool is_initialized_;
1048
1049 #if BUILDFLAG(IS_TIZEN_TV)
1050   bool is_processing_edge_scroll_;
1051   bool use_early_rwi_;
1052   bool rwi_info_showed_;
1053   GURL rwi_gurl_;
1054   bool is_high_bitrate_ = false;
1055   bool context_menu_show_;
1056   base::OneShotTimer mouse_long_press_timer_;
1057   base::OnceClosure pending_setfocus_closure_;
1058
1059   enum PlaybackState {
1060     kPlaybackLoad = 0,
1061     // kPlaybackReady: player with both audio and video starts prepare and will
1062     // acquire audio and video resources (if they are not already taken)
1063     kPlaybackReady,
1064     kPlaybackStart,
1065     kPlaybackFinish,
1066     kPlaybackStop,
1067   };
1068   double current_time_ = 0.0;
1069 #endif
1070
1071   std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
1072
1073   static content::WebViewDelegate::WebContentsCreateCallback
1074       create_new_window_web_contents_cb_;
1075
1076 #if defined(TIZEN_VIDEO_HOLE)
1077   void EnableVideoHoleSupportInternal();
1078 #endif
1079   gfx::Vector2d previous_scroll_position_;
1080
1081   gfx::Point context_menu_position_;
1082
1083   content::ContextMenuParams saved_context_menu_params_;
1084
1085   std::vector<IPC::Message*> delayed_messages_;
1086
1087   std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
1088
1089   content::AcceptLanguagesHelper::AcceptLangsChangedCallback
1090       accept_langs_changed_callback_;
1091
1092   std::unique_ptr<SelectPickerBase> select_picker_;
1093   std::unique_ptr<aura::WindowTreeHost> host_;
1094   std::unique_ptr<aura::client::FocusClient> focus_client_;
1095   std::unique_ptr<aura::client::WindowParentingClient> window_parenting_client_;
1096   std::unique_ptr<ui::CompositorObserver> compositor_observer_;
1097
1098 #if defined(TIZEN_ATK_SUPPORT)
1099   std::unique_ptr<EWebAccessibility> eweb_accessibility_;
1100   bool lazy_initialize_atk_ = false;
1101 #endif
1102 #if defined(TIZEN_PEPPER_EXTENSIONS)
1103   content::ExtensionSystemDelegateManager::RenderFrameID render_frame_id_;
1104 #endif
1105 #if defined(TIZEN_VIDEO_HOLE)
1106   bool pending_video_hole_setting_ = false;
1107 #endif
1108
1109   Ecore_Timer* delayed_show_context_menu_timer_ = nullptr;
1110   base::WeakPtrFactory<EWebView> weak_factory_{this};
1111 };
1112
1113 const unsigned int g_default_tilt_motion_sensitivity = 3;
1114
1115 #endif