MIME-filter
Say you want to create a webbrowser that will help
parents keep their children from reading profanity on the internet. You
could design a pluggable MIME filter, register it to handle "text/html"
MIME type, and have it replace all occurances of the word NETSCAPE with
<BEEP>.
MIME filter is not much more then a namespacehandler where
you also implement IInternetProtocolSink and register it with the MIME
type you want to filter:
begin
CoGetClassObject(Class_OurMimeFilter, CLSCTX_SERVER, nil, IClassFactory,
Factory);
CoInternetGetSession(0, InternetSession, 0);
InternetSession.RegisterMimeFilter(Factory, Class_OurMimeFilter, 'text/html');
end;
The logic in a MIME-filter is like ping-pong. The transaction handler (or
call it webbrowser) has implemented IInternetProtocol and
IInternetProtocolSink - and so have you:
1. Transaction handler call your function Start.
2. Transaction handler call your function ReportProgress and tell you the
name of the Cachefile where the downloaded file will be stored.
3. Transaction handler calls your ReportData when data is avaiable.
4. Your Call the transaction handlers Function Read to get the data.
5. You filter the content and call the transaction handlers ReportData,
telling that you have data ready.
6. The transaction handler call your Function Read to get the data.
... and so on
How to use:
Permanent MIME filter:
A permament MIME filter is active in all running instances of Internet
Explorer. See included code for creating a MIME filter DLL-file. Register
it:
Regsvr32 <DLL-filename>
or from Delphi IDE: choose Run->Register ActiveX
Server.
To unregister it:
Regsvr32 /u <DLL-filename>
or from Delphi IDE: choose Run->Unregister ActiveX
Server.
Temporary MIME filter (TWebbrowser):
var
Factory: IClassFactory;
InternetSession: IInternetSession;
procedure RegisterMimeFilter;
begin
CoGetClassObject(Class_OurMimeFilter, CLSCTX_SERVER, nil, IClassFactory,
Factory);
CoInternetGetSession(0, InternetSession, 0);
InternetSession.RegisterMimeFilter(Factory, Class_OurMimeFilter, 'text/html');
end;
procedure UnRegisterMimeFilter;
begin
InternetSession.UnregisterMimeFilter(Factory, 'text/html');
end;
Temporary MIME filter (EmbeddedWB):
RegisterMimeFilter(Class_OurMimeFilter,'text/html');
UnRegisterMimeFilter('text/html');
(Make sure your mimefilter-fimename is placed before
EmbeddedWB in the USES-clauses.)
The demo was tested in D5 but should also work in D4.
Enjoy!
Update: February 5, 2000