Skip to content
Permalink
Browse files
[Settings] Generate the bulk of WebPage::updatePreferences(...)
https://bugs.webkit.org/show_bug.cgi?id=178823

Patch by Sam Weinig <sam@webkit.org> on 2017-10-26
Reviewed by Tim Horton.

* CMakeLists.txt:
* DerivedSources.make:
* WebKit.xcodeproj/project.pbxproj:

    Add new file generation.

* Scripts/GeneratePreferences.rb:

    Replace 'webkitOnly' boolean option with a new 'webcoreBinding' option.
    'webcoreBinding' supports the following values:
        - none (same as webkit only)
        - custom (means that you do bind to a webcore concept, but currently it must
          be done in a custom manner)
        - DeprecatedGlobalSettings (binds to a DeprecatedGlobalSettings setting)
        - RuntimeEnabledFeatures (binds to a RuntimeEnabledFeatures setting)
    If 'webcoreBinding' is not provided, the preference binds to WebCore Setting
    of either the same name or the override name provided by the new 'webcoreName'
    option (we should try to remove the need for 'webcoreName' by unifying with
    WebCore on preference/setting naming).

    A 'condition' option was also added to indicate that the preference is only available
    when that macro condition is true.

    Since we are generating most of WebPage::updatePreferences, we can simplify the
    macros in WebPreferencesDefinitions.h to only have normal/debug/experimental variants
    and remove the need for per-type macros, which were only used in WebPage::updatePreferences.

* Scripts/PreferencesTemplates/WebPageUpdatePreferences.cpp.erb: Added.

    Generates bindings from WebPreferences to WebCore::Settings/DeprecatedGlobalSettings/RuntimeEnabledFeatures.
    Does not generate a binding if the 'webcoreBinding' option is set to either 'none' or 'custom'.

* Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb:

    Simplify down to just normal/debug/experimental macros.

* Shared/WebPreferences.yaml:

    Annotate perferences with new optional 'webcoreBinding', 'webcoreName', and 'condition'
    options.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

    Replace a ton of hand written preference to settings bindings with a call to updatePreferencesGenerated().

* WebProcess/WebPage/WebPage.h:

    Add declaration of updatePreferencesGenerated, remove platformPreferencesDidChange.

* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.
* WebProcess/WebPage/win/WebPageWin.cpp:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.
* WebProcess/WebPage/wpe/WebPageWPE.cpp:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.

    Remove all the empty platformPreferencesDidChange functions.

Canonical link: https://commits.webkit.org/195065@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@224077 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
Sam Weinig authored and webkit-commit-queue committed Oct 27, 2017
1 parent db3c6fb commit e661afe71141a50b131ea174a5f6a40b110c71ea
Showing 15 changed files with 370 additions and 448 deletions.
@@ -907,11 +907,12 @@ list(APPEND WebKit_HEADERS
)

set(WebKit_WEB_PREFERENCES_TEMPLATES
${WEBKIT_DIR}/Scripts/PreferencesTemplates/WebPageUpdatePreferences.cpp.erb
${WEBKIT_DIR}/Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb
)

add_custom_command(
OUTPUT ${DERIVED_SOURCES_WEBKIT_DIR}/WebPreferencesDefinitions.h
OUTPUT ${DERIVED_SOURCES_WEBKIT_DIR}/WebPageUpdatePreferences.cpp ${DERIVED_SOURCES_WEBKIT_DIR}/WebPreferencesDefinitions.h
MAIN_DEPENDENCY ${WEBKIT_DIR}/Shared/WebPreferences.yaml
DEPENDS ${WebKit_WEB_PREFERENCES_TEMPLATES}
COMMAND ${RUBY_EXECUTABLE} ${WEBKIT_DIR}/Scripts/GeneratePreferences.rb --input ${WEBKIT_DIR}/Shared/WebPreferences.yaml --outputDir "${DERIVED_SOURCES_WEBKIT_DIR}"
@@ -921,6 +922,11 @@ list(APPEND WebKit_HEADERS
${DERIVED_SOURCES_WEBKIT_DIR}/WebPreferencesDefinitions.h
)

list(APPEND WebKit_SOURCES
${DERIVED_SOURCES_WEBKIT_DIR}/WebPageUpdatePreferences.cpp
)


list(APPEND WebKit_SOURCES ${WebKit_DERIVED_SOURCES})

WEBKIT_FRAMEWORK(WebKit)
@@ -1,3 +1,73 @@
2017-10-26 Sam Weinig <sam@webkit.org>

[Settings] Generate the bulk of WebPage::updatePreferences(...)
https://bugs.webkit.org/show_bug.cgi?id=178823

Reviewed by Tim Horton.

* CMakeLists.txt:
* DerivedSources.make:
* WebKit.xcodeproj/project.pbxproj:

Add new file generation.

* Scripts/GeneratePreferences.rb:

Replace 'webkitOnly' boolean option with a new 'webcoreBinding' option.
'webcoreBinding' supports the following values:
- none (same as webkit only)
- custom (means that you do bind to a webcore concept, but currently it must
be done in a custom manner)
- DeprecatedGlobalSettings (binds to a DeprecatedGlobalSettings setting)
- RuntimeEnabledFeatures (binds to a RuntimeEnabledFeatures setting)
If 'webcoreBinding' is not provided, the preference binds to WebCore Setting
of either the same name or the override name provided by the new 'webcoreName'
option (we should try to remove the need for 'webcoreName' by unifying with
WebCore on preference/setting naming).

A 'condition' option was also added to indicate that the preference is only available
when that macro condition is true.

Since we are generating most of WebPage::updatePreferences, we can simplify the
macros in WebPreferencesDefinitions.h to only have normal/debug/experimental variants
and remove the need for per-type macros, which were only used in WebPage::updatePreferences.

* Scripts/PreferencesTemplates/WebPageUpdatePreferences.cpp.erb: Added.

Generates bindings from WebPreferences to WebCore::Settings/DeprecatedGlobalSettings/RuntimeEnabledFeatures.
Does not generate a binding if the 'webcoreBinding' option is set to either 'none' or 'custom'.

* Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb:

Simplify down to just normal/debug/experimental macros.

* Shared/WebPreferences.yaml:

Annotate perferences with new optional 'webcoreBinding', 'webcoreName', and 'condition'
options.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):

Replace a ton of hand written preference to settings bindings with a call to updatePreferencesGenerated().

* WebProcess/WebPage/WebPage.h:

Add declaration of updatePreferencesGenerated, remove platformPreferencesDidChange.

* WebProcess/WebPage/gtk/WebPageGtk.cpp:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.
* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.
* WebProcess/WebPage/mac/WebPageMac.mm:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.
* WebProcess/WebPage/win/WebPageWin.cpp:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.
* WebProcess/WebPage/wpe/WebPageWPE.cpp:
(WebKit::WebPage::platformPreferencesDidChange): Deleted.

Remove all the empty platformPreferencesDidChange functions.

2017-10-26 Alex Christensen <achristensen@webkit.org>

Move WKWebViewConfiguration validation to WKWebView construction
@@ -288,11 +288,12 @@ all : WebAutomationSessionProxyScriptSource.h
# WebPreferences generation

WEB_PREFERENCES_TEMPLATES = \
$(WebKit2)/Scripts/PreferencesTemplates/WebPageUpdatePreferences.cpp.erb \
$(WebKit2)/Scripts/PreferencesTemplates/WebPreferencesDefinitions.h.erb \
#

all : WebPreferencesDefinitions.h
all : WebPreferencesDefinitions.h WebPageUpdatePreferences.cpp

WebPreferencesDefinitions%h : $(WebKit2)/Scripts/GeneratePreferences.rb $(WEB_PREFERENCES_TEMPLATES) $(WebKit2)/Shared/WebPreferences.yaml
WebPreferencesDefinitions%h WebPageUpdatePreferences%cpp: $(WebKit2)/Scripts/GeneratePreferences.rb $(WEB_PREFERENCES_TEMPLATES) $(WebKit2)/Shared/WebPreferences.yaml
$(RUBY) $< --input $(WebKit2)/Shared/WebPreferences.yaml

@@ -67,18 +67,21 @@ class Preference
attr_accessor :defaultValue
attr_accessor :humanReadableName
attr_accessor :humanReadableDescription
attr_accessor :webkitOnly
attr_accessor :category
attr_accessor :webcoreBinding
attr_accessor :condition

def initialize(name, opts)
@name = name
@type = opts["type"]
@defaultValue = opts["defaultValue"]
@humanReadableName = '"' + (opts["humanReadableName"] || "") + '"'
@humanReadableDescription = '"' + (opts["humanReadableDescription"] || "") + '"'
@webkitOnly = opts["webkitOnly"]
@category = opts["category"]
@getter = opts["getter"]
@webcoreBinding = opts["webcoreBinding"]
@webcoreName = opts["webcoreName"]
@condition = opts["condition"]
end

def nameLower
@@ -92,6 +95,23 @@ def nameLower
@name[0].downcase + @name[1..@name.length]
end
end

def webcoreNameUpper
if @webcoreName
@webcoreName[0].upcase + @webcoreName[1..@webcoreName.length]
else
@name
end
end

def typeUpper
if @type == "uint32_t"
"UInt32"
else
@type.capitalize
end
end

end

class Conditional
@@ -114,16 +134,13 @@ def initialize(hash)
end
@preferences.sort! { |x, y| x.name <=> y.name }

@boolPreferencesNotDebug = @preferences.select { |p| !p.category && !p.webkitOnly && p.type == "bool" }
@doublePreferencesNotDebug = @preferences.select { |p| !p.category && !p.webkitOnly && p.type == "double" }
@intPreferencesNotDebug = @preferences.select { |p| !p.category && !p.webkitOnly && p.type == "uint32_t" }
@stringPreferencesNotDebug = @preferences.select { |p| !p.category && !p.webkitOnly && p.type == "String" }
@stringPreferencesNotDebugNotInWebKit = @preferences.select { |p| !p.category && p.webkitOnly && p.type == "String" }

@boolPreferencesDebug = @preferences.select { |p| p.category == "debug" && !p.webkitOnly && p.type == "bool" }
@intPreferencesDebug = @preferences.select { |p| p.category == "debug" && !p.webkitOnly && p.type == "uint32_t" }
@preferencesNotDebug = @preferences.select { |p| !p.category }
@preferencesDebug = @preferences.select { |p| p.category == "debug" }
@experimentalFeatures = @preferences.select { |p| p.category == "experimental" }

@experimentalFeature = @preferences.select { |p| p.category == "experimental" && !p.webkitOnly }
@preferencesBoundToSetting = @preferences.select { |p| !p.webcoreBinding }
@preferencesBoundToDeprecatedGlobalSettings = @preferences.select { |p| p.webcoreBinding == "DeprecatedGlobalSettings" }
@preferencesBoundToRuntimeEnabledFeatures = @preferences.select { |p| p.webcoreBinding == "RuntimeEnabledFeatures" }
end

def renderToFile(template, file)
@@ -138,3 +155,4 @@ def renderToFile(template, file)

preferences = Preferences.new(parsedPreferences)
preferences.renderToFile("PreferencesTemplates/WebPreferencesDefinitions.h.erb", File.join(options[:outputDirectory], "WebPreferencesDefinitions.h"))
preferences.renderToFile("PreferencesTemplates/WebPageUpdatePreferences.cpp.erb", File.join(options[:outputDirectory], "WebPageUpdatePreferences.cpp"))
@@ -0,0 +1,75 @@
/*
* THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT.
*
* Copyright (C) 2017 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "WebPage.h"

#include "WebPreferencesKeys.h"
#include "WebPreferencesStore.h"
#include <WebCore/DeprecatedGlobalSettings.h>
#include <WebCore/Page.h>
#include <WebCore/RuntimeEnabledFeatures.h>
#include <WebCore/Settings.h>

namespace WebKit {

void WebPage::updatePreferencesGenerated(const WebPreferencesStore& store)
{
WebCore::Settings& settings = m_page->settings();

<%- for @pref in @preferencesBoundToSetting do -%>
<%- if @pref.condition -%>
#if <%= @pref.condition %>
<%- end -%>
settings.set<%= @pref.webcoreNameUpper %>(store.get<%= @pref.typeUpper %>ValueForKey(WebPreferencesKey::<%= @pref.nameLower %>Key()));
<%- if @pref.condition -%>
#endif
<%- end -%>
<%- end -%>
<%- for @pref in @preferencesBoundToDeprecatedGlobalSettings do -%>
<%- if @pref.condition -%>
#if <%= @pref.condition %>
<%- end -%>
WebCore::DeprecatedGlobalSettings::set<%= @pref.webcoreNameUpper %>(store.get<%= @pref.typeUpper %>ValueForKey(WebPreferencesKey::<%= @pref.nameLower %>Key()));
<%- if @pref.condition -%>
#endif
<%- end -%>
<%- end -%>
<%- for @pref in @preferencesBoundToRuntimeEnabledFeatures do -%>
<%- if @pref.condition -%>
#if <%= @pref.condition %>
<%- end -%>
WebCore::RuntimeEnabledFeatures::sharedFeatures().set<%= @pref.webcoreNameUpper %>(store.get<%= @pref.typeUpper %>ValueForKey(WebPreferencesKey::<%= @pref.nameLower %>Key()));
<%- if @pref.condition -%>
#endif
<%- end -%>
<%- end -%>
}

}
@@ -31,72 +31,26 @@

// macro(KeyUpper, KeyLower, TypeNameUpper, TypeName, DefaultValue, HumanReadableName, HumanReadableDescription)

#define FOR_EACH_WEBKIT_BOOL_PREFERENCE(macro) \
<%- for @pref in @boolPreferencesNotDebug do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, Bool, bool, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
<%- end -%>
\

#define FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \
<%- for @pref in @doublePreferencesNotDebug do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, Double, double, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
<%- end -%>
\

#define FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \
<%- for @pref in @intPreferencesNotDebug do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, UInt32, uint32_t, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
<%- end -%>
\

#define FOR_EACH_WEBKIT_STRING_PREFERENCE(macro) \
<%- for @pref in @stringPreferencesNotDebug do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, String, String, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
<%- end -%>
\

#define FOR_EACH_WEBKIT_STRING_PREFERENCE_NOT_IN_WEBCORE(macro) \
<%- for @pref in @stringPreferencesNotDebugNotInWebKit do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, String, String, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
#define FOR_EACH_WEBKIT_PREFERENCE(macro) \
<%- for @pref in @preferencesNotDebug do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, <%= @pref.typeUpper %>, <%= @pref.type %>, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
<%- end -%>
\


// Debug Preferences

#define FOR_EACH_WEBKIT_DEBUG_BOOL_PREFERENCE(macro) \
<%- for @pref in @boolPreferencesDebug do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, Bool, bool, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
<%- end -%>
\

#define FOR_EACH_WEBKIT_DEBUG_UINT32_PREFERENCE(macro) \
<%- for @pref in @intPreferencesDebug do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, UInt32, uint32_t, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
#define FOR_EACH_WEBKIT_DEBUG_PREFERENCE(macro) \
<%- for @pref in @preferencesDebug do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, <%= @pref.typeUpper %>, <%= @pref.type %>, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
<%- end -%>
\


// Experimental Features

#define FOR_EACH_WEBKIT_EXPERIMENTAL_FEATURE_PREFERENCE(macro) \
<%- for @pref in @experimentalFeature do -%>
<%- for @pref in @experimentalFeatures do -%>
macro(<%= @pref.name %>, <%= @pref.nameLower %>, Bool, bool, <%= @pref.defaultValue %>, <%= @pref.humanReadableName %>, <%= @pref.humanReadableDescription %>) \
<%- end -%>
\



#define FOR_EACH_WEBKIT_DEBUG_PREFERENCE(macro) \
FOR_EACH_WEBKIT_DEBUG_BOOL_PREFERENCE(macro) \
FOR_EACH_WEBKIT_DEBUG_UINT32_PREFERENCE(macro) \
\

#define FOR_EACH_WEBKIT_PREFERENCE(macro) \
FOR_EACH_WEBKIT_BOOL_PREFERENCE(macro) \
FOR_EACH_WEBKIT_DOUBLE_PREFERENCE(macro) \
FOR_EACH_WEBKIT_UINT32_PREFERENCE(macro) \
FOR_EACH_WEBKIT_STRING_PREFERENCE(macro) \
FOR_EACH_WEBKIT_STRING_PREFERENCE_NOT_IN_WEBCORE(macro) \
\

0 comments on commit e661afe

Please sign in to comment.