Search code examples
javascriptgoogle-chromegoogle-chrome-extensionnpapi

Showing a progress dialog for a Chrome extension that interacts with an NPAPI plugin


I'm writing an extension for Google Chrome that converts a page to a PDF file. The extension, written in Javascript, extracts the DOM of the current page, and passes it to an NPAPI DLL, where the conversion happens. I want to show a progress dialog to the user that comes up as soon as the conversion begins, and goes away, or shows a status complete dialog, when the conversion has ended and the PDF file is opened for viewing. I'm a newbie at using Javascript. What should I do to achieve the aforementioned task?


Solution

  • The basic idea would be to:

    • register an event handler on the plugin to receive the completion event (plugin has to implement the (script-)function addEventListener for that)
    • call the plugin telling it to start the conversion
    • the plugin starts a background worker thread for the conversion (as you can't block the main thread)
    • show progress dialog overlay
    • when the plugin is done it fires the completion event (note: NPAPI calls have to occur on the main thread, NPN_PluginThreadAsyncCall helps with that)
    • the JS can now close the progress dialog / show completion dialog / ...