Fix crash issue when favicon is null. 15/258015/5
authorhuayong.xu <huayong.xu@samsung.com>
Fri, 7 May 2021 11:00:57 +0000 (19:00 +0800)
committerhuayong.xu <huayong.xu@samsung.com>
Tue, 11 May 2021 03:23:24 +0000 (11:23 +0800)
When favicon of web page is null, it would cause crash.
This patch is to add a check if pixel data is null or not.

Change-Id: If6b5f88053c2377ed4a87b6d83600cdd7f9c6746

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 e3596c4..b30d3b6 100755 (executable)
@@ -841,11 +841,11 @@ public:
 
   Dali::PixelData GetImageBuffer() override
   {
-    uint8_t* faviconData = new uint8_t[ 16 ];
-    memset(faviconData, 0xff, 16);
-    return Dali::PixelData::New( faviconData, 16, 2, 2,
-                                 Dali::Pixel::Format::RGBA8888,
-                                 Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
+    uint8_t* imageData = new uint8_t[16];
+    memset(imageData, 0xff, 16);
+    return Dali::PixelData::New(imageData, 16, 2, 2,
+                                Dali::Pixel::Format::RGBA8888,
+                                Dali::PixelData::ReleaseFunction::DELETE_ARRAY);
   }
 
 private:
@@ -1229,28 +1229,20 @@ public:
 
   Dali::PixelData GetFavicon() const
   {
-    uint8_t* faviconData = new uint8_t[ 16 ];
-
-    faviconData[ 0 ] = 0xff;
-    faviconData[ 1 ] = 0x00;
-    faviconData[ 2 ] = 0x00;
-    faviconData[ 3 ] = 0xff;
-    faviconData[ 4 ] = 0xff;
-    faviconData[ 5 ] = 0x00;
-    faviconData[ 6 ] = 0x00;
-    faviconData[ 7 ] = 0xff;
-    faviconData[ 8 ] = 0xff;
-    faviconData[ 9 ] = 0x00;
-    faviconData[ 10 ] = 0x00;
-    faviconData[ 11 ] = 0xff;
-    faviconData[ 12 ] = 0xff;
-    faviconData[ 13 ] = 0x00;
-    faviconData[ 14 ] = 0x00;
-    faviconData[ 15 ] = 0xff;
-
-    return Dali::PixelData::New( faviconData, 16, 2, 2,
-                                 Dali::Pixel::Format::RGBA8888,
-                                 Dali::PixelData::ReleaseFunction::DELETE_ARRAY );
+    static int testGetFaviconCount = 0;
+    if (testGetFaviconCount == 0)
+    {
+      testGetFaviconCount++;
+      uint8_t* faviconData = new uint8_t[16];
+      memset(faviconData, 0xff, 16);
+      return Dali::PixelData::New(faviconData, 16, 2, 2,
+                                  Dali::Pixel::Format::RGBA8888,
+                                  Dali::PixelData::ReleaseFunction::DELETE_ARRAY);
+    }
+    else
+    {
+      return Dali::PixelData();
+    }
   }
 
   bool CanGoForward() const
index 867c44f..4fbe8c1 100755 (executable)
@@ -1059,12 +1059,16 @@ int UtcDaliWebViewPropertyTitleFavicon(void)
   view.GetProperty( WebView::Property::TITLE ).Get( output );
   DALI_TEST_EQUALS( output, testValue, TEST_LOCATION );
 
-  // Check default value of favicon
-  Dali::Toolkit::ImageView* favicon = &view.GetFavicon();
+  // Check the case that favicon is not null.
+  Dali::Toolkit::ImageView favicon = view.GetFavicon();
   DALI_TEST_CHECK( favicon );
-  Dali::Vector3 iconsize = favicon->GetProperty< Vector3 >( Dali::Actor::Property::SIZE );
+  Dali::Vector3 iconsize = favicon.GetProperty< Vector3 >( Dali::Actor::Property::SIZE );
   DALI_TEST_CHECK( ( int )iconsize.width == 2 && ( int )iconsize.height == 2 );
 
+  // Check the case that favicon is null.
+  favicon = view.GetFavicon();
+  DALI_TEST_CHECK( !favicon );
+
   END_TEST;
 }
 
index b777e7a..5cac9f4 100755 (executable)
@@ -89,7 +89,7 @@ Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
   return Dali::Toolkit::GetImpl(*this).GetBackForwardList();
 }
 
-Dali::Toolkit::ImageView& WebView::GetFavicon()
+Dali::Toolkit::ImageView WebView::GetFavicon() const
 {
   return Dali::Toolkit::GetImpl(*this).GetFavicon();
 }
index 2ef7d91..b290bfd 100755 (executable)
@@ -342,11 +342,11 @@ public:
   Dali::Toolkit::WebBackForwardList* GetBackForwardList() const;
 
   /**
-   * @brief Get Favicon of web page.
+   * @brief Get favicon of web page.
    *
-   * @return Handle to a fav icon
+   * @return Handle to a favicon
    */
-  Dali::Toolkit::ImageView& GetFavicon();
+  Dali::Toolkit::ImageView GetFavicon() const;
 
   /**
    * @brief Load a web page based on a given URL.
index 86b39c2..3342374 100755 (executable)
@@ -268,14 +268,15 @@ Dali::Toolkit::WebBackForwardList* WebView::GetBackForwardList() const
   return mWebBackForwardList.get();
 }
 
-Dali::Toolkit::ImageView& WebView::GetFavicon()
+Dali::Toolkit::ImageView WebView::GetFavicon() const
 {
+  Dali::Toolkit::ImageView faviconView;
   if(mWebEngine)
   {
     Dali::PixelData pixelData = mWebEngine.GetFavicon();
-    mFaviconView              = CreateImageView(pixelData);
+    faviconView               = CreateImageView(pixelData);
   }
-  return mFaviconView;
+  return faviconView;
 }
 
 void WebView::LoadUrl(const std::string& url)
@@ -706,8 +707,13 @@ void WebView::EnableBlendMode(bool blendEnabled)
   }
 }
 
-Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel)
+Dali::Toolkit::ImageView WebView::CreateImageView(Dali::PixelData pixel) const
 {
+  if(!pixel)
+  {
+    return Dali::Toolkit::ImageView();
+  }
+
   std::string              url       = Dali::Toolkit::Image::GenerateUrl(pixel);
   Dali::Toolkit::ImageView imageView = Dali::Toolkit::ImageView::New(url);
   imageView.SetProperty(Dali::Actor::Property::SIZE, Vector2(pixel.GetWidth(), pixel.GetHeight()));
index c9eaa39..a5cefa4 100755 (executable)
@@ -95,7 +95,7 @@ public:
   /**
    * @copydoc Dali::Toolkit::WebView::GetFavicon()
    */
-  Dali::Toolkit::ImageView& GetFavicon();
+  Dali::Toolkit::ImageView GetFavicon() const;
 
   /**
    * @copydoc Dali::Toolkit::WebView::LoadUrl()
@@ -608,7 +608,7 @@ private:
    * @param[in] pixel Pixel data
    * @return The new image view
    */
-  Dali::Toolkit::ImageView CreateImageView(Dali::PixelData pixel);
+  Dali::Toolkit::ImageView CreateImageView(Dali::PixelData pixel) const;
 
   /**
    * @brief Callback function to be called when page load started.
@@ -772,8 +772,6 @@ private:
   std::unique_ptr<Dali::Toolkit::WebSettings>        mWebSettings;
   std::unique_ptr<Dali::Toolkit::WebBackForwardList> mWebBackForwardList;
 
-  Dali::Toolkit::ImageView mFaviconView;
-
   Dali::PropertyNotification mPositionUpdateNotification;
   Dali::PropertyNotification mSizeUpdateNotification;
   Dali::PropertyNotification mScaleUpdateNotification;