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