2

Does anyone has any idea on how to sandbox ActiveX components in a windows app so that if it crashes it doesnt bring down the whole app along with it? I can see Google doing this with Flash. How is it done?

I think they host it out proc and then show only the UI only in the application. Is this possible?

I am interested in doing this on a C# Window application.

bobbyalex
  • 2,681
  • 3
  • 30
  • 51

2 Answers2

1

My initial thought is that this would not be possible. The Chrome Flash sandbox was a joint venture between Google and Adobe where Adobe had to do a lot of work to associate the Flash plugin with the sandbox:

EDIT

Check out this answer: Detecting application hangs with ActiveX controls in .Net

It could be what you are looking for.

Additionally, if you are relying on the UI from the ActiveX you might want to look into this: How do I host an application window as a child of a window belonging to another process?

Disclaimer: I have not done this myself, so - anybody - please feel free to correct my assumptions.

Community
  • 1
  • 1
Simen S
  • 3,210
  • 18
  • 24
  • Thanks Simen. I didnt know that it was a collaborative effort. Makes sense actually. – bobbyalex Apr 08 '11 at 11:31
  • But of course there we are talking about the browser's link to Flash for the purpose of protecting against malicious code. Your need is slightly different. – Simen S Apr 08 '11 at 11:36
  • What you want is to have to have a specific UI area within a form in your application to be isolated into a different process, at the same time as your application is sufficiantly in control so that you can detect whether the process behind the hosted window is "hanging". Am I right? – Simen S Apr 08 '11 at 11:44
  • Thats right Simen. I have tried app domains but I believe there is a restriction that prevents UI elements in one app domain from being hosted in another. – bobbyalex Apr 09 '11 at 18:33
  • Incidently, it should be noticed that the Chrome Flash sandbox is no different (in any significant way, anyway) from the sandbox they use with any other plugin; it was not developed by Adobe, but by Google. – taxilian Jun 06 '11 at 17:18
0

Google Chrome is set up so that no matter what plugin it is, if it crashes it doesn't take down the whole process. In fact, they don't use the ActiveX version of Flash at all... they use the NPAPI version, same as Firefox and Safari.

The trick that Chrome uses, which I assume you could also use but could be tricky, is that they launch the plugin in a seperate process. Firefox 4 has started doing the same thing, in fact (if you look in your task bar you'll see a plugin-container.exe process for Firefox when flash is running; Chrome just launches more chrome.exe processes). Since it's a seperate process, it can crash and it doesn't take out your application; you just detect that the other process is now gone and act accordingly.

Anyway, I've never done multiple processes in c#, but I assume it's possible. that's the most common method for "sandboxing" something like that AFAIK. I could do it in C++ (and have), but C# could be trickier.

taxilian
  • 14,229
  • 4
  • 34
  • 73
  • But I am not really sure if UI from an out proc process can be hosted in a different one. And that is essentially what I want. – bobbyalex Jun 05 '11 at 16:00
  • an HWND is global to the system; again, I'm not sure how easy this is in .NET, but if you can get the HWND to the child process it can create a child HWND inside the parent and draw to that child HWND just fine. The only reason you even need a child HWND is because you can't get the WINPROC from the parent. – taxilian Jun 06 '11 at 17:17