summaryrefslogtreecommitdiffstats
path: root/src/core/favicon_manager.cpp
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2017-12-11 13:59:13 +0100
committerPeter Varga <pvarga@inf.u-szeged.hu>2018-01-10 15:27:19 +0000
commitf3d4cd402ecbdd45793884b5b46c287af0e4cb6e (patch)
treeaf0c9bf0eb4f44c7fca101de30567e9c6baf4a74 /src/core/favicon_manager.cpp
parent7219986a18d45dd0e32a8004c748ce91d22a535b (diff)
Add data URL handling to FaviconManager
Favicons passed in data URL now are converted directly to QImage in FaviconManager (Browser Process). Without this improvement content::WebContents::DownloadImage() handled the data URL, Render Process did the conversion and FaviconManager had to convert the resulted SkBitmap to QImage. Change-Id: Ie216b1d09fa4e1000297b1bd71c35aed70d968b0 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src/core/favicon_manager.cpp')
-rw-r--r--src/core/favicon_manager.cpp23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/core/favicon_manager.cpp b/src/core/favicon_manager.cpp
index 214fd5fa7..03da67335 100644
--- a/src/core/favicon_manager.cpp
+++ b/src/core/favicon_manager.cpp
@@ -48,6 +48,8 @@
#include "content/public/browser/favicon_status.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/url_constants.h"
+#include "net/base/data_url.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkPixelRef.h"
#include "ui/gfx/geometry/size.h"
@@ -59,6 +61,11 @@ static inline bool isResourceUrl(const QUrl &url)
return !url.scheme().compare(QLatin1String("qrc"));
}
+static inline bool isDataUrl(const QUrl &url)
+{
+ return !url.scheme().compare(QLatin1String(url::kDataScheme));
+}
+
static inline unsigned area(const QSize &size)
{
return size.width() * size.height();
@@ -82,7 +89,7 @@ int FaviconManagerPrivate::downloadIcon(const QUrl &url)
int id;
bool cached = m_icons.contains(url);
- if (isResourceUrl(url) || cached) {
+ if (isResourceUrl(url) || isDataUrl(url) || cached) {
id = --fakeId;
m_pendingRequests.insert(id, url);
} else {
@@ -124,8 +131,18 @@ void FaviconManagerPrivate::downloadPendingRequests()
QIcon icon;
QUrl requestUrl = it.value();
- if (isResourceUrl(requestUrl) && !m_icons.contains(requestUrl))
- icon = QIcon(requestUrl.toString().remove(0, 3));
+ if (!m_icons.contains(requestUrl)) {
+ if (isResourceUrl(requestUrl)) {
+ icon = QIcon(requestUrl.toString().remove(0, 3));
+ } else if (isDataUrl(requestUrl)) {
+ std::string mime_type, char_set, data;
+ if (net::DataURL::Parse(toGurl(requestUrl), &mime_type, &char_set, &data) && !data.empty()) {
+ const unsigned char *src_data = reinterpret_cast<const unsigned char *>(data.data());
+ QImage image = QImage::fromData(src_data, data.size());
+ icon.addPixmap(QPixmap::fromImage(image).copy());
+ }
+ }
+ }
storeIcon(it.key(), icon);
}