diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2005-08-18 01:31:23 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2005-08-18 01:31:23 +0800 |
commit | 3200b1592abd9f4ff0a020b3048bf6abf2cfb437 (patch) | |
tree | c3279ebeecc5cfdb545926155bb0a658f62aa826 /embed/mozilla | |
parent | 9dc72322ce56b9e377a1d889ea5bd4453f69ea47 (diff) | |
download | gsoc2013-epiphany-3200b1592abd9f4ff0a020b3048bf6abf2cfb437.tar gsoc2013-epiphany-3200b1592abd9f4ff0a020b3048bf6abf2cfb437.tar.gz gsoc2013-epiphany-3200b1592abd9f4ff0a020b3048bf6abf2cfb437.tar.bz2 gsoc2013-epiphany-3200b1592abd9f4ff0a020b3048bf6abf2cfb437.tar.lz gsoc2013-epiphany-3200b1592abd9f4ff0a020b3048bf6abf2cfb437.tar.xz gsoc2013-epiphany-3200b1592abd9f4ff0a020b3048bf6abf2cfb437.tar.zst gsoc2013-epiphany-3200b1592abd9f4ff0a020b3048bf6abf2cfb437.zip |
Add EPHY_EMBED_PERSIST_FROM_CACHE, and try harder to get a cache
2005-08-17 Christian Persch <chpe@cvs.gnome.org>
* embed/ephy-embed-persist.h:
* embed/mozilla/mozilla-embed-persist.cpp:
Add EPHY_EMBED_PERSIST_FROM_CACHE, and try harder to get a cache
descriptor for the source URL.
* src/popup-commands.c: (save_property_url),
(popup_cmd_set_image_as_background), (save_temp_source):
Use EPHY_EMBED_PERSIST_FROM_CACHE to try to get the content from
cache when saving background, images or links. Part of bug #168554.
Diffstat (limited to 'embed/mozilla')
-rw-r--r-- | embed/mozilla/mozilla-embed-persist.cpp | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp index 7c20d2f81..990ed0fbd 100644 --- a/embed/mozilla/mozilla-embed-persist.cpp +++ b/embed/mozilla/mozilla-embed-persist.cpp @@ -30,6 +30,7 @@ #include "EphyHeaderSniffer.h" #include "MozDownload.h" #include "EphyUtils.h" +#include "ephy-debug.h" #include <stddef.h> @@ -41,6 +42,9 @@ #include <nsIIOService.h> #include <nsNetCID.h> #include <nsNetError.h> +#include <nsICacheEntryDescriptor.h> +#include <nsICacheService.h> +#include <nsICacheSession.h> static void mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass); @@ -193,6 +197,7 @@ impl_save (EphyEmbedPersist *persist) /* Get post data */ nsCOMPtr<nsIInputStream> postData; + /* FIXME: don't do this on COPY_PAGE to ensure we don't end up reposting? */ if (browser) { PRInt32 sindex; @@ -227,17 +232,63 @@ impl_save (EphyEmbedPersist *persist) /* Get the current page descriptor */ - nsCOMPtr<nsISupports> pageDescriptor; + nsCOMPtr<nsISupports> cacheDescriptor; if (browser) { - browser->GetPageDescriptor(getter_AddRefs(pageDescriptor)); + browser->GetPageDescriptor(getter_AddRefs (cacheDescriptor)); } + /* Try to get a descriptor from the cache session */ + /* FIXME: what about https?? */ + PRBool isHttp = PR_FALSE, isHttps = PR_FALSE; + if (!cacheDescriptor && + (flags & EPHY_EMBED_PERSIST_FROM_CACHE) && + inURI && + ((NS_SUCCEEDED (inURI->SchemeIs ("http", &isHttp)) && isHttp) || + (NS_SUCCEEDED (inURI->SchemeIs ("https", &isHttps)) && isHttps ))) + { + nsCOMPtr<nsICacheService> cacheService + (do_GetService(NS_CACHESERVICE_CONTRACTID)); + if (cacheService) + { + nsCOMPtr<nsICacheSession> cacheSession; + rv = cacheService->CreateSession ("HTTP", + nsICache::STORE_ANYWHERE, + PR_TRUE, + getter_AddRefs (cacheSession)); + if (NS_SUCCEEDED (rv) && cacheSession) + { + nsCOMPtr<nsICacheEntryDescriptor> descriptor; + + nsEmbedCString spec; + inURI->GetSpec (spec); + +#ifdef HAVE_GECKO_1_8 + rv = cacheSession->OpenCacheEntry + (spec, + nsICache::ACCESS_READ, + PR_FALSE, getter_AddRefs (descriptor)); +#else + rv = cacheSession->OpenCacheEntry + (spec.get(), + nsICache::ACCESS_READ, + PR_FALSE, getter_AddRefs (descriptor)); +#endif + + cacheDescriptor = do_QueryInterface (descriptor); + + LOG ("Getting cache descriptor for '%s' rv=%x", spec.get(), rv); + } + } + } + + LOG ("Cache descriptor %p", cacheDescriptor.get()); + /* if we have COPY_PAGE, we *need* to have a page descriptor, else we'll re-fetch * the page, which will possibly give a different page than the original which we * need for view source */ - NS_ENSURE_TRUE (!(flags & EPHY_EMBED_PERSIST_COPY_PAGE) || pageDescriptor, FALSE); + NS_ENSURE_TRUE (!(flags & EPHY_EMBED_PERSIST_COPY_PAGE) || cacheDescriptor, FALSE); if (filename == NULL || filename[0] == '\0') { @@ -265,7 +316,7 @@ impl_save (EphyEmbedPersist *persist) if (!sniffer) return FALSE; webPersist->SetProgressListener(sniffer); - rv = webPersist->SaveURI(inURI, pageDescriptor, nsnull, nsnull, nsnull, tmpFile); + rv = webPersist->SaveURI(inURI, cacheDescriptor, nsnull /* FIXME: Referrer */, nsnull, nsnull, tmpFile); if (NS_FAILED (rv)) return FALSE; } else @@ -278,7 +329,7 @@ impl_save (EphyEmbedPersist *persist) rv = InitiateMozillaDownload (DOMDocument, inURI, destFile, nsnull, inURI, MOZILLA_EMBED_PERSIST (persist), - postData, pageDescriptor, max_size); + postData, cacheDescriptor, max_size); if (NS_FAILED (rv)) return FALSE; } |