Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Source/WebKit/UIProcess/API/glib/WebKitFeature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,27 @@ WebKitFeature* webkit_feature_list_get(WebKitFeatureList* featureList, gsize ind
g_return_val_if_fail(index < featureList->items.size(), nullptr);
return featureList->items[index];
}

/**
* webkit_feature_list_find:
* @feature_list: a #WebKitFeatureList
* @identifier: a #WebKitFeature identifier
*
* Finds a feature given its identifier.
*
* Returns: (transfer none) (nullable): The feature with the given
* @identifier, or @NULL if it cannot be found.
*
* Since: 2.54
*/
WebKitFeature* webkit_feature_list_find(WebKitFeatureList* featureList, const char* identifier)
{
g_return_val_if_fail(featureList, nullptr);
g_return_val_if_fail(identifier, nullptr);

auto it = std::ranges::find_if(featureList->items, [identifier](WebKitFeature* feature) -> bool {
return !g_ascii_strcasecmp(identifier, webkit_feature_get_identifier(feature));
});

return (it != featureList->items.end()) ? *it : nullptr;
}
4 changes: 4 additions & 0 deletions Source/WebKit/UIProcess/API/glib/WebKitFeature.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ WEBKIT_API WebKitFeature *
webkit_feature_list_get (WebKitFeatureList *feature_list,
gsize index);

WEBKIT_API WebKitFeature *
webkit_feature_list_find (WebKitFeatureList *feature_list,
const gchar *identifier);

G_DEFINE_AUTOPTR_CLEANUP_FUNC(WebKitFeatureList, webkit_feature_list_unref)

G_END_DECLS
Expand Down
12 changes: 1 addition & 11 deletions Tools/MiniBrowser/gtk/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,6 @@ static gboolean isValidParameterType(GType gParamType)
|| gParamType == G_TYPE_FLOAT);
}

static WebKitFeature* findFeature(WebKitFeatureList *featureList, const char *identifier)
{
for (gsize i = 0; i < webkit_feature_list_get_length(featureList); i++) {
WebKitFeature *feature = webkit_feature_list_get(featureList, i);
if (!g_ascii_strcasecmp(identifier, webkit_feature_get_identifier(feature)))
return feature;
}
return NULL;
}

static gboolean parseFeaturesOptionCallback(const gchar *option, const gchar *value, WebKitSettings *webSettings, GError **error)
{
g_autoptr(WebKitFeatureList) featureList = webkit_settings_get_all_features();
Expand Down Expand Up @@ -311,7 +301,7 @@ static gboolean parseFeaturesOptionCallback(const gchar *option, const gchar *va
return FALSE;
}

WebKitFeature *feature = findFeature(featureList, item);
WebKitFeature *feature = webkit_feature_list_find(featureList, item);
if (!feature) {
g_set_error(error, G_OPTION_ERROR, G_OPTION_ERROR_FAILED, "Feature '%s' is not available", item);
return FALSE;
Expand Down
12 changes: 1 addition & 11 deletions Tools/MiniBrowser/wpe/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,6 @@ static void automationStartedCallback(WebKitWebContext*, WebKitAutomationSession
g_signal_connect(session, "create-web-view", G_CALLBACK(createWebViewForAutomationCallback), view);
}

static WebKitFeature* findFeature(WebKitFeatureList* featureList, const char* identifier)
{
for (gsize i = 0; i < webkit_feature_list_get_length(featureList); i++) {
WebKitFeature* feature = webkit_feature_list_get(featureList, i);
if (!g_ascii_strcasecmp(identifier, webkit_feature_get_identifier(feature)))
return feature;
}
return nullptr;
}

static void activate(GApplication* application, WPEToolingBackends::ViewBackend* backend)
{
g_application_hold(application);
Expand Down Expand Up @@ -507,7 +497,7 @@ static void activate(GApplication* application, WPEToolingBackends::ViewBackend*
continue;
}

if (auto* feature = findFeature(features, item))
if (auto* feature = webkit_feature_list_find(features, item))
webkit_settings_set_feature_enabled(settings, feature, enabled);
else
g_printerr("Feature '%s' is not available.", item);
Expand Down
16 changes: 16 additions & 0 deletions Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,22 @@ void testWebKitFeatures(Test* test, gconstpointer)

g_assert(webkit_settings_get_feature_enabled(settings.get(), feature) == webkit_feature_get_default_value(feature));
}

// Check finding features given their identifier.
if (webkit_feature_list_get_length(allFeatures)) {
WebKitFeature* firstFeature = webkit_feature_list_get(allFeatures, 0);
WebKitFeature* foundFeature = webkit_feature_list_find(allFeatures, webkit_feature_get_identifier(firstFeature));
g_assert_nonnull(foundFeature);
g_assert(firstFeature == foundFeature);

g_autofree char* lowerCaseIdentifier = g_utf8_strdown(webkit_feature_get_identifier(firstFeature), -1);
foundFeature = webkit_feature_list_find(allFeatures, lowerCaseIdentifier);
g_assert_nonnull(foundFeature);
g_assert(firstFeature == foundFeature);
}

WebKitFeature* foundFeature = webkit_feature_list_find(allFeatures, "ThisFeatureIdentifierCannotPossiblyExist");
g_assert_null(foundFeature);
}

void testWebKitSettingsApplyFromConfigFile(Test* test, gconstpointer)
Expand Down