1999-06-07 14:08:47 +04:00
|
|
|
/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-06-07 14:08:47 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-06-07 14:08:47 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-06-07 14:08:47 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-06-07 14:08:47 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
Code for the Related Links Sidebar Panel
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1999-11-30 03:56:44 +03:00
|
|
|
function debug(msg)
|
|
|
|
{
|
1999-12-18 06:51:16 +03:00
|
|
|
// uncomment for noise
|
|
|
|
// dump(msg);
|
1999-11-30 03:56:44 +03:00
|
|
|
}
|
|
|
|
|
1999-09-29 05:20:17 +04:00
|
|
|
// The content window that we're supposed to be observing.
|
1999-09-16 05:23:37 +04:00
|
|
|
var ContentWindow = window.content;
|
1999-06-07 14:08:47 +04:00
|
|
|
|
|
|
|
// The related links handler
|
|
|
|
var Handler = Components.classes["component://netscape/related-links-handler"].createInstance();
|
|
|
|
Handler = Handler.QueryInterface(Components.interfaces.nsIRelatedLinksHandler);
|
|
|
|
|
|
|
|
// Our observer object
|
|
|
|
var Observer = {
|
|
|
|
Observe: function(subject, topic, data) {
|
1999-12-29 12:17:41 +03:00
|
|
|
debug("Observer.Observe(" + subject + ", " + topic + ", " + data + ")\n");
|
1999-06-08 02:21:53 +04:00
|
|
|
|
1999-12-29 12:17:41 +03:00
|
|
|
if (subject != ContentWindow)
|
1999-09-29 05:20:17 +04:00
|
|
|
{
|
1999-12-29 12:17:41 +03:00
|
|
|
debug("subject was not content window, ignoring\n");
|
|
|
|
return;
|
1999-06-07 14:08:47 +04:00
|
|
|
}
|
1999-12-29 12:17:41 +03:00
|
|
|
refetchRelatedLinks(Handler, data);
|
1999-06-07 14:08:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-29 05:20:17 +04:00
|
|
|
|
|
|
|
|
1999-12-18 06:51:16 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-09-29 05:20:17 +04:00
|
|
|
function refetchRelatedLinks(Handler, data)
|
|
|
|
{
|
|
|
|
var newSite = "" + data;
|
1999-11-05 12:28:42 +03:00
|
|
|
|
|
|
|
// if we're looking at a translated page, get RL data for the true site
|
|
|
|
if (newSite.indexOf("http://levis.alis.com:8080/") == 0)
|
|
|
|
{
|
|
|
|
var matchStr = "AlisTargetURI="; // this is expected to be the last argument
|
|
|
|
var targetOffset = data.indexOf(matchStr);
|
|
|
|
if (targetOffset > 0)
|
|
|
|
{
|
|
|
|
targetOffset += matchStr.length;
|
|
|
|
newSite = newSite.substr(targetOffset);
|
|
|
|
data = newSite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// we can only get related links data on HTTP URLs
|
1999-09-29 05:20:17 +04:00
|
|
|
if (newSite.indexOf("http://") != 0)
|
|
|
|
{
|
1999-12-18 06:51:16 +03:00
|
|
|
debug("Unable to fetch related links data on non-HTTP URL.\n");
|
1999-09-29 05:20:17 +04:00
|
|
|
return(false);
|
|
|
|
}
|
|
|
|
newSite = newSite.substr(7); // strip off "http://" prefix
|
1999-11-05 12:28:42 +03:00
|
|
|
|
1999-09-29 05:20:17 +04:00
|
|
|
var portOffset = newSite.indexOf(":");
|
|
|
|
var slashOffset = newSite.indexOf("/");
|
|
|
|
var theOffset = ((portOffset >=0) && (portOffset <= slashOffset)) ? portOffset : slashOffset;
|
|
|
|
if (theOffset >= 0) newSite = newSite.substr(0, theOffset);
|
|
|
|
|
|
|
|
var currentSite = "";
|
|
|
|
if (Handler.URL != null)
|
|
|
|
{
|
|
|
|
currentSite = Handler.URL.substr(7); // strip off "http://" prefix
|
|
|
|
portOffset = currentSite.indexOf(":");
|
|
|
|
slashOffset = currentSite.indexOf("/");
|
|
|
|
theOffset = ((portOffset >=0) && (portOffset <= slashOffset)) ? portOffset : slashOffset;
|
|
|
|
if (theOffset >= 0) currentSite = currentSite.substr(0, theOffset );
|
|
|
|
}
|
|
|
|
|
1999-11-30 03:56:44 +03:00
|
|
|
debug("Related Links: Current top-level: " + currentSite + " new top-level: " + newSite + "\n");
|
1999-09-29 05:20:17 +04:00
|
|
|
|
|
|
|
// only request new related links data if we've got a new web site (hostname change)
|
|
|
|
if (currentSite != newSite)
|
|
|
|
{
|
1999-11-05 12:28:42 +03:00
|
|
|
// privacy: don't send anything after a '?'
|
|
|
|
var theSite = "" + data;
|
|
|
|
var questionOffset = theSite.indexOf("?");
|
|
|
|
if (questionOffset > 0)
|
|
|
|
{
|
|
|
|
theSite = theSite.substr(0, questionOffset);
|
|
|
|
}
|
|
|
|
|
1999-12-18 06:51:16 +03:00
|
|
|
if (skipRelatedLinksDomain(newSite) != true)
|
|
|
|
{
|
|
|
|
Handler.URL = theSite;
|
|
|
|
}
|
1999-09-29 05:20:17 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function Init()
|
|
|
|
{
|
1999-12-29 12:17:41 +03:00
|
|
|
// Initialize the Related Links panel
|
1999-06-07 14:08:47 +04:00
|
|
|
|
1999-12-29 12:17:41 +03:00
|
|
|
// Create a Related Links handler, and install it in the tree
|
|
|
|
var Tree = document.getElementById("Tree");
|
|
|
|
Tree.database.AddDataSource(Handler.QueryInterface(Components.interfaces.nsIRDFDataSource));
|
1999-06-07 14:08:47 +04:00
|
|
|
|
1999-12-29 12:17:41 +03:00
|
|
|
// Install the observer so we'll be notified when new content is loaded.
|
|
|
|
var ObserverService = Components.classes["component://netscape/observer-service"].getService();
|
|
|
|
ObserverService = ObserverService.QueryInterface(Components.interfaces.nsIObserverService);
|
|
|
|
if (ObserverService)
|
|
|
|
{
|
|
|
|
ObserverService.AddObserver(Observer, "StartDocumentLoad");
|
|
|
|
ObserverService.AddObserver(Observer, "EndDocumentLoad");
|
|
|
|
ObserverService.AddObserver(Observer, "FailDocumentLoad");
|
|
|
|
debug("added observer\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
debug("FAILURE to get observer service\n");
|
|
|
|
}
|
1999-06-07 14:08:47 +04:00
|
|
|
|
1999-12-31 01:39:28 +03:00
|
|
|
if (ContentWindow) {
|
|
|
|
refetchRelatedLinks(Handler, ContentWindow.location);
|
|
|
|
}
|
1999-06-07 14:08:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-29 05:20:17 +04:00
|
|
|
|
1999-12-29 12:17:41 +03:00
|
|
|
function openURL(event, treeitem, root)
|
1999-06-08 02:21:53 +04:00
|
|
|
{
|
1999-12-29 12:17:41 +03:00
|
|
|
if ((event.button != 1) || (event.clickCount != 2))
|
|
|
|
return(false);
|
1999-06-08 02:21:53 +04:00
|
|
|
|
1999-12-29 12:17:41 +03:00
|
|
|
if (treeitem.getAttribute('container') == 'true')
|
|
|
|
return(false);
|
1999-06-08 02:21:53 +04:00
|
|
|
|
1999-12-29 12:17:41 +03:00
|
|
|
if (treeitem.getAttribute("type") == "http://home.netscape.com/NC-rdf#BookmarkSeparator")
|
|
|
|
return(false);
|
1999-06-08 03:53:41 +04:00
|
|
|
|
1999-12-29 12:17:41 +03:00
|
|
|
var id = treeitem.getAttribute('id');
|
|
|
|
if (!id) return(false);
|
1999-09-17 14:38:40 +04:00
|
|
|
|
|
|
|
// rjc: add support for anonymous resources; if the node has
|
|
|
|
// a "#URL" property, use it, otherwise default to using the id
|
|
|
|
try
|
|
|
|
{
|
|
|
|
var rootNode = document.getElementById(root);
|
|
|
|
var ds = null;
|
|
|
|
if (rootNode)
|
|
|
|
{
|
|
|
|
ds = rootNode.database;
|
|
|
|
}
|
|
|
|
var rdf = Components.classes["component://netscape/rdf/rdf-service"].getService();
|
|
|
|
if (rdf) rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
|
|
|
|
if (rdf)
|
|
|
|
{
|
|
|
|
if (ds)
|
|
|
|
{
|
|
|
|
var src = rdf.GetResource(id, true);
|
|
|
|
var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
|
|
|
|
var target = ds.GetTarget(src, prop, true);
|
|
|
|
if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
|
|
|
if (target) target = target.Value;
|
|
|
|
if (target) id = target;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(ex)
|
|
|
|
{
|
|
|
|
}
|
1999-12-29 12:17:41 +03:00
|
|
|
|
|
|
|
ContentWindow.location = id;
|
1999-06-08 02:21:53 +04:00
|
|
|
}
|