[EFL][WK2] Use C API inside ewk_favicon_database

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

Reviewed by Kenneth Rohde Christiansen.

Use C API inside ewk_favicon_database instead of
accessible the C++ classes and violating layering.
We still rely on some C++ methods but this will be
addressed later since there is no equivalent in
the C API and it will require more refactoring.

* UIProcess/API/efl/ewk_context.cpp:
(EwkContext::ensureFaviconDatabase):
* UIProcess/API/efl/ewk_favicon_database.cpp:
(EwkFaviconDatabase::EwkFaviconDatabase):
(EwkFaviconDatabase::~EwkFaviconDatabase):
(EwkFaviconDatabase::iconURLForPageURL):
(EwkFaviconDatabase::iconForPageURL):
(EwkFaviconDatabase::getIconSurfaceSynchronously):
(EwkFaviconDatabase::iconDataReadyForPageURL):
(ewk_favicon_database_async_icon_get):
* UIProcess/API/efl/ewk_favicon_database_private.h:
(EwkFaviconDatabase::create):
(EwkFaviconDatabase):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@140692 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent c0d2b7ab
2013-01-24 Christophe Dumez <christophe.dumez@intel.com>
[EFL][WK2] Use C API inside ewk_favicon_database
https://bugs.webkit.org/show_bug.cgi?id=107680
Reviewed by Kenneth Rohde Christiansen.
Use C API inside ewk_favicon_database instead of
accessible the C++ classes and violating layering.
We still rely on some C++ methods but this will be
addressed later since there is no equivalent in
the C API and it will require more refactoring.
* UIProcess/API/efl/ewk_context.cpp:
(EwkContext::ensureFaviconDatabase):
* UIProcess/API/efl/ewk_favicon_database.cpp:
(EwkFaviconDatabase::EwkFaviconDatabase):
(EwkFaviconDatabase::~EwkFaviconDatabase):
(EwkFaviconDatabase::iconURLForPageURL):
(EwkFaviconDatabase::iconForPageURL):
(EwkFaviconDatabase::getIconSurfaceSynchronously):
(EwkFaviconDatabase::iconDataReadyForPageURL):
(ewk_favicon_database_async_icon_get):
* UIProcess/API/efl/ewk_favicon_database_private.h:
(EwkFaviconDatabase::create):
(EwkFaviconDatabase):
2013-01-24 Mikhail Pozdnyakov <mikhail.pozdnyakov@intel.com>
[EFL][WK2] Rename EwkViewImpl class to EwkView
......@@ -151,7 +151,7 @@ void EwkContext::ensureFaviconDatabase()
if (m_faviconDatabase)
return;
m_faviconDatabase = EwkFaviconDatabase::create(m_context.get()->iconDatabase());
m_faviconDatabase = EwkFaviconDatabase::create(WKContextGetIconDatabase(toAPI(m_context.get())));
}
bool EwkContext::setFaviconDatabaseDirectoryPath(const String& databaseDirectory)
......
......@@ -30,7 +30,6 @@
#include "WKIconDatabase.h"
#include "WKURL.h"
#include "WebIconDatabase.h"
#include "WebURL.h"
#include "ewk_favicon_database_private.h"
#include <WebCore/CairoUtilitiesEfl.h>
#include <WebCore/RefPtrCairo.h>
......@@ -39,7 +38,7 @@
using namespace WebKit;
EwkFaviconDatabase::EwkFaviconDatabase(WebIconDatabase* iconDatabase)
EwkFaviconDatabase::EwkFaviconDatabase(WKIconDatabaseRef iconDatabase)
: m_iconDatabase(iconDatabase)
{
WKIconDatabaseClient iconDatabaseClient;
......@@ -48,18 +47,18 @@ EwkFaviconDatabase::EwkFaviconDatabase(WebIconDatabase* iconDatabase)
iconDatabaseClient.clientInfo = this;
iconDatabaseClient.didChangeIconForPageURL = didChangeIconForPageURL;
iconDatabaseClient.iconDataReadyForPageURL = iconDataReadyForPageURL;
WKIconDatabaseSetIconDatabaseClient(toAPI(m_iconDatabase.get()), &iconDatabaseClient);
WKIconDatabaseSetIconDatabaseClient(m_iconDatabase.get(), &iconDatabaseClient);
}
EwkFaviconDatabase::~EwkFaviconDatabase()
{
WKIconDatabaseSetIconDatabaseClient(toAPI(m_iconDatabase.get()), 0);
WKIconDatabaseSetIconDatabaseClient(m_iconDatabase.get(), 0);
}
String EwkFaviconDatabase::iconURLForPageURL(const String& pageURL) const
{
String iconURL;
m_iconDatabase->synchronousIconURLForPageURL(pageURL, iconURL);
toImpl(m_iconDatabase.get())->synchronousIconURLForPageURL(pageURL, iconURL);
return iconURL;
}
......@@ -103,26 +102,28 @@ static Eina_Bool respond_icon_request_idle(void* data)
return ECORE_CALLBACK_DONE;
}
void EwkFaviconDatabase::iconForPageURL(const String& pageURL, const IconRequestCallbackData& callbackData)
void EwkFaviconDatabase::iconForPageURL(const char* pageURL, const IconRequestCallbackData& callbackData)
{
// We ask for the icon directly. If we don't get the icon data now,
// we'll be notified later (even if the database is still importing icons).
RefPtr<cairo_surface_t> surface = getIconSurfaceSynchronously(pageURL);
WKRetainPtr<WKURLRef> wkPageURL(AdoptWK, WKURLCreateWithUTF8CString(pageURL));
RefPtr<cairo_surface_t> surface = getIconSurfaceSynchronously(wkPageURL.get());
// If there's no valid icon, but there's an iconURL registered,
// or it's still not registered but the import process hasn't
// finished yet, we need to wait for iconDataReadyForPageURL to be
// called before making and informed decision.
String iconURL = iconURLForPageURL(pageURL);
if (!surface && (!iconURL.isEmpty() || !m_iconDatabase->isUrlImportCompleted())) {
PendingIconRequestVector requests = m_iconRequests.get(pageURL);
String pageURLString = String::fromUTF8(pageURL);
String iconURL = iconURLForPageURL(pageURLString);
if (!surface && (!iconURL.isEmpty() || !toImpl(m_iconDatabase.get())->isUrlImportCompleted())) {
PendingIconRequestVector requests = m_iconRequests.get(pageURLString);
requests.append(callbackData);
m_iconRequests.set(pageURL, requests);
m_iconRequests.set(pageURLString, requests);
return;
}
// Respond when idle.
AsyncIconRequestResponse* response = new AsyncIconRequestResponse(pageURL, surface.release(), callbackData);
AsyncIconRequestResponse* response = new AsyncIconRequestResponse(pageURLString, surface.release(), callbackData);
ecore_idler_add(respond_icon_request_idle, response);
}
......@@ -141,13 +142,13 @@ void EwkFaviconDatabase::didChangeIconForPageURL(WKIconDatabaseRef, WKURLRef pag
it->value.callback(pageURL.data(), it->value.userData);
}
PassRefPtr<cairo_surface_t> EwkFaviconDatabase::getIconSurfaceSynchronously(const String& pageURL) const
PassRefPtr<cairo_surface_t> EwkFaviconDatabase::getIconSurfaceSynchronously(WKURLRef pageURL) const
{
m_iconDatabase->retainIconForPageURL(pageURL);
WKIconDatabaseRetainIconForURL(m_iconDatabase.get(), pageURL);
WebCore::NativeImagePtr icon = m_iconDatabase->nativeImageForPageURL(pageURL);
WebCore::NativeImagePtr icon = toImpl(m_iconDatabase.get())->nativeImageForPageURL(toWTFString(pageURL));
if (!icon) {
m_iconDatabase->releaseIconForPageURL(pageURL);
WKIconDatabaseReleaseIconForURL(m_iconDatabase.get(), pageURL);
return 0;
}
......@@ -164,7 +165,7 @@ void EwkFaviconDatabase::iconDataReadyForPageURL(WKIconDatabaseRef, WKURLRef pag
if (!ewkIconDatabase->m_iconRequests.contains(urlString))
return;
RefPtr<cairo_surface_t> surface = ewkIconDatabase->getIconSurfaceSynchronously(urlString);
RefPtr<cairo_surface_t> surface = ewkIconDatabase->getIconSurfaceSynchronously(pageURL);
PendingIconRequestVector requestsForURL = ewkIconDatabase->m_iconRequests.take(urlString);
size_t requestCount = requestsForURL.size();
......@@ -192,7 +193,7 @@ Eina_Bool ewk_favicon_database_async_icon_get(Ewk_Favicon_Database* ewkIconDatab
EINA_SAFETY_ON_NULL_RETURN_VAL(evas, false);
EINA_SAFETY_ON_NULL_RETURN_VAL(callback, false);
ewkIconDatabase->iconForPageURL(String::fromUTF8(page_url), IconRequestCallbackData(callback, userData, evas));
ewkIconDatabase->iconForPageURL(page_url, IconRequestCallbackData(callback, userData, evas));
return true;
}
......
......@@ -26,14 +26,11 @@
#ifndef ewk_favicon_database_private_h
#define ewk_favicon_database_private_h
#include "WKRetainPtr.h"
#include "ewk_favicon_database.h"
#include <WebKit2/WKBase.h>
#include <wtf/HashMap.h>
namespace WebKit {
class WebIconDatabase;
}
struct IconChangeCallbackData {
Ewk_Favicon_Database_Icon_Change_Cb callback;
void* userData;
......@@ -73,27 +70,27 @@ typedef HashMap<String /* pageURL */, PendingIconRequestVector> PendingIconReque
class EwkFaviconDatabase {
public:
static PassOwnPtr<EwkFaviconDatabase> create(WebKit::WebIconDatabase* iconDatabase)
static PassOwnPtr<EwkFaviconDatabase> create(WKIconDatabaseRef iconDatabase)
{
return adoptPtr(new EwkFaviconDatabase(iconDatabase));
}
~EwkFaviconDatabase();
String iconURLForPageURL(const String& pageURL) const;
void iconForPageURL(const String& pageURL, const IconRequestCallbackData& callbackData);
void iconForPageURL(const char* pageURL, const IconRequestCallbackData& callbackData);
void watchChanges(const IconChangeCallbackData& callbackData);
void unwatchChanges(Ewk_Favicon_Database_Icon_Change_Cb callback);
private:
explicit EwkFaviconDatabase(WebKit::WebIconDatabase* iconDatabase);
explicit EwkFaviconDatabase(WKIconDatabaseRef iconDatabase);
PassRefPtr<cairo_surface_t> getIconSurfaceSynchronously(const String& pageURL) const;
PassRefPtr<cairo_surface_t> getIconSurfaceSynchronously(WKURLRef pageURL) const;
static void didChangeIconForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL, const void* clientInfo);
static void iconDataReadyForPageURL(WKIconDatabaseRef iconDatabase, WKURLRef pageURL, const void* clientInfo);
RefPtr<WebKit::WebIconDatabase> m_iconDatabase;
WKRetainPtr<WKIconDatabaseRef> m_iconDatabase;
ChangeListenerMap m_changeListeners;
PendingIconRequestMap m_iconRequests;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment