[M120 Migration][VD] Support EWK Scroll API for TV WebBrowser
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / eweb_view.cc
index c184c32..ce6088c 100644 (file)
 #include "devtools_port_manager.h"
 #include "private/ewk_file_chooser_request_private.h"
 #include "public/ewk_media_downloadable_font_info.h"
+#include "public/ewk_media_parental_rating_info.h"
 #include "public/ewk_media_playback_info_product.h"
+#include "public/ewk_media_subtitle_info_product.h"
 #include "public/ewk_user_media_internal.h"
+#include "third_party/blink/public/platform/web_media_player.h"
 #endif
 
 #if defined(TIZEN_PEPPER_EXTENSIONS)
@@ -324,6 +327,9 @@ void EWebView::VisibleContentChangedCallback(void* user_data,
                                              Evas_Object* /*object*/,
                                              void* event_info) {
   auto view = static_cast<EWebView*>(user_data);
+  if (!view->GetSelectionController()) {
+    return;
+  }
   auto rect = static_cast<Eina_Rectangle*>(event_info);
   view->GetSelectionController()->SetCustomVisibleViewRect(
       gfx::Rect(rect->x, rect->y, rect->w, rect->h));
@@ -494,6 +500,9 @@ EWebView::~EWebView() {
   select_picker_.reset();
   context_menu_.reset();
   mhtml_callback_map_.Clear();
+#if BUILDFLAG(IS_TIZEN_TV)
+  is_video_playing_callback_map_.Clear();
+#endif
 
   compositor_observer_.reset();
 
@@ -627,6 +636,9 @@ bool EWebView::SetPageVisibility(
 
 bool EWebView::CreateNewWindow(
     content::WebViewDelegate::WebContentsCreateCallback cb) {
+#if BUILDFLAG(IS_TIZEN_TV)
+  LOG(INFO) << __FUNCTION__;
+#endif
   create_new_window_web_contents_cb_ = cb;
   Evas_Object* new_object = NULL;
   SmartCallback<EWebViewCallbacks::CreateNewWindow>().call(&new_object);
@@ -844,13 +856,22 @@ void EWebView::EnterDragState() {
 #endif
 
 void EWebView::SetOrientation(int orientation) {
+  LOG(INFO) << "New ori " << orientation << " GetOrientation "
+            << GetOrientation();
   if (GetOrientation() == orientation)
     return;
+  SetRotationChanged(true);
 
   if (orientation == 0 || orientation == 90 || orientation == 180 ||
       orientation == 270) {
 #if !defined(USE_AURA)
     GetWebContentsViewEfl()->SetOrientation(orientation);
+#else
+#if BUILDFLAG(IS_TIZEN)
+    TRACE_EVENT2("viz", "EWebView::SetOrientation", "orientation", orientation,
+                 "this", (void*)this);
+    wcva()->SetOrientation(orientation);
+#endif
 #endif
     int width = 0;
     int height = 0;
@@ -871,8 +892,12 @@ int EWebView::GetOrientation() {
 #if !defined(USE_AURA)
   return GetWebContentsViewEfl()->GetOrientation();
 #else
+#if BUILDFLAG(IS_TIZEN)
+  return wcva()->GetOrientation();
+#else
   return 0;
 #endif
+#endif
 }
 
 void EWebView::Show() {
@@ -1310,13 +1335,11 @@ void EWebView::SetViewLoadErrorPageCallback(
 }
 
 // Remove below code while ewk_error_cancellation_get has been implemented.
-const char* EWebView::InvokeViewLoadErrorPageCallback(
-    const GURL& url,
-    int error_code,
-    const std::string& error_description) {
-  std::unique_ptr<_Ewk_Error> err(
-      new _Ewk_Error(error_code, url.possibly_invalid_spec().c_str(),
-                     error_description.c_str()));
+const char* EWebView::InvokeViewLoadErrorPageCallback(const GURL& url,
+                                                      int error_code,
+                                                      bool is_cancellation) {
+  std::unique_ptr<_Ewk_Error> err(new _Ewk_Error(
+      error_code, is_cancellation, url.possibly_invalid_spec().c_str()));
   _Ewk_Error_Page error_page;
 
   LOG(INFO) << "EWebView::InvokeLoadErrorPageCallback url: "
@@ -1389,12 +1412,13 @@ void EWebView::HandleLongPressGesture(
   convertedParams.x += x;
   convertedParams.y += y;
 
+  bool show_context_menu_now = true;
   if (GetSelectionController() && GetSelectionController()->GetLongPressed()) {
-    bool show_context_menu_now =
-        !GetSelectionController()->HandleLongPressEvent(convertedPoint,
-                                                        convertedParams);
-    if (show_context_menu_now)
-      ShowContextMenuInternal(convertedParams);
+    show_context_menu_now = !GetSelectionController()->HandleLongPressEvent(
+        convertedPoint, convertedParams);
+  }
+  if (show_context_menu_now) {
+    ShowContextMenuInternal(convertedParams);
   }
 }
 
@@ -1685,6 +1709,10 @@ SelectionControllerEfl* EWebView::GetSelectionController() const {
 }
 
 void EWebView::SelectFocusedLink() {
+  if (!rwhva()) {
+    return;
+  }
+
   rwhva()->host()->SelectFocusedLink();
 }
 
@@ -2753,6 +2781,17 @@ void EWebView::InvokeEdgeScrollByCallback(const gfx::Point& offset,
 }
 #endif
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void EWebView::InvokeScrollbarThumbFocusChangedCallback(
+    Ewk_Scrollbar_Orientation orientation,
+    bool focused) {
+  Ewk_Scrollbar_Data data;
+  data.orientation = orientation;
+  data.focused = focused;
+  SmartCallback<EWebViewCallbacks::DidChagneScrollbarsThumbFocus>().call(&data);
+}
+#endif
+
 void EWebView::HandleRendererProcessCrash() {
   content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE,
       base::BindOnce(&EWebView::InvokeWebProcessCrashedCallback,
@@ -3089,6 +3128,11 @@ void EWebView::SendDelayedMessages(RenderViewHost* render_view_host) {
     return;
   }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+  if (pending_setfocus_closure_)
+    std::move(pending_setfocus_closure_).Run();
+#endif
+
   for (auto iter = delayed_messages_.begin(); iter != delayed_messages_.end();
        ++iter) {
     IPC::Message* message = *iter;
@@ -3196,6 +3240,32 @@ void EWebView::SetTranslatedURL(const char* url) {
   rwhva()->aura_efl_helper()->SetTranslatedURL(std::string(url));
   LOG(INFO) << "translate_url:" << url;
 }
+
+bool EWebView::IsVideoPlaying(Ewk_Is_Video_Playing_Callback callback,
+                              void* user_data) {
+  IsVideoPlayingCallback* cb = new IsVideoPlayingCallback(callback, user_data);
+  int callback_id = is_video_playing_callback_map_.Add(cb);
+
+  if (!rwhva() || !rwhva()->aura_efl_helper()) {
+    LOG(ERROR) << "rwhva() or rwhva()->aura_efl_helper() is false";
+    return false;
+  }
+  rwhva()->aura_efl_helper()->RequestVideoPlaying(callback_id);
+  return true;
+}
+
+void EWebView::InvokeIsVideoPlayingCallback(bool is_playing, int callback_id) {
+  IsVideoPlayingCallback* callback =
+      is_video_playing_callback_map_.Lookup(callback_id);
+  if (!callback) {
+    LOG(INFO) << "callback is null";
+    return;
+  }
+
+  LOG(INFO) << __func__ << " ; is_playing : " << is_playing;
+  callback->Run(ewk_view(), is_playing);
+  is_video_playing_callback_map_.Remove(callback_id);
+}
 #endif
 
 void EWebView::RequestManifest(Ewk_View_Request_Manifest_Callback callback,
@@ -3366,6 +3436,116 @@ void EWebView::AddDynamicCertificatePath(const std::string& host,
                                          const std::string& cert_path) {
   web_contents_->AddDynamicCertificatePath(host, cert_path);
 }
+
+void EWebView::NotifySubtitleState(int state, double time_stamp) {
+  LOG(INFO) << "subtitle state: " << state
+            << ",(0-Play : 1-Pause : 2-SeekStart : 3-SeekComplete : 4-Stop "
+               ":5-Resume)";
+  switch (state) {
+    case blink::WebMediaPlayer::kSubtitlePause:
+      SmartCallback<EWebViewCallbacks::SubtitlePause>().call();
+      break;
+    case blink::WebMediaPlayer::kSubtitleStop:
+      SmartCallback<EWebViewCallbacks::SubtitleStop>().call();
+      break;
+    case blink::WebMediaPlayer::kSubtitleResume:
+      SmartCallback<EWebViewCallbacks::SubtitleResume>().call();
+      break;
+    case blink::WebMediaPlayer::kSubtitleSeekStart: {
+      double ts = time_stamp;
+      SmartCallback<EWebViewCallbacks::SubtitleSeekStart>().call(&ts);
+    } break;
+    case blink::WebMediaPlayer::kSubtitleSeekComplete:
+      SmartCallback<EWebViewCallbacks::SubtitleSeekComplete>().call();
+      break;
+    default:
+      NOTREACHED();
+      break;
+  }
+}
+
+void EWebView::NotifySubtitlePlay(int active_track_id,
+                                  const char* url,
+                                  const char* lang) {
+  LOG(INFO) << "id:" << active_track_id << ",url:" << url << ",lang:" << lang;
+  Ewk_Media_Subtitle_Info* subtitle_info =
+      ewkMediaSubtitleInfoCreate(active_track_id, url, lang, 0);
+  SmartCallback<EWebViewCallbacks::SubtitlePlay>().call(
+      static_cast<void*>(subtitle_info));
+  ewkMediaSubtitleInfoDelete(subtitle_info);
+}
+
+void EWebView::NotifySubtitleData(int track_id,
+                                  double time_stamp,
+                                  const std::string& data,
+                                  unsigned int size) {
+  const void* buffer = static_cast<const void*>(data.c_str());
+  Ewk_Media_Subtitle_Data* subtitle_data =
+      ewkMediaSubtitleDataCreate(track_id, time_stamp, buffer, size);
+  SmartCallback<EWebViewCallbacks::SubtitleNotifyData>().call(
+      static_cast<void*>(subtitle_data));
+  ewkMediaSubtitleDataDelete(subtitle_data);
+}
+
+void EWebView::UpdateCurrentTime(double current_time) {
+  current_time_ = current_time;
+}
+
+void EWebView::UpdateEventData(void* data) {
+  LOG(INFO) << "EWebView::UpdateEventData data:" << (char*)data;
+  SmartCallback<EWebViewCallbacks::EVENTData>().call(data);
+}
+
+void EWebView::NotifyParentalRatingInfo(const char* info, const char* url) {
+  LOG(INFO) << "info:" << info << ",url:" << url;
+  Ewk_Media_Parental_Rating_Info* data =
+      ewkMediaParentalRatingInfoCreate(info, url);
+  SmartCallback<EWebViewCallbacks::ParentalRatingInfo>().call(
+      static_cast<void*>(data));
+  ewkMediaParentalRatingInfoDelete(data);
+}
+
+void EWebView::SetParentalRatingResult(const char* url, bool is_pass) {
+  LOG(INFO) << "SetParentalRatingResult,url:" << url
+            << ",pass:" << std::boolalpha << is_pass;
+
+  if (!rwhva() || !rwhva()->aura_efl_helper()){
+    LOG(ERROR) << "rwhva() or rwhva()->aura_efl_helper() is false";
+    return;
+  }
+  rwhva()->aura_efl_helper()->SetParentalRatingResult(
+      static_cast<std::string>(url), is_pass);
+}
+void EWebView::NotifyFirstTimeStamp(unsigned long long timestamp,
+                                    int time_base_num,
+                                    int time_base_den) {
+  Ewk_First_Timestamp_Info* info =
+      ewkFirstTimeStampInfoCreate(timestamp, time_base_num, time_base_den);
+  SmartCallback<EWebViewCallbacks::FirstTimestamp>().call(
+      static_cast<void*>(info));
+  ewkFirstTimeStampInfoDelete(info);
+}
+
+void EWebView::NotifyPESData(const std::string& buf,
+                             unsigned int len,
+                             int media_position) {
+  const void* data = static_cast<const void*>(buf.c_str());
+  Ewk_PES_Info* info = ewkPESInfoCreate(data, len, media_position);
+  SmartCallback<EWebViewCallbacks::PESData>().call(static_cast<void*>(info));
+  ewkPESInfoDelete(info);
+}
+
+void EWebView::SetPreferSubtitleLang(const char* lang_list) {
+  LOG(INFO) << "SetPreferSubtitleLang: " << lang_list;
+  const std::string lang(lang_list ? lang_list : "");
+
+  if (!rwhva()) {
+    LOG(ERROR) << "rwhva() is null";
+    return;
+  }
+
+  rwhva()->aura_efl_helper()->SetPreferSubtitleLang(lang);
+}
 #endif
 
 bool EWebView::SetVisibility(bool enable) {