Skip to content

Commit

Permalink
Merge r220694 - [GTK][WPE] Avoid emitting WebKitFaviconDatabase::favi…
Browse files Browse the repository at this point in the history
…con-changed multiple times while setting an icon

https://bugs.webkit.org/show_bug.cgi?id=175531

Reviewed by Michael Catanzaro.

When webkitFaviconDatabaseSetIconForPageURL() is called, both setIconURLForPageURL() and setIconDataForIconURL()
might notify the client, which ends up emitting the WebKitFaviconDatabase::favicon-changed signal and calling
webkitFaviconDatabaseSetIconURLForPageURL(). Both things are already done by
webkitFaviconDatabaseSetIconForPageURL() itself, so we can just ignore the client notification while setting a
new icon.

* UIProcess/API/glib/WebKitFaviconDatabase.cpp:
(webkitFaviconDatabaseSetIconURLForPageURL): Return early if isSettingIcon is true.
(webkitFaviconDatabaseSetIconForPageURL): Set isSettingIcon to true for the scope.
  • Loading branch information
carlosgcampos committed Aug 14, 2017
1 parent 7844f46 commit d4abc27
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Source/WebKit/ChangeLog
@@ -1,3 +1,20 @@
2017-08-14 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK][WPE] Avoid emitting WebKitFaviconDatabase::favicon-changed multiple times while setting an icon
https://bugs.webkit.org/show_bug.cgi?id=175531

Reviewed by Michael Catanzaro.

When webkitFaviconDatabaseSetIconForPageURL() is called, both setIconURLForPageURL() and setIconDataForIconURL()
might notify the client, which ends up emitting the WebKitFaviconDatabase::favicon-changed signal and calling
webkitFaviconDatabaseSetIconURLForPageURL(). Both things are already done by
webkitFaviconDatabaseSetIconForPageURL() itself, so we can just ignore the client notification while setting a
new icon.

* UIProcess/API/glib/WebKitFaviconDatabase.cpp:
(webkitFaviconDatabaseSetIconURLForPageURL): Return early if isSettingIcon is true.
(webkitFaviconDatabaseSetIconForPageURL): Set isSettingIcon to true for the scope.

2017-08-14 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK][WPE] Crash in IconDatabase::IconRecord::setImageData()
Expand Down
8 changes: 8 additions & 0 deletions Source/WebKit/UIProcess/API/glib/WebKitFaviconDatabase.cpp
Expand Up @@ -29,6 +29,7 @@
#include <WebCore/RefPtrCairo.h>
#include <glib/gi18n-lib.h>
#include <wtf/RunLoop.h>
#include <wtf/SetForScope.h>
#include <wtf/glib/GRefPtr.h>
#include <wtf/glib/GUniquePtr.h>
#include <wtf/glib/WTFGType.h>
Expand Down Expand Up @@ -75,6 +76,7 @@ struct _WebKitFaviconDatabasePrivate {
PendingIconRequestMap pendingIconRequests;
HashMap<String, String> pageURLToIconURLMap;
bool isURLImportCompleted;
bool isSettingIcon;
};

WEBKIT_DEFINE_TYPE(WebKitFaviconDatabase, webkit_favicon_database, G_TYPE_OBJECT)
Expand Down Expand Up @@ -193,6 +195,9 @@ static void webkitFaviconDatabaseSetIconURLForPageURL(WebKitFaviconDatabase* dat
return;

priv->pageURLToIconURLMap.set(pageURL, iconURL);
if (priv->isSettingIcon)
return;

g_signal_emit(database, signals[FAVICON_CHANGED], 0, pageURL.utf8().data(), iconURL.utf8().data());
}

Expand All @@ -212,6 +217,8 @@ class WebKitIconDatabaseClient final : public IconDatabaseClient {

void didChangeIconForPageURL(const String& pageURL) override
{
if (m_database->priv->isSettingIcon)
return;
String iconURL = m_database->priv->iconDatabase->synchronousIconURLForPageURL(pageURL);
webkitFaviconDatabaseSetIconURLForPageURL(m_database, iconURL, pageURL);
}
Expand Down Expand Up @@ -305,6 +312,7 @@ void webkitFaviconDatabaseSetIconForPageURL(WebKitFaviconDatabase* database, con
return;

WebKitFaviconDatabasePrivate* priv = database->priv;
SetForScope<bool> change(priv->isSettingIcon, true);
priv->iconDatabase->setIconURLForPageURL(icon.url.string(), pageURL);
priv->iconDatabase->setIconDataForIconURL(SharedBuffer::create(iconData.bytes(), iconData.size()), icon.url.string());
webkitFaviconDatabaseSetIconURLForPageURL(database, icon.url.string(), pageURL);
Expand Down

0 comments on commit d4abc27

Please sign in to comment.