First (sidebar) part of fix for 20721, r=slamm
git-svn-id: svn://10.0.0.236/trunk@61091 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
345e9c57a6
commit
7314dd9419
@ -24,14 +24,15 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIDOMWindow;
|
||||
|
||||
[scriptable, uuid(577CB745-8CAF-11d3-AAEF-00805F8A4905)]
|
||||
interface nsISidebar : nsISupports
|
||||
{
|
||||
void init();
|
||||
void open();
|
||||
|
||||
void setWindow (in nsIDOMWindow aWindow);
|
||||
void addPanel(in wstring aTitle, in string aContentURL,
|
||||
in string aCustomizeURL);
|
||||
void setPanelTitle(in wstring aTitle);
|
||||
};
|
||||
|
||||
%{ C++
|
||||
|
||||
@ -26,7 +26,7 @@ RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
|
||||
var NC = "http://home.netscape.com/NC-rdf#";
|
||||
|
||||
var sidebar = new Object;
|
||||
var sidebarObj = new Object;
|
||||
var original_panels = new Array();
|
||||
|
||||
function debug(msg)
|
||||
@ -38,13 +38,13 @@ function Init()
|
||||
{
|
||||
var all_panels_datasources = window.arguments[0];
|
||||
var all_panels_resource = window.arguments[1];
|
||||
sidebar.datasource_uri = window.arguments[2];
|
||||
sidebar.resource = window.arguments[3];
|
||||
sidebarObj.datasource_uri = window.arguments[2];
|
||||
sidebarObj.resource = window.arguments[3];
|
||||
|
||||
debug("Init: all panels datasources = " + all_panels_datasources);
|
||||
debug("Init: all panels resource = " + all_panels_resource);
|
||||
debug("Init: sidebar.datasource_uri = " + sidebar.datasource_uri);
|
||||
debug("Init: sidebar.resource = " + sidebar.resource);
|
||||
debug("Init: sidebarObj.datasource_uri = " + sidebarObj.datasource_uri);
|
||||
debug("Init: sidebarObj.resource = " + sidebarObj.resource);
|
||||
|
||||
var all_panels = document.getElementById('other-panels');
|
||||
var current_panels = document.getElementById('current-panels');
|
||||
@ -61,15 +61,15 @@ function Init()
|
||||
|
||||
// Add the datasource for current list of panels. It selects panels out
|
||||
// of the other datasources.
|
||||
debug("Init: Adding current panels, "+sidebar.datasource_uri);
|
||||
sidebar.datasource = RDF.GetDataSource(sidebar.datasource_uri);
|
||||
current_panels.database.AddDataSource(sidebar.datasource);
|
||||
debug("Init: Adding current panels, "+sidebarObj.datasource_uri);
|
||||
sidebarObj.datasource = RDF.GetDataSource(sidebarObj.datasource_uri);
|
||||
current_panels.database.AddDataSource(sidebarObj.datasource);
|
||||
|
||||
// Root the customize dialog at the correct place.
|
||||
debug("Init: reset all panels ref, "+all_panels_resource);
|
||||
all_panels.setAttribute('ref', all_panels_resource);
|
||||
debug("Init: reset current panels ref, "+sidebar.resource);
|
||||
current_panels.setAttribute('ref', sidebar.resource);
|
||||
debug("Init: reset current panels ref, "+sidebarObj.resource);
|
||||
current_panels.setAttribute('ref', sidebarObj.resource);
|
||||
|
||||
save_initial_panels();
|
||||
enable_buttons_for_current_panels();
|
||||
@ -359,13 +359,13 @@ function Save()
|
||||
// Without this, the dialog tries to update as it is being destroyed.
|
||||
current_panels.setAttribute('ref', 'rdf:null');
|
||||
|
||||
start_batch(sidebar.datasource, sidebar.resource);
|
||||
start_batch(sidebarObj.datasource, sidebarObj.resource);
|
||||
|
||||
// Create a "container" wrapper around the current panels to
|
||||
// manipulate the RDF:Seq more easily.
|
||||
var container = Components.classes["component://netscape/rdf/container"].createInstance();
|
||||
container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
|
||||
container.Init(sidebar.datasource, RDF.GetResource(sidebar.resource));
|
||||
container.Init(sidebarObj.datasource, RDF.GetResource(sidebarObj.resource));
|
||||
|
||||
// Remove all the current panels from the datasource.
|
||||
var current_panels = container.GetElements();
|
||||
@ -392,10 +392,10 @@ function Save()
|
||||
container);
|
||||
}
|
||||
|
||||
end_batch(sidebar.datasource, sidebar.resource);
|
||||
end_batch(sidebarObj.datasource, sidebarObj.resource);
|
||||
|
||||
// Write the modified panels out.
|
||||
sidebar.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
|
||||
sidebarObj.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
|
||||
|
||||
window.close();
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
|
||||
var NC = "http://home.netscape.com/NC-rdf#";
|
||||
|
||||
var sidebar = new Object;
|
||||
var sidebarObj = new Object;
|
||||
var original_panels = new Array();
|
||||
|
||||
function debug(msg)
|
||||
@ -36,20 +36,20 @@ function debug(msg)
|
||||
|
||||
function Init()
|
||||
{
|
||||
sidebar.datasource_uri = window.arguments[0];
|
||||
sidebar.resource = window.arguments[1];
|
||||
debug("sidebar.datasource_uri = " + sidebar.datasource_uri);
|
||||
debug("sidebar.resource = " + sidebar.resource);
|
||||
sidebarObj.datasource_uri = window.arguments[0];
|
||||
sidebarObj.resource = window.arguments[1];
|
||||
debug("sidebarObj.datasource_uri = " + sidebarObj.datasource_uri);
|
||||
debug("sidebarObj.resource = " + sidebarObj.resource);
|
||||
|
||||
// This will load the datasource, if it isn't already.
|
||||
sidebar.datasource = RDF.GetDataSource(sidebar.datasource_uri);
|
||||
sidebarObj.datasource = RDF.GetDataSource(sidebarObj.datasource_uri);
|
||||
|
||||
// Add the necessary datasources to the select list
|
||||
var select_list = document.getElementById('selected-panels');
|
||||
select_list.database.AddDataSource(sidebar.datasource);
|
||||
select_list.database.AddDataSource(sidebarObj.datasource);
|
||||
|
||||
// Root the customize dialog at the correct place.
|
||||
select_list.setAttribute('ref', sidebar.resource);
|
||||
select_list.setAttribute('ref', sidebarObj.resource);
|
||||
|
||||
saveInitialPanels();
|
||||
enableButtons();
|
||||
@ -265,7 +265,7 @@ function Save()
|
||||
// object. This makes it easier to manipulate the RDF:Seq correctly.
|
||||
var container = Components.classes["component://netscape/rdf/container"].createInstance();
|
||||
container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
|
||||
container.Init(sidebar.datasource, RDF.GetResource(sidebar.resource));
|
||||
container.Init(sidebarObj.datasource, RDF.GetResource(sidebarObj.resource));
|
||||
|
||||
for (var ii = container.GetCount(); ii >= 1; --ii) {
|
||||
debug('removing panel ' + ii);
|
||||
@ -279,7 +279,7 @@ function Save()
|
||||
}
|
||||
|
||||
// Write the modified panels out.
|
||||
sidebar.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
|
||||
sidebarObj.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
|
||||
|
||||
window.close();
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ var PANELS_RDF_FILE = 66626;
|
||||
var SIDEBAR_VERSION = "0.0";
|
||||
|
||||
// the default sidebar:
|
||||
var sidebar = new Object;
|
||||
var sidebarObj = new Object;
|
||||
|
||||
function debug(msg) {
|
||||
// uncomment for noise
|
||||
@ -41,7 +41,7 @@ function debug(msg) {
|
||||
var panel_observer = new Object;
|
||||
|
||||
panel_observer = {
|
||||
OnAssert : function(src,prop,target) {},
|
||||
OnAssert : function(src,prop,target) { debug ("*** assert");},
|
||||
OnUnassert : function(src,prop,target) {
|
||||
// Wait for unassert that marks the end of the customize changes.
|
||||
// See customize.js for where this is unasserted.
|
||||
@ -85,15 +85,15 @@ function get_sidebar_datasource_uri(panels_file_id) {
|
||||
}
|
||||
|
||||
function sidebar_overlay_init() {
|
||||
sidebar.datasource_uri = get_sidebar_datasource_uri(PANELS_RDF_FILE);
|
||||
sidebar.resource = 'urn:sidebar:current-panel-list';
|
||||
sidebar.master_datasources = 'chrome://sidebar/content/local-panels.rdf';
|
||||
sidebar.master_datasources += ' chrome://sidebar/content/remote-panels.rdf';
|
||||
//sidebar.master_datasources += " " + get_remote_datasource_url();
|
||||
sidebar.master_resource = 'urn:sidebar:master-panel-list';
|
||||
sidebar.component = document.location.href;
|
||||
sidebarObj.datasource_uri = get_sidebar_datasource_uri(PANELS_RDF_FILE);
|
||||
sidebarObj.resource = 'urn:sidebar:current-panel-list';
|
||||
sidebarObj.master_datasources = 'chrome://sidebar/content/local-panels.rdf';
|
||||
sidebarObj.master_datasources += ' chrome://sidebar/content/remote-panels.rdf';
|
||||
//sidebarObj.master_datasources += " " + get_remote_datasource_url();
|
||||
sidebarObj.master_resource = 'urn:sidebar:master-panel-list';
|
||||
sidebarObj.component = document.location.href;
|
||||
|
||||
debug("sidebar_overlay_init: sidebar.component: " + sidebar.component);
|
||||
debug("sidebar_overlay_init: sidebarObj.component: " + sidebarObj.component);
|
||||
|
||||
|
||||
// Initialize the display
|
||||
@ -108,28 +108,28 @@ function sidebar_overlay_init() {
|
||||
sidebar_menuitem.setAttribute('checked', 'true');
|
||||
}
|
||||
|
||||
debug("sidebar = " + sidebar);
|
||||
debug("sidebar.resource = " + sidebar.resource);
|
||||
debug("sidebar.datasource_uri = " + sidebar.datasource_uri);
|
||||
debug("sidebar = " + sidebarObj);
|
||||
debug("sidebarObj.resource = " + sidebarObj.resource);
|
||||
debug("sidebarObj.datasource_uri = " + sidebarObj.datasource_uri);
|
||||
|
||||
// Add the user's current panel choices to the template builder,
|
||||
// which will aggregate it with the other datasources that describe
|
||||
// the individual panel's title, customize URL, and content URL.
|
||||
var panels = document.getElementById('sidebar-panels');
|
||||
panels.database.AddDataSource(RDF.GetDataSource(sidebar.datasource_uri));
|
||||
panels.database.AddDataSource(RDF.GetDataSource(sidebarObj.datasource_uri));
|
||||
|
||||
// The stuff on the bottom
|
||||
var panels_bottom = document.getElementById('sidebar-panels-bottom');
|
||||
panels_bottom.database.AddDataSource(RDF.GetDataSource(sidebar.datasource_uri));
|
||||
panels_bottom.database.AddDataSource(RDF.GetDataSource(sidebarObj.datasource_uri));
|
||||
|
||||
debug("Adding observer to database.");
|
||||
panels.database.AddObserver(panel_observer);
|
||||
|
||||
// XXX This is a hack to force re-display
|
||||
panels.setAttribute('ref', sidebar.resource);
|
||||
panels.setAttribute('ref', sidebarObj.resource);
|
||||
|
||||
// XXX This is a hack to force re-display
|
||||
panels_bottom.setAttribute('ref', sidebar.resource);
|
||||
panels_bottom.setAttribute('ref', sidebarObj.resource);
|
||||
|
||||
sidebar_open_default_panel(100, 0);
|
||||
}
|
||||
@ -255,7 +255,7 @@ function is_excluded(item) {
|
||||
var src = item.getAttribute('iframe-src');
|
||||
debug("src="+src);
|
||||
debug("exclude="+exclude);
|
||||
return exclude && exclude != '' && exclude.indexOf(sidebar.component) != -1;
|
||||
return exclude && exclude != '' && exclude.indexOf(sidebarObj.component) != -1;
|
||||
}
|
||||
|
||||
function update_headers(index) {
|
||||
@ -335,10 +335,10 @@ function SidebarCustomize() {
|
||||
customizeWindow = window.openDialog(
|
||||
'chrome://sidebar/content/customize.xul',
|
||||
'_blank','chrome,resizable',
|
||||
sidebar.master_datasources,
|
||||
sidebar.master_resource,
|
||||
sidebar.datasource_uri,
|
||||
sidebar.resource);
|
||||
sidebarObj.master_datasources,
|
||||
sidebarObj.master_resource,
|
||||
sidebarObj.datasource_uri,
|
||||
sidebarObj.resource);
|
||||
setTimeout(enable_customize, 2000);
|
||||
}
|
||||
}
|
||||
@ -347,18 +347,18 @@ function SidebarCustomize() {
|
||||
// Show/Hide the entire sidebar.
|
||||
// Envoked by the "View / Sidebar" menu option.
|
||||
function SidebarShowHide() {
|
||||
var sidebar = document.getElementById('sidebar-box');
|
||||
var sidebarBox = document.getElementById('sidebar-box');
|
||||
var sidebar_splitter = document.getElementById('sidebar-splitter');
|
||||
var is_hidden = sidebar.getAttribute('hidden');
|
||||
var is_hidden = sidebarBox.getAttribute('hidden');
|
||||
|
||||
if (is_hidden && is_hidden == "true") {
|
||||
debug("Showing the sidebar");
|
||||
sidebar.removeAttribute('hidden');
|
||||
sidebarBox.removeAttribute('hidden');
|
||||
sidebar_splitter.removeAttribute('hidden');
|
||||
sidebar_overlay_init()
|
||||
} else {
|
||||
debug("Hiding the sidebar");
|
||||
sidebar.setAttribute('hidden','true');
|
||||
sidebarBox.setAttribute('hidden','true');
|
||||
sidebar_splitter.setAttribute('hidden','true');
|
||||
}
|
||||
// Immediately save persistent values
|
||||
@ -370,10 +370,10 @@ function SidebarShowHide() {
|
||||
// XXX This whole function is a hack to work around
|
||||
// bugs #20546, and #22214.
|
||||
function SidebarExpandCollapse() {
|
||||
var sidebar = document.getElementById('sidebar-box');
|
||||
var sidebarBox = document.getElementById('sidebar-box');
|
||||
var sidebar_splitter = document.getElementById('sidebar-splitter');
|
||||
|
||||
sidebar.setAttribute('hackforbug20546-applied','true');
|
||||
sidebarBox.setAttribute('hackforbug20546-applied','true');
|
||||
|
||||
// Get the current open/collapsed state
|
||||
// The value of state is the "preclick" state
|
||||
@ -382,7 +382,7 @@ function SidebarExpandCollapse() {
|
||||
if (state && state == 'collapsed') {
|
||||
// Going from collapsed to open.
|
||||
|
||||
sidebar.removeAttribute('hackforbug20546');
|
||||
sidebarBox.removeAttribute('hackforbug20546');
|
||||
|
||||
// Reset the iframe's src to get the content to display.
|
||||
// This might be bug #22214.
|
||||
@ -398,15 +398,15 @@ function SidebarExpandCollapse() {
|
||||
} else {
|
||||
// Going from open to collapsed.
|
||||
|
||||
sidebar.setAttribute('hackforbug20546','true');
|
||||
sidebarBox.setAttribute('hackforbug20546','true');
|
||||
}
|
||||
}
|
||||
|
||||
// XXX Partial hack workaround for bug #22214.
|
||||
function bump_width(delta) {
|
||||
var sidebar = document.getElementById('sidebar-box');
|
||||
var width = sidebar.getAttribute('width');
|
||||
sidebar.setAttribute('width', parseInt(width) + delta);
|
||||
var sidebarBox = document.getElementById('sidebar-box');
|
||||
var width = sidebarBox.getAttribute('width');
|
||||
sidebarBox.setAttribute('width', parseInt(width) + delta);
|
||||
}
|
||||
|
||||
function PersistHeight() {
|
||||
@ -419,19 +419,19 @@ function PersistHeight() {
|
||||
|
||||
function persist_width() {
|
||||
// XXX Partial workaround for bug #19488.
|
||||
var sidebar = document.getElementById('sidebar-box');
|
||||
var sidebarBox = document.getElementById('sidebar-box');
|
||||
var sidebar_splitter = document.getElementById('sidebar-splitter');
|
||||
var state = sidebar_splitter.getAttribute('state');
|
||||
|
||||
var width = sidebar.getAttribute('width');
|
||||
var width = sidebarBox.getAttribute('width');
|
||||
|
||||
if (!state || state == '' || state == 'open') {
|
||||
sidebar.removeAttribute('hackforbug20546');
|
||||
sidebar.setAttribute('hackforbug20546-applied','true');
|
||||
sidebarBox.removeAttribute('hackforbug20546');
|
||||
sidebarBox.setAttribute('hackforbug20546-applied','true');
|
||||
}
|
||||
|
||||
if (width && (width > 410 || width < 15)) {
|
||||
sidebar.setAttribute('width',168);
|
||||
sidebarBox.setAttribute('width',168);
|
||||
}
|
||||
|
||||
document.persist('sidebar-box', 'width');
|
||||
|
||||
@ -32,217 +32,197 @@
|
||||
* for portability reasons -- and even when you're building completely
|
||||
* platform-specific code, you can't throw across an XPCOM method boundary.)
|
||||
*/
|
||||
function mySidebar() { /* big comment for no code, eh? */ }
|
||||
|
||||
const DEBUG = true; /* set to false to suppress debug messages */
|
||||
const PANELS_RDF_FILE = 66626; /* the magic number to find panels.rdf */
|
||||
|
||||
const SIDEBAR_PROGID = "component://mozilla/sidebar";
|
||||
const SIDEBAR_CID = Components.ID("{22117140-9c6e-11d3-aaf1-00805f8a4905}");
|
||||
const CONTAINER_PROGID = "component://netscape/rdf/container";
|
||||
const LOCATOR_PROGID = "component://netscape/filelocator";
|
||||
const nsISupports = Components.interfaces.nsISupports;
|
||||
const nsIFactory = Components.interfaces.nsIFactory;
|
||||
const nsISidebar = Components.interfaces.nsISidebar;
|
||||
const nsIRDFContainer = Components.interfaces.nsIRDFContainer;
|
||||
const nsIFileLocator = Components.interfaces.nsIFileLocator;
|
||||
const nsIRDFRemoteDataSource = Components.interfaces.nsIRDFRemoteDataSource;
|
||||
|
||||
function nsSidebar()
|
||||
{
|
||||
const RDF_PROGID = "component://netscape/rdf/rdf-service";
|
||||
const nsIRDFService = Components.interfaces.nsIRDFService;
|
||||
|
||||
this.rdf = Components.classes[RDF_PROGID].getService(nsIRDFService);
|
||||
this.datasource_uri = getSidebarDatasourceURI(PANELS_RDF_FILE);
|
||||
debug('datasource_uri is ' + this.datasource_uri);
|
||||
this.resource = 'urn:sidebar:current-panel-list';
|
||||
this.datasource = this.rdf.GetDataSource(this.datasource_uri);
|
||||
}
|
||||
|
||||
nsSidebar.prototype.nc = "http://home.netscape.com/NC-rdf#";
|
||||
|
||||
nsSidebar.prototype.setWindow =
|
||||
function (aWindow)
|
||||
{
|
||||
this.window = aWindow;
|
||||
}
|
||||
|
||||
nsSidebar.prototype.isPanel =
|
||||
function (aContentURL)
|
||||
{
|
||||
var container =
|
||||
Components.classes[CONTAINER_PROGID].createInstance(nsIRDFContainer);
|
||||
|
||||
container.Init(this.datasource, this.rdf.GetResource(this.resource));
|
||||
|
||||
/* Create a resource for the new panel and add it to the list */
|
||||
var panel_resource =
|
||||
this.rdf.GetResource("urn:sidebar:3rdparty-panel:" + aContentURL);
|
||||
|
||||
return (container.IndexOf(panel_resource) != -1);
|
||||
}
|
||||
|
||||
|
||||
/* decorate prototype to provide ``class'' methods and property accessors */
|
||||
mySidebar.prototype = {
|
||||
open: function () {
|
||||
debug("mySidebar::open()");
|
||||
if (!document) return;
|
||||
splitter = top.document.getElementById('sidebar-splitter')
|
||||
if (!splitter) return;
|
||||
splitter.removeAttribute('collapsed');
|
||||
},
|
||||
addPanel: function (aTitle, aContentURL, aCustomizeURL) {
|
||||
debug("mySidebar::addPanel("+aTitle+", "+aContentURL+", "
|
||||
+ aCustomizeURL+")");
|
||||
|
||||
var appShell = Components.classes['component://netscape/appshell/appShellService'].getService();
|
||||
appShell = appShell.QueryInterface(Components.interfaces.nsIAppShellService);
|
||||
|
||||
// Grab the nsINetSupportDialog. It does not have a prog id
|
||||
// registered, so use the CID instead. Ugly.
|
||||
//var prompt = Components.classes['{05650684-eb9f-11d2-8e19-9ac64aca4d3c}'].getService();
|
||||
var prompt = Components.classes['component://netscape/appshell/netSupportDialog'].getService();
|
||||
prompt = prompt.QueryInterface(Components.interfaces.nsIPrompt);
|
||||
|
||||
// Create a "container" wrapper around the
|
||||
// "urn:sidebar:current-panel-list" object. This makes it easier
|
||||
// to manipulate the RDF:Seq correctly.
|
||||
var container = Components.classes["component://netscape/rdf/container"].createInstance();
|
||||
container = container.QueryInterface(Components.interfaces.nsIRDFContainer);
|
||||
debug(" this.datasource ="+this.datasource);
|
||||
debug(" this.resource ="+this.resource);
|
||||
container.Init(this.datasource, this.rdf.GetResource(this.resource));
|
||||
|
||||
// Create a resource for the new panel and add it to the list
|
||||
var panel_resource = this.rdf.GetResource("urn:sidebar:3rdparty-panel:"+aContentURL);
|
||||
var panel_index = container.IndexOf(panel_resource);
|
||||
if (panel_index != -1) {
|
||||
dump(prompt);
|
||||
prompt.alert("That panel already exists in your sidebar.")
|
||||
return;
|
||||
}
|
||||
if (!prompt.confirm("Are you sure you want to add this panel to your sidebar?")) {
|
||||
return;
|
||||
}
|
||||
|
||||
container.AppendElement(panel_resource);
|
||||
|
||||
// Now make some sidebar-ish assertions about it...
|
||||
this.datasource.Assert(panel_resource,
|
||||
this.rdf.GetResource(this.nc + "title"),
|
||||
this.rdf.GetLiteral(aTitle),
|
||||
true);
|
||||
this.datasource.Assert(panel_resource,
|
||||
this.rdf.GetResource(this.nc + "content"),
|
||||
this.rdf.GetLiteral(aContentURL),
|
||||
true);
|
||||
if (aCustomizeURL && aCustomizeURL != "") {
|
||||
this.datasource.Assert(panel_resource,
|
||||
this.rdf.GetResource(this.nc + "customize"),
|
||||
this.rdf.GetLiteral(aCustomizeURL),
|
||||
true);
|
||||
}
|
||||
|
||||
// Write the modified panels out.
|
||||
this.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource).Flush();
|
||||
|
||||
},
|
||||
setPanelTitle: function (aTitle) {
|
||||
debug("mySidebar::setPanelTitle("+aTitle+")");
|
||||
},
|
||||
init: function() {
|
||||
// the magic number to find panels.rdf
|
||||
var PANELS_RDF_FILE = 66626;
|
||||
|
||||
// The rdf service
|
||||
this.rdf = 'component://netscape/rdf/rdf-service'
|
||||
this.rdf = Components.classes[this.rdf].getService();
|
||||
this.rdf = this.rdf.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
this.nc = "http://home.netscape.com/NC-rdf#";
|
||||
this.datasource_uri = getSidebarDatasourceURI(PANELS_RDF_FILE);
|
||||
debug('Sidebar datasource_uri is '+this.datasource_uri);
|
||||
this.resource = 'urn:sidebar:current-panel-list';
|
||||
this.datasource = this.rdf.GetDataSource(this.datasource_uri);
|
||||
}
|
||||
}
|
||||
|
||||
var myModule = {
|
||||
firstTime: true,
|
||||
|
||||
/*
|
||||
* RegisterSelf is called at registration time (component installation
|
||||
* or the only-until-release startup autoregistration) and is responsible
|
||||
* for notifying the component manager of all components implemented in
|
||||
* this module. The fileSpec, location and type parameters are mostly
|
||||
* opaque, and should be passed on to the registerComponent call
|
||||
* unmolested.
|
||||
*/
|
||||
registerSelf: function (compMgr, fileSpec, location, type) {
|
||||
if (0 && this.firstTime) {
|
||||
debug("*** Deferring registration of sidebar JS components");
|
||||
this.firstTime = false;
|
||||
throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
|
||||
}
|
||||
debug("*** Registering sidebar JS components");
|
||||
compMgr.registerComponentWithType(this.myCID,
|
||||
"Sidebar JS Component",
|
||||
"component://mozilla/sidebar.js",
|
||||
fileSpec,
|
||||
location, true, true,
|
||||
type);
|
||||
},
|
||||
|
||||
/*
|
||||
* The GetClassObject method is responsible for producing Factory and
|
||||
* SingletonFactory objects (the latter are specialized for services).
|
||||
*/
|
||||
getClassObject: function (compMgr, cid, iid) {
|
||||
if (!cid.equals(this.myCID))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
return this.myFactory;
|
||||
},
|
||||
|
||||
/* CID for this class */
|
||||
myCID: Components.ID("{22117140-9c6e-11d3-aaf1-00805f8a4905}"),
|
||||
|
||||
/* factory object */
|
||||
myFactory: {
|
||||
/*
|
||||
* Construct an instance of the interface specified by iid,
|
||||
* possibly aggregating with the provided |outer|. (If you don't
|
||||
* know what aggregation is all about, you don't need to. It reduces
|
||||
* even the mightiest of XPCOM warriors to snivelling cowards.)
|
||||
*/
|
||||
CreateInstance: function (outer, iid) {
|
||||
debug("CI: " + iid);
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
/*
|
||||
* If we had a QueryInterface method (see above), we would write
|
||||
* the following as:
|
||||
* return (new mySidebar()).QueryInterface(iid);
|
||||
* because our QI would check the IID correctly for us.
|
||||
*/
|
||||
|
||||
if (!iid.equals(Components.interfaces.nsISidebar) &&
|
||||
!iid.equals(Components.interfaces.nsISupports)) {
|
||||
throw Components.results.NS_ERROR_INVALID_ARG;
|
||||
}
|
||||
|
||||
return new mySidebar();
|
||||
}
|
||||
},
|
||||
|
||||
/*
|
||||
* canUnload is used to signal that the component is about to be unloaded.
|
||||
* C++ components can return false to indicate that they don't wish to
|
||||
* be unloaded, but the return value from JS components' canUnload is
|
||||
* ignored: mark-and-sweep will keep everything around until it's no
|
||||
* longer in use, making unconditional ``unload'' safe.
|
||||
*
|
||||
* You still need to provide a (likely useless) canUnload method, though:
|
||||
* it's part of the nsIModule interface contract, and the JS loader _will_
|
||||
* call it.
|
||||
*/
|
||||
canUnload: function(compMgr) {
|
||||
debug("*** Unloading sidebar JS components.");
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
function NSGetModule(compMgr, fileSpec) {
|
||||
return myModule;
|
||||
}
|
||||
|
||||
function debug(s)
|
||||
nsSidebar.prototype.addPanel =
|
||||
function (aTitle, aContentURL, aCustomizeURL)
|
||||
{
|
||||
dump(s+"\n");
|
||||
debug("addPanel(" + aTitle + ", " + aContentURL + ", " +
|
||||
aCustomizeURL + ")");
|
||||
|
||||
if (!this.window)
|
||||
{
|
||||
debug ("no window object set, bailing out.");
|
||||
throw Components.results.NS_ERROR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
/* Create a "container" wrapper around the
|
||||
* "urn:sidebar:current-panel-list" object. This makes it easier
|
||||
* to manipulate the RDF:Seq correctly. */
|
||||
var container =
|
||||
Components.classes[CONTAINER_PROGID].createInstance(nsIRDFContainer);
|
||||
container.Init(this.datasource, this.rdf.GetResource(this.resource));
|
||||
|
||||
/* Create a resource for the new panel and add it to the list */
|
||||
var panel_resource =
|
||||
this.rdf.GetResource("urn:sidebar:3rdparty-panel:" + aContentURL);
|
||||
var panel_index = container.IndexOf(panel_resource);
|
||||
if (panel_index != -1)
|
||||
{
|
||||
this.window.alert(aContentURL + " already exists in your sidebar.");
|
||||
return;
|
||||
}
|
||||
|
||||
var rv = this.window.confirm("Add " + aContentURL + " to your sidebar?");
|
||||
if (!rv)
|
||||
return;
|
||||
|
||||
container.AppendElement(panel_resource);
|
||||
|
||||
/* Now make some sidebar-ish assertions about it... */
|
||||
this.datasource.Assert(panel_resource,
|
||||
this.rdf.GetResource(this.nc + "title"),
|
||||
this.rdf.GetLiteral(aTitle),
|
||||
true);
|
||||
this.datasource.Assert(panel_resource,
|
||||
this.rdf.GetResource(this.nc + "content"),
|
||||
this.rdf.GetLiteral(aContentURL),
|
||||
true);
|
||||
if (aCustomizeURL)
|
||||
this.datasource.Assert(panel_resource,
|
||||
this.rdf.GetResource(this.nc + "customize"),
|
||||
this.rdf.GetLiteral(aCustomizeURL),
|
||||
true);
|
||||
|
||||
/* Write the modified panels out. */
|
||||
this.datasource.QueryInterface(nsIRDFRemoteDataSource).Flush();
|
||||
|
||||
}
|
||||
|
||||
var sidebarModule = new Object();
|
||||
|
||||
sidebarModule.registerSelf =
|
||||
function (compMgr, fileSpec, location, type)
|
||||
{
|
||||
debug("registering (all right -- a JavaScript module!)");
|
||||
compMgr.registerComponentWithType(SIDEBAR_CID, "Sidebar JS Component",
|
||||
SIDEBAR_PROGID, fileSpec, location,
|
||||
true, true, type);
|
||||
}
|
||||
|
||||
function getSidebarDatasourceURI(panels_file_id) {
|
||||
try {
|
||||
var fileLocatorInterface = Components.interfaces.nsIFileLocator;
|
||||
var fileLocatorProgID = 'component://netscape/filelocator';
|
||||
var fileLocatorService = Components.classes[fileLocatorProgID].getService();
|
||||
// use the fileLocator to look in the profile directory
|
||||
// to find 'panels.rdf', which is the
|
||||
// database of the user's currently selected panels.
|
||||
fileLocatorService = fileLocatorService.QueryInterface(fileLocatorInterface);
|
||||
|
||||
// if <profile>/panels.rdf doesn't exist, GetFileLocation() will copy
|
||||
// bin/defaults/profile/panels.rdf to <profile>/panels.rdf
|
||||
var sidebar_file = fileLocatorService.GetFileLocation(panels_file_id);
|
||||
|
||||
if (!sidebar_file.exists()) {
|
||||
// this should not happen, as GetFileLocation() should copy
|
||||
// defaults/panels.rdf to the users profile directory
|
||||
debug("sidebar file does not exist");
|
||||
return null;
|
||||
}
|
||||
|
||||
debug("sidebar uri is " + sidebar_file.URLString);
|
||||
return sidebar_file.URLString;
|
||||
}
|
||||
catch (ex) {
|
||||
// this should not happen
|
||||
debug("Exception raise getting sidebar datasource uri");
|
||||
return null;
|
||||
}
|
||||
sidebarModule.getClassObject =
|
||||
function (compMgr, cid, iid) {
|
||||
if (!cid.equals(SIDEBAR_CID))
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
|
||||
if (!iid.equals(Components.interfaces.nsIFactory))
|
||||
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
return sidebarFactory;
|
||||
}
|
||||
|
||||
sidebarModule.canUnload =
|
||||
function(compMgr)
|
||||
{
|
||||
debug("Unloading component.");
|
||||
return true;
|
||||
}
|
||||
|
||||
/* factory object */
|
||||
sidebarFactory = new Object();
|
||||
|
||||
sidebarFactory.CreateInstance =
|
||||
function (outer, iid) {
|
||||
debug("CI: " + iid);
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
if (!iid.equals(nsISidebar) && !iid.equals(nsISupports))
|
||||
throw Components.results.NS_ERROR_INVALID_ARG;
|
||||
|
||||
return new nsSidebar();
|
||||
}
|
||||
|
||||
/* entrypoint */
|
||||
function NSGetModule(compMgr, fileSpec) {
|
||||
return sidebarModule;
|
||||
}
|
||||
|
||||
/* static functions */
|
||||
if (DEBUG)
|
||||
debug = function (s) { dump("-*- sidebar: " + s + "\n"); }
|
||||
else
|
||||
debug = function (s) {}
|
||||
|
||||
function getSidebarDatasourceURI(panels_file_id)
|
||||
{
|
||||
try
|
||||
{
|
||||
/* use the fileLocator to look in the profile directory
|
||||
* to find 'panels.rdf', which is the
|
||||
* database of the user's currently selected panels. */
|
||||
var fileLocatorService =
|
||||
Components.classes[LOCATOR_PROGID].getService(nsIFileLocator);
|
||||
|
||||
/* if <profile>/panels.rdf doesn't exist, GetFileLocation() will copy
|
||||
*bin/defaults/profile/panels.rdf to <profile>/panels.rdf */
|
||||
var sidebar_file = fileLocatorService.GetFileLocation(panels_file_id);
|
||||
|
||||
if (!sidebar_file.exists())
|
||||
{
|
||||
/* this should not happen, as GetFileLocation() should copy
|
||||
* defaults/panels.rdf to the users profile directory */
|
||||
debug("sidebar file does not exist");
|
||||
return null;
|
||||
}
|
||||
|
||||
debug("sidebar uri is " + sidebar_file.URLString);
|
||||
return sidebar_file.URLString;
|
||||
}
|
||||
catch (ex)
|
||||
{
|
||||
/* this should not happen */
|
||||
debug("caught " + ex + " getting sidebar datasource uri");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user