00001 // This code based on an example retrieved from http://wiki.forum.nokia.com/index.php/Writing_an_HTTP_filter_plugin 00002 00003 // References: 00004 // http://wiki.forum.nokia.com/index.php/Writing_an_HTTP_filter_plugin 00005 // http://wiki.forum.nokia.com/index.php/TSS001070_-_Modifying_web_content_using_an_HTTP_filter 00006 // http://discussion.forum.nokia.com/forum/showthread.php?128548-How-to-monitor-S60-browser-to-get-the-details-of-URLs-visited-by-the-user 00007 // http://wiki.forum.nokia.com/index.php/CS000835_-_ECom:_Implementing_interface 00008 00009 #include "cl2webfilter.h" 00010 00011 #include "common/epoc-session.hpp" 00012 #include "common/logging.h" 00013 00014 #include <e32base.h> 00015 #include <e32property.h> 00016 #include <ecom/ecom.h> 00017 #include <ecom/implementationproxy.h> 00018 #include <http/cecomfilter.h> 00019 #include <http/mhttpfilter.h> 00020 #include <http/rhttptransaction.h> 00021 00022 _LIT8(KCl2WebFilterName, "cl2webfilter"); 00023 00024 class CCl2WebFilter : 00025 public CEComFilter, 00026 public MHTTPFilter 00027 { 00028 public: 00029 static CEComFilter* CreateFilterL(TAny* aHttpSession); 00030 00031 // virtuals from MHTTPFilter 00032 void MHFUnload(RHTTPSession aSession, THTTPFilterHandle aHandle); 00033 void MHFLoad(RHTTPSession aSession, THTTPFilterHandle aHandle); 00034 void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent); 00035 void MHFSessionRunL(const THTTPSessionEvent& aEvent); 00036 TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent); 00037 TInt MHFSessionRunError(TInt aError, const THTTPSessionEvent& aEvent); 00038 00039 ~CCl2WebFilter(); 00040 private: 00041 void ConstructL(RHTTPSession& aHttpSession); 00042 00043 private: 00044 RStringF iFilterName; 00045 DEF_SESSION(RProperty, iProperty); 00046 }; 00047 00048 CEComFilter* CCl2WebFilter::CreateFilterL(TAny* aHttpSession) 00049 { 00050 // The CEcomFilter class passes us a pointer to the RHTTPSession so we can install ourselves 00051 RHTTPSession* session = reinterpret_cast<RHTTPSession*>(aHttpSession); 00052 CCl2WebFilter* self = new (ELeave) CCl2WebFilter; 00053 CleanupStack::PushL(self); 00054 self->ConstructL(*session); 00055 CleanupStack::Pop(self); 00056 return self; 00057 } 00058 00059 CCl2WebFilter::~CCl2WebFilter() 00060 { 00061 iFilterName.Close(); 00062 SESSION_CLOSE_IF_OPEN(iProperty); 00063 } 00064 00065 void CCl2WebFilter::ConstructL(RHTTPSession& aSession) 00066 { 00067 TInt errCode = RProperty::Define(TUid::Uid(KCl2WebFilterCat), 00068 KCl2WebFilterKey, 00069 RProperty::EByteArray, 00070 256); 00071 if (errCode != KErrNone && errCode != KErrAlreadyExists) 00072 User::Leave(errCode); 00073 00074 LEAVE_IF_ERROR_OR_SET_SESSION_OPEN(iProperty, iProperty.Attach(TUid::Uid(KCl2WebFilterCat), KCl2WebFilterKey, EOwnerThread)); 00075 00076 // install this filter in to the current session 00077 iFilterName = aSession.StringPool().OpenFStringL(KCl2WebFilterName); 00078 aSession.FilterCollection().AddFilterL(*this, THTTPEvent::EAnyTransactionEvent, 00079 RStringF(), KAnyStatusCode, 00080 EClientFilters, iFilterName); 00081 } 00082 00083 void CCl2WebFilter::MHFUnload(RHTTPSession aSession, THTTPFilterHandle aHandle) 00084 { 00085 //logt("Demo Filter: HTTP filter unloaded."); 00086 00087 // self loading filters manage their own life cycle... 00088 delete this; 00089 } 00090 00091 void CCl2WebFilter::MHFLoad(RHTTPSession aSession, THTTPFilterHandle aHandle) 00092 { 00093 //logt("Demo Filter: HTTP filter loaded."); 00094 } 00095 00096 void CCl2WebFilter::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) 00097 { 00098 // Called when a RHTTPTransaction event happens. 00099 if (aEvent == THTTPEvent::ESubmit) 00100 { 00101 const TDesC8& uri = aTransaction.Request().URI().UriDes(); 00102 //logg("Demo Filter: New transaction submitted to '%S'", &uri); 00103 if (uri.Length() <= RProperty::KMaxPropertySize) 00104 // We ignore errors here. 00105 iProperty.Set(uri); 00106 } 00107 } 00108 00109 void CCl2WebFilter::MHFSessionRunL(const THTTPSessionEvent& aEvent) 00110 { 00111 // Called when an RHTTPSession event happens. 00112 } 00113 00114 TInt CCl2WebFilter::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent) 00115 { 00116 // Called when MHFRunL leaves. Our implementation never does. 00117 return KErrNone; 00118 } 00119 00120 TInt CCl2WebFilter::MHFSessionRunError(TInt aError, const THTTPSessionEvent& aEvent) 00121 { 00122 // Called when MHFSessionRunL leaves. Our implementation does nothing. 00123 return KErrNone; 00124 } 00125 00126 // standard ECOM initialisation 00127 00128 static const TImplementationProxy KImplementationTable[] = 00129 { 00130 IMPLEMENTATION_PROXY_ENTRY(0xe846000f, CCl2WebFilter::CreateFilterL) 00131 }; 00132 00133 EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) 00134 { 00135 aTableCount = sizeof(KImplementationTable) / sizeof(TImplementationProxy); 00136 return KImplementationTable; 00137 }
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:55 2011 by Doxygen 1.6.1