4

I've written a Chrome Extension (w/ NPAPI as well) that allows my application and Chrome to communicate with each other. That is all mostly working fine.

What I'm trying to do now is be able to tie the HWND of a Chrome window to a particular Window ID & Tab ID.

When I'm inside of Chrome (via the plugin) I have the Tab ID and Window ID and I can do most operations based on that.

When I'm outside of Chrome (via my application) I can see the window structure and get the HWND of the various tabs.

Is there any way that I can tie them together reliably such that my application could tell Chrome to get me information about/from a specific tab?

Tim
  • 14,999
  • 1
  • 45
  • 68
  • What kinds of information do you need? – Silviu-Marian Jul 13 '12 at 22:55
  • Such an approach will be fragile as it depends on implementation details of the browser. What exactly do you want to achieve with this? – Georg Fritzsche Jul 14 '12 at 17:34
  • For a short-term scenario, I need to be able to say that when my app encounters a Chrome window, it can somehow use the HWND to ask the plugin for information about that particular window/tab. There's no way (that I can see) to get the TabID/WindowID from outside of the plugin... and no way to get the HWND inside the plugin. So I'm basically just trying to figure out how to tie those pieces of information together. – Tim Jul 14 '12 at 19:24
  • Keep in mind that plugins run out of press. I don't know if there is an easier way from a extension, but if you are injecting the plugin into pages you might be able to retrieve the parent process or it's id. Alternatively you could try to get to the parent via the plugins window or drawing context. Keep in mind that all this depends on the details of the multi-process-architecture of Chrome (which i haven't looked into) and might break with future releases. – Georg Fritzsche Jul 19 '12 at 17:59
  • `s/out of press/out of process/` – Georg Fritzsche Jul 19 '12 at 22:22
  • This is a Chrome feature request: https://code.google.com/p/chromium/issues/detail?id=354597 – josh3736 Mar 20 '14 at 20:15

1 Answers1

2

If you have Spy++ you'll see that site titles stay consistent with tab window titles. You should definitely use that.

To eliminate title collisions simply call chrome.tabs.query() and chrome.tabs.update() from extension to save, change, and restore a tab's title. Then use GetCurrentProcess() and EnumWindows()/WindowEnumProc() to get child windows hierarchy and match your custom title. You will have to pass it to an EnumWindowsProc callback function.

Silviu-Marian
  • 10,565
  • 6
  • 50
  • 72