From 17cf0ba3256455d450aa539fcb8850057bd361e1 Mon Sep 17 00:00:00 2001 From: "pnunn%netscape.com" Date: Sat, 12 Feb 2000 01:51:57 +0000 Subject: [PATCH] bug# 21036: Change imglib reload policies to work with necko load attributes. pnunn, r:neeti,dp. git-svn-id: svn://10.0.0.236/trunk@60563 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/src/nsImageNetContextAsync.cpp | 23 ++++++++++++++++++++-- mozilla/gfx/src/nsImageNetContextSync.cpp | 2 +- mozilla/include/ntypes.h | 21 +++++++++++++------- mozilla/modules/libimg/src/if.cpp | 5 ++--- mozilla/modules/libimg/src/if.h | 4 ++-- mozilla/modules/libimg/src/ilclient.cpp | 16 +++++---------- 6 files changed, 45 insertions(+), 26 deletions(-) diff --git a/mozilla/gfx/src/nsImageNetContextAsync.cpp b/mozilla/gfx/src/nsImageNetContextAsync.cpp index a452e6e4e8e..5667f1865c4 100644 --- a/mozilla/gfx/src/nsImageNetContextAsync.cpp +++ b/mozilla/gfx/src/nsImageNetContextAsync.cpp @@ -674,7 +674,26 @@ ImageNetContextImpl::GetURL (ilIURL * aURL, if (bIsBackground) { (void)channel->SetLoadAttributes(nsIChannel::LOAD_BACKGROUND); } - + switch(aLoadMethod){ + case IMG_CACHE_ONLY: + /* should never get here, but don't fail if you do. */ + case IMG_NTWK_SERVER: + (void)channel->SetLoadAttributes(nsIChannel::VALIDATE_NEVER); + break; + + case TV_IMG_NTWK_SERVER: + case TV_NTWK_SERVER_ONLY: + (void)channel->SetLoadAttributes(nsIChannel::FORCE_VALIDATION); + break; + + case SERVER_ONLY: + (void)channel->SetLoadAttributes(nsIChannel::FORCE_RELOAD); + break; + + default: + break; + } + nsCOMPtr window (do_QueryInterface(NS_STATIC_CAST(nsIStreamListener *, ic))); // let's try uri dispatching... @@ -726,7 +745,7 @@ NS_NewImageNetContext(ilINetContext **aInstancePtrResult, return NS_ERROR_NULL_POINTER; } - ilINetContext *cx = new ImageNetContextImpl(NET_NORMAL_RELOAD, + ilINetContext *cx = new ImageNetContextImpl(TV_IMG_NTWK_SERVER, aLoadGroup, aReconnectCallback, aReconnectArg); diff --git a/mozilla/gfx/src/nsImageNetContextSync.cpp b/mozilla/gfx/src/nsImageNetContextSync.cpp index f07fc50eb12..7b2738d0df6 100644 --- a/mozilla/gfx/src/nsImageNetContextSync.cpp +++ b/mozilla/gfx/src/nsImageNetContextSync.cpp @@ -293,7 +293,7 @@ nsresult NS_NewImageNetContextSync(ilINetContext **aInstancePtrResult) return NS_ERROR_NULL_POINTER; } - ilINetContext *cx = new ImageNetContextSyncImpl(NET_NORMAL_RELOAD); + ilINetContext *cx = new ImageNetContextSyncImpl(TV_IMG_NTWK_SERVER); if (cx == nsnull) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/mozilla/include/ntypes.h b/mozilla/include/ntypes.h index a1863594570..34f5951195f 100644 --- a/mozilla/include/ntypes.h +++ b/mozilla/include/ntypes.h @@ -40,15 +40,22 @@ typedef struct _NET_StreamClass NET_StreamClass; typedef struct OpaqueCCCDataObject *CCCDataObject; typedef struct OpaqueINTL_CharSetInfo *INTL_CharSetInfo; -/* How to refill when there's a cache miss */ +/* This lists the data input policies for the image lib. + Note that only the last 3 policies request server validation of + image data. These policies are very distinct from the netlib + cache attributes, but are used to set the netlib cache attributes + for a specific image request. +*/ typedef enum NET_ReloadMethod { - NET_DONT_RELOAD, /* use the cache */ - NET_RESIZE_RELOAD, /* use the cache -- special for resizing */ - NET_NORMAL_RELOAD, /* use IMS gets for reload */ - NET_SUPER_RELOAD, /* retransfer everything */ - NET_CACHE_ONLY_RELOAD /* Don't do anything if we miss in the cache. - (For the image library) */ + IMG_CACHE_ONLY, /* imgcache, no validation, don't go to netlib cache */ + IMG_NTWK_SERVER, /* imgcache 1st, netcache 2nd, server 3rd, no initial validation */ + TV_IMG_NTWK_SERVER, /* test validation, use imgcache first. This is now + implemented as TV_NTWK_SERVER_ONLY, since the image cache + is not saved once we know we have to check with the server anyway. + */ + TV_NTWK_SERVER_ONLY, /* test validation, use necko cache first */ + SERVER_ONLY, /* server only, force_reload */ } NET_ReloadMethod; /* diff --git a/mozilla/modules/libimg/src/if.cpp b/mozilla/modules/libimg/src/if.cpp index 0912e634c5a..28520bde3a4 100644 --- a/mozilla/modules/libimg/src/if.cpp +++ b/mozilla/modules/libimg/src/if.cpp @@ -1482,7 +1482,7 @@ il_image_complete(il_container *ic) ILTRACE(1,("il: loop %s", ic->url_address)); if(ic->net_cx){ //ptn test - netRequest = ic->net_cx->CreateURL(ic->fetch_url, NET_DONT_RELOAD); + netRequest = ic->net_cx->CreateURL(ic->fetch_url, IMG_NTWK_SERVER); if (!netRequest) { /* OOM */ il_container_complete(ic); break; @@ -1542,8 +1542,7 @@ il_image_complete(il_container *ic) /* Call to netlib for net cache data happens here. */ netRequest->SetBackgroundLoad(PR_TRUE); reader = IL_NewNetReader(ic); - (void) ic->net_cx->GetURL(ic->url, NET_CACHE_ONLY_RELOAD /*NET_DONT_RELOAD*/, - reader); + (void) ic->net_cx->GetURL(ic->url, IMG_NTWK_SERVER, reader); /* Release reader, GetURL will keep a ref to it. */ NS_RELEASE(reader); } else { diff --git a/mozilla/modules/libimg/src/if.h b/mozilla/modules/libimg/src/if.h index 0ddb3cc28c0..8c3bd7e9eae 100644 --- a/mozilla/modules/libimg/src/if.h +++ b/mozilla/modules/libimg/src/if.h @@ -22,7 +22,7 @@ /* if.h --- Top-level image library internal routines * - * $Id: if.h,v 3.17 1999-12-03 01:07:49 pnunn%netscape.com Exp $ + * $Id: if.h,v 3.18 2000-02-12 01:49:35 pnunn%netscape.com Exp $ */ #ifndef _if_h @@ -162,7 +162,7 @@ enum icstate { /* Force memory cache to be flushed ? */ #define FORCE_RELOAD(reload_method) \ - (((reload_method)==NET_NORMAL_RELOAD) || ((reload_method)==NET_SUPER_RELOAD)) + (reload_method > IMG_NTWK_SERVER) /* Simple list of image contexts. */ struct il_context_list { diff --git a/mozilla/modules/libimg/src/ilclient.cpp b/mozilla/modules/libimg/src/ilclient.cpp index 31787f797f5..51fb7f22cf7 100644 --- a/mozilla/modules/libimg/src/ilclient.cpp +++ b/mozilla/modules/libimg/src/ilclient.cpp @@ -429,10 +429,9 @@ il_get_container(IL_GroupContext *img_cx, ic = il_find_in_cache(img_cx->display_type, hash, image_url, background_color, req_depth, req_width, req_height); - if (ic) { + if (ic) { - /* We already started to discard this image container. - Make a new one.*/ + /* This ic is being destroyed. Need a new one */ if ((ic->state == IC_ABORT_PENDING)) ic = NULL; @@ -444,14 +443,9 @@ il_get_container(IL_GroupContext *img_cx, /* 2) Their namespace crosses document boundaries, so caching */ /* could result in incorrect behavior. */ - else if((cache_reload_policy == NET_SUPER_RELOAD) || - ((cache_reload_policy == NET_NORMAL_RELOAD) && (!ic->forced)) || - (cache_reload_policy != NET_CACHE_ONLY_RELOAD && - ic->expires && (time(NULL) > ic->expires)) - ) { - /* Get rid of the old copy of the image that we're replacing. */ - if (!ic->is_in_use) - { + else if(cache_reload_policy > IMG_NTWK_SERVER){ + /* Don't use old copy and purge it from cache.*/ + if (!ic->is_in_use) { il_removefromcache(ic); il_delete_container(ic); }