99using O2 . Kernel . ExtensionMethods ;
1010using O2 . DotNetWrappers . DotNet ;
1111using O2 . DotNetWrappers . ExtensionMethods ;
12+ using O2 . XRules . Database . Utils ;
1213using OpenQA . Selenium ;
1314using OpenQA . Selenium . Chrome ;
15+ //O2File:API_Win32_Handle_Hijack.cs
1416//O2Ref:Selenium\net40\WebDriver.dll
1517//Installer:Selenium_Installer.cs!Selenium\net40\WebDriver.dll
1618
@@ -20,14 +22,17 @@ namespace O2.XRules.Database.APIs
2022{
2123 public class API_Chrome_Hijack
2224 {
23- public ChromeDriver ChromeDriver { get ; set ; }
24- public ChromeOptions ChromeOptions { get ; set ; }
25- public ChromeDriverService ChromeDriverService { get ; set ; }
26- public Process ChromeDriverProcess { get ; set ; }
27- public Process ChromeProcess { get ; set ; }
28- public string ChromeDriver_Exe { get ; set ; }
29- public string WebDriver_Folder { get ; set ; }
30- public string ChromeDriverDownloadLink { get ; set ; }
25+ public ChromeDriver ChromeDriver { get ; set ; }
26+ public ChromeOptions ChromeOptions { get ; set ; }
27+ public ChromeDriverService ChromeDriverService { get ; set ; }
28+ public Process ChromeDriverProcess { get ; set ; }
29+ public Process ChromeProcess { get ; set ; }
30+ public Panel Panel_Chrome { get ; set ; }
31+ public Panel Panel_ChromeDriver { get ; set ; }
32+ public ascx_Simple_Script_Editor WebDriver_Script_Me { get ; set ; }
33+ public string ChromeDriver_Exe { get ; set ; }
34+ public string WebDriver_Folder { get ; set ; }
35+ public string ChromeDriverDownloadLink { get ; set ; }
3136
3237 public API_Chrome_Hijack ( )
3338 {
@@ -61,33 +66,83 @@ public API_Chrome_Hijack open_ChromeDriver()
6166
6267 return this ;
6368 }
69+
70+ }
71+
72+
73+ public static class API_Chrome_Test_ExtensionMethods
74+ {
75+ public static ChromeDriver add_Chrome ( this Panel targetPanel )
76+ {
77+ return new API_Chrome_Hijack ( )
78+ . open_ChromeDriver ( )
79+ . hijack_Chrome ( targetPanel , true )
80+ . ChromeDriver ;
81+ }
6482
65- /* public IntPtr startChromeDriver( )
83+ public static API_Chrome_Hijack add_Chrome_To_Panel ( this API_Chrome_Hijack chromeHijack , Panel targetPanel )
6684 {
67- "[setup_Chrome] start".info();
68- //var selenium = new API_Selenium();
69- //ChromeDriver = selenium.setTarget_Chrome();
70- //ChromeDriver chromeDriverProcess = "ChromeDriver".process_WithName();
71- //chromeHandle= getProcessWithParentHandle(chromeDriverProcess.Id).MainWindowHandle;
72- return chromeHandle;
73- }*/
85+ var chrome_Panel = targetPanel . add_GroupBox ( "Chrome" ) . add_Panel ( ) ;
86+ var chromeDriver_Panel = chromeHijack . Panel_Chrome . parent ( ) . insert_Below ( 150 , "Chrome WebDriver" ) ;
87+
88+ return chromeHijack . hijack_Chrome ( chrome_Panel , false )
89+ . hijack_ChromeDriver ( chromeDriver_Panel ) ;
90+ }
7491
75- /*Func<IntPtr, IWebDriver> setup_Chrome =
76- (targetHandle)=>{
77- "[setup_Chrome] start".info();
78- var selenium = new API_Selenium();
79- selenium.setTarget_Chrome();
80- chromeDriverProcess = "ChromeDriver".process_WithName();
81- chromeHandle= getProcessWithParentHandle(chromeDriverProcess.Id).MainWindowHandle;
82- chromeHandle.setParent(targetHandle);
83- WinAPI.ShowWindow(chromeHandle, WinAPI.ShowWindowCommands.ShowMaximized);
84- "[setup_Chrome] done".info();
85- return selenium.WebDriver;
86- };*/
87-
92+ public static API_Chrome_Hijack hijack_Chrome ( this API_Chrome_Hijack chromeHijack , Panel targetPanel , bool hijackJustViewer )
93+ {
94+ if ( chromeHijack . notNull ( ) && chromeHijack . ChromeProcess . notNull ( ) && targetPanel . notNull ( ) )
95+ {
96+ chromeHijack . Panel_Chrome = targetPanel ;
97+ var hijackGui = chromeHijack . Panel_Chrome . add_Handle_HijackGui ( false ) ;
98+ if ( hijackJustViewer )
99+ {
100+ hijackGui . hijackProcessWindow ( chromeHijack . ChromeProcess ,
101+ ( mainWindowHandle ) =>
102+ {
103+ // this doesn't work well now since the main chrome window (with the address bar) still gains focus)
104+ // need to look at how to capture and filter events from the child to the parent (and vice versa)
105+ //
106+ var targetWindow = mainWindowHandle . child_Windows ( ) . second ( ) ;
107+ return targetWindow ;
108+
109+ return mainWindowHandle ; // for now hijack the whole thing
110+ } ) ;
111+
112+ }
113+ else
114+ hijackGui . hijackProcessMainWindow ( chromeHijack . ChromeProcess ) ;
115+ }
116+ return chromeHijack ;
117+ }
118+
119+ public static API_Chrome_Hijack hijack_ChromeDriver ( this API_Chrome_Hijack chromeHijack , Panel targetPanel )
120+ {
121+ if ( chromeHijack . notNull ( ) && chromeHijack . ChromeDriverProcess . notNull ( ) && targetPanel . notNull ( ) )
122+ {
123+ chromeHijack . Panel_ChromeDriver = targetPanel ;
124+ chromeHijack . Panel_ChromeDriver . add_Handle_HijackGui ( false )
125+ . hijackProcessMainWindow ( chromeHijack . ChromeDriverProcess ) ;
126+ }
127+ return chromeHijack ;
128+ }
129+
130+ public static API_Chrome_Hijack add_WebDriver_ScriptMe_To ( this API_Chrome_Hijack chromeHijack , Panel targetPanel )
131+ {
132+
133+ chromeHijack . WebDriver_Script_Me = chromeHijack . ChromeDriver . script_Me ( targetPanel ) ;
134+ return chromeHijack ;
135+ }
136+
137+ public static Win32_Handle_Hijack hijack_Process_Into_Panel ( this API_Chrome_Hijack chromeHijack , Panel targetPanel , Process targetProcess )
138+ {
139+ var hijackGui = targetPanel . add_Handle_HijackGui ( false )
140+ . hijackProcessMainWindow ( targetProcess ) ;
141+ return hijackGui ;
142+ }
88143 }
89-
90- public static class API_Chrome_Test_ExtensionMethods
144+
145+ public static class Process_Extra_ExtensionMethods
91146 {
92147 public static Process getProcessWithParentHandle ( this Process process )
93148 {
@@ -100,7 +155,7 @@ public static Process getProcessWithParentHandle(this Process process)
100155 var foundProcess = procId . process_WithId ( ) ;
101156 "foundProcess: {0}" . debug ( foundProcess ) ;
102157 return foundProcess ;
103- } ;
158+ }
104159 "Failed to find process with id: {0} name: {0}" . error ( process . Id , process . ProcessName ) ;
105160 }
106161 return null ;
0 commit comments