diff --git a/suite/common/builtinURLs.js b/suite/common/builtinURLs.js index 0e0671b70e4..d8a44f86fc6 100644 --- a/suite/common/builtinURLs.js +++ b/suite/common/builtinURLs.js @@ -1,119 +1,159 @@ // the rdf service -var RDF; -var titleArc; -var contentArc; -var ds; -var state; -var loaded; +var gRDFService; +var gTitleArc; +var gContentArc; +var gBuiltinUrlsDataSource; +var gDataSourceState; +var gDataSourceLoaded; +var gSinkObserverRegistered; var SinkObserver = { onBeginLoad: function( aSink) { - state = (state | 1); - //dump("\n-> SinkObserver:onBeginLoad: " + aSink + ", state=" + state + "\n"); + gDataSourceState = (gDataSourceState | 1); + debug_dump("\n-> SinkObserver:onBeginLoad: " + aSink + ", gDataSourceState=" + gDataSourceState + "\n"); }, onInterrupt: function( aSink) { - state = (state | 2); - //dump("\n-> SinkObserver:onInterrupt: " + aSink + ", state=" + state + "\n"); + gDataSourceState = (gDataSourceState | 2); + debug_dump("\n-> SinkObserver:onInterrupt: " + aSink + ", gDataSourceState=" + gDataSourceState + "\n"); }, onResume: function( aSink) { - state = (state & ~2); - //dump("\n-> SinkObserver:onResume: " + aSink + ", state=" + state + "\n"); + gDataSourceState = (gDataSourceState & ~2); + debug_dump("\n-> SinkObserver:onResume: " + aSink + ", gDataSourceState=" + gDataSourceState + "\n"); }, onEndLoad: function( aSink) { - state = (state | 4); - loaded = (state == 5); - //dump("\n-> onEndLoad: " + aSink + ", state=" + state + ", loaded=" + loaded + "\n"); + gDataSourceState = (gDataSourceState | 4); + gDataSourceLoaded = (gDataSourceState == 5); + + debug_dump("\n-> onEndLoad: " + aSink + ", gDataSourceState=" + gDataSourceState + ", gDataSourceLoaded=" + gDataSourceLoaded + "\n"); - if (!loaded) { - dump("\n-> builtin URLs not loaded!\n"); + if (!gDataSourceLoaded) { + debug_dump("\n-> builtin URLs not loaded!\n"); return; } - ds = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource); - - titleArc = RDF.GetResource("http://home.netscape.com/NC-rdf#title"); - contentArc = RDF.GetResource("http://home.netscape.com/NC-rdf#content"); + gBuiltinUrlsDataSource = aSink.QueryInterface(Components.interfaces.nsIRDFDataSource); + + debug_dump("Got gBuiltinUrlsDataSource " + gBuiltinUrlsDataSource + " with gTitleArc " + gTitleArc + " and gContentArc " + gContentArc + "\n"); }, onError: function( aSink, aStatus, aErrMsg) { - state = (state | 8); - dump("\n-> SinkObserver:onError: " + aSink + ", status=" + aStatus + - ", errMsg=" + aErrMsg + ", state=" + state + "\n"); + gDataSourceState = (gDataSourceState | 8); + debug_dump("\n-> SinkObserver:onError: " + aSink + ", status=" + aStatus + + ", errMsg=" + aErrMsg + ", gDataSourceState=" + gDataSourceState + "\n"); } }; +function debug_dump(msg) +{ +} + +/* +function debug_dump(msg) +{ + dump(msg); +} +*/ + function loadDS() { - //dump("\n-->loadDS() called <--\n"); - if (ds && loaded) { - //dump("\n-->loadDS(): ds=" + ds + ", loaded=" + loaded + ", returning! <--\n"); + debug_dump("\n-->loadDS() called for " + window.document + " <--\n"); + if (gBuiltinUrlsDataSource && gDataSourceLoaded) { + debug_dump("\n-->loadDS(): gBuiltinUrlsDataSource=" + gBuiltinUrlsDataSource + ", gDataSourceLoaded=" + gDataSourceLoaded + ", returning! <--\n"); return; } - + + if (gSinkObserverRegistered) + { + debug_dump("Already registered SinkObserver in loadDS()\n"); + return; + } + // initialize - RDF = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService(); - RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService); + gRDFService = Components.classes['@mozilla.org/rdf/rdf-service;1'].getService(); + gRDFService = gRDFService.QueryInterface(Components.interfaces.nsIRDFService); - if (!RDF) { - dump("\n-->loadDS(): RDF service is null!\n"); + if (!gRDFService) { + debug_dump("\n-->loadDS(): gRDFService service is null!\n"); return; } - var ds_uri = "chrome://global/locale/builtinURLs.rdf"; - var url_ds = RDF.GetDataSource(ds_uri); // return nsIRDFDataSource - if (!url_ds) { - dump("\n >>Can't get " + ds_uri + "<-\n"); - return; - } - var rdfXMLSink = url_ds.QueryInterface( Components.interfaces.nsIRDFXMLSink ); - if (rdfXMLSink) { - ds = null; - state = 0x0; // init. - loaded = false; + gTitleArc = gRDFService.GetResource("http://home.netscape.com/NC-rdf#title"); + gContentArc = gRDFService.GetResource("http://home.netscape.com/NC-rdf#content"); - rdfXMLSink.addXMLSinkObserver(SinkObserver); + var ds_uri = "chrome://global/locale/builtinURLs.rdf"; + var url_ds = gRDFService.GetDataSource(ds_uri); // return nsIRDFDataSource + if (!url_ds) { + debug_dump("\n >>Can't get " + ds_uri + "<-\n"); + return; + } + + if (url_ds.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).loaded) + { + var ds_uri = "chrome://global/locale/builtinURLs.rdf"; + gBuiltinUrlsDataSource = gRDFService.GetDataSource(ds_uri); // return nsIRDFDataSource + gDataSourceLoaded = (gBuiltinUrlsDataSource != null); + } + else + { + var rdfXMLSink = url_ds.QueryInterface( Components.interfaces.nsIRDFXMLSink ); + if (rdfXMLSink) { + gBuiltinUrlsDataSource = null; + gDataSourceState = 0x0; // init. + gDataSourceLoaded = false; + gSinkObserverRegistered = true; + + rdfXMLSink.addXMLSinkObserver(SinkObserver); + } + else + { + debug_dump("rdfXMLSink is null\n"); + } } } function xlateURL(key) { - //dump("\n>> xlateURL(" + key + "): ds=" + ds + ", loaded=" + loaded); - if (!ds || !loaded) { - dump("\n xlateURL(): data source is not loaded! Try again later! \n"); - return ""; + debug_dump("\n>> xlateURL(" + key + "): gBuiltinUrlsDataSource=" + gBuiltinUrlsDataSource + ", gDataSourceLoaded=" + gDataSourceLoaded + "\n"); + + if (!gBuiltinUrlsDataSource || !gDataSourceLoaded) { + throw("urn translation data source not loaded"); } // get data - var srcNode = RDF.GetResource(key); - var titleTarget = ds.GetTarget(srcNode, titleArc, true); + var srcNode = gRDFService.GetResource(key); + var titleTarget = gBuiltinUrlsDataSource.GetTarget(srcNode, gTitleArc, true); if (titleTarget) { titleTarget = titleTarget.QueryInterface(Components.interfaces.nsIRDFLiteral); - dump("\n-> " + key + "::title=" + titleTarget.Value); + debug_dump("\n-> " + key + "::title=" + titleTarget.Value); } else { - dump("\n title target=" + titleTarget + "\n"); + debug_dump("\n title target=" + titleTarget + "\n"); } - var contentTarget = ds.GetTarget(srcNode, contentArc, true); + var contentTarget = gBuiltinUrlsDataSource.GetTarget(srcNode, gContentArc, true); if (contentTarget) { contentTarget = contentTarget.QueryInterface(Components.interfaces.nsIRDFLiteral); - dump("\n-> " + key + "::content=" + contentTarget.Value + "\n"); + debug_dump("\n-> " + key + "::content=" + contentTarget.Value + "\n"); return contentTarget.Value; } else { - dump("\n content target=" + contentTarget + "\n"); + debug_dump("\n content target=" + contentTarget + "\n"); + throw("urn not found in datasource"); } + // not reached return ""; } function loadXURL(key) { + debug_dump("loadXURL call with " + key + "\n"); + window._content.location.href = xlateURL(key); } diff --git a/suite/common/utilityOverlay.js b/suite/common/utilityOverlay.js index 1069828a623..a5c7f57dfd2 100644 --- a/suite/common/utilityOverlay.js +++ b/suite/common/utilityOverlay.js @@ -268,31 +268,32 @@ function openTopWin( url ) but if we do this we need to have the option for chrome controls because goClickThrobber() needs to use this function with chrome controls */ /* also, do we want to limit the number of help windows that can be spawned? */ - dump("SetPrefToCurrentPage("+ url +") \n "); + // dump("SetPrefToCurrentPage("+ url +")\n"); if ((url == null) || (url == "")) return; - + + // xlate the URL if necessary + if (url.indexOf("urn:") == 0) + { + url = xlateURL(url); // does RDF urn expansion + } + + // avoid loading "", since this loads a directory listing + if (url == "") { + dump("openTopWin told to load an empty URL, so loading about:blank instead\n"); + url = "about:blank"; + } + var windowManager = Components.classes['@mozilla.org/rdf/datasource;1?name=window-mediator'].getService(); var windowManagerInterface = windowManager.QueryInterface( Components.interfaces.nsIWindowMediator); var topWindowOfType = windowManagerInterface.getMostRecentWindow( "navigator:browser" ); if ( topWindowOfType ) { - dump("setting page: " + topWindowOfType._content.location.href + "\n"); topWindowOfType.focus(); - // urn: - var pos = url.indexOf("urn:"); - dump("\n ** openTopWin, url=" + url + ", pos=" + pos + "\n"); - if (pos == 0) { - topWindowOfType._content.location.href = xlateURL(url); - } - else - { - topWindowOfType._content.location.href = url; - } + topWindowOfType._content.location.href = url; } else { - dump(" No browser window. Should be disabling this button \n"); window.openDialog( getBrowserURL(), "_blank", "chrome,all,dialog=no", url ); } }