view dstep/foundation/NSURLProtocol.d @ 16:19885b43130e

Huge update, the bridge actually works now
author Jacob Carlborg <doob@me.com>
date Sun, 03 Jan 2010 22:06:11 +0100
parents 89f3c3ef1fd2
children b9de51448c6b
line wrap: on
line source

/**
 * Copyright: Copyright (c) 2009 Jacob Carlborg.
 * Authors: Jacob Carlborg
 * Version: Initial created: Aug 3, 2009 
 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
 */
module dstep.foundation.NSURLProtocol;

import dstep.foundation.NSData;
import dstep.foundation.NSError;
import dstep.foundation.NSObject;
import dstep.foundation.NSString;
import dstep.foundation.NSURLAuthenticationChallenge;
import dstep.foundation.NSURLCache;
import dstep.foundation.NSURLConnection;
import dstep.foundation.NSURLRequest;
import dstep.foundation.NSURLResponse;
import dstep.objc.bridge.Bridge;
import dstep.objc.objc;

class NSURLProtocol : NSObject
{
	mixin (ObjcWrap);
	
	this ()
	{
		super(typeof(this).alloc.init.objcObject);
	}
	
	typeof(this) init ()
	{
		return invokeObjcSelf!(typeof(this), "init");
	}

	Object initWithRequest (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client)
	{
		return invokeObjcSelf!(Object, "initWithRequest:cachedResponse:client:", NSURLRequest, NSCachedURLResponse, INSURLProtocolClient)(request, cachedResponse, client);
	}

	this (NSURLRequest request, NSCachedURLResponse cachedResponse, INSURLProtocolClient client)
	{
		typeof(this).alloc.initWithRequest(request, cachedResponse, client);
	}

	INSURLProtocolClient client ()
	{
		return invokeObjcSelf!(INSURLProtocolClient, "client");
	}

	NSURLRequest request ()
	{
		return invokeObjcSelf!(NSURLRequest, "request");
	}

	NSCachedURLResponse cachedResponse ()
	{
		return invokeObjcSelf!(NSCachedURLResponse, "cachedResponse");
	}

	static bool canInitWithRequest (NSURLRequest request)
	{
		return invokeObjcSuperClass!(bool, "canInitWithRequest:", NSURLRequest)(request);
	}

	static NSURLRequest canonicalRequestForRequest (NSURLRequest request)
	{
		return invokeObjcSuperClass!(NSURLRequest, "canonicalRequestForRequest:", NSURLRequest)(request);
	}

	static bool requestIsCacheEquivalent (NSURLRequest a, NSURLRequest b)
	{
		return invokeObjcSuperClass!(bool, "requestIsCacheEquivalent:toRequest:", NSURLRequest, NSURLRequest)(a, b);
	}

	void startLoading ()
	{
		return invokeObjcSelf!(void, "startLoading");
	}

	void stopLoading ()
	{
		return invokeObjcSelf!(void, "stopLoading");
	}

	static Object propertyForKey (NSString key, NSURLRequest request)
	{
		return invokeObjcSuperClass!(Object, "propertyForKey:inRequest:", NSString, NSURLRequest)(key, request);
	}

	static void setProperty (Object value, NSString key, NSMutableURLRequest request)
	{
		return invokeObjcSuperClass!(void, "setProperty:forKey:inRequest:", Object, NSString, NSMutableURLRequest)(value, key, request);
	}

	static void removePropertyForKey (NSString key, NSMutableURLRequest request)
	{
		return invokeObjcSuperClass!(void, "removePropertyForKey:inRequest:", NSString, NSMutableURLRequest)(key, request);
	}

	static bool registerClass (Class protocolClass)
	{
		return invokeObjcSuperClass!(bool, "registerClass:", Class)(protocolClass);
	}

	static void unregisterClass (Class protocolClass)
	{
		return invokeObjcSuperClass!(void, "unregisterClass:", Class)(protocolClass);
	}
}

interface INSURLProtocolClient : INSObject
{
	void URLProtocol (NSURLProtocol protocol, NSURLRequest request, NSURLResponse redirectResponse);
	void URLProtocol (NSURLProtocol protocol, NSCachedURLResponse cachedResponse);
	void URLProtocol (NSURLProtocol protocol, NSURLResponse response, uint policy);
	void URLProtocol (NSURLProtocol protocol, NSData data);
	void URLProtocolDidFinishLoading (NSURLProtocol protocol);
	void URLProtocol (NSURLProtocol protocol, NSError error);
	void URLProtocol (NSURLProtocol protocol, NSURLAuthenticationChallenge challenge);
	void URLProtocol (NSURLProtocol protocol, NSURLAuthenticationChallenge challenge);
}