[M120 Migration]URL of _Ewk_Error set wrong
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / eweb_view.h
index 571af8c..08fc8e7 100644 (file)
 #include <locale.h>
 #include <vector>
 
-#include "base/callback.h"
 #include "base/containers/id_map.h"
+#include "base/functional/callback.h"
 #include "base/synchronization/waitable_event.h"
 #include "browser/input_picker/input_picker.h"
-#include "content/browser/date_time_chooser_efl.h"
-#include "content/browser/renderer_host/event_with_latency_info.h"
 #include "content/browser/select_picker/select_picker_base.h"
 #include "content/browser/selection/selection_controller_efl.h"
 #include "content/browser/web_contents/web_contents_view_aura.h"
 #include "content/browser/web_contents/web_contents_view_aura_helper_efl.h"
+#include "content/common/input/event_with_latency_info.h"
 #include "content/public/browser/context_menu_params.h"
 #include "content/public/browser/navigation_controller.h"
-#include "content/public/browser/quota_permission_context.h"
 #include "content/public/browser/web_contents_delegate.h"
-#include "content/public/browser/web_contents_efl_delegate.h"
+#include "content/public/browser/webview_delegate.h"
 #include "content/public/common/input_event_ack_state.h"
 #include "content_browser_client_efl.h"
 #include "context_menu_controller_efl.h"
 #include "ui/gfx/geometry/point.h"
 #include "ui/gfx/geometry/size.h"
 #include "web_contents_delegate_efl.h"
+#if defined(TIZEN_PEPPER_EXTENSIONS)
+#include "ewk_extension_system_delegate.h"
+#include "public/ewk_value_product.h"
+#endif
+
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "third_party/blink/public/common/mediastream/media_devices.h"
+#endif
 
 namespace aura {
 namespace client {
@@ -71,6 +77,7 @@ class WebContentsDelegateEfl;
 class WebContentsViewAura;
 class ContextMenuControllerEfl;
 class PopupControllerEfl;
+class DateTimeChooserEfl;
 class InputPicker;
 class GinNativeBridgeDispatcherHost;
 class NavigationHandle;
@@ -81,9 +88,12 @@ class _Ewk_App_Control;
 class _Ewk_Policy_Decision;
 class _Ewk_Hit_Test;
 class Ewk_Context;
-class WebViewEvasEventHandler;
 class _Ewk_Quota_Permission_Request;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+struct _Ewk_File_Chooser_Request;
+#endif
+
 #if defined(TIZEN_ATK_SUPPORT)
 class EWebAccessibility;
 #endif
@@ -150,6 +160,28 @@ class WebViewCallbackWithReturnValue {
 };
 
 template <typename CallbackPtr, typename... CallbackParameter>
+class WebViewErrorPageLoadCallback {
+ public:
+  WebViewErrorPageLoadCallback() { Set(nullptr, nullptr); }
+
+  void Set(CallbackPtr cb, void* data) {
+    callback_ = cb;
+    user_data_ = data;
+  }
+
+  bool IsCallbackSet() const { return callback_; }
+
+  void Run(Evas_Object* webview, CallbackParameter... param) {
+    if (IsCallbackSet())
+      callback_(webview, param..., user_data_);
+  }
+
+ private:
+  CallbackPtr callback_;
+  void* user_data_;
+};
+
+template <typename CallbackPtr, typename... CallbackParameter>
 class WebViewExceededQuotaCallback {
  public:
   WebViewExceededQuotaCallback() { Set(nullptr, nullptr); }
@@ -262,13 +294,52 @@ class DidChangeThemeColorCallback {
   void* user_data_;
 };
 
+#if BUILDFLAG(IS_TIZEN_TV)
+class GetMediaDeviceCallback {
+ public:
+  GetMediaDeviceCallback() : func_(nullptr), user_data_(nullptr) {}
+
+  void Set(Ewk_Media_Device_List_Get_Callback func, void* user_data) {
+    func_ = func;
+    user_data_ = user_data;
+  }
+
+  void Run(EwkMediaDeviceInfo* device_list, int size) {
+    if (func_) {
+      (func_)(device_list, size, user_data_);
+    }
+  }
+
+ private:
+  Ewk_Media_Device_List_Get_Callback func_;
+  void* user_data_;
+};
+#endif
+
+#if BUILDFLAG(IS_TIZEN_TV)
+class IsVideoPlayingCallback {
+ public:
+  IsVideoPlayingCallback(Ewk_Is_Video_Playing_Callback func, void* user_data)
+      : func_(func), user_data_(user_data) {}
+  void Run(Evas_Object* obj, bool isplaying) {
+    if (func_) {
+      (func_)(obj, isplaying ? EINA_TRUE : EINA_FALSE, user_data_);
+    }
+  }
+
+ private:
+  Ewk_Is_Video_Playing_Callback func_;
+  void* user_data_;
+};
+#endif
+
 class WebViewAsyncRequestHitTestDataCallback;
 class JavaScriptDialogManagerEfl;
 class PermissionPopupManager;
 
 class EWebView {
  public:
-  static EWebView* FromEvasObject(Evas_Object* eo);
+  static EWebView* FromEwkView(Evas_Object* ewk_view);
 
   EWebView(Ewk_Context*, Evas_Object* smart_object);
   ~EWebView();
@@ -277,22 +348,22 @@ class EWebView {
   // call this once after created and before use
   void Initialize();
 
-  bool CreateNewWindow(
-      content::WebContentsEflDelegate::WebContentsCreateCallback);
+  bool CreateNewWindow(content::WebViewDelegate::WebContentsCreateCallback);
   static Evas_Object* GetHostWindowDelegate(const content::WebContents*);
 
   content::WebContentsViewAura* wcva() const;
   content::RenderWidgetHostViewAura* rwhva() const;
   Ewk_Context* context() const { return context_.get(); }
-  Evas_Object* evas_object() const { return evas_object_; }
-  Evas_Object* native_view() const { return native_view_; }
+  Evas_Object* ewk_view() const { return ewk_view_; }
+  Evas_Object* efl_main_layout() const { return efl_main_layout_; }
   Evas_Object* GetElmWindow() const;
-  Evas* GetEvas() const { return evas_object_evas_get(evas_object_); }
+  Evas* GetEvas() const { return evas_object_evas_get(ewk_view_); }
   PermissionPopupManager* GetPermissionPopupManager() const {
     return permission_popup_manager_.get();
   }
 
   content::WebContents& web_contents() const { return *web_contents_.get(); }
+  content::WebContentsViewAura* GetWebContentsViewAura() const;
 
 #if defined(TIZEN_ATK_SUPPORT)
   EWebAccessibility& eweb_accessibility() const {
@@ -302,7 +373,7 @@ class EWebView {
 
   template <EWebViewCallbacks::CallbackType callbackType>
   EWebViewCallbacks::CallBack<callbackType> SmartCallback() const {
-    return EWebViewCallbacks::CallBack<callbackType>(evas_object_);
+    return EWebViewCallbacks::CallBack<callbackType>(ewk_view_);
   }
 
   // ewk_view api
@@ -320,18 +391,36 @@ class EWebView {
   void Suspend();
   void Resume();
   void Stop();
+#if BUILDFLAG(IS_TIZEN_TV)
+  void SetFloatVideoWindowState(bool enabled);
+  void NotifyDownloadableFontInfo(const char* scheme_id_uri,
+                                  const char* value,
+                                  const char* data,
+                                  int type);
+  std::vector<std::string> NotifyPlaybackState(int state,
+                                               int player_id,
+                                               const char* url,
+                                               const char* mime_type);
+  void SuspendNetworkLoading();
+  void ResumeNetworkLoading();
+#endif // IS_TIZEN_TV
   void SetSessionTimeout(uint64_t timeout);
   double GetTextZoomFactor() const;
   void SetTextZoomFactor(double text_zoom_factor);
   double GetPageZoomFactor() const;
   void SetPageZoomFactor(double page_zoom_factor);
   void ExecuteEditCommand(const char* command, const char* value);
+#if BUILDFLAG(IS_TIZEN)
+  void EnterDragState();
+#endif
   void SetOrientation(int orientation);
   int GetOrientation();
   bool TouchEventsEnabled() const;
   void SetTouchEventsEnabled(bool enabled);
   bool MouseEventsEnabled() const;
   void SetMouseEventsEnabled(bool enabled);
+  void SendKeyEvent(Evas_Object* ewk_view, void* key_event, bool is_press);
+  bool SetKeyEventsEnabled(bool enabled);
   void HandleTouchEvents(Ewk_Touch_Event_Type type,
                          const Eina_List* points,
                          const Evas_Modifier* modifiers);
@@ -356,13 +445,17 @@ class EWebView {
                       const char* base_uri,
                       const char* unreachable_uri);
   void LoadPlainTextString(const char* plain_text);
+
+  void LoadHTMLStringOverridingCurrentEntry(const char* html,
+                                            const char* base_uri,
+                                            const char* unreachable_url);
   void LoadData(const char* data,
                 size_t size,
                 const char* mime_type,
                 const char* encoding,
                 const char* base_uri,
-                const char* unreachable_uri = NULL);
-
+                const char* unreachable_uri = NULL,
+                bool should_replace_current_entry = false);
   void InvokeLoadError(const GURL& url, int error_code, bool is_cancellation);
 
   void SetViewAuthCallback(Ewk_View_Authentication_Callback callback,
@@ -479,6 +572,13 @@ class EWebView {
   Ewk_User_Media_Permission_Query_Result
   InvokeViewUserMediaPermissionQueryCallback(
       _Ewk_User_Media_Permission_Query* user_media_permission_query_context);
+
+  void SetViewLoadErrorPageCallback(Ewk_View_Error_Page_Load_Callback callback,
+                                    void* user_data);
+  const char* InvokeViewLoadErrorPageCallback(const GURL& url,
+                                              int error_code,
+                                              bool is_cancellation);
+  bool IsLoadErrorPageCallbackSet() const;
   void SetViewUnfocusAllowCallback(Ewk_View_Unfocus_Allow_Callback callback,
                                    void* user_data);
   bool InvokeViewUnfocusAllowCallback(Ewk_Unfocus_Direction direction,
@@ -536,14 +636,16 @@ class EWebView {
   void JavaScriptPromptReply(const char* result);
   void set_renderer_crashed();
   void GetPageScaleRange(double* min_scale, double* max_scale);
-  void SetDrawsTransparentBackground(bool enabled);
+  bool SetDrawsTransparentBackground(bool enabled);
+  bool GetDrawsTransparentBackground();
+  bool SetBackgroundColor(int red, int green, int blue, int alpha);
   bool GetBackgroundColor(Ewk_View_Background_Color_Get_Callback callback,
                           void* user_data);
   void OnGetBackgroundColor(int callback_id, SkColor bg_color);
 
   void GetSessionData(const char** data, unsigned* length) const;
   bool RestoreFromSessionData(const char* data, unsigned length);
-  void ShowFileChooser(content::RenderFrameHost* render_frame_host,
+  void ShowFileChooser(scoped_refptr<content::FileSelectListener> listener,
                        const blink::mojom::FileChooserParams&);
   void SetBrowserFont();
   bool IsDragging() const;
@@ -573,13 +675,13 @@ class EWebView {
   void SetQuotaPermissionRequestCallback(
       Ewk_Quota_Permission_Request_Callback callback,
       void* user_data);
+#if !defined(EWK_BRINGUP)  // FIXME: m114 bringup
   void InvokeQuotaPermissionRequest(
       _Ewk_Quota_Permission_Request* request,
       content::QuotaPermissionContext::PermissionCallback cb);
   void QuotaRequestReply(const _Ewk_Quota_Permission_Request* request,
                          bool allow);
   void QuotaRequestCancel(const _Ewk_Quota_Permission_Request* request);
-#if !defined(EWK_BRINGUP)  // FIXME: m67 bringup
   void SetViewMode(blink::WebViewMode view_mode);
 #endif
   gfx::Point GetContextMenuPosition() const;
@@ -613,7 +715,11 @@ class EWebView {
   void ExceededIndexedDatabaseQuotaReply(bool allow);
 
 #if defined(TIZEN_VIDEO_HOLE)
-  void SetVideoHoleSupport(bool enable);
+  void EnableVideoHoleSupport();
+#endif
+
+#if defined(TIZEN_TBM_SUPPORT)
+  void SetOffscreenRendering(bool enable);
 #endif
 
   /// ---- Event handling
@@ -637,12 +743,27 @@ class EWebView {
                                  Ewk_View_Request_Manifest_Callback callback,
                                  void* user_data);
 
+  void SetBeforeUnloadConfirmPanelCallback(
+      Ewk_View_Before_Unload_Confirm_Panel_Callback callback,
+      void* user_data);
+  void ReplyBeforeUnloadConfirmPanel(Eina_Bool result);
   void SyncAcceptLanguages(const std::string& accept_languages);
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  //Browser edge scroll
+  bool EdgeScrollBy(int delta_x, int delta_y);
+  void GetMousePosition(gfx::Point&);
+  void InvokeEdgeScrollByCallback(const gfx::Point&, bool);
+  // notify web browser video playing status
+  bool IsVideoPlaying(Ewk_Is_Video_Playing_Callback callback, void* user_data);
+  void InvokeIsVideoPlayingCallback(bool is_playing, int callback_id);
+#endif
+
   void OnOverscrolled(const gfx::Vector2dF& accumulated_overscroll,
                       const gfx::Vector2dF& latest_overscroll_delta);
 
   bool SetVisibility(bool enable);
+  void SetDoNotTrack(Eina_Bool);
 
 #if defined(TIZEN_ATK_SUPPORT)
   void UpdateSpatialNavigationStatus(Eina_Bool enable);
@@ -654,16 +775,62 @@ class EWebView {
   void InitAtk();
   bool GetAtkStatus();
 #endif
-
-  content::DateTimeChooserEfl* GetDateTimeChooser() {
-    return date_time_chooser_;
-  }
+#if defined(TIZEN_PEPPER_EXTENSIONS)
+  void InitializePepperExtensionSystem();
+  EwkExtensionSystemDelegate* GetExtensionDelegate();
+  void SetWindowId();
+  void SetPepperExtensionWidgetInfo(Ewk_Value widget_pepper_ext_info);
+  void SetPepperExtensionCallback(Generic_Sync_Call_Callback cb, void* data);
+  void RegisterPepperExtensionDelegate();
+  void UnregisterPepperExtensionDelegate();
+#endif
 
   bool ShouldIgnoreNavigation(content::NavigationHandle* navigation_handle);
 
 #if BUILDFLAG(IS_TIZEN_TV)
   void DrawLabel(Evas_Object* image, Eina_Rectangle rect);
+  void DeactivateAtk(bool deactivated);
   void ClearLabels();
+  void AddDynamicCertificatePath(const std::string& host,
+                                 const std::string& cert_path);
+
+  bool SetMixedContents(bool allow);
+  void ClearAllTilesResources();
+  bool UseEarlyRWI() { return use_early_rwi_; }
+  bool RWIInfoShowed() { return rwi_info_showed_; }
+  GURL RWIURL() { return rwi_gurl_; }
+  void OnDialogClosed();
+  void NotifyMediaStateChanged(uint32_t type,
+                               uint32_t previous,
+                               uint32_t current);
+  void SetHighBitRate(Eina_Bool is_high_bitrate);
+  bool IsHighBitRate() const { return is_high_bitrate_; }
+  void NotifyFirstTimeStamp(unsigned long long timestamp,
+                            int time_base_num,
+                            int time_base_den);
+  void NotifyPESData(const std::string& buf,
+                     unsigned int len,
+                     int media_position);
+  void SetPreferSubtitleLang(const char* lang_list);
+  void NotifySubtitleState(int state, double time_stamp);
+  void NotifySubtitlePlay(int active_track_id,
+                          const char* url,
+                          const char* lang);
+  void NotifySubtitleData(int track_id,
+                          double time_stamp,
+                          const std::string& data,
+                          unsigned int size);
+  void UpdateCurrentTime(double current_time);
+  void UpdateEventData(void* data);
+  double GetCurrentTime() { return current_time_; }
+  void GetMediaDeviceList(Ewk_Media_Device_List_Get_Callback callback,
+                          void* userData);
+  using MediaDeviceEnumeration =
+      std::array<blink::WebMediaDeviceInfoArray, NUM_MEDIA_DEVICE_TYPES>;
+  void OnDeviceListed(const MediaDeviceEnumeration& devices);
+  void SetTranslatedURL(const char* url);
+  void NotifyParentalRatingInfo(const char* info, const char* url);
+  void SetParentalRatingResult(const char* info, bool is_pass);
 #endif  // IS_TIZEN_TV
 
   void SetDidChangeThemeColorCallback(
@@ -688,16 +855,14 @@ class EWebView {
       int y,
       Ewk_Hit_Test_Mode mode,
       WebViewAsyncRequestHitTestDataCallback* cb);
-#if BUILDFLAG(IS_TIZEN) && !defined(EWK_BRINGUP)
-  static void cameraResultCb(service_h request,
-                             service_h reply,
-                             service_result_e result,
-                             void* data);
-#endif
 
-#if BUILDFLAG(IS_TIZEN) && !defined(EWK_BRINGUP)
-  bool LaunchCamera(std::u16string mimetype);
+#if BUILDFLAG(IS_TIZEN_TV)
+  void InitInspectorServer();
+
+  void RunPendingSetFocus(Eina_Bool focus);
+  void SetFocusInternal(Eina_Bool focus);
 #endif
+
   JavaScriptDialogManagerEfl* GetJavaScriptDialogManagerEfl();
 
   // Changes viewport without resizing Evas_Object representing webview
@@ -720,8 +885,6 @@ class EWebView {
                       const base::FilePath& file_path,
                       int64_t file_size);
 
-  static void OnViewFocusIn(void* data, Evas*, Evas_Object*, void*);
-  static void OnViewFocusOut(void* data, Evas*, Evas_Object*, void*);
   static void VisibleContentChangedCallback(void* user_data,
                                             Evas_Object* object,
                                             void* event_info);
@@ -735,16 +898,19 @@ class EWebView {
                                         void* event_info);
   void UpdateContextMenuWithParams(const content::ContextMenuParams& params);
 
-  scoped_refptr<WebViewEvasEventHandler> evas_event_handler_;
+  static Eina_Bool DelayedPopulateAndShowContextMenu(void* data);
+
   scoped_refptr<Ewk_Context> context_;
   std::unique_ptr<content::WebContents> web_contents_;
   std::unique_ptr<content::WebContentsDelegateEfl> web_contents_delegate_;
+  std::unique_ptr<content::WebViewDelegate> webview_delegate_;
   std::string pending_url_request_;
   std::unique_ptr<Ewk_Settings> settings_;
   std::unique_ptr<_Ewk_Frame> frame_;
   std::unique_ptr<_Ewk_Policy_Decision> window_policy_;
-  Evas_Object* evas_object_;
-  Evas_Object* native_view_;
+  Evas_Object* ewk_view_;
+  Evas_Object* efl_main_layout_;
+  bool key_events_enabled_ = true;
   bool mouse_events_enabled_;
   double text_zoom_factor_;
   mutable std::string user_agent_;
@@ -753,7 +919,9 @@ class EWebView {
   std::string selected_text_cached_;
 
   std::unique_ptr<content::ContextMenuControllerEfl> context_menu_;
-#if !defined(EWK_BRINGUP)  // FIXME: m71 bringup
+#if BUILDFLAG(IS_TIZEN_TV)
+  std::unique_ptr<_Ewk_File_Chooser_Request> file_chooser_request_;
+#else
   std::unique_ptr<content::FileChooserControllerEfl> file_chooser_;
 #endif
   std::unique_ptr<content::PopupControllerEfl> popup_controller_;
@@ -769,6 +937,10 @@ class EWebView {
       MHTMLCallbackDetails;
   base::IDMap<MHTMLCallbackDetails*> mhtml_callback_map_;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  base::IDMap<IsVideoPlayingCallback*> is_video_playing_callback_map_;
+#endif
+
   typedef WebViewCallback<Ewk_View_Main_Frame_Scrollbar_Visible_Get_Callback,
                           bool>
       MainFrameScrollbarVisibleGetCallback;
@@ -777,6 +949,10 @@ class EWebView {
 
   base::IDMap<BackgroundColorGetCallback*> background_color_get_callback_map_;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  GetMediaDeviceCallback device_cb_;
+#endif
+
   gfx::Size contents_size_;
   double progress_;
   mutable std::string title_;
@@ -796,6 +972,10 @@ class EWebView {
                                  Ewk_View_User_Media_Permission_Query_Callback,
                                  _Ewk_User_Media_Permission_Query*>
       user_media_permission_query_cb_;
+  WebViewErrorPageLoadCallback<Ewk_View_Error_Page_Load_Callback,
+                               Ewk_Error*,
+                               Ewk_Error_Page*>
+      load_error_page_cb_;
   WebViewCallback<Ewk_View_Unfocus_Allow_Callback, Ewk_Unfocus_Direction>
       unfocus_allow_cb_;
   WebViewCallback<Ewk_View_Notification_Permission_Callback,
@@ -831,22 +1011,48 @@ class EWebView {
       long long>
       exceeded_indexed_db_quota_callback_;
   std::unique_ptr<Ewk_Security_Origin> exceeded_indexed_db_quota_origin_;
-
-#if BUILDFLAG(IS_TIZEN)
-  blink::mojom::FileChooserParams::Mode filechooser_mode_;
-#endif
+#if !defined(EWK_BRINGUP)  // FIXME: m114 bringup
   std::map<const _Ewk_Quota_Permission_Request*,
            content::QuotaPermissionContext::PermissionCallback>
       quota_permission_request_map_;
+#endif
+#if BUILDFLAG(IS_TIZEN)
+  blink::mojom::FileChooserParams::Mode filechooser_mode_ =
+      blink::mojom::FileChooserParams::Mode::kOpen;
+  Ecore_Event_Handler* window_rotate_handler_ = nullptr;
+#endif
 
   bool is_initialized_;
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  bool is_processing_edge_scroll_;
+  bool use_early_rwi_;
+  bool rwi_info_showed_;
+  GURL rwi_gurl_;
+  bool is_high_bitrate_ = false;
+
+  base::OnceClosure pending_setfocus_closure_;
+
+  enum PlaybackState {
+    kPlaybackLoad = 0,
+    // kPlaybackReady: player with both audio and video starts prepare and will
+    // acquire audio and video resources (if they are not already taken)
+    kPlaybackReady,
+    kPlaybackStart,
+    kPlaybackFinish,
+    kPlaybackStop,
+  };
+  double current_time_ = 0.0;
+#endif
+
   std::unique_ptr<_Ewk_Back_Forward_List> back_forward_list_;
 
-  static content::WebContentsEflDelegate::WebContentsCreateCallback
+  static content::WebViewDelegate::WebContentsCreateCallback
       create_new_window_web_contents_cb_;
 
- private:
+#if defined(TIZEN_VIDEO_HOLE)
+  void EnableVideoHoleSupportInternal();
+#endif
   gfx::Vector2d previous_scroll_position_;
 
   gfx::Point context_menu_position_;
@@ -865,15 +1071,20 @@ class EWebView {
   std::unique_ptr<aura::client::FocusClient> focus_client_;
   std::unique_ptr<aura::client::WindowParentingClient> window_parenting_client_;
   std::unique_ptr<ui::CompositorObserver> compositor_observer_;
-  content::DateTimeChooserEfl* date_time_chooser_ = nullptr;
 
 #if defined(TIZEN_ATK_SUPPORT)
   std::unique_ptr<EWebAccessibility> eweb_accessibility_;
   bool lazy_initialize_atk_ = false;
 #endif
+#if defined(TIZEN_PEPPER_EXTENSIONS)
+  content::ExtensionSystemDelegateManager::RenderFrameID render_frame_id_;
+#endif
 #if defined(TIZEN_VIDEO_HOLE)
   bool pending_video_hole_setting_ = false;
 #endif
+
+  Ecore_Timer* delayed_show_context_menu_timer_ = nullptr;
+  base::WeakPtrFactory<EWebView> weak_factory_{this};
 };
 
 const unsigned int g_default_tilt_motion_sensitivity = 3;