#pragma once
#include <wtf/URL.h>
#include "UserContentTypes.h"
#include "UserScriptTypes.h"
#include <wtf/Vector.h>
namespace WebCore {
class UserScript {
WTF_MAKE_FAST_ALLOCATED;
public:
~UserScript() = default;
UserScript(const UserScript&) = default;
UserScript(UserScript&&) = default;
UserScript& operator=(const UserScript&) = default;
UserScript& operator=(UserScript&&) = default;
UserScript(String&& source, URL&& url, Vector<String>&& allowlist, Vector<String>&& blocklist, UserScriptInjectionTime injectionTime, UserContentInjectedFrames injectedFrames, WaitForNotificationBeforeInjecting waitForNotification)
: m_source(WTFMove(source))
, m_url(WTFMove(url))
, m_allowlist(WTFMove(allowlist))
, m_blocklist(WTFMove(blocklist))
, m_injectionTime(injectionTime)
, m_injectedFrames(injectedFrames)
, m_waitForNotificationBeforeInjecting(waitForNotification)
{
}
const String& source() const { return m_source; }
const URL& url() const { return m_url; }
const Vector<String>& allowlist() const { return m_allowlist; }
const Vector<String>& blocklist() const { return m_blocklist; }
UserScriptInjectionTime injectionTime() const { return m_injectionTime; }
UserContentInjectedFrames injectedFrames() const { return m_injectedFrames; }
WaitForNotificationBeforeInjecting waitForNotificationBeforeInjecting() const { return m_waitForNotificationBeforeInjecting; }
template<class Encoder> void encode(Encoder&) const;
template<class Decoder> static Optional<UserScript> decode(Decoder&);
private:
String m_source;
URL m_url;
Vector<String> m_allowlist;
Vector<String> m_blocklist;
UserScriptInjectionTime m_injectionTime { UserScriptInjectionTime::DocumentStart };
UserContentInjectedFrames m_injectedFrames { UserContentInjectedFrames::InjectInAllFrames };
WaitForNotificationBeforeInjecting m_waitForNotificationBeforeInjecting { WaitForNotificationBeforeInjecting::No };
};
template<class Encoder>
void UserScript::encode(Encoder& encoder) const
{
encoder << m_source;
encoder << m_url;
encoder << m_allowlist;
encoder << m_blocklist;
encoder << m_injectionTime;
encoder << m_injectedFrames;
encoder << m_waitForNotificationBeforeInjecting;
}
template<class Decoder>
Optional<UserScript> UserScript::decode(Decoder& decoder)
{
Optional<String> source;
decoder >> source;
if (!source)
return WTF::nullopt;
Optional<URL> url;
decoder >> url;
if (!url)
return WTF::nullopt;
Optional<Vector<String>> allowlist;
decoder >> allowlist;
if (!allowlist)
return WTF::nullopt;
Optional<Vector<String>> blocklist;
decoder >> blocklist;
if (!blocklist)
return WTF::nullopt;
Optional<UserScriptInjectionTime> injectionTime;
decoder >> injectionTime;
if (!injectionTime)
return WTF::nullopt;
Optional<UserContentInjectedFrames> injectedFrames;
decoder >> injectedFrames;
if (!injectedFrames)
return WTF::nullopt;
Optional<WaitForNotificationBeforeInjecting> waitForNotification;
decoder >> waitForNotification;
if (!waitForNotification)
return WTF::nullopt;
return {{
WTFMove(*source),
WTFMove(*url),
WTFMove(*allowlist),
WTFMove(*blocklist),
WTFMove(*injectionTime),
WTFMove(*injectedFrames),
WTFMove(*waitForNotification)
}};
}
}