LegacyCustomProtocolManager.h [plain text]
#pragma once
#include "MessageReceiver.h"
#include "NetworkProcessSupplement.h"
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/text/StringHash.h>
#include <wtf/text/WTFString.h>
#if PLATFORM(COCOA)
#include <wtf/RetainPtr.h>
OBJC_CLASS NSURLSessionConfiguration;
OBJC_CLASS WKCustomProtocol;
#endif
#if USE(SOUP)
#include <wtf/glib/GRefPtr.h>
typedef struct _GCancellable GCancellable;
typedef struct _GInputStream GInputStream;
typedef struct _GTask GTask;
typedef struct _WebKitSoupRequestGeneric WebKitSoupRequestGeneric;
#endif
namespace IPC {
class DataReference;
}
namespace WebCore {
class ResourceError;
class ResourceRequest;
class ResourceResponse;
}
namespace WebKit {
class ChildProcess;
struct NetworkProcessCreationParameters;
class LegacyCustomProtocolManager : public NetworkProcessSupplement, public IPC::MessageReceiver {
WTF_MAKE_NONCOPYABLE(LegacyCustomProtocolManager);
public:
explicit LegacyCustomProtocolManager(ChildProcess&);
static const char* supplementName();
void registerScheme(const String&);
void unregisterScheme(const String&);
bool supportsScheme(const String&);
#if PLATFORM(COCOA)
typedef RetainPtr<WKCustomProtocol> CustomProtocol;
#endif
#if USE(SOUP)
struct WebSoupRequestAsyncData {
WebSoupRequestAsyncData(GRefPtr<GTask>&&, WebKitSoupRequestGeneric*);
~WebSoupRequestAsyncData();
GRefPtr<GTask> task;
WebKitSoupRequestGeneric* request;
GRefPtr<GCancellable> cancellable;
GRefPtr<GInputStream> stream;
};
typedef std::unique_ptr<WebSoupRequestAsyncData> CustomProtocol;
#endif
uint64_t addCustomProtocol(CustomProtocol&&);
void removeCustomProtocol(uint64_t customProtocolID);
void startLoading(uint64_t customProtocolID, const WebCore::ResourceRequest&);
void stopLoading(uint64_t customProtocolID);
#if PLATFORM(COCOA) && USE(NETWORK_SESSION)
void registerProtocolClass(NSURLSessionConfiguration*);
#endif
private:
void initialize(const NetworkProcessCreationParameters&) override;
void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
void didFailWithError(uint64_t customProtocolID, const WebCore::ResourceError&);
void didLoadData(uint64_t customProtocolID, const IPC::DataReference&);
void didReceiveResponse(uint64_t customProtocolID, const WebCore::ResourceResponse&, uint32_t cacheStoragePolicy);
void didFinishLoading(uint64_t customProtocolID);
void wasRedirectedToRequest(uint64_t customProtocolID, const WebCore::ResourceRequest&, const WebCore::ResourceResponse& redirectResponse);
void registerProtocolClass();
ChildProcess& m_childProcess;
typedef HashMap<uint64_t, CustomProtocol> CustomProtocolMap;
CustomProtocolMap m_customProtocolMap;
Lock m_customProtocolMapMutex;
#if PLATFORM(COCOA)
HashSet<String, ASCIICaseInsensitiveHash> m_registeredSchemes;
Lock m_registeredSchemesMutex;
RetainPtr<WKCustomProtocol> protocolForID(uint64_t customProtocolID);
#endif
#if USE(SOUP)
GRefPtr<GPtrArray> m_registeredSchemes;
#endif
};
}