// 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;

#region Autogenerated code
	public partial class UserScript : GLib.Opaque {

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

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

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

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_webkit_user_script_new(IntPtr source, int injected_frames, int injection_time, IntPtr[] allow_list, IntPtr[] block_list);
		static d_webkit_user_script_new webkit_user_script_new = FuncLoader.LoadFunction<d_webkit_user_script_new>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Webkit), "webkit_user_script_new"));

		public UserScript (string source, WebKit.UserContentInjectedFrames injected_frames, WebKit.UserScriptInjectionTime injection_time, string[] allow_list, string[] block_list) 
		{
			IntPtr native_source = GLib.Marshaller.StringToPtrGStrdup (source);
			int cnt_allow_list = allow_list == null ? 0 : allow_list.Length;
			IntPtr[] native_allow_list = new IntPtr [cnt_allow_list + 1];
			for (int i = 0; i < cnt_allow_list; i++)
				native_allow_list [i] = GLib.Marshaller.StringToPtrGStrdup (allow_list[i]);
			native_allow_list [cnt_allow_list] = IntPtr.Zero;
			int cnt_block_list = block_list == null ? 0 : block_list.Length;
			IntPtr[] native_block_list = new IntPtr [cnt_block_list + 1];
			for (int i = 0; i < cnt_block_list; i++)
				native_block_list [i] = GLib.Marshaller.StringToPtrGStrdup (block_list[i]);
			native_block_list [cnt_block_list] = IntPtr.Zero;
			Raw = webkit_user_script_new(native_source, (int) injected_frames, (int) injection_time, native_allow_list, native_block_list);
			GLib.Marshaller.Free (native_source);
			for (int i = 0; i < native_allow_list.Length - 1; i++) {
				allow_list [i] = GLib.Marshaller.Utf8PtrToString (native_allow_list[i]);
				GLib.Marshaller.Free (native_allow_list[i]);
			}
			for (int i = 0; i < native_block_list.Length - 1; i++) {
				block_list [i] = GLib.Marshaller.Utf8PtrToString (native_block_list[i]);
				GLib.Marshaller.Free (native_block_list[i]);
			}
		}

		[UnmanagedFunctionPointer (CallingConvention.Cdecl)]
		delegate IntPtr d_webkit_user_script_new_for_world(IntPtr source, int injected_frames, int injection_time, IntPtr world_name, IntPtr[] allow_list, IntPtr[] block_list);
		static d_webkit_user_script_new_for_world webkit_user_script_new_for_world = FuncLoader.LoadFunction<d_webkit_user_script_new_for_world>(FuncLoader.GetProcAddress(GLibrary.Load(Library.Webkit), "webkit_user_script_new_for_world"));

		public UserScript (string source, WebKit.UserContentInjectedFrames injected_frames, WebKit.UserScriptInjectionTime injection_time, string world_name, string[] allow_list, string[] block_list) 
		{
			IntPtr native_source = GLib.Marshaller.StringToPtrGStrdup (source);
			IntPtr native_world_name = GLib.Marshaller.StringToPtrGStrdup (world_name);
			int cnt_allow_list = allow_list == null ? 0 : allow_list.Length;
			IntPtr[] native_allow_list = new IntPtr [cnt_allow_list + 1];
			for (int i = 0; i < cnt_allow_list; i++)
				native_allow_list [i] = GLib.Marshaller.StringToPtrGStrdup (allow_list[i]);
			native_allow_list [cnt_allow_list] = IntPtr.Zero;
			int cnt_block_list = block_list == null ? 0 : block_list.Length;
			IntPtr[] native_block_list = new IntPtr [cnt_block_list + 1];
			for (int i = 0; i < cnt_block_list; i++)
				native_block_list [i] = GLib.Marshaller.StringToPtrGStrdup (block_list[i]);
			native_block_list [cnt_block_list] = IntPtr.Zero;
			Raw = webkit_user_script_new_for_world(native_source, (int) injected_frames, (int) injection_time, native_world_name, native_allow_list, native_block_list);
			GLib.Marshaller.Free (native_source);
			GLib.Marshaller.Free (native_world_name);
			for (int i = 0; i < native_allow_list.Length - 1; i++) {
				allow_list [i] = GLib.Marshaller.Utf8PtrToString (native_allow_list[i]);
				GLib.Marshaller.Free (native_allow_list[i]);
			}
			for (int i = 0; i < native_block_list.Length - 1; i++) {
				block_list [i] = GLib.Marshaller.Utf8PtrToString (native_block_list[i]);
				GLib.Marshaller.Free (native_block_list[i]);
			}
		}

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

		protected override void Ref (IntPtr raw)
		{
			if (!Owned) {
				webkit_user_script_ref (raw);
				Owned = true;
			}
		}

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

		protected override void Unref (IntPtr raw)
		{
			if (Owned) {
				webkit_user_script_unref (raw);
				Owned = false;
			}
		}

		class FinalizerInfo {
			IntPtr handle;
			public uint timeoutHandlerId;

			public FinalizerInfo (IntPtr handle)
			{
				this.handle = handle;
			}

			public bool Handler ()
			{
				webkit_user_script_unref (handle);
				GLib.Timeout.Remove(timeoutHandlerId);
				return false;
			}
		}

		~UserScript ()
		{
			if (!Owned)
				return;
			FinalizerInfo info = new FinalizerInfo (Handle);
			info.timeoutHandlerId = GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
		}


		// Internal representation of the wrapped structure ABI.
		static GLib.AbiStruct _abi_info = null;
		static public unsafe GLib.AbiStruct abi_info {
			get {
				if (_abi_info == null)
					_abi_info = new GLib.AbiStruct (new List<GLib.AbiField>{ 
					});

				return _abi_info;
			}
		}


		// End of the ABI representation.

#endregion
	}
}
