1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Netscape Public License
5
* Version 1.1 (the "License"); you may not use this file except in
6
* compliance with the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/NPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is mozilla.org code.
16
* The Initial Developer of the Original Code is
17
* Netscape Communications Corporation.
18
* Portions created by the Initial Developer are Copyright (C) 2001
19
* the Initial Developer. All Rights Reserved.
22
* Joe Hewitt <hewitt@netscape.com> (original author)
25
* Alternatively, the contents of this file may be used under the terms of
26
* either the GNU General Public License Version 2 or later (the "GPL"), or
27
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28
* in which case the provisions of the GPL or the LGPL are applicable instead
29
* of those above. If you wish to allow use of your version of this file only
30
* under the terms of either the GPL or the LGPL, and not to allow others to
31
* use your version of this file under the terms of the NPL, indicate your
32
* decision by deleting the provisions above and replace them with the notice
33
* and other provisions required by the GPL or the LGPL. If you do not delete
34
* the provisions above, a recipient may use your version of this file under
35
* the terms of any one of the NPL, the GPL or the LGPL.
37
* ***** END LICENSE BLOCK ***** */
39
/***************************************************************
40
* Inspector Utils ----------------------------------------------
41
* Common functions and constants used across the app.
42
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44
* chrome://inspector/content/jsutil/xpcom/XPCU.js
45
* chrome://inspector/content/jsutil/rdf/RDFU.js
46
****************************************************************/
48
//////////// global constants ////////////////////
50
const kInspectorNSURI = "http://www.mozilla.org/inspector#";
51
const kXULNSURI = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
52
const kHTMLNSURI = "http://www.w3.org/1999/xhtml";
55
/******************************************************************************
56
* Convenience function for calling nsIChromeRegistry::convertChromeURL
57
*******************************************************************************/
58
convertChromeURL: function(aURL)
60
var uri = XPCU.getService("@mozilla.org/network/simple-uri;1", "nsIURI");
62
var reg = XPCU.getService("@mozilla.org/chrome/chrome-registry;1", "nsIChromeRegistry");
63
return reg.convertChromeURL(uri);
66
/******************************************************************************
67
* Convenience function for getting a literal value from nsIRDFDataSource::GetTarget
68
*******************************************************************************/
69
getDSProperty: function(/*nsISupports*/ aDS, /*String*/ aId, /*String*/ aPropName)
71
var ruleRes = gRDF.GetResource(aId);
72
var ds = XPCU.QI(aDS, "nsIRDFDataSource"); // just to be sure
73
var propRes = ds.GetTarget(ruleRes, gRDF.GetResource(kInspectorNSURI+aPropName), true);
74
propRes = XPCU.QI(propRes, "nsIRDFLiteral");
78
/******************************************************************************
79
* Convenience function for persisting an element's persisted attributes.
80
*******************************************************************************/
81
persistAll: function(aId)
83
var el = document.getElementById(aId);
85
var attrs = el.getAttribute("persist").split(" ");
86
for (var i = 0; i < attrs.length; ++i) {
87
document.persist(aId, attrs[i]);
93
// ::::::: debugging utilities ::::::
97
// XX comment out to reduce noise
102
// dump text to the Javascript Console
103
function consoleDump(aText)
105
var csClass = Components.classes['@mozilla.org/consoleservice;1'];
106
var cs = csClass.getService(Components.interfaces.nsIConsoleService);
107
cs.logStringMessage(aText);
110
function dumpDOM(aNode, aIndent)
112
if (!aIndent) aIndent = "";
113
debug(aIndent + "<" + aNode.localName + "\n");
114
var attrs = aNode.attributes;
116
for (var a = 0; a < attrs.length; ++a) {
118
debug(aIndent + " " + attr.nodeName + "=\"" + attr.nodeValue + "\"\n");
120
debug(aIndent + ">\n");
124
for (var i = 0; i < aNode.childNodes.length; ++i)
125
dumpDOM(aNode.childNodes[i], aIndent);
130
// convert nodeType constant into human readable form
131
function nodeTypeToText (nodeType)
133
if (!gStringBundle) {
134
var strBundleService =
135
Components.classes["@mozilla.org/intl/stringbundle;1"].
136
getService(Components.interfaces.nsIStringBundleService);
137
gStringBundle = strBundleService.createBundle("chrome://inspector/locale/inspector.properties");
141
const nsIDOMNode = Components.interfaces.nsIDOMNode;
142
if (nodeType >= nsIDOMNode.ELEMENT_NODE && nodeType <= nsIDOMNode.NOTATION_NODE) {
143
return gStringBundle.GetStringFromName(nodeType);