1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*
* Copyright (C) 2016 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.
*/
#pragma once
#if ENABLE(NETWORK_CAPTURE)
#include <WebCore/SharedBuffer.h>
#include <wtf/MonotonicTime.h>
#include <wtf/Optional.h>
#include <wtf/Variant.h>
#include <wtf/Vector.h>
namespace WebCore {
class ResourceError;
class ResourceRequest;
class ResourceResponse;
}
namespace WebKit {
namespace NetworkCapture {
struct RequestSentEvent;
struct ResponseReceivedEvent;
struct RedirectReceivedEvent;
struct RedirectSentEvent;
struct DataReceivedEvent;
struct FinishedEvent;
using CaptureEvent = WTF::Variant<RequestSentEvent, ResponseReceivedEvent, RedirectReceivedEvent, RedirectSentEvent, DataReceivedEvent, FinishedEvent>;
using OptionalCaptureEvent = std::optional<CaptureEvent>;
using CaptureEvents = Vector<CaptureEvent>;
using CaptureClockType = WTF::MonotonicTime;
using CaptureTimeType = WTF::MonotonicTime;
using KeyValuePair = std::pair<String, String>;
using Headers = Vector<KeyValuePair>;
std::string eventToString(const CaptureEvent&);
OptionalCaptureEvent stringToEvent(const char*);
struct Request {
// See comment for RequestSentEvent for why we need this default constructor.
Request()
: url()
, referrer()
, policy(0)
, method()
, headers() { }
Request(String&& url, String&& referrer, int policy, String&& method, Headers&&);
Request(const WebCore::ResourceRequest&);
operator WebCore::ResourceRequest() const;
String url;
String referrer;
int policy;
String method;
Headers headers;
};
static_assert(std::is_default_constructible<Request>::value, "Request is not default constructible");
static_assert(std::is_move_constructible<Request>::value, "Request is not move constructible");
static_assert(std::is_move_assignable<Request>::value, "Request is not move assignable");
struct Response {
Response(String&& url, String&& mimeType, long long expectedLength, String&& textEncodingName, String&& version, int status, String&& reason, Headers&&);
Response(const WebCore::ResourceResponse&);
operator WebCore::ResourceResponse() const;
String url;
String mimeType;
long long expectedLength;
String textEncodingName;
String version;
int status;
String reason;
Headers headers;
};
static_assert(std::is_move_constructible<Response>::value, "Response is not move constructible");
static_assert(std::is_move_assignable<Response>::value, "Response is not move assignable");
struct Error {
Error(String&& domain, String&& failingURL, String&& localizedDescription, int errorCode, int type);
Error(const WebCore::ResourceError&);
operator WebCore::ResourceError() const;
String domain;
String failingURL;
String localizedDescription;
int errorCode;
int type;
};
static_assert(std::is_move_constructible<Error>::value, "Error is not move constructible");
static_assert(std::is_move_assignable<Error>::value, "Error is not move assignable");
struct TimedEvent {
TimedEvent()
: time(CaptureClockType::now()) { }
TimedEvent(CaptureTimeType&& time)
: time(WTFMove(time)) { }
CaptureTimeType time;
};
static_assert(std::is_move_constructible<TimedEvent>::value, "TimedEvent is not move constructible");
static_assert(std::is_move_assignable<TimedEvent>::value, "TimedEvent is not move assignable");
struct RequestSentEvent final : public TimedEvent {
// This default constructor is needed only because this struct is the first
// type passed to CaptureEvent, which is a WTF::Variant. This means that if
// CaptureEvent is default-constructed, it needs to default-construct an
// instance of RequestSentEvent, the first type on its list. If we don't
// have a default constructor for this type, the CaptureEvent will be
// created in an invalid state and will crash when destructed.
RequestSentEvent()
: TimedEvent()
, request() { }
RequestSentEvent(const WebCore::ResourceRequest& request)
: TimedEvent()
, request(request) { }
RequestSentEvent(CaptureTimeType&& time, Request&& request)
: TimedEvent(WTFMove(time))
, request(WTFMove(request)) { }
Request request;
static const char typeName[];
};
static_assert(std::is_default_constructible<RequestSentEvent>::value, "RequestSentEvent is not default constructible");
static_assert(std::is_move_constructible<RequestSentEvent>::value, "RequestSentEvent is not move constructible");
static_assert(std::is_move_assignable<RequestSentEvent>::value, "RequestSentEvent is not move assignable");
struct ResponseReceivedEvent final : public TimedEvent {
ResponseReceivedEvent(const WebCore::ResourceResponse& response)
: TimedEvent()
, response(response) { }
ResponseReceivedEvent(CaptureTimeType&& time, Response&& response)
: TimedEvent(WTFMove(time))
, response(WTFMove(response)) { }
Response response;
static const char typeName[];
};
static_assert(std::is_move_constructible<ResponseReceivedEvent>::value, "ResponseReceivedEvent is not move constructible");
static_assert(std::is_move_assignable<ResponseReceivedEvent>::value, "ResponseReceivedEvent is not move assignable");
struct RedirectReceivedEvent final : public TimedEvent {
RedirectReceivedEvent(const WebCore::ResourceRequest& request, const WebCore::ResourceResponse& response)
: TimedEvent()
, request(request)
, response(response) { }
RedirectReceivedEvent(CaptureTimeType&& time, Request&& request, Response&& response)
: TimedEvent(WTFMove(time))
, request(WTFMove(request))
, response(WTFMove(response)) { }
Request request;
Response response;
static const char typeName[];
};
static_assert(std::is_move_constructible<RedirectReceivedEvent>::value, "RedirectReceivedEvent is not move constructible");
static_assert(std::is_move_assignable<RedirectReceivedEvent>::value, "RedirectReceivedEvent is not move assignable");
struct RedirectSentEvent final : public TimedEvent {
RedirectSentEvent(const WebCore::ResourceRequest& request)
: TimedEvent()
, request(request) { }
RedirectSentEvent(CaptureTimeType&& time, Request&& request)
: TimedEvent(WTFMove(time))
, request(WTFMove(request)) { }
Request request;
static const char typeName[];
};
static_assert(std::is_move_constructible<RedirectSentEvent>::value, "RedirectSentEvent is not move constructible");
static_assert(std::is_move_assignable<RedirectSentEvent>::value, "RedirectSentEvent is not move assignable");
struct DataReceivedEvent final : public TimedEvent {
DataReceivedEvent()
: TimedEvent()
, data(WebCore::SharedBuffer::create()) { }
DataReceivedEvent(WebCore::SharedBuffer& data)
: TimedEvent()
, data(Ref<WebCore::SharedBuffer>(data)) { }
DataReceivedEvent(CaptureTimeType&& time, WebCore::SharedBuffer& data)
: TimedEvent(WTFMove(time))
, data(Ref<WebCore::SharedBuffer>(data)) { }
Ref<WebCore::SharedBuffer> data;
static const char typeName[];
};
static_assert(std::is_move_constructible<DataReceivedEvent>::value, "DataReceivedEvent is not move constructible");
static_assert(std::is_move_assignable<DataReceivedEvent>::value, "DataReceivedEvent is not move assignable");
struct FinishedEvent final : public TimedEvent {
FinishedEvent(const WebCore::ResourceError& error)
: TimedEvent()
, error(error) { }
FinishedEvent(CaptureTimeType&& time, Error&& error)
: TimedEvent(WTFMove(time))
, error(WTFMove(error)) { }
Error error;
static const char typeName[];
};
static_assert(std::is_move_constructible<FinishedEvent>::value, "FinishedEvent is not move constructible");
static_assert(std::is_move_assignable<FinishedEvent>::value, "FinishedEvent is not move assignable");
} // namespace NetworkCapture
} // namespace WebKit
#endif // ENABLE(NETWORK_CAPTURE)
|