From 3200b1592abd9f4ff0a020b3048bf6abf2cfb437 Mon Sep 17 00:00:00 2001 From: Christian Persch Date: Wed, 17 Aug 2005 17:31:23 +0000 Subject: Add EPHY_EMBED_PERSIST_FROM_CACHE, and try harder to get a cache 2005-08-17 Christian Persch * 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. --- ChangeLog | 14 ++++++++ embed/ephy-embed-persist.h | 3 +- embed/mozilla/mozilla-embed-persist.cpp | 61 ++++++++++++++++++++++++++++++--- src/popup-commands.c | 11 +++--- 4 files changed, 78 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5cbe523bf..df7422c48 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-08-17 Christian Persch + + * 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. + 2005-08-17 Christian Persch * src/ephy-tab.c: (ephy_tab_set_loading_title), diff --git a/embed/ephy-embed-persist.h b/embed/ephy-embed-persist.h index dfccaa719..005327b1c 100644 --- a/embed/ephy-embed-persist.h +++ b/embed/ephy-embed-persist.h @@ -48,7 +48,8 @@ typedef enum EPHY_EMBED_PERSIST_MAINDOC = 1 << 1, EPHY_EMBED_PERSIST_NO_VIEW = 1 << 2, EPHY_EMBED_PERSIST_ASK_DESTINATION = 1 << 3, - EPHY_EMBED_PERSIST_DO_CONVERSION = 1 << 4 + EPHY_EMBED_PERSIST_DO_CONVERSION = 1 << 4, + EPHY_EMBED_PERSIST_FROM_CACHE = 1 << 5 } EphyEmbedPersistFlags; struct _EphyEmbedPersist 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 @@ -41,6 +42,9 @@ #include #include #include +#include +#include +#include static void mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass); @@ -193,6 +197,7 @@ impl_save (EphyEmbedPersist *persist) /* Get post data */ nsCOMPtr 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 pageDescriptor; + nsCOMPtr 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 cacheService + (do_GetService(NS_CACHESERVICE_CONTRACTID)); + if (cacheService) + { + nsCOMPtr cacheSession; + rv = cacheService->CreateSession ("HTTP", + nsICache::STORE_ANYWHERE, + PR_TRUE, + getter_AddRefs (cacheSession)); + if (NS_SUCCEEDED (rv) && cacheSession) + { + nsCOMPtr 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; } diff --git a/src/popup-commands.c b/src/popup-commands.c index a637241cd..bd76c3825 100644 --- a/src/popup-commands.c +++ b/src/popup-commands.c @@ -199,11 +199,11 @@ save_property_url (GtkAction *action, persist = EPHY_EMBED_PERSIST (ephy_embed_factory_new_object (EPHY_TYPE_EMBED_PERSIST)); - ephy_embed_persist_set_embed (persist, embed); ephy_embed_persist_set_fc_title (persist, title); ephy_embed_persist_set_fc_parent (persist, GTK_WINDOW (window)); ephy_embed_persist_set_flags - (persist, ask_dest ? EPHY_EMBED_PERSIST_ASK_DESTINATION : 0); + (persist, EPHY_EMBED_PERSIST_FROM_CACHE | + (ask_dest ? EPHY_EMBED_PERSIST_ASK_DESTINATION : 0)); ephy_embed_persist_set_persist_key (persist, CONF_STATE_SAVE_DIR); ephy_embed_persist_set_source (persist, location); @@ -309,9 +309,9 @@ popup_cmd_set_image_as_background (GtkAction *action, base_converted = g_filename_from_utf8 (base, -1, NULL, NULL, NULL); dest = g_build_filename (ephy_dot_dir (), base_converted, NULL); - ephy_embed_persist_set_embed (persist, embed); ephy_embed_persist_set_dest (persist, dest); - ephy_embed_persist_set_flags (persist, EPHY_EMBED_PERSIST_NO_VIEW); + ephy_embed_persist_set_flags (persist, EPHY_EMBED_PERSIST_NO_VIEW | + EPHY_EMBED_PERSIST_FROM_CACHE); ephy_embed_persist_set_source (persist, location); g_signal_connect (persist, "completed", @@ -421,7 +421,8 @@ save_temp_source (const char *address) (ephy_embed_factory_new_object (EPHY_TYPE_EMBED_PERSIST)); ephy_embed_persist_set_source (persist, address); - ephy_embed_persist_set_flags (persist, EPHY_EMBED_PERSIST_NO_VIEW); + ephy_embed_persist_set_flags (persist, EPHY_EMBED_PERSIST_FROM_CACHE | + EPHY_EMBED_PERSIST_NO_VIEW); ephy_embed_persist_set_dest (persist, tmp); g_signal_connect (persist, "completed", -- cgit v1.2.3