MIME-filter
NewsProductsDownloadsSupportForumCredits

TEmbeddedWB 
History 
HtmlEdit 
TIEAddress 
TIEDownload 
TIEDownloadManager 
IEGuid 
TIEParser 
Favorites 
TIESecurityManager 
IE5Tools 
TIETravelLog 
TLinksBar 
Protocols 
TRichEditWB 
TWebUpdater 
ResourceTool 
UI - lessParser 
Delphi Links 
[Home][Support][Protocols][MIME-filter]


NameSpaceHandlerMIME-filterPluggable protocol

 

Mime Filter:

 

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 'Porn' with <BEEP>.

A pluggable MIME filter is an asynchronous pluggable protocol that receives data through a stream, performs some operation on the data, and returns a data stream. The output data might be in a different format from the original stream.
Multiple pluggable MIME filters can be registered either temporarily or permanently. Temporarily registered pluggable MIME filters are called first, in the reverse order in which they were registered.
So pluggable MIME filters registered last will be called first.
All asynchronous pluggable MIME filters must support the BINDF_NO_UI and BINDF_SILENTOPERATION flags.
Also, pluggable MIME filters are only invoked by browser for the resource specified by the URL. The MIME filter will not be invoked for other resources (such as images on an HTML page) that are associated with the resource specified by the URL.
The MimeFilter manipulates the data stream it receives and returns a data stream for any resources of the specified MIME type.

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 available.
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 permanent 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.


Notes:
1. Add ComServ to your uses cloud.
2. Make sure your MimeFilter-FileName is placed before EmbeddedWB in the USES-cloud.
3. Check out our demo. It has all the details you need.
4.
There are web sites like msn.com, forums and so on where the paged html code gives E_PENDING state (...Wait to complete...) or any page that it's download state is "Done but with errors"
In this case, the mime filter don't get the E_FALSE state (all data available). So, the ComServer still has an open connection to the server.
We use ComServer.UIInteractive to disable it and all the connection will be closed on destroy.
5. Use EmbeddedWB DownloadOptions to disable ActiveX controls and so on that do not interact with the MimeFilter.

6.
The MimeFilter in the demo is connected/registered when ever the application starts!

From our demo:
var
Factory: IClassFactory;
InternetSession: IInternetSession;
bConnected: Boolean;

procedure RegisterMimeFilter;
begin
   if Succeeded(CoInternetGetSession(0, InternetSession, 0))
      and Succeeded(CoGetClassObject(Class_StrMimeFilter, CLSCTX_SERVER, nil, IClassFactory, Factory))
      and Succeeded(InternetSession.RegisterMimeFilter(Factory, Class_StrMimeFilter, 'text/html')) then
      bConnected := True;

end;

procedure UnRegisterMimeFilter;
begin
   if bConnected then
      begin
         if Succeeded(InternetSession.UnregisterMimeFilter(Factory, 'text/html')) then
            bConnected := False;
         ComServer.UIInteractive := False;
      end;
end;

Implementation:

RegisterMimeFilter(Class_OurMimeFilter,'text/html');

UnRegisterMimeFilter('text/html');



For more info, You can use our forum  or MSDN:
Handling MIME Types in Internet Explorer
About Asynchronous Pluggable Protocols 
MIME Type Detection in Internet Explorer 
IInternetSession Interface 
IInternetProtoco
IInternetProtocolRoot
IInternetProtocolSink 

Our demo is includded in the components pack.

[Previous][Up][Next]

Created by
Eran Bodankin

Copyright (c) 2005 bsalsa productions. All rights reserved.

bsalsa@bsalsa.no-ip.info