1 module webkit2.AutomationSession;
2 
3 private import glib.Str;
4 private import gobject.ObjectG;
5 private import gobject.Signals;
6 private import std.algorithm;
7 private import webkit2.ApplicationInfo;
8 private import webkit2.WebView;
9 private import webkit2.c.functions;
10 public  import webkit2.c.types;
11 
12 
13 /**
14  * WebKitAutomationSession represents an automation session of a WebKitWebContext.
15  * When a new session is requested, a WebKitAutomationSession is created and the signal
16  * WebKitWebContext::automation-started is emitted with the WebKitAutomationSession as
17  * argument. Then, the automation client can request the session to create a new
18  * #WebKitWebView to interact with it. When this happens the signal #WebKitAutomationSession::create-web-view
19  * is emitted.
20  *
21  * Since: 2.18
22  */
23 public class AutomationSession : ObjectG
24 {
25 	/** the main Gtk struct */
26 	protected WebKitAutomationSession* webKitAutomationSession;
27 
28 	/** Get the main Gtk struct */
29 	public WebKitAutomationSession* getAutomationSessionStruct(bool transferOwnership = false)
30 	{
31 		if (transferOwnership)
32 			ownedRef = false;
33 		return webKitAutomationSession;
34 	}
35 
36 	/** the main Gtk struct as a void* */
37 	protected override void* getStruct()
38 	{
39 		return cast(void*)webKitAutomationSession;
40 	}
41 
42 	/**
43 	 * Sets our main struct and passes it to the parent class.
44 	 */
45 	public this (WebKitAutomationSession* webKitAutomationSession, bool ownedRef = false)
46 	{
47 		this.webKitAutomationSession = webKitAutomationSession;
48 		super(cast(GObject*)webKitAutomationSession, ownedRef);
49 	}
50 
51 
52 	/** */
53 	public static GType getType()
54 	{
55 		return webkit_automation_session_get_type();
56 	}
57 
58 	/**
59 	 * Get the #WebKitAutomationSession previously set with webkit_automation_session_set_application_info().
60 	 *
61 	 * Returns: the #WebKitAutomationSession of @session, or %NULL if no one has been set.
62 	 *
63 	 * Since: 2.18
64 	 */
65 	public ApplicationInfo getApplicationInfo()
66 	{
67 		auto __p = webkit_automation_session_get_application_info(webKitAutomationSession);
68 
69 		if(__p is null)
70 		{
71 			return null;
72 		}
73 
74 		return ObjectG.getDObject!(ApplicationInfo)(cast(WebKitApplicationInfo*) __p);
75 	}
76 
77 	/**
78 	 * Get the unique identifier of a #WebKitAutomationSession
79 	 *
80 	 * Returns: the unique identifier of @session
81 	 *
82 	 * Since: 2.18
83 	 */
84 	public string getId()
85 	{
86 		return Str.toString(webkit_automation_session_get_id(webKitAutomationSession));
87 	}
88 
89 	/**
90 	 * Set the application information to @session. This information will be used by the driver service
91 	 * to match the requested capabilities with the actual application information. If this information
92 	 * is not provided to the session when a new automation session is requested, the creation might fail
93 	 * if the client requested a specific browser name or version. This will not have any effect when called
94 	 * after the automation session has been fully created, so this must be called in the callback of
95 	 * #WebKitWebContext::automation-started signal.
96 	 *
97 	 * Params:
98 	 *     info = a #WebKitApplicationInfo
99 	 *
100 	 * Since: 2.18
101 	 */
102 	public void setApplicationInfo(ApplicationInfo info)
103 	{
104 		webkit_automation_session_set_application_info(webKitAutomationSession, (info is null) ? null : info.getApplicationInfoStruct());
105 	}
106 
107 	/**
108 	 * This signal is emitted when the automation client requests a new
109 	 * browsing context to interact with it. The callback handler should
110 	 * return a #WebKitWebView created with #WebKitWebView:is-controlled-by-automation
111 	 * construct property enabled and #WebKitWebView:automation-presentation-type construct
112 	 * property set if needed.
113 	 *
114 	 * If the signal is emitted with "tab" detail, the returned #WebKitWebView should be
115 	 * a new web view added to a new tab of the current browsing context window.
116 	 * If the signal is emitted with "window" detail, the returned #WebKitWebView should be
117 	 * a new web view added to a new window.
118 	 * When creating a new web view and there's an active browsing context, the new window
119 	 * or tab shouldn't be focused.
120 	 *
121 	 * Returns: a #WebKitWebView widget.
122 	 *
123 	 * Since: 2.18
124 	 */
125 	gulong addOnCreateWebView(WebView delegate(AutomationSession) dlg, ConnectFlags connectFlags=cast(ConnectFlags)0)
126 	{
127 		return Signals.connect(this, "create-web-view", dlg, connectFlags ^ ConnectFlags.SWAPPED);
128 	}
129 }