Intercepting navigation commands in AxWebBrowser control

  • Thread starter Thread starter igarrison
  • Start date Start date
I

igarrison

I'm working on an application for browsing encrypted files (HTML and
PDF mostly)on a DVD. My plan is to decrypt the files to memory and
stream them to the AxWebBrowser component which should be able to
display them at that point. However, I haven't been able to find a way
to intercept the navigation command when someone clicks on a link in an
HTML page so I can pre-process the file before it is rendered.
From what I've been able to find, it looks like I may have to create a
wrapper for the AxWebBrowser that overrides the Navigate() function,
but I haven't found any good documentation on how to do that or what
the Navigate() function does exactly. I can handle the Navigate2()
function with the event handler that is part of the class, but that
doesn't help me when the user clicks on a link embedded in one of the
HTML pages.

Anyone have any suggestions?
 
You will have to do much more than this, actually. You want to look
into Asynchronous Pluggable Protocols (APP). You will have to create
something which will handle a custom protocol that you define, and then
stream the appropriate data.

An APP is a COM object, and the interfaces are not defined in .NET which
you need to define, so you will have to do a good deal of interop.

You could also take the cheap way out, and basically decrypt the file to
a temp file on disk, and then delete it, but I imagine that is not a
feasable solution for you.

Hope this helps.
 
The cheap way out may be a feasible solution. The current 3rd party
app my company currently uses takes that approach, but I was hoping it
wouldn't be significantly more difficult to read/write the files
directly to/from memory to increase security.

The APPs look promising. I assume that they will work for file URIs as
well? Also, can I temporarily register the APP for my application
only, so that other instances of IE (not the AxWebBrowser component)
will not be affected, even if both are in use at the same time?
 
Yeah, that boldtbanan post is mine too, logged in with the wrong acct.

One more thing about APPs....do I have to include the protocol name
when calling the file? ...e.g. myprotocol:myfile ...The files I'm
using are an existing HTML dump of sections of our company website, so
I would have to modify every link tag in the HTML to include the
protocol reference if that's the case.

Thanks

Ian Garrison
 
The thing about APPs is that it is YOUR uri scheme. You arent going to
replace the HTTP scheme, you are going to create your own, and you are going
to feed the data to the calling architecture (which is COM). It doesn't
matter what the back end is to COM, you are responsible for it.

As for temporarily registering the protocol, you would have to get the
CoInternetGetSession function (it is a function that COM exposes) which gets
the IInternetSession interface implementation. On that, you would call the
RegisterNamespace method to register a particular implementation for a
particular scheme for the process.
 
Ian,

If the references are absolute, then yes, you will have to change them.
However, if they are relative, then you shouldn't have to worry about it.
They should fix up normally.

The APP is very simple in a sense. It sees a scheme, it calls your
object to get it, passing you the url. You then return a stream to the
source (it's much more complicated than that, but that's a very high level
view).
 
Nicholas,

The APP approach is looking good, and I think I've figured out how to
approach things from that angle, but I'm still shaky on how to
temporarily register an APP. I understand what you said previously
about getting the IInternetSession and using the RegisterNamespace
method, but I'm not sure how to access the objects through C#. I've
only been working with C# for about 2 months now, and haven't dealt
with Interop beyond using the VS2003 COM object importer, and from what
I've read, that isn't effective in this situation.

The most helpful example I've found is at

http://www.codeproject.com/aspnet/AspxProtocol.asp

and I'm piecing together the actual implementation of the APP from
that. (Actual examples are hard to come by, especially for temporarily
registering the APP. The Microsoft documentation helps with the idea
behind APPS, which I completely understand, but not one bit with the
implementation side). Can you point me somewhere that shows me what I
need to do to set up my app to register the namespace (preferable with
some code examples).

Thanks,

Ian
 
Back
Top