// This file was generated by the Gtk# code generator.
// Any changes made will be lost if regenerated.

namespace WebKit {

	using System;
	using System.Runtime.InteropServices;

#region Autogenerated code
	public partial class PermissionRequestAdapter : GLib.GInterfaceAdapter, WebKit.IPermissionRequest {

		[StructLayout (LayoutKind.Sequential)]
		struct WebKitPermissionRequestIface {
			public AllowNativeDelegate Allow;
			public DenyNativeDelegate Deny;
		}

		static WebKitPermissionRequestIface iface;

		static PermissionRequestAdapter ()
		{
			GLib.GType.Register (_gtype, typeof (PermissionRequestAdapter));
			iface.Allow = new AllowNativeDelegate (Allow_cb);
			iface.Deny = new DenyNativeDelegate (Deny_cb);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void AllowNativeDelegate (IntPtr inst);

		static void Allow_cb (IntPtr inst)
		{
			try {
				IPermissionRequestImplementor __obj = GLib.Object.GetObject (inst, false) as IPermissionRequestImplementor;
				__obj.Allow ();
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void DenyNativeDelegate (IntPtr inst);

		static void Deny_cb (IntPtr inst)
		{
			try {
				IPermissionRequestImplementor __obj = GLib.Object.GetObject (inst, false) as IPermissionRequestImplementor;
				__obj.Deny ();
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		static int class_offset = 2 * IntPtr.Size;

		static void Initialize (IntPtr ptr, IntPtr data)
		{
			IntPtr ifaceptr = new IntPtr (ptr.ToInt64 () + class_offset);
			WebKitPermissionRequestIface native_iface = (WebKitPermissionRequestIface) Marshal.PtrToStructure (ifaceptr, typeof (WebKitPermissionRequestIface));
			native_iface.Allow = iface.Allow;
			native_iface.Deny = iface.Deny;
			Marshal.StructureToPtr (native_iface, ifaceptr, false);
		}

		GLib.Object implementor;

		public PermissionRequestAdapter ()
		{
			InitHandler = new GLib.GInterfaceInitHandler (Initialize);
		}

		public PermissionRequestAdapter (IPermissionRequestImplementor implementor)
		{
			if (implementor == null)
				throw new ArgumentNullException ("implementor");
			else if (!(implementor is GLib.Object))
				throw new ArgumentException ("implementor must be a subclass of GLib.Object");
			this.implementor = implementor as GLib.Object;
		}

		public PermissionRequestAdapter (IntPtr handle)
		{
			if (!_gtype.IsInstance (handle))
				throw new ArgumentException ("The gobject doesn't implement the GInterface of this adapter", "handle");
			implementor = GLib.Object.GetObject (handle);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_webkit_permission_request_get_type();
		static d_webkit_permission_request_get_type webkit_permission_request_get_type = FuncLoader.LoadFunction<d_webkit_permission_request_get_type>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Webkit), "webkit_permission_request_get_type"));

		private static GLib.GType _gtype = new GLib.GType (webkit_permission_request_get_type ());

		public static GLib.GType GType {
			get {
				return _gtype;
			}
		}

		public override GLib.GType GInterfaceGType {
			get {
				return _gtype;
			}
		}

		public override IntPtr Handle {
			get {
				return implementor.Handle;
			}
		}

		public IntPtr OwnedHandle {
			get {
				return implementor.OwnedHandle;
			}
		}

		public static IPermissionRequest GetObject (IntPtr handle, bool owned)
		{
			GLib.Object obj = GLib.Object.GetObject (handle, owned);
			return GetObject (obj);
		}

		public static IPermissionRequest GetObject (GLib.Object obj)
		{
			if (obj == null)
				return null;
			else if (obj is IPermissionRequestImplementor)
				return new PermissionRequestAdapter (obj as IPermissionRequestImplementor);
			else if (obj as IPermissionRequest == null)
				return new PermissionRequestAdapter (obj.Handle);
			else
				return obj as IPermissionRequest;
		}

		public IPermissionRequestImplementor Implementor {
			get {
				return implementor as IPermissionRequestImplementor;
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_webkit_permission_request_allow(IntPtr raw);
		static d_webkit_permission_request_allow webkit_permission_request_allow = FuncLoader.LoadFunction<d_webkit_permission_request_allow>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Webkit), "webkit_permission_request_allow"));

		public void Allow() {
			webkit_permission_request_allow(Handle);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_webkit_permission_request_deny(IntPtr raw);
		static d_webkit_permission_request_deny webkit_permission_request_deny = FuncLoader.LoadFunction<d_webkit_permission_request_deny>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Webkit), "webkit_permission_request_deny"));

		public void Deny() {
			webkit_permission_request_deny(Handle);
		}

#endregion
	}
}
