diff --git a/CMakeLists.txt b/CMakeLists.txt
index 459ea7b839e6..c59e0f6c0a2c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -38,6 +38,7 @@ set(ALL_PORTS
AppleWin
Efl
GTK
+ Haiku
JSCOnly
Mac
PlayStation
diff --git a/LayoutTests/fast/block/border-fit-with-right-alignment-expected.html b/LayoutTests/fast/block/border-fit-with-right-alignment-expected.html
index 6f4ea98700a1..c1b35081e1f8 100644
--- a/LayoutTests/fast/block/border-fit-with-right-alignment-expected.html
+++ b/LayoutTests/fast/block/border-fit-with-right-alignment-expected.html
@@ -1,4 +1,4 @@
-
+
+
+
+
+
diff --git a/Source/WebCore/platform/image-decoders/haiku/ImageDecoderHaiku.cpp b/Source/WebCore/platform/image-decoders/haiku/ImageDecoderHaiku.cpp
new file mode 100644
index 000000000000..00a9fb8daaa8
--- /dev/null
+++ b/Source/WebCore/platform/image-decoders/haiku/ImageDecoderHaiku.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2010 Stephan Aßmus,
+ *
+ * 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#include "config.h"
+#include "ImageBackingStore.h"
+#include "ImageDecoder.h"
+
+#include
+
+namespace WebCore {
+
+NativeImagePtr ImageBackingStore::image() const
+{
+ int bytesPerRow = size().width() * sizeof(RGBA32);
+ BitmapRef* bitmap = new BitmapRef(BRect(0, 0, size().width() - 1, size().height() - 1), 0, B_RGBA32, bytesPerRow);
+ if (!bitmap || !bitmap->IsValid() || !m_pixelsPtr) {
+ delete bitmap;
+ return NULL;
+ }
+
+ const uint8* source = reinterpret_cast(m_pixelsPtr);
+ uint8* destination = reinterpret_cast(bitmap->Bits());
+ int h = size().height();
+ int w = size().width();
+ for (int y = 0; y < h; y++) {
+#if 0
+// FIXME: Enable this conversion once Haiku has B_RGBA32P[remultiplied]...
+ memcpy(dst, source, bytesPerRow);
+#else
+ const uint8* sourceHandle = source;
+ uint8* destinationHandle = destination;
+ for (int x = 0; x < w; x++) {
+ if (sourceHandle[3] == 255 || !sourceHandle[3]) {
+ destinationHandle[0] = sourceHandle[0];
+ destinationHandle[1] = sourceHandle[1];
+ destinationHandle[2] = sourceHandle[2];
+ destinationHandle[3] = sourceHandle[3];
+ } else {
+ destinationHandle[0] = static_cast(sourceHandle[0]) * 255 / sourceHandle[3];
+ destinationHandle[1] = static_cast(sourceHandle[1]) * 255 / sourceHandle[3];
+ destinationHandle[2] = static_cast(sourceHandle[2]) * 255 / sourceHandle[3];
+ destinationHandle[3] = sourceHandle[3];
+ }
+ destinationHandle += 4;
+ sourceHandle += 4;
+ }
+#endif
+ destination += bytesPerRow;
+ source += bytesPerRow;
+ }
+
+ return bitmap;
+}
+
+} // namespace WebCore
+
diff --git a/Source/WebCore/platform/network/DNSResolveQueue.cpp b/Source/WebCore/platform/network/DNSResolveQueue.cpp
index 885070485559..9b16b22e9e91 100644
--- a/Source/WebCore/platform/network/DNSResolveQueue.cpp
+++ b/Source/WebCore/platform/network/DNSResolveQueue.cpp
@@ -33,6 +33,8 @@
#include "DNSResolveQueueCurl.h"
#elif USE(CF)
#include "DNSResolveQueueCFNet.h"
+#elif USE(HAIKU)
+#include "DNSResolveQueueHaiku.h"
#endif
#include
diff --git a/Source/WebCore/platform/network/HTTPParsers.cpp b/Source/WebCore/platform/network/HTTPParsers.cpp
index 474a1a2e0c54..e3d1098e28c4 100644
--- a/Source/WebCore/platform/network/HTTPParsers.cpp
+++ b/Source/WebCore/platform/network/HTTPParsers.cpp
@@ -284,12 +284,16 @@ String filenameFromHTTPContentDisposition(const String& value)
if (key.isEmpty() || key != "filename")
continue;
-
+
String value = keyValuePair.substring(valueStartPos + 1).stripWhiteSpace();
// Remove quotes if there are any
- if (value[0] == '\"')
- value = value.substring(1, value.length() - 2);
+ if (value[0] == '"') {
+ if (value[value.length() - 1] == '"')
+ value = value.substring(1, value.length() - 2);
+ else
+ return String();
+ }
return value;
}
diff --git a/Source/WebCore/platform/network/NetworkStorageSession.h b/Source/WebCore/platform/network/NetworkStorageSession.h
index 58da878907ff..0655d72f8299 100644
--- a/Source/WebCore/platform/network/NetworkStorageSession.h
+++ b/Source/WebCore/platform/network/NetworkStorageSession.h
@@ -38,6 +38,8 @@
#if PLATFORM(COCOA) || USE(CFURLCONNECTION)
#include
#include
+#elif PLATFORM(HAIKU)
+class BUrlContext;
#endif
#if USE(SOUP)
@@ -107,6 +109,12 @@ class NetworkStorageSession {
void setCookieObserverHandler(Function&&);
void getCredentialFromPersistentStorage(const ProtectionSpace&, GCancellable*, Function&& completionHandler);
void saveCredentialToPersistentStorage(const ProtectionSpace&, const Credential&);
+#elif USE(HAIKU)
+ WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID);
+ ~NetworkStorageSession();
+
+ BUrlContext& platformSession() const;
+ void setPlatformSession(BUrlContext*);
#elif USE(CURL)
WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID);
~NetworkStorageSession();
@@ -173,6 +181,8 @@ class NetworkStorageSession {
mutable std::unique_ptr m_session;
Function m_cookieObserverHandler;
+#elif USE(HAIKU)
+ BUrlContext* m_context;
#elif USE(CURL)
UniqueRef m_cookieStorage;
mutable UniqueRef m_cookieDatabase;
diff --git a/Source/WebCore/platform/network/ResourceHandle.h b/Source/WebCore/platform/network/ResourceHandle.h
index 9e25d9e2b449..cbbc9573dcee 100644
--- a/Source/WebCore/platform/network/ResourceHandle.h
+++ b/Source/WebCore/platform/network/ResourceHandle.h
@@ -67,6 +67,10 @@ typedef struct OpaqueCFHTTPCookieStorage* CFHTTPCookieStorageRef;
typedef const struct __CFURLStorageSession* CFURLStorageSessionRef;
#endif
+#if PLATFORM(HAIKU)
+class BCertificate;
+#endif
+
namespace WTF {
class SchedulePair;
template class MessageQueue;
@@ -141,6 +145,10 @@ class ResourceHandle : public RefCounted, public AuthenticationC
void unschedule(WTF::SchedulePair&);
#endif
+#if PLATFORM(HAIKU)
+ bool didReceiveInvalidCertificate(BCertificate& certificate, const char* message);
+#endif
+
#if USE(CFURLCONNECTION)
CFURLStorageSessionRef storageSession() const;
CFURLConnectionRef connection() const;
@@ -166,7 +174,7 @@ class ResourceHandle : public RefCounted, public AuthenticationC
WEBCORE_EXPORT static void forceContentSniffing();
-#if USE(CURL)
+#if USE(CURL) || USE(HAIKU)
ResourceHandleInternal* getInternal() { return d.get(); }
#endif
diff --git a/Source/WebCore/platform/network/ResourceHandleClient.h b/Source/WebCore/platform/network/ResourceHandleClient.h
index 7343bda55047..b91882a646d5 100644
--- a/Source/WebCore/platform/network/ResourceHandleClient.h
+++ b/Source/WebCore/platform/network/ResourceHandleClient.h
@@ -41,6 +41,10 @@
OBJC_CLASS NSCachedURLResponse;
#endif
+#if PLATFORM(HAIKU)
+class BCertificate;
+#endif
+
namespace WebCore {
class AuthenticationChallenge;
class Credential;
@@ -92,6 +96,11 @@ class ResourceHandleClient {
virtual void didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&) { }
virtual void receivedCancellation(ResourceHandle*, const AuthenticationChallenge&) { }
+#if PLATFORM(HAIKU)
+ virtual bool didReceiveInvalidCertificate(ResourceHandle*, const BCertificate&,
+ const char*) { return false; }
+#endif
+
#if PLATFORM(IOS_FAMILY) || USE(CFURLCONNECTION)
virtual RetainPtr connectionProperties(ResourceHandle*) { return nullptr; }
#endif
diff --git a/Source/WebCore/platform/network/ResourceHandleInternal.h b/Source/WebCore/platform/network/ResourceHandleInternal.h
index 243de9f8265a..1cf06fb1e7fe 100644
--- a/Source/WebCore/platform/network/ResourceHandleInternal.h
+++ b/Source/WebCore/platform/network/ResourceHandleInternal.h
@@ -43,6 +43,11 @@
#include
#endif
+#if PLATFORM(HAIKU)
+#include
+class BUrlProtocolHandler;
+#endif
+
#if PLATFORM(COCOA)
OBJC_CLASS NSURLAuthenticationChallenge;
OBJC_CLASS NSURLConnection;
@@ -72,6 +77,9 @@ class ResourceHandleInternal {
, m_shouldContentEncodingSniff(shouldContentEncodingSniff)
#if USE(CFURLCONNECTION)
, m_currentRequest(request)
+#endif
+#if PLATFORM(HAIKU)
+ , m_urlrequest(0)
#endif
, m_failureTimer(*loader, &ResourceHandle::failureTimerFired)
{
@@ -129,6 +137,11 @@ class ResourceHandleInternal {
MonotonicTime m_startTime;
#endif
+#if PLATFORM(HAIKU)
+ BUrlProtocolHandler* m_urlrequest;
+ BString m_url;
+#endif
+
#if PLATFORM(COCOA)
// We need to keep a reference to the original challenge to be able to cancel it.
// It is almost identical to m_currentWebChallenge.nsURLAuthenticationChallenge(), but has a different sender.
diff --git a/Source/WebCore/platform/network/haiku/AuthenticationChallenge.h b/Source/WebCore/platform/network/haiku/AuthenticationChallenge.h
new file mode 100644
index 000000000000..0d62ed5cbd12
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/AuthenticationChallenge.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2007 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+#ifndef AuthenticationChallenge_h
+#define AuthenticationChallenge_h
+
+#include "AuthenticationChallengeBase.h"
+#include "AuthenticationClient.h"
+
+namespace WebCore {
+
+class AuthenticationChallenge : public AuthenticationChallengeBase {
+public:
+ AuthenticationChallenge()
+ {
+ }
+
+ AuthenticationChallenge(const ProtectionSpace& protectionSpace, const Credential& proposedCredential, unsigned previousFailureCount, const ResourceResponse& response, const ResourceError& error)
+ : AuthenticationChallengeBase(protectionSpace, proposedCredential, previousFailureCount, response, error)
+ {
+ }
+
+ AuthenticationClient* authenticationClient() const { return m_authenticationClient.get(); }
+
+ RefPtr m_authenticationClient;
+};
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/network/haiku/BUrlProtocolHandler.cpp b/Source/WebCore/platform/network/haiku/BUrlProtocolHandler.cpp
new file mode 100644
index 000000000000..8bfa7bb9b3a7
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/BUrlProtocolHandler.cpp
@@ -0,0 +1,398 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ Copyright (C) 2007 Staikos Computing Services Inc.
+ Copyright (C) 2008 Holger Hans Peter Freyther
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#include "config.h"
+#include "BUrlProtocolHandler.h"
+
+#include "FormData.h"
+#include "HTTPParsers.h"
+#include "MIMETypeRegistry.h"
+#include "NetworkStorageSession.h"
+#include "ProtectionSpace.h"
+#include "ResourceHandle.h"
+#include "ResourceHandleClient.h"
+#include "ResourceHandleInternal.h"
+#include "ResourceResponse.h"
+#include "ResourceRequest.h"
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+static const int gMaxRecursionLimit = 10;
+
+namespace WebCore {
+
+BUrlProtocolHandler::BUrlProtocolHandler(NetworkingContext* context,
+ ResourceHandle* handle, bool synchronous)
+ : BUrlProtocolAsynchronousListener(!synchronous)
+ , m_resourceHandle(handle)
+ , m_redirected(false)
+ , m_responseDataSent(false)
+ , m_postData(NULL)
+ , m_request(handle->firstRequest().toNetworkRequest(
+ context ? &context->storageSession()->platformSession() : nullptr))
+ , m_position(0)
+ , m_redirectionTries(gMaxRecursionLimit)
+{
+ if (!m_resourceHandle)
+ return;
+
+ BString method = BString(m_resourceHandle->firstRequest().httpMethod());
+
+ m_postData = NULL;
+
+ if (m_request == NULL)
+ return;
+
+ m_baseUrl = URL(m_request->Url());
+
+ BHttpRequest* httpRequest = dynamic_cast(m_request);
+ if(httpRequest) {
+ // TODO maybe we have data to send in other cases ?
+ if(method == B_HTTP_POST || method == B_HTTP_PUT) {
+ FormData* form = m_resourceHandle->firstRequest().httpBody();
+ if(form) {
+ m_postData = new BFormDataIO(form);
+ httpRequest->AdoptInputData(m_postData, m_postData->Size());
+ }
+ }
+
+ httpRequest->SetMethod(method.String());
+ }
+
+ // In synchronous mode, call this listener directly.
+ // In asynchronous mode, go through a BMessage
+ if(this->SynchronousListener()) {
+ m_request->SetListener(this->SynchronousListener());
+ } else {
+ m_request->SetListener(this);
+ }
+
+ if (m_request->Run() < B_OK) {
+ ResourceHandleClient* client = m_resourceHandle->client();
+ if (!client)
+ return;
+
+ ResourceError error("BUrlProtocol", 42,
+ handle->firstRequest().url(),
+ "The service kit failed to start the request.");
+ client->didFail(m_resourceHandle, error);
+ }
+}
+
+BUrlProtocolHandler::~BUrlProtocolHandler()
+{
+ abort();
+ if (m_request)
+ m_request->SetListener(NULL);
+ delete m_request;
+}
+
+void BUrlProtocolHandler::abort()
+{
+ if (m_resourceHandle != NULL && m_request != NULL)
+ m_request->Stop();
+
+ m_resourceHandle = NULL;
+}
+
+static bool ignoreHttpError(BHttpRequest* reply, bool receivedData)
+{
+ int httpStatusCode = static_cast(reply->Result()).StatusCode();
+
+ if (httpStatusCode == 401 || httpStatusCode == 407)
+ return false;
+
+ if (receivedData && (httpStatusCode >= 400 && httpStatusCode < 600))
+ return true;
+
+ return false;
+}
+
+void BUrlProtocolHandler::RequestCompleted(BUrlRequest* caller, bool success)
+{
+ if (!m_resourceHandle)
+ return;
+
+ ResourceHandleClient* client = m_resourceHandle->client();
+ if (!client)
+ return;
+
+ BHttpRequest* httpRequest = dynamic_cast(m_request);
+
+ if (success || (httpRequest && ignoreHttpError(httpRequest, m_responseDataSent))) {
+ client->didFinishLoading(m_resourceHandle);
+ return;
+ } else if(httpRequest) {
+ const BHttpResult& result = static_cast(httpRequest->Result());
+ int httpStatusCode = result.StatusCode();
+
+ if (httpStatusCode != 0) {
+ ResourceError error("HTTP", httpStatusCode,
+ URL(caller->Url()), strerror(caller->Status()));
+
+ client->didFail(m_resourceHandle, error);
+ return;
+ }
+ }
+
+ // If we get here, it means we are in failure without an HTTP error code
+ // (DNS error, or error from a protocol other than HTTP).
+ ResourceError error("BUrlRequest", caller->Status(), URL(caller->Url()), strerror(caller->Status()));
+ client->didFail(m_resourceHandle, error);
+}
+
+
+bool BUrlProtocolHandler::CertificateVerificationFailed(BUrlRequest*,
+ BCertificate& certificate, const char* message)
+{
+ return m_resourceHandle->didReceiveInvalidCertificate(certificate, message);
+}
+
+
+void BUrlProtocolHandler::AuthenticationNeeded(BHttpRequest* request, ResourceResponse& response)
+{
+ if (!m_resourceHandle)
+ return;
+
+ ResourceHandleInternal* d = m_resourceHandle->getInternal();
+ unsigned failureCount = 0;
+
+ const URL& url = m_resourceHandle->firstRequest().url();
+ ProtectionSpaceServerType serverType = ProtectionSpaceServerHTTP;
+ if (url.protocolIs("https"))
+ serverType = ProtectionSpaceServerHTTPS;
+
+ String challenge = static_cast(request->Result()).Headers()["WWW-Authenticate"];
+ ProtectionSpaceAuthenticationScheme scheme = ProtectionSpaceAuthenticationSchemeDefault;
+
+ ResourceHandleClient* client = m_resourceHandle->client();
+
+ // TODO according to RFC7235, there could be more than one challenge in WWW-Authenticate. We
+ // should parse them all, instead of just the first one.
+ if (challenge.startsWith("Digest"))
+ scheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
+ else if (challenge.startsWith("Basic"))
+ scheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
+ else {
+ // Unknown authentication type, ignore (various websites are intercepting the auth and
+ // handling it by themselves)
+ return;
+ }
+
+ String realm;
+ int realmStart = challenge.find("realm=\"", 0);
+ if (realmStart > 0) {
+ realmStart += 7;
+ int realmEnd = challenge.find("\"", realmStart);
+ if (realmEnd >= 0)
+ realm = challenge.substring(realmStart, realmEnd - realmStart);
+ }
+
+ int port;
+ if (url.port())
+ port = *url.port();
+ else if (url.protocolIs("https"))
+ port = 443;
+ else
+ port = 80;
+ ProtectionSpace protectionSpace(url.host().utf8().data(), port, serverType, realm, scheme);
+ ResourceError resourceError(url.host().utf8().data(), 401, url, String());
+
+ m_redirectionTries--;
+ if(m_redirectionTries == 0)
+ {
+ client->didFinishLoading(m_resourceHandle);
+ return;
+ }
+
+ Credential proposedCredential(d->m_user, d->m_pass, CredentialPersistenceForSession);
+
+ AuthenticationChallenge authenticationChallenge(protectionSpace,
+ proposedCredential, failureCount++, response, resourceError);
+ authenticationChallenge.m_authenticationClient = m_resourceHandle;
+ m_resourceHandle->didReceiveAuthenticationChallenge(authenticationChallenge);
+ // will set m_user and m_pass in ResourceHandleInternal
+
+ if (d->m_user != "") {
+ // Handle this just like redirects.
+ m_redirected = true;
+
+ ResourceRequest request = m_resourceHandle->firstRequest();
+ ResourceResponse responseCopy = response;
+ request.setCredentials(d->m_user.utf8().data(), d->m_pass.utf8().data());
+ client->willSendRequestAsync(m_resourceHandle, WTFMove(request), WTFMove(responseCopy),
+ [handle = makeRef(*m_resourceHandle)] (ResourceRequest&& request) {
+ //continueAfterWillSendRequest(handle.ptr(), WTFMove(request));
+ });
+ } else {
+ // Anything to do in case of failure?
+ }
+}
+
+
+void BUrlProtocolHandler::ConnectionOpened(BUrlRequest*)
+{
+ m_responseDataSent = false;
+}
+
+
+void BUrlProtocolHandler::HeadersReceived(BUrlRequest* caller,
+ const BUrlResult& result)
+{
+ if (!m_resourceHandle)
+ return;
+
+ const BHttpResult* httpResult = dynamic_cast(&result);
+
+ WTF::String contentType = result.ContentType();
+ int contentLength = result.Length();
+ URL url;
+
+ WTF::String encoding = extractCharsetFromMediaType(contentType);
+ WTF::String mimeType = extractMIMETypeFromMediaType(contentType);
+
+ if (httpResult) {
+ url = URL(httpResult->Url());
+
+ BString location = httpResult->Headers()["Location"];
+ if (location.Length() > 0) {
+ m_redirected = true;
+ url = URL(url, location);
+ } else {
+ m_redirected = false;
+ }
+ } else {
+ url = m_baseUrl;
+ }
+
+ ResourceResponse response(url, mimeType, contentLength, encoding);
+
+ if (httpResult) {
+ int statusCode = httpResult->StatusCode();
+
+ String suggestedFilename = filenameFromHTTPContentDisposition(
+ httpResult->Headers()["Content-Disposition"]);
+
+ if (!suggestedFilename.isEmpty())
+ response.setSuggestedFilename(suggestedFilename);
+
+ response.setHTTPStatusCode(statusCode);
+ response.setHTTPStatusText(httpResult->StatusText());
+
+ // Add remaining headers.
+ const BHttpHeaders& resultHeaders = httpResult->Headers();
+ for (int i = 0; i < resultHeaders.CountHeaders(); i++) {
+ BHttpHeader& headerPair = resultHeaders.HeaderAt(i);
+ response.setHTTPHeaderField(headerPair.Name(), headerPair.Value());
+ }
+
+ if (statusCode == 401) {
+ AuthenticationNeeded((BHttpRequest*)m_request, response);
+ // AuthenticationNeeded may have aborted the request
+ // so we need to make sure we can continue.
+ if (!m_resourceHandle)
+ return;
+ }
+ }
+
+ ResourceHandleClient* client = m_resourceHandle->client();
+ if (!client)
+ return;
+
+ if (m_redirected) {
+ m_redirectionTries--;
+
+ if (m_redirectionTries == 0) {
+ ResourceError error(url.host().utf8().data(), 400, url,
+ "Redirection limit reached");
+ client->didFail(m_resourceHandle, error);
+ return;
+ }
+
+ // Notify the client that we are redirecting.
+ ResourceRequest request = m_resourceHandle->firstRequest();
+ ResourceResponse responseCopy = response;
+ request.setURL(url);
+
+ client->willSendRequestAsync(m_resourceHandle, WTFMove(request), WTFMove(responseCopy),
+ [handle = makeRef(*m_resourceHandle)] (ResourceRequest&& request) {
+ //continueAfterWillSendRequest(handle.ptr(), WTFMove(request));
+ });
+ } else {
+ ResourceResponse responseCopy = response;
+ // Make sure the resource handle is not deleted immediately, otherwise
+ // didReceiveResponse would crash. Keep a reference to it so it can be
+ // deleted cleanly after the function returns.
+ RefPtr protectedHandle(m_resourceHandle);
+ protectedHandle->didReceiveResponse(WTFMove(responseCopy), [this/*, protectedThis = makeRef(*this)*/] {
+ //continueAfterDidReceiveResponse();
+ });
+ }
+}
+
+void BUrlProtocolHandler::DataReceived(BUrlRequest* caller, const char* data,
+ off_t position, ssize_t size)
+{
+ if (!m_resourceHandle)
+ return;
+
+ ResourceHandleClient* client = m_resourceHandle->client();
+ if (!client)
+ return;
+
+ // don't emit the "Document has moved here" type of HTML
+ if (m_redirected)
+ return;
+
+ if (position != m_position)
+ {
+ debugger("bad redirect");
+ return;
+ }
+
+ if (size > 0) {
+ m_responseDataSent = true;
+ client->didReceiveData(m_resourceHandle, data, size, size);
+ }
+
+ m_position += size;
+}
+
+void BUrlProtocolHandler::UploadProgress(BUrlRequest* caller, ssize_t bytesSent, ssize_t bytesTotal)
+{
+ if (!m_resourceHandle)
+ return;
+
+ ResourceHandleClient* client = m_resourceHandle->client();
+ if (!client)
+ return;
+
+ client->didSendData(m_resourceHandle, bytesSent, bytesTotal);
+}
+
+}
diff --git a/Source/WebCore/platform/network/haiku/BUrlProtocolHandler.h b/Source/WebCore/platform/network/haiku/BUrlProtocolHandler.h
new file mode 100644
index 000000000000..71b55685adb1
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/BUrlProtocolHandler.h
@@ -0,0 +1,74 @@
+/*
+ Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+#ifndef BURLPROTOCOLHANDLER_H
+#define BURLPROTOCOLHANDLER_H
+
+#include "HaikuFormDataStream.h"
+#include "ResourceRequest.h"
+
+#include
+#include
+#include
+#include
+
+class BFile;
+
+namespace WebCore {
+
+class NetworkingContext;
+class ResourceHandle;
+class ResourceResponse;
+
+class BUrlProtocolHandler : public BUrlProtocolAsynchronousListener
+{
+public:
+ BUrlProtocolHandler(NetworkingContext* context, ResourceHandle *handle,
+ bool synchronous);
+ virtual ~BUrlProtocolHandler();
+ void abort();
+
+ bool isValid() { return m_request != NULL; }
+
+private:
+ void AuthenticationNeeded(BHttpRequest* caller, ResourceResponse& response);
+
+ // BUrlListener hooks
+ void ConnectionOpened(BUrlRequest* caller) override;
+ void HeadersReceived(BUrlRequest* caller, const BUrlResult& result) override;
+ void DataReceived(BUrlRequest* caller, const char* data, off_t position,
+ ssize_t size) override;
+ void UploadProgress(BUrlRequest* caller, ssize_t bytesSent, ssize_t bytesTotal) override;
+ void RequestCompleted(BUrlRequest* caller, bool success) override;
+ bool CertificateVerificationFailed(BUrlRequest* caller, BCertificate& certificate, const char* message) override;
+
+private:
+ ResourceHandle* m_resourceHandle;
+ bool m_redirected;
+ bool m_responseDataSent;
+ BFormDataIO* m_postData;
+ BUrlRequest* m_request;
+ off_t m_position;
+ URL m_baseUrl;
+
+ int m_redirectionTries;
+};
+
+}
+
+#endif // BURLPROTOCOLHANDLER_H
diff --git a/Source/WebCore/platform/network/haiku/CertificateInfo.cpp b/Source/WebCore/platform/network/haiku/CertificateInfo.cpp
new file mode 100644
index 000000000000..ade3c990ccca
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/CertificateInfo.cpp
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2014 Haiku, inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+
+#include "CertificateInfo.h"
+
+#include "NotImplemented.h"
+#include "ResourceError.h"
+#include "ResourceResponse.h"
+
+namespace WebCore {
+
+CertificateInfo::CertificateInfo()
+ : m_certificate(nullptr)
+{
+}
+
+} // namespace WebCore
+
diff --git a/Source/WebCore/platform/network/haiku/CertificateInfo.h b/Source/WebCore/platform/network/haiku/CertificateInfo.h
new file mode 100644
index 000000000000..ea5cecaedd71
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/CertificateInfo.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2014 Haiku 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.
+ */
+
+#ifndef CertificateInfo_h
+#define CertificateInfo_h
+
+#include "CertificateInfoBase.h"
+#include "NotImplemented.h"
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+namespace WebCore {
+
+class ResourceError;
+class ResourceResponse;
+
+class CertificateInfo : public CertificateInfoBase {
+public:
+ CertificateInfo();
+ explicit CertificateInfo(const BCertificate& certificate)
+ : m_certificate(&certificate)
+ { }
+
+ Optional summaryInfo() const { notImplemented(); return WTF::nullopt; }
+
+ const BCertificate& certificate() const { return *m_certificate; }
+
+private:
+ const BCertificate* m_certificate;
+};
+
+} // namespace WebCore
+
+namespace WTF {
+namespace Persistence {
+
+template<> struct Coder {
+ static void encode(Encoder& encoder, const WebCore::CertificateInfo& certificateInfo)
+ {
+ notImplemented();
+ }
+
+ static bool decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
+ {
+ notImplemented();
+ return false;
+ }
+};
+
+} // namespace WTF::Persistence
+} // namespace WTF
+
+#endif // CertificateInfo_h
diff --git a/Source/WebCore/platform/network/haiku/CookieJarHaiku.cpp b/Source/WebCore/platform/network/haiku/CookieJarHaiku.cpp
new file mode 100644
index 000000000000..62085c5dc86c
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/CookieJarHaiku.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2006 George Staikos
+ * Copyright (C) 2007 Ryan Leavengood
+ *
+ * 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#include "config.h"
+
+#include "CookieStorage.h"
+
+#include "NetworkStorageSession.h"
+#include "NotImplemented.h"
+
+#include
+#include
+
+#include
+#include
+
+#define TRACE_COOKIE_JAR 0
+
+
+namespace WebCore {
+
+void setCookieStoragePrivateBrowsingEnabled(bool)
+{
+#if TRACE_COOKIE_JAR
+ printf("CookieJar: private browsing (NOT IMPLEMENTED)\n");
+#endif
+}
+
+void startObservingCookieChanges(const NetworkStorageSession& storageSession, WTF::Function&& callback)
+{
+ notImplemented();
+}
+
+void stopObservingCookieChanges(const NetworkStorageSession& storageSession)
+{
+}
+
+} // namespace WebCore
+
diff --git a/Source/WebCore/platform/network/haiku/CredentialStorageHaiku.cpp b/Source/WebCore/platform/network/haiku/CredentialStorageHaiku.cpp
new file mode 100644
index 000000000000..54ccad05651d
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/CredentialStorageHaiku.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#include "config.h"
+#include "CredentialStorage.h"
+
+#include "Credential.h"
+
+namespace WebCore {
+
+Credential CredentialStorage::getFromPersistentStorage(const ProtectionSpace&)
+{
+ return Credential();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/network/haiku/DNSHaiku.cpp b/Source/WebCore/platform/network/haiku/DNSHaiku.cpp
new file mode 100644
index 000000000000..1aaeb881333c
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/DNSHaiku.cpp
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2008 Apple Computer, 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 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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#include "config.h"
+#include "DNS.h"
+#include "DNSResolveQueueHaiku.h"
+
+#include "NotImplemented.h"
+
+namespace WebCore {
+
+void DNSResolveQueueHaiku::updateIsUsingProxy()
+{
+ notImplemented();
+}
+
+void DNSResolveQueueHaiku::platformResolve(const String& /* hostname */)
+{
+ notImplemented();
+}
+
+void DNSResolveQueueHaiku::resolve(const String& /* hostname */, uint64_t /* identifier */, DNSCompletionHandler&& /* completionHandler */)
+{
+ notImplemented();
+}
+
+void DNSResolveQueueHaiku::stopResolve(uint64_t /* identifier */)
+{
+ notImplemented();
+}
+
+}
diff --git a/Source/WebCore/platform/network/haiku/DNSResolveQueueHaiku.h b/Source/WebCore/platform/network/haiku/DNSResolveQueueHaiku.h
new file mode 100644
index 000000000000..1e9ede28cd4f
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/DNSResolveQueueHaiku.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2018 Adrien Destugues
+ *
+ * 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 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
+ * 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
+
+#include "DNSResolveQueue.h"
+
+namespace WebCore {
+
+class DNSResolveQueueHaiku final : public DNSResolveQueue {
+public:
+ DNSResolveQueueHaiku() = default;
+ void resolve(const String& hostname, uint64_t identifier, DNSCompletionHandler&&) final;
+ void stopResolve(uint64_t identifier) final;
+
+private:
+ void updateIsUsingProxy() final;
+ void platformResolve(const String&) final;
+};
+
+using DNSResolveQueuePlatform = DNSResolveQueueHaiku;
+
+}
diff --git a/Source/WebCore/platform/network/haiku/HaikuFormDataStream.cpp b/Source/WebCore/platform/network/haiku/HaikuFormDataStream.cpp
new file mode 100644
index 000000000000..7a182fd4b3d8
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/HaikuFormDataStream.cpp
@@ -0,0 +1,239 @@
+/*
+ Copyright (C) 2018 Haiku, inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "HaikuFormDataStream.h"
+
+#include "BlobRegistry.h"
+#include "BlobRegistryImpl.h"
+#include "SharedBuffer.h"
+
+#include
+
+namespace WebCore {
+
+BFormDataIO::BFormDataIO(const FormData* formData)
+{
+ ASSERT(isMainThread());
+
+ if (!formData || formData->isEmpty())
+ return;
+
+ m_formData = formData->isolatedCopy();
+
+ // Resolve the blob elements so the formData can correctly report it's size.
+ m_formData = m_formData->resolveBlobReferences(blobRegistry());
+}
+
+BFormDataIO::~BFormDataIO()
+{
+}
+
+ssize_t BFormDataIO::Size()
+{
+ computeContentLength();
+
+ return m_totalSize;
+}
+
+
+ssize_t
+BFormDataIO::Read(void* buffer, size_t size)
+{
+ if (!m_formData)
+ return -1;
+
+ const auto totalElementSize = m_formData->elements().size();
+ if (m_elementPosition >= totalElementSize)
+ return 0;
+
+ size_t totalReadBytes = 0;
+
+ while ((m_elementPosition < totalElementSize) && (totalReadBytes < size)) {
+ const auto& element = m_formData->elements().at(m_elementPosition);
+
+ size_t bufferSize = size - totalReadBytes;
+ char* bufferPosition = (char*)buffer + totalReadBytes;
+
+ WTF::Optional readBytes = switchOn(element.data,
+ [&] (const Vector& bytes) {
+ return readFromData(bytes, bufferPosition, bufferSize);
+ }, [&] (const FormDataElement::EncodedFileData& fileData) {
+ return readFromFile(fileData, bufferPosition, bufferSize);
+ }, [&] (const FormDataElement::EncodedBlobData& blobData) {
+ return readFromBlob(blobData, bufferPosition, bufferSize);
+ }
+ );
+
+ if (!readBytes)
+ return -1;
+
+ totalReadBytes += *readBytes;
+ }
+
+ m_totalReadSize += totalReadBytes;
+
+ return totalReadBytes;
+}
+
+ssize_t
+BFormDataIO::Write(const void* /*buffer*/, size_t /*size*/)
+{
+ // Write isn't implemented since we don't use it
+ return B_NOT_SUPPORTED;
+}
+
+
+void BFormDataIO::computeContentLength()
+{
+ if (!m_formData || m_isContentLengthUpdated)
+ return;
+
+ m_isContentLengthUpdated = true;
+
+ for (const auto& element : m_formData->elements())
+ m_totalSize += element.lengthInBytes();
+}
+
+
+WTF::Optional BFormDataIO::readFromFile(const FormDataElement::EncodedFileData& fileData, char* buffer, size_t size)
+{
+ if (m_fileHandle == FileSystem::invalidPlatformFileHandle)
+ m_fileHandle = FileSystem::openFile(fileData.filename, FileSystem::FileOpenMode::Read);
+
+ if (!FileSystem::isHandleValid(m_fileHandle)) {
+ LOG(Network, "Haiku - Failed while trying to open %s for upload\n", fileData.filename.utf8().data());
+ m_fileHandle = FileSystem::invalidPlatformFileHandle;
+ return WTF::nullopt;
+ }
+
+ // Note: there is no management of a file offset, we just keep the file
+ // handle open and read from the current position.
+ auto readBytes = FileSystem::readFromFile(m_fileHandle, buffer, size);
+ if (readBytes < 0) {
+ LOG(Network, "Haiku - Failed while trying to read %s for upload\n", fileData.filename.utf8().data());
+ FileSystem::closeFile(m_fileHandle);
+ m_fileHandle = FileSystem::invalidPlatformFileHandle;
+ return WTF::nullopt;
+ }
+
+ if (!readBytes) {
+ FileSystem::closeFile(m_fileHandle);
+ m_fileHandle = FileSystem::invalidPlatformFileHandle;
+ m_elementPosition++;
+ }
+
+ return readBytes;
+}
+
+WTF::Optional BFormDataIO::readFromData(const Vector& data, char* buffer, size_t size)
+{
+ size_t elementSize = data.size() - m_dataOffset;
+ const char* elementBuffer = data.data() + m_dataOffset;
+
+ size_t readBytes = elementSize > size ? size : elementSize;
+ memcpy(buffer, elementBuffer, readBytes);
+
+ if (elementSize > readBytes)
+ m_dataOffset += readBytes;
+ else {
+ m_dataOffset = 0;
+ m_elementPosition++;
+ }
+
+ return readBytes;
+}
+
+
+WTF::Optional BFormDataIO::readFromBlob(const FormDataElement::EncodedBlobData& blob, char* buffer, size_t size)
+{
+ auto* blobData = static_cast(blobRegistry()).getBlobDataFromURL(blob.url);
+
+ if (!blobData)
+ return WTF::nullopt;
+
+ auto& blobItem = blobData->items().at(m_blobItemIndex);
+ off_t readBytes;
+
+ switch (blobItem.type()) {
+ case BlobDataItem::Type::Data:
+ {
+ size_t elementSize = blobItem.data().data()->size() - m_dataOffset;
+ const uint8_t* elementBuffer = blobItem.data().data()->data() + m_dataOffset;
+
+ readBytes = elementSize > size ? size : elementSize;
+ memcpy(buffer, elementBuffer, readBytes);
+
+ if (elementSize > readBytes)
+ m_dataOffset += readBytes;
+ else {
+ m_dataOffset = 0;
+ m_blobItemIndex++;
+ }
+ }
+ break;
+ case BlobDataItem::Type::File: {
+ // Open the file if not done yet
+ if (m_fileHandle == FileSystem::invalidPlatformFileHandle)
+ {
+ WTF::Optional fileModificationTime = FileSystem::getFileModificationTime(blobItem.file()->path());
+ if (fileModificationTime
+ && fileModificationTime == blobItem.file()->expectedModificationTime())
+ m_fileHandle = FileSystem::openFile(blobItem.file()->path(), FileSystem::FileOpenMode::Read);
+
+ // FIXME the blob can specify an offset and chunk size inside the file
+ // So we should seek there and make sure we stop at the right time.
+ }
+
+
+ if (!FileSystem::isHandleValid(m_fileHandle)) {
+ LOG(Network, "Haiku - Failed while trying to open %s for upload\n", fileData.filename.utf8().data());
+ m_fileHandle = FileSystem::invalidPlatformFileHandle;
+ readBytes = -1;
+ } else {
+ // Note: there is no management of a file offset, we just keep the file
+ // handle open and read from the current position.
+ readBytes = FileSystem::readFromFile(m_fileHandle, buffer, size);
+ if (readBytes < 0) {
+ LOG(Network, "Haiku - Failed while trying to read %s for upload\n", fileData.filename.utf8().data());
+ }
+ }
+
+ if (readBytes <= 0) {
+ FileSystem::closeFile(m_fileHandle);
+ m_fileHandle = FileSystem::invalidPlatformFileHandle;
+ m_blobItemIndex++;
+ }
+ }
+ break;
+ }
+
+ // Should we advance to the next form element yet?
+ if (m_blobItemIndex > blobData->items().size())
+ {
+ m_elementPosition++;
+ m_blobItemIndex = 0;
+ }
+
+ if (readBytes < 0)
+ return WTF::nullopt;
+ return readBytes;
+}
+
+};
diff --git a/Source/WebCore/platform/network/haiku/HaikuFormDataStream.h b/Source/WebCore/platform/network/haiku/HaikuFormDataStream.h
new file mode 100644
index 000000000000..6ab0cabb3c52
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/HaikuFormDataStream.h
@@ -0,0 +1,64 @@
+/*
+ Copyright (C) 2018 Haiku, inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef HAIKUFORMDATASTREAM_H
+#define HAIKUFORMDATASTREAM_H
+
+#include "wtf/FileSystem.h"
+#include "FormData.h"
+
+#include
+#include
+
+namespace WebCore {
+
+class BFormDataIO : public BDataIO
+{
+public:
+ BFormDataIO(const FormData* form);
+ ~BFormDataIO();
+
+ ssize_t Size();
+ ssize_t Read(void* buffer, size_t size) override;
+ ssize_t Write(const void* buffer, size_t size) override;
+
+private:
+ void computeContentLength();
+
+ WTF::Optional readFromFile(const FormDataElement::EncodedFileData&, char*, size_t);
+ WTF::Optional readFromData(const Vector&, char*, size_t);
+ WTF::Optional readFromBlob(const FormDataElement::EncodedBlobData&, char*, size_t);
+
+ RefPtr m_formData;
+
+ bool m_isContentLengthUpdated { false };
+ unsigned long long m_totalSize { 0 };
+ unsigned long long m_totalReadSize { 0 };
+
+ size_t m_elementPosition { 0 };
+ size_t m_blobItemIndex { 0 };
+
+ FileSystem::PlatformFileHandle m_fileHandle { FileSystem::invalidPlatformFileHandle };
+ size_t m_dataOffset { 0 };
+};
+
+};
+
+
+#endif /* !HAIKUFORMDATASTREAM_H */
diff --git a/Source/WebCore/platform/network/haiku/NetworkStateNotifierHaiku.cpp b/Source/WebCore/platform/network/haiku/NetworkStateNotifierHaiku.cpp
new file mode 100644
index 000000000000..47cb3e98d72d
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/NetworkStateNotifierHaiku.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2008 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. ``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
+ * 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.
+ */
+
+#include "config.h"
+#include "NetworkStateNotifier.h"
+#include "NotImplemented.h"
+
+#include
+#include
+
+namespace WebCore {
+
+void NetworkStateNotifier::updateStateWithoutNotifying()
+{
+ // Should return true if at least one network interface is up.
+ notImplemented();
+ m_isOnLine = true;
+}
+
+void NetworkStateNotifier::startObserving()
+{
+ // Should register to call singleton().updateStateSoon() when an interface is up/down
+ notImplemented();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/network/haiku/NetworkStorageSessionHaiku.cpp b/Source/WebCore/platform/network/haiku/NetworkStorageSessionHaiku.cpp
new file mode 100644
index 000000000000..e21d2c689345
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/NetworkStorageSessionHaiku.cpp
@@ -0,0 +1,243 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2013 University of Szeged. 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 THE COPYRIGHT HOLDERS ``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.
+ */
+
+#include "config.h"
+#include "NetworkStorageSession.h"
+
+#include
+#include
+
+#include "Cookie.h"
+#include "CookieRequestHeaderFieldProxy.h"
+#include "NetworkingContext.h"
+#include "NotImplemented.h"
+#include "ResourceHandle.h"
+#include "wtf/URL.h"
+
+#include
+#include
+
+#define TRACE_COOKIE_JAR 0
+
+namespace WebCore {
+
+NetworkStorageSession::NetworkStorageSession(PAL::SessionID sessionID)
+ : m_sessionID(sessionID)
+ , m_context(nullptr)
+{
+}
+
+NetworkStorageSession::~NetworkStorageSession()
+{
+}
+
+static std::unique_ptr& defaultSession()
+{
+ ASSERT(isMainThread());
+ static NeverDestroyed> session;
+ return session;
+}
+
+void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty,
+ const SameSiteInfo& sameSiteInfo, const URL& url,
+ WTF::Optional frameID, WTF::Optional pageID,
+ const String& value) const
+{
+ BNetworkCookie* heapCookie
+ = new BNetworkCookie(value, BUrl(url));
+
+#if TRACE_COOKIE_JAR
+ printf("CookieJar: Add %s for %s\n", heapCookie->RawCookie(true).String(),
+ url.string().utf8().data());
+ printf(" from %s\n", value.utf8().data());
+#endif
+ platformSession().GetCookieJar().AddCookie(heapCookie);
+}
+
+bool NetworkStorageSession::cookiesEnabled() const
+{
+ return true;
+}
+
+std::pair NetworkStorageSession::cookiesForDOM(const URL& firstParty,
+ const SameSiteInfo& sameSiteInfo, const URL& url,
+ WTF::Optional frameID, WTF::Optional pageID,
+ IncludeSecureCookies includeSecureCookies) const
+{
+#if TRACE_COOKIE_JAR
+ printf("CookieJar: Request for %s\n", url.string().utf8().data());
+#endif
+
+ BString result;
+ BUrl hUrl(url);
+ bool secure = false;
+
+ const BNetworkCookie* c;
+ for (BNetworkCookieJar::UrlIterator it(
+ platformSession().GetCookieJar().GetUrlIterator(hUrl));
+ (c = it.Next()); ) {
+ // filter out httpOnly cookies,as this method is used to get cookies
+ // from JS code and these shouldn't be visible there.
+ if(c->HttpOnly())
+ continue;
+
+ // filter out secure cookies if they should be
+ if (c->Secure())
+ {
+ secure = true;
+ if (includeSecureCookies == IncludeSecureCookies::No)
+ continue;
+ }
+
+ result << "; " << c->RawCookie(false);
+ }
+ result.Remove(0, 2);
+
+ return {result, secure};
+}
+
+void NetworkStorageSession::setCookies(const Vector&, const URL&, const URL&)
+{
+ // FIXME: Implement for WebKit to use.
+}
+
+void NetworkStorageSession::setCookie(const Cookie&)
+{
+ // FIXME: Implement for WebKit to use.
+}
+
+void NetworkStorageSession::deleteCookie(const Cookie&)
+{
+ // FIXME: Implement for WebKit to use.
+}
+
+void NetworkStorageSession::deleteCookie(const URL& url, const String& cookie) const
+{
+#if TRACE_COOKIE_JAR
+ printf("CookieJar: delete cookie for %s (NOT IMPLEMENTED)\n", url.string().utf8().data());
+#endif
+ notImplemented();
+}
+
+void NetworkStorageSession::deleteAllCookies()
+{
+ notImplemented();
+}
+
+void NetworkStorageSession::deleteAllCookiesModifiedSince(WallTime since)
+{
+ notImplemented();
+}
+
+void NetworkStorageSession::deleteCookiesForHostnames(const Vector& cookieHostNames)
+{
+ notImplemented();
+}
+
+Vector NetworkStorageSession::getAllCookies()
+{
+ // FIXME: Implement for WebKit to use.
+ return { };
+}
+
+void NetworkStorageSession::getHostnamesWithCookies(HashSet& hostnames)
+{
+ notImplemented();
+}
+
+Vector NetworkStorageSession::getCookies(const URL&)
+{
+ // FIXME: Implement for WebKit to use.
+ return { };
+}
+
+bool NetworkStorageSession::getRawCookies(const URL& firstParty,
+ const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional frameID,
+ WTF::Optional pageID, Vector& rawCookies) const
+{
+#if TRACE_COOKIE_JAR
+ printf("CookieJar: get raw cookies for %s (NOT IMPLEMENTED)\n", url.string().utf8().data());
+#endif
+ notImplemented();
+
+ rawCookies.clear();
+ return false; // return true when implemented
+}
+
+void NetworkStorageSession::flushCookieStore()
+{
+ // FIXME: Implement for WebKit to use.
+}
+
+std::pair NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty,
+ const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional frameID,
+ WTF::Optional pageID, IncludeSecureCookies includeSecureCookies) const
+{
+#if TRACE_COOKIE_JAR
+ printf("CookieJar: RequestHeaderField for %s\n", url.string().utf8().data());
+#endif
+
+ BString result;
+ BUrl hUrl(url);
+ bool secure = false;
+
+ const BNetworkCookie* c;
+ for (BNetworkCookieJar::UrlIterator it(
+ platformSession().GetCookieJar().GetUrlIterator(hUrl));
+ (c = it.Next()); ) {
+ // filter out secure cookies if they should be
+ if (c->Secure())
+ {
+ secure = true;
+ if (includeSecureCookies == IncludeSecureCookies::No)
+ continue;
+ }
+
+ result << "; " << c->RawCookie(false);
+ }
+ result.Remove(0, 2);
+
+ return {result, secure};
+}
+
+std::pair NetworkStorageSession::cookieRequestHeaderFieldValue(const CookieRequestHeaderFieldProxy& headerFieldProxy) const
+{
+ return cookieRequestHeaderFieldValue(headerFieldProxy.firstParty, headerFieldProxy.sameSiteInfo, headerFieldProxy.url, headerFieldProxy.frameID, headerFieldProxy.pageID, headerFieldProxy.includeSecureCookies);
+}
+
+BUrlContext& NetworkStorageSession::platformSession() const
+{
+ static BUrlContext sDefaultContext;
+ return m_context ? *m_context : sDefaultContext;
+}
+
+void NetworkStorageSession::setPlatformSession(BUrlContext* context)
+{
+ m_context = context;
+}
+
+}
+
diff --git a/Source/WebCore/platform/network/haiku/ProxyServerHaiku.cpp b/Source/WebCore/platform/network/haiku/ProxyServerHaiku.cpp
new file mode 100644
index 000000000000..4bdde731a085
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/ProxyServerHaiku.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2014 Haiku, inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "ProxyServer.h"
+
+#include "wtf/URL.h"
+
+namespace WebCore {
+
+Vector proxyServersForURL(const URL&)
+{
+ // FIXME: Implement.
+ return Vector();
+}
+
+} // namespace WebCore
+
diff --git a/Source/WebCore/platform/network/haiku/ResourceError.h b/Source/WebCore/platform/network/haiku/ResourceError.h
new file mode 100644
index 000000000000..1996a6b85d9e
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/ResourceError.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2006 Apple Computer, 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#ifndef ResourceError_h
+#define ResourceError_h
+
+#include "ResourceErrorBase.h"
+
+namespace WebCore {
+
+class ResourceError : public ResourceErrorBase
+{
+public:
+ ResourceError(Type type = Type::Null)
+ : ResourceErrorBase(type)
+ {
+ }
+
+ ResourceError(const String& domain, int errorCode, const URL& failingURL, const String& localizedDescription, Type type = Type::General)
+ : ResourceErrorBase(domain, errorCode, failingURL, localizedDescription, type)
+ {
+ }
+
+private:
+ friend class ResourceErrorBase;
+ void doPlatformIsolatedCopy(const ResourceError&) { }
+};
+}
+
+#endif // ResourceError_h_
diff --git a/Source/WebCore/platform/network/haiku/ResourceHandleHaiku.cpp b/Source/WebCore/platform/network/haiku/ResourceHandleHaiku.cpp
new file mode 100644
index 000000000000..f49280ca06fc
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/ResourceHandleHaiku.cpp
@@ -0,0 +1,178 @@
+/*
+ * Copyright (C) 2006 Nikolas Zimmermann
+ * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
+ * Copyright (C) 2008 Holger Hans Peter Freyther
+ *
+ * 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#include "config.h"
+#include "ResourceHandle.h"
+
+#include "DocumentLoader.h"
+#include "Frame.h"
+#include "NotImplemented.h"
+#include "Page.h"
+#include "BUrlProtocolHandler.h"
+#include "ResourceHandleClient.h"
+#include "ResourceHandleInternal.h"
+#include "SharedBuffer.h"
+
+// TODO move to SynchronousLoaderClientHaiku.cpp
+#include "SynchronousLoaderClient.h"
+
+namespace WebCore {
+
+ResourceHandleInternal::~ResourceHandleInternal()
+{
+}
+
+ResourceHandle::~ResourceHandle()
+{
+ cancel();
+}
+
+bool ResourceHandle::start()
+{
+ // If NetworkingContext is invalid then we are no longer attached to a Page,
+ // this must be an attempted load from an unload event handler, so let's just block it.
+ if (d->m_context && !d->m_context->isValid())
+ return false;
+
+ if (!d->m_user.isEmpty() || !d->m_pass.isEmpty()) {
+ // If credentials were specified for this request, add them to the url,
+ // so that they will be passed to QNetworkRequest.
+ URL urlWithCredentials(firstRequest().url());
+ urlWithCredentials.setUser(d->m_user);
+ urlWithCredentials.setPass(d->m_pass);
+ d->m_firstRequest.setURL(urlWithCredentials);
+ }
+
+ d->m_urlrequest = new BUrlProtocolHandler(d->m_context.get(), this, false);
+
+ if (!d->m_urlrequest->isValid())
+ scheduleFailure(InvalidURLFailure);
+ return true;
+}
+
+void ResourceHandle::cancel()
+{
+ if (d->m_urlrequest) {
+ d->m_urlrequest->abort();
+ delete d->m_urlrequest;
+ d->m_urlrequest = 0;
+ }
+}
+
+void ResourceHandle::platformLoadResourceSynchronously(NetworkingContext* context, const ResourceRequest& request, StoredCredentialsPolicy /*storedCredentials*/, ResourceError& error, ResourceResponse& response, Vector& data)
+{
+ ASSERT_NOT_REACHED();
+}
+
+
+bool ResourceHandle::didReceiveInvalidCertificate(BCertificate& certificate,
+ const char* message)
+{
+ if (client())
+ return client()->didReceiveInvalidCertificate(this, certificate, message);
+ return false;
+}
+
+
+void ResourceHandle::didReceiveAuthenticationChallenge(const AuthenticationChallenge& challenge)
+{
+ ResourceHandleInternal* internal = getInternal();
+ ASSERT(internal->m_currentWebChallenge.isNull());
+ ASSERT(challenge.authenticationClient() == this); // Should be already set.
+ internal->m_currentWebChallenge = challenge;
+
+ if (client())
+ client()->didReceiveAuthenticationChallenge(this, challenge);
+}
+
+void ResourceHandle::receivedCredential(const AuthenticationChallenge& challenge, const Credential& credential)
+{
+ ASSERT(!challenge.isNull());
+ ResourceHandleInternal* internal = getInternal();
+ if (challenge != internal->m_currentWebChallenge)
+ return;
+
+ internal->m_user = credential.user();
+ internal->m_pass = credential.password();
+
+ clearAuthentication();
+}
+
+void ResourceHandle::receivedRequestToContinueWithoutCredential(const AuthenticationChallenge& challenge)
+{
+ ASSERT(!challenge.isNull());
+ ResourceHandleInternal* internal = getInternal();
+ if (challenge != internal->m_currentWebChallenge)
+ return;
+
+ internal->m_user = "";
+ internal->m_pass = "";
+
+ clearAuthentication();
+}
+
+void ResourceHandle::receivedCancellation(const AuthenticationChallenge&)
+{
+ // TODO
+}
+
+
+void ResourceHandle::receivedRequestToPerformDefaultHandling(const AuthenticationChallenge&)
+{
+ ASSERT_NOT_REACHED();
+}
+
+
+void ResourceHandle::receivedChallengeRejection(const AuthenticationChallenge&)
+{
+ ASSERT_NOT_REACHED();
+}
+
+
+void ResourceHandle::platformSetDefersLoading(bool defers)
+{
+ d->m_defersLoading = defers;
+
+ /*if (d->m_job)
+ d->m_job->setLoadMode(QNetworkReplyHandler::LoadMode(defers));*/
+}
+
+// TODO move to SynchronousLoaderClientHaiku.cpp
+void SynchronousLoaderClient::didReceiveAuthenticationChallenge(ResourceHandle*, const AuthenticationChallenge&)
+{
+ notImplemented();
+}
+
+ResourceError SynchronousLoaderClient::platformBadResponseError()
+{
+ notImplemented();
+ return ResourceError();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/network/haiku/ResourceRequest.h b/Source/WebCore/platform/network/haiku/ResourceRequest.h
new file mode 100644
index 000000000000..de3542205d09
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/ResourceRequest.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2003, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig
+ * Copyright (C) 2019 Haiku, 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#ifndef ResourceRequest_h
+#define ResourceRequest_h
+
+#include "ResourceRequestBase.h"
+
+#include
+#include
+
+class BUrlContext;
+class BUrlRequest;
+
+namespace WebCore {
+
+ class ResourceRequest : public ResourceRequestBase {
+ public:
+ ResourceRequest(const String& url)
+ : ResourceRequestBase(URL({ }, url), ResourceRequestCachePolicy::UseProtocolCachePolicy)
+ {
+ }
+
+ ResourceRequest(const URL& url)
+ : ResourceRequestBase(url, ResourceRequestCachePolicy::UseProtocolCachePolicy)
+ {
+ }
+
+ ResourceRequest(const URL& url, const String& referrer, ResourceRequestCachePolicy policy = ResourceRequestCachePolicy::UseProtocolCachePolicy)
+ : ResourceRequestBase(url, policy)
+ {
+ setHTTPReferrer(referrer);
+ }
+
+ ResourceRequest()
+ : ResourceRequestBase(URL(), ResourceRequestCachePolicy::UseProtocolCachePolicy)
+ {
+ }
+
+ BUrlRequest* toNetworkRequest(BUrlContext*);
+
+ void setCredentials(const char* username, const char* password);
+ void updateFromDelegatePreservingOldProperties(const ResourceRequest& delegateProvidedRequest) { *this = delegateProvidedRequest; }
+
+ template void encodePlatformData(Encoder&) const;
+ template bool decodePlatformData(Decoder&);
+
+ private:
+ friend class ResourceRequestBase;
+
+ void doUpdatePlatformRequest() {}
+ void doUpdateResourceRequest() {}
+ void doUpdatePlatformHTTPBody() { }
+ void doUpdateResourceHTTPBody() { }
+
+ void doPlatformSetAsIsolatedCopy(const ResourceRequest&) { }
+
+ BString fUsername;
+ BString fPassword;
+ };
+
+template
+void ResourceRequest::encodePlatformData(Encoder& encoder) const
+{
+ encodeBase(encoder);
+}
+
+template
+bool ResourceRequest::decodePlatformData(Decoder& decoder)
+{
+ if(!decodeBase(decoder))
+ {
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ResourceRequest_h
diff --git a/Source/WebCore/platform/network/haiku/ResourceRequestHaiku.cpp b/Source/WebCore/platform/network/haiku/ResourceRequestHaiku.cpp
new file mode 100644
index 000000000000..d24b955c03e0
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/ResourceRequestHaiku.cpp
@@ -0,0 +1,112 @@
+/*
+ Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#include "ResourceRequest.h"
+
+#include "CookieJar.h"
+#include "NetworkingContext.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+namespace WebCore {
+
+BUrlRequest* ResourceRequest::toNetworkRequest(BUrlContext* context)
+{
+ BUrlRequest* request = BUrlProtocolRoster::MakeRequest(url());
+
+ if (!request) {
+ m_url = WTF::blankURL(); // This tells the ResourceLoader we failed.
+ return NULL;
+ }
+
+ if (context)
+ request->SetContext(context);
+
+ if (timeoutInterval() > 0)
+ request->SetTimeout(timeoutInterval());
+
+ BHttpRequest* httpRequest = dynamic_cast(request);
+ if (httpRequest != NULL) {
+ const HTTPHeaderMap &headers = httpHeaderFields();
+ BHttpHeaders* requestHeaders = new BHttpHeaders();
+
+ for (HTTPHeaderMap::const_iterator it = headers.begin(),
+ end = headers.end(); it != end; ++it)
+ {
+ requestHeaders->AddHeader(it->key.utf8().data(),
+ it->value.utf8().data());
+ }
+
+ if (!fUsername.IsEmpty()) {
+ httpRequest->SetUserName(fUsername);
+ httpRequest->SetPassword(fPassword);
+ }
+
+ if (!requestHeaders->HasHeader("Accept-Language")) {
+ // Add the default languages
+ BMessage message;
+ BLocaleRoster::Default()->GetPreferredLanguages(&message);
+
+ BString languages;
+ BString language;
+ for(int i = 0; message.FindString("language", i, &language) == B_OK; i++) {
+ if (i != 0)
+ languages << ',';
+ languages << language;
+ languages << ";q=";
+ // This will lead to negative priorities if there are more than
+ // 100 languages. Hopefully no one can read that much...
+ languages << 1 - (i / 100.f);
+
+ int underscore = language.FindFirst('_');
+ if (underscore > 0) {
+ // Some page only accept 2-letter language codes (eg Google
+ // account login). Include that if we have a country suffix
+ language.Truncate(underscore);
+ languages << ',';
+ languages << language;
+ languages << ";q=";
+ languages << 1 - (i / 100.f);
+ }
+ }
+
+ requestHeaders->AddHeader("Accept-Language", languages);
+ }
+
+ httpRequest->AdoptHeaders(requestHeaders);
+ }
+
+ return request;
+}
+
+
+void ResourceRequest::setCredentials(const char* username, const char* password)
+{
+ fUsername = username;
+ fPassword = password;
+}
+
+}
+
diff --git a/Source/WebCore/platform/network/haiku/ResourceResponse.h b/Source/WebCore/platform/network/haiku/ResourceResponse.h
new file mode 100644
index 000000000000..32f6341be466
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/ResourceResponse.h
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2006 Apple Computer, 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#ifndef ResourceResponse_h
+#define ResourceResponse_h
+
+#include "ResourceResponseBase.h"
+
+namespace WebCore {
+
+class ResourceResponse : public ResourceResponseBase {
+public:
+ ResourceResponse()
+ {
+ }
+
+ ResourceResponse(const URL& url, const String& mimeType, long long expectedLength, const String& textEncodingName)
+ : ResourceResponseBase(url, mimeType, expectedLength, textEncodingName)
+ {
+ m_resourceName = url.lastPathComponent();
+ }
+
+ void setSuggestedFilename(String name) { m_resourceName = name;}
+
+ template void encodePlatformData(Encoder&) const;
+ template bool decodePlatformData(Decoder&);
+
+private:
+ friend class ResourceResponseBase;
+
+ String platformSuggestedFilename() const { return m_resourceName; }
+
+ String m_resourceName;
+};
+
+template
+void ResourceResponse::encodePlatformData(Encoder& encoder) const
+{
+ fprintf(stderr,"%s \n",__PRETTY_FUNCTION__);
+ encodeBase(encoder);
+}
+
+template
+bool ResourceResponse::decodePlatformData(Decoder& decoder)
+{
+ fprintf(stderr,"%s \n",__PRETTY_FUNCTION__);
+ if(!decodeBase(decoder))
+ {
+ fprintf(stderr,"%s -- failed\n",__PRETTY_FUNCTION__);
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace WebCore
+
+#endif // ResourceResponse_h
diff --git a/Source/WebCore/platform/network/haiku/SocketStreamHandleHaiku.cpp b/Source/WebCore/platform/network/haiku/SocketStreamHandleHaiku.cpp
new file mode 100644
index 000000000000..383032bc5d5f
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/SocketStreamHandleHaiku.cpp
@@ -0,0 +1,218 @@
+/*
+ * Copyright (C) 2009 Brent Fulgham. All rights reserved.
+ * Copyright (C) 2009 Google Inc. All rights reserved.
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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.
+ */
+
+#include "config.h"
+#include "SocketStreamHandleImpl.h"
+
+#include "Logging.h"
+#include "SocketStreamError.h"
+#include "SocketStreamHandleClient.h"
+#include "StorageSessionProvider.h"
+
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+namespace WebCore {
+
+SocketStreamHandleImpl::SocketStreamHandleImpl(const URL& url, SocketStreamHandleClient& client, const StorageSessionProvider* provider)
+ : SocketStreamHandle(url, client)
+ , m_storageSessionProvider(provider)
+{
+ LOG(Network, "SocketStreamHandle %p new client %p", this, &m_client);
+ ASSERT(isMainThread());
+
+ m_workerThread = Thread::create("WebSocket thread", [this, protectedThis = makeRef(*this)] {
+ threadEntryPoint();
+ });
+}
+
+SocketStreamHandleImpl::~SocketStreamHandleImpl()
+{
+ LOG(Network, "SocketStreamHandle %p delete", this);
+ stopThread();
+}
+
+Optional SocketStreamHandleImpl::platformSendInternal(const uint8_t* data, size_t length)
+{
+ LOG(Network, "SocketStreamHandle %p platformSend", this);
+ ASSERT(isMainThread());
+
+ if (m_hasPendingWriteData)
+ return 0;
+
+ m_hasPendingWriteData = true;
+
+ auto writeBuffer = makeUniqueArray(length);
+ memcpy(writeBuffer.get(), data, length);
+
+ callOnWorkerThread([this, writeBuffer = WTFMove(writeBuffer), writeBufferSize = length]() mutable {
+ ASSERT(!isMainThread());
+ m_writeBuffer = WTFMove(writeBuffer);
+ m_writeBufferSize = writeBufferSize;
+ m_writeBufferOffset = 0;
+ });
+
+ return length;
+}
+
+void SocketStreamHandleImpl::platformClose()
+{
+ LOG(Network, "SocketStreamHandle %p platformClose", this);
+ ASSERT(isMainThread());
+
+ if (m_state == Closed)
+ return;
+ m_state = Closed;
+
+ stopThread();
+ m_client.didCloseSocketStream(*this);
+}
+
+void SocketStreamHandleImpl::threadEntryPoint()
+{
+ ASSERT(!isMainThread());
+
+ unsigned int port = m_url.port() ? *m_url.port() : (m_url.protocolIs("wss") ? 443 : 80);
+ BNetworkAddress peer(m_url.host().utf8().data(), port);
+ BSocket* socket = m_url.protocolIs("wss") ? new BSecureSocket : new BSocket;
+
+ // Connect to host
+ status_t status = socket->Connect(peer);
+ if (status != B_OK) {
+ handleError(status);
+ return;
+ }
+
+ callOnMainThread([this, protectedThis = makeRef(*this)] {
+ if (m_state == Connecting) {
+ m_state = Open;
+ m_client.didOpenSocketStream(*this);
+ }
+ });
+
+ while (m_running) {
+ executeTasks();
+
+ status_t readable = socket->WaitForReadable(20 * 1000);
+ status_t writable = B_ERROR;
+ if (m_writeBuffer.get() != nullptr)
+ writable = socket->WaitForWritable(20 * 1000);
+
+ // These logic only run when there's data waiting.
+ if ((writable == B_OK) && m_running) {
+ auto bytesSent = socket->Write(m_writeBuffer.get() + m_writeBufferOffset, m_writeBufferSize - m_writeBufferOffset);
+ m_writeBufferOffset += bytesSent;
+
+ if (m_writeBufferSize <= m_writeBufferOffset) {
+ m_writeBuffer = nullptr;
+ m_writeBufferSize = 0;
+ m_writeBufferOffset = 0;
+
+ callOnMainThread([this, protectedThis = makeRef(*this)] {
+ m_hasPendingWriteData = false;
+ sendPendingData();
+ });
+ }
+ }
+
+ if ((readable == B_OK) && m_running) {
+ auto readBuffer = makeUniqueArray(kReadBufferSize);
+ ssize_t bytesRead = socket->Read(readBuffer.get(), kReadBufferSize);
+ // `0` result means nothing to handle at this moment.
+ if (bytesRead <= 0) {
+ // Make sure we are still connected.
+ if (!socket->IsConnected()) {
+ m_running = false;
+ callOnMainThread([this, protectedThis = makeRef(*this)] {
+ close();
+ });
+ break;
+ }
+ continue;
+ }
+
+ callOnMainThread([this, protectedThis = makeRef(*this), buffer = WTFMove(readBuffer), size = bytesRead ] {
+ if (m_state == Open)
+ m_client.didReceiveSocketStreamData(*this, reinterpret_cast(buffer.get()), size);
+ });
+ }
+ }
+
+ m_writeBuffer = nullptr;
+ delete socket;
+}
+
+void SocketStreamHandleImpl::handleError(status_t errorCode)
+{
+ m_running = false;
+ callOnMainThread([this, protectedThis = makeRef(*this), errorCode, localizedDescription = strerror(errorCode)] {
+ if (m_state == Closed)
+ return;
+
+ // TODO: when to call m_client.didFailToReceiveSocketStreamData(*this); ?
+ m_client.didFailSocketStream(*this, SocketStreamError(static_cast(errorCode), { }, localizedDescription));
+ });
+}
+
+void SocketStreamHandleImpl::stopThread()
+{
+ ASSERT(isMainThread());
+
+ m_running = false;
+
+ if (m_workerThread) {
+ m_workerThread->waitForCompletion();
+ m_workerThread = nullptr;
+ }
+}
+
+void SocketStreamHandleImpl::callOnWorkerThread(Function&& task)
+{
+ ASSERT(isMainThread());
+ m_taskQueue.append(std::make_unique>(WTFMove(task)));
+}
+
+void SocketStreamHandleImpl::executeTasks()
+{
+ ASSERT(!isMainThread());
+
+ auto tasks = m_taskQueue.takeAllMessages();
+ for (auto& task : tasks)
+ (*task)();
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/network/haiku/SocketStreamHandleImpl.h b/Source/WebCore/platform/network/haiku/SocketStreamHandleImpl.h
new file mode 100644
index 000000000000..322b25b0fed2
--- /dev/null
+++ b/Source/WebCore/platform/network/haiku/SocketStreamHandleImpl.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2009-2018 Apple Inc. All rights reserved.
+ * Copyright (C) 2009 Google 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:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
+ * OWNER OR 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
+
+#include "SocketStreamHandle.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+
+namespace WebCore {
+
+class SocketStreamHandleClient;
+class StorageSessionProvider;
+
+class SocketStreamHandleImpl : public SocketStreamHandle {
+public:
+ static Ref create(const URL& url, SocketStreamHandleClient& client, PAL::SessionID, const String&, SourceApplicationAuditToken&&, const StorageSessionProvider* provider) { return adoptRef(*new SocketStreamHandleImpl(url, client, provider)); }
+
+ virtual ~SocketStreamHandleImpl();
+
+ WEBCORE_EXPORT void platformSend(const uint8_t* data, size_t length, Function&&) final;
+ WEBCORE_EXPORT void platformSendHandshake(const uint8_t* data, size_t length, const Optional&, Function&&) final;
+ WEBCORE_EXPORT void platformClose() final;
+
+private:
+ WEBCORE_EXPORT SocketStreamHandleImpl(const URL&, SocketStreamHandleClient&, const StorageSessionProvider*);
+
+ size_t bufferedAmount() final;
+ Optional platformSendInternal(const uint8_t*, size_t);
+ bool sendPendingData();
+
+ void threadEntryPoint();
+ void handleError(status_t);
+ void stopThread();
+
+ void callOnWorkerThread(Function&&);
+ void executeTasks();
+
+ static const size_t kReadBufferSize = 4 * 1024;
+
+ RefPtr m_storageSessionProvider;
+ RefPtr m_workerThread;
+ std::atomic m_running { true };
+
+ MessageQueue> m_taskQueue;
+
+ bool m_hasPendingWriteData { false };
+ size_t m_writeBufferSize { 0 };
+ size_t m_writeBufferOffset { 0 };
+ UniqueArray m_writeBuffer;
+
+ StreamBuffer m_buffer;
+ static const unsigned maxBufferSize = 100 * 1024 * 1024;
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/platform/text/haiku/StringHaiku.cpp b/Source/WebCore/platform/text/haiku/StringHaiku.cpp
new file mode 100644
index 000000000000..e50ec909e4d2
--- /dev/null
+++ b/Source/WebCore/platform/text/haiku/StringHaiku.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2007 Ryan Leavengood
+ *
+ * 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 COMPUTER, INC. ``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 COMPUTER, INC. OR
+ * 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.
+ */
+
+#include "config.h"
+#include
+#include
+
+#include
+
+namespace WTF {
+
+// String conversions
+String::String(const BString& string)
+{
+ if (string.Length())
+ m_impl = String::fromUTF8(string.String(), string.Length()).impl();
+ else
+ m_impl = StringImpl::empty();
+}
+
+String::operator BString() const
+{
+ BString string;
+ string.SetTo(utf8().data());
+
+ return string;
+}
+
+} // namespace WebCore
+
diff --git a/Source/WebKit/CMakeLists.txt b/Source/WebKit/CMakeLists.txt
index b8e08c1fb42b..c453360d1910 100644
--- a/Source/WebKit/CMakeLists.txt
+++ b/Source/WebKit/CMakeLists.txt
@@ -96,6 +96,10 @@ set(WebKit_INCLUDE_DIRECTORIES
"${CMAKE_SOURCE_DIR}/WebKitLibraries"
)
+SET(WebKit_LOCAL_INCLUDE_DIRECTORIES
+ "${WEBCORE_DIR}/css"
+)
+
set(PROTOCOL_GENERATOR_SCRIPTS_DIR "${JAVASCRIPTCORE_DIR}/inspector/scripts")
list(APPEND WebKit_UNIFIED_SOURCE_LIST_FILES
@@ -417,6 +421,15 @@ add_executable(WebProcess ${WebProcess_SOURCES})
ADD_WEBKIT_PREFIX_HEADER(WebProcess)
target_link_libraries(WebProcess ${WebProcess_LIBRARIES})
+if (WebProcess_RESOURCES)
+ add_custom_command(TARGET WebProcess POST_BUILD
+ COMMAND rc -o WebProcess.rsrc ${WEBKIT_DIR}/haiku/WebProcess.rdef
+ COMMAND xres -o ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/WebProcess WebProcess.rsrc
+ COMMAND mimeset -f ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/WebProcess
+ DEPENDS ${WebProcess_RESOURCES}
+ VERBATIM)
+endif()
+
if (WebKit_WebProcess_OUTPUT_NAME)
set_target_properties(WebProcess PROPERTIES OUTPUT_NAME ${WebKit_WebProcess_OUTPUT_NAME})
endif ()
diff --git a/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h b/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h
index dc79eebcf18d..5c47b3bd49fe 100644
--- a/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h
+++ b/Source/WebKit/NetworkProcess/CustomProtocols/LegacyCustomProtocolManager.h
@@ -88,6 +88,12 @@ class LegacyCustomProtocolManager : public NetworkProcessSupplement, public IPC:
};
typedef std::unique_ptr CustomProtocol;
#endif
+#if USE(HAIKU)
+ class HaikuCustomProtocolImpl {
+ // TODO
+ };
+ typedef std::unique_ptr CustomProtocol;
+#endif
uint64_t addCustomProtocol(CustomProtocol&&);
void removeCustomProtocol(uint64_t customProtocolID);
diff --git a/Source/WebKit/NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp b/Source/WebKit/NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
index 736c01708a46..9f42524d4fac 100644
--- a/Source/WebKit/NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
+++ b/Source/WebKit/NetworkProcess/EntryPoint/unix/NetworkProcessMain.cpp
@@ -24,6 +24,7 @@
*/
#include "NetworkProcessMainUnix.h"
+#include "wtf/Platform.h"
#include
diff --git a/Source/WebKit/NetworkProcess/NetworkDataTask.cpp b/Source/WebKit/NetworkProcess/NetworkDataTask.cpp
index bcbae9d31fbf..41fa61792563 100644
--- a/Source/WebKit/NetworkProcess/NetworkDataTask.cpp
+++ b/Source/WebKit/NetworkProcess/NetworkDataTask.cpp
@@ -42,6 +42,9 @@
#if USE(CURL)
#include "NetworkDataTaskCurl.h"
#endif
+#if PLATFORM(HAIKU)
+#include "NetworkDataTaskHaiku.h"
+#endif
namespace WebKit {
using namespace WebCore;
@@ -58,6 +61,9 @@ Ref NetworkDataTask::create(NetworkSession& session, NetworkDat
#if USE(CURL)
return NetworkDataTaskCurl::create(session, client, parameters.request, parameters.storedCredentialsPolicy, parameters.contentSniffingPolicy, parameters.contentEncodingSniffingPolicy, parameters.shouldClearReferrerOnHTTPSToHTTPRedirect, parameters.isMainFrameNavigation);
#endif
+#if PLATFORM(HAIKU)
+ return NetworkDataTaskHaiku::create(session, client, parameters.request, parameters.storedCredentialsPolicy, parameters.contentSniffingPolicy, parameters.contentEncodingSniffingPolicy, parameters.shouldClearReferrerOnHTTPSToHTTPRedirect, parameters.isMainFrameNavigation);
+#endif
}
NetworkDataTask::NetworkDataTask(NetworkSession& session, NetworkDataTaskClient& client, const ResourceRequest& requestWithCredentials, StoredCredentialsPolicy storedCredentialsPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect, bool dataTaskIsForMainFrameNavigation)
diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.cpp b/Source/WebKit/NetworkProcess/NetworkProcess.cpp
index dd9a1e3a8c5d..d82450f70ccc 100644
--- a/Source/WebKit/NetworkProcess/NetworkProcess.cpp
+++ b/Source/WebKit/NetworkProcess/NetworkProcess.cpp
@@ -420,6 +420,8 @@ void NetworkProcess::createNetworkConnectionToWebProcess(bool isServiceWorkerPro
IPC::Attachment clientSocket(clientIdentifier);
parentProcessConnection()->send(Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess(clientSocket), 0);
+#elif PLATFORM(HAIKU)
+ //do nothing
#else
notImplemented();
#endif
diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.h b/Source/WebKit/NetworkProcess/NetworkProcess.h
index 0e1dabd00ee4..9aa33cecd769 100644
--- a/Source/WebKit/NetworkProcess/NetworkProcess.h
+++ b/Source/WebKit/NetworkProcess/NetworkProcess.h
@@ -386,6 +386,9 @@ class NetworkProcess : public AuxiliaryProcess, private DownloadManager::Client,
// Message Handlers
void didReceiveSyncNetworkProcessMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr&);
void initializeNetworkProcess(NetworkProcessCreationParameters&&);
+#if PLATFORM(HAIKU)
+ void createNetworkConnectionToWebProcessHaiku(bool isServiceWorkerProcess, WebCore::RegistrableDomain&&,int64_t webPID);
+#endif
void createNetworkConnectionToWebProcess(bool isServiceWorkerProcess, WebCore::RegistrableDomain&&);
void fetchWebsiteData(PAL::SessionID, OptionSet, OptionSet, uint64_t callbackID);
diff --git a/Source/WebKit/NetworkProcess/NetworkProcess.messages.in b/Source/WebKit/NetworkProcess/NetworkProcess.messages.in
index 6d0624083f75..404cbc7c6953 100644
--- a/Source/WebKit/NetworkProcess/NetworkProcess.messages.in
+++ b/Source/WebKit/NetworkProcess/NetworkProcess.messages.in
@@ -27,6 +27,9 @@ messages -> NetworkProcess LegacyReceiver {
# Creates a connection for communication with a WebProcess
CreateNetworkConnectionToWebProcess(bool isServiceWorkerProcess, WebCore::RegistrableDomain registrableDomain)
+#if PLATFORM(HAIKU)
+ CreateNetworkConnectionToWebProcessHaiku(bool isServiceWorkerProcess, WebCore::RegistrableDomain registrableDomain,int64_t webPID)
+#endif
#if USE(SOUP)
SetIgnoreTLSErrors(bool ignoreTLSErrors)
UserPreferredLanguagesChanged(Vector languages)
diff --git a/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp b/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
index 0d4f9a2a1aea..4fbe218a0ad0 100644
--- a/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
+++ b/Source/WebKit/NetworkProcess/NetworkResourceLoader.cpp
@@ -778,9 +778,12 @@ void NetworkResourceLoader::startBufferingTimerIfNeeded()
{
if (isSynchronous())
return;
+
if (m_bufferingTimer.isActive())
return;
+
m_bufferingTimer.startOneShot(m_parameters.maximumBufferingTime);
+
}
void NetworkResourceLoader::bufferingTimerFired()
diff --git a/Source/WebKit/NetworkProcess/NetworkSession.cpp b/Source/WebKit/NetworkProcess/NetworkSession.cpp
index 1d0a8ab9ba75..532c7d264b1c 100644
--- a/Source/WebKit/NetworkProcess/NetworkSession.cpp
+++ b/Source/WebKit/NetworkProcess/NetworkSession.cpp
@@ -50,6 +50,10 @@
#include "NetworkSessionCurl.h"
#endif
+#if PLATFORM(HAIKU)
+#include "NetworkSessionHaiku.h"
+#endif
+
namespace WebKit {
using namespace WebCore;
@@ -64,6 +68,9 @@ Ref NetworkSession::create(NetworkProcess& networkProcess, Netwo
#if USE(CURL)
return NetworkSessionCurl::create(networkProcess, WTFMove(parameters));
#endif
+#if PLATFORM(HAIKU)
+ return NetworkSessionHaiku::create(networkProcess, WTFMove(parameters));
+#endif
}
NetworkStorageSession& NetworkSession::networkStorageSession() const
diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCacheDataHaiku.cpp b/Source/WebKit/NetworkProcess/cache/NetworkCacheDataHaiku.cpp
new file mode 100644
index 000000000000..dc2c046cb3a8
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/cache/NetworkCacheDataHaiku.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2019 Haiku, Inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "NetworkCacheData.h"
+
+#include
+
+namespace WebKit {
+namespace NetworkCache {
+
+Data::Data(const uint8_t* data, size_t size)
+{
+ notImplemented();
+}
+
+Data Data::empty()
+{
+ notImplemented();
+ return { };
+}
+
+const uint8_t* Data::data() const
+{
+ notImplemented();
+ return nullptr;
+}
+
+bool Data::isNull() const
+{
+ notImplemented();
+ return true;
+}
+
+bool Data::apply(const Function& applier) const
+{
+ notImplemented();
+ return false;
+}
+
+Data Data::subrange(size_t offset, size_t size) const
+{
+ return { };
+}
+
+Data concatenate(const Data& a, const Data& b)
+{
+ notImplemented();
+ return { };
+}
+
+Data Data::adoptMap(void* map, size_t size, int fd)
+{
+ notImplemented();
+ return { };
+}
+
+} // namespace NetworkCache
+} // namespace WebKit
diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp b/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp
index be84371a8630..e99496ff627c 100644
--- a/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp
+++ b/Source/WebKit/NetworkProcess/cache/NetworkCacheFileSystem.cpp
@@ -53,7 +53,7 @@
namespace WebKit {
namespace NetworkCache {
-#if !OS(WINDOWS)
+#if !OS(WINDOWS) && !OS(HAIKU)
static DirectoryEntryType directoryEntryType(uint8_t dtype)
{
switch (dtype) {
@@ -71,7 +71,7 @@ static DirectoryEntryType directoryEntryType(uint8_t dtype)
void traverseDirectory(const String& path, const Function& function)
{
-#if !OS(WINDOWS)
+#if !OS(WINDOWS) && !OS(HAIKU)
DIR* dir = opendir(FileSystem::fileSystemRepresentation(path).data());
if (!dir)
return;
diff --git a/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelHaiku.cpp b/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelHaiku.cpp
new file mode 100644
index 000000000000..7b0c0e80ae4c
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/cache/NetworkCacheIOChannelHaiku.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2019 Haiku Inc.,
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "NetworkCacheIOChannel.h"
+
+#include
+
+namespace WebKit {
+namespace NetworkCache {
+
+IOChannel::IOChannel(const String& filePath, Type type)
+ : m_path{filePath}
+ , m_type{type}
+{
+ notImplemented();
+}
+
+IOChannel::~IOChannel()
+{
+}
+
+Ref IOChannel::open(const String& filePath, IOChannel::Type type)
+{
+ return adoptRef(*new IOChannel(filePath, type));
+}
+
+void IOChannel::read(size_t offset, size_t size, WorkQueue* queue, Function&& completionHandler)
+{
+ notImplemented();
+}
+
+void IOChannel::write(size_t offset, const Data& data, WorkQueue* queue, Function&& completionHandler)
+{
+ notImplemented();
+}
+
+} // namespace NetworkCache
+} // namespace WebKit
diff --git a/Source/WebKit/NetworkProcess/haiku/NetworkDataTaskHaiku.cpp b/Source/WebKit/NetworkProcess/haiku/NetworkDataTaskHaiku.cpp
new file mode 100644
index 000000000000..23a9a0550f8a
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/haiku/NetworkDataTaskHaiku.cpp
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2019 Haiku, Inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "NetworkDataTaskHaiku.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include "BeDC.h"
+#include
+static const int gMaxRecursionLimit = 10;
+
+namespace WebKit {
+
+using namespace WebCore;
+
+NetworkDataTaskHaiku::NetworkDataTaskHaiku(NetworkSession& session, NetworkDataTaskClient& client, const ResourceRequest& requestWithCredentials,
+ StoredCredentialsPolicy storedCredentialsPolicy, ContentSniffingPolicy shouldContentSniff, ContentEncodingSniffingPolicy,
+ bool shouldClearReferrerOnHTTPSToHTTPRedirect, bool dataTaskIsForMainFrameNavigation)
+ : NetworkDataTask(session, client, requestWithCredentials, storedCredentialsPolicy, shouldClearReferrerOnHTTPSToHTTPRedirect, dataTaskIsForMainFrameNavigation)
+ //, BUrlProtocolAsynchronousListener(true)
+ , m_postData(NULL)
+ , m_responseDataSent(false)
+ , m_redirected(false)
+ , m_redirectionTries(gMaxRecursionLimit)
+ , m_position(0)
+
+{
+ if (m_scheduledFailureType != NoFailure)
+ return;
+
+ auto request = requestWithCredentials;
+ if (request.url().protocolIsInHTTPFamily()) {
+ m_startTime = MonotonicTime::now();
+ auto url = request.url();
+ if (m_storedCredentialsPolicy == StoredCredentialsPolicy::Use) {
+ m_user = url.user();
+ m_password = url.pass();
+ request.removeCredentials();
+ }
+ }
+ createRequest(WTFMove(request));
+}
+
+NetworkDataTaskHaiku::~NetworkDataTaskHaiku()
+{
+ cancel();
+ if (m_request)
+ m_request->SetListener(NULL);
+ delete m_request;
+}
+
+void NetworkDataTaskHaiku::createRequest(ResourceRequest&& request)
+{
+ m_currentRequest = WTFMove(request);
+ m_request = m_currentRequest.toNetworkRequest(nullptr);
+
+ BString method = BString(m_currentRequest.httpMethod());
+
+ m_postData = NULL;
+
+ if (m_request == NULL)
+ return;
+
+ m_baseUrl = URL(m_request->Url());
+
+ BHttpRequest* httpRequest = dynamic_cast(m_request);
+ if(httpRequest) {
+
+ if(method == B_HTTP_POST || method == B_HTTP_PUT) {
+ FormData* form = m_currentRequest.httpBody();
+ if(form) {
+ m_postData = new BFormDataIO(form);
+ httpRequest->AdoptInputData(m_postData, m_postData->Size());
+ }
+ }
+
+ httpRequest->SetMethod(method.String());
+ }
+
+ if(this->SynchronousListener()){
+ m_request->SetListener(this->SynchronousListener());
+ } else {
+ m_request->SetListener(this);
+ }
+
+ if (m_request->Run() < B_OK)
+ {
+ if (!m_client)
+ return;
+
+ ResourceError error("BUrlProtocol", 42,
+ m_baseUrl,
+ "The service kit failed to start the request.");
+
+ m_networkLoadMetrics.responseEnd = MonotonicTime::now() - m_startTime;
+ m_networkLoadMetrics.markComplete();
+ m_client->didCompleteWithError(error,m_networkLoadMetrics);
+ }
+}
+
+void NetworkDataTaskHaiku::cancel()
+{
+ if(m_state == State::Canceling || m_state == State::Completed)
+ return;
+
+ m_state = State::Canceling;
+
+ if(m_request)
+ m_request->Stop();
+
+}
+
+void NetworkDataTaskHaiku::resume()
+{
+ if(m_state == State::Completed || m_state == State::Canceling)
+ return;
+
+ m_state = State::Running;
+
+ if(m_request)
+ m_request->Resume();
+}
+
+void NetworkDataTaskHaiku::invalidateAndCancel()
+{
+}
+
+NetworkDataTask::State NetworkDataTaskHaiku::state() const
+{
+ return m_state;
+}
+
+void NetworkDataTaskHaiku::ConnectionOpened(BUrlRequest*)
+{
+ m_responseDataSent = false;
+}
+void NetworkDataTaskHaiku::HeadersReceived(BUrlRequest* caller, const BUrlResult& result)
+{
+ if (m_currentRequest.isNull())
+ return;
+
+ const BHttpResult* httpResult = dynamic_cast(&result);
+
+ WTF::String contentType = result.ContentType();
+ int contentLength = result.Length();
+ URL url;
+
+ WTF::String encoding = extractCharsetFromMediaType(contentType);
+ WTF::String mimeType = extractMIMETypeFromMediaType(contentType);
+
+ if (httpResult) {
+ url = URL(httpResult->Url());
+
+ BString location = httpResult->Headers()["Location"];
+ if (location.Length() > 0) {
+ m_redirected = true;
+ url = URL(url, location);
+ } else {
+ m_redirected = false;
+ }
+ } else {
+ url = m_baseUrl;
+ }
+
+ ResourceResponse response(url, mimeType, contentLength, encoding);
+
+ if (httpResult) {
+ int statusCode = httpResult->StatusCode();
+
+ String suggestedFilename = filenameFromHTTPContentDisposition(
+ httpResult->Headers()["Content-Disposition"]);
+
+ if (!suggestedFilename.isEmpty())
+ response.setSuggestedFilename(suggestedFilename);
+
+ response.setHTTPStatusCode(statusCode);
+ response.setHTTPStatusText(httpResult->StatusText());
+
+ // Add remaining headers.
+ const BHttpHeaders& resultHeaders = httpResult->Headers();
+ for (int i = 0; i < resultHeaders.CountHeaders(); i++) {
+ BHttpHeader& headerPair = resultHeaders.HeaderAt(i);
+ response.setHTTPHeaderField(headerPair.Name(), headerPair.Value());
+ }
+
+ if (statusCode == 401) {
+
+ //TODO
+
+ //AuthenticationNeeded((BHttpRequest*)m_request, response);
+ // AuthenticationNeeded may have aborted the request
+ // so we need to make sure we can continue.
+
+ if (m_currentRequest.isNull())
+ return;
+ }
+ }
+
+ if (!m_client)
+ return;
+
+ if (m_redirected) {
+ m_redirectionTries--;
+
+ if (m_redirectionTries == 0) {
+ ResourceError error(url.host().utf8().data(), 400, url,
+ "Redirection limit reached");
+
+ m_networkLoadMetrics.responseEnd = MonotonicTime::now() - m_startTime;
+ m_networkLoadMetrics.markComplete();
+ m_client->didCompleteWithError(error,m_networkLoadMetrics);
+ return;
+ }
+
+ // Notify the client that we are redirecting.
+ ResourceRequest request = m_currentRequest;
+ ResourceResponse responseCopy = response;
+ request.setURL(url);
+ m_client->willPerformHTTPRedirection(WTFMove(responseCopy),WTFMove(request), [this](const ResourceRequest& newRequest){
+
+ if(newRequest.isNull() || m_state == State::Canceling)
+ return;
+
+ m_startTime = MonotonicTime::now();//network metrics
+
+ if( m_state != State::Suspended ){
+ m_state = State::Suspended;
+ resume();
+ }
+ });
+
+ } else {
+ ResourceResponse responseCopy = response;
+ m_client->didReceiveResponse(WTFMove(responseCopy),[this](WebCore::PolicyAction policyAction){
+ if(m_state == State::Canceling || m_state == State::Completed){
+ return;
+ }
+ });
+ }
+}
+void NetworkDataTaskHaiku::DataReceived(BUrlRequest* caller, const char* data, off_t position,
+ ssize_t size)
+{
+ if (m_currentRequest.isNull())
+ return;
+
+ if (!m_client)
+ return;
+
+ // don't emit the "Document has moved here" type of HTML
+ if (m_redirected)
+ return;
+
+ if (position != m_position)
+ {
+ debugger("bad redirect");
+ return;
+ }
+
+ if (size > 0) {
+ m_responseDataSent = true;
+ runOnMainThread([this,data=data,size=size]{
+ m_client->didReceiveData(SharedBuffer::create(data,size));
+ });
+ }
+
+ m_position += size;
+}
+void NetworkDataTaskHaiku::UploadProgress(BUrlRequest* caller, ssize_t bytesSent, ssize_t bytesTotal)
+{
+}
+void NetworkDataTaskHaiku::RequestCompleted(BUrlRequest* caller, bool success)
+{
+}
+bool NetworkDataTaskHaiku::CertificateVerificationFailed(BUrlRequest* caller, BCertificate& certificate, const char* message)
+{
+ //TODO
+ return true;
+}
+void NetworkDataTaskHaiku::DebugMessage(BUrlRequest* caller,BUrlProtocolDebugMessage type,const char* text)
+{
+ int8 color;
+ switch(type)
+ {
+ case B_URL_PROTOCOL_DEBUG_TEXT:
+ case B_URL_PROTOCOL_DEBUG_HEADER_IN:
+ case B_URL_PROTOCOL_DEBUG_TRANSFER_IN:
+ color = DC_GREEN;
+ break;
+ case B_URL_PROTOCOL_DEBUG_HEADER_OUT:
+ case B_URL_PROTOCOL_DEBUG_TRANSFER_OUT:
+ color = DC_BLUE;
+ break;
+ case B_URL_PROTOCOL_DEBUG_ERROR:
+ color = DC_RED;
+ }
+ BeDC dc("network-request",type);
+ dc.SendMessage((char*)text);
+}
+void NetworkDataTaskHaiku::runOnMainThread(Function&& task)
+{
+ if(isMainThread())
+ task();
+ else
+ callOnMainThreadAndWait(WTFMove(task));
+}
+}
diff --git a/Source/WebKit/NetworkProcess/haiku/NetworkDataTaskHaiku.h b/Source/WebKit/NetworkProcess/haiku/NetworkDataTaskHaiku.h
new file mode 100644
index 000000000000..599d487fa19d
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/haiku/NetworkDataTaskHaiku.h
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2019 Haiku, Inc.
+ *
+ * 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
+
+#include "config.h"
+#include "NetworkDataTask.h"
+
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+
+namespace WebKit {
+using namespace WebCore;
+
+class NetworkDataTaskHaiku final : public NetworkDataTask
+ ,public BUrlProtocolAsynchronousListener
+{
+public:
+ static Ref create(NetworkSession& session, NetworkDataTaskClient& client, const WebCore::ResourceRequest& request, WebCore::StoredCredentialsPolicy storedCredentialsPolicy, WebCore::ContentSniffingPolicy shouldContentSniff, WebCore::ContentEncodingSniffingPolicy shouldContentEncodingSniff,
+ bool shouldClearReferrerOnHTTPSToHTTPRedirect, bool dataTaskIsForMainFrameNavigation)
+ {
+ return adoptRef(*new NetworkDataTaskHaiku(session, client, request, storedCredentialsPolicy, shouldContentSniff, shouldContentEncodingSniff, shouldClearReferrerOnHTTPSToHTTPRedirect, dataTaskIsForMainFrameNavigation));
+ }
+
+ ~NetworkDataTaskHaiku();
+private:
+ NetworkDataTaskHaiku(NetworkSession&, NetworkDataTaskClient&, const WebCore::ResourceRequest&, WebCore::StoredCredentialsPolicy, WebCore::ContentSniffingPolicy, WebCore::ContentEncodingSniffingPolicy, bool shouldClearReferrerOnHTTPSToHTTPRedirect, bool dataTaskIsForMainFrameNavigation);
+ void createRequest(WebCore::ResourceRequest&&);
+ State m_state{State::Suspended};
+ void cancel() override;
+ void resume() override;
+ void invalidateAndCancel() override;
+ NetworkDataTask::State state() const override;
+
+ void runOnMainThread(Function&&);
+
+ void ConnectionOpened(BUrlRequest* caller) override;
+ void HeadersReceived(BUrlRequest* caller, const BUrlResult& result) override;
+ void DataReceived(BUrlRequest* caller, const char* data, off_t position,
+ ssize_t size) override;
+ void UploadProgress(BUrlRequest* caller, ssize_t bytesSent, ssize_t bytesTotal) override;
+ void RequestCompleted(BUrlRequest* caller, bool success) override;
+ bool CertificateVerificationFailed(BUrlRequest* caller, BCertificate& certificate, const char* message) override;
+ void DebugMessage(BUrlRequest* caller,BUrlProtocolDebugMessage type,const char* text) override;
+
+ WebCore::ResourceResponse m_response;
+ WebCore::ResourceRequest m_currentRequest;
+ WebCore::NetworkLoadMetrics m_networkLoadMetrics;
+ unsigned m_redirectCount { 0 };
+ unsigned m_authFailureCount { 0 };
+ MonotonicTime m_startTime;
+ BUrlRequest* m_request;
+ BFormDataIO* m_postData;
+ URL m_baseUrl;
+ bool m_responseDataSent;
+ bool m_redirected;
+ off_t m_position;
+
+ int m_redirectionTries;
+};
+}
diff --git a/Source/WebKit/NetworkProcess/haiku/NetworkProcessHaiku.cpp b/Source/WebKit/NetworkProcess/haiku/NetworkProcessHaiku.cpp
new file mode 100644
index 000000000000..41278379e0fc
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/haiku/NetworkProcessHaiku.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2019 Haiku, Inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "NetworkProcess.h"
+
+#include "NetworkProcessCreationParameters.h"
+#include
+#include
+
+#include "NetworkConnectionToWebProcess.h"
+#include "NetworkProcessProxyMessages.h"
+#include
+#include
+
+namespace WebCore
+{
+ class NetworkStorageSession;
+}
+
+namespace WebKit {
+
+using namespace WebCore;
+
+void NetworkProcess::platformInitializeNetworkProcess(const NetworkProcessCreationParameters& parameters)
+{
+ notImplemented();
+}
+
+void NetworkProcess::allowSpecificHTTPSCertificateForHost(const CertificateInfo& certificateInfo, const String& host)
+{
+ notImplemented();
+}
+
+std::unique_ptr NetworkProcess::platformCreateDefaultStorageSession() const
+{
+ return std::make_unique(PAL::SessionID::defaultSessionID());
+}
+
+void NetworkProcess::platformProcessDidTransitionToForeground()
+{
+ notImplemented();
+}
+
+void NetworkProcess::platformProcessDidTransitionToBackground()
+{
+ notImplemented();
+}
+
+void NetworkProcess::clearCacheForAllOrigins(uint32_t cachesToClear)
+{
+ notImplemented();
+}
+
+void NetworkProcess::platformProcessDidResume()
+{
+ notImplemented();
+}
+
+void NetworkProcess::platformTerminate()
+{
+ notImplemented();
+}
+
+void NetworkProcess::platformPrepareToSuspend(CompletionHandler&& completionHandler)
+{
+ notImplemented();
+ completionHandler();
+}
+
+void NetworkProcess::clearDiskCache(WallTime modifiedSince, CompletionHandler&& completionHandler)
+{
+ notImplemented();
+}
+
+void NetworkProcess::createNetworkConnectionToWebProcessHaiku(bool isServiceWorkerProcess, WebCore::RegistrableDomain&& registrableDomain,int64_t webPID)
+{
+ team_id webID = (team_id)webPID;
+ uint32_t connectionRandkey = (uint32_t)find_thread(NULL);
+ BString key;
+ key.SetToFormat("%u",connectionRandkey);
+
+ /* Network Process uses current thread id as key for workqueue identification and shares its pid and key to webprocess
+ So a connection can be established*/
+ auto connection = NetworkConnectionToWebProcess::create(*this,{webID,key});
+ m_webProcessConnections.append(WTFMove(connection));
+
+ IPC::Attachment clientConnector(getpid(),connectionRandkey);
+ parentProcessConnection()->send(Messages::NetworkProcessProxy::DidCreateNetworkConnectionToWebProcess(clientConnector), 0);
+ createNetworkConnectionToWebProcess(isServiceWorkerProcess,std::move(registrableDomain));
+}
+
+
+} // namespace WebKit
diff --git a/Source/WebKit/NetworkProcess/haiku/NetworkProcessMainHaiku.cpp b/Source/WebKit/NetworkProcess/haiku/NetworkProcessMainHaiku.cpp
new file mode 100644
index 000000000000..cdb8c985e835
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/haiku/NetworkProcessMainHaiku.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 Haiku, Inc.
+ *
+ * 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 THE COPYRIGHT HOLDERS ``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.
+ */
+
+#include "config.h"
+#include "NetworkProcessMainUnix.h"
+
+#include "AuxiliaryProcessMainHaiku.h"
+#include "NetworkProcess.h"
+#include
+
+namespace WebKit {
+class NetworkProcessMainBase: public AuxiliaryProcessMainBase
+{
+ public:
+ ProcessApp* app = nullptr;
+ bool platformInitialize(char* sign) override
+ {
+ app = new ProcessApp(sign);
+ return true;
+ }
+ void runApp()
+ {
+ app->Run();
+ }
+};
+template<>
+void initializeAuxiliaryProcess(AuxiliaryProcessInitializationParameters&& parameters)
+{
+ static NeverDestroyed networkProcess(WTFMove(parameters));
+}
+
+int NetworkProcessMainUnix(int argc, char** argv)
+{
+ return AuxiliaryProcessMain(argc, argv);
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit/NetworkProcess/haiku/NetworkSessionHaiku.cpp b/Source/WebKit/NetworkProcess/haiku/NetworkSessionHaiku.cpp
new file mode 100644
index 000000000000..0797da7fe2cb
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/haiku/NetworkSessionHaiku.cpp
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2019 Haiku, Inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "NetworkSessionHaiku.h"
+
+#include "NetworkProcess.h"
+#include "NetworkSessionCreationParameters.h"
+#include "WebCookieManager.h"
+#include
+
+namespace WebKit {
+
+using namespace WebCore;
+
+NetworkSessionHaiku::NetworkSessionHaiku(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
+ : NetworkSession(networkProcess, parameters.sessionID, parameters.localStorageDirectory, parameters.localStorageDirectoryExtensionHandle)
+{
+ notImplemented();
+}
+
+NetworkSessionHaiku::~NetworkSessionHaiku()
+{
+
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit/NetworkProcess/haiku/NetworkSessionHaiku.h b/Source/WebKit/NetworkProcess/haiku/NetworkSessionHaiku.h
new file mode 100644
index 000000000000..b83ad078b7b5
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/haiku/NetworkSessionHaiku.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ * Copyright (C) 2019 Haiku, Inc.
+ *
+ * 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
+
+#include "NetworkSession.h"
+
+namespace WebKit {
+
+struct NetworkSessionCreationParameters;
+
+class NetworkSessionHaiku final : public NetworkSession {
+public:
+ static Ref create(NetworkProcess& networkProcess, NetworkSessionCreationParameters&& parameters)
+ {
+ return adoptRef(*new NetworkSessionHaiku(networkProcess, WTFMove(parameters)));
+ }
+ ~NetworkSessionHaiku();
+
+private:
+ NetworkSessionHaiku(NetworkProcess&, NetworkSessionCreationParameters&&);
+};
+
+} // namespace WebKit
diff --git a/Source/WebKit/NetworkProcess/haiku/RemoteNetworkingContextHaiku.cpp b/Source/WebKit/NetworkProcess/haiku/RemoteNetworkingContextHaiku.cpp
new file mode 100644
index 000000000000..82d556271b8a
--- /dev/null
+++ b/Source/WebKit/NetworkProcess/haiku/RemoteNetworkingContextHaiku.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2019 Haiku, Inc.
+ *
+ * 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.
+ */
+
+#include "config.h"
+#include "RemoteNetworkingContext.h"
+
+#include "NetworkProcess.h"
+#include "NetworkSession.h"
+#include "WebsiteDataStoreParameters.h"
+#include
+
+namespace WebKit {
+
+using namespace WebCore;
+
+void RemoteNetworkingContext::ensureWebsiteDataStoreSession(NetworkProcess& networkProcess, WebsiteDataStoreParameters&& parameters)
+{
+ auto sessionID = parameters.networkSessionParameters.sessionID;
+ if (networkProcess.storageSession(sessionID))
+ return;
+
+ networkProcess.ensureSession(sessionID, String::number(sessionID.sessionID()));
+ networkProcess.setSession(sessionID, NetworkSession::create(networkProcess, WTFMove(parameters.networkSessionParameters)));
+}
+
+}
diff --git a/Source/WebKit/Platform/IPC/ArgumentCoder.h b/Source/WebKit/Platform/IPC/ArgumentCoder.h
index 1bbaf101eb8f..8668a2ed0c58 100644
--- a/Source/WebKit/Platform/IPC/ArgumentCoder.h
+++ b/Source/WebKit/Platform/IPC/ArgumentCoder.h
@@ -34,6 +34,10 @@ class ResourceResponse;
struct ViewportArguments;
}
+namespace WebKit {
+ struct PidWrapper;
+};
+
namespace IPC {
class Decoder;
@@ -84,6 +88,7 @@ class DefaultDecoderValues {
};
// ResourceResponseBase has the legacy decode template, not ResourceResponse.
+template<> class UsesModernDecoder : public DefaultDecoderValues { };
template<> class UsesModernDecoder : public DefaultDecoderValues { };
template<> class UsesLegacyDecoder : public DefaultDecoderValues { };
diff --git a/Source/WebKit/Platform/IPC/Attachment.cpp b/Source/WebKit/Platform/IPC/Attachment.cpp
index 95ae710b139e..474b8a022962 100644
--- a/Source/WebKit/Platform/IPC/Attachment.cpp
+++ b/Source/WebKit/Platform/IPC/Attachment.cpp
@@ -50,7 +50,7 @@ void Attachment::release()
}
#endif
-#if !OS(WINDOWS)
+#if !OS(WINDOWS) && !PLATFORM(HAIKU)
void Attachment::encode(Encoder& encoder) const
{
encoder.addAttachment(WTFMove(*const_cast(this)));
diff --git a/Source/WebKit/Platform/IPC/Attachment.h b/Source/WebKit/Platform/IPC/Attachment.h
index 7f3b413c8461..9d2a30111586 100644
--- a/Source/WebKit/Platform/IPC/Attachment.h
+++ b/Source/WebKit/Platform/IPC/Attachment.h
@@ -35,6 +35,10 @@
#include
#endif
+#if PLATFORM(HAIKU)
+#include
+#include
+#endif
namespace IPC {
class Decoder;
@@ -66,6 +70,12 @@ class Attachment {
Attachment(HANDLE handle)
: m_handle(handle)
{ }
+#elif PLATFORM(HAIKU)
+ Attachment(team_id connectionInfo,uint32_t key)
+ : m_connectionID(connectionInfo),
+ m_key(key)
+ {
+ }
#endif
Type type() const { return m_type; }
@@ -83,6 +93,9 @@ class Attachment {
mach_msg_type_name_t disposition() const { return m_disposition; }
#elif OS(WINDOWS)
HANDLE handle() const { return m_handle; }
+#elif PLATFORM(HAIKU)
+ team_id connectionID () const { return m_connectionID; }
+ uint32_t key () const { return m_key; }
#endif
void encode(Encoder&) const;
@@ -99,6 +112,9 @@ class Attachment {
mach_msg_type_name_t m_disposition;
#elif OS(WINDOWS)
HANDLE m_handle { INVALID_HANDLE_VALUE };
+#elif PLATFORM(HAIKU)
+ team_id m_connectionID;
+ uint32_t m_key;
#endif
};
diff --git a/Source/WebKit/Platform/IPC/Connection.cpp b/Source/WebKit/Platform/IPC/Connection.cpp
index 361f8619d23c..f81061fba44e 100644
--- a/Source/WebKit/Platform/IPC/Connection.cpp
+++ b/Source/WebKit/Platform/IPC/Connection.cpp
@@ -586,12 +586,12 @@ std::unique_ptr Connection::waitForSyncReply(uint64_t syncRequestID, Se
WallTime absoluteTime = WallTime::now() + timeout;
willSendSyncMessage(sendSyncOptions);
-
+
bool timedOut = false;
while (!timedOut) {
// First, check if we have any messages that we need to process.
SyncMessageState::singleton().dispatchMessages(nullptr);
-
+
{
LockHolder locker(m_syncReplyStateMutex);
@@ -622,6 +622,7 @@ std::unique_ptr Connection::waitForSyncReply(uint64_t syncRequestID, Se
// This allows the WebProcess to still serve clients while waiting for the message to return.
// Notably, it can continue to process accessibility requests, which are on the main thread.
timedOut = !SyncMessageState::singleton().wait(absoluteTime);
+
}
RELEASE_LOG_ERROR(IPC, "Connection::waitForSyncReply: Timed-out while waiting for reply, id = %" PRIu64, syncRequestID);
diff --git a/Source/WebKit/Platform/IPC/Connection.h b/Source/WebKit/Platform/IPC/Connection.h
index 3edf82adf3b5..f4c1bc2d73c8 100644
--- a/Source/WebKit/Platform/IPC/Connection.h
+++ b/Source/WebKit/Platform/IPC/Connection.h
@@ -55,6 +55,12 @@
#include "GSocketMonitor.h"
#endif
+#if PLATFORM(HAIKU)
+#include
+#include
+#include
+#endif
+
namespace IPC {
enum class SendOption {
@@ -147,6 +153,17 @@ class Connection : public ThreadSafeRefCounted createServerConnection(Identifier, Client&);
@@ -432,6 +449,15 @@ class Connection : public ThreadSafeRefCounted m_pendingWriteEncoder;
EventListener m_writeListener;
HANDLE m_connectionPipe { INVALID_HANDLE_VALUE };
+#elif PLATFORM(HAIKU)
+ Identifier m_connectedProcess;
+ BHandler* m_readHandler;
+ BMessenger m_messenger;
+ BMessenger targetMessenger;
+ void runReadEventLoop();
+ void runWriteEventLoop();
+ Vector m_readBuffer;
+ std::unique_ptr m_pendingWriteEncoder;
#endif
};
@@ -523,12 +549,10 @@ template bool Connection::sendSync(T&& message, typename T::Reply&&
// Encode the rest of the input arguments.
encoder->encode(message.arguments());
-
// Now send the message and wait for a reply.
std::unique_ptr replyDecoder = sendSyncMessage(syncRequestID, WTFMove(encoder), timeout, sendSyncOptions);
if (!replyDecoder)
return false;
-
// Decode the reply.
Optional replyArguments;
*replyDecoder >> replyArguments;
diff --git a/Source/WebKit/Platform/IPC/Decoder.cpp b/Source/WebKit/Platform/IPC/Decoder.cpp
index 154c3d9da901..55b958c902ee 100644
--- a/Source/WebKit/Platform/IPC/Decoder.cpp
+++ b/Source/WebKit/Platform/IPC/Decoder.cpp
@@ -341,10 +341,10 @@ bool Decoder::decode(double& result)
}
bool Decoder::removeAttachment(Attachment& attachment)
-{
+{fprintf(stderr,"\n%s\n",__PRETTY_FUNCTION__);
if (m_attachments.isEmpty())
return false;
-
+fprintf(stderr,"\n%s\n",__PRETTY_FUNCTION__);
attachment = m_attachments.takeLast();
return true;
}
diff --git a/Source/WebKit/Platform/IPC/Encoder.cpp b/Source/WebKit/Platform/IPC/Encoder.cpp
index b586162eab44..8a439882dd5c 100644
--- a/Source/WebKit/Platform/IPC/Encoder.cpp
+++ b/Source/WebKit/Platform/IPC/Encoder.cpp
@@ -30,7 +30,7 @@
#include "MessageFlags.h"
#include
#include
-
+#include
#if OS(DARWIN)
#include
#endif
diff --git a/Source/WebKit/Platform/IPC/haiku/AttachmentHaiku.cpp b/Source/WebKit/Platform/IPC/haiku/AttachmentHaiku.cpp
new file mode 100644
index 000000000000..377cc0ec545e
--- /dev/null
+++ b/Source/WebKit/Platform/IPC/haiku/AttachmentHaiku.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2019 Haiku, 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.
+ */
+
+#include "config.h"
+#include "Attachment.h"
+
+#include "Decoder.h"
+#include "Encoder.h"
+#include
+
+namespace IPC {
+
+void Attachment::encode(Encoder& encoder) const
+{
+ //int encoding is easier
+ encoder << (int64_t)m_connectionID;
+ encoder << m_key;
+}
+
+bool Attachment::decode(Decoder& decoder, Attachment& attachment)
+{
+
+ int64_t sourceID;
+ if (!decoder.decode(sourceID))
+ return false;
+
+ uint32_t sourceKey;
+ if (!decoder.decode(sourceKey))
+ return false;
+
+ attachment.m_connectionID = (team_id)sourceID;
+ attachment.m_key = sourceKey;
+ return true;
+}
+
+} // namespace IPC
diff --git a/Source/WebKit/Platform/IPC/haiku/ConnectionHaiku.cpp b/Source/WebKit/Platform/IPC/haiku/ConnectionHaiku.cpp
new file mode 100644
index 000000000000..65a6308b4451
--- /dev/null
+++ b/Source/WebKit/Platform/IPC/haiku/ConnectionHaiku.cpp
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2019 Haiku, 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.
+ */
+#include "config.h"
+#include "Connection.h"
+
+#include
+#include
+#include
+#include
+namespace IPC{
+ class ReadLoop: public BHandler
+ {
+ public:
+ ReadLoop(IPC::Connection* con)
+ :BHandler("Read Message Loop"),
+ connection(con)
+ {
+ }
+ void MessageReceived(BMessage* message)
+ {
+
+ switch(message->what)
+ {
+ case 'ipcm':
+ connection->prepareIncomingMessage(message);
+ break;
+ case 'inig':
+ connection->finalizeConnection(message);
+ break;
+ default:
+ BHandler::MessageReceived(message);
+
+ }
+ }
+ private:
+ IPC::Connection* connection;
+
+ };
+ void Connection::finalizeConnection(BMessage* message)
+ {
+ //unwrap the message
+ status_t result = message->FindMessenger("target",&targetMessenger);
+ if(result == B_OK)
+ m_isConnected = true;
+
+ m_connectionQueue->dispatch([protectedThis = makeRef(*this)]() mutable {
+ protectedThis->sendOutgoingMessages();
+ });
+ }
+ void Connection::platformInitialize(Identifier identifier)
+ {
+ m_connectedProcess = identifier;
+ }
+ void Connection::platformInvalidate()
+ {
+
+ }
+ void Connection::prepareIncomingMessage(BMessage* message)
+ {
+ size_t size;
+ const uint8_t* Buffer;
+ status_t result;
+
+ result = message->FindData("bufferData",B_ANY_TYPE,(const void**)&Buffer,(ssize_t*)&size);
+
+ if(result == B_OK)
+ {
+ Vector attachments(0);
+ auto decoder = std::make_unique(Buffer,size,nullptr,WTFMove(attachments));
+ processIncomingMessage(WTFMove(decoder));
+ }
+ else
+ {
+ //return
+ }
+ }
+ void Connection::runReadEventLoop()
+ {
+ status_t result;
+ BLooper* looper = m_connectionQueue->runLoop().runLoopLooper();
+
+ looper->Lock();
+ looper->AddHandler(m_readHandler);
+ looper->SetPreferredHandler(m_readHandler);
+ looper->Unlock();
+ /*
+ notify the mainloop about our workqueue
+ */
+ BMessage init('inil');
+ init.AddString("identifier",m_connectedProcess.key.String());
+ init.AddPointer("looper",(const void*)looper);
+ BMessenger hostProcess(NULL,getpid());
+ result = hostProcess.SendMessage(&init);
+ /*
+ notify the other process about our workqueue
+ */
+ BMessenger target(looper->PreferredHandler(),looper,&result);
+ BMessage inig('inig');
+ inig.AddString("identifier",m_connectedProcess.key.String());
+ inig.AddMessenger("target",target);
+ BMessage reply;
+ m_messenger.SendMessage(&inig);
+ //sent to the other process
+ }
+ void Connection::runWriteEventLoop()
+ {
+ // write the pending encoding but do we need this will messaging fail
+ //probably when the message queue is full
+ }
+ bool Connection::open()
+ {
+ status_t result = m_messenger.SetTo(NULL,m_connectedProcess.connectedProcess);
+ m_readHandler = new ReadLoop(this);
+ m_connectionQueue->dispatch([this,protectedThis = makeRef(*this)]{
+ this->runReadEventLoop();
+ });
+ return true;
+ }
+ bool Connection::platformCanSendOutgoingMessages() const
+ {
+ return true;
+ }
+ bool Connection::sendOutgoingMessage(std::unique_ptr encoder)
+ {
+ BMessage processMessage('ipcm');
+ processMessage.AddString("identifier",m_connectedProcess.key.String());
+ const uint8_t* Buffer= encoder->buffer();
+ status_t result = processMessage.AddData("bufferData",B_ANY_TYPE,(void*)Buffer,encoder->bufferSize());
+ //
+ processMessage.AddInt32("sender",getpid());
+ result = targetMessenger.SendMessage(&processMessage);
+
+ if(result == B_OK)
+ return true;
+ else
+ {
+ m_pendingWriteEncoder = WTFMove(encoder);
+ return false;
+ }
+ }
+ void Connection::willSendSyncMessage(OptionSet )
+ {
+
+ }
+ void Connection::didReceiveSyncReply(OptionSet )
+ {
+
+ }
+}
diff --git a/Source/WebKit/Platform/Module.h b/Source/WebKit/Platform/Module.h
index 441cddd713e0..3b6c4ce64a65 100644
--- a/Source/WebKit/Platform/Module.h
+++ b/Source/WebKit/Platform/Module.h
@@ -37,6 +37,10 @@
typedef struct _GModule GModule;
#endif
+#if PLATFORM(HAIKU)
+#include
+#endif
+
#if OS(WINDOWS)
#include