0d50a4db82d70d36840f4eb8334068baa420a4c6
[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 #endif // IS_TIZEN_TV
407   void SetSessionTimeout(uint64_t timeout);
408   double GetTextZoomFactor() const;
409   void SetTextZoomFactor(double text_zoom_factor);
410   double GetPageZoomFactor() const;
411   void SetPageZoomFactor(double page_zoom_factor);
412   void ExecuteEditCommand(const char* command, const char* value);
413 #if BUILDFLAG(IS_TIZEN)
414   void EnterDragState();
415 #endif
416   void SetOrientation(int orientation);
417   int GetOrientation();
418   bool TouchEventsEnabled() const;
419   void SetTouchEventsEnabled(bool enabled);
420   bool MouseEventsEnabled() const;
421   void SetMouseEventsEnabled(bool enabled);
422   void SendKeyEvent(Evas_Object* ewk_view, void* key_event, bool is_press);
423   bool SetKeyEventsEnabled(bool enabled);
424   void HandleTouchEvents(Ewk_Touch_Event_Type type,
425                          const Eina_List* points,
426                          const Evas_Modifier* modifiers);
427   void Show();
428   void Hide();
429   bool ExecuteJavaScript(const char* script,
430                          Ewk_View_Script_Execute_Callback callback,
431                          void* userdata);
432   bool SetUserAgent(const char* userAgent);
433   bool SetUserAgentAppName(const char* application_name);
434 #if BUILDFLAG(IS_TIZEN)
435   bool SetPrivateBrowsing(bool incognito);
436   bool GetPrivateBrowsing() const;
437 #endif
438   const char* GetUserAgent() const;
439   const char* GetUserAgentAppName() const;
440   const char* CacheSelectedText();
441   Ewk_Settings* GetSettings() { return settings_.get(); }
442   _Ewk_Frame* GetMainFrame();
443   void UpdateWebKitPreferences();
444   void LoadHTMLString(const char* html,
445                       const char* base_uri,
446                       const char* unreachable_uri);
447   void LoadPlainTextString(const char* plain_text);
448
449   void LoadHTMLStringOverridingCurrentEntry(const char* html,
450                                             const char* base_uri,
451                                             const char* unreachable_url);
452   void LoadData(const char* data,
453                 size_t size,
454                 const char* mime_type,
455                 const char* encoding,
456                 const char* base_uri,
457                 const char* unreachable_uri = NULL,
458                 bool should_replace_current_entry = false);
459   void InvokeLoadError(const GURL& url, int error_code, bool is_cancellation);
460
461   void SetViewAuthCallback(Ewk_View_Authentication_Callback callback,
462                            void* user_data);
463   void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
464                           const GURL& url,
465                           const std::string& realm);
466   void Find(const char* text, Ewk_Find_Options);
467   void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
468   void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
469   void HandlePopupMenu(std::vector<blink::mojom::MenuItemPtr> items,
470                        int selectedIndex,
471                        bool multiple,
472                        const gfx::Rect& bounds);
473   void HidePopupMenu();
474   void DidSelectPopupMenuItems(std::vector<int>& indices);
475   void DidCancelPopupMenu();
476   void HandleLongPressGesture(const content::ContextMenuParams&);
477   void ShowContextMenu(const content::ContextMenuParams&);
478   void CancelContextMenu(int request_id);
479   void SetScale(double scale_factor);
480   void SetScaleChangedCallback(Ewk_View_Scale_Changed_Callback callback,
481                                void* user_data);
482
483   bool GetScrollPosition(int* x, int* y) const;
484   void SetScroll(int x, int y);
485   void UrlRequestSet(const char* url,
486                      content::NavigationController::LoadURLType loadtype,
487                      Eina_Hash* headers,
488                      const char* body);
489
490   SelectPickerBase* GetSelectPicker() const { return select_picker_.get(); }
491   content::SelectionControllerEfl* GetSelectionController() const;
492   content::PopupControllerEfl* GetPopupController() const {
493     return popup_controller_.get();
494   }
495   ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
496   void MoveCaret(const gfx::Point& point);
497   void SelectFocusedLink();
498   bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
499   Eina_Bool ClearSelection();
500
501   // Callback OnCopyFromBackingStore will be called once we get the snapshot
502   // from render
503   void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
504
505   void OnFocusIn();
506   void OnFocusOut();
507
508   void UpdateContextMenu(bool is_password_input);
509   void RenderViewReady();
510
511   /**
512    * Creates a snapshot of given rectangle from EWebView
513    *
514    * @param rect rectangle of EWebView which will be taken into snapshot
515    * @param scale_factor scale factor
516    * @return created snapshot or NULL if error occured.
517    * @note ownership of snapshot is passed to caller
518    */
519   Evas_Object* GetSnapshot(Eina_Rectangle rect, float scale_factor);
520
521   bool GetSnapshotAsync(Eina_Rectangle rect,
522                         Ewk_Web_App_Screenshot_Captured_Callback callback,
523                         void* user_data,
524                         float scale_factor);
525   void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision,
526                                     bool* defer);
527   void InvokePolicyNavigationCallback(const NavigationPolicyParams& params,
528                                       bool* handled);
529   void UseSettingsFont();
530
531   _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
532   Eina_Bool AsyncRequestHitTestDataAt(int x,
533                                       int y,
534                                       Ewk_Hit_Test_Mode mode,
535                                       Ewk_View_Hit_Test_Request_Callback,
536                                       void* user_data);
537   _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
538                                                  int y,
539                                                  Ewk_Hit_Test_Mode mode);
540   Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
541       int x,
542       int y,
543       Ewk_Hit_Test_Mode mode,
544       Ewk_View_Hit_Test_Request_Callback,
545       void* user_data);
546   void DispatchAsyncHitTestData(const Hit_Test_Params& params,
547                                 int64_t request_id);
548   void UpdateHitTestData(const Hit_Test_Params& params);
549
550   int current_find_request_id() const { return current_find_request_id_; }
551   bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
552   void InvokePlainTextGetCallback(const std::string& content_text,
553                                   int plain_text_get_callback_id);
554   int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
555                                      void* user_data);
556   void SetViewGeolocationPermissionCallback(
557       Ewk_View_Geolocation_Permission_Callback callback,
558       void* user_data);
559   bool InvokeViewGeolocationPermissionCallback(
560       _Ewk_Geolocation_Permission_Request*
561           geolocation_permission_request_context,
562       Eina_Bool* result);
563   void SetViewUserMediaPermissionCallback(
564       Ewk_View_User_Media_Permission_Callback callback,
565       void* user_data);
566   bool InvokeViewUserMediaPermissionCallback(
567       _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
568       Eina_Bool* result);
569   void SetViewUserMediaPermissionQueryCallback(
570       Ewk_View_User_Media_Permission_Query_Callback callback,
571       void* user_data);
572   Ewk_User_Media_Permission_Query_Result
573   InvokeViewUserMediaPermissionQueryCallback(
574       _Ewk_User_Media_Permission_Query* user_media_permission_query_context);
575
576   void SetViewLoadErrorPageCallback(Ewk_View_Error_Page_Load_Callback callback,
577                                     void* user_data);
578   const char* InvokeViewLoadErrorPageCallback(const GURL& url,
579                                               int error_code,
580                                               bool is_cancellation);
581   bool IsLoadErrorPageCallbackSet() const;
582   void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
583                                    void* user_data);
584   bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
585                                       Eina_Bool* result);
586   void DidChangeContentsSize(int width, int height);
587   const Eina_Rectangle GetContentsSize() const;
588   void GetScrollSize(int* w, int* h);
589   void StopFinding();
590   void SetProgressValue(double progress);
591   double GetProgressValue();
592   const char* GetTitle();
593   bool SaveAsPdf(int width, int height, const std::string& file_name);
594   void BackForwardListClear();
595   _Ewk_Back_Forward_List* GetBackForwardList() const;
596   void InvokeBackForwardListChangedCallback();
597   _Ewk_History* GetBackForwardHistory() const;
598   bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
599                         void* userData);
600   bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
601                         void* userData);
602   bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
603                          void* userData);
604   void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
605   void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
606                                       int callbackId);
607   void InvokeWebAppIconUrlsGetCallback(
608       const std::map<std::string, std::string>& iconUrls,
609       int callbackId);
610   void SetNotificationPermissionCallback(
611       Ewk_View_Notification_Permission_Callback callback,
612       void* user_data);
613   bool IsNotificationPermissionCallbackSet() const;
614   bool InvokeNotificationPermissionCallback(
615       Ewk_Notification_Permission_Request* request);
616
617   bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
618   void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
619   bool SavePageAsMHTML(const std::string& path,
620                        Ewk_View_Save_Page_Callback callback,
621                        void* user_data);
622   bool IsFullscreen();
623   void ExitFullscreen();
624   double GetScale();
625   void DidChangePageScaleFactor(double scale_factor);
626   void SetScaledContentsSize();
627   void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
628                                   void* user_data);
629   void JavaScriptAlertReply();
630   void SetJavaScriptConfirmCallback(
631       Ewk_View_JavaScript_Confirm_Callback callback,
632       void* user_data);
633   void JavaScriptConfirmReply(bool result);
634   void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
635                                    void* user_data);
636   void JavaScriptPromptReply(const char* result);
637   void set_renderer_crashed();
638   void GetPageScaleRange(double* min_scale, double* max_scale);
639   bool SetDrawsTransparentBackground(bool enabled);
640   bool GetDrawsTransparentBackground();
641   bool SetBackgroundColor(int red, int green, int blue, int alpha);
642   bool GetBackgroundColor(Ewk_View_Background_Color_Get_Callback callback,
643                           void* user_data);
644   void OnGetBackgroundColor(int callback_id, SkColor bg_color);
645
646   void GetSessionData(const char** data, unsigned* length) const;
647   bool RestoreFromSessionData(const char* data, unsigned length);
648   void ShowFileChooser(scoped_refptr<content::FileSelectListener> listener,
649                        const blink::mojom::FileChooserParams&);
650   void SetBrowserFont();
651   bool IsDragging() const;
652
653   void RequestColorPicker(int r, int g, int b, int a);
654   bool SetColorPickerColor(int r, int g, int b, int a);
655   void InputPickerShow(ui::TextInputType input_type,
656                        double input_value,
657                        content::DateTimeChooserEfl* date_time_chooser);
658
659   void ShowContentsDetectedPopup(const char*);
660
661   // Returns TCP port number with Inspector, or 0 if error.
662   int StartInspectorServer(int port = 0);
663   bool StopInspectorServer();
664
665   void LoadNotFoundErrorPage(const std::string& invalidUrl);
666   static std::string GetPlatformLocale();
667   bool GetLinkMagnifierEnabled() const;
668   void SetLinkMagnifierEnabled(bool enabled);
669
670   bool GetHorizontalPanningHold() const;
671   void SetHorizontalPanningHold(bool hold);
672   bool GetVerticalPanningHold() const;
673   void SetVerticalPanningHold(bool hold);
674
675   bool GetRotationChanged() { return rotation_changed_; }
676   void SetRotationChanged(bool change) { rotation_changed_ = change; }
677
678   void SetQuotaPermissionRequestCallback(
679       Ewk_Quota_Permission_Request_Callback callback,
680       void* user_data);
681 #if !defined(EWK_BRINGUP)  // FIXME: m114 bringup
682   void InvokeQuotaPermissionRequest(
683       _Ewk_Quota_Permission_Request* request,
684       content::QuotaPermissionContext::PermissionCallback cb);
685   void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
686                          bool allow);
687   void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
688   void SetViewMode(blink::WebViewMode view_mode);
689 #endif
690   gfx::Point GetContextMenuPosition() const;
691
692   content::ContextMenuControllerEfl* GetContextMenuController() {
693     return context_menu_.get();
694   }
695
696   bool SetMainFrameScrollbarVisible(bool visible);
697   bool GetMainFrameScrollbarVisible(
698       Ewk_View_Main_Frame_Scrollbar_Visible_Get_Callback callback,
699       void* user_data);
700   void InvokeMainFrameScrollbarVisibleCallback(int callback_id, bool visible);
701
702   void ResetContextMenuController();
703   Eina_Bool AddJavaScriptMessageHandler(Evas_Object* view,
704                                         Ewk_View_Script_Message_Cb callback,
705                                         std::string name);
706
707   content::GinNativeBridgeDispatcherHost* GetGinNativeBridgeDispatcherHost()
708       const {
709     return gin_native_bridge_dispatcher_host_.get();
710   }
711   bool SetPageVisibility(Ewk_Page_Visibility_State page_visibility_state);
712
713   void SetExceededIndexedDatabaseQuotaCallback(
714       Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback,
715       void* user_data);
716   void InvokeExceededIndexedDatabaseQuotaCallback(const GURL& origin,
717                                                   int64_t current_quota);
718   void ExceededIndexedDatabaseQuotaReply(bool allow);
719
720 #if defined(TIZEN_VIDEO_HOLE)
721   void EnableVideoHoleSupport();
722 #endif
723
724 #if defined(TIZEN_TBM_SUPPORT)
725   void SetOffscreenRendering(bool enable);
726 #endif
727
728   /// ---- Event handling
729   bool HandleShow();
730   bool HandleHide();
731   bool HandleMove(int x, int y);
732   bool HandleResize(int width, int height);
733   bool HandleTextSelectionDown(int x, int y);
734   bool HandleTextSelectionUp(int x, int y);
735
736   void HandleRendererProcessCrash();
737   void InvokeWebProcessCrashedCallback();
738
739   void HandleTapGestureForSelection(bool is_content_editable);
740   void HandleZoomGesture(blink::WebGestureEvent& event);
741   void ClosePage();
742
743   void RequestManifest(Ewk_View_Request_Manifest_Callback callback,
744                        void* user_data);
745   void DidRespondRequestManifest(_Ewk_View_Request_Manifest* manifest,
746                                  Ewk_View_Request_Manifest_Callback callback,
747                                  void* user_data);
748
749   void SetBeforeUnloadConfirmPanelCallback(
750       Ewk_View_Before_Unload_Confirm_Panel_Callback callback,
751       void* user_data);
752   void ReplyBeforeUnloadConfirmPanel(Eina_Bool result);
753   void SyncAcceptLanguages(const std::string& accept_languages);
754
755 #if BUILDFLAG(IS_TIZEN_TV)
756   //Browser edge scroll
757   bool EdgeScrollBy(int delta_x, int delta_y);
758   void GetMousePosition(gfx::Point&);
759   void InvokeEdgeScrollByCallback(const gfx::Point&, bool);
760   // notify web browser video playing status
761   bool IsVideoPlaying(Ewk_Is_Video_Playing_Callback callback, void* user_data);
762   void InvokeIsVideoPlayingCallback(bool is_playing, int callback_id);
763   void InvokeScrollbarThumbFocusChangedCallback(
764       Ewk_Scrollbar_Orientation orientation,
765       bool focused);
766 #endif
767
768   void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
769                       const gfx::Vector2dF& latest_overscroll_delta);
770
771   bool SetVisibility(bool enable);
772   void SetDoNotTrack(Eina_Bool);
773
774 #if defined(TIZEN_ATK_SUPPORT)
775   void UpdateSpatialNavigationStatus(Eina_Bool enable);
776   void UpdateAccessibilityStatus(Eina_Bool enable);
777
778   bool CheckLazyInitializeAtk() {
779     return is_initialized_ && lazy_initialize_atk_;
780   }
781   void InitAtk();
782   bool GetAtkStatus();
783 #endif
784 #if defined(TIZEN_PEPPER_EXTENSIONS)
785   void InitializePepperExtensionSystem();
786   EwkExtensionSystemDelegate* GetExtensionDelegate();
787   void SetWindowId();
788   void SetPepperExtensionWidgetInfo(Ewk_Value widget_pepper_ext_info);
789   void SetPepperExtensionCallback(Generic_Sync_Call_Callback cb, void* data);
790   void RegisterPepperExtensionDelegate();
791   void UnregisterPepperExtensionDelegate();
792 #endif
793
794   bool ShouldIgnoreNavigation(content::NavigationHandle* navigation_handle);
795
796 #if BUILDFLAG(IS_TIZEN_TV)
797   void DrawLabel(Evas_Object* image, Eina_Rectangle rect);
798   void DeactivateAtk(bool deactivated);
799   void ClearLabels();
800   void AddDynamicCertificatePath(const std::string& host,
801                                  const std::string& cert_path);
802
803   bool SetMixedContents(bool allow);
804   void ClearAllTilesResources();
805   bool UseEarlyRWI() { return use_early_rwi_; }
806   bool RWIInfoShowed() { return rwi_info_showed_; }
807   GURL RWIURL() { return rwi_gurl_; }
808   void OnDialogClosed();
809   void NotifyMediaStateChanged(uint32_t type,
810                                uint32_t previous,
811                                uint32_t current);
812   void SetHighBitRate(Eina_Bool is_high_bitrate);
813   bool IsHighBitRate() const { return is_high_bitrate_; }
814   void NotifyFirstTimeStamp(unsigned long long timestamp,
815                             int time_base_num,
816                             int time_base_den);
817   void NotifyPESData(const std::string& buf,
818                      unsigned int len,
819                      int media_position);
820   void SetPreferSubtitleLang(const char* lang_list);
821   void NotifySubtitleState(int state, double time_stamp);
822   void NotifySubtitlePlay(int active_track_id,
823                           const char* url,
824                           const char* lang);
825   void NotifySubtitleData(int track_id,
826                           double time_stamp,
827                           const std::string& data,
828                           unsigned int size);
829   void UpdateCurrentTime(double current_time);
830   void UpdateEventData(void* data);
831   double GetCurrentTime() { return current_time_; }
832   void GetMediaDeviceList(Ewk_Media_Device_List_Get_Callback callback,
833                           void* userData);
834   using MediaDeviceEnumeration =
835       std::array<blink::WebMediaDeviceInfoArray, NUM_MEDIA_DEVICE_TYPES>;
836   void OnDeviceListed(const MediaDeviceEnumeration& devices);
837   void SetTranslatedURL(const char* url);
838   void NotifyParentalRatingInfo(const char* info, const char* url);
839   void SetParentalRatingResult(const char* info, bool is_pass);
840   void OnMouseLongPressed(int x, int y);
841   void OnMouseDown(int x, int y);
842   bool OnMouseUp();
843   void OnMouseMove();
844 #endif  // IS_TIZEN_TV
845
846   void SetDidChangeThemeColorCallback(
847       Ewk_View_Did_Change_Theme_Color_Callback callback,
848       void* user_data);
849   void DidChangeThemeColor(const SkColor& color);
850
851   void OnSelectionRectReceived(const gfx::Rect& selection_rect) const;
852
853  private:
854   static void NativeViewResize(void* data,
855                                Evas* e,
856                                Evas_Object* obj,
857                                void* event_info);
858   void InitializeContent();
859   void InitializeWindowTreeHost();
860   void SendDelayedMessages(content::RenderViewHost* render_view_host);
861
862   void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
863   Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
864       int x,
865       int y,
866       Ewk_Hit_Test_Mode mode,
867       WebViewAsyncRequestHitTestDataCallback* cb);
868
869 #if BUILDFLAG(IS_TIZEN_TV)
870   void InitInspectorServer();
871
872   void RunPendingSetFocus(Eina_Bool focus);
873   void SetFocusInternal(Eina_Bool focus);
874 #endif
875
876   JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
877
878   // Changes viewport without resizing Evas_Object representing webview
879   // and its corresponding RWHV to let Blink renders custom viewport
880   // while showing picker.
881   void AdjustViewPortHeightToPopupMenu(bool is_popup_menu_visible);
882
883   void ShowContextMenuInternal(const content::ContextMenuParams&);
884
885   void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
886
887   void ChangeScroll(int& x, int& y);
888   void ScrollFocusedNodeIntoView();
889
890   void GenerateMHTML(Ewk_View_Save_Page_Callback callback,
891                      void* user_data,
892                      const base::FilePath& file_path);
893   void MHTMLGenerated(Ewk_View_Save_Page_Callback callback,
894                       void* user_data,
895                       const base::FilePath& file_path,
896                       int64_t file_size);
897
898   static void VisibleContentChangedCallback(void* user_data,
899                                             Evas_Object* object,
900                                             void* event_info);
901
902   static void OnCustomScrollBeginCallback(void* user_data,
903                                           Evas_Object* object,
904                                           void* event_info);
905
906   static void OnCustomScrollEndCallback(void* user_data,
907                                         Evas_Object* object,
908                                         void* event_info);
909   void UpdateContextMenuWithParams(const content::ContextMenuParams& params);
910
911   static Eina_Bool DelayedPopulateAndShowContextMenu(void* data);
912
913   scoped_refptr<Ewk_Context> context_;
914   std::unique_ptr<content::WebContents> web_contents_;
915   std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
916   std::unique_ptr<content::WebViewDelegate> webview_delegate_;
917   std::string pending_url_request_;
918   std::unique_ptr<Ewk_Settings> settings_;
919   std::unique_ptr<_Ewk_Frame> frame_;
920   std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
921   Evas_Object* ewk_view_;
922   Evas_Object* efl_main_layout_;
923   bool key_events_enabled_ = true;
924   bool rotation_changed_ = false;
925   bool mouse_events_enabled_;
926   double text_zoom_factor_;
927   mutable std::string user_agent_;
928   mutable std::string user_agent_app_name_;
929   std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
930   std::string selected_text_cached_;
931
932   std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
933 #if BUILDFLAG(IS_TIZEN_TV)
934   std::unique_ptr<_Ewk_File_Chooser_Request> file_chooser_request_;
935 #else
936   std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
937 #endif
938   std::unique_ptr<content::PopupControllerEfl> popup_controller_;
939   std::u16string previous_text_;
940   int current_find_request_id_;
941   static int find_request_id_counter_;
942
943   typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
944       EwkViewPlainTextGetCallback;
945   base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
946
947   typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
948       MHTMLCallbackDetails;
949   base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
950
951 #if BUILDFLAG(IS_TIZEN_TV)
952   base::IDMap<IsVideoPlayingCallback*> is_video_playing_callback_map_;
953 #endif
954
955   typedef WebViewCallback<Ewk_View_Main_Frame_Scrollbar_Visible_Get_Callback,
956                           bool>
957       MainFrameScrollbarVisibleGetCallback;
958   base::IDMap<MainFrameScrollbarVisibleGetCallback*>
959       main_frame_scrollbar_visible_callback_map_;
960
961   base::IDMap<BackgroundColorGetCallback*> background_color_get_callback_map_;
962
963 #if BUILDFLAG(IS_TIZEN_TV)
964   GetMediaDeviceCallback device_cb_;
965 #endif
966
967   gfx::Size contents_size_;
968   double progress_;
969   mutable std::string title_;
970   Hit_Test_Params hit_test_params_;
971   base::WaitableEvent hit_test_completion_;
972   double page_scale_factor_;
973   double x_delta_;
974   double y_delta_;
975
976   WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
977                   _Ewk_Geolocation_Permission_Request*>
978       geolocation_permission_cb_;
979   WebViewCallback<Ewk_View_User_Media_Permission_Callback,
980                   _Ewk_User_Media_Permission_Request*>
981       user_media_permission_cb_;
982   WebViewCallbackWithReturnValue<Ewk_User_Media_Permission_Query_Result,
983                                  Ewk_View_User_Media_Permission_Query_Callback,
984                                  _Ewk_User_Media_Permission_Query*>
985       user_media_permission_query_cb_;
986   WebViewErrorPageLoadCallback<Ewk_View_Error_Page_Load_Callback,
987                                Ewk_Error*,
988                                Ewk_Error_Page*>
989       load_error_page_cb_;
990   WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
991       unfocus_allow_cb_;
992   WebViewCallback<Ewk_View_Notification_Permission_Callback,
993                   Ewk_Notification_Permission_Request*>
994       notification_permission_callback_;
995   WebViewCallback<Ewk_Quota_Permission_Request_Callback,
996                   const _Ewk_Quota_Permission_Request*>
997       quota_request_callback_;
998   WebViewCallback<Ewk_View_Authentication_Callback, _Ewk_Auth_Challenge*>
999       authentication_cb_;
1000   WebViewCallback<Ewk_View_Scale_Changed_Callback, double> scale_changed_cb_;
1001
1002   std::unique_ptr<content::InputPicker> input_picker_;
1003
1004   DidChangeThemeColorCallback did_change_theme_color_callback_;
1005
1006   base::IDMap<WebApplicationIconUrlGetCallback*>
1007       web_app_icon_url_get_callback_map_;
1008   base::IDMap<WebApplicationIconUrlsGetCallback*>
1009       web_app_icon_urls_get_callback_map_;
1010   base::IDMap<WebApplicationCapableGetCallback*>
1011       web_app_capable_get_callback_map_;
1012   std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
1013   std::unique_ptr<ScrollDetector> scroll_detector_;
1014
1015   // Manages injecting native objects.
1016   std::unique_ptr<content::GinNativeBridgeDispatcherHost>
1017       gin_native_bridge_dispatcher_host_;
1018
1019   WebViewExceededQuotaCallback<
1020       Ewk_View_Exceeded_Indexed_Database_Quota_Callback,
1021       Ewk_Security_Origin*,
1022       long long>
1023       exceeded_indexed_db_quota_callback_;
1024   std::unique_ptr<Ewk_Security_Origin> exceeded_indexed_db_quota_origin_;
1025 #if !defined(EWK_BRINGUP)  // FIXME: m114 bringup
1026   std::map<const _Ewk_Quota_Permission_Request*,
1027            content::QuotaPermissionContext::PermissionCallback>
1028       quota_permission_request_map_;
1029 #endif
1030 #if BUILDFLAG(IS_TIZEN)
1031   blink::mojom::FileChooserParams::Mode filechooser_mode_ =
1032       blink::mojom::FileChooserParams::Mode::kOpen;
1033   Ecore_Event_Handler* window_rotate_handler_ = nullptr;
1034 #endif
1035
1036   bool is_initialized_;
1037
1038 #if BUILDFLAG(IS_TIZEN_TV)
1039   bool is_processing_edge_scroll_;
1040   bool use_early_rwi_;
1041   bool rwi_info_showed_;
1042   GURL rwi_gurl_;
1043   bool is_high_bitrate_ = false;
1044   bool context_menu_show_;
1045   base::OneShotTimer mouse_long_press_timer_;
1046   base::OnceClosure pending_setfocus_closure_;
1047
1048   enum PlaybackState {
1049     kPlaybackLoad = 0,
1050     // kPlaybackReady: player with both audio and video starts prepare and will
1051     // acquire audio and video resources (if they are not already taken)
1052     kPlaybackReady,
1053     kPlaybackStart,
1054     kPlaybackFinish,
1055     kPlaybackStop,
1056   };
1057   double current_time_ = 0.0;
1058 #endif
1059
1060   std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
1061
1062   static content::WebViewDelegate::WebContentsCreateCallback
1063       create_new_window_web_contents_cb_;
1064
1065 #if defined(TIZEN_VIDEO_HOLE)
1066   void EnableVideoHoleSupportInternal();
1067 #endif
1068   gfx::Vector2d previous_scroll_position_;
1069
1070   gfx::Point context_menu_position_;
1071
1072   content::ContextMenuParams saved_context_menu_params_;
1073
1074   std::vector<IPC::Message*> delayed_messages_;
1075
1076   std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
1077
1078   content::AcceptLanguagesHelper::AcceptLangsChangedCallback
1079       accept_langs_changed_callback_;
1080
1081   std::unique_ptr<SelectPickerBase> select_picker_;
1082   std::unique_ptr<aura::WindowTreeHost> host_;
1083   std::unique_ptr<aura::client::FocusClient> focus_client_;
1084   std::unique_ptr<aura::client::WindowParentingClient> window_parenting_client_;
1085   std::unique_ptr<ui::CompositorObserver> compositor_observer_;
1086
1087 #if defined(TIZEN_ATK_SUPPORT)
1088   std::unique_ptr<EWebAccessibility> eweb_accessibility_;
1089   bool lazy_initialize_atk_ = false;
1090 #endif
1091 #if defined(TIZEN_PEPPER_EXTENSIONS)
1092   content::ExtensionSystemDelegateManager::RenderFrameID render_frame_id_;
1093 #endif
1094 #if defined(TIZEN_VIDEO_HOLE)
1095   bool pending_video_hole_setting_ = false;
1096 #endif
1097
1098   Ecore_Timer* delayed_show_context_menu_timer_ = nullptr;
1099   base::WeakPtrFactory<EWebView> weak_factory_{this};
1100 };
1101
1102 const unsigned int g_default_tilt_motion_sensitivity = 3;
1103
1104 #endif