Skip to content
Permalink
Browse files
Consolidate ArgumentCodersMac and ArgumentCodersCocoa.
https://bugs.webkit.org/show_bug.cgi?id=195636
rdar://problem/45055697

Reviewed by Ryosuke Niwa.

Source/WebCore:

* editing/DictionaryPopupInfo.h:
(WebCore::DictionaryPopupInfo::encodingRequiresPlatformData const): Added.
* editing/FontAttributes.h:
(WebCore::FontAttributes::encodingRequiresPlatformData const): Added.

Source/WebKit:

Merge the two similar encoders and decoders. This avoids issues where
one encoder could be used and the other decoder, which caused a crash.
It also stops handling NSAttributedString specifically and just uses
the NSSecureCoding path to handle more complex attributes.

Some WebCore encoders code needed to move to platform files, since
ArgumentCodersCocoa.h requires an ObjectiveC++ implementation to work.

* Shared/Cocoa/ArgumentCodersCocoa.h:
(IPC::encode):
(IPC::decode):
(IPC::ArgumentCoder<RetainPtr<T>>::encode):
(IPC::ArgumentCoder<RetainPtr<T>>::decode):
* Shared/Cocoa/ArgumentCodersCocoa.mm:
(IPC::typeFromObject):
(IPC::isSerializableFont):
(IPC::isSerializableValue):
(IPC::encodeObject):
(IPC::decodeObject):
* Shared/Cocoa/LoadParametersCocoa.mm:
* Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
(IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::encodePlatformData):
(IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::decodePlatformData):
(IPC::ArgumentCoder<WebCore::FontAttributes>::encodePlatformData):
(IPC::ArgumentCoder<WebCore::FontAttributes>::decodePlatformData):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<DictionaryPopupInfo>::encode):
(IPC::ArgumentCoder<DictionaryPopupInfo>::decode):
(IPC::ArgumentCoder<FontAttributes>::encode):
(IPC::ArgumentCoder<FontAttributes>::decode):
* Shared/WebCoreArgumentCoders.h:
* Shared/mac/ArgumentCodersMac.h: Removed.
* Shared/mac/ArgumentCodersMac.mm: Removed.
* Shared/mac/AttributedString.mm:
(WebKit::AttributedString::encode const):
* Shared/mac/ObjCObjectGraph.mm:
* SourcesCocoa.txt:
* WebKit.xcodeproj/project.pbxproj:


Canonical link: https://commits.webkit.org/209999@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242908 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
xeenon committed Mar 13, 2019
1 parent 71e23bb commit 123bb65b5822900e83be9b9964df9209dd0108fe
Show file tree
Hide file tree
Showing 18 changed files with 640 additions and 779 deletions.
@@ -1,3 +1,16 @@
2019-03-13 Timothy Hatcher <timothy@apple.com>

Consolidate ArgumentCodersMac and ArgumentCodersCocoa.
https://bugs.webkit.org/show_bug.cgi?id=195636
rdar://problem/45055697

Reviewed by Ryosuke Niwa.

* editing/DictionaryPopupInfo.h:
(WebCore::DictionaryPopupInfo::encodingRequiresPlatformData const): Added.
* editing/FontAttributes.h:
(WebCore::FontAttributes::encodingRequiresPlatformData const): Added.

2019-03-13 Chris Dumez <cdumez@apple.com>

Unreviewed build fix after r242901.
@@ -40,6 +40,10 @@ struct DictionaryPopupInfo {
#if PLATFORM(COCOA)
RetainPtr<NSDictionary> options;
RetainPtr<NSAttributedString> attributedString;

bool encodingRequiresPlatformData() const { return true; }
#else
bool encodingRequiresPlatformData() const { return false; }
#endif
};

@@ -79,7 +79,11 @@ struct FontAttributes {
enum class HorizontalAlignment : uint8_t { Left, Center, Right, Justify, Natural };

#if PLATFORM(COCOA)
bool encodingRequiresPlatformData() const { return true; }

WEBCORE_EXPORT RetainPtr<NSDictionary> createDictionary() const;
#else
bool encodingRequiresPlatformData() const { return false; }
#endif

#if PLATFORM(MAC)
@@ -1,3 +1,50 @@
2019-03-13 Timothy Hatcher <timothy@apple.com>

Consolidate ArgumentCodersMac and ArgumentCodersCocoa.
https://bugs.webkit.org/show_bug.cgi?id=195636
rdar://problem/45055697

Reviewed by Ryosuke Niwa.

Merge the two similar encoders and decoders. This avoids issues where
one encoder could be used and the other decoder, which caused a crash.
It also stops handling NSAttributedString specifically and just uses
the NSSecureCoding path to handle more complex attributes.

Some WebCore encoders code needed to move to platform files, since
ArgumentCodersCocoa.h requires an ObjectiveC++ implementation to work.

* Shared/Cocoa/ArgumentCodersCocoa.h:
(IPC::encode):
(IPC::decode):
(IPC::ArgumentCoder<RetainPtr<T>>::encode):
(IPC::ArgumentCoder<RetainPtr<T>>::decode):
* Shared/Cocoa/ArgumentCodersCocoa.mm:
(IPC::typeFromObject):
(IPC::isSerializableFont):
(IPC::isSerializableValue):
(IPC::encodeObject):
(IPC::decodeObject):
* Shared/Cocoa/LoadParametersCocoa.mm:
* Shared/Cocoa/WebCoreArgumentCodersCocoa.mm:
(IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::encodePlatformData):
(IPC::ArgumentCoder<WebCore::DictionaryPopupInfo>::decodePlatformData):
(IPC::ArgumentCoder<WebCore::FontAttributes>::encodePlatformData):
(IPC::ArgumentCoder<WebCore::FontAttributes>::decodePlatformData):
* Shared/WebCoreArgumentCoders.cpp:
(IPC::ArgumentCoder<DictionaryPopupInfo>::encode):
(IPC::ArgumentCoder<DictionaryPopupInfo>::decode):
(IPC::ArgumentCoder<FontAttributes>::encode):
(IPC::ArgumentCoder<FontAttributes>::decode):
* Shared/WebCoreArgumentCoders.h:
* Shared/mac/ArgumentCodersMac.h: Removed.
* Shared/mac/ArgumentCodersMac.mm: Removed.
* Shared/mac/AttributedString.mm:
(WebKit::AttributedString::encode const):
* Shared/mac/ObjCObjectGraph.mm:
* SourcesCocoa.txt:
* WebKit.xcodeproj/project.pbxproj:

2019-03-13 Chris Dumez <cdumez@apple.com>

Use a ServiceWorker process per registrable domain
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2018 Apple Inc. All rights reserved.
* Copyright (C) 2018, 2019 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -31,17 +31,14 @@

namespace IPC {

void encodeObject(Encoder&, id <NSSecureCoding>);
Optional<RetainPtr<id <NSSecureCoding>>> decodeObject(Decoder&, NSArray<Class> *allowedClasses);
void encodeObject(Encoder&, id);
Optional<RetainPtr<id>> decodeObject(Decoder&, NSArray<Class> *allowedClasses);

template<typename T> Optional<RetainPtr<T>> decode(Decoder&, Class allowedClass);
template<typename T> Optional<RetainPtr<T>> decode(Decoder&, NSArray<Class> *allowedClasses = @[ [T class] ]);
template<typename T> using IsObjCObject = std::enable_if_t<std::is_convertible<T *, id>::value, T *>;

template<typename T>
Optional<RetainPtr<T>> decode(Decoder& decoder, Class allowedClass)
{
return decode<T>(decoder, @[ allowedClass ]);
}
template<typename T, typename = IsObjCObject<T>> void encode(Encoder&, T *);
template<typename T, typename = IsObjCObject<T>> bool decode(Decoder&, RetainPtr<T>&, NSArray<Class> *allowedClasses = @[ [T class] ]);
template<typename T, typename = IsObjCObject<T>> Optional<RetainPtr<T>> decode(Decoder&, NSArray<Class> *allowedClasses = @[ [T class] ]);

#ifndef NDEBUG

@@ -56,39 +53,49 @@ static inline bool isObjectClassAllowed(id object, NSArray<Class> *allowedClasse

#endif

template<typename T>
template<typename T, typename>
void encode(Encoder& encoder, T *object)
{
encodeObject(encoder, object);
}

template<typename T, typename>
bool decode(Decoder& decoder, RetainPtr<T>& result, NSArray<Class> *allowedClasses)
{
auto object = decodeObject(decoder, allowedClasses);
if (!object)
return false;
result = *object;
ASSERT(!*object || isObjectClassAllowed((*object).get(), allowedClasses));
return true;
}

template<typename T, typename>
Optional<RetainPtr<T>> decode(Decoder& decoder, NSArray<Class> *allowedClasses)
{
auto result = decodeObject(decoder, allowedClasses);
if (!result)
return WTF::nullopt;

if (!*result)
return { nullptr };

id object = result->leakRef();
ASSERT(isObjectClassAllowed(object, allowedClasses));
return { adoptNS(static_cast<T *>(object)) };
ASSERT(!*result || isObjectClassAllowed((*result).get(), allowedClasses));
return { *result };
}

template<typename T> using ConformsToSecureCoding = std::is_convertible<T *, id <NSSecureCoding>>;

template<typename T> struct ArgumentCoder<T *> {
template<typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
template<typename U = T, typename = IsObjCObject<U>>
static void encode(Encoder& encoder, U *object)
{
encodeObject(encoder, object);
}
};

template<typename T> struct ArgumentCoder<RetainPtr<T>> {
template <typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
template<typename U = T, typename = IsObjCObject<U>>
static void encode(Encoder& encoder, const RetainPtr<U>& object)
{
ArgumentCoder<U *>::encode(encoder, object.get());
}

template <typename U = T, std::enable_if_t<ConformsToSecureCoding<U>::value>* = nullptr>
template<typename U = T, typename = IsObjCObject<U>>
static Optional<RetainPtr<U>> decode(Decoder& decoder)
{
return IPC::decode<U>(decoder);

0 comments on commit 123bb65

Please sign in to comment.