Merge "Add a callback for navigation policy in web view." into devel/master
authorSeoyeon Kim <seoyeon2.kim@samsung.com>
Tue, 11 Jan 2022 06:45:21 +0000 (06:45 +0000)
committerGerrit Code Review <gerrit@review>
Tue, 11 Jan 2022 06:45:21 +0000 (06:45 +0000)
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-web-engine.cpp
automated-tests/src/dali-toolkit/utc-Dali-WebView.cpp
dali-toolkit/devel-api/controls/web-view/web-view.cpp
dali-toolkit/devel-api/controls/web-view/web-view.h
dali-toolkit/internal/controls/web-view/web-view-impl.cpp
dali-toolkit/internal/controls/web-view/web-view-impl.h

index cd863b9..b291020 100755 (executable)
@@ -1544,6 +1544,11 @@ public:
     mResponsePolicyDecisionCallback = callback;
   }
 
+  void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
+  {
+    mNavigationPolicyDecisionCallback = callback;
+  }
+
   void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
   {
     mCertificateConfirmCallback = callback;
@@ -1600,29 +1605,30 @@ public:
 
   std::vector<Dali::WebEnginePlugin::JavaScriptMessageHandlerCallback> mResultCallbacks;
 
-  Dali::WebEnginePlugin::WebEnginePageLoadCallback               mPageLoadStartedCallback;
-  Dali::WebEnginePlugin::WebEnginePageLoadCallback               mPageLoadInProgressCallback;
-  Dali::WebEnginePlugin::WebEnginePageLoadCallback               mPageLoadFinishedCallback;
-  Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback          mPageLoadErrorCallback;
-  Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback      mScrollEdgeReachedCallback;
-  Dali::WebEnginePlugin::WebEngineUrlChangedCallback             mUrlChangedCallback;
-  Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback      mFormRepostDecidedCallback;
-  Dali::WebEnginePlugin::WebEngineFrameRenderedCallback          mFrameRenderedCallback;
-  Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback mConsoleMessageCallback;
-  Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback  mResponsePolicyDecisionCallback;
-  Dali::WebEnginePlugin::WebEngineCertificateCallback            mCertificateConfirmCallback;
-  Dali::WebEnginePlugin::WebEngineCertificateCallback            mSslCertificateChangedCallback;
-  Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback        mHttpAuthHandlerCallback;
-  Dali::WebEnginePlugin::WebEngineContextMenuShownCallback       mContextMenuShownCallback;
-  Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback      mContextMenuHiddenCallback;
-  Dali::WebEnginePlugin::JavaScriptAlertCallback                 mJavaScriptAlertCallback;
-  Dali::WebEnginePlugin::JavaScriptConfirmCallback               mJavaScriptConfirmCallback;
-  Dali::WebEnginePlugin::JavaScriptPromptCallback                mJavaScriptPromptCallback;
-  Dali::WebEnginePlugin::ScreenshotCapturedCallback              mScreenshotCapturedCallback;
-  Dali::WebEnginePlugin::VideoPlayingCallback                    mVideoPlayingCallback;
-  Dali::WebEnginePlugin::GeolocationPermissionCallback           mGeolocationPermissionCallback;
-  Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback         mHitTestCreatedCallback;
-  Dali::WebEnginePlugin::PlainTextReceivedCallback               mPlainTextReceivedCallback;
+  Dali::WebEnginePlugin::WebEnginePageLoadCallback                mPageLoadStartedCallback;
+  Dali::WebEnginePlugin::WebEnginePageLoadCallback                mPageLoadInProgressCallback;
+  Dali::WebEnginePlugin::WebEnginePageLoadCallback                mPageLoadFinishedCallback;
+  Dali::WebEnginePlugin::WebEnginePageLoadErrorCallback           mPageLoadErrorCallback;
+  Dali::WebEnginePlugin::WebEngineScrollEdgeReachedCallback       mScrollEdgeReachedCallback;
+  Dali::WebEnginePlugin::WebEngineUrlChangedCallback              mUrlChangedCallback;
+  Dali::WebEnginePlugin::WebEngineFormRepostDecidedCallback       mFormRepostDecidedCallback;
+  Dali::WebEnginePlugin::WebEngineFrameRenderedCallback           mFrameRenderedCallback;
+  Dali::WebEnginePlugin::WebEngineConsoleMessageReceivedCallback  mConsoleMessageCallback;
+  Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback   mResponsePolicyDecisionCallback;
+  Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback mNavigationPolicyDecisionCallback;
+  Dali::WebEnginePlugin::WebEngineCertificateCallback             mCertificateConfirmCallback;
+  Dali::WebEnginePlugin::WebEngineCertificateCallback             mSslCertificateChangedCallback;
+  Dali::WebEnginePlugin::WebEngineHttpAuthHandlerCallback         mHttpAuthHandlerCallback;
+  Dali::WebEnginePlugin::WebEngineContextMenuShownCallback        mContextMenuShownCallback;
+  Dali::WebEnginePlugin::WebEngineContextMenuHiddenCallback       mContextMenuHiddenCallback;
+  Dali::WebEnginePlugin::JavaScriptAlertCallback                  mJavaScriptAlertCallback;
+  Dali::WebEnginePlugin::JavaScriptConfirmCallback                mJavaScriptConfirmCallback;
+  Dali::WebEnginePlugin::JavaScriptPromptCallback                 mJavaScriptPromptCallback;
+  Dali::WebEnginePlugin::ScreenshotCapturedCallback               mScreenshotCapturedCallback;
+  Dali::WebEnginePlugin::VideoPlayingCallback                     mVideoPlayingCallback;
+  Dali::WebEnginePlugin::GeolocationPermissionCallback            mGeolocationPermissionCallback;
+  Dali::WebEnginePlugin::WebEngineHitTestCreatedCallback          mHitTestCreatedCallback;
+  Dali::WebEnginePlugin::PlainTextReceivedCallback                mPlainTextReceivedCallback;
 };
 
 
@@ -1704,6 +1710,11 @@ bool OnLoadUrl()
       std::unique_ptr<Dali::WebEnginePolicyDecision> policyDecision(new MockWebEnginePolicyDecision());
       gInstance->mResponsePolicyDecisionCallback(std::move(policyDecision));
     }
+    if (gInstance->mNavigationPolicyDecisionCallback)
+    {
+      std::unique_ptr<Dali::WebEnginePolicyDecision> policyDecision(new MockWebEnginePolicyDecision());
+      gInstance->mNavigationPolicyDecisionCallback(std::move(policyDecision));
+    }
     if (gInstance->mCertificateConfirmCallback)
     {
       std::unique_ptr<Dali::WebEngineCertificate> certificate(new MockWebEngineCertificate());
@@ -2424,6 +2435,11 @@ void WebEngine::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::Web
   Internal::Adaptor::GetImplementation( *this ).RegisterResponsePolicyDecidedCallback(callback);
 }
 
+void WebEngine::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
+{
+  Internal::Adaptor::GetImplementation(*this).RegisterNavigationPolicyDecidedCallback(callback);
+}
+
 void WebEngine::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
 {
   Internal::Adaptor::GetImplementation( *this ).RegisterCertificateConfirmedCallback(callback);
index 4e553e8..aa2fdcc 100755 (executable)
@@ -80,6 +80,7 @@ static int gFrameRenderedCallbackCalled = 0;
 static int gConsoleMessageCallbackCalled = 0;
 static std::unique_ptr<Dali::WebEngineConsoleMessage> gConsoleMessageInstance = nullptr;
 static int gResponsePolicyDecidedCallbackCalled = 0;
+static int gNavigationPolicyDecidedCallbackCalled = 0;
 static std::unique_ptr<Dali::WebEnginePolicyDecision> gResponsePolicyDecisionInstance = nullptr;
 static int gCertificateConfirmCallbackCalled = 0;
 static std::unique_ptr<Dali::WebEngineCertificate> gCertificateConfirmInstance = nullptr;
@@ -144,6 +145,11 @@ static void OnResponsePolicyDecided(std::unique_ptr<Dali::WebEnginePolicyDecisio
   gResponsePolicyDecisionInstance = std::move(decision);
 }
 
+static void OnNavigationPolicyDecided(std::unique_ptr<Dali::WebEnginePolicyDecision> decision)
+{
+  gNavigationPolicyDecidedCallbackCalled++;
+}
+
 static void OnUrlChanged(const std::string& url)
 {
   gUrlChangedCallbackCalled++;
@@ -1277,6 +1283,24 @@ int UtcDaliWebViewResponsePolicyDecisionRequest(void)
   END_TEST;
 }
 
+int UtcDaliWebViewNavigationPolicyDecisionRequest(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK(view);
+
+  // load url.
+  view.RegisterNavigationPolicyDecidedCallback(&OnNavigationPolicyDecided);
+  DALI_TEST_EQUALS(gNavigationPolicyDecidedCallbackCalled, 0, TEST_LOCATION);
+
+  view.LoadUrl(TEST_URL1);
+  Test::EmitGlobalTimerSignal();
+  DALI_TEST_EQUALS(gNavigationPolicyDecidedCallbackCalled, 1, TEST_LOCATION);
+
+  END_TEST;
+}
+
 int UtcDaliWebViewHitTest(void)
 {
   ToolkitTestApplication application;
index 8412273..5b0f3d2 100755 (executable)
@@ -364,6 +364,11 @@ void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEn
   Dali::Toolkit::GetImpl(*this).RegisterResponsePolicyDecidedCallback(callback);
 }
 
+void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
+{
+  Dali::Toolkit::GetImpl(*this).RegisterNavigationPolicyDecidedCallback(callback);
+}
+
 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
 {
   Dali::Toolkit::GetImpl(*this).RegisterCertificateConfirmedCallback(callback);
index 6b373df..af7a058 100755 (executable)
@@ -692,6 +692,13 @@ public:
   void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
 
   /**
+   * @brief Callback to be called when navigation policy would be decided.
+   *
+   * @param[in] callback
+   */
+  void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
+
+  /**
    * @brief Callback to be called when certificate need be confirmed.
    *
    * @param[in] callback
index f791349..0a8c129 100755 (executable)
@@ -717,6 +717,14 @@ void WebView::RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEn
   }
 }
 
+void WebView::RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback)
+{
+  if(mWebEngine)
+  {
+    mWebEngine.RegisterNavigationPolicyDecidedCallback(callback);
+  }
+}
+
 void WebView::RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback)
 {
   if(mWebEngine)
index ca1ec27..2d8a523 100755 (executable)
@@ -363,6 +363,11 @@ public:
   void RegisterResponsePolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineResponsePolicyDecidedCallback callback);
 
   /**
+   * @copydoc Dali::Toolkit::WebView::RegisterNavigationPolicyDecidedCallback()
+   */
+  void RegisterNavigationPolicyDecidedCallback(Dali::WebEnginePlugin::WebEngineNavigationPolicyDecidedCallback callback);
+
+  /**
    * @copydoc Dali::Toolkit::WebView::RegisterCertificateConfirmedCallback()
    */
   void RegisterCertificateConfirmedCallback(Dali::WebEnginePlugin::WebEngineCertificateCallback callback);