Fix bug # 21669: The Related Links datasource needs to observe user preferences, at least for the "skip these domains" list (which can contain wildcards, such as "*.mcom.com") Approval: chofmann

This commit is contained in:
rjc%netscape.com 1999-12-18 03:51:16 +00:00
Родитель fda9dc2a0c
Коммит 6439a438cd
3 изменённых файлов: 145 добавлений и 13 удалений

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

@ -28,8 +28,8 @@
function debug(msg)
{
// uncomment for noise
//dump(msg);
// uncomment for noise
// dump(msg);
}
// The content window that we're supposed to be observing.
@ -59,6 +59,67 @@ var Observer = {
function
skipRelatedLinksDomain(newDomain)
{
var skipDomainFlag = false;
if (newDomain[newDomain.length - 1] == '/')
{
newDomain = newDomain.substring(0, newDomain.length - 1);
}
try
{
var pref = Components.classes["component://netscape/preferences"];
if (pref) pref = pref.getService();
if (pref) pref = pref.QueryInterface(Components.interfaces.nsIPref);
if (pref)
{
var domainList = pref.CopyCharPref("browser.related.disabledForDomains");
if ((domainList) && (domainList != ""))
{
debug("\nProposed New Domain: '" + newDomain + "'\n");
debug("Skip Domain List: '" + domainList + "'\n");
var domains = domainList.split(","); // split on commas
for (var x=0; x < domains.length; x++)
{
var aDomain = newDomain;
var domain = domains[x];
debug("Skip Domain #" + x + ": " + domain + "\n");
if (domain[0] == '*') // wildcard match
{
debug(" Wildcard domain.\n");
domain = domain.substring(1); // strip off the asterisk
if (aDomain.length > domain.length)
{
aDomain = aDomain.substring(newDomain.length-domain.length);
}
}
if (aDomain.lastIndexOf(domain) == 0)
{
debug(" Skip this domain '" + aDomain + "'\n");
skipDomainFlag = true;
break;
}
}
}
}
}
catch(ex)
{
}
return(skipDomainFlag);
}
function refetchRelatedLinks(Handler, data)
{
var newSite = "" + data;
@ -79,7 +140,7 @@ function refetchRelatedLinks(Handler, data)
// we can only get related links data on HTTP URLs
if (newSite.indexOf("http://") != 0)
{
dump("Unable to fetch related links data on non-HTTP URL.\n");
debug("Unable to fetch related links data on non-HTTP URL.\n");
return(false);
}
newSite = newSite.substr(7); // strip off "http://" prefix
@ -112,7 +173,10 @@ function refetchRelatedLinks(Handler, data)
theSite = theSite.substr(0, questionOffset);
}
Handler.URL = theSite;
if (skipRelatedLinksDomain(newSite) != true)
{
Handler.URL = theSite;
}
}
}
@ -202,7 +266,6 @@ function openURL(treeitem, root)
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (target) target = target.Value;
if (target) id = target;
}
}
}

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

@ -28,8 +28,8 @@
function debug(msg)
{
// uncomment for noise
//dump(msg);
// uncomment for noise
// dump(msg);
}
// The content window that we're supposed to be observing.
@ -59,6 +59,67 @@ var Observer = {
function
skipRelatedLinksDomain(newDomain)
{
var skipDomainFlag = false;
if (newDomain[newDomain.length - 1] == '/')
{
newDomain = newDomain.substring(0, newDomain.length - 1);
}
try
{
var pref = Components.classes["component://netscape/preferences"];
if (pref) pref = pref.getService();
if (pref) pref = pref.QueryInterface(Components.interfaces.nsIPref);
if (pref)
{
var domainList = pref.CopyCharPref("browser.related.disabledForDomains");
if ((domainList) && (domainList != ""))
{
debug("\nProposed New Domain: '" + newDomain + "'\n");
debug("Skip Domain List: '" + domainList + "'\n");
var domains = domainList.split(","); // split on commas
for (var x=0; x < domains.length; x++)
{
var aDomain = newDomain;
var domain = domains[x];
debug("Skip Domain #" + x + ": " + domain + "\n");
if (domain[0] == '*') // wildcard match
{
debug(" Wildcard domain.\n");
domain = domain.substring(1); // strip off the asterisk
if (aDomain.length > domain.length)
{
aDomain = aDomain.substring(newDomain.length-domain.length);
}
}
if (aDomain.lastIndexOf(domain) == 0)
{
debug(" Skip this domain '" + aDomain + "'\n");
skipDomainFlag = true;
break;
}
}
}
}
}
catch(ex)
{
}
return(skipDomainFlag);
}
function refetchRelatedLinks(Handler, data)
{
var newSite = "" + data;
@ -79,7 +140,7 @@ function refetchRelatedLinks(Handler, data)
// we can only get related links data on HTTP URLs
if (newSite.indexOf("http://") != 0)
{
dump("Unable to fetch related links data on non-HTTP URL.\n");
debug("Unable to fetch related links data on non-HTTP URL.\n");
return(false);
}
newSite = newSite.substr(7); // strip off "http://" prefix
@ -112,7 +173,10 @@ function refetchRelatedLinks(Handler, data)
theSite = theSite.substr(0, questionOffset);
}
Handler.URL = theSite;
if (skipRelatedLinksDomain(newSite) != true)
{
Handler.URL = theSite;
}
}
}
@ -202,7 +266,6 @@ function openURL(treeitem, root)
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (target) target = target.Value;
if (target) id = target;
}
}
}

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

@ -546,6 +546,7 @@ private:
static nsIRDFResource *kNC_Child;
static nsIRDFResource *kNC_Name;
static nsIRDFResource *kRDF_type;
static nsIRDFResource *kNC_RelatedLinksTopic;
nsCOMPtr<nsIRDFDataSource> mInner;
@ -629,6 +630,7 @@ nsIRDFService *RelatedLinksHandlerImpl::gRDFService;
nsIRDFResource *RelatedLinksHandlerImpl::kNC_RelatedLinksRoot;
nsIRDFResource *RelatedLinksHandlerImpl::kRDF_type;
nsIRDFResource *RelatedLinksHandlerImpl::kNC_RelatedLinksTopic;
nsIRDFResource *RelatedLinksHandlerImpl::kNC_Child;
@ -655,6 +657,7 @@ RelatedLinksHandlerImpl::~RelatedLinksHandlerImpl()
{
NS_IF_RELEASE(kNC_RelatedLinksRoot);
NS_IF_RELEASE(kRDF_type);
NS_IF_RELEASE(kNC_RelatedLinksTopic);
NS_IF_RELEASE(kNC_Child);
nsServiceManager::ReleaseService(kRDFServiceCID, gRDFService);
@ -678,6 +681,7 @@ RelatedLinksHandlerImpl::Init()
gRDFService->GetResource(kURINC_RelatedLinksRoot, &kNC_RelatedLinksRoot);
gRDFService->GetResource(RDF_NAMESPACE_URI "type", &kRDF_type);
gRDFService->GetResource(NC_NAMESPACE_URI "RelatedLinksTopic", &kNC_RelatedLinksTopic);
gRDFService->GetResource(NC_NAMESPACE_URI "child", &kNC_Child);
}
@ -974,9 +978,11 @@ RelatedLinksHandlerImpl::ArcLabelsOut(nsIRDFResource *aSource,
nsISimpleEnumerator* result = new nsArrayEnumerator(array);
if (! result) return(NS_ERROR_OUT_OF_MEMORY);
nsCOMPtr<nsIRDFNode> typeNode;
if ((aSource == kNC_RelatedLinksRoot) || (NS_SUCCEEDED(rv = GetTarget(aSource,
kRDF_type, PR_TRUE, getter_AddRefs(typeNode))) && (rv != NS_RDF_NO_VALUE)))
PRBool hasValueFlag = PR_FALSE;
if ((aSource == kNC_RelatedLinksRoot) ||
(NS_SUCCEEDED(rv = mInner->HasAssertion(aSource, kRDF_type,
kNC_RelatedLinksTopic, PR_TRUE, &hasValueFlag))) &&
(hasValueFlag == PR_TRUE))
{
array->AppendElement(kNC_Child);
}