ContentRuleListResults.h [plain text]
#pragma once
#include <wtf/KeyValuePair.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
struct ContentRuleListResults {
struct Result {
bool blockedLoad { false };
bool madeHTTPS { false };
bool blockedCookies { false };
Vector<String> notifications;
bool shouldNotifyApplication() const
{
return blockedLoad
|| madeHTTPS
|| blockedCookies
|| !notifications.isEmpty();
}
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static Optional<Result> decode(Decoder&);
};
struct Summary {
bool blockedLoad { false };
bool madeHTTPS { false };
bool blockedCookies { false };
bool hasNotifications { false };
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static Optional<Summary> decode(Decoder&);
};
using ContentRuleListIdentifier = String;
Summary summary;
Vector<std::pair<ContentRuleListIdentifier, Result>> results;
bool shouldNotifyApplication() const
{
return summary.blockedLoad
|| summary.madeHTTPS
|| summary.blockedCookies
|| summary.hasNotifications;
}
template<class Encoder> void encode(Encoder& encoder) const
{
encoder << summary;
encoder << results;
}
template<class Decoder> static Optional<ContentRuleListResults> decode(Decoder& decoder)
{
Optional<Summary> summary;
decoder >> summary;
if (!summary)
return WTF::nullopt;
Optional<Vector<std::pair<ContentRuleListIdentifier, Result>>> results;
decoder >> results;
if (!results)
return WTF::nullopt;
return {{
WTFMove(*summary),
WTFMove(*results)
}};
}
};
template<class Encoder> void ContentRuleListResults::Result::encode(Encoder& encoder) const
{
encoder << blockedLoad;
encoder << madeHTTPS;
encoder << blockedCookies;
encoder << notifications;
}
template<class Decoder> auto ContentRuleListResults::Result::decode(Decoder& decoder) -> Optional<Result>
{
Optional<bool> blockedLoad;
decoder >> blockedLoad;
if (!blockedLoad)
return WTF::nullopt;
Optional<bool> madeHTTPS;
decoder >> madeHTTPS;
if (!madeHTTPS)
return WTF::nullopt;
Optional<bool> blockedCookies;
decoder >> blockedCookies;
if (!blockedCookies)
return WTF::nullopt;
Optional<Vector<String>> notifications;
decoder >> notifications;
if (!notifications)
return WTF::nullopt;
return {{
WTFMove(*blockedLoad),
WTFMove(*madeHTTPS),
WTFMove(*blockedCookies),
WTFMove(*notifications)
}};
}
template<class Encoder> void ContentRuleListResults::Summary::encode(Encoder& encoder) const
{
encoder << blockedLoad;
encoder << madeHTTPS;
encoder << blockedCookies;
encoder << hasNotifications;
}
template<class Decoder> auto ContentRuleListResults::Summary::decode(Decoder& decoder) -> Optional<Summary>
{
Optional<bool> blockedLoad;
decoder >> blockedLoad;
if (!blockedLoad)
return WTF::nullopt;
Optional<bool> madeHTTPS;
decoder >> madeHTTPS;
if (!madeHTTPS)
return WTF::nullopt;
Optional<bool> blockedCookies;
decoder >> blockedCookies;
if (!blockedCookies)
return WTF::nullopt;
Optional<bool> hasNotifications;
decoder >> hasNotifications;
if (!hasNotifications)
return WTF::nullopt;
return {{
WTFMove(*blockedLoad),
WTFMove(*madeHTTPS),
WTFMove(*blockedCookies),
WTFMove(*hasNotifications),
}};
}
}