[Tizen] Implement WebView::GetPlainTextAsynchronously 28/261928/1 accepted/tizen/6.0/unified/20210908.124451 submit/tizen_6.0/20210908.054804
authorJiyun Yang <ji.yang@samsung.com>
Thu, 22 Jul 2021 13:07:20 +0000 (22:07 +0900)
committerJiyun Yang <ji.yang@samsung.com>
Thu, 29 Jul 2021 00:51:14 +0000 (09:51 +0900)
Change-Id: I6691a877ec987dc9971216a43a34bb6daa2ba95d
Signed-off-by: Jiyun Yang <ji.yang@samsung.com>
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 106feba..5f5160d 100755 (executable)
@@ -50,6 +50,7 @@ bool OnGoForward();
 bool OnLoadUrl();
 bool OnEvaluteJavaScript();
 bool OnClearHistory();
+bool OnPlainTextReceived();
 
 static void ConnectToGlobalSignal( bool (*func)() )
 {
@@ -484,6 +485,15 @@ public:
     return mScrollEdgeReachedSignal;
   }
 
+  void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
+  {
+    if (callback)
+    {
+      ConnectToGlobalSignal(&OnPlainTextReceived);
+      mPlainTextReceivedCallback = callback;
+    }
+  }
+
   std::string                                                mUrl;
   std::vector< std::string >                                 mHistory;
   size_t                                                     mCurrentPlusOnePos;
@@ -502,6 +512,7 @@ public:
   WebEngineContext*                                           mockWebEngineContext;
   WebEngineCookieManager*                                     mockWebEngineCookieManager;
   WebEngineSettings*                                          mockWebEngineSettings;
+  Dali::WebEnginePlugin::PlainTextReceivedCallback            mPlainTextReceivedCallback;
 };
 
 inline WebEngine& GetImplementation( Dali::WebEngine& webEngine )
@@ -588,6 +599,18 @@ bool OnClearHistory()
   }
   return false;
 }
+
+bool OnPlainTextReceived()
+{
+  DisconnectFromGlobalSignal(&OnPlainTextReceived);
+  if (gInstance)
+  {
+    std::string dummyResultText;
+    gInstance->mPlainTextReceivedCallback(dummyResultText);
+  }
+  return false;
+}
+
 } // namespace
 
 } // namespace Adaptor
@@ -830,5 +853,10 @@ Dali::WebEnginePlugin::WebEngineScrollEdgeReachedSignalType& WebEngine::ScrollEd
   return Internal::Adaptor::GetImplementation( *this ).ScrollEdgeReachedSignal();
 }
 
+void WebEngine::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
+{
+  Internal::Adaptor::GetImplementation(*this).GetPlainTextAsynchronously(callback);
+}
+
 } // namespace Dali;
 
index 7b1c978..72b50b3 100755 (executable)
@@ -48,6 +48,7 @@ static int gPageLoadFinishedCallbackCalled = 0;
 static int gScrollEdgeReachedCallbackCalled = 0;
 static int gEvaluateJavaScriptCallbackCalled = 0;
 static bool gTouched = false;
+static int gPlainTextReceivedCallbackCalled = 0;
 
 struct CallbackFunctor
 {
@@ -78,6 +79,12 @@ static void OnScrollEdgeReached( WebView view, Dali::WebEnginePlugin::ScrollEdge
   gScrollEdgeReachedCallbackCalled++;
 }
 
+static bool OnPlainTextReceived(const std::string& plainText)
+{
+  gPlainTextReceivedCallbackCalled++;
+  return true;
+}
+
 static void OnPageLoadError( WebView view, const std::string& url, WebView::LoadErrorCode errorCode )
 {
 }
@@ -794,3 +801,18 @@ int UtcDaliWebSettingsGetSetDefaultTextEncodingName(void)
   END_TEST;
 }
 
+int UtcDaliWebViewGetPlainText(void)
+{
+  ToolkitTestApplication application;
+
+  WebView view = WebView::New();
+  DALI_TEST_CHECK(view);
+
+  view.LoadUrl(TEST_URL1);
+
+  view.GetPlainTextAsynchronously(&OnPlainTextReceived);
+  Test::EmitGlobalTimerSignal();
+  DALI_TEST_EQUALS(gPlainTextReceivedCallbackCalled, 1, TEST_LOCATION);
+
+  END_TEST;
+}
index c5bcab5..3616de2 100644 (file)
@@ -199,6 +199,11 @@ WebView::WebViewScrollEdgeReachedSignalType& WebView::ScrollEdgeReachedSignal()
   return Dali::Toolkit::GetImpl( *this ).ScrollEdgeReachedSignal();
 }
 
+void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
+{
+  Dali::Toolkit::GetImpl(*this).GetPlainTextAsynchronously(callback);
+}
+
 WebView::WebView(Internal::WebView& implementation)
 : Control(implementation)
 {
index 2a2069f..4fb5880 100644 (file)
@@ -400,6 +400,13 @@ public:
    */
   WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
 
+  /**
+   * @brief Get a plain text of current web page asynchronously.
+   *
+   * @param[in] callback The callback function called asynchronously.
+   */
+  void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
+
 public: // Not intended for application developers
   /// @cond internal
   /**
index 97b545e..d82463d 100644 (file)
@@ -532,6 +532,14 @@ void WebView::OnScrollEdgeReached( Dali::WebEnginePlugin::ScrollEdge edge )
   }
 }
 
+void WebView::GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback)
+{
+  if(mWebEngine)
+  {
+    mWebEngine.GetPlainTextAsynchronously(callback);
+  }
+}
+
 bool WebView::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
   Dali::BaseHandle handle( object );
index ccf07e9..9aab208 100644 (file)
@@ -203,6 +203,11 @@ public:
    */
   Dali::Toolkit::WebView::WebViewScrollEdgeReachedSignalType& ScrollEdgeReachedSignal();
 
+  /**
+   * @copydoc Dali::Toolkit::WebView::GetPlainTextAsynchronously()
+   */
+  void GetPlainTextAsynchronously(Dali::WebEnginePlugin::PlainTextReceivedCallback callback);
+
 public: // Properties
 
   /**