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