1 module webkit2.UserScript; 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 public class UserScript 12 { 13 /** the main Gtk struct */ 14 protected WebKitUserScript* webKitUserScript; 15 protected bool ownedRef; 16 17 /** Get the main Gtk struct */ 18 public WebKitUserScript* getUserScriptStruct(bool transferOwnership = false) 19 { 20 if (transferOwnership) 21 ownedRef = false; 22 return webKitUserScript; 23 } 24 25 /** the main Gtk struct as a void* */ 26 protected void* getStruct() 27 { 28 return cast(void*)webKitUserScript; 29 } 30 31 /** 32 * Sets our main struct and passes it to the parent class. 33 */ 34 public this (WebKitUserScript* webKitUserScript, bool ownedRef = false) 35 { 36 this.webKitUserScript = webKitUserScript; 37 this.ownedRef = ownedRef; 38 } 39 40 ~this () 41 { 42 if ( ownedRef ) 43 webkit_user_script_unref(webKitUserScript); 44 } 45 46 47 /** */ 48 public static GType getType() 49 { 50 return webkit_user_script_get_type(); 51 } 52 53 /** 54 * Creates a new user script. Scripts can be applied to some URIs 55 * only by passing non-null values for @allow_list or @block_list. Passing a 56 * %NULL allow_list implies that all URIs are on the allow_list. The script 57 * is applied if an URI matches the allow_list and not the block_list. 58 * URI patterns must be of the form `[protocol]://[host]/[path]`, where the 59 * *host* and *path* components can contain the wildcard character (`*`) to 60 * represent zero or more other characters. 61 * 62 * Params: 63 * source = Source code of the user script. 64 * injectedFrames = A #WebKitUserContentInjectedFrames value 65 * injectionTime = A #WebKitUserScriptInjectionTime value 66 * allowList = An allow_list of URI patterns or %NULL 67 * blockList = A block_list of URI patterns or %NULL 68 * 69 * Returns: A new #WebKitUserScript 70 * 71 * Since: 2.6 72 * 73 * Throws: ConstructionException GTK+ fails to create the object. 74 */ 75 public this(string source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserScriptInjectionTime injectionTime, string[] allowList, string[] blockList) 76 { 77 auto __p = webkit_user_script_new(Str.toStringz(source), injectedFrames, injectionTime, Str.toStringzArray(allowList), Str.toStringzArray(blockList)); 78 79 if(__p is null) 80 { 81 throw new ConstructionException("null returned by new"); 82 } 83 84 this(cast(WebKitUserScript*) __p); 85 } 86 87 /** 88 * Creates a new user script for script world with name @world_name. 89 * See webkit_user_script_new() for a full description. 90 * 91 * Params: 92 * source = Source code of the user script. 93 * injectedFrames = A #WebKitUserContentInjectedFrames value 94 * injectionTime = A #WebKitUserScriptInjectionTime value 95 * worldName = the name of a #WebKitScriptWorld 96 * allowList = An allow_list of URI patterns or %NULL 97 * blockList = A block_list of URI patterns or %NULL 98 * 99 * Returns: A new #WebKitUserScript 100 * 101 * Since: 2.22 102 * 103 * Throws: ConstructionException GTK+ fails to create the object. 104 */ 105 public this(string source, WebKitUserContentInjectedFrames injectedFrames, WebKitUserScriptInjectionTime injectionTime, string worldName, string[] allowList, string[] blockList) 106 { 107 auto __p = webkit_user_script_new_for_world(Str.toStringz(source), injectedFrames, injectionTime, Str.toStringz(worldName), Str.toStringzArray(allowList), Str.toStringzArray(blockList)); 108 109 if(__p is null) 110 { 111 throw new ConstructionException("null returned by new_for_world"); 112 } 113 114 this(cast(WebKitUserScript*) __p); 115 } 116 117 alias doref = ref_; 118 /** 119 * Atomically increments the reference count of @user_script by one. 120 * This function is MT-safe and may be called from any thread. 121 * 122 * Returns: The passed #WebKitUserScript 123 * 124 * Since: 2.6 125 */ 126 public UserScript ref_() 127 { 128 auto __p = webkit_user_script_ref(webKitUserScript); 129 130 if(__p is null) 131 { 132 return null; 133 } 134 135 return ObjectG.getDObject!(UserScript)(cast(WebKitUserScript*) __p, true); 136 } 137 138 /** 139 * Atomically decrements the reference count of @user_script by one. 140 * If the reference count drops to 0, all memory allocated by 141 * #WebKitUserScript is released. This function is MT-safe and may be called 142 * from any thread. 143 * 144 * Since: 2.6 145 */ 146 public void unref() 147 { 148 webkit_user_script_unref(webKitUserScript); 149 } 150 }