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

namespace WebKit {

	using System;
	using System.Collections;
	using System.Collections.Generic;
	using System.Runtime.InteropServices;
	using static GLib.AbiStructExtension;

#region Autogenerated code
	public partial class FaviconDatabase : GLib.Object {

		public FaviconDatabase (IntPtr raw) : base(raw) {}

		protected FaviconDatabase() : base(IntPtr.Zero)
		{
			CreateNativeObject (Array.Empty<string> (), Array.Empty<GLib.Value> ());
		}

		[GLib.Signal("favicon-changed")]
		public event WebKit.FaviconChangedHandler FaviconChanged {
			add {
				this.AddSignalHandler ("favicon-changed", value, typeof (WebKit.FaviconChangedArgs));
			}
			remove {
				this.RemoveSignalHandler ("favicon-changed", value);
			}
		}

		static FaviconChangedNativeDelegate FaviconChanged_cb_delegate;
		static FaviconChangedNativeDelegate FaviconChangedVMCallback {
			get {
				if (FaviconChanged_cb_delegate == null)
					FaviconChanged_cb_delegate = new FaviconChangedNativeDelegate (FaviconChanged_cb);
				return FaviconChanged_cb_delegate;
			}
		}

		static void OverrideFaviconChanged (GLib.GType gtype)
		{
			OverrideFaviconChanged (gtype, FaviconChangedVMCallback);
		}

		static void OverrideFaviconChanged (GLib.GType gtype, FaviconChangedNativeDelegate callback)
		{
			OverrideVirtualMethod (gtype, "favicon-changed", callback);
		}
		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void FaviconChangedNativeDelegate (IntPtr inst, IntPtr page_uri, IntPtr favicon_uri);

		static void FaviconChanged_cb (IntPtr inst, IntPtr page_uri, IntPtr favicon_uri)
		{
			try {
				FaviconDatabase __obj = GLib.Object.GetObject (inst, false) as FaviconDatabase;
				__obj.OnFaviconChanged (GLib.Marshaller.Utf8PtrToString (page_uri), GLib.Marshaller.Utf8PtrToString (favicon_uri));
			} catch (Exception e) {
				GLib.ExceptionManager.RaiseUnhandledException (e, false);
			}
		}

		[GLib.DefaultSignalHandler(Type=typeof(WebKit.FaviconDatabase), ConnectionMethod="OverrideFaviconChanged")]
		protected virtual void OnFaviconChanged (string page_uri, string favicon_uri)
		{
			InternalFaviconChanged (page_uri, favicon_uri);
		}

		private void InternalFaviconChanged (string page_uri, string favicon_uri)
		{
			GLib.Value ret = GLib.Value.Empty;
			GLib.ValueArray inst_and_params = new GLib.ValueArray (3);
			GLib.Value[] vals = new GLib.Value [3];
			vals [0] = new GLib.Value (this);
			inst_and_params.Append (vals [0]);
			vals [1] = new GLib.Value (page_uri);
			inst_and_params.Append (vals [1]);
			vals [2] = new GLib.Value (favicon_uri);
			inst_and_params.Append (vals [2]);
			g_signal_chain_from_overridden (inst_and_params.ArrayPtr, ref ret);
			foreach (GLib.Value v in vals)
				v.Dispose ();
		}


		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _class_abi = null;
		static public unsafe new GLib.AbiStruct class_abi {
			get {
				if (_class_abi == null)
					_class_abi = new GLib.AbiStruct (new List<GLib.AbiField>{ 
						new GLib.AbiField("_webkit_reserved0"
							, GLib.Object.class_abi.Fields
							, (uint) sizeof( IntPtr ) // _webkit_reserved0
							, null
							, "_webkit_reserved1"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_webkit_reserved1"
							, -1
							, (uint) sizeof( IntPtr ) // _webkit_reserved1
							, "_webkit_reserved0"
							, "_webkit_reserved2"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_webkit_reserved2"
							, -1
							, (uint) sizeof( IntPtr ) // _webkit_reserved2
							, "_webkit_reserved1"
							, "_webkit_reserved3"
							, (uint) sizeof(IntPtr)
							, 0
							),
						new GLib.AbiField("_webkit_reserved3"
							, -1
							, (uint) sizeof( IntPtr ) // _webkit_reserved3
							, "_webkit_reserved2"
							, null
							, (uint) sizeof(IntPtr)
							, 0
							),
					});

				return _class_abi;
			}
		}


		// End of the ABI representation.

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

		public static new GLib.GType GType { 
			get {
				IntPtr raw_ret = webkit_favicon_database_get_type();
				GLib.GType ret = new GLib.GType(raw_ret);
				return ret;
			}
		}

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

		public void Clear() {
			webkit_favicon_database_clear(Handle);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate void d_webkit_favicon_database_get_favicon(IntPtr raw, IntPtr page_uri, IntPtr cancellable, GLibSharp.AsyncReadyCallbackNative cb, IntPtr user_data);
		static d_webkit_favicon_database_get_favicon webkit_favicon_database_get_favicon = FuncLoader.LoadFunction<d_webkit_favicon_database_get_favicon>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Webkit), "webkit_favicon_database_get_favicon"));

		public void GetFavicon(string page_uri, GLib.Cancellable cancellable, GLib.AsyncReadyCallback cb) {
			IntPtr native_page_uri = GLib.Marshaller.StringToPtrGStrdup (page_uri);
			GLibSharp.AsyncReadyCallbackWrapper cb_wrapper = new GLibSharp.AsyncReadyCallbackWrapper (cb);
			cb_wrapper.PersistUntilCalled ();
			webkit_favicon_database_get_favicon(Handle, native_page_uri, cancellable == null ? IntPtr.Zero : cancellable.Handle, cb_wrapper.NativeDelegate, IntPtr.Zero);
			GLib.Marshaller.Free (native_page_uri);
		}

		public void GetFavicon(string page_uri) {
			GetFavicon (page_uri, null, null);
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_webkit_favicon_database_get_favicon_finish(IntPtr raw, IntPtr _result, out IntPtr error);
		static d_webkit_favicon_database_get_favicon_finish webkit_favicon_database_get_favicon_finish = FuncLoader.LoadFunction<d_webkit_favicon_database_get_favicon_finish>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Webkit), "webkit_favicon_database_get_favicon_finish"));

		public unsafe Cairo.Surface GetFaviconFinish(GLib.IAsyncResult _result) {
			IntPtr error = IntPtr.Zero;
			IntPtr raw_ret = webkit_favicon_database_get_favicon_finish(Handle, _result == null ? IntPtr.Zero : ((_result is GLib.Object) ? (_result as GLib.Object).Handle : (_result as GLib.AsyncResultAdapter).Handle), out error);
			Cairo.Surface ret = Cairo.Surface.Lookup (raw_ret, true);
			if (error != IntPtr.Zero) throw new GLib.GException (error);
			return ret;
		}

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

		public string GetFaviconUri(string page_uri) {
			IntPtr native_page_uri = GLib.Marshaller.StringToPtrGStrdup (page_uri);
			IntPtr raw_ret = webkit_favicon_database_get_favicon_uri(Handle, native_page_uri);
			string ret = GLib.Marshaller.PtrToStringGFree(raw_ret);
			GLib.Marshaller.Free (native_page_uri);
			return ret;
		}


		static FaviconDatabase ()
		{
			GtkSharp.WebkitGtkSharp.ObjectManager.Initialize ();
		}

		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _abi_info = null;
		static public unsafe new GLib.AbiStruct abi_info {
			get {
				if (_abi_info == null)
					_abi_info = new GLib.AbiStruct (new List<GLib.AbiField>{ 
						new GLib.AbiField("priv"
							, GLib.Object.abi_info.Fields
							, (uint) sizeof( IntPtr ) // priv
							, null
							, null
							, (uint) sizeof(IntPtr)
							, 0
							),
					});

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}
