Hi
I've been trying to get the pagesource via the cache, but that only
seems to work with some pages. Mainly simpler/strait ones like www.w3c.org.
The strange thing is that "about:cache?device=file" does seem to
contain the currently loaded page.
My code looks like this (using gtkmozembed): I fail with pages like
www.google.com on the ERROR 4,
OpenCacheEntry returns error.
Any help would really be appreciated
-Martin L
static void ex_nsCache1()
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMan;
rv = NS_GetServiceManager(getter_AddRefs(servMan));
if (NS_FAILED(rv)) {
printf ( "ERROR 1\n" ); return;
}
nsCOMPtr<nsICacheService> cacheService;
rv = servMan->GetServiceByContractID( "@mozilla.org/network/cache-
service;1" , NS_GET_IID(nsICacheService),
getter_AddRefs(cacheService));
if (NS_FAILED(rv)) {
printf ( "ERROR 2\n" ); return;
}
nsCOMPtr<nsICacheSession> cacheSession;
nsCacheStoragePolicy storagePolicy = nsICache::STORE_ON_DISK;
const char* sessionName = "HTTP";
switch (storagePolicy) {
case nsICache::STORE_IN_MEMORY:
sessionName = "HTTP-memory-only";
break;
case nsICache::STORE_OFFLINE:
sessionName = "HTTP-offline";
break;
default:
break;
}
rv = cacheService->CreateSession( sessionName , storagePolicy,
nsICache::STREAM_BASED , getter_AddRefs(cacheSession) );
if (NS_FAILED(rv)) {
printf ( "ERROR 3\n" ); return;
}
nsCAutoString cacheKey;
const char* szUrl = "http://www.doxys.dk/doxys_homepage/
index.html";
cacheKey.Append( szUrl );
nsCOMPtr<nsICacheEntryDescriptor> cacheEntry;
rv = cacheSession->OpenCacheEntry(cacheKey, nsICache::ACCESS_READ,
PR_TRUE, getter_AddRefs(cacheEntry));
// FAILS HERE with pages like www.google.com
if (NS_FAILED(rv)) {
printf ( "ERROR 4: %d\n", rv ); return;
}
nsCOMPtr<nsIInputStream> cacheEntryStream;
rv = cacheEntry->OpenInputStream( 0,
getter_AddRefs(cacheEntryStream) );
if (NS_FAILED(rv)) {
printf ( "ERROR 5: %d\n", rv ); return;
}
PRUint32 iStreamLen;
PRUint32 iBytesRead;
PRBool bNonBlocking;
rv = cacheEntryStream->Available( &iStreamLen );
if (NS_FAILED(rv)) {
printf ( "ERROR 6: %d\n", rv ); return;
}
rv = cacheEntryStream->IsNonBlocking( &bNonBlocking );
char szBuf[iStreamLen+1];
rv = cacheEntryStream->Read( szBuf, iStreamLen, &iBytesRead);
if (NS_FAILED(rv)) {
printf ( "ERROR 7: %d\n", rv ); return;
}
printf("iBytesRead: %d\n", iBytesRead );
printf("----------------------------\n");
printf("%s\n", szBuf );
printf("----------------------------\n");
}
_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding