I have wanted to look into creating a custom protocol handler to plug into a TWebBrowser with Delphi for a while, called an Asynchronous Pluggable Protocol. I have seen a few implementations, but they were all quite old, and none did exactly what I wanted, which is to be able to create a temporary APP, which is local to the application and self contained.
From this StackOverflow question, I found a basic implementation of a registered APP, at http://www.doogal.co.uk/plugprot.php. Starting from this, I figured out how to create a temporary asynchronous pluggable protocol.
The way I implemented it allows you to specify a callback procedure of object which gets called to handle any URLs for your custom protocol. My implementation allows you to decide the content you return and the MIME type, and also handles POSTs, which I haven’t seen in other Delphi implementations.
See the AsyncPlugProtoDemo project in twebbrowser.utilities/AsynchronousPluggableProtocol/. Note that the code should work with Delphi 2009 and later. I was able to get it working in Delphi 2007, by changing some PChar to PWideChar, and String to WideString where Delphi showed errors, and use UTF8Decode() instead of UTF8ToString().