[M108 Migration] Segregate InputPicker into ewk independent base classes
[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/callback.h"
15 #include "base/containers/id_map.h"
16 #include "base/synchronization/waitable_event.h"
17 #include "browser/input_picker/input_picker.h"
18 #include "content/browser/renderer_host/event_with_latency_info.h"
19 #include "content/browser/select_picker/select_picker_base.h"
20 #include "content/browser/selection/selection_controller_efl.h"
21 #include "content/browser/web_contents/web_contents_view_aura.h"
22 #include "content/browser/web_contents/web_contents_view_aura_helper_efl.h"
23 #include "content/public/browser/context_menu_params.h"
24 #include "content/public/browser/navigation_controller.h"
25 #include "content/public/browser/quota_permission_context.h"
26 #include "content/public/browser/web_contents_delegate.h"
27 #include "content/public/browser/web_contents_efl_delegate.h"
28 #include "content/public/common/input_event_ack_state.h"
29 #include "content_browser_client_efl.h"
30 #include "context_menu_controller_efl.h"
31 #include "eweb_context.h"
32 #include "eweb_view_callbacks.h"
33 #include "file_chooser_controller_efl.h"
34 #include "permission_popup_manager.h"
35 #include "popup_controller_efl.h"
36 #include "private/ewk_auth_challenge_private.h"
37 #include "private/ewk_back_forward_list_private.h"
38 #include "private/ewk_history_private.h"
39 #include "private/ewk_hit_test_private.h"
40 #include "private/ewk_settings_private.h"
41 #include "private/ewk_web_application_icon_data_private.h"
42 #include "public/ewk_hit_test_internal.h"
43 #include "public/ewk_touch_internal.h"
44 #include "public/ewk_view_product.h"
45 #include "scroll_detector.h"
46 #include "third_party/blink/public/common/context_menu_data/menu_item_info.h"
47 #include "third_party/blink/public/mojom/choosers/file_chooser.mojom.h"
48 #include "third_party/blink/public/mojom/choosers/popup_menu.mojom.h"
49 #include "ui/aura/window_tree_host.h"
50 #include "ui/gfx/geometry/point.h"
51 #include "ui/gfx/geometry/size.h"
52 #include "web_contents_delegate_efl.h"
53
54 namespace aura {
55 namespace client {
56 class FocusClient;
57 class WindowParentingClient;
58 }  // namespace client
59 }  // namespace aura
60
61 namespace base {
62 class FilePath;
63 }
64
65 namespace content {
66 class RenderFrameHost;
67 class RenderViewHost;
68 class RenderWidgetHostViewAura;
69 class WebContentsDelegateEfl;
70 class WebContentsViewAura;
71 class ContextMenuControllerEfl;
72 class PopupControllerEfl;
73 class DateTimeChooserEfl;
74 class InputPicker;
75 class GinNativeBridgeDispatcherHost;
76 class NavigationHandle;
77 }
78
79 class ErrorParams;
80 class _Ewk_App_Control;
81 class _Ewk_Policy_Decision;
82 class _Ewk_Hit_Test;
83 class Ewk_Context;
84 class WebViewEvasEventHandler;
85 class _Ewk_Quota_Permission_Request;
86
87 #if defined(TIZEN_ATK_SUPPORT)
88 class EWebAccessibility;
89 #endif
90
91 template <typename CallbackPtr, typename CallbackParameter>
92 class WebViewCallback {
93  public:
94   WebViewCallback() { Set(nullptr, nullptr); }
95
96   void Set(CallbackPtr cb, void* data) {
97     callback_ = cb;
98     user_data_ = data;
99   }
100
101   bool IsCallbackSet() const { return callback_; }
102
103   Eina_Bool Run(Evas_Object* webview,
104                 CallbackParameter param,
105                 Eina_Bool* callback_result) {
106     CHECK(callback_result);
107     if (IsCallbackSet()) {
108       *callback_result = callback_(webview, param, user_data_);
109       return true;
110     }
111     return false;
112   }
113
114   void Run(Evas_Object* webview, CallbackParameter param) {
115     if (IsCallbackSet())
116       callback_(webview, param, user_data_);
117   }
118
119  private:
120   CallbackPtr callback_;
121   void* user_data_;
122 };
123
124 template <typename CallbackReturnValue,
125           typename CallbackPtr,
126           typename CallbackParameter>
127 class WebViewCallbackWithReturnValue {
128  public:
129   WebViewCallbackWithReturnValue() { Set(nullptr, nullptr); }
130
131   void Set(CallbackPtr cb, void* data) {
132     callback_ = cb;
133     user_data_ = data;
134   }
135
136   /* LCOV_EXCL_START */
137   bool IsCallbackSet() const { return callback_; }
138
139   CallbackReturnValue Run(Evas_Object* webview, CallbackParameter param) {
140     if (IsCallbackSet())
141       return callback_(webview, param, user_data_);
142
143     return {};
144   }
145   /* LCOV_EXCL_STOP */
146
147  private:
148   CallbackPtr callback_;
149   void* user_data_;
150 };
151
152 template <typename CallbackPtr, typename... CallbackParameter>
153 class WebViewErrorPageLoadCallback {
154  public:
155   WebViewErrorPageLoadCallback() { Set(nullptr, nullptr); }
156
157   void Set(CallbackPtr cb, void* data) {
158     callback_ = cb;
159     user_data_ = data;
160   }
161
162   bool IsCallbackSet() const { return callback_; }
163
164   void Run(Evas_Object* webview, CallbackParameter... param) {
165     if (IsCallbackSet())
166       callback_(webview, param..., user_data_);
167   }
168
169  private:
170   CallbackPtr callback_;
171   void* user_data_;
172 };
173
174 template <typename CallbackPtr, typename... CallbackParameter>
175 class WebViewExceededQuotaCallback {
176  public:
177   WebViewExceededQuotaCallback() { Set(nullptr, nullptr); }
178
179   void Set(CallbackPtr cb, void* data) {
180     callback_ = cb;
181     user_data_ = data;
182   }
183
184   bool IsCallbackSet() const { return callback_; }
185
186   /* LCOV_EXCL_START */
187   void Run(Evas_Object* webview, CallbackParameter... param) {
188     if (IsCallbackSet())
189       callback_(webview, param..., user_data_);
190   }
191   /* LCOV_EXCL_STOP */
192
193  private:
194   CallbackPtr callback_;
195   void* user_data_;
196 };
197
198 class BackgroundColorGetCallback {
199  public:
200   BackgroundColorGetCallback(Ewk_View_Background_Color_Get_Callback func,
201                              void* user_data)
202       : func_(func), user_data_(user_data) {}
203
204   void Run(Evas_Object* webview, int r, int g, int b, int a) {
205     if (func_)
206       func_(webview, r, g, b, a, user_data_);
207   }
208
209  private:
210   Ewk_View_Background_Color_Get_Callback func_;
211   void* user_data_;
212 };
213
214 class WebApplicationIconUrlGetCallback {
215  public:
216   WebApplicationIconUrlGetCallback(Ewk_Web_App_Icon_URL_Get_Callback func,
217                                    void* user_data)
218       : func_(func), user_data_(user_data) {}
219   void Run(const std::string& url) {
220     if (func_) {
221       (func_)(url.c_str(), user_data_);
222     }
223   }
224
225  private:
226   Ewk_Web_App_Icon_URL_Get_Callback func_;
227   void* user_data_;
228 };
229
230 class WebApplicationIconUrlsGetCallback {
231  public:
232   WebApplicationIconUrlsGetCallback(Ewk_Web_App_Icon_URLs_Get_Callback func,
233                                     void* user_data)
234       : func_(func), user_data_(user_data) {}
235   void Run(const std::map<std::string, std::string>& urls) {
236     if (func_) {
237       Eina_List* list = NULL;
238       for (std::map<std::string, std::string>::const_iterator it = urls.begin();
239            it != urls.end(); ++it) {
240         _Ewk_Web_App_Icon_Data* data =
241             ewkWebAppIconDataCreate(it->first, it->second);
242         list = eina_list_append(list, data);
243       }
244       (func_)(list, user_data_);
245     }
246   }
247
248  private:
249   Ewk_Web_App_Icon_URLs_Get_Callback func_;
250   void* user_data_;
251 };
252
253 class WebApplicationCapableGetCallback {
254  public:
255   WebApplicationCapableGetCallback(Ewk_Web_App_Capable_Get_Callback func,
256                                    void* user_data)
257       : func_(func), user_data_(user_data) {}
258   void Run(bool capable) {
259     if (func_) {
260       (func_)(capable ? EINA_TRUE : EINA_FALSE, user_data_);
261     }
262   }
263
264  private:
265   Ewk_Web_App_Capable_Get_Callback func_;
266   void* user_data_;
267 };
268
269 class DidChangeThemeColorCallback {
270  public:
271   DidChangeThemeColorCallback() : callback_(nullptr), user_data_(nullptr) {}
272   void Set(Ewk_View_Did_Change_Theme_Color_Callback callback, void* user_data) {
273     callback_ = callback;
274     user_data_ = user_data;
275   }
276   void Run(Evas_Object* o, const SkColor& color) {
277     if (callback_)
278       callback_(o, SkColorGetR(color), SkColorGetG(color), SkColorGetB(color),
279                 SkColorGetA(color), user_data_);
280   }
281
282  private:
283   Ewk_View_Did_Change_Theme_Color_Callback callback_;
284   void* user_data_;
285 };
286
287 class WebViewAsyncRequestHitTestDataCallback;
288 class JavaScriptDialogManagerEfl;
289 class PermissionPopupManager;
290
291 class EWebView {
292  public:
293   static EWebView* FromEvasObject(Evas_Object* eo);
294
295   EWebView(Ewk_Context*, Evas_Object* smart_object);
296   ~EWebView();
297
298   // initialize data members and activate event handlers.
299   // call this once after created and before use
300   void Initialize();
301
302   bool CreateNewWindow(
303       content::WebContentsEflDelegate::WebContentsCreateCallback);
304   static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
305
306   content::WebContentsViewAura* wcva() const;
307   content::RenderWidgetHostViewAura* rwhva() const;
308   Ewk_Context* context() const { return context_.get(); }
309   Evas_Object* evas_object() const { return evas_object_; }
310   Evas_Object* native_view() const { return native_view_; }
311   Evas_Object* GetElmWindow() const;
312   Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
313   PermissionPopupManager* GetPermissionPopupManager() const {
314     return permission_popup_manager_.get();
315   }
316
317   content::WebContents& web_contents() const { return *web_contents_.get(); }
318
319 #if defined(TIZEN_ATK_SUPPORT)
320   EWebAccessibility& eweb_accessibility() const {
321     return *eweb_accessibility_.get();
322   }
323 #endif
324
325   template <EWebViewCallbacks::CallbackType callbackType>
326   EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
327     return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
328   }
329
330   // ewk_view api
331   void SetURL(const GURL& url, bool from_api = false);
332   const GURL& GetURL() const;
333   const GURL& GetOriginalURL() const;
334   void Reload();
335   void ReloadBypassingCache();
336   Eina_Bool CanGoBack();
337   Eina_Bool CanGoForward();
338   Eina_Bool HasFocus() const;
339   void SetFocus(Eina_Bool focus);
340   Eina_Bool GoBack();
341   Eina_Bool GoForward();
342   void Suspend();
343   void Resume();
344   void Stop();
345   void SetSessionTimeout(uint64_t timeout);
346   double GetTextZoomFactor() const;
347   void SetTextZoomFactor(double text_zoom_factor);
348   double GetPageZoomFactor() const;
349   void SetPageZoomFactor(double page_zoom_factor);
350   void ExecuteEditCommand(const char* command, const char* value);
351 #if BUILDFLAG(IS_TIZEN)
352   void EnterDragState();
353 #endif
354   void SetOrientation(int orientation);
355   int GetOrientation();
356   bool TouchEventsEnabled() const;
357   void SetTouchEventsEnabled(bool enabled);
358   bool MouseEventsEnabled() const;
359   void SetMouseEventsEnabled(bool enabled);
360   void HandleTouchEvents(Ewk_Touch_Event_Type type,
361                          const Eina_List* points,
362                          const Evas_Modifier* modifiers);
363   void Show();
364   void Hide();
365   bool ExecuteJavaScript(const char* script,
366                          Ewk_View_Script_Execute_Callback callback,
367                          void* userdata);
368   bool SetUserAgent(const char* userAgent);
369   bool SetUserAgentAppName(const char* application_name);
370 #if BUILDFLAG(IS_TIZEN)
371   bool SetPrivateBrowsing(bool incognito);
372   bool GetPrivateBrowsing() const;
373 #endif
374   const char* GetUserAgent() const;
375   const char* GetUserAgentAppName() const;
376   const char* CacheSelectedText();
377   Ewk_Settings* GetSettings() { return settings_.get(); }
378   _Ewk_Frame* GetMainFrame();
379   void UpdateWebKitPreferences();
380   void LoadHTMLString(const char* html,
381                       const char* base_uri,
382                       const char* unreachable_uri);
383   void LoadPlainTextString(const char* plain_text);
384   void LoadData(const char* data,
385                 size_t size,
386                 const char* mime_type,
387                 const char* encoding,
388                 const char* base_uri,
389                 const char* unreachable_uri = NULL);
390
391   void InvokeLoadError(const GURL& url, int error_code, bool is_cancellation);
392
393   void SetViewAuthCallback(Ewk_View_Authentication_Callback callback,
394                            void* user_data);
395   void InvokeAuthCallback(LoginDelegateEfl* login_delegate,
396                           const GURL& url,
397                           const std::string& realm);
398   void Find(const char* text, Ewk_Find_Options);
399   void InvokeAuthCallbackOnUI(_Ewk_Auth_Challenge* auth_challenge);
400   void SetContentSecurityPolicy(const char* policy, Ewk_CSP_Header_Type type);
401   void HandlePopupMenu(std::vector<blink::mojom::MenuItemPtr> items,
402                        int selectedIndex,
403                        bool multiple,
404                        const gfx::Rect& bounds);
405   void HidePopupMenu();
406   void DidSelectPopupMenuItems(std::vector<int>& indices);
407   void DidCancelPopupMenu();
408   void HandleLongPressGesture(const content::ContextMenuParams&);
409   void ShowContextMenu(const content::ContextMenuParams&);
410   void CancelContextMenu(int request_id);
411   void SetScale(double scale_factor);
412   void SetScaleChangedCallback(Ewk_View_Scale_Changed_Callback callback,
413                                void* user_data);
414
415   bool GetScrollPosition(int* x, int* y) const;
416   void SetScroll(int x, int y);
417   void UrlRequestSet(const char* url,
418                      content::NavigationController::LoadURLType loadtype,
419                      Eina_Hash* headers,
420                      const char* body);
421
422   SelectPickerBase* GetSelectPicker() const { return select_picker_.get(); }
423   content::SelectionControllerEfl* GetSelectionController() const;
424   content::PopupControllerEfl* GetPopupController() const {
425     return popup_controller_.get();
426   }
427   ScrollDetector* GetScrollDetector() const { return scroll_detector_.get(); }
428   void MoveCaret(const gfx::Point& point);
429   void SelectFocusedLink();
430   bool GetSelectionRange(Eina_Rectangle* left_rect, Eina_Rectangle* right_rect);
431   Eina_Bool ClearSelection();
432
433   // Callback OnCopyFromBackingStore will be called once we get the snapshot
434   // from render
435   void OnCopyFromBackingStore(bool success, const SkBitmap& bitmap);
436
437   void OnFocusIn();
438   void OnFocusOut();
439
440   void UpdateContextMenu(bool is_password_input);
441   void RenderViewReady();
442
443   /**
444    * Creates a snapshot of given rectangle from EWebView
445    *
446    * @param rect rectangle of EWebView which will be taken into snapshot
447    * @param scale_factor scale factor
448    * @return created snapshot or NULL if error occured.
449    * @note ownership of snapshot is passed to caller
450    */
451   Evas_Object* GetSnapshot(Eina_Rectangle rect, float scale_factor);
452
453   bool GetSnapshotAsync(Eina_Rectangle rect,
454                         Ewk_Web_App_Screenshot_Captured_Callback callback,
455                         void* user_data,
456                         float scale_factor);
457   void InvokePolicyResponseCallback(_Ewk_Policy_Decision* policy_decision,
458                                     bool* defer);
459   void InvokePolicyNavigationCallback(const NavigationPolicyParams& params,
460                                       bool* handled);
461   void UseSettingsFont();
462
463   _Ewk_Hit_Test* RequestHitTestDataAt(int x, int y, Ewk_Hit_Test_Mode mode);
464   Eina_Bool AsyncRequestHitTestDataAt(int x,
465                                       int y,
466                                       Ewk_Hit_Test_Mode mode,
467                                       Ewk_View_Hit_Test_Request_Callback,
468                                       void* user_data);
469   _Ewk_Hit_Test* RequestHitTestDataAtBlinkCoords(int x,
470                                                  int y,
471                                                  Ewk_Hit_Test_Mode mode);
472   Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
473       int x,
474       int y,
475       Ewk_Hit_Test_Mode mode,
476       Ewk_View_Hit_Test_Request_Callback,
477       void* user_data);
478   void DispatchAsyncHitTestData(const Hit_Test_Params& params,
479                                 int64_t request_id);
480   void UpdateHitTestData(const Hit_Test_Params& params);
481
482   int current_find_request_id() const { return current_find_request_id_; }
483   bool PlainTextGet(Ewk_View_Plain_Text_Get_Callback callback, void* user_data);
484   void InvokePlainTextGetCallback(const std::string& content_text,
485                                   int plain_text_get_callback_id);
486   int SetEwkViewPlainTextGetCallback(Ewk_View_Plain_Text_Get_Callback callback,
487                                      void* user_data);
488   void SetViewGeolocationPermissionCallback(
489       Ewk_View_Geolocation_Permission_Callback callback,
490       void* user_data);
491   bool InvokeViewGeolocationPermissionCallback(
492       _Ewk_Geolocation_Permission_Request*
493           geolocation_permission_request_context,
494       Eina_Bool* result);
495   void SetViewUserMediaPermissionCallback(
496       Ewk_View_User_Media_Permission_Callback callback,
497       void* user_data);
498   bool InvokeViewUserMediaPermissionCallback(
499       _Ewk_User_Media_Permission_Request* user_media_permission_request_context,
500       Eina_Bool* result);
501   void SetViewUserMediaPermissionQueryCallback(
502       Ewk_View_User_Media_Permission_Query_Callback callback,
503       void* user_data);
504   Ewk_User_Media_Permission_Query_Result
505   InvokeViewUserMediaPermissionQueryCallback(
506       _Ewk_User_Media_Permission_Query* user_media_permission_query_context);
507
508   void SetViewLoadErrorPageCallback(Ewk_View_Error_Page_Load_Callback callback,
509                                     void* user_data);
510   const char* InvokeViewLoadErrorPageCallback(
511       const GURL& url,
512       int error_code,
513       const std::string& error_description);
514   bool IsLoadErrorPageCallbackSet() const;
515   void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
516                                    void* user_data);
517   bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
518                                       Eina_Bool* result);
519   void DidChangeContentsSize(int width, int height);
520   const Eina_Rectangle GetContentsSize() const;
521   void GetScrollSize(int* w, int* h);
522   void StopFinding();
523   void SetProgressValue(double progress);
524   double GetProgressValue();
525   const char* GetTitle();
526   bool SaveAsPdf(int width, int height, const std::string& file_name);
527   void BackForwardListClear();
528   _Ewk_Back_Forward_List* GetBackForwardList() const;
529   void InvokeBackForwardListChangedCallback();
530   _Ewk_History* GetBackForwardHistory() const;
531   bool WebAppCapableGet(Ewk_Web_App_Capable_Get_Callback callback,
532                         void* userData);
533   bool WebAppIconUrlGet(Ewk_Web_App_Icon_URL_Get_Callback callback,
534                         void* userData);
535   bool WebAppIconUrlsGet(Ewk_Web_App_Icon_URLs_Get_Callback callback,
536                          void* userData);
537   void InvokeWebAppCapableGetCallback(bool capable, int callbackId);
538   void InvokeWebAppIconUrlGetCallback(const std::string& iconUrl,
539                                       int callbackId);
540   void InvokeWebAppIconUrlsGetCallback(
541       const std::map<std::string, std::string>& iconUrls,
542       int callbackId);
543   void SetNotificationPermissionCallback(
544       Ewk_View_Notification_Permission_Callback callback,
545       void* user_data);
546   bool IsNotificationPermissionCallbackSet() const;
547   bool InvokeNotificationPermissionCallback(
548       Ewk_Notification_Permission_Request* request);
549
550   bool GetMHTMLData(Ewk_View_MHTML_Data_Get_Callback callback, void* user_data);
551   void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id);
552   bool SavePageAsMHTML(const std::string& path,
553                        Ewk_View_Save_Page_Callback callback,
554                        void* user_data);
555   bool IsFullscreen();
556   void ExitFullscreen();
557   double GetScale();
558   void DidChangePageScaleFactor(double scale_factor);
559   void SetScaledContentsSize();
560   void SetJavaScriptAlertCallback(Ewk_View_JavaScript_Alert_Callback callback,
561                                   void* user_data);
562   void JavaScriptAlertReply();
563   void SetJavaScriptConfirmCallback(
564       Ewk_View_JavaScript_Confirm_Callback callback,
565       void* user_data);
566   void JavaScriptConfirmReply(bool result);
567   void SetJavaScriptPromptCallback(Ewk_View_JavaScript_Prompt_Callback callback,
568                                    void* user_data);
569   void JavaScriptPromptReply(const char* result);
570   void set_renderer_crashed();
571   void GetPageScaleRange(double* min_scale, double* max_scale);
572   void SetDrawsTransparentBackground(bool enabled);
573   bool GetBackgroundColor(Ewk_View_Background_Color_Get_Callback callback,
574                           void* user_data);
575   void OnGetBackgroundColor(int callback_id, SkColor bg_color);
576
577   void GetSessionData(const char** data, unsigned* length) const;
578   bool RestoreFromSessionData(const char* data, unsigned length);
579   void ShowFileChooser(content::RenderFrameHost* render_frame_host,
580                        const blink::mojom::FileChooserParams&);
581   void SetBrowserFont();
582   bool IsDragging() const;
583
584   void RequestColorPicker(int r, int g, int b, int a);
585   bool SetColorPickerColor(int r, int g, int b, int a);
586   void InputPickerShow(ui::TextInputType input_type,
587                        double input_value,
588                        content::DateTimeChooserEfl* date_time_chooser);
589
590   void ShowContentsDetectedPopup(const char*);
591
592   // Returns TCP port number with Inspector, or 0 if error.
593   int StartInspectorServer(int port = 0);
594   bool StopInspectorServer();
595
596   void LoadNotFoundErrorPage(const std::string& invalidUrl);
597   static std::string GetPlatformLocale();
598   bool GetLinkMagnifierEnabled() const;
599   void SetLinkMagnifierEnabled(bool enabled);
600
601   bool GetHorizontalPanningHold() const;
602   void SetHorizontalPanningHold(bool hold);
603   bool GetVerticalPanningHold() const;
604   void SetVerticalPanningHold(bool hold);
605
606   void SetQuotaPermissionRequestCallback(
607       Ewk_Quota_Permission_Request_Callback callback,
608       void* user_data);
609   void InvokeQuotaPermissionRequest(
610       _Ewk_Quota_Permission_Request* request,
611       content::QuotaPermissionContext::PermissionCallback cb);
612   void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
613                          bool allow);
614   void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
615 #if !defined(EWK_BRINGUP)  // FIXME: m67 bringup
616   void SetViewMode(blink::WebViewMode view_mode);
617 #endif
618   gfx::Point GetContextMenuPosition() const;
619
620   content::ContextMenuControllerEfl* GetContextMenuController() {
621     return context_menu_.get();
622   }
623
624   bool SetMainFrameScrollbarVisible(bool visible);
625   bool GetMainFrameScrollbarVisible(
626       Ewk_View_Main_Frame_Scrollbar_Visible_Get_Callback callback,
627       void* user_data);
628   void InvokeMainFrameScrollbarVisibleCallback(int callback_id, bool visible);
629
630   void ResetContextMenuController();
631   Eina_Bool AddJavaScriptMessageHandler(Evas_Object* view,
632                                         Ewk_View_Script_Message_Cb callback,
633                                         std::string name);
634
635   content::GinNativeBridgeDispatcherHost* GetGinNativeBridgeDispatcherHost()
636       const {
637     return gin_native_bridge_dispatcher_host_.get();
638   }
639   bool SetPageVisibility(Ewk_Page_Visibility_State page_visibility_state);
640
641   void SetExceededIndexedDatabaseQuotaCallback(
642       Ewk_View_Exceeded_Indexed_Database_Quota_Callback callback,
643       void* user_data);
644   void InvokeExceededIndexedDatabaseQuotaCallback(const GURL& origin,
645                                                   int64_t current_quota);
646   void ExceededIndexedDatabaseQuotaReply(bool allow);
647
648 #if defined(TIZEN_VIDEO_HOLE)
649   void SetVideoHoleSupport(bool enable);
650 #endif
651
652   /// ---- Event handling
653   bool HandleShow();
654   bool HandleHide();
655   bool HandleMove(int x, int y);
656   bool HandleResize(int width, int height);
657   bool HandleTextSelectionDown(int x, int y);
658   bool HandleTextSelectionUp(int x, int y);
659
660   void HandleRendererProcessCrash();
661   void InvokeWebProcessCrashedCallback();
662
663   void HandleTapGestureForSelection(bool is_content_editable);
664   void HandleZoomGesture(blink::WebGestureEvent& event);
665   void ClosePage();
666
667   void RequestManifest(Ewk_View_Request_Manifest_Callback callback,
668                        void* user_data);
669   void DidRespondRequestManifest(_Ewk_View_Request_Manifest* manifest,
670                                  Ewk_View_Request_Manifest_Callback callback,
671                                  void* user_data);
672
673   void SetBeforeUnloadConfirmPanelCallback(
674       Ewk_View_Before_Unload_Confirm_Panel_Callback callback,
675       void* user_data);
676   void ReplyBeforeUnloadConfirmPanel(Eina_Bool result);
677   void SyncAcceptLanguages(const std::string& accept_languages);
678
679   void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
680                       const gfx::Vector2dF& latest_overscroll_delta);
681
682   bool SetVisibility(bool enable);
683   void SetDoNotTrack(Eina_Bool);
684
685 #if defined(TIZEN_ATK_SUPPORT)
686   void UpdateSpatialNavigationStatus(Eina_Bool enable);
687   void UpdateAccessibilityStatus(Eina_Bool enable);
688
689   bool CheckLazyInitializeAtk() {
690     return is_initialized_ && lazy_initialize_atk_;
691   }
692   void InitAtk();
693   bool GetAtkStatus();
694 #endif
695
696   bool ShouldIgnoreNavigation(content::NavigationHandle* navigation_handle);
697
698 #if BUILDFLAG(IS_TIZEN_TV)
699   void DrawLabel(Evas_Object* image, Eina_Rectangle rect);
700   void DeactivateAtk(bool deactivated);
701   void ClearLabels();
702 #endif  // IS_TIZEN_TV
703
704   void SetDidChangeThemeColorCallback(
705       Ewk_View_Did_Change_Theme_Color_Callback callback,
706       void* user_data);
707   void DidChangeThemeColor(const SkColor& color);
708
709   void OnSelectionRectReceived(const gfx::Rect& selection_rect) const;
710
711  private:
712   static void NativeViewResize(void* data,
713                                Evas* e,
714                                Evas_Object* obj,
715                                void* event_info);
716   void InitializeContent();
717   void InitializeWindowTreeHost();
718   void SendDelayedMessages(content::RenderViewHost* render_view_host);
719
720   void EvasToBlinkCords(int x, int y, int* view_x, int* view_y);
721   Eina_Bool AsyncRequestHitTestDataAtBlinkCords(
722       int x,
723       int y,
724       Ewk_Hit_Test_Mode mode,
725       WebViewAsyncRequestHitTestDataCallback* cb);
726 #if BUILDFLAG(IS_TIZEN) && !defined(EWK_BRINGUP)
727   static void cameraResultCb(service_h request,
728                              service_h reply,
729                              service_result_e result,
730                              void* data);
731 #endif
732
733 #if BUILDFLAG(IS_TIZEN) && !defined(EWK_BRINGUP)
734   bool LaunchCamera(std::u16string mimetype);
735 #endif
736   JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
737
738   // Changes viewport without resizing Evas_Object representing webview
739   // and its corresponding RWHV to let Blink renders custom viewport
740   // while showing picker.
741   void AdjustViewPortHeightToPopupMenu(bool is_popup_menu_visible);
742
743   void ShowContextMenuInternal(const content::ContextMenuParams&);
744
745   void UpdateWebkitPreferencesEfl(content::RenderViewHost*);
746
747   void ChangeScroll(int& x, int& y);
748   void ScrollFocusedNodeIntoView();
749
750   void GenerateMHTML(Ewk_View_Save_Page_Callback callback,
751                      void* user_data,
752                      const base::FilePath& file_path);
753   void MHTMLGenerated(Ewk_View_Save_Page_Callback callback,
754                       void* user_data,
755                       const base::FilePath& file_path,
756                       int64_t file_size);
757
758   static void OnViewFocusIn(void* data, Evas*, Evas_Object*, void*);
759   static void OnViewFocusOut(void* data, Evas*, Evas_Object*, void*);
760   static void VisibleContentChangedCallback(void* user_data,
761                                             Evas_Object* object,
762                                             void* event_info);
763
764   static void OnCustomScrollBeginCallback(void* user_data,
765                                           Evas_Object* object,
766                                           void* event_info);
767
768   static void OnCustomScrollEndCallback(void* user_data,
769                                         Evas_Object* object,
770                                         void* event_info);
771   void UpdateContextMenuWithParams(const content::ContextMenuParams& params);
772
773   static Eina_Bool DelayedPopulateAndShowContextMenu(void* data);
774
775   scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
776   scoped_refptr<Ewk_Context> context_;
777   std::unique_ptr<content::WebContents> web_contents_;
778   std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
779   std::string pending_url_request_;
780   std::unique_ptr<Ewk_Settings> settings_;
781   std::unique_ptr<_Ewk_Frame> frame_;
782   std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
783   Evas_Object* evas_object_;
784   Evas_Object* native_view_;
785   bool mouse_events_enabled_;
786   double text_zoom_factor_;
787   mutable std::string user_agent_;
788   mutable std::string user_agent_app_name_;
789   std::unique_ptr<_Ewk_Auth_Challenge> auth_challenge_;
790   std::string selected_text_cached_;
791
792   std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
793 #if !defined(EWK_BRINGUP)  // FIXME: m71 bringup
794   std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
795 #endif
796   std::unique_ptr<content::PopupControllerEfl> popup_controller_;
797   std::u16string previous_text_;
798   int current_find_request_id_;
799   static int find_request_id_counter_;
800
801   typedef WebViewCallback<Ewk_View_Plain_Text_Get_Callback, const char*>
802       EwkViewPlainTextGetCallback;
803   base::IDMap<EwkViewPlainTextGetCallback*> plain_text_get_callback_map_;
804
805   typedef WebViewCallback<Ewk_View_MHTML_Data_Get_Callback, const char*>
806       MHTMLCallbackDetails;
807   base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
808
809   typedef WebViewCallback<Ewk_View_Main_Frame_Scrollbar_Visible_Get_Callback,
810                           bool>
811       MainFrameScrollbarVisibleGetCallback;
812   base::IDMap<MainFrameScrollbarVisibleGetCallback*>
813       main_frame_scrollbar_visible_callback_map_;
814
815   base::IDMap<BackgroundColorGetCallback*> background_color_get_callback_map_;
816
817   gfx::Size contents_size_;
818   double progress_;
819   mutable std::string title_;
820   Hit_Test_Params hit_test_params_;
821   base::WaitableEvent hit_test_completion_;
822   double page_scale_factor_;
823   double x_delta_;
824   double y_delta_;
825
826   WebViewCallback<Ewk_View_Geolocation_Permission_Callback,
827                   _Ewk_Geolocation_Permission_Request*>
828       geolocation_permission_cb_;
829   WebViewCallback<Ewk_View_User_Media_Permission_Callback,
830                   _Ewk_User_Media_Permission_Request*>
831       user_media_permission_cb_;
832   WebViewCallbackWithReturnValue<Ewk_User_Media_Permission_Query_Result,
833                                  Ewk_View_User_Media_Permission_Query_Callback,
834                                  _Ewk_User_Media_Permission_Query*>
835       user_media_permission_query_cb_;
836   WebViewErrorPageLoadCallback<Ewk_View_Error_Page_Load_Callback,
837                                Ewk_Error*,
838                                Ewk_Error_Page*>
839       load_error_page_cb_;
840   WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
841       unfocus_allow_cb_;
842   WebViewCallback<Ewk_View_Notification_Permission_Callback,
843                   Ewk_Notification_Permission_Request*>
844       notification_permission_callback_;
845   WebViewCallback<Ewk_Quota_Permission_Request_Callback,
846                   const _Ewk_Quota_Permission_Request*>
847       quota_request_callback_;
848   WebViewCallback<Ewk_View_Authentication_Callback, _Ewk_Auth_Challenge*>
849       authentication_cb_;
850   WebViewCallback<Ewk_View_Scale_Changed_Callback, double> scale_changed_cb_;
851
852   std::unique_ptr<content::InputPicker> input_picker_;
853
854   DidChangeThemeColorCallback did_change_theme_color_callback_;
855
856   base::IDMap<WebApplicationIconUrlGetCallback*>
857       web_app_icon_url_get_callback_map_;
858   base::IDMap<WebApplicationIconUrlsGetCallback*>
859       web_app_icon_urls_get_callback_map_;
860   base::IDMap<WebApplicationCapableGetCallback*>
861       web_app_capable_get_callback_map_;
862   std::unique_ptr<PermissionPopupManager> permission_popup_manager_;
863   std::unique_ptr<ScrollDetector> scroll_detector_;
864
865   // Manages injecting native objects.
866   std::unique_ptr<content::GinNativeBridgeDispatcherHost>
867       gin_native_bridge_dispatcher_host_;
868
869   WebViewExceededQuotaCallback<
870       Ewk_View_Exceeded_Indexed_Database_Quota_Callback,
871       Ewk_Security_Origin*,
872       long long>
873       exceeded_indexed_db_quota_callback_;
874   std::unique_ptr<Ewk_Security_Origin> exceeded_indexed_db_quota_origin_;
875
876 #if BUILDFLAG(IS_TIZEN)
877   blink::mojom::FileChooserParams::Mode filechooser_mode_;
878 #endif
879   std::map<const _Ewk_Quota_Permission_Request*,
880            content::QuotaPermissionContext::PermissionCallback>
881       quota_permission_request_map_;
882
883 #if BUILDFLAG(IS_TIZEN)
884   Ecore_Event_Handler* window_rotate_handler_ = nullptr;
885 #endif
886
887   bool is_initialized_;
888
889   std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
890
891   static content::WebContentsEflDelegate::WebContentsCreateCallback
892       create_new_window_web_contents_cb_;
893
894  private:
895   gfx::Vector2d previous_scroll_position_;
896
897   gfx::Point context_menu_position_;
898
899   content::ContextMenuParams saved_context_menu_params_;
900
901   std::vector<IPC::Message*> delayed_messages_;
902
903   std::map<int64_t, WebViewAsyncRequestHitTestDataCallback*> hit_test_callback_;
904
905   content::AcceptLanguagesHelper::AcceptLangsChangedCallback
906       accept_langs_changed_callback_;
907
908   std::unique_ptr<SelectPickerBase> select_picker_;
909   std::unique_ptr<aura::WindowTreeHost> host_;
910   std::unique_ptr<aura::client::FocusClient> focus_client_;
911   std::unique_ptr<aura::client::WindowParentingClient> window_parenting_client_;
912   std::unique_ptr<ui::CompositorObserver> compositor_observer_;
913
914 #if defined(TIZEN_ATK_SUPPORT)
915   std::unique_ptr<EWebAccessibility> eweb_accessibility_;
916   bool lazy_initialize_atk_ = false;
917 #endif
918 #if defined(TIZEN_VIDEO_HOLE)
919   bool pending_video_hole_setting_ = false;
920 #endif
921
922   Ecore_Timer* delayed_show_context_menu_timer_ = nullptr;
923 };
924
925 const unsigned int g_default_tilt_motion_sensitivity = 3;
926
927 #endif