Skip to content
Permalink
Browse files
[GTK] Add API to WebKitWebsiteDataManager to handle website data
https://bugs.webkit.org/show_bug.cgi?id=146589

Reviewed by Michael Catanzaro.

Source/WebKit2:

Add WebKitWebsiteData boxed type to wrap a WebsiteDataRecord and new methods to WebKitWebsiteDataManager to
fetch, remove and clear website data.

* PlatformGTK.cmake: Add new files to compilation.
* UIProcess/API/gtk/WebKitWebsiteData.cpp: Added.
(_WebKitWebsiteData::_WebKitWebsiteData):
(recordContainsSupportedDataTypes): Helper function to check if the WebsiteDataRecord contains any type exposed
by our API.
(toWebKitWebsiteDataTypes): Convert from WebKit::WebsiteDataType to the GTK+ public API types.
(webkitWebsiteDataCreate): Create a new WebKitWebsiteData for the given WebsiteDataRecord if it contains any
supported type.
(webkitWebsiteDataGetRecord): Returns the wrapped WebsiteDataRecord.
(webkit_website_data_ref):
(webkit_website_data_unref):
(webkit_website_data_get_name): Return the display name.
(webkit_website_data_get_types): Returns the mask of types.
(webkit_website_data_get_size): Returns the size for the given types.
* UIProcess/API/gtk/WebKitWebsiteData.h: Added.
* UIProcess/API/gtk/WebKitWebsiteDataManager.cpp:
(toWebsiteDataTypes): Convert from GTK+ public API types to WebKit::WebsiteDataType.
(webkit_website_data_manager_fetch): Fetch website data of the given types.
(webkit_website_data_manager_fetch_finish):
(webkit_website_data_manager_remove): Remove the website data of the given types for the given WebKitWebsiteData list.
(webkit_website_data_manager_remove_finish):
(webkit_website_data_manager_clear): Clear all website data of the given types modified since the given time span.
(webkit_website_data_manager_clear_finish):
* UIProcess/API/gtk/WebKitWebsiteDataManager.h:
* UIProcess/API/gtk/WebKitWebsiteDataPrivate.h: Added.
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section.
* UIProcess/API/gtk/webkit2.h: Inlcude WebKitWebsiteData.h

Tools:

Add about:data handler to MiniBrowser to manually test the website data API. Also add unit tests to test all the
new API, moving the WebKitWebsiteDataManager configuration API to the new file too.

* MiniBrowser/gtk/BrowserWindow.c:
(webViewDecidePolicy):
(newTabCallback):
* MiniBrowser/gtk/main.c:
(createBrowserTab):
(aboutDataRequestFree):
(aboutDataRequestNew):
(aboutDataRequestForView):
(websiteDataRemovedCallback):
(websiteDataClearedCallback):
(aboutDataScriptMessageReceivedCallback):
(domainListFree):
(aboutDataFillTable):
(gotWebsiteDataCallback):
(aboutDataHandleRequest):
(aboutURISchemeRequestCallback):
(main):
* TestWebKitAPI/Tests/WebKit2Gtk/CMakeLists.txt:
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebKitWebContext.cpp:
(serverCallback):
(beforeAll):
* TestWebKitAPI/Tests/WebKit2Gtk/TestWebsiteData.cpp: Added.
(serverCallback):
(WebsiteDataTest::WebsiteDataTest):
(WebsiteDataTest::~WebsiteDataTest):
(WebsiteDataTest::fetch):
(WebsiteDataTest::remove):
(WebsiteDataTest::clear):
(testWebsiteDataConfiguration):
(testWebsiteDataCache):
(testWebsiteDataStorage):
(testWebsiteDataDatabases):
(testWebsiteDataAppcache):
(beforeAll):
(afterAll):

Canonical link: https://commits.webkit.org/184391@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Jan 24, 2017
1 parent 54d56ef commit e964da82f53718614e9734012545bce8b8c1e62c
@@ -15,6 +15,7 @@ LocalizedStringsGtk.cpp
../../../WebKit2/UIProcess/API/gtk/WebKitURIResponse.cpp
../../../WebKit2/UIProcess/API/gtk/WebKitWebInspector.cpp
../../../WebKit2/UIProcess/API/gtk/WebKitWebResource.cpp
../../../WebKit2/UIProcess/API/gtk/WebKitWebsiteData.cpp
../../../WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp
../../../WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
../../../WebKit2/UIProcess/API/gtk/WebKitWindowProperties.cpp
@@ -1,3 +1,42 @@
2017-01-23 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] Add API to WebKitWebsiteDataManager to handle website data
https://bugs.webkit.org/show_bug.cgi?id=146589

Reviewed by Michael Catanzaro.

Add WebKitWebsiteData boxed type to wrap a WebsiteDataRecord and new methods to WebKitWebsiteDataManager to
fetch, remove and clear website data.

* PlatformGTK.cmake: Add new files to compilation.
* UIProcess/API/gtk/WebKitWebsiteData.cpp: Added.
(_WebKitWebsiteData::_WebKitWebsiteData):
(recordContainsSupportedDataTypes): Helper function to check if the WebsiteDataRecord contains any type exposed
by our API.
(toWebKitWebsiteDataTypes): Convert from WebKit::WebsiteDataType to the GTK+ public API types.
(webkitWebsiteDataCreate): Create a new WebKitWebsiteData for the given WebsiteDataRecord if it contains any
supported type.
(webkitWebsiteDataGetRecord): Returns the wrapped WebsiteDataRecord.
(webkit_website_data_ref):
(webkit_website_data_unref):
(webkit_website_data_get_name): Return the display name.
(webkit_website_data_get_types): Returns the mask of types.
(webkit_website_data_get_size): Returns the size for the given types.
* UIProcess/API/gtk/WebKitWebsiteData.h: Added.
* UIProcess/API/gtk/WebKitWebsiteDataManager.cpp:
(toWebsiteDataTypes): Convert from GTK+ public API types to WebKit::WebsiteDataType.
(webkit_website_data_manager_fetch): Fetch website data of the given types.
(webkit_website_data_manager_fetch_finish):
(webkit_website_data_manager_remove): Remove the website data of the given types for the given WebKitWebsiteData list.
(webkit_website_data_manager_remove_finish):
(webkit_website_data_manager_clear): Clear all website data of the given types modified since the given time span.
(webkit_website_data_manager_clear_finish):
* UIProcess/API/gtk/WebKitWebsiteDataManager.h:
* UIProcess/API/gtk/WebKitWebsiteDataPrivate.h: Added.
* UIProcess/API/gtk/docs/webkit2gtk-4.0-sections.txt: Add new symbols.
* UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add new section.
* UIProcess/API/gtk/webkit2.h: Inlcude WebKitWebsiteData.h

2017-01-23 Antti Koivisto <antti@apple.com>

Maintain ordering when doing speculative loads
@@ -270,6 +270,9 @@ list(APPEND WebKit2_SOURCES
UIProcess/API/gtk/WebKitWebViewSessionState.cpp
UIProcess/API/gtk/WebKitWebViewSessionState.h
UIProcess/API/gtk/WebKitWebViewSessionStatePrivate.h
UIProcess/API/gtk/WebKitWebsiteData.cpp
UIProcess/API/gtk/WebKitWebsiteData.h
UIProcess/API/gtk/WebKitWebsiteDataPrivate.h
UIProcess/API/gtk/WebKitWebsiteDataManager.cpp
UIProcess/API/gtk/WebKitWebsiteDataManager.h
UIProcess/API/gtk/WebKitWebsiteDataManagerPrivate.h
@@ -554,6 +557,7 @@ set(WebKit2GTK_INSTALLED_HEADERS
${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebView.h
${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebViewBase.h
${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebViewSessionState.h
${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebsiteData.h
${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWebsiteDataManager.h
${WEBKIT2_DIR}/UIProcess/API/gtk/WebKitWindowProperties.h
${WEBKIT2_DIR}/UIProcess/API/gtk/webkit2.h
@@ -0,0 +1,229 @@
/*
* Copyright (C) 2017 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#include "config.h"
#include "WebKitWebsiteData.h"

#include "WebKitSecurityOriginPrivate.h"
#include "WebKitWebsiteDataPrivate.h"
#include <glib/gi18n.h>
#include <wtf/HashTable.h>
#include <wtf/Vector.h>

using namespace WebKit;

/**
* SECTION: WebKitWebsiteData
* @Short_description: Website data
* @Title: WebKitWebsiteData
* @See_also: #WebKitWebsiteDataManager
*
* WebKitWebsiteData represents data stored in the client by a particular website.
* A website is normally a set of URLs grouped by domain name. You can get the website name,
* which is usually the domain, with webkit_website_data_get_name().
* Documents loaded from the file system, like file:// URIs, are all grouped in the same WebKitWebsiteData
* with the name "Local files".
*
* A website can store different types of data in the client side. #WebKitWebsiteDataTypes is an enum containing
* all the possible data types; use webkit_website_data_get_types() to get the bitmask of data types.
* It's also possible to know the size of the data stored for some of the #WebKitWebsiteDataTypes by using
* webkit_website_data_get_size().
*
* A list of WebKitWebsiteData can be retrieved with webkit_website_data_manager_fetch(). See #WebKitWebsiteDataManager
* for more information.
*
* Since: 2.16
*/
struct _WebKitWebsiteData {
explicit _WebKitWebsiteData(WebsiteDataRecord&& websiteDataDecord)
: record(WTFMove(websiteDataDecord))
{
}

WebsiteDataRecord record;
CString displayName;
int referenceCount { 1 };
};

G_DEFINE_BOXED_TYPE(WebKitWebsiteData, webkit_website_data, webkit_website_data_ref, webkit_website_data_unref)

static bool recordContainsSupportedDataTypes(const WebsiteDataRecord& record)
{
static const OptionSet<WebsiteDataType> typesSupported = {
WebsiteDataType::MemoryCache,
WebsiteDataType::DiskCache,
WebsiteDataType::OfflineWebApplicationCache,
WebsiteDataType::SessionStorage,
WebsiteDataType::LocalStorage,
WebsiteDataType::WebSQLDatabases,
WebsiteDataType::IndexedDBDatabases,
WebsiteDataType::PlugInData
};
return record.types.contains(typesSupported);
}

static WebKitWebsiteDataTypes toWebKitWebsiteDataTypes(OptionSet<WebsiteDataType> types)
{
uint32_t returnValue = 0;
if (types.contains(WebsiteDataType::MemoryCache))
returnValue |= WEBKIT_WEBSITE_DATA_MEMORY_CACHE;
if (types.contains(WebsiteDataType::DiskCache))
returnValue |= WEBKIT_WEBSITE_DATA_DISK_CACHE;
if (types.contains(WebsiteDataType::OfflineWebApplicationCache))
returnValue |= WEBKIT_WEBSITE_DATA_OFFLINE_APPLICATION_CACHE;
if (types.contains(WebsiteDataType::SessionStorage))
returnValue |= WEBKIT_WEBSITE_DATA_SESSION_STORAGE;
if (types.contains(WebsiteDataType::LocalStorage))
returnValue |= WEBKIT_WEBSITE_DATA_LOCAL_STORAGE;
if (types.contains(WebsiteDataType::WebSQLDatabases))
returnValue |= WEBKIT_WEBSITE_DATA_WEBSQL_DATABASES;
if (types.contains(WebsiteDataType::IndexedDBDatabases))
returnValue |= WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES;
if (types.contains(WebsiteDataType::PlugInData))
returnValue |= WEBKIT_WEBSITE_DATA_PLUGIN_DATA;
return static_cast<WebKitWebsiteDataTypes>(returnValue);
}

WebKitWebsiteData* webkitWebsiteDataCreate(WebsiteDataRecord&& record)
{
if (!recordContainsSupportedDataTypes(record))
return nullptr;

WebKitWebsiteData* websiteData = static_cast<WebKitWebsiteData*>(fastMalloc(sizeof(WebKitWebsiteData)));
new (websiteData) WebKitWebsiteData(WTFMove(record));
return websiteData;
}

const WebKit::WebsiteDataRecord& webkitWebsiteDataGetRecord(WebKitWebsiteData* websiteData)
{
ASSERT(websiteData);
return websiteData->record;
}

/**
* webkit_website_data_ref:
* @website_data: a #WebKitWebsiteData
*
* Atomically increments the reference count of @website_data by one.
* This function is MT-safe and may be called from any thread.
*
* Returns: The passed #WebKitWebsiteData
*
* Since: 2.16
*/
WebKitWebsiteData* webkit_website_data_ref(WebKitWebsiteData* websiteData)
{
g_return_val_if_fail(websiteData, nullptr);

g_atomic_int_inc(&websiteData->referenceCount);
return websiteData;
}

/**
* webkit_website_data_unref:
* @website_data: A #WebKitWebsiteData
*
* Atomically decrements the reference count of @website_data by one.
* If the reference count drops to 0, all memory allocated by
* #WebKitWebsiteData is released. This function is MT-safe and may be
* called from any thread.
*
* Since: 2.16
*/
void webkit_website_data_unref(WebKitWebsiteData* websiteData)
{
g_return_if_fail(websiteData);

if (g_atomic_int_dec_and_test(&websiteData->referenceCount)) {
websiteData->~WebKitWebsiteData();
fastFree(websiteData);
}
}

/**
* webkit_website_data_get_name:
* @website_data: a #WebKitWebsiteData
*
* Gets the name of #WebKitWebsiteData. This is the website name, normally represented by
* a domain or host name. All local documents are grouped in the same #WebKitWebsiteData using
* the name "Local files".
*
* Returns: the website name of @website_data.
*
* Since: 2.16
*/
const char* webkit_website_data_get_name(WebKitWebsiteData* websiteData)
{
g_return_val_if_fail(websiteData, nullptr);

if (websiteData->displayName.isNull()) {
if (websiteData->record.displayName == "Local documents on your computer")
websiteData->displayName = _("Local files");
else
websiteData->displayName = websiteData->record.displayName.utf8();
}
return websiteData->displayName.data();
}

/**
* webkit_website_data_get_types:
* @website_data: a #WebKitWebsiteData
*
* Gets the types of data stored in the client for a #WebKitWebsiteData. These are the
* types actually present, not the types queried with webkit_website_data_manager_fetch().
*
* Returns: a bitmask of #WebKitWebsiteDataTypes in @website_data
*
* Since: 2.16
*/
WebKitWebsiteDataTypes webkit_website_data_get_types(WebKitWebsiteData* websiteData)
{
g_return_val_if_fail(websiteData, static_cast<WebKitWebsiteDataTypes>(0));

return toWebKitWebsiteDataTypes(websiteData->record.types);
}

/**
* webkit_website_data_get_size:
* @website_data: a #WebKitWebsiteData
* @types: a bitmask of #WebKitWebsiteDataTypes
*
* Gets the size of the data of types @types in a #WebKitWebsiteData.
* Note that currently the data size is only known for %WEBKIT_WEBSITE_DATA_DISK_CACHE data type
* so for all other types 0 will be returned.
*
* Returns: the size of @website_data for the given @types.
*
* Since: 2.16
*/
guint64 webkit_website_data_get_size(WebKitWebsiteData* websiteData, WebKitWebsiteDataTypes types)
{
g_return_val_if_fail(websiteData, 0);

if (!types || !websiteData->record.size)
return 0;

guint64 totalSize = 0;
for (auto type : websiteData->record.size->typeSizes.keys()) {
if (type & types)
totalSize += websiteData->record.size->typeSizes.get(type);
}

return totalSize;
}
@@ -0,0 +1,85 @@
/*
* Copyright (C) 2017 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/

#if !defined(__WEBKIT2_H_INSIDE__) && !defined(WEBKIT2_COMPILATION)
#error "Only <webkit2/webkit2.h> can be included directly."
#endif

#ifndef WebKitWebsiteData_h
#define WebKitWebsiteData_h

#include <glib-object.h>
#include <webkit2/WebKitDefines.h>

G_BEGIN_DECLS

#define WEBKIT_TYPE_WEBSITE_DATA (webkit_website_data_get_type())

typedef struct _WebKitWebsiteData WebKitWebsiteData;

/**
* WebKitWebsiteDataTypes:
* @WEBKIT_WEBSITE_DATA_MEMORY_CACHE: Memory cache.
* @WEBKIT_WEBSITE_DATA_DISK_CACHE: HTTP disk cache.
* @WEBKIT_WEBSITE_DATA_OFFLINE_APPLICATION_CACHE: Offline web application cache.
* @WEBKIT_WEBSITE_DATA_SESSION_STORAGE: Session storage data.
* @WEBKIT_WEBSITE_DATA_LOCAL_STORAGE: Local storage data.
* @WEBKIT_WEBSITE_DATA_WEBSQL_DATABASES: WebSQL databases.
* @WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES: IndexedDB databases.
* @WEBKIT_WEBSITE_DATA_PLUGIN_DATA: Plugins data.
* @WEBKIT_WEBSITE_DATA_ALL: All types.
*
* Enum values with flags representing types of Website data.
*
* Since: 2.16
*/
typedef enum {
WEBKIT_WEBSITE_DATA_MEMORY_CACHE = 1 << 0,
WEBKIT_WEBSITE_DATA_DISK_CACHE = 1 << 1,
WEBKIT_WEBSITE_DATA_OFFLINE_APPLICATION_CACHE = 1 << 2,
WEBKIT_WEBSITE_DATA_SESSION_STORAGE = 1 << 3,
WEBKIT_WEBSITE_DATA_LOCAL_STORAGE = 1 << 4,
WEBKIT_WEBSITE_DATA_WEBSQL_DATABASES = 1 << 5,
WEBKIT_WEBSITE_DATA_INDEXEDDB_DATABASES = 1 << 6,
WEBKIT_WEBSITE_DATA_PLUGIN_DATA = 1 << 7,
WEBKIT_WEBSITE_DATA_ALL = (1 << 8) - 1
} WebKitWebsiteDataTypes;

WEBKIT_API GType
webkit_website_data_get_type (void);

WEBKIT_API WebKitWebsiteData *
webkit_website_data_ref (WebKitWebsiteData *website_data);

WEBKIT_API void
webkit_website_data_unref (WebKitWebsiteData *website_data);

WEBKIT_API const char *
webkit_website_data_get_name (WebKitWebsiteData *website_data);

WEBKIT_API WebKitWebsiteDataTypes
webkit_website_data_get_types (WebKitWebsiteData *website_data);

WEBKIT_API guint64
webkit_website_data_get_size (WebKitWebsiteData *website_data,
WebKitWebsiteDataTypes types);

G_END_DECLS

#endif /* WebKitWebsiteData_h */

0 comments on commit e964da8

Please sign in to comment.