1 module webkit2.SecurityOrigin;
2 
3 private import glib.ConstructionException;
4 private import glib.Str;
5 private import gobject.ObjectG;
6 private import webkit2.c.functions;
7 public  import webkit2.c.types;
8 
9 
10 /**
11  * #WebKitSecurityOrigin is a representation of a security domain
12  * defined by websites. A security origin normally consists of a
13  * protocol, a hostname, and a port number. It is also possible for a
14  * security origin to be opaque, as defined by the HTML standard, in
15  * which case it has no associated protocol, host, or port.
16  * 
17  * Websites with the same security origin can access each other's
18  * resources for client-side scripting or database access.
19  *
20  * Since: 2.16
21  */
22 public class SecurityOrigin
23 {
24 	/** the main Gtk struct */
25 	protected WebKitSecurityOrigin* webKitSecurityOrigin;
26 	protected bool ownedRef;
27 
28 	/** Get the main Gtk struct */
29 	public WebKitSecurityOrigin* getSecurityOriginStruct(bool transferOwnership = false)
30 	{
31 		if (transferOwnership)
32 			ownedRef = false;
33 		return webKitSecurityOrigin;
34 	}
35 
36 	/** the main Gtk struct as a void* */
37 	protected void* getStruct()
38 	{
39 		return cast(void*)webKitSecurityOrigin;
40 	}
41 
42 	/**
43 	 * Sets our main struct and passes it to the parent class.
44 	 */
45 	public this (WebKitSecurityOrigin* webKitSecurityOrigin, bool ownedRef = false)
46 	{
47 		this.webKitSecurityOrigin = webKitSecurityOrigin;
48 		this.ownedRef = ownedRef;
49 	}
50 
51 	~this ()
52 	{
53 		if ( ownedRef )
54 			webkit_security_origin_unref(webKitSecurityOrigin);
55 	}
56 
57 
58 	/** */
59 	public static GType getType()
60 	{
61 		return webkit_security_origin_get_type();
62 	}
63 
64 	/**
65 	 * Create a new security origin from the provided protocol, host and
66 	 * port.
67 	 *
68 	 * Params:
69 	 *     protocol = The protocol for the new origin
70 	 *     host = The host for the new origin
71 	 *     port = The port number for the new origin, or 0 to indicate the
72 	 *         default port for @protocol
73 	 *
74 	 * Returns: A #WebKitSecurityOrigin.
75 	 *
76 	 * Since: 2.16
77 	 *
78 	 * Throws: ConstructionException GTK+ fails to create the object.
79 	 */
80 	public this(string protocol, string host, ushort port)
81 	{
82 		auto __p = webkit_security_origin_new(Str.toStringz(protocol), Str.toStringz(host), port);
83 
84 		if(__p is null)
85 		{
86 			throw new ConstructionException("null returned by new");
87 		}
88 
89 		this(cast(WebKitSecurityOrigin*) __p);
90 	}
91 
92 	/**
93 	 * Create a new security origin from the provided URI. Components of
94 	 * @uri other than protocol, host, and port do not affect the created
95 	 * #WebKitSecurityOrigin.
96 	 *
97 	 * Params:
98 	 *     uri = The URI for the new origin
99 	 *
100 	 * Returns: A #WebKitSecurityOrigin.
101 	 *
102 	 * Since: 2.16
103 	 *
104 	 * Throws: ConstructionException GTK+ fails to create the object.
105 	 */
106 	public this(string uri)
107 	{
108 		auto __p = webkit_security_origin_new_for_uri(Str.toStringz(uri));
109 
110 		if(__p is null)
111 		{
112 			throw new ConstructionException("null returned by new_for_uri");
113 		}
114 
115 		this(cast(WebKitSecurityOrigin*) __p);
116 	}
117 
118 	/**
119 	 * Gets the hostname of @origin, or %NULL if @origin is opaque or if its
120 	 * protocol does not require a host component.
121 	 *
122 	 * Returns: The host of the #WebKitSecurityOrigin
123 	 *
124 	 * Since: 2.16
125 	 */
126 	public string getHost()
127 	{
128 		return Str.toString(webkit_security_origin_get_host(webKitSecurityOrigin));
129 	}
130 
131 	/**
132 	 * Gets the port of @origin. This function will always return 0 if the
133 	 * port is the default port for the given protocol. For example,
134 	 * http://example.com has the same security origin as
135 	 * http://example.com:80, and this function will return 0 for a
136 	 * #WebKitSecurityOrigin constructed from either URI. It will also
137 	 * return 0 if @origin is opaque.
138 	 *
139 	 * Returns: The port of the #WebKitSecurityOrigin.
140 	 *
141 	 * Since: 2.16
142 	 */
143 	public ushort getPort()
144 	{
145 		return webkit_security_origin_get_port(webKitSecurityOrigin);
146 	}
147 
148 	/**
149 	 * Gets the protocol of @origin, or %NULL if @origin is opaque.
150 	 *
151 	 * Returns: The protocol of the #WebKitSecurityOrigin
152 	 *
153 	 * Since: 2.16
154 	 */
155 	public string getProtocol()
156 	{
157 		return Str.toString(webkit_security_origin_get_protocol(webKitSecurityOrigin));
158 	}
159 
160 	/**
161 	 * Gets whether @origin is an opaque security origin, which does not
162 	 * possess an associated protocol, host, or port.
163 	 *
164 	 * Returns: %TRUE if @origin is opaque.
165 	 *
166 	 * Since: 2.16
167 	 */
168 	public bool isOpaque()
169 	{
170 		return webkit_security_origin_is_opaque(webKitSecurityOrigin) != 0;
171 	}
172 
173 	alias doref = ref_;
174 	/**
175 	 * Atomically increments the reference count of @origin by one.
176 	 * This function is MT-safe and may be called from any thread.
177 	 *
178 	 * Returns: The passed #WebKitSecurityOrigin
179 	 *
180 	 * Since: 2.16
181 	 */
182 	public SecurityOrigin ref_()
183 	{
184 		auto __p = webkit_security_origin_ref(webKitSecurityOrigin);
185 
186 		if(__p is null)
187 		{
188 			return null;
189 		}
190 
191 		return ObjectG.getDObject!(SecurityOrigin)(cast(WebKitSecurityOrigin*) __p, true);
192 	}
193 
194 	/**
195 	 * Gets a string representation of @origin. The string representation
196 	 * is a valid URI with only protocol, host, and port components. It may
197 	 * be %NULL, but usually only if @origin is opaque.
198 	 *
199 	 * Returns: a URI representing @origin.
200 	 *
201 	 * Since: 2.16
202 	 */
203 	public override string toString()
204 	{
205 		auto retStr = webkit_security_origin_to_string(webKitSecurityOrigin);
206 
207 		scope(exit) Str.freeString(retStr);
208 		return Str.toString(retStr);
209 	}
210 
211 	/**
212 	 * Atomically decrements the reference count of @origin by one.
213 	 * If the reference count drops to 0, all memory allocated by
214 	 * #WebKitSecurityOrigin is released. This function is MT-safe and may be
215 	 * called from any thread.
216 	 *
217 	 * Since: 2.16
218 	 */
219 	public void unref()
220 	{
221 		webkit_security_origin_unref(webKitSecurityOrigin);
222 	}
223 }