[M120 Migration][hbbtv] Audio tracks count notification
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / web_contents_delegate_efl.cc
index 688930e..01f2d66 100644 (file)
 
 #include "web_contents_delegate_efl.h"
 
-#include "private/ewk_console_message_private.h"
-#include "private/ewk_error_private.h"
-#include "private/ewk_certificate_private.h"
-#include "private/ewk_custom_handlers_private.h"
-#include "private/ewk_policy_decision_private.h"
-#include "private/ewk_user_media_private.h"
+#include <tuple>
+
+#include "base/strings/utf_string_conversions.h"
+#include "base/trace_event/ttrace.h"
+#include "browser/input_picker/color_chooser_efl.h"
 #include "browser/javascript_dialog_manager_efl.h"
 #include "browser/policy_response_delegate_efl.h"
-#include "browser/inputpicker/color_chooser_efl.h"
-#include "content/common/render_messages_efl.h"
+#include "browser_context_efl.h"
 #include "common/render_messages_ewk.h"
-#include "eweb_view.h"
-#include "eweb_view_callbacks.h"
-#include "base/strings/utf_string_conversions.h"
-#include "content/common/view_messages.h"
-#include "content/browser/renderer_host/render_widget_host_view_efl.h"
-#include "content/public/browser/invalidate_type.h"
+#include "components/password_manager/core/common/password_manager_pref_names.h"
+#include "components/prefs/pref_service.h"
+#include "content/browser/manifest/manifest_manager_host.h"
+#include "content/browser/renderer_host/render_widget_host_view_aura.h"
+#include "content/browser/web_contents/web_contents_impl.h"
+#include "content/common/content_switches_internal.h"
+#include "content/common/render_messages_efl.h"
 #include "content/public/browser/browser_thread.h"
+#include "content/public/browser/file_select_listener.h"
+#include "content/public/browser/invalidate_type.h"
 #include "content/public/browser/navigation_entry.h"
-#include "content/public/browser/favicon_status.h"
-#include "content/public/common/favicon_url.h"
-#include "content/common/date_time_suggestion.h"
+#include "content/public/browser/navigation_handle.h"
+#include "content/public/browser/render_view_host.h"
+#include "eweb_view.h"
+#include "eweb_view_callbacks.h"
 #include "net/base/load_states.h"
+#include "net/cert/x509_certificate.h"
 #include "net/http/http_response_headers.h"
-#include "printing/pdf_metafile_skia.h"
+#include "private/ewk_certificate_private.h"
+#include "private/ewk_console_message_private.h"
+#include "private/ewk_error_private.h"
+#include "private/ewk_policy_decision_private.h"
+#include "private/ewk_user_media_private.h"
+#include "private/webview_delegate_ewk.h"
+#include "third_party/blink/public/common/input/web_input_event.h"
+#include "third_party/blink/public/common/manifest/manifest_util.h"
+#include "tizen/system_info.h"
 #include "url/gurl.h"
-#include "browser/favicon/favicon_service.h"
+#include "web_contents_observer_efl.h"
+
+#if BUILDFLAG(IS_TIZEN)
+#include <app_control.h>
+#include <app_manager.h>
+#endif
 
-#include "tizen_webview/public/tw_web_context.h"
+#if BUILDFLAG(IS_TIZEN_TV)
+#include "browser/mixed_content_observer.h"
+#include "devtools_port_manager.h"
+#endif
 
-#if defined(OS_TIZEN_MOBILE)
+#if defined(TIZEN_MULTIMEDIA)
+#include "base/functional/callback.h"
 #include "content/public/browser/media_capture_devices.h"
-#include "media/video/capture/tizen/video_capture_device_tizen.h"
+#include "third_party/blink/public/mojom/mediastream/media_stream.mojom.h"
+#endif
+
+#if defined(TIZEN_AUTOFILL_FW)
+#include "browser/autofill/autofill_request_manager.h"
 #endif
 
-#ifdef TIZEN_AUTOFILL_SUPPORT
-#include "browser/autofill/autofill_manager_delegate_efl.h"
+#if defined(TIZEN_AUTOFILL)
+#include "base/command_line.h"
+#include "browser/autofill/autofill_client_efl.h"
 #include "browser/password_manager/password_manager_client_efl.h"
-#include "components/autofill/content/browser/content_autofill_driver.h"
+#include "components/autofill/content/browser/content_autofill_driver_factory.h"
 #include "components/autofill/core/browser/autofill_client.h"
 #include "components/autofill/core/browser/autofill_manager.h"
+#include "components/autofill/core/common/autofill_switches.h"
 #include "components/web_modal/web_contents_modal_dialog_manager.h"
 
 using autofill::AutofillManager;
-using autofill::AutofillManagerDelegateEfl;
-using autofill::ContentAutofillDriver;
+using autofill::AutofillClientEfl;
+using autofill::ContentAutofillDriverFactory;
 using password_manager::PasswordManagerClientEfl;
 #endif
-using base::string16;
-using namespace tizen_webview;
+using std::u16string;
 using namespace ui;
 
 namespace content {
 
-void WritePdfDataToFile(printing::PdfMetafileSkia* metafile, const base::FilePath& filename) {
-  DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
-  DCHECK(metafile);
-  base::File file(filename, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
-  metafile->SaveTo(&file);
-  file.Close();
-  delete metafile;
+#if BUILDFLAG(IS_TIZEN) && defined(TIZEN_MULTIMEDIA)
+static const blink::MediaStreamDevice* GetRequestedAudioDevice(
+    const std::string& device_id) {
+  const blink::MediaStreamDevices& audio_devices =
+      MediaCaptureDevices::GetInstance()->GetAudioCaptureDevices();
+  if (audio_devices.empty())
+    return NULL;
+  if (device_id.length() == 0)
+    return &(*audio_devices.begin());
+
+  for (blink::MediaStreamDevices::const_iterator i = audio_devices.begin();
+       i != audio_devices.end(); i++) {
+    if (i->id.compare(device_id) == 0)
+      return &(*i);
+  }
+
+  NOTREACHED();
+  return nullptr;
 }
 
-#if defined(OS_TIZEN_MOBILE)
-static const content::MediaStreamDevice*
-  GetRequestedVideoDevice(std::string& device_id) {
-  const content::MediaStreamDevices& video_devices =
+/* LCOV_EXCL_START */
+static const blink::MediaStreamDevice* GetRequestedVideoDevice(
+    const std::string& device_id) {
+  const blink::MediaStreamDevices& video_devices =
       MediaCaptureDevices::GetInstance()->GetVideoCaptureDevices();
   if (video_devices.empty())
-    return NULL;
+    return nullptr;
   if (device_id.length() == 0)
     return &(*video_devices.begin());
-  return video_devices.FindById(device_id);
+
+  for (blink::MediaStreamDevices::const_iterator i = video_devices.begin();
+       i != video_devices.end(); i++) {
+    if (i->id.compare(device_id) == 0)
+      return &(*i);
+  }
+
+  NOTREACHED();
+  return nullptr;
 }
+/* LCOV_EXCL_STOP */
 #endif
 
 WebContentsDelegateEfl::WebContentsDelegateEfl(EWebView* view)
-    : WebContentsObserver(&view->web_contents())
-    , web_view_(view)
-    , is_fullscreen_(false)
-    , web_contents_(view->web_contents())
-    , document_created_(false)
-    , dialog_manager_(NULL)
-    , weak_ptr_factory_(this) {
-#ifdef TIZEN_AUTOFILL_SUPPORT
-  AutofillManagerDelegateEfl::CreateForWebContents(&web_contents_);
-  AutofillManagerDelegateEfl* autofill_manager =
-      AutofillManagerDelegateEfl::FromWebContents(&web_contents_);
-  autofill_manager->SetEWebView(view);
-  ContentAutofillDriver::CreateForWebContentsAndDelegate(&web_contents_,
-      autofill_manager,
-      EWebView::GetPlatformLocale(),
-      AutofillManager::DISABLE_AUTOFILL_DOWNLOAD_MANAGER);
-  PasswordManagerClientEfl::CreateForWebContents(&web_contents_);
+    : web_view_(view),
+      web_contents_(view->web_contents()),
+      contents_observer_(std::make_unique<WebContentsObserverEfl>(view, this)) {
+#if BUILDFLAG(IS_TIZEN_TV)
+  MixedContentObserver::CreateForWebContents(&web_contents_);
+#endif
+#if defined(TIZEN_AUTOFILL)
+  if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+          autofill::switches::kDisableAutofill)) {
+    AutofillClientEfl::CreateForWebContents(&web_contents_);
+    AutofillClientEfl* autofill_client =
+        AutofillClientEfl::FromWebContents(&web_contents_);
+    if (autofill_client)
+      autofill_client->SetEWebView(view);
+    PasswordManagerClientEfl::CreateForWebContentsWithAutofillClient(
+        &web_contents_, autofill_client);
+  }
+#if defined(TIZEN_AUTOFILL_FW)
+  LOG(INFO) << "[Autofill] " << __FUNCTION__ << " Create AutofillRequest";
+  autofill::AutofillRequestManager::GetInstance()->CreateAutofillRequest(
+      view->ewk_view());
+#endif
 #endif
 }
 
 WebContentsDelegateEfl::~WebContentsDelegateEfl() {
   // It's important to delete web_contents_ before dialog_manager_
   // destructor of web contents uses dialog_manager_
+  if (dialog_manager_)
+    delete dialog_manager_;
+}
 
-  delete dialog_manager_;
+static bool IsMainFrame(RenderFrameHost* render_frame_host) {
+  return !render_frame_host->GetParent();
 }
 
 WebContents* WebContentsDelegateEfl::OpenURLFromTab(
-  WebContents* source,
-  const content::OpenURLParams& params) {
-
+    WebContents* source,
+    const OpenURLParams& params) {
   const GURL& url = params.url;
   WindowOpenDisposition disposition = params.disposition;
 
-  if (!source || (disposition != CURRENT_TAB &&
-                  disposition != NEW_FOREGROUND_TAB &&
-                  disposition != NEW_BACKGROUND_TAB &&
-                  disposition != OFF_THE_RECORD)) {
+  if (!source || (disposition != WindowOpenDisposition::CURRENT_TAB &&
+                  disposition != WindowOpenDisposition::NEW_FOREGROUND_TAB &&
+                  disposition != WindowOpenDisposition::NEW_BACKGROUND_TAB &&
+                  disposition != WindowOpenDisposition::OFF_THE_RECORD)) {
     NOTIMPLEMENTED();
     return NULL;
   }
 
-  if (disposition == NEW_FOREGROUND_TAB ||
-      disposition == NEW_BACKGROUND_TAB ||
-      disposition == OFF_THE_RECORD) {
+  if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB ||
+      disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB ||
+      disposition == WindowOpenDisposition::OFF_THE_RECORD) {
     Evas_Object* new_object = NULL;
-    web_view_->SmartCallback<EWebViewCallbacks::CreateNewWindow>().call(&new_object);
+    if (IsMobileProfile() &&
+        disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) {
+      web_view_->SmartCallback<EWebViewCallbacks::CreateNewBackgroundWindow>()
+          .call(&new_object);
+    } else {
+      web_view_->SmartCallback<EWebViewCallbacks::CreateNewWindow>().call(
+          &new_object);
+    }
 
     if (!new_object)
       return NULL;
 
-    EWebView* wv = EWebView::FromEvasObject(new_object);
+    if (disposition == WindowOpenDisposition::NEW_FOREGROUND_TAB)
+      ActivateContents(source);
+
+    EWebView* wv =
+        WebViewDelegateEwk::GetInstance().GetEWebViewFromEwkView(new_object);
     DCHECK(wv);
-    wv->SetURL(url.spec().c_str());
+    wv->SetURL(url);
     return NULL;
   }
 
@@ -144,34 +208,82 @@ WebContents* WebContentsDelegateEfl::OpenURLFromTab(
   return source;
 }
 
+#if BUILDFLAG(IS_TIZEN_TV)
+void WebContentsDelegateEfl::NotifyMediaStateChanged(uint32_t type,
+                                                     uint32_t previous,
+                                                     uint32_t current) {
+  if (!web_view_) {
+    LOG(ERROR) << "web_view_ is null";
+    return;
+  }
+
+  web_view_->NotifyMediaStateChanged(type, previous, current);
+}
+
+void WebContentsDelegateEfl::GetMediaDeviceList(EnumerationCallback cb) {
+  MediaCaptureDevices::GetInstance()->GetMediaDeviceList(std::move(cb));
+}
+#endif
+
 void WebContentsDelegateEfl::NavigationStateChanged(
     WebContents* source, InvalidateTypes changed_flags) {
-  if (changed_flags & content::INVALIDATE_TYPE_URL) {
-    const char* url = source->GetVisibleURL().spec().c_str();
+  // We always notfiy clients about title invalidation, even if its text
+  // didn't actually change. This is to maintain EWK API consistency.
+  if (changed_flags & INVALIDATE_TYPE_TITLE) {
+    web_view_->SmartCallback<EWebViewCallbacks::TitleChange>().call(
+        base::UTF16ToUTF8(source->GetTitle()).c_str());
+  }
+
+  // We only notify clients if visible url actually changed, because on some
+  // pages we would get notifications with flag INVALIDATE_TYPE_URL even when
+  // visible url did not change.
+  if ((changed_flags & INVALIDATE_TYPE_URL) &&
+       last_visible_url_ != source->GetVisibleURL()) {
+    last_visible_url_ = source->GetVisibleURL();
+    const char* url = last_visible_url_.spec().c_str();
+
     web_view_->SmartCallback<EWebViewCallbacks::URLChanged>().call(url);
     web_view_->SmartCallback<EWebViewCallbacks::URIChanged>().call(url);
+    web_view_->ResetContextMenuController();
+    auto rwhva = static_cast<RenderWidgetHostViewAura*>(
+        web_contents_.GetRenderWidgetHostView());
+    if (rwhva && rwhva->offscreen_helper()) {
+      if (auto selection_controller =
+              rwhva->offscreen_helper()->GetSelectionController()) {
+        selection_controller->ClearSelection();
+      }
+    }
   }
 }
 
-void WebContentsDelegateEfl::LoadingStateChanged(WebContents* source,
-                                                 bool to_different_document) {
-  if (source->IsLoading())
-    web_view_->SmartCallback<EWebViewCallbacks::LoadProgressStarted>().call();
-  else
-    web_view_->SmartCallback<EWebViewCallbacks::LoadProgressFinished>().call();
-}
-
-void WebContentsDelegateEfl::LoadProgressChanged(WebContents* source, double progress) {
-  web_view_->SetProgressValue(progress);
-  web_view_->SmartCallback<EWebViewCallbacks::LoadProgress>().call(&progress);
+void WebContentsDelegateEfl::AddNewContents(
+    WebContents* source,
+    std::unique_ptr<WebContents> new_contents,
+    const GURL& target_url,
+    WindowOpenDisposition disposition,
+    const blink::mojom::WindowFeatures& window_features,
+    bool user_gesture,
+    bool* was_blocked) {
+  // Initialize the delegate for the new contents here using source's delegate
+  // as it will be needed to create a new window with the pre-created
+  // new contents in case the opener is suppressed. Otherwise, the delegate
+  // had already been initialized in EWebView::InitializeContent()
+  if (!new_contents->GetDelegate())
+    new_contents->SetDelegate(this);
+
+  // EWebView takes the ownership of new WebContents in
+  // EWebView::InitializeContent(). So, we can release the ownership of new
+  // WebContents here.
+  std::ignore = new_contents.release();
 }
 
 bool WebContentsDelegateEfl::ShouldCreateWebContents(
     WebContents* web_contents,
-    int route_id,
-    int main_frame_route_id,
-    WindowContainerType window_container_type,
-    const string16& /*frame_name*/,
+    RenderFrameHost* opener,
+    SiteInstance* source_site_instance,
+    mojom::WindowContainerType window_container_type,
+    const GURL& opener_url,
+    const std::string& frame_name,
     const GURL& target_url,
     const std::string& partition_id,
     SessionStorageNamespace* session_storage_namespace) {
@@ -181,276 +293,274 @@ bool WebContentsDelegateEfl::ShouldCreateWebContents(
   return false;
 }
 
-bool WebContentsDelegateEfl::ShouldCreateWebContentsAsync(
-    NewWindowDecideCallback callback, const GURL& target_url) {
-  // this method is called ONLY when creating new window - no matter what type
-  scoped_ptr<_Ewk_Policy_Decision> pd(
-      new _Ewk_Policy_Decision(web_view_, callback));
-  pd->ParseUrl(target_url);
-  web_view_->SmartCallback<EWebViewCallbacks::NewWindowPolicyDecision>().call(pd.get());
-
-  if (pd->isSuspended()) {
-    // it will be deleted later after it's used/ignored/downloaded
-    pd.release();
-  } else if (!pd->isDecided()) {
-    pd->Use();
-  }
-  return true;
-}
-
-bool WebContentsDelegateEfl::WebContentsCreateAsync(
-    WebContentsCreateCallback callback) {
-  web_view_->CreateNewWindow(callback);
-  return true;
-}
-
 void WebContentsDelegateEfl::CloseContents(WebContents* source) {
   web_view_->SmartCallback<EWebViewCallbacks::WindowClosed>().call();
 }
 
-void WebContentsDelegateEfl::EnterFullscreenModeForTab(content::WebContents* web_contents,
-      const GURL& origin) {
-   is_fullscreen_ = true;
-   web_view_->SmartCallback<EWebViewCallbacks::EnterFullscreen>().call();
+void WebContentsDelegateEfl::EnterFullscreenModeForTab(
+    RenderFrameHost* requesting_frame,
+    const blink::mojom::FullscreenOptions& options) {
+  is_fullscreen_ = true;
+  web_view_->SmartCallback<EWebViewCallbacks::EnterFullscreen>().call();
 }
 
-void WebContentsDelegateEfl::ExitFullscreenModeForTab(content::WebContents* web_contents) {
-   is_fullscreen_ = false;
-   web_view_->SmartCallback<EWebViewCallbacks::ExitFullscreen>().call();
+void WebContentsDelegateEfl::ExitFullscreenModeForTab(
+    WebContents* web_contents) {
+  is_fullscreen_ = false;
+  web_view_->SmartCallback<EWebViewCallbacks::ExitFullscreen>().call();
 }
 
 bool WebContentsDelegateEfl::IsFullscreenForTabOrPending(
-      const WebContents* web_contents) const {
+    const WebContents* web_contents) {
   return is_fullscreen_;
 }
 
-void WebContentsDelegateEfl::RegisterProtocolHandler(WebContents* web_contents,
-        const std::string& protocol, const GURL& url, bool user_gesture) {
-  scoped_ptr<Ewk_Custom_Handlers_Data> protocol_data(
-      new Ewk_Custom_Handlers_Data(protocol.c_str(),
-          url.host().c_str(), url.spec().c_str()));
-  web_view_->SmartCallback<EWebViewCallbacks::RegisterProtocolHandler>().call(protocol_data.get());
-}
+#if defined(TIZEN_MULTIMEDIA)
+/* LCOV_EXCL_START */
+void WebContentsDelegateEfl::RequestMediaAccessAllow(
+    const MediaStreamRequest& request,
+    MediaResponseCallback callback) {
+  blink::mojom::StreamDevicesSet stream_devices_set;
+  stream_devices_set.stream_devices.emplace_back(
+      blink::mojom::StreamDevices::New());
+  blink::mojom::StreamDevices& stream_devices =
+      *stream_devices_set.stream_devices[0];
+
+  if (request.audio_type ==
+      blink::mojom::MediaStreamType::DEVICE_AUDIO_CAPTURE) {
+    const blink::MediaStreamDevice* audio_device =
+        GetRequestedAudioDevice(request.requested_audio_device_id);
+    if (audio_device) {
+      stream_devices.audio_device = *audio_device;
+    } else {
+      std::move(callback).Run(
+          blink::mojom::StreamDevicesSet(),
+          blink::mojom::MediaStreamRequestResult::NOT_SUPPORTED,
+          std::unique_ptr<MediaStreamUI>());
+      return;
+    }
+  }
 
-#if defined(TIZEN_MULTIMEDIA_SUPPORT)
-WebContentsDelegateEfl::PendingAccessRequest::PendingAccessRequest(
-  const content::MediaStreamRequest& request,
-  const content::MediaResponseCallback& callback)
-  : request(request)
-  , callback(callback) {
-}
+  if (request.video_type ==
+      blink::mojom::MediaStreamType::DEVICE_VIDEO_CAPTURE) {
+    const blink::MediaStreamDevice* video_device =
+        GetRequestedVideoDevice(request.requested_video_device_id);
+    if (video_device) {
+      stream_devices.video_device = *video_device;
+    } else {
+      std::move(callback).Run(
+          blink::mojom::StreamDevicesSet(),
+          blink::mojom::MediaStreamRequestResult::NOT_SUPPORTED,
+          std::unique_ptr<MediaStreamUI>());
+      return;
+    }
+  }
 
-WebContentsDelegateEfl::PendingAccessRequest::~PendingAccessRequest() {
+  std::move(callback).Run(stream_devices_set,
+                          blink::mojom::MediaStreamRequestResult::OK,
+                          std::unique_ptr<MediaStreamUI>());
 }
+/* LCOV_EXCL_STOP */
 
-void WebContentsDelegateEfl::OnAccessRequestResponse(bool allowed) {
-  MediaStreamDevices devices;
-  if (requests_queue_.empty()) {
-    LOG(ERROR) << __FUNCTION__ << " Empty Queue ";
-    return;
-  }
-  PendingAccessRequest pending_request = requests_queue_.front();
-  if (pending_request.callback.is_null()) {
-    requests_queue_.pop_front();
-    LOG(ERROR) << __FUNCTION__ << " Invalid Callback ";
-    return;
-  }
-  if (allowed) {
-    if (pending_request.request.audio_type == content::MEDIA_DEVICE_AUDIO_CAPTURE) {
-      devices.push_back(MediaStreamDevice(pending_request.request.audio_type,
-                                          "default", "Default"));
-    }
-    if (pending_request.request.video_type == content::MEDIA_DEVICE_VIDEO_CAPTURE) {
-#if defined(OS_TIZEN_MOBILE)
-      const content::MediaStreamDevice* video_device =
-          GetRequestedVideoDevice(pending_request.request.requested_video_device_id);
-      if (video_device) {
-        devices.push_back(*video_device);
-      } else {
-        LOG(ERROR) << "Error in device request, declining request";
-        pending_request.callback.Run(MediaStreamDevices(),
-                                     MEDIA_DEVICE_NOT_SUPPORTED,
-                                     scoped_ptr<MediaStreamUI>());
-      }
-#else
-      devices.push_back(MediaStreamDevice(pending_request.request.video_type,
-                                          "/dev/video0", "1"));
-#endif
-    }
-    pending_request.callback.Run(devices, MEDIA_DEVICE_OK,scoped_ptr<MediaStreamUI>());
-  } else {
-    LOG(ERROR) << __FUNCTION__ << " Decline request with empty list";
-    pending_request.callback.Run(MediaStreamDevices(),
-                                 MEDIA_DEVICE_NOT_SUPPORTED,
-                                 scoped_ptr<MediaStreamUI>());
-  }
-  requests_queue_.pop_front();
+void WebContentsDelegateEfl::RequestMediaAccessDeny(
+    const MediaStreamRequest& request,
+    MediaResponseCallback callback) {
+  std::move(callback).Run(blink::mojom::StreamDevicesSet(),
+                          blink::mojom::MediaStreamRequestResult::NOT_SUPPORTED,
+                          std::unique_ptr<MediaStreamUI>());
 }
 
 bool WebContentsDelegateEfl::CheckMediaAccessPermission(
-    WebContents* web_contents,
+    RenderFrameHost* render_frame_host,
     const GURL& security_origin,
-    MediaStreamType type) {
+    blink::mojom::MediaStreamType type) {
   return true;
 }
 
 void WebContentsDelegateEfl::RequestMediaAccessPermission(
-        WebContents* web_contents,
-        const MediaStreamRequest& request,
-        const MediaResponseCallback& callback) {
-  //send callback to application to request for user permission.
-  _Ewk_User_Media_Permission_Request* media_permission_request =
-    new _Ewk_User_Media_Permission_Request(web_view_, request,this);
-  requests_queue_.push_back(PendingAccessRequest(request, callback));
-  web_view_->SmartCallback<EWebViewCallbacks::UserMediaPermission>().call(
-    media_permission_request);
+    WebContents* web_contents,
+    const MediaStreamRequest& request,
+    MediaResponseCallback callback) {
+  std::unique_ptr<_Ewk_User_Media_Permission_Request> media_permission_request(
+      new _Ewk_User_Media_Permission_Request(this, request,
+                                             std::move(callback)));
+
+  Eina_Bool callback_result = EINA_FALSE;
+  if (!web_view_->InvokeViewUserMediaPermissionCallback(
+          media_permission_request.get(), &callback_result)) {
+    web_view_->SmartCallback<EWebViewCallbacks::UserMediaPermission>()
+        .call(  // LCOV_EXCL_LINE
+            media_permission_request.get());
+  }
+
+  // if policy is suspended, the API takes over the policy object lifetime
+  // and policy will be deleted after decision is made
+  if (media_permission_request->IsSuspended())
+    std::ignore = media_permission_request.release();
+  /* LCOV_EXCL_START */
+  else if (!media_permission_request->IsDecided())
+    media_permission_request->ProceedPermissionCallback(false);
+  /* LCOV_EXCL_STOP */
 }
 #endif
 
-void WebContentsDelegateEfl::OnAuthRequired(net::URLRequest* request,
-                                            const std::string& realm,
+void WebContentsDelegateEfl::OnAuthRequired(const std::string& realm,
+                                            const GURL& url,
                                             LoginDelegateEfl* login_delegate) {
-  web_view_->InvokeAuthCallback(login_delegate, request->url(), realm);
-}
-
-void WebContentsDelegateEfl::DidStartProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
-                                                             const GURL& validated_url,
-                                                             bool is_error_page,
-                                                             bool is_iframe_srcdoc) {
-  web_view_->SmartCallback<EWebViewCallbacks::ProvisionalLoadStarted>().call();
+  web_view_->InvokeAuthCallback(login_delegate, url, realm);
 }
 
-void WebContentsDelegateEfl::DidCommitProvisionalLoadForFrame(RenderFrameHost* render_frame_host,
-                                                              const GURL& url,
-                                                              ui::PageTransition transition_type) {
-  web_view_->SmartCallback<EWebViewCallbacks::LoadCommitted>().call();
-}
-
-
-void WebContentsDelegateEfl::DidNavigateMainFrame(const LoadCommittedDetails& details,
-                                                  const FrameNavigateParams& params) {
-  // The condition checks whether the main frame navigated to a different page,
-  // not scrolled to a fragment inside the current page.
-  if (details.is_navigation_to_different_page())
-    web_view_->SmartCallback<EWebViewCallbacks::LoadStarted>().call();
-}
-
-void WebContentsDelegateEfl::DocumentOnLoadCompletedInMainFrame() {
-  web_view_->SmartCallback<EWebViewCallbacks::LoadFinished>().call();
-}
-
-void WebContentsDelegateEfl::DidNavigateAnyFrame(RenderFrameHost* render_frame_host, const LoadCommittedDetails& details, const FrameNavigateParams& params) {
-  web_view_->SmartCallback<EWebViewCallbacks::ProvisionalLoadRedirect>().call();
-  static_cast<BrowserContextEfl*>(web_contents_.GetBrowserContext())->AddVisitedURLs(params.redirects);
-}
-
-void WebContentsDelegateEfl::DidFinishLoad(RenderFrameHost* render_frame_host,
-                                           const GURL& validated_url) {
-  if (render_frame_host->GetParent())
+void WebContentsDelegateEfl::RequestCertificateConfirm(
+    WebContents* /*web_contents*/,
+    int cert_error,
+    const net::SSLInfo& ssl_info,
+    const GURL& url,
+    bool is_main_frame_request,
+    bool /*strict_enforcement*/,
+    base::OnceCallback<void(CertificateRequestResultType)> callback) {
+  std::string pem_certificate;
+  const GURL request_url(url);
+  if (!net::X509Certificate::GetPEMEncoded(ssl_info.cert->cert_buffer(),
+                                           &pem_certificate)) {
+    LOG(INFO) << "Certificate for URL: " << request_url.spec()
+              << " could not be opened";
+    std::move(callback).Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL);
     return;
+  }
+  certificate_policy_decision_.reset(new _Ewk_Certificate_Policy_Decision(
+      request_url, pem_certificate, is_main_frame_request, cert_error,
+      std::move(callback)));
 
-  NavigationEntry *entry = web_contents().GetController().GetVisibleEntry();
-  DCHECK(entry);
-  FaviconStatus &favicon = entry->GetFavicon();
-
-  if (favicon.valid) {
-    // check/update the url and favicon url in favicon database
-    FaviconService fs;
-    fs.SetFaviconURLForPageURL(favicon.url, validated_url);
-
-    // download favicon if there is no such in database
-    if (!fs.ExistsForFaviconURL(favicon.url)) {
-      LOG(ERROR) << "[DidFinishLoad] :: no favicon in database for URL: "
-                 << favicon.url.spec();
-      favicon_downloader_.reset(
-        new FaviconDownloader(&web_contents_,
-                              favicon.url,
-                              base::Bind(
-                                &WebContentsDelegateEfl::DidDownloadFavicon,
-                                weak_ptr_factory_.GetWeakPtr())));
-      favicon_downloader_->Start();
+  web_view_->SmartCallback<EWebViewCallbacks::RequestCertificateConfirm>().call(
+      certificate_policy_decision_.get());
+  LOG(INFO) << "Certificate policy decision called for URL: "
+            << request_url.spec() << " with cert_error: " << cert_error;
+
+  // if policy is suspended, the API takes over the policy object lifetime
+  // and policy will be deleted after decision is made
+  if (certificate_policy_decision_->IsSuspended()) {
+    std::ignore = certificate_policy_decision_.release();
+  } else if (!certificate_policy_decision_->IsDecided()) {
+    // When the embeder neither suspended certificate decision nor handled it
+    // inside the smart callback by calling
+    // ewk_certificate_policy_decision_allowed_set
+    // this means the embeder let chromium decide what to do.
+    if (!is_main_frame_request) {
+      // A sub-resource has a certificate error. The user doesn't really
+      // have a context for making the right decision, so block the
+      // request hard.
+      std::move(certificate_policy_decision_->Callback())
+          .Run(content::CERTIFICATE_REQUEST_RESULT_TYPE_DENY);
     } else {
-      web_view_->SmartCallback<EWebViewCallbacks::IconReceived>().call();
+      // By default chromium-efl allows page to be opened with certificate
+      // compromise.
+      certificate_policy_decision_->SetDecision(true);
+      LOG(WARNING) << "Certificate for " << request_url.spec()
+                   << " was compromised";
     }
   }
-
-  web_contents_.Focus();
 }
 
+void WebContentsDelegateEfl::VisibleSecurityStateChanged(WebContents* source) {
+  std::unique_ptr<_Ewk_Certificate_Info> certificate_info;
+  std::string pem_certificate;
+  SSLStatus ssl_status = source->GetController().GetVisibleEntry()->GetSSL();
+  scoped_refptr<net::X509Certificate> cert = ssl_status.certificate;
 
-void WebContentsDelegateEfl::DidUpdateFaviconURL(const std::vector<FaviconURL>& candidates) {
-  // select and set proper favicon
-  for (unsigned int i = 0; i < candidates.size(); ++i) {
-    FaviconURL favicon = candidates[i];
-    if (favicon.icon_type == FaviconURL::FAVICON && !favicon.icon_url.is_empty()) {
-      NavigationEntry *entry = web_contents_.GetController().GetVisibleEntry();
-      if (!entry)
-        return;
-      entry->GetFavicon().url = favicon.icon_url;
-      entry->GetFavicon().valid = true;
+  if (!cert) {
+    LOG(ERROR) << "Unable to get certificate!";
+    certificate_info.reset(new _Ewk_Certificate_Info(nullptr, false));
+  } else {
+    if (!net::X509Certificate::GetPEMEncoded(cert->cert_buffer(),
+                                             &pem_certificate)) {
+      LOG(ERROR) << "Unable to get encoded PEM!";
       return;
     }
+    // Note: The implementation below is a copy of the one in
+    // ChromeAutofillClient::IsContextSecure, and should be kept in sync
+    // until crbug.com/505388 gets implemented.
+    bool is_context_secure =
+        ssl_status.certificate &&
+        !net::IsCertStatusError(ssl_status.cert_status) &&
+        !(ssl_status.content_status & content::SSLStatus::RAN_INSECURE_CONTENT);
+
+    certificate_info.reset(
+        new _Ewk_Certificate_Info(pem_certificate.c_str(), is_context_secure));
   }
-  return;
+  web_view_->SmartCallback<EWebViewCallbacks::SSLCertificateChanged>().call(
+      certificate_info.get());
 }
 
-void WebContentsDelegateEfl::DidDownloadFavicon(bool success, const GURL& icon_url, const SkBitmap& bitmap) {
-  favicon_downloader_.reset();
-  if (success) {
-    FaviconService fs;
-    fs.SetBitmapForFaviconURL(bitmap, icon_url);
-    // emit "icon,received"
-    web_view_->SmartCallback<EWebViewCallbacks::IconReceived>().call();
+void WebContentsDelegateEfl::ActivateContents(WebContents* contents) {
+#if BUILDFLAG(IS_TIZEN)
+  app_control_h app_control = nullptr;
+  int ret = app_control_create(&app_control);
+  if (ret != APP_CONTROL_ERROR_NONE) {
+    LOG(ERROR) << "app_control_create is failed with err " << ret;
+    return;
   }
-}
 
-void WebContentsDelegateEfl::RequestCertificateConfirm(WebContents* /*web_contents*/,
-                                                      int cert_error,
-                                                      const net::SSLInfo& ssl_info,
-                                                      const GURL& url,
-                                                      ResourceType /*resource_type*/,
-                                                      bool /*overridable*/,
-                                                      bool /*strict_enforcement*/,
-                                                      const base::Callback<void(bool)>& callback,
-                                                      CertificateRequestResultType* result) {
-  DCHECK(result);
-  std::string pem_certificate;
-  if (!net::X509Certificate::GetPEMEncoded(ssl_info.cert->os_cert_handle(), &pem_certificate)) {
-    *result = content::CERTIFICATE_REQUEST_RESULT_TYPE_CANCEL;
+  std::unique_ptr<std::remove_pointer<app_control_h>::type,
+                  decltype(app_control_destroy)*>
+      auto_release{app_control, app_control_destroy};
+
+  char* app_id = nullptr;
+  ret = app_manager_get_app_id(getpid(), &app_id);
+  if (ret != APP_MANAGER_ERROR_NONE) {
+    LOG(ERROR) << "app_manager_get_app_id is failed with err " << ret;
     return;
   }
-  certificate_policy_decision_.reset(new _Ewk_Certificate_Policy_Decision(url,
-                                                                        pem_certificate,
-                                                                        cert_error,
-                                                                        callback));
-  web_view_->SmartCallback<EWebViewCallbacks::RequestCertificateConfirm>().call(
-      certificate_policy_decision_.get());
 
-  // if policy is suspended, the API takes over the policy object lifetime
-  // and policy will be deleted after decision is made
-  if (certificate_policy_decision_->isSuspended()) {
-    certificate_policy_decision_.release();
-  } else {
-    certificate_policy_decision_->setDecision(true);
+  ret = app_control_set_app_id(app_control, app_id);
+  if (app_id)
+    free(app_id);
+  if (ret != APP_CONTROL_ERROR_NONE) {
+    LOG(ERROR) << "app_control_set_app_id is failed with err " << ret;
+    return;
+  }
+
+  ret = app_control_send_launch_request(app_control, nullptr, nullptr);
+  if (ret != APP_CONTROL_ERROR_NONE) {
+    LOG(ERROR) << "app_control_send_launch_request is failed with err " << ret;
+    return;
   }
+#endif
 }
 
-void WebContentsDelegateEfl::SetContentSecurityPolicy(const std::string& policy, Ewk_CSP_Header_Type header_type) {
-  if (document_created_) {
-    RenderViewHost* rvh = web_contents_.GetRenderViewHost();
-    rvh->Send(new EwkViewMsg_SetCSP(rvh->GetRoutingID(), policy, header_type));
-  } else {
-    DCHECK(!pending_content_security_policy_.get());
-    pending_content_security_policy_.reset(new ContentSecurityPolicy(policy, header_type));
+void WebContentsDelegateEfl::SetContentSecurityPolicy(
+    const std::string& policy,
+    Ewk_CSP_Header_Type header_type) {
+  contents_observer_->SetContentSecurityPolicy(policy, header_type);
+}
+
+#if defined(TIZEN_AUTOFILL)
+void WebContentsDelegateEfl::UpdateAutofillIfRequired() {
+  if (AutofillClientEfl* autofill_client =
+          AutofillClientEfl::FromWebContents(&web_contents_)) {
+    autofill_client->UpdateAutofillIfRequired();
   }
 }
+#endif
 
-void WebContentsDelegateEfl::UpdateFormNavigation(int formElementCount,
-    int currentNodeIndex, bool prevState, bool nextState) {
-  web_view_->UpdateFormNavigation(formElementCount, currentNodeIndex,
-      prevState, nextState);
+void WebContentsDelegateEfl::OnDidChangeFocusedNodeBounds(
+    const gfx::RectF& focused_node_bounds) {
+#if defined(TIZEN_AUTOFILL)
+  if (AutofillClientEfl* autofill_client =
+          AutofillClientEfl::FromWebContents(&web_contents_)) {
+    autofill_client->DidChangeFocusedNodeBounds(focused_node_bounds);
+  }
+#endif
 }
 
+#if defined(TIZEN_AUTOFILL_FW)
+void WebContentsDelegateEfl::ResetLastInteractedElements() {
+  if (AutofillClientEfl* autofill_client =
+          AutofillClientEfl::FromWebContents(&web_contents_)) {
+    autofill_client->ResetLastInteractedElements();
+  }
+}
+#endif
+
 void WebContentsDelegateEfl::FindReply(WebContents* web_contents,
                                        int request_id,
                                        int number_of_matches,
@@ -458,146 +568,361 @@ void WebContentsDelegateEfl::FindReply(WebContents* web_contents,
                                        int active_match_ordinal,
                                        bool final_update) {
   if (final_update && request_id == web_view_->current_find_request_id()) {
-    unsigned int uint_number_of_matches = static_cast<unsigned int>(number_of_matches);
-    web_view_->SmartCallback<EWebViewCallbacks::TextFound>().call(&uint_number_of_matches);
+    unsigned int uint_number_of_matches =
+        static_cast<unsigned int>(number_of_matches);
+    web_view_->SmartCallback<EWebViewCallbacks::TextFound>().call(
+        &uint_number_of_matches);
+  }
+}
+
+#if defined(TIZEN_TBM_SUPPORT)
+void WebContentsDelegateEfl::DidRenderOffscreenFrame(void* buffer) {
+  web_view_->SmartCallback<EWebViewCallbacks::OffscreenFrameRendered>().call(
+      buffer);
+}
+#endif
+
+void WebContentsDelegateEfl::DidRenderFrame() {
+  // Call FrameRendered callback when loading and first layout is finished.
+  if (!did_render_frame_ && did_first_visually_non_empty_paint_ &&
+      (web_view_->GetProgressValue() > 0.1)) {
+    did_first_visually_non_empty_paint_ = false;
+    did_render_frame_ = true;
+    TTRACE_WEB("WebContentsDelegateEfl::DidRenderFrame");
+    LOG(INFO) << "WebContentsDelegateEfl::DidRenderFrame";
+
+    // "frame,rendered" message is triggered as soon as rendering of a frame
+    // is completed.
+    web_view_->SmartCallback<EWebViewCallbacks::FrameRendered>().call(0);
   }
 }
 
+void WebContentsDelegateEfl::DidChangeInputType(bool is_password_input) {
+  web_view_->UpdateContextMenu(is_password_input);
+}
+
 JavaScriptDialogManager* WebContentsDelegateEfl::GetJavaScriptDialogManager(
-      WebContents* source) {
+    WebContents* source) {
   if (!dialog_manager_)
     dialog_manager_ = new JavaScriptDialogManagerEfl();
   return dialog_manager_;
 }
 
-void WebContentsDelegateEfl::OnUpdateSettings(const Ewk_Settings *settings) {
-#ifdef TIZEN_AUTOFILL_SUPPORT
-  PasswordManagerClientEfl *client =
+void WebContentsDelegateEfl::OnUpdateSettings(const Ewk_Settingssettings) {
+#if defined(TIZEN_AUTOFILL)
+  PasswordManagerClientEflclient =
       PasswordManagerClientEfl::FromWebContents(&web_contents_);
-  if(client) {
-    client->SetPasswordManagerSavingEnabled(settings->autofillPasswordForm());
-    client->SetPasswordManagerFillingEnabled(settings->autofillPasswordForm());
+  if (client) {
+    PrefService* prefs = client->GetPrefs();
+    prefs->SetBoolean(password_manager::prefs::kCredentialsEnableService,
+                      settings->autofillPasswordForm());
   }
 #endif
 }
 
-bool WebContentsDelegateEfl::OnMessageReceived(const IPC::Message& message) {
-  bool handled = true;
-  IPC_BEGIN_MESSAGE_MAP(WebContentsDelegateEfl, message)
-    IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_GetContentSecurityPolicy, OnGetContentSecurityPolicy)
-    IPC_MESSAGE_HANDLER(EwkHostMsg_DidPrintPagesToPdf, OnPrintedMetafileReceived)
-    IPC_MESSAGE_HANDLER(EwkHostMsg_WrtMessage, OnWrtPluginMessage)
-    IPC_MESSAGE_HANDLER(EwkHostMsg_FormSubmit, OnFormSubmit)
-    IPC_MESSAGE_HANDLER_DELAY_REPLY(EwkHostMsg_WrtSyncMessage, OnWrtPluginSyncMessage)
-    IPC_MESSAGE_UNHANDLED(handled = false)
-  IPC_END_MESSAGE_MAP()
-
-  return handled;
+void WebContentsDelegateEfl::DidFirstVisuallyNonEmptyPaint() {
+  did_first_visually_non_empty_paint_ = true;
+  web_view_->SmartCallback<EWebViewCallbacks::LoadNonEmptyLayoutFinished>()
+      .call();
+}
+
+void WebContentsDelegateEfl::DidStartLoading() {
+  did_render_frame_ = false;
+}
+
+bool WebContentsDelegateEfl::DidAddMessageToConsole(
+    WebContents* source,
+    blink::mojom::ConsoleMessageLevel level,
+    const std::u16string& message,
+    int32_t line_no,
+    const std::u16string& source_id) {
+  std::unique_ptr<_Ewk_Console_Message> console_message(
+      new _Ewk_Console_Message(static_cast<unsigned>(level),
+                               base::UTF16ToUTF8(message).c_str(), line_no,
+                               base::UTF16ToUTF8(source_id).c_str()));
+  web_view_->SmartCallback<EWebViewCallbacks::ConsoleMessage>().call(
+      console_message.get());
+  return true;
 }
 
-void WebContentsDelegateEfl::OnFormSubmit(const GURL&url) {
-  web_view_->SmartCallback<EWebViewCallbacks::FormSubmit>().call(url.GetContent().c_str());
+void WebContentsDelegateEfl::RunFileChooser(
+    RenderFrameHost* render_frame_host,
+    scoped_refptr<FileSelectListener> listener,
+    const blink::mojom::FileChooserParams& params) {
+  web_view_->ShowFileChooser(std::move(listener), params);
 }
 
-void WebContentsDelegateEfl::OnWrtPluginMessage(const Ewk_Wrt_Message_Data& data) {
-  scoped_ptr<Ewk_Wrt_Message_Data> p(new Ewk_Wrt_Message_Data);
-  p->type = data.type;
-  p->value = data.value;
-  p->id = data.id;
-  p->reference_id = data.reference_id;
-
-  web_view_->SmartCallback<EWebViewCallbacks::WrtPluginsMessage>().call(p.get());
+std::unique_ptr<ColorChooser> WebContentsDelegateEfl::OpenColorChooser(
+    WebContents* web_contents,
+    SkColor color,
+    const std::vector<blink::mojom::ColorSuggestionPtr>& suggestions) {
+  web_view_->RequestColorPicker(SkColorGetR(color), SkColorGetG(color),
+                                SkColorGetB(color), SkColorGetA(color));
+  return std::make_unique<ColorChooserEfl>(*web_contents);
+}
+
+bool WebContentsDelegateEfl::PreHandleGestureEvent(
+    WebContents* source,
+    const blink::WebGestureEvent& event) {
+  blink::WebInputEvent::Type event_type = event.GetType();
+  switch (event_type) {
+    case blink::WebInputEvent::Type::kGestureDoubleTap:
+      if (is_fullscreen_)
+        return true;
+      break;
+    case blink::WebInputEvent::Type::kGesturePinchBegin:
+    case blink::WebInputEvent::Type::kGesturePinchUpdate:
+    case blink::WebInputEvent::Type::kGesturePinchEnd:
+      if (!IsPinchToZoomEnabled() ||
+          IsFullscreenForTabOrPending(&web_contents()))
+        return true;
+      break;
+    default:
+      break;
+  }
+  return false;
 }
 
-void WebContentsDelegateEfl::OnWrtPluginSyncMessage(const Ewk_Wrt_Message_Data& data,
-                                                    IPC::Message* reply) {
-  scoped_ptr<Ewk_Wrt_Message_Data> tmp(new Ewk_Wrt_Message_Data);
-  tmp->type = data.type;
-  web_view_->SmartCallback<EWebViewCallbacks::WrtPluginsMessage>().call(tmp.get());
-  EwkHostMsg_WrtSyncMessage::WriteReplyParams(reply, tmp->value);
-  Send(reply);
+void WebContentsDelegateEfl::BackgroundColorReceived(int callback_id,
+                                                     SkColor bg_color) {
+  web_view_->OnGetBackgroundColor(callback_id, bg_color);
 }
 
-void WebContentsDelegateEfl::DidFirstVisuallyNonEmptyPaint() {
-  web_view_->SmartCallback<EWebViewCallbacks::LoadNonEmptyLayoutFinished>().call();
-  web_view_->SmartCallback<EWebViewCallbacks::FrameRendered>().call(0);
+void WebContentsDelegateEfl::RequestManifestInfo(
+    Ewk_View_Request_Manifest_Callback callback,
+    void* user_data) {
+  WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
+  ManifestManagerHost* manifest_manager_host =
+      ManifestManagerHost::GetOrCreateForPage(wci->GetPrimaryPage());
+  if (!manifest_manager_host) {
+    web_view_->DidRespondRequestManifest(nullptr, callback, user_data);
+    return;
+  }
+
+  manifest_manager_host->GetManifest(
+      base::BindOnce(&WebContentsDelegateEfl::OnDidGetManifest,
+                     base::Unretained(this), callback, user_data));
 }
 
-void WebContentsDelegateEfl::OnGetContentSecurityPolicy(IPC::Message* reply_msg) {
-  document_created_ = true;
-  if (!pending_content_security_policy_.get()) {
-    EwkHostMsg_GetContentSecurityPolicy::WriteReplyParams(reply_msg, std::string(), EWK_DEFAULT_POLICY);
+void WebContentsDelegateEfl::OnDidGetManifest(
+    Ewk_View_Request_Manifest_Callback callback,
+    void* user_data,
+    const GURL& manifest_url,
+    blink::mojom::ManifestPtr manifest) {
+  if (blink::IsEmptyManifest(*manifest)) {
+    web_view_->DidRespondRequestManifest(nullptr, callback, user_data);
   } else {
-    EwkHostMsg_GetContentSecurityPolicy::WriteReplyParams(reply_msg,
-        pending_content_security_policy_->policy, pending_content_security_policy_->header_type);
-    pending_content_security_policy_.reset();
+    _Ewk_View_Request_Manifest ewk_manifest(std::move(manifest));
+    web_view_->DidRespondRequestManifest(&ewk_manifest, callback, user_data);
   }
-  Send(reply_msg);
 }
 
-void WebContentsDelegateEfl::OnPrintedMetafileReceived(const DidPrintPagesParams& params) {
-  base::SharedMemory shared_buf(params.metafile_data_handle, true);
-  if (!shared_buf.Map(params.data_size)) {
-     NOTREACHED() << "couldn't map";
-     return;
+#if BUILDFLAG(IS_TIZEN_TV)
+void WebContentsDelegateEfl::ShowInspectorPortInfo() {
+  std::string mappingInfo;
+  devtools_http_handler::DevToolsPortManager::GetInstance()->GetMappingInfo(
+      mappingInfo);
+  if (web_view_->UseEarlyRWI()) {
+    mappingInfo.append(
+        "\r\nFast RWI is used, [about:blank] is loaded fist instead of \r\n[");
+    mappingInfo.append(web_view_->RWIURL().spec());
+    mappingInfo.append(
+        "]\r\nClick OK button will start the real loading.\r\nNotes:\r\nPlease "
+        "connect to RWI in PC before click OK button.\r\nThen you can get "
+        "network log from the initial loading.\r\nPlease click Record button "
+        "in Timeline panel in PC before click OK button,\r\nThen you can get "
+        "profile log from the initial loading.");
+  }
+  LOG(INFO) << "[RWI] WebContentsDelegateEfl::ShowPortInfo mappingInfo = "
+            << mappingInfo.c_str();
+
+  if (!mappingInfo.empty()) {
+    const GURL kGURL("");
+    WebContentsImpl* wci = static_cast<WebContentsImpl*>(&web_contents_);
+    auto dialog_closed_callback =
+        base::BindOnce([](JavaScriptDialogManager* manager, bool success,
+                          const std::u16string& response) {},
+                       dialog_manager_);
+    wci->RunJavaScriptDialog(
+        wci->GetPrimaryMainFrame(), base::ASCIIToUTF16(mappingInfo),
+        base::ASCIIToUTF16(base::StringPiece("OK")),
+        JAVASCRIPT_DIALOG_TYPE_ALERT, false, std::move(dialog_closed_callback));
   }
-  scoped_ptr<printing::PdfMetafileSkia> metafile(new printing::PdfMetafileSkia);
-  if (!metafile->InitFromData(shared_buf.memory(), params.data_size)) {
-    NOTREACHED() << "Invalid metafile header";
+}
+#endif
+
+#if BUILDFLAG(IS_TIZEN_TV)
+void WebContentsDelegateEfl::UpdateTargetURL(WebContents* /*source*/,
+                                             const GURL& url) {
+  std::string absolute_link_url(url.spec());
+  if (absolute_link_url == last_hovered_url_)
     return;
+
+  if (absolute_link_url.empty()) {
+    // If length is 0, it is not link. send "hover,out,link" callback with the
+    // original hovered URL.
+    web_view_->SmartCallback<EWebViewCallbacks::HoverOutLink>().call(
+        last_hovered_url_.c_str());
+  } else {
+    web_view_->SmartCallback<EWebViewCallbacks::HoverOverLink>().call(
+        absolute_link_url.c_str());
   }
-  BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
-        base::Bind(&WritePdfDataToFile, metafile.release(), params.filename));
+
+  // Update latest hovered url.
+  last_hovered_url_ = absolute_link_url;
+}
+
+void WebContentsDelegateEfl::UpdateCurrentTime(double current_time) {
+  web_view_->UpdateCurrentTime(current_time);
+}
+
+void WebContentsDelegateEfl::UpdateEventData(void* data) {
+  web_view_->UpdateEventData(data);
+}
+
+void WebContentsDelegateEfl::NotifySubtitleState(int state, double time_stamp) {
+  web_view_->NotifySubtitleState(state, time_stamp);
+}
+
+void WebContentsDelegateEfl::NotifySubtitlePlay(int active_track_id,
+                                                const std::string& url,
+                                                const std::string& lang) {
+  web_view_->NotifySubtitlePlay(active_track_id, url.c_str(), lang.c_str());
 }
 
-void WebContentsDelegateEfl::NavigationEntryCommitted(const LoadCommittedDetails& load_details) {
-  web_view_->InvokeBackForwardListChangedCallback();
+void WebContentsDelegateEfl::NotifySubtitleData(int track_id,
+                                                double time_stamp,
+                                                const std::string& data,
+                                                unsigned int size) {
+  web_view_->NotifySubtitleData(track_id, time_stamp, data, size);
 }
 
-void WebContentsDelegateEfl::RenderProcessGone(base::TerminationStatus status) {
-  // See RenderWidgetHostViewEfl::RenderProcessGone.
-  if (status == base::TERMINATION_STATUS_ABNORMAL_TERMINATION
-      || status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED
-      || status == base::TERMINATION_STATUS_PROCESS_CRASHED) {
-    web_view_->HandleRendererProcessCrash();
+void WebContentsDelegateEfl::NotifyFirstTimeStamp(unsigned long long timestamp,
+                                                  int time_base_num,
+                                                  int time_base_den) {
+  return web_view_->NotifyFirstTimeStamp(timestamp, time_base_num,
+                                         time_base_den);
+}
+
+void WebContentsDelegateEfl::NotifyPESData(const std::string& buf,
+                                           unsigned int len,
+                                           int media_position) {
+  return web_view_->NotifyPESData(buf, len, media_position);
+}
+#endif
+
+void WebContentsDelegateEfl::OnGetMainFrameScrollbarVisible(int callback_id,
+                                                            bool visible) {
+  web_view_->InvokeMainFrameScrollbarVisibleCallback(callback_id, visible);
+}
+
+#if BUILDFLAG(IS_TIZEN_TV)
+void WebContentsDelegateEfl::DidEdgeScrollBy(const gfx::Point& offset,
+    bool handled) {
+  if (web_view_)
+    web_view_->InvokeEdgeScrollByCallback(offset, handled);
+}
+
+void WebContentsDelegateEfl::MoveFocusToBrowser(int direction) {
+  if (web_view_) {
+    web_view_->SmartCallback<EWebViewCallbacks::AtkKeyEventNotHandled>().call(
+        &direction);
   }
 }
 
-bool WebContentsDelegateEfl::AddMessageToConsole(WebContents* source,
-                                              int32 level,
-                                              const string16& message,
-                                              int32 line_no,
-                                              const string16& source_id) {
-  scoped_ptr<_Ewk_Console_Message> console_message(new _Ewk_Console_Message(level,
-                                                                          UTF16ToUTF8(message).c_str(),
-                                                                          line_no,
-                                                                          source->GetVisibleURL().spec().c_str()));
-  web_view_->SmartCallback<EWebViewCallbacks::ConsoleMessage>().call(console_message.get());
-  return true;
+void WebContentsDelegateEfl::WillDraw(int new_rotation,
+                                      gfx::Size frame_data_output_size) {
+  if (web_view_) {
+    if (web_view_->GetRotationChanged()) {
+      web_view_->SetRotationChanged(false);
+      LOG(ERROR) << __func__ << " frame_data_output_size "
+                 << frame_data_output_size.ToString() << " new rotation "
+                 << new_rotation;
+      web_view_->SmartCallback<EWebViewCallbacks::RotatePrepared>().call(0);
+    }
+  }
 }
 
-void WebContentsDelegateEfl::RunFileChooser(WebContents* web_contents, const FileChooserParams& params) {
-  web_view_->ShowFileChooser(params);
+bool WebContentsDelegateEfl::IsHighBitRate() const {
+  return web_view_ ? web_view_->IsHighBitRate() : false;
 }
 
-content::ColorChooser* WebContentsDelegateEfl::OpenColorChooser(
-    WebContents* web_contents,
-    SkColor color,
-    const std::vector<ColorSuggestion>& suggestions) {
-  ColorChooserEfl* color_chooser_efl = new ColorChooserEfl(*web_contents);
-  web_view_->RequestColorPicker(SkColorGetR(color), SkColorGetG(color), SkColorGetB(color), SkColorGetA(color));
+void WebContentsDelegateEfl::NotifyParentalRatingInfo(const std::string& info,
+                                                      const std::string& url) {
+  if (web_view_)
+    web_view_->NotifyParentalRatingInfo(info.c_str(), url.c_str());
+  else
+    LOG(ERROR) << "web_view_ is null";
+}
 
-  return color_chooser_efl;
+void WebContentsDelegateEfl::NotifyDownloadableFontInfo(
+    const std::string& scheme_id_uri,
+    const std::string& value,
+    const std::string& data,
+    int type) {
+  if (!web_view_)
+    return;
+  web_view_->NotifyDownloadableFontInfo(scheme_id_uri.c_str(), value.c_str(),
+                                        data.c_str(), type);
+}
+
+void WebContentsDelegateEfl::NotifyPlaybackState(int state,
+                                                 int player_id,
+                                                 const std::string& url,
+                                                 const std::string& mime_type,
+                                                 bool* media_resource_acquired,
+                                                 std::string* translated_url,
+                                                 std::string* drm_info) {
+  if (!web_view_)
+    return;
+  std::vector<std::string> data = web_view_->NotifyPlaybackState(
+      state, player_id, url.empty() ? "" : url.c_str(),
+      mime_type.empty() ? "" : mime_type.c_str());
+  if (data.size()) {
+    if (media_resource_acquired)
+      *media_resource_acquired = !data.at(0).empty() ? true : false;
+    if (translated_url)
+      *translated_url = data.at(1);
+    if (drm_info)
+      *drm_info = data.at(2);
+  }
 }
 
-void WebContentsDelegateEfl::OpenDateTimeDialog(
-    ui::TextInputType dialog_type,
-    double dialog_value,
-    double min,
-    double max,
-    double step,
-    const std::vector<DateTimeSuggestion>& suggestions) {
-  int inputPickerType;
-  web_view_->InputPickerShow(dialog_type, dialog_value);
+void WebContentsDelegateEfl::NotifyAudioTracksCount(
+    int player_id,
+    unsigned audio_tracks_count) {
+  if (web_view_)
+    web_view_->NotifyAudioTracksCount(player_id, audio_tracks_count);
+  else
+    LOG(INFO) << "web_view_ is null";
+}
+
+void WebContentsDelegateEfl::OnIsVideoPlayingGet(bool is_playing,
+                                                 int callback_id) {
+  if (web_view_)
+    web_view_->InvokeIsVideoPlayingCallback(is_playing, callback_id);
+  else
+    LOG(INFO) << "web_view_ is null";
+}
+
+void WebContentsDelegateEfl::VideoPlayingStatusReceived(bool is_playing,
+                                                        int callback_id) {
+  if (web_view_)
+    web_view_->InvokeIsVideoPlayingCallback(is_playing, callback_id);
+  else
+    LOG(INFO) << "web_view_ is null";
+}
+#endif
+
+void WebContentsDelegateEfl::UpdateTooltipUnderCursor(
+    const std::u16string& text) {
+  std::string tooltip = base::UTF16ToUTF8(text);
+  LOG(INFO) << __func__ << " " << tooltip.c_str();
+  if (tooltip.empty()) {
+    web_view_->SmartCallback<EWebViewCallbacks::TooltipTextUnset>().call();
+  } else {
+    web_view_->SmartCallback<EWebViewCallbacks::TooltipTextSet>().call(
+        tooltip.c_str());
+  }
 }
-} //namespace content
+}  // namespace content