1 module webkit2webextension.ScriptWorld; 2 3 private import glib.ConstructionException; 4 private import glib.Str; 5 private import gobject.ObjectG; 6 private import gobject.Signals; 7 private import std.algorithm; 8 private import webkit2webextension.Frame; 9 private import webkit2webextension.WebPage; 10 private import webkit2webextension.c.functions; 11 public import webkit2webextension.c.types; 12 13 14 /** */ 15 public class ScriptWorld : ObjectG 16 { 17 /** the main Gtk struct */ 18 protected WebKitScriptWorld* webKitScriptWorld; 19 20 /** Get the main Gtk struct */ 21 public WebKitScriptWorld* getScriptWorldStruct(bool transferOwnership = false) 22 { 23 if (transferOwnership) 24 ownedRef = false; 25 return webKitScriptWorld; 26 } 27 28 /** the main Gtk struct as a void* */ 29 protected override void* getStruct() 30 { 31 return cast(void*)webKitScriptWorld; 32 } 33 34 /** 35 * Sets our main struct and passes it to the parent class. 36 */ 37 public this (WebKitScriptWorld* webKitScriptWorld, bool ownedRef = false) 38 { 39 this.webKitScriptWorld = webKitScriptWorld; 40 super(cast(GObject*)webKitScriptWorld, ownedRef); 41 } 42 43 44 /** */ 45 public static GType getType() 46 { 47 return webkit_script_world_get_type(); 48 } 49 50 /** 51 * Creates a new isolated #WebKitScriptWorld. Scripts executed in 52 * isolated worlds have access to the DOM but not to other variable 53 * or functions created by the page. 54 * The #WebKitScriptWorld is created with a generated unique name. Use 55 * webkit_script_world_new_with_name() if you want to create it with a 56 * custom name. 57 * You can get the JavaScript execution context of a #WebKitScriptWorld 58 * for a given #WebKitFrame with webkit_frame_get_javascript_context_for_script_world(). 59 * 60 * Returns: a new isolated #WebKitScriptWorld 61 * 62 * Since: 2.2 63 * 64 * Throws: ConstructionException GTK+ fails to create the object. 65 */ 66 public this() 67 { 68 auto __p = webkit_script_world_new(); 69 70 if(__p is null) 71 { 72 throw new ConstructionException("null returned by new"); 73 } 74 75 this(cast(WebKitScriptWorld*) __p, true); 76 } 77 78 /** 79 * Creates a new isolated #WebKitScriptWorld with a name. Scripts executed in 80 * isolated worlds have access to the DOM but not to other variable 81 * or functions created by the page. 82 * You can get the JavaScript execution context of a #WebKitScriptWorld 83 * for a given #WebKitFrame with webkit_frame_get_javascript_context_for_script_world(). 84 * 85 * Params: 86 * name = a name for the script world 87 * 88 * Returns: a new isolated #WebKitScriptWorld 89 * 90 * Since: 2.22 91 * 92 * Throws: ConstructionException GTK+ fails to create the object. 93 */ 94 public this(string name) 95 { 96 auto __p = webkit_script_world_new_with_name(Str.toStringz(name)); 97 98 if(__p is null) 99 { 100 throw new ConstructionException("null returned by new_with_name"); 101 } 102 103 this(cast(WebKitScriptWorld*) __p, true); 104 } 105 106 /** 107 * Get the default #WebKitScriptWorld. This is the normal script world 108 * where all scripts are executed by default. 109 * You can get the JavaScript execution context of a #WebKitScriptWorld 110 * for a given #WebKitFrame with webkit_frame_get_javascript_context_for_script_world(). 111 * 112 * Returns: the default #WebKitScriptWorld 113 * 114 * Since: 2.2 115 */ 116 public static ScriptWorld getDefault() 117 { 118 auto __p = webkit_script_world_get_default(); 119 120 if(__p is null) 121 { 122 return null; 123 } 124 125 return ObjectG.getDObject!(ScriptWorld)(cast(WebKitScriptWorld*) __p); 126 } 127 128 /** 129 * Get the name of a #WebKitScriptWorld. 130 * 131 * Returns: the name of @world 132 * 133 * Since: 2.22 134 */ 135 public string getName() 136 { 137 return Str.toString(webkit_script_world_get_name(webKitScriptWorld)); 138 } 139 140 /** 141 * Emitted when the JavaScript window object in a #WebKitScriptWorld has been 142 * cleared. This is the preferred place to set custom properties on the window 143 * object using the JavaScriptCore API. You can get the window object of @frame 144 * from the JavaScript execution context of @world that is returned by 145 * webkit_frame_get_js_context_for_script_world(). 146 * 147 * Params: 148 * page = a #WebKitWebPage 149 * frame = the #WebKitFrame to which @world belongs 150 * 151 * Since: 2.2 152 */ 153 gulong addOnWindowObjectCleared(void delegate(WebPage, Frame, ScriptWorld) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0) 154 { 155 return Signals.connect(this, "window-object-cleared", dlg, connectFlags ^ ConnectFlags.SWAPPED); 156 } 157 }