Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[IPC] Add WTF::EnumTraits<> for every enum type used in IPC
<https://webkit.org/b/213093>

Reviewed by Darin Adler.

Summary:
- Change underlying type of enum class to `bool` when there are
  only two values.  In some cases, reorder the two values so the
  mapping to 0 and 1 makes more sense.  Converting every enum to
  an enum class is not a goal of this patch, so some two-value
  enums stil have WTF::EnumTraits<> defined as noted below.
- Add WTF::EnumTraits<> for the remaining enum types that are
  used by IPC::Encoder::encodeEnum() and
  IPC::Decoder::decodeEnum() so that WTF::isValidEnum<>() checks
  may be added next.
- Add #include <WebCore/LibWebRTCEnumTraits.h> as needed.

Source/WebCore:

* Headers.cmake:
* WebCore.xcodeproj/project.pbxproj:
- Add LibWebRTCEnumTraits.h to project. Keep these definitions
  separate from the libwebrtc project cut down on changes to
  re-merge after updating.

* platform/mediastream/libwebrtc/LibWebRTCEnumTraits.h: Add.

* Modules/applepay/ApplePaySessionPaymentRequest.h:
* Modules/indexeddb/IDBTransactionMode.h:
* Modules/indexeddb/IndexedDB.h:
(WTF::EnumTraits<WebCore::IndexedDB::IndexRecordType>):
- Remove after changing enum class to bool.
* Modules/indexeddb/shared/IDBGetRecordData.h:
* Modules/indexeddb/shared/IDBResultData.h:
* WebCore.xcodeproj/project.pbxproj:
* dom/ExceptionCode.h:
* editing/CompositionUnderline.h:
* html/Autofill.h:
* html/DataListSuggestionInformation.h:
* html/EnterKeyHint.h:
* html/LinkIconType.h:
* loader/FrameLoaderTypes.h:
- Alphabetize WTF::EnumTraits<> definitions.
* loader/ResourceLoaderOptions.h:
* page/SecurityOrigin.h:
* page/UserStyleSheetTypes.h:
(WTF::EnumTraits<WebCore::UserStyleLevel>):
- Define this since UserStyleLevel is not an enum class.
* page/scrolling/ScrollingCoordinatorTypes.h:
* platform/ContextMenuItem.h:
* platform/Cursor.h:
* platform/DragData.h:
* platform/FileChooser.h:
* platform/PopupMenuStyle.h:
* platform/ScreenProperties.h:
* platform/ScrollTypes.h:
* platform/SerializedPlatformDataCueValue.h:
(WebCore::SerializedPlatformDataCueValue::PlatformType):
- Convert from enum to enum class.
* platform/UserInterfaceLayoutDirection.h:
* platform/animation/TimingFunction.h:
* platform/graphics/GraphicsContext.h:
* platform/graphics/GraphicsLayer.h:
* platform/graphics/GraphicsTypes.h:
- Alphabetize WTF::EnumTraits<> definitions.
* platform/graphics/Image.h:
* platform/graphics/Path.h:
* platform/graphics/ca/PlatformCAAnimation.h:
* platform/graphics/ca/PlatformCALayer.h:
* platform/graphics/filters/FilterOperation.h:
* platform/mediastream/MediaConstraints.h:
* platform/mediastream/MediaStreamRequest.h:
(WTF::EnumTraits<WebCore::MediaStreamRequest::Type>):
- Fix EnumTraits definition (missing "::Type").
* platform/mediastream/RealtimeMediaSourceCapabilities.h:
* platform/mediastream/RealtimeMediaSourceSupportedConstraints.h:
* platform/network/CredentialBase.h:
* platform/network/ProtectionSpaceBase.h:
* platform/network/ResourceErrorBase.h:
* platform/network/soup/SoupNetworkProxySettings.h:
* platform/text/TextChecking.h:
(WTF::EnumTraits<WebCore::TextCheckingProcessType):
- Define this since TextCheckingProcessType is not an enum class.
* platform/text/WritingMode.h:
* rendering/Pagination.h:
* workers/service/ServiceWorkerJobType.h:

Source/WebKit:

* GPUProcess/GPUConnectionToWebProcess.h:
* GPUProcess/GPUProcess.h:
* NetworkProcess/NetworkLoadParameters.h:
* Shared/API/APIObject.h:
* Shared/ContextMenuContextData.h:
* Shared/DrawingAreaInfo.h:
* Shared/FocusedElementInformation.h:
* Shared/PrintInfo.h:
(WTF::EnumTraits<WebKit::PrintInfo::PrintMode>):
- Define this since PrintMode is not an enum class.
* Shared/RTCPacketOptions.cpp:
* Shared/SessionState.h:
* Shared/TouchBarMenuItemData.h:
* Shared/WebEvent.h:
* Shared/WebPopupItem.cpp:
(WebKit::WebPopupItem::WebPopupItem):
- Fix reference to WebPopupItem::Type enum.
* Shared/WebPopupItem.h:
(WebKit::WebPopupItem::Type):
- Convert from enum to enum class.
* Shared/WebsiteData/WebsiteDataType.h:
* Shared/glib/InputMethodState.h:
* Shared/glib/UserMessage.h:
* Shared/mac/ColorSpaceData.mm:
* Shared/mac/SecItemRequestData.h:
* UIProcess/mac/WebPopupMenuProxyMac.mm:
(WebKit::WebPopupMenuProxyMac::populate):
- Fix reference to WebPopupItem::Type enum.
* WebProcess/Plugins/Plugin.cpp:
* WebProcess/WebCoreSupport/WebPopupMenu.cpp:
(WebKit::WebPopupMenu::populateItems):
- Fix reference to WebPopupItem::Type enum.
* WebProcess/WebPage/RemoteLayerTree/PlatformCAAnimationRemote.h:


Canonical link: https://commits.webkit.org/225887@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@262933 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
ddkilzer committed Jun 12, 2020
1 parent c4c48d0 commit 45928c2
Show file tree
Hide file tree
Showing 84 changed files with 1,775 additions and 144 deletions.
87 changes: 87 additions & 0 deletions Source/WebCore/ChangeLog
@@ -1,3 +1,90 @@
2020-06-11 David Kilzer <ddkilzer@apple.com>

[IPC] Add WTF::EnumTraits<> for every enum type used in IPC
<https://webkit.org/b/213093>

Reviewed by Darin Adler.

Summary:
- Change underlying type of enum class to `bool` when there are
only two values. In some cases, reorder the two values so the
mapping to 0 and 1 makes more sense. Converting every enum to
an enum class is not a goal of this patch, so some two-value
enums stil have WTF::EnumTraits<> defined as noted below.
- Add WTF::EnumTraits<> for the remaining enum types that are
used by IPC::Encoder::encodeEnum() and
IPC::Decoder::decodeEnum() so that WTF::isValidEnum<>() checks
may be added next.
- Add #include <WebCore/LibWebRTCEnumTraits.h> as needed.

* Headers.cmake:
* WebCore.xcodeproj/project.pbxproj:
- Add LibWebRTCEnumTraits.h to project. Keep these definitions
separate from the libwebrtc project cut down on changes to
re-merge after updating.

* platform/mediastream/libwebrtc/LibWebRTCEnumTraits.h: Add.

* Modules/applepay/ApplePaySessionPaymentRequest.h:
* Modules/indexeddb/IDBTransactionMode.h:
* Modules/indexeddb/IndexedDB.h:
(WTF::EnumTraits<WebCore::IndexedDB::IndexRecordType>):
- Remove after changing enum class to bool.
* Modules/indexeddb/shared/IDBGetRecordData.h:
* Modules/indexeddb/shared/IDBResultData.h:
* WebCore.xcodeproj/project.pbxproj:
* dom/ExceptionCode.h:
* editing/CompositionUnderline.h:
* html/Autofill.h:
* html/DataListSuggestionInformation.h:
* html/EnterKeyHint.h:
* html/LinkIconType.h:
* loader/FrameLoaderTypes.h:
- Alphabetize WTF::EnumTraits<> definitions.
* loader/ResourceLoaderOptions.h:
* page/SecurityOrigin.h:
* page/UserStyleSheetTypes.h:
(WTF::EnumTraits<WebCore::UserStyleLevel>):
- Define this since UserStyleLevel is not an enum class.
* page/scrolling/ScrollingCoordinatorTypes.h:
* platform/ContextMenuItem.h:
* platform/Cursor.h:
* platform/DragData.h:
* platform/FileChooser.h:
* platform/PopupMenuStyle.h:
* platform/ScreenProperties.h:
* platform/ScrollTypes.h:
* platform/SerializedPlatformDataCueValue.h:
(WebCore::SerializedPlatformDataCueValue::PlatformType):
- Convert from enum to enum class.
* platform/UserInterfaceLayoutDirection.h:
* platform/animation/TimingFunction.h:
* platform/graphics/GraphicsContext.h:
* platform/graphics/GraphicsLayer.h:
* platform/graphics/GraphicsTypes.h:
- Alphabetize WTF::EnumTraits<> definitions.
* platform/graphics/Image.h:
* platform/graphics/Path.h:
* platform/graphics/ca/PlatformCAAnimation.h:
* platform/graphics/ca/PlatformCALayer.h:
* platform/graphics/filters/FilterOperation.h:
* platform/mediastream/MediaConstraints.h:
* platform/mediastream/MediaStreamRequest.h:
(WTF::EnumTraits<WebCore::MediaStreamRequest::Type>):
- Fix EnumTraits definition (missing "::Type").
* platform/mediastream/RealtimeMediaSourceCapabilities.h:
* platform/mediastream/RealtimeMediaSourceSupportedConstraints.h:
* platform/network/CredentialBase.h:
* platform/network/ProtectionSpaceBase.h:
* platform/network/ResourceErrorBase.h:
* platform/network/soup/SoupNetworkProxySettings.h:
* platform/text/TextChecking.h:
(WTF::EnumTraits<WebCore::TextCheckingProcessType):
- Define this since TextCheckingProcessType is not an enum class.
* platform/text/WritingMode.h:
* rendering/Pagination.h:
* workers/service/ServiceWorkerJobType.h:

2020-06-11 Beth Dakin <bdakin@apple.com>

Fix comment after blocklist transition
Expand Down
1 change: 1 addition & 0 deletions Source/WebCore/Headers.cmake
Expand Up @@ -1255,6 +1255,7 @@ set(WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/mediastream/VideoPreset.h
platform/mediastream/WebAudioSourceProvider.h

platform/mediastream/libwebrtc/LibWebRTCEnumTraits.h
platform/mediastream/libwebrtc/LibWebRTCMacros.h
platform/mediastream/libwebrtc/LibWebRTCProvider.h
platform/mediastream/libwebrtc/LibWebRTCSocketIdentifier.h
Expand Down
19 changes: 15 additions & 4 deletions Source/WebCore/Modules/applepay/ApplePaySessionPaymentRequest.h
Expand Up @@ -29,6 +29,7 @@

#include "PaymentContact.h"
#include "PaymentInstallmentConfigurationWebCore.h"
#include <wtf/EnumTraits.h>
#include <wtf/Optional.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
Expand Down Expand Up @@ -85,7 +86,7 @@ class ApplePaySessionPaymentRequest {
void setMerchantCapabilities(const MerchantCapabilities& merchantCapabilities) { m_merchantCapabilities = merchantCapabilities; }

struct LineItem {
enum class Type {
enum class Type : bool {
Pending,
Final,
} type { Type::Final };
Expand Down Expand Up @@ -130,7 +131,7 @@ class ApplePaySessionPaymentRequest {
const Vector<String>& supportedCountries() const { return m_supportedCountries; }
void setSupportedCountries(Vector<String>&& supportedCountries) { m_supportedCountries = WTFMove(supportedCountries); }

enum class Requester {
enum class Requester : bool {
ApplePayJS,
PaymentRequest,
};
Expand Down Expand Up @@ -221,10 +222,20 @@ struct ShippingMethodUpdate {

WEBCORE_EXPORT bool isFinalStateResult(const Optional<PaymentAuthorizationResult>&);

}
} // namespace WebCore

namespace WTF {

template<> struct EnumTraits<WebCore::ApplePaySessionPaymentRequest::ShippingType> {
using values = EnumValues<
WebCore::ApplePaySessionPaymentRequest::ShippingType,
WebCore::ApplePaySessionPaymentRequest::ShippingType::Shipping,
WebCore::ApplePaySessionPaymentRequest::ShippingType::Delivery,
WebCore::ApplePaySessionPaymentRequest::ShippingType::StorePickup,
WebCore::ApplePaySessionPaymentRequest::ShippingType::ServicePickup
>;
};

template<> struct EnumTraits<WebCore::PaymentError::Code> {
using values = EnumValues<
WebCore::PaymentError::Code,
Expand Down Expand Up @@ -254,6 +265,6 @@ template<> struct EnumTraits<WebCore::PaymentError::ContactField> {
>;
};

}
} // namespace WTF

#endif
17 changes: 16 additions & 1 deletion Source/WebCore/Modules/indexeddb/IDBTransactionMode.h
Expand Up @@ -27,6 +27,8 @@

#if ENABLE(INDEXED_DATABASE)

#include <wtf/EnumTraits.h>

namespace WebCore {

enum class IDBTransactionMode {
Expand All @@ -35,6 +37,19 @@ enum class IDBTransactionMode {
Versionchange
};

}
} // namespace WebCore

namespace WTF {

template<> struct EnumTraits<WebCore::IDBTransactionMode> {
using values = EnumValues<
WebCore::IDBTransactionMode,
WebCore::IDBTransactionMode::Readonly,
WebCore::IDBTransactionMode::Readwrite,
WebCore::IDBTransactionMode::Versionchange
>;
};

} // namespace WTF

#endif
41 changes: 33 additions & 8 deletions Source/WebCore/Modules/indexeddb/IndexedDB.h
Expand Up @@ -50,13 +50,13 @@ enum class CursorDirection {
};
const unsigned CursorDirectionMaximum = 3;

enum class CursorType {
enum class CursorType : bool {
KeyAndValue = 0,
KeyOnly = 1,
};
const unsigned CursorTypeMaximum = 1;

enum class CursorSource {
enum class CursorSource : bool {
Index,
ObjectStore,
};
Expand All @@ -72,7 +72,7 @@ enum class ObjectStoreOverwriteMode {
NoOverwrite,
};

enum class IndexRecordType {
enum class IndexRecordType : bool {
Key,
Value,
};
Expand Down Expand Up @@ -107,7 +107,7 @@ enum class GetAllType {

enum class ConnectionClosedOnBehalfOfServer : bool { No, Yes };

enum class CursorIterateOption {
enum class CursorIterateOption : bool {
DoNotReply,
Reply,
};
Expand All @@ -118,11 +118,27 @@ enum class CursorIterateOption {

namespace WTF {

template<> struct EnumTraits<WebCore::IndexedDB::IndexRecordType> {
template<> struct EnumTraits<WebCore::IndexedDB::CursorDirection> {
using values = EnumValues<
WebCore::IndexedDB::IndexRecordType,
WebCore::IndexedDB::IndexRecordType::Key,
WebCore::IndexedDB::IndexRecordType::Value
WebCore::IndexedDB::CursorDirection,
WebCore::IndexedDB::CursorDirection::Next,
WebCore::IndexedDB::CursorDirection::Nextunique,
WebCore::IndexedDB::CursorDirection::Prev,
WebCore::IndexedDB::CursorDirection::Prevunique
>;
};

template<> struct EnumTraits<WebCore::IndexedDB::KeyType> {
using values = EnumValues<
WebCore::IndexedDB::KeyType,
WebCore::IndexedDB::KeyType::Max,
WebCore::IndexedDB::KeyType::Invalid,
WebCore::IndexedDB::KeyType::Array,
WebCore::IndexedDB::KeyType::Binary,
WebCore::IndexedDB::KeyType::String,
WebCore::IndexedDB::KeyType::Date,
WebCore::IndexedDB::KeyType::Number,
WebCore::IndexedDB::KeyType::Min
>;
};

Expand All @@ -135,6 +151,15 @@ template<> struct EnumTraits<WebCore::IndexedDB::ObjectStoreOverwriteMode> {
>;
};

template<> struct EnumTraits<WebCore::IndexedDB::RequestType> {
using values = EnumValues<
WebCore::IndexedDB::RequestType,
WebCore::IndexedDB::RequestType::Open,
WebCore::IndexedDB::RequestType::Delete,
WebCore::IndexedDB::RequestType::Other
>;
};

} // namespace WTF

#endif // ENABLED(INDEXED_DATABASE)
Expand Up @@ -41,7 +41,7 @@ namespace WebCore {
class IDBResultData;

namespace IndexedDB {
enum class IndexRecordType;
enum class IndexRecordType : bool;
}

namespace IDBClient {
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/indexeddb/server/IDBBackingStore.h
Expand Up @@ -45,14 +45,14 @@ class IDBTransactionInfo;
class IDBValue;
class ThreadSafeDataBuffer;

enum class IDBGetRecordDataType;
enum class IDBGetRecordDataType : bool;

struct IDBGetAllRecordsData;
struct IDBIterateCursorData;
struct IDBKeyRangeData;

namespace IndexedDB {
enum class IndexRecordType;
enum class IndexRecordType : bool;
}

namespace IDBServer {
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/indexeddb/server/MemoryIndex.h
Expand Up @@ -46,7 +46,7 @@ struct IDBKeyRangeData;

namespace IndexedDB {
enum class GetAllType;
enum class IndexRecordType;
enum class IndexRecordType : bool;
}

namespace IDBServer {
Expand Down
Expand Up @@ -52,7 +52,7 @@ struct IDBKeyRangeData;

namespace IndexedDB {
enum class GetAllType;
enum class IndexRecordType;
enum class IndexRecordType : bool;
}

namespace IDBServer {
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/indexeddb/server/UniqueIDBDatabase.h
Expand Up @@ -51,10 +51,10 @@ class IDBRequestData;
class IDBTransactionInfo;
class StorageQuotaManager;

enum class IDBGetRecordDataType;
enum class IDBGetRecordDataType : bool;

namespace IndexedDB {
enum class IndexRecordType;
enum class IndexRecordType : bool;
}

namespace IDBServer {
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/Modules/indexeddb/shared/IDBCursorInfo.h
Expand Up @@ -36,8 +36,8 @@ class IDBTransaction;

namespace IndexedDB {
enum class CursorDirection;
enum class CursorSource;
enum class CursorType;
enum class CursorSource : bool;
enum class CursorType : bool;
}

struct IDBKeyRangeData;
Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/Modules/indexeddb/shared/IDBGetRecordData.h
Expand Up @@ -28,10 +28,11 @@
#if ENABLE(INDEXED_DATABASE)

#include "IDBKeyRangeData.h"
#include <wtf/EnumTraits.h>

namespace WebCore {

enum class IDBGetRecordDataType {
enum class IDBGetRecordDataType : bool {
KeyOnly,
KeyAndValue,
};
Expand Down
2 changes: 1 addition & 1 deletion Source/WebCore/Modules/indexeddb/shared/IDBRequestData.h
Expand Up @@ -37,7 +37,7 @@ class IDBOpenDBRequest;
class IDBTransaction;

namespace IndexedDB {
enum class IndexRecordType;
enum class IndexRecordType : bool;
}

namespace IDBClient {
Expand Down
29 changes: 29 additions & 0 deletions Source/WebCore/Modules/indexeddb/shared/IDBResultData.h
Expand Up @@ -35,6 +35,7 @@
#include "IDBResourceIdentifier.h"
#include "IDBTransactionInfo.h"
#include "ThreadSafeDataBuffer.h"
#include <wtf/EnumTraits.h>

namespace WebCore {

Expand Down Expand Up @@ -235,4 +236,32 @@ template<class Decoder> Optional<IDBResultData> IDBResultData::decode(Decoder& d

} // namespace WebCore

namespace WTF {

template<> struct EnumTraits<WebCore::IDBResultType> {
using values = EnumValues<
WebCore::IDBResultType,
WebCore::IDBResultType::Error,
WebCore::IDBResultType::OpenDatabaseSuccess,
WebCore::IDBResultType::OpenDatabaseUpgradeNeeded,
WebCore::IDBResultType::DeleteDatabaseSuccess,
WebCore::IDBResultType::CreateObjectStoreSuccess,
WebCore::IDBResultType::DeleteObjectStoreSuccess,
WebCore::IDBResultType::ClearObjectStoreSuccess,
WebCore::IDBResultType::PutOrAddSuccess,
WebCore::IDBResultType::GetRecordSuccess,
WebCore::IDBResultType::GetAllRecordsSuccess,
WebCore::IDBResultType::GetCountSuccess,
WebCore::IDBResultType::DeleteRecordSuccess,
WebCore::IDBResultType::CreateIndexSuccess,
WebCore::IDBResultType::DeleteIndexSuccess,
WebCore::IDBResultType::OpenCursorSuccess,
WebCore::IDBResultType::IterateCursorSuccess,
WebCore::IDBResultType::RenameObjectStoreSuccess,
WebCore::IDBResultType::RenameIndexSuccess
>;
};

} // namespace WTF

#endif // ENABLE(INDEXED_DATABASE)

0 comments on commit 45928c2

Please sign in to comment.