0

I'm developing a Chrome packaged app which displays a certain kind of document as HTML. I have the app working to some degree, but would like to add a feature allowing the user to open a file by clicking on a link to an applicable file.

I am able to launch the app by MIME type as per the docs here, and am familiar with the pp::Instance::HandleDocumentLoad method to handle the clicked link's source, but am unsure how to display HTML I'm generating from the parsed document.

This is easy enough to do when the user manually launches the app and selects a file using an input element and the HTML file system since the HTML GUI is specified in the app manifest, but as far as I can tell, launching based on MIME type just embeds the NMF.

TL;DR: Is there a way to specify a HTML interface for (or a simple way to render HTML from) a NaCl module instance created by a nacl_modules manifest entry?

Benjineer
  • 1,323
  • 16
  • 21

1 Answers1

0

This is possible, but it's a bit of a hack. I copied the trick from here: https://groups.google.com/d/msg/native-client-discuss/UJu7VXvV_bw/pLc19D50gbwJ

You can see how I did it here and here:

Basically, you listen on chrome.tabs.onCreated and chrome.tabs.onUpdated, then you inject a small bit of JavaScript that checks for the embed element with the correct mimetype. If it finds the element, it sends a message (via chrome.runtime.sendMessage) to your extension. When your extension gets that message, it injects the rest of your JavaScript into the page using chrome.tabs.executeScript. At this point you can display whatever you want.

You could do it earlier, by injecting your code into every page, but I found this was a bit nicer, as it only injects a small bit of code.

binji
  • 1,850
  • 7
  • 9
  • Seems like a workable solution for an extension, but I'm pretty sure this wouldn't work for an app. – Benjineer Feb 18 '16 at 04:25
  • 1
    Ah, I missed that part, sorry. You can specify file_handlers in the manifest: see https://developer.chrome.com/apps/manifest/file_handlers. It seems like this may be supported only for browsing files in ChromeOS, however. – binji Feb 18 '16 at 18:36
  • File handlers may actually be the way to go, I should be able to load the doc into the web filesystem if it's not a `file://` link - I think the "ChromeOS only" part refers to handling files, but I could be wrong. Will test it out. – Benjineer Feb 24 '16 at 08:41