bug 166648 - allow link prefetching to be disabled via user prefs. r-dougt, sr-alecf, a-asa.

This commit is contained in:
suresh%netscape.com 2003-01-27 22:23:28 +00:00
Родитель f1caad5c41
Коммит 4053b81c11
5 изменённых файлов: 108 добавлений и 77 удалений

Просмотреть файл

@ -40,7 +40,7 @@
#include "nsICategoryManager.h"
#include "nsIObserverService.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsIPrefBranchInternal.h"
#include "nsIDocCharset.h"
#include "nsIWebProgress.h"
#include "nsCURILoader.h"
@ -74,6 +74,8 @@ static PRLogModuleInfo *gPrefetchLog;
static NS_DEFINE_IID(kDocLoaderServiceCID, NS_DOCUMENTLOADER_SERVICE_CID);
static NS_DEFINE_IID(kPrefServiceCID, NS_PREFSERVICE_CID);
#define PREFETCH_PREF "network.prefetch-next"
//-----------------------------------------------------------------------------
// helpers
//-----------------------------------------------------------------------------
@ -203,7 +205,7 @@ nsPrefetchService::nsPrefetchService()
: mQueueHead(nsnull)
, mQueueTail(nsnull)
, mStopCount(0)
, mDisabled(PR_FALSE)
, mDisabled(PR_TRUE)
{
}
@ -224,19 +226,20 @@ nsPrefetchService::Init()
nsresult rv;
// Verify that "network.prefetch-next" preference is set to true. Skip
// this step if we encounter any errors.
// read prefs and hook up pref observer
nsCOMPtr<nsIPrefService> prefServ(do_GetService(kPrefServiceCID, &rv));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIPrefBranch> prefs;
rv = prefServ->GetBranch(nsnull, getter_AddRefs(prefs));
if (NS_SUCCEEDED(rv)) {
PRBool enabled;
rv = prefs->GetBoolPref("network.prefetch-next", &enabled);
if (NS_SUCCEEDED(rv) && !enabled) {
LOG(("nsPrefetchService disabled via preferences\n"));
return NS_ERROR_ABORT;
}
rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled);
if (NS_SUCCEEDED(rv) && enabled)
mDisabled = PR_FALSE;
nsCOMPtr<nsIPrefBranchInternal> prefsInt(do_QueryInterface(prefs));
if (prefsInt)
prefsInt->AddObserver(PREFETCH_PREF, this, PR_TRUE);
}
}
@ -247,12 +250,11 @@ nsPrefetchService::Init()
rv = observerServ->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE);
if (NS_FAILED(rv)) return rv;
// Register as an observer for the document loader
nsCOMPtr<nsIWebProgress> progress(do_GetService(kDocLoaderServiceCID, &rv));
if (NS_FAILED(rv)) return rv;
return progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
if (!mDisabled)
AddProgressListener();
return NS_OK;
}
void
@ -305,6 +307,24 @@ nsPrefetchService::ProcessNextURI()
// nsPrefetchService <private>
//-----------------------------------------------------------------------------
void
nsPrefetchService::AddProgressListener()
{
// Register as an observer for the document loader
nsCOMPtr<nsIWebProgress> progress(do_GetService(kDocLoaderServiceCID));
if (progress)
progress->AddProgressListener(this, nsIWebProgress::NOTIFY_STATE_DOCUMENT);
}
void
nsPrefetchService::RemoveProgressListener()
{
// Register as an observer for the document loader
nsCOMPtr<nsIWebProgress> progress(do_GetService(kDocLoaderServiceCID));
if (progress)
progress->RemoveProgressListener(this);
}
nsresult
nsPrefetchService::EnqueueURI(nsIURI *aURI, nsIURI *aReferrerURI)
{
@ -576,6 +596,26 @@ nsPrefetchService::Observe(nsISupports *aSubject,
StopPrefetching();
mDisabled = PR_TRUE;
}
else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
nsCOMPtr<nsIPrefBranch> prefs(do_QueryInterface(aSubject));
PRBool enabled;
nsresult rv = prefs->GetBoolPref(PREFETCH_PREF, &enabled);
if (NS_SUCCEEDED(rv) && enabled) {
if (mDisabled) {
LOG(("enabling prefetching\n"));
mDisabled = PR_FALSE;
AddProgressListener();
}
}
else {
if (!mDisabled) {
LOG(("disabling prefetching\n"));
StopPrefetching();
mDisabled = PR_TRUE;
RemoveProgressListener();
}
}
}
return NS_OK;
}

Просмотреть файл

@ -75,6 +75,8 @@ public:
private:
void AddProgressListener();
void RemoveProgressListener();
nsresult EnqueueURI(nsIURI *aURI, nsIURI *aReferrerURI);
nsresult DequeueURI(nsIURI **aURI, nsIURI **aReferrerURI);
void EmptyQueue();

Просмотреть файл

@ -89,12 +89,8 @@ function prefClearCache(aType)
cacheService.evictEntries(aType);
}
function prefClearMemCache()
{
prefClearCache(Components.interfaces.nsICache.STORE_IN_MEMORY);
}
function prefClearDiskCache()
function prefClearDiskAndMemCache()
{
prefClearCache(Components.interfaces.nsICache.STORE_ON_DISK);
prefClearCache(Components.interfaces.nsICache.STORE_IN_MEMORY);
}

Просмотреть файл

@ -37,7 +37,7 @@
<script type="application/x-javascript">
<![CDATA[
var _elementIDs = ["browserCacheMemoryCache", "browserCacheDiskCache", "browserCacheCheckDocFrequency"];
var _elementIDs = ["browserCacheDiskCache", "browserCacheCheckDocFrequency", "enablePrefetch"];
]]>
</script>
@ -50,62 +50,53 @@
<description>&cachePara;</description>
<grid>
<columns>
<column/>
<column flex="1"/>
<column/>
</columns>
<rows>
<row align="center">
<label value="&memCache.label;" accesskey="&memCache.accesskey;" control="browserCacheMemoryCache"/>
<hbox align="center">
<textbox id="browserCacheMemoryCache" size="8" preftype="int"
prefstring="browser.cache.memory.capacity"/>
<label value="&kbytes;"/>
</hbox>
<button label="&clearMemCache.label;" accesskey="&clearMemCache.accesskey;"
oncommand="prefClearMemCache();"
id="clearMemCache"
prefstring="pref.advanced.cache.disable_button.clear_memory"/>
</row>
<row align="center">
<label value="&diskCache.label;" accesskey="&diskCache.accesskey;" control="browserCacheDiskCache"/>
<hbox align="center">
<textbox id="browserCacheDiskCache" size="8" preftype="int"
prefstring="browser.cache.disk.capacity" prefattribute="value"/>
<label value="&kbytes;"/>
</hbox>
<button label="&clearDiskCache.label;" accesskey="&clearDiskCache.accesskey;"
oncommand="prefClearDiskCache();"
id="clearDiskCache"
prefstring="pref.advanced.cache.disable_button.clear_disk"/>
</row>
</rows>
</grid>
<hbox flex="1" align="center">
<label value="&diskCache.label;" accesskey="&diskCache.accesskey;" control="browserCacheDiskCache"/>
<textbox id="browserCacheDiskCache" size="8" preftype="int"
prefstring="browser.cache.disk.capacity" prefattribute="value"/>
<label value="&kbytes;"/>
<button label="&clearDiskCache.label;" accesskey="&clearDiskCache.accesskey;"
oncommand="prefClearDiskAndMemCache();"
id="clearDiskCache"
prefstring="pref.advanced.cache.disable_button.clear_disk"/>
</hbox>
<hbox align="center">
<vbox>
<label value="&diskCacheFolder.label;"/>
<textbox id="browserCacheDiskCacheFolder" flex="1" readonly="true" class="uri-element"/>
</hbox>
<hbox align="center" pack="end">
<button label="&chooseDiskCacheFolder.label;" accesskey="&chooseDiskCacheFolder.accesskey;"
<hbox align="center" flex="1">
<textbox id="browserCacheDiskCacheFolder" flex="1" readonly="true" class="uri-element"/>
<button label="&chooseDiskCacheFolder.label;" accesskey="&chooseDiskCacheFolder.accesskey;"
oncommand="prefCacheSelectFolder();" id="chooseDiskCacheFolder"/>
</hbox>
</hbox>
</vbox>
<description>&diskCacheFolderExplanation;</description>
<separator class="thin"/>
<description>&docCache;</description>
<vbox align="start">
<radiogroup id="browserCacheCheckDocFrequency" prefstring="browser.cache.check_doc_frequency">
<radio value="1" label="&everyTimeRadio.label;" accesskey="&everyTimeRadio.accesskey;"/>
<radio value="3" label="&autoRadio.label;" accesskey="&autoRadio.accesskey;"/>
<radio value="0" label="&oncePsessionRadio.label;" accesskey="&oncePsessionRadio.accesskey;"/>
<radio value="2" label="&neverRadio.label;" accesskey="&neverRadio.accesskey;"/>
<hbox align="start">
<radiogroup id="browserCacheCheckDocFrequency" orient="horizontal" prefstring="browser.cache.check_doc_frequency">
<vbox flex="1">
<radio value="1" label="&everyTimeRadio.label;" accesskey="&everyTimeRadio.accesskey;"/>
<radio value="3" label="&autoRadio.label;" accesskey="&autoRadio.accesskey;"/>
</vbox>
<vbox flex="1">
<radio value="0" label="&oncePsessionRadio.label;" accesskey="&oncePsessionRadio.accesskey;"/>
<radio value="2" label="&neverRadio.label;" accesskey="&neverRadio.accesskey;"/>
</vbox>
</radiogroup>
</vbox>
</hbox>
</groupbox>
<groupbox id="prefetch">
<caption id="prefetchLabel" label="&prefetchTitle.label;"/>
<vbox id="prefetchBox" align="start">
<checkbox id="enablePrefetch" label="&enablePrefetch.label;" accesskey="&enablePrefetch.accesskey;"
prefstring="network.prefetch-next" />
<!-- <vbox class="indent" flex="1">
<description>&prefetchDesc.label;</description>
</vbox> -->
</vbox>
</groupbox>
</page>

Просмотреть файл

@ -3,16 +3,12 @@
<!--LOCALIZATION NOTE : FILE Cache prefs dialog -->
<!ENTITY lHeader "Cache">
<!ENTITY cacheTitle.label "Set Cache Options">
<!ENTITY cachePara "The cache keeps copies of frequently visited web pages on your hard disk. This reduces the amount of time you are connected to the Internet. (Clicking Reload always shows you the latest version of a page.)">
<!ENTITY memCache.label "Memory Cache:">
<!ENTITY memCache.accesskey "M">
<!ENTITY diskCache.label "Disk Cache:">
<!ENTITY diskCache.accesskey "d">
<!ENTITY cachePara "The cache keeps copies of frequently visited web pages on your hard disk. (Clicking Reload always shows you the latest version of a page.)">
<!ENTITY diskCache.label "Cache:">
<!ENTITY diskCache.accesskey "c">
<!ENTITY kbytes "KB">
<!ENTITY diskCacheFolder.label "Disk Cache Folder:">
<!ENTITY clearMemCache.label "Clear Memory Cache">
<!ENTITY clearMemCache.accesskey "C">
<!ENTITY clearDiskCache.label "Clear Disk Cache">
<!ENTITY diskCacheFolder.label "Cache Folder:">
<!ENTITY clearDiskCache.label "Clear Cache">
<!ENTITY clearDiskCache.accesskey "l">
<!ENTITY chooseDiskCacheFolder.label "Choose Folder...">
<!ENTITY chooseDiskCacheFolder.accesskey "h">
@ -28,3 +24,9 @@
<!ENTITY neverRadio.accesskey "n">
<!ENTITY autoRadio.label "When the page is out of date">
<!ENTITY autoRadio.accesskey "w">
<!ENTITY prefetchTitle.label "Link Prefetching">
<!-- <!ENTITY enablePrefetch.label "Enable link prefetching"> -->
<!ENTITY enablePrefetch.label "Prefetch web pages when idle, so that links in web pages designed for prefetching can load faster.">
<!ENTITY enablePrefetch.accesskey "p">
<!-- <!ENTITY prefetchDesc.label "If you check this item, &brandShortName; will follow special directives from websites to prefetch content while the browser is idle. Websites designed to take advantage of this feature will appear to load quicker."> -->