Wednesday 18 September 2013

Opening up a native Chrome Browser window inside Eclipse (raw version)

On the Win32 Window’s Hijack theme, here is a raw version of how to show an actual Chrome browser window inside an Eclipse view (ie. a window from a C++ process inside a JVM-based Process).

Using the Groovy execution capabilities described in the Programming Eclipse in Real-Time (using an 'Groovy based' Eclipse Plug-in) post, in Eclipse, I start by creating an instance of a SWT panel and get its handle:

image

After executing that script we will get an empty panel in the bottom of the screen:

image

… and the 4461984 return value in the purple 'Groovy script output window'

image

… which is the handle to that Panel/View (which is where were we are going to insert our hijacked window).

In an C# REPL UI, we can now use this script (that consumes that 4461984 handle) to open an Cmd.exe and hijack its window into the Eclipse panel:

image

… which looks like this:

image

… in eclipse:

image

Since what we want is chrome, we can use the API_Chrome_Hijack API to:
  1. open up a new instance of chrome, 
  2. find its dedicated process and 
  3. get that process MainWindowHandle
image

… which looks like this:

image

Finally here is the script that starts a new instance of chrome and insert’s it into the eclipse panel:

image

… which looks like this (in Eclipse)

image 

Note the native Chrome window (C++ Process)  fitting nicely with the Eclipse UI (JVM Process)

image

Since chrome is now running inside an native Eclipse view/control, we can put it where ever we want tit to be (inside the Eclipse UI).

Like on the top right:

image

… on the left:

image

… maximised

image

… as a detached eclipse window:

image

..or in the middle (with another chrome tab opened inside the same Hijacked panel)

image

Here is the Groovy script that created the panel (in Eclipse)

def panelView = activePage.showView("g2.scripts.views.DefaultPart_Panel");
return panelView.panel.handle;


Here is the C# Script that did the Handle setParent:

var chromeHijack = new API_Chrome_Hijack().open_ChromeDriver();
var chromeHandle = chromeHijack.ChromeProcess.MainWindowHandle;
    
var eclipsePanel = 4461984.intPtr();
    
chromeHandle.setParent(eclipsePanel);
    
500.sleep();
    
chromeHandle.window_Maximized();
    
//O2File:API_Chrome_Hijack.cs
//O2File:API_WinAPI.cs
//using O2.XRules.Database.APIs