diff --git a/extensions/inspector/base/Makefile.in b/extensions/inspector/base/Makefile.in new file mode 100644 index 000000000000..38147de3c9d7 --- /dev/null +++ b/extensions/inspector/base/Makefile.in @@ -0,0 +1,32 @@ +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH=../../.. +topsrcdir=@top_srcdir@ +srcdir=@srcdir@ +VPATH=@srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS=public src + +include $(topsrcdir)/config/rules.mk + diff --git a/extensions/inspector/base/makefile.win b/extensions/inspector/base/makefile.win new file mode 100644 index 000000000000..f387218e4af1 --- /dev/null +++ b/extensions/inspector/base/makefile.win @@ -0,0 +1,27 @@ +#!nmake +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\.. +include <$(DEPTH)/config/config.mak> + +DIRS = public src + +include <$(DEPTH)\config\rules.mak> diff --git a/extensions/inspector/base/public/Makefile.in b/extensions/inspector/base/public/Makefile.in new file mode 100644 index 000000000000..0d2c82b0754b --- /dev/null +++ b/extensions/inspector/base/public/Makefile.in @@ -0,0 +1,45 @@ +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH=../../../.. +topsrcdir=@top_srcdir@ +srcdir=@srcdir@ +VPATH=@srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE=inspector +XPIDL_MODULE=inspector + +XPIDLSRCS = nsIDOMDSResource.idl \ + nsIInsDOMDataSource.idl \ + nsICSSRuleDataSource.idl \ + nsICSSDecDataSource.idl \ + nsICSSDecIntHolder.idl \ + inIFlasher.idl \ + inISearchProcess.idl \ + inISearchObserver.idl \ + inICSSValueSearch.idl \ + inIFileSearch.idl \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + diff --git a/extensions/inspector/base/public/inICSSValueSearch.idl b/extensions/inspector/base/public/inICSSValueSearch.idl new file mode 100644 index 000000000000..c2d34de700e0 --- /dev/null +++ b/extensions/inspector/base/public/inICSSValueSearch.idl @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "inISearchProcess.idl" + +interface nsIDOMDocument; + +[scriptable, uuid(e0d39e48-1dd1-11b2-81bd-9a0c117f0736)] +interface inICSSValueSearch : inISearchProcess { + + attribute nsIDOMDocument document; + + // the base url for all returned URL results, if returnRelativeURLs is true + attribute wstring baseURL; + + // strip off the baseURL for all URL results if true + attribute boolean returnRelativeURLs; + + // correct the paths on a chrome url, such as turning global/skin/blah into global/blah + attribute boolean normalizeChromeURLs; + + // add a css property to search for + void addPropertyCriteria(in wstring aPropName); + + // set the text value to search for in the properties specified (optional) + attribute wstring textCriteria; + +}; diff --git a/extensions/inspector/base/public/inIFileSearch.idl b/extensions/inspector/base/public/inIFileSearch.idl new file mode 100644 index 000000000000..eb051d808bda --- /dev/null +++ b/extensions/inspector/base/public/inIFileSearch.idl @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "inISearchProcess.idl" + +interface nsIFile; +interface nsISupportsArray; + +[scriptable, uuid(EFA53257-526D-4350-9088-343A510346B8)] +interface inIFileSearch : inISearchProcess { + // the base url for all returned URL results, if returnRelativePaths is true + attribute wstring basePath; + + // strip off the basePath for all results through getStringResultAt if true + attribute boolean returnRelativePaths; + + unsigned long getDirectoryDepth(in nsIFile aDir); + nsISupportsArray getSubDirectories(in nsIFile aDir); + + // criteria + attribute wstring filenameCriteria; + attribute wstring textCriteria; + attribute nsIFile searchPath; + attribute boolean searchRecursive; + + // results + readonly attribute unsigned long directoriesSearched; + readonly attribute nsIFile currentDirectory; + + nsIFile getFileResultAt(in long aIndex); +}; diff --git a/extensions/inspector/base/public/inIFlasher.idl b/extensions/inspector/base/public/inIFlasher.idl new file mode 100644 index 000000000000..b18e940e5c59 --- /dev/null +++ b/extensions/inspector/base/public/inIFlasher.idl @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +interface nsIDOMDocument; +interface nsIDOMElement; +interface nsIDOMWindowInternal; + +[scriptable, uuid(7B4A099F-6F6E-4565-977B-FB622ADBFF49)] +interface inIFlasher : nsISupports +{ + void drawElementOutline(in nsIDOMElement aElement, in nsIDOMWindowInternal aWindow, in wstring aColor, in long aThickness); + void repaintElement(in nsIDOMElement aElement, in nsIDOMWindowInternal aWindow); +}; + diff --git a/extensions/inspector/base/public/inISearchObserver.idl b/extensions/inspector/base/public/inISearchObserver.idl new file mode 100644 index 000000000000..87a0d00026a0 --- /dev/null +++ b/extensions/inspector/base/public/inISearchObserver.idl @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +interface inISearchProcess; + +[scriptable, uuid(46226D9B-E398-4106-8D9B-225D4D0589F5)] +interface inISearchObserver : nsISupports +{ + // result codes which are sent to onSearchEnd + const short SUCCESS = 1; // search completed successfully + const short INTERRUPTED = 2; // search stopped due to user interruption + const short ERROR = 3; // search stopped due to an error + + void onSearchStart(in inISearchProcess aModule); + void onSearchResult(in inISearchProcess aModule); + void onSearchEnd(in inISearchProcess aModule, in short aResult); + void onSearchError(in inISearchProcess aModule, in wstring aMessage); +}; diff --git a/extensions/inspector/base/public/inISearchOrphanImages.idl b/extensions/inspector/base/public/inISearchOrphanImages.idl new file mode 100644 index 000000000000..1e5690a21f26 --- /dev/null +++ b/extensions/inspector/base/public/inISearchOrphanImages.idl @@ -0,0 +1,34 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +interface nsIDOMDocument; + +[scriptable, uuid(A7FC849B-A705-4da2-AF6C-989417548E6A)] +interface inISearchOrphanImages : nsISupports { + attribute wstring searchPath; + attribute wstring remotePath; + attribute boolean isSkin; + attribute nsIDOMDocument document; +}; + diff --git a/extensions/inspector/base/public/inISearchProcess.idl b/extensions/inspector/base/public/inISearchProcess.idl new file mode 100644 index 000000000000..7957e71d93c1 --- /dev/null +++ b/extensions/inspector/base/public/inISearchProcess.idl @@ -0,0 +1,66 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +interface inISearchObserver; +interface nsISupportsArray; + +[scriptable, uuid(D5FA765B-2448-4686-B7C1-5FF13ACB0FC9)] +interface inISearchProcess : nsISupports +{ + // indicates if an asynchronous search is in progress + readonly attribute boolean isActive; + + // the number of results returned + readonly attribute long resultCount; + + // for optimization when doing an async search, this will optionally + // destroy old results, assuming they will be fetched as soon as + // the observer is notified of their presence. If true, then indices + // pass to the get*ResultAt methods will return null for any index + // other than the most recent one, and getResults will return null always. + attribute boolean holdResults; + + // start a synchronous search + void searchSync(); + + // start an asynchronous search + void searchAsync(in inISearchObserver aObserver); + + // command an async process to stop immediately + void searchStop(); + + // performs a step in the asynchronous search loop + // return indicates true if loop is done, false if it should continue + // This is there only for the benefit of asynchronous search controllers, + // and is not for use by those who just wish to call searchAsync + boolean searchStep(); + + // methods for getting results of specific types + + wstring getStringResultAt(in long aIndex); + + long getIntResultAt(in long aIndex); + + unsigned long getUIntResultAt(in long aIndex); +}; diff --git a/extensions/inspector/base/public/makefile.win b/extensions/inspector/base/public/makefile.win new file mode 100644 index 000000000000..d26ded7cad0e --- /dev/null +++ b/extensions/inspector/base/public/makefile.win @@ -0,0 +1,39 @@ +#!nmake +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\..\.. + +XPIDLSRCS = .\nsIDOMDSResource.idl \ + .\nsIInsDOMDataSource.idl \ + .\nsICSSRuleDataSource.idl \ + .\nsICSSDecDataSource.idl \ + .\nsICSSDecIntHolder.idl \ + .\inIFlasher.idl \ + .\inISearchProcess.idl \ + .\inISearchObserver.idl \ + .\inICSSValueSearch.idl \ + .\inIFileSearch.idl \ + $(NULL) + +MODULE=inspector + +include <$(DEPTH)\config\rules.mak> + diff --git a/extensions/inspector/base/public/nsICSSDecDataSource.idl b/extensions/inspector/base/public/nsICSSDecDataSource.idl new file mode 100644 index 000000000000..581152cdf787 --- /dev/null +++ b/extensions/inspector/base/public/nsICSSDecDataSource.idl @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +interface nsIRDFResource; + +[scriptable, uuid(3777C69B-0605-454f-851C-760F4A05888A)] +interface nsICSSDecDataSource : nsISupports +{ + attribute nsIRDFResource refResource; + + void setCSSProperty(in wstring aName, in wstring aValue, in wstring aPriority); + void removeCSSProperty(in wstring aName); +}; + +%{C++ + +/* {B10FB023-72C7-489f-BE65-BCA9B38F856D} */ +#define NS_CSSDEC_DATASOURCE_CID \ +{ 0xb10fb023, 0x72c7, 0x489f, { 0xbe, 0x65, 0xbc, 0xa9, 0xb3, 0x8f, 0x85, 0x6d } } + +%} + diff --git a/extensions/inspector/base/public/nsICSSDecIntHolder.idl b/extensions/inspector/base/public/nsICSSDecIntHolder.idl new file mode 100644 index 000000000000..ce89b12669fb --- /dev/null +++ b/extensions/inspector/base/public/nsICSSDecIntHolder.idl @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +[scriptable, uuid(AC2EEEC0-8C36-4792-9020-3A81D9AA3110)] +interface nsICSSDecIntHolder : nsISupports +{ +}; + +%{C++ + +/* {32E9DAA2-6D24-46bc-B2A6-E97839650EDA} */ +#define NS_CSSDECINTHOLDER_CID \ +{ 0x32e9daa2, 0x6d24, 0x46bc, { 0xb2, 0xa6, 0xe9, 0x78, 0x39, 0x65, 0xe, 0xda } } + +#define NS_CSSDECINTHOLDER_CONTRACTID \ + "@mozilla.org/inspector/cssdecIntHolder;1" + +%} + diff --git a/extensions/inspector/base/public/nsICSSRuleDataSource.idl b/extensions/inspector/base/public/nsICSSRuleDataSource.idl new file mode 100644 index 000000000000..04ac6bedbd41 --- /dev/null +++ b/extensions/inspector/base/public/nsICSSRuleDataSource.idl @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +interface nsIDOMElement; + +[scriptable, uuid(88B8B7CB-A1A0-4056-A2E1-04F4831C4C91)] +interface nsICSSRuleDataSource : nsISupports +{ + attribute nsIDOMElement element; +}; + +%{C++ + +/* {71BCEACF-D73A-43f3-8F37-09BF916D7854} */ +#define NS_CSSRULE_DATASOURCE_CID \ +{ 0x71bceacf, 0xd73a, 0x43f3, { 0x8f, 0x37, 0x9, 0xbf, 0x91, 0x6d, 0x78, 0x54 } } + +%} + diff --git a/extensions/inspector/base/public/nsIDOMDSResource.idl b/extensions/inspector/base/public/nsIDOMDSResource.idl new file mode 100644 index 000000000000..86722e100e92 --- /dev/null +++ b/extensions/inspector/base/public/nsIDOMDSResource.idl @@ -0,0 +1,41 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" +#include "domstubs.idl" +%{C++ +#include "nsIDOMNode.h" +%} + + +[scriptable, uuid(F092D67C-0DBE-472e-82EA-BF70C9649A8A)] +interface nsIDOMDSResource : nsISupports { + attribute nsISupports object; +}; + +%{C++ + +/* {76C9161F-4C4C-4c1b-8F96-64587315C79E} */ +#define NS_DOMDSRESOURCE_CID \ +{ 0x76c9161f, 0x4c4c, 0x4c1b, { 0x8f, 0x96, 0x64, 0x58, 0x73, 0x15, 0xc7, 0x9e } } + +%} diff --git a/extensions/inspector/base/public/nsIInsDOMDataSource.idl b/extensions/inspector/base/public/nsIInsDOMDataSource.idl new file mode 100644 index 000000000000..ec2867657e1b --- /dev/null +++ b/extensions/inspector/base/public/nsIInsDOMDataSource.idl @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsISupports.idl" + +interface nsIDOMDocument; +interface nsIRDFResource; + +[scriptable, uuid(A029F6DD-9945-4607-850F-C8476387A52A)] +interface nsIInsDOMDataSource : nsISupports +{ + attribute nsIDOMDocument document; + attribute boolean showAnonymousContent; + + void addFilterByType(in unsigned short aType, in boolean aExclusive); + void removeFilterByType(in unsigned short aType); + boolean isFiltered(in unsigned short aType); + nsIRDFResource getResourceForObject(in nsISupports aObject); +}; + +%{C++ + +/* {3AD0C13B-195E-48e7-AF29-F024E2D759EA} */ +#define NS_INSDOMDATASOURCE_CID \ +{ 0x3ad0c13b, 0x195e, 0x48e7, { 0xaf, 0x29, 0xf0, 0x24, 0xe2, 0xd7, 0x59, 0xea } } + +%} + diff --git a/extensions/inspector/base/src/Makefile.in b/extensions/inspector/base/src/Makefile.in new file mode 100644 index 000000000000..db3836c9b696 --- /dev/null +++ b/extensions/inspector/base/src/Makefile.in @@ -0,0 +1,48 @@ +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH=../../../.. +topsrcdir=@top_srcdir@ +srcdir=@srcdir@ +VPATH=@srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE=inspector +LIBRARY_NAME=inspector_s +SHORT_LIBNAME=inspector_s + +CPPSRCS= \ + nsDOMDSResource.cpp \ + nsDOMDataSource.cpp \ + nsCSSRuleDataSource.cpp \ + nsCSSDecDataSource.cpp \ + nsCSSDecIntHolder.cpp \ + inFlasher.cpp \ + inSearchLoop.cpp \ + inCSSValueSearch.cpp \ + inFileSearch.cpp \ + $(NULL) + +override NO_SHARED_LIB=1 +override NO_STATIC_LIB= + +include $(topsrcdir)/config/rules.mk diff --git a/extensions/inspector/base/src/dsinfo.h b/extensions/inspector/base/src/dsinfo.h new file mode 100644 index 000000000000..2e72397ba820 --- /dev/null +++ b/extensions/inspector/base/src/dsinfo.h @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + */ + +#include "nsRDFCID.h" +#include "nsHashtable.h" + +#define INS_NAMESPACE_URI "http://www.mozilla.org/inspector#" + +static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID); +static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); +static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID); +static NS_DEFINE_CID(kRDFContainerUtilsCID, NS_RDFCONTAINERUTILS_CID); +static NS_DEFINE_CID(kISupportsIID, NS_ISUPPORTS_IID); + +// This might not be thread safe as a global variable, but it needs to be global +// because multiple instances of nsDOMDataSource need to use the same +// resource objects for the same nodes so they can pass resource id's +// back and forth. Need to make sure this is thread-safe in the future, though. +static nsSupportsHashtable gDOMObjectTable; + + diff --git a/extensions/inspector/base/src/inCSSValueSearch.cpp b/extensions/inspector/base/src/inCSSValueSearch.cpp new file mode 100644 index 000000000000..d3d0576c9ae9 --- /dev/null +++ b/extensions/inspector/base/src/inCSSValueSearch.cpp @@ -0,0 +1,360 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "inCSSValueSearch.h" + +#include "nsIComponentManager.h" +#include "nsVoidArray.h" + +/////////////////////////////////////////////////////////////////////////////// + +inCSSValueSearch::inCSSValueSearch() +{ + NS_INIT_ISUPPORTS(); + + mHoldResults = PR_TRUE; + mReturnRelativeURLs = PR_FALSE; + mNormalizeChromeURLs = PR_FALSE; + mResultCount = 0; + + mProperties = new nsCSSProperty[100]; + mPropertyCount = 0; + nsCSSProps::AddRefTable(); +} + +inCSSValueSearch::~inCSSValueSearch() +{ + nsCSSProps::ReleaseTable(); + delete mProperties; + delete mResults; +} + +NS_IMPL_ISUPPORTS2(inCSSValueSearch, inISearchProcess, inICSSValueSearch); + +/////////////////////////////////////////////////////////////////////////////// +// inISearchProcess + +NS_IMETHODIMP +inCSSValueSearch::GetIsActive(PRBool *aIsActive) +{ + *aIsActive = mIsActive; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::GetResultCount(PRInt32 *aResultCount) +{ + *aResultCount = mResultCount; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::GetHoldResults(PRBool *aHoldResults) +{ + *aHoldResults = mHoldResults; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SetHoldResults(PRBool aHoldResults) +{ + mHoldResults = aHoldResults; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SearchSync() +{ + InitSearch(); + + nsCOMPtr doc = do_QueryInterface(mDocument); + if (doc) { + PRInt32 count = doc->GetNumberOfStyleSheets(); + for (PRInt32 i = 0; i < count; i++) { + nsIStyleSheet* sheet = doc->GetStyleSheetAt(i); + SearchStyleSheet(sheet); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SearchAsync(inISearchObserver *aObserver) +{ + InitSearch(); + mObserver = aObserver; + + return NS_OK; +} + + +NS_IMETHODIMP +inCSSValueSearch::SearchStop() +{ + KillSearch(inISearchObserver::INTERRUPTED); + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SearchStep(PRBool* _retval) +{ + + return NS_OK; +} + + +NS_IMETHODIMP +inCSSValueSearch::GetStringResultAt(PRInt32 aIndex, PRUnichar **_retval) +{ + if (mHoldResults) { + nsAutoString* result = (nsAutoString*)mResults->ElementAt(aIndex); + *_retval = result->ToNewUnicode(); + } else if (aIndex == mResultCount-1) { + *_retval = mLastResult->ToNewUnicode(); + } else { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::GetIntResultAt(PRInt32 aIndex, PRInt32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +inCSSValueSearch::GetUIntResultAt(PRInt32 aIndex, PRUint32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/////////////////////////////////////////////////////////////////////////////// +// inICSSValueSearch + +NS_IMETHODIMP +inCSSValueSearch::GetDocument(nsIDOMDocument** aDocument) +{ + *aDocument = mDocument; + NS_IF_ADDREF(*aDocument); + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SetDocument(nsIDOMDocument* aDocument) +{ + mDocument = aDocument; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::GetBaseURL(PRUnichar** aBaseURL) +{ + *aBaseURL = mBaseURL->ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SetBaseURL(const PRUnichar* aBaseURL) +{ + nsAutoString url; + mBaseURL = &url; + url.Assign(aBaseURL); + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::GetReturnRelativeURLs(PRBool* aReturnRelativeURLs) +{ + *aReturnRelativeURLs = mReturnRelativeURLs; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SetReturnRelativeURLs(PRBool aReturnRelativeURLs) +{ + mReturnRelativeURLs = aReturnRelativeURLs; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::GetNormalizeChromeURLs(PRBool *aNormalizeChromeURLs) +{ + *aNormalizeChromeURLs = mNormalizeChromeURLs; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SetNormalizeChromeURLs(PRBool aNormalizeChromeURLs) +{ + mNormalizeChromeURLs = aNormalizeChromeURLs; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::AddPropertyCriteria(const PRUnichar *aPropName) +{ + nsAutoString propName; + propName.Assign(aPropName); + nsCSSProperty prop = nsCSSProps::LookupProperty(propName); + mProperties[mPropertyCount] = prop; + mPropertyCount++; + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::GetTextCriteria(PRUnichar** aTextCriteria) +{ + *aTextCriteria = mTextCriteria->ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +inCSSValueSearch::SetTextCriteria(const PRUnichar* aTextCriteria) +{ + if (!mTextCriteria) mTextCriteria = new nsAutoString(); + mTextCriteria->Assign(aTextCriteria); + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////////////// +// inCSSValueSearch + +nsresult +inCSSValueSearch::InitSearch() +{ + if (mHoldResults) { + mResults = new nsVoidArray(); + } + + mResultCount = 0; + + return NS_OK; +} + +nsresult +inCSSValueSearch::KillSearch(PRInt16 aResult) +{ + mIsActive = PR_TRUE; + mObserver->OnSearchEnd(this, aResult); + + return NS_OK; +} + +nsresult +inCSSValueSearch::SearchStyleSheet(nsIStyleSheet* aStyleSheet) +{ + NS_IF_ADDREF(aStyleSheet); + nsCOMPtr cssSheet = do_QueryInterface(aStyleSheet); + if (cssSheet) { + // recurse downward through the stylesheet tree + PRInt32 count; + cssSheet->StyleSheetCount(count); + for (PRInt32 i = 0; i < count; i++) { + nsICSSStyleSheet* child; + cssSheet->GetStyleSheetAt(i, child); + SearchStyleSheet(child); + } + + cssSheet->StyleRuleCount(count); + for (i = 0; i < count; i++) { + nsICSSRule* rule; + cssSheet->GetStyleRuleAt(i, rule); + SearchStyleRule(rule); + } + } + + NS_IF_RELEASE(aStyleSheet); + return NS_OK; +} + +nsresult +inCSSValueSearch::SearchStyleRule(nsIStyleRule* aStyleRule) +{ + NS_IF_ADDREF(aStyleRule); + + nsCOMPtr cssRule = do_QueryInterface(aStyleRule); + if (cssRule) { + nsCOMPtr aDec = cssRule->GetDeclaration(); + for (PRUint32 i = 0; i < mPropertyCount; i++) { + nsCSSProperty prop = mProperties[i]; + SearchStyleValue(aDec, prop); + } + } + + + NS_IF_RELEASE(aStyleRule); + return NS_OK; +} + +nsresult +inCSSValueSearch::SearchStyleValue(nsICSSDeclaration* aDec, nsCSSProperty aProp) +{ + nsCString cstring = nsCSSProps::GetStringValue(aProp); + + nsCSSValue value; + aDec->GetValue(aProp, value); + + if (value.GetUnit() == eCSSUnit_URL) { + nsAutoString* result = new nsAutoString(); + value.GetStringValue(*result); + if (mReturnRelativeURLs) + EqualizeURL(result); + mResults->AppendElement((void*)result); + mResultCount++; + } + + return NS_OK; +} + +nsresult +inCSSValueSearch::EqualizeURL(nsAutoString* aURL) +{ + if (mNormalizeChromeURLs) { + if (aURL->Find("chrome://", false, 0, 1) >= 0) { + PRUint32 len = aURL->Length(); + char* result = new char[len-8]; + char* buffer = aURL->ToNewCString(); + PRUint32 i = 9; + PRUint32 milestone = 0; + PRUint32 s = 0; + while (i < len) { + if (buffer[i] == '/') { + milestone += 1; + } + if (milestone == 0 || milestone > 1) { + result[i-9-s] = (buffer[i] == '/') ? '/' : buffer[i]; + } else { + s++; + } + i++; + } + result[i-9-s] = 0; + + aURL->AssignWithConversion(result); + } + } else { + } + + return NS_OK; +} \ No newline at end of file diff --git a/extensions/inspector/base/src/inCSSValueSearch.h b/extensions/inspector/base/src/inCSSValueSearch.h new file mode 100644 index 000000000000..d098bf75a7d3 --- /dev/null +++ b/extensions/inspector/base/src/inCSSValueSearch.h @@ -0,0 +1,85 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef __inCSSValueSearch_h__ +#define __inCSSValueSearch_h__ + +#include "inICSSValueSearch.h" + +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsIDocument.h" +#include "nsIDOMDocument.h" +#include "inISearchObserver.h" +#include "nsVoidArray.h" +#include "nsICSSStyleSheet.h" +#include "nsICSSStyleRule.h" +#include "nsICSSDeclaration.h" +#include "nsCSSValue.h" + +class inCSSValueSearch : public inICSSValueSearch +{ +public: + inCSSValueSearch(); + ~inCSSValueSearch(); + +protected: + PRBool mIsActive; + PRInt32 mResultCount; + PRBool mHoldResults; + nsVoidArray* mResults; + nsAutoString* mLastResult; + nsCOMPtr mObserver; + + nsCOMPtr mDocument; + nsAutoString* mBaseURL; + PRBool mReturnRelativeURLs; + PRBool mNormalizeChromeURLs; + nsAutoString* mTextCriteria; + nsCSSProperty* mProperties; + PRUint32 mPropertyCount; + + nsresult InitSearch(); + nsresult KillSearch(PRInt16 aResult); + nsresult SearchStyleSheet(nsIStyleSheet* aStyleSheet); + nsresult SearchStyleRule(nsIStyleRule* aStyleRule); + nsresult SearchStyleValue(nsICSSDeclaration* aDec, nsCSSProperty aProp); + nsresult EqualizeURL(nsAutoString* aURL); + +public: + NS_DECL_ISUPPORTS + + NS_DECL_INISEARCHPROCESS + + NS_DECL_INICSSVALUESEARCH +}; + +////////////////////////////////////////////////////////////// + +// {4D977F60-FBE7-4583-8CB7-F5ED882293EF} +#define IN_CSSVALUESEARCH_CID \ +{ 0x4d977f60, 0xfbe7, 0x4583, { 0x8c, 0xb7, 0xf5, 0xed, 0x88, 0x22, 0x93, 0xef } } + +#define IN_CSSVALUESEARCH_CONTRACTID \ +"@mozilla.org/inspector/search;1?type=cssvalue" + +#endif diff --git a/extensions/inspector/base/src/inFileSearch.cpp b/extensions/inspector/base/src/inFileSearch.cpp new file mode 100644 index 000000000000..fc9c1de7a89b --- /dev/null +++ b/extensions/inspector/base/src/inFileSearch.cpp @@ -0,0 +1,638 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "inFileSearch.h" + +#include "nsCOMPtr.h" +#include "nsString.h" + +/////////////////////////////////////////////////////////////////////////////// + +inFileSearch::inFileSearch() +{ + NS_INIT_ISUPPORTS(); + + mSearchLoop = 0; +} + +inFileSearch::~inFileSearch() +{ +} + +NS_IMPL_ISUPPORTS2(inFileSearch, inISearchProcess, inIFileSearch); + +/////////////////////////////////////////////////////////////////////////////// +// inISearchProcess + +NS_IMETHODIMP +inFileSearch::GetIsActive(PRBool *aIsActive) +{ + *aIsActive = mIsActive; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetResultCount(PRInt32 *aResultCount) +{ + *aResultCount = mResultCount; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetHoldResults(PRBool *aHoldResults) +{ + *aHoldResults = mHoldResults; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SetHoldResults(PRBool aHoldResults) +{ + mHoldResults = aHoldResults; + return NS_OK; +} + + +NS_IMETHODIMP +inFileSearch::SearchSync() +{ +/* if (mSearchPath) + SearchDirectory(mSearchPath, PR_TRUE); + else { + return NS_ERROR_FAILURE; + } +*/ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +inFileSearch::SearchAsync(inISearchObserver *aObserver) +{ + mObserver = aObserver; + mObserver->OnSearchStart(this); + + InitSearch(); + InitSubDirectoryStack(); + InitSearchLoop(); + + if (mSearchPath) { + // start off by searching the first directory + SearchDirectory(mSearchPath, PR_FALSE); + + if (mSearchRecursive) { + // start the loop to continue searching + mIsActive = PR_TRUE; + mSearchLoop->Start(); + } else { + KillSearch(inISearchObserver::SUCCESS); + } + } else { + nsAutoString msg; + msg.AssignWithConversion("No search path has been provided"); + mObserver->OnSearchError(this, msg.ToNewUnicode()); + KillSearch(inISearchObserver::ERROR); + } + + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SearchStop() +{ + KillSearch(inISearchObserver::INTERRUPTED); + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SearchStep(PRBool* _retval) +{ + nsIFile* nextDir; + PRBool more = GetNextSubDirectory(&nextDir); + + if (more) { + SearchDirectory(nextDir, PR_FALSE); + } else { + KillSearch(inISearchObserver::SUCCESS); + *_retval = PR_TRUE; + } + + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetStringResultAt(PRInt32 aIndex, PRUnichar **_retval) +{ + nsCOMPtr file; + + if (mHoldResults) { + nsCOMPtr supports; + mResults->GetElementAt(aIndex, getter_AddRefs(supports)); + file = do_QueryInterface(supports); + } else if (aIndex == mResultCount-1 && mLastResult) { + // get the path of the last result as an nsAutoString + file = mLastResult; + } + + if (file) { + char* temp; + mLastResult->GetPath(&temp); + nsAutoString path; + path.AssignWithConversion(temp); + if (mReturnRelativePaths) + MakePathRelative(&path); + *_retval = path.ToNewUnicode(); + } else { + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetIntResultAt(PRInt32 aIndex, PRInt32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +inFileSearch::GetUIntResultAt(PRInt32 aIndex, PRUint32 *_retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/////////////////////////////////////////////////////////////////////////////// +// inIFileSearch + +NS_IMETHODIMP +inFileSearch::GetBasePath(PRUnichar** aBasePath) +{ + if (mBasePath) { + *aBasePath = mBasePath->ToNewUnicode(); + } else { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SetBasePath(const PRUnichar* aBasePath) +{ + mBasePath = new nsAutoString(); + mBasePath->Assign(aBasePath); + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetReturnRelativePaths(PRBool* aReturnRelativePaths) +{ + *aReturnRelativePaths = mReturnRelativePaths; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SetReturnRelativePaths(PRBool aReturnRelativePaths) +{ + mReturnRelativePaths = aReturnRelativePaths; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetFilenameCriteria(PRUnichar** aFilenameCriteria) +{ + // TODO: reconstruct parsed filename criteria into string + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SetFilenameCriteria(const PRUnichar* aFilenameCriteria) +{ + // first pass: scan for commas so we know how long to make array + PRUint32 idx = 0; + PRUint32 commas = 0; + const PRUnichar* c = aFilenameCriteria; + while (*c) { + if (*c == ',') + ++commas; + ++c; + } + + mFilenameCriteria = new PRUnichar*[commas+1]; + mFilenameCriteriaCount = 0; + + // second pass: split up at commas and insert into array + idx = 0; + PRUint32 lastComma = -1; + PRUnichar* buf = new PRUnichar[257]; + c = aFilenameCriteria; + PRBool going = PR_TRUE; + while (going) { + if (*c == ',' || !*c) { + buf[idx-lastComma-1] = 0; + lastComma = idx; + mFilenameCriteria[mFilenameCriteriaCount] = buf; + ++mFilenameCriteriaCount; + buf = new PRUnichar[257]; + if (!*c) going = PR_FALSE; + } else { + buf[idx-lastComma-1] = *c; + } + ++c; + ++idx; + } + + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetTextCriteria(PRUnichar** aTextCriteria) +{ + *aTextCriteria = mTextCriteria->ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SetTextCriteria(const PRUnichar* aTextCriteria) +{ + mTextCriteria = new nsAutoString(); + mTextCriteria->Assign(aTextCriteria); + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetSearchPath(nsIFile** aSearchPath) +{ + *aSearchPath = mSearchPath; + NS_IF_ADDREF(*aSearchPath); + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SetSearchPath(nsIFile* aSearchPath) +{ + mSearchPath = aSearchPath; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetSearchRecursive(PRBool* aSearchRecursive) +{ + *aSearchRecursive = mSearchRecursive; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::SetSearchRecursive(PRBool aSearchRecursive) +{ + mSearchRecursive = aSearchRecursive; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetDirectoriesSearched(PRUint32* aDirectoriesSearched) +{ + *aDirectoriesSearched = mDirsSearched; + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetCurrentDirectory(nsIFile** aCurrentDirectory) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +inFileSearch::GetFileResultAt(PRInt32 aIndex, nsIFile** _retval) +{ + if (mHoldResults && mResults) { + nsCOMPtr supports; + mResults->GetElementAt(aIndex, getter_AddRefs(supports)); + nsCOMPtr file = do_QueryInterface(supports); + *_retval = file; + } else if (aIndex == mResultCount-1 && mLastResult) { + *_retval = mLastResult; + NS_IF_ADDREF(*_retval); + } else { + return NS_ERROR_FAILURE; + } + return NS_OK; +} + +NS_IMETHODIMP +inFileSearch::GetDirectoryDepth(nsIFile* aDir, PRUint32* _retval) +{ + *_retval = 0; + return CountDirectoryDepth(aDir, _retval); +} + +NS_IMETHODIMP +inFileSearch::GetSubDirectories(nsIFile* aDir, nsISupportsArray** _retval) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +/////////////////////////////////////////////////////////////////////////////// +// inFileSearch + +nsresult +inFileSearch::InitSearch() +{ + if (mHoldResults) { + mResults = do_CreateInstance("@mozilla.org/supports-array;1"); + } else { + mResults = nsnull; + } + + mLastResult = nsnull; + mResultCount = 0; + mDirsSearched = 0; + return NS_OK; +} + +nsresult +inFileSearch::KillSearch(PRInt16 aResult) +{ + mIsActive = PR_TRUE; + mObserver->OnSearchEnd(this, aResult); + + return NS_OK; +} + +nsresult +inFileSearch::SearchDirectory(nsIFile* aDir, PRBool aIsSync) +{ + ++mDirsSearched; + + // recurse through subdirectories + nsISimpleEnumerator* entries; + aDir->GetDirectoryEntries(&entries); + + if (!aIsSync) { + // store this directory for next step in async search + PushSubDirectoryOnStack(aDir); + } + + PRBool hasMoreElements; + PRBool isDirectory; + nsCOMPtr entry; + + entries->HasMoreElements(&hasMoreElements); + while (hasMoreElements) { + entries->GetNext(getter_AddRefs(entry)); + entries->HasMoreElements(&hasMoreElements); + + entry->IsDirectory(&isDirectory); + if (isDirectory && aIsSync) { + // this is a directory, so search it now (only if synchronous) + if (aIsSync) + SearchDirectory(entry, aIsSync); + } else { + // this is a file, so see if it matches + if (MatchFile(entry)) { + PrepareResult(entry, aIsSync); + } + } + } + + return NS_OK; +} + +nsresult +inFileSearch::PrepareResult(nsIFile* aFile, PRBool aIsSync) +{ + if (aIsSync || mHoldResults) { + mResults->AppendElement(aFile); + } + + if (!aIsSync) { + ++mResultCount; + mLastResult = aFile; + mObserver->OnSearchResult(this); + } + + return NS_OK; +} + +nsresult +inFileSearch::InitSearchLoop() +{ + if (!mSearchLoop) { + nsCOMPtr process = do_QueryInterface(this); + mSearchLoop = new inSearchLoop(process); + } + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////////////// +// Subdirectory stack (for asynchronous searches) + +nsresult +inFileSearch::InitSubDirectoryStack() +{ + mDirStack = do_CreateInstance("@mozilla.org/supports-array;1"); + + return NS_OK; +} + +PRBool +inFileSearch::GetNextSubDirectory(nsIFile** aDir) +{ + // get the enumerator on top of the stack + nsCOMPtr supports; + nsCOMPtr nextDirs; + PRUint32 count; + + while (true) { + mDirStack->Count(&count); + // the stack is empty, so our search must be complete + if (count == 0) return PR_FALSE; + + // get the next directory enumerator on the stack + mDirStack->GetElementAt(count-1, getter_AddRefs(supports)); + nextDirs = do_QueryInterface(supports); + + // get the next directory from the enumerator + nsIFile* dir = GetNextDirectory(nextDirs); + + if (dir) { + // this enumerator is ready to rock, so let's move on + *aDir = dir; + return PR_TRUE; + } else { + // enumerator is done, so pop it off the stack + mDirStack->RemoveElement(supports); + } + } + + + return PR_TRUE; +} + +nsresult +inFileSearch::PushSubDirectoryOnStack(nsIFile* aDir) +{ + nsISimpleEnumerator* entries; + aDir->GetDirectoryEntries(&entries); + mDirStack->AppendElement(entries); + return NS_OK; +} + +nsIFile* +inFileSearch::GetNextDirectory(nsISimpleEnumerator* aEnum) +{ + nsCOMPtr file; + nsCOMPtr supports; + PRBool isDir; + PRBool hasMoreElements; + + while (true) { + aEnum->HasMoreElements(&hasMoreElements); + if (!hasMoreElements) + break; + aEnum->GetNext(getter_AddRefs(supports)); + file = do_QueryInterface(supports); + file->IsDirectory(&isDir); + if (isDir) + break; + } + + nsIFile* f = file.get(); + NS_IF_ADDREF(f); + + return isDir ? f : nsnull; +} + +/////////////////////////////////////////////////////////////////////////////// +// Pattern Matching + +PRBool +inFileSearch::MatchFile(nsIFile* aFile) +{ + char* fileName; + aFile->GetLeafName(&fileName); + + nsAutoString temp; + temp.AssignWithConversion(fileName); + + PRUnichar* fileNameUnicode = temp.ToNewUnicode(); + + PRBool match; + + for (PRUint32 i = 0; i < mFilenameCriteriaCount; ++i) { + match = MatchPattern(mFilenameCriteria[i], fileNameUnicode); + if (match) return PR_TRUE; + } + + return PR_FALSE; +} + +PRBool +inFileSearch::MatchPattern(PRUnichar* aPattern, PRUnichar* aString) +{ + PRInt32 index = 0; + PRBool matching = true; + char wildcard = '*'; + + PRUnichar* patternPtr = aPattern; + PRUnichar* stringPtr = aString; + + while (matching && *patternPtr && *stringPtr) { + if (*patternPtr == wildcard) { + matching = AdvanceWildcard(&stringPtr, patternPtr+1); + } else { + matching = *patternPtr == *stringPtr; + ++stringPtr; + } + if (!matching) return false; + ++patternPtr; + ++index; + } + + return matching; +} + +PRBool +inFileSearch::AdvanceWildcard(PRUnichar** aString, PRUnichar* aNextChar) +{ + PRUnichar* stringPtr = *aString; + + while (1) { + if (*stringPtr == *aNextChar) { + // we have found the next char after the wildcard, so return with success + *aString = stringPtr; + return true; + } else if (*stringPtr == 0) + return false; + ++stringPtr; + } +} + +/////////////////////////////////////////////////////////////////////////////// +// URL fixing + +nsresult +inFileSearch::MakePathRelative(nsAutoString* aPath) +{ + nsAutoString result; + + // get an nsAutoString version of the search path + char* temp; + mSearchPath->GetPath(&temp); + nsAutoString searchPath; + searchPath.AssignWithConversion(temp); + + PRInt32 found = aPath->Find(searchPath, false, 0, 1); + if (found == 0) { + PRUint32 len = searchPath.Length(); + aPath->Mid(result, len+1, aPath->Length()-len); + result.ReplaceChar('\\', '/'); + } + aPath->Assign(result); + + return NS_OK; +} + +nsresult +inFileSearch::CountDirectoryDepth(nsIFile* aDir, PRUint32* aDepth) +{ + ++(*aDepth); + + nsISimpleEnumerator* entries; + aDir->GetDirectoryEntries(&entries); + + PRBool hasMoreElements; + PRBool isDirectory; + nsCOMPtr entry; + + entries->HasMoreElements(&hasMoreElements); + while (hasMoreElements) { + entries->GetNext(getter_AddRefs(entry)); + entries->HasMoreElements(&hasMoreElements); + + entry->IsDirectory(&isDirectory); + if (isDirectory) { + CountDirectoryDepth(entry, aDepth); + } + } + + return NS_OK; +} \ No newline at end of file diff --git a/extensions/inspector/base/src/inFileSearch.h b/extensions/inspector/base/src/inFileSearch.h new file mode 100644 index 000000000000..f4db59b90d21 --- /dev/null +++ b/extensions/inspector/base/src/inFileSearch.h @@ -0,0 +1,103 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef __inFileSearch_h__ +#define __inFileSearch_h__ + +#include "inIFileSearch.h" + +#include "nsString.h" +#include "nsVoidArray.h" +#include "nsISupportsArray.h" +#include "inISearchObserver.h" +#include "nsIFile.h" +#include "inSearchLoop.h" + +class inFileSearch : public inIFileSearch +{ +public: + inFileSearch(); + ~inFileSearch(); + +protected: + // inISearchProcess related + PRBool mIsActive; + PRInt32 mResultCount; + nsIFile* mLastResult; + nsCOMPtr mResults; + PRBool mHoldResults; + nsAutoString* mBasePath; + PRBool mReturnRelativePaths; + nsCOMPtr mObserver; + + // inIFileSearch related + nsCOMPtr mSearchPath; + nsAutoString* mTextCriteria; + PRUnichar** mFilenameCriteria; + PRUint32 mFilenameCriteriaCount; + PRBool mSearchRecursive; + PRUint32 mDirsSearched; + + // asynchronous search related + nsCOMPtr mDirStack; + inSearchLoop* mSearchLoop; + + // life cycle of search + nsresult InitSearch(); + nsresult KillSearch(PRInt16 aResult); + nsresult SearchDirectory(nsIFile* aDir, PRBool aIsSync); + nsresult PrepareResult(nsIFile* aFile, PRBool aIsSync); + + // asynchronous search helpers + nsresult InitSearchLoop(); + nsresult InitSubDirectoryStack(); + PRBool GetNextSubDirectory(nsIFile** aDir); + nsresult PushSubDirectoryOnStack(nsIFile* aDir); + nsIFile* GetNextDirectory(nsISimpleEnumerator* aEnum); + + // pattern matching + PRBool MatchFile(nsIFile* aFile); + static PRBool MatchPattern(PRUnichar* aPattern, PRUnichar* aString); + static PRBool AdvanceWildcard(PRUnichar** aString, PRUnichar* aNextChar); + + // misc + nsresult MakePathRelative(nsAutoString* aPath); + nsresult CountDirectoryDepth(nsIFile* aDir, PRUint32* aDepth); + +public: + NS_DECL_ISUPPORTS + + NS_DECL_INISEARCHPROCESS + + NS_DECL_INIFILESEARCH +}; + +////////////////////////////////////////////////////////////// + +// {D5636476-9F94-47f2-9CE9-69CDD9D7BBCD} +#define IN_FILESEARCH_CID \ +{ 0xd5636476, 0x9f94, 0x47f2, { 0x9c, 0xe9, 0x69, 0xcd, 0xd9, 0xd7, 0xbb, 0xcd } } + +#define IN_FILESEARCH_CONTRACTID \ +"@mozilla.org/inspector/search;1?type=file" + +#endif diff --git a/extensions/inspector/base/src/inFlasher.cpp b/extensions/inspector/base/src/inFlasher.cpp new file mode 100644 index 000000000000..ef8afd3d83e2 --- /dev/null +++ b/extensions/inspector/base/src/inFlasher.cpp @@ -0,0 +1,182 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "inFlasher.h" +#include "dsinfo.h" + +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsIServiceManager.h" +#include "nsIFile.h" +#include "nsDirectoryServiceDefs.h" +#include "nsIDocument.h" +#include "nsIDocShell.h" +#include "nsIPresShell.h" +#include "nsIRenderingContext.h" +#include "nsIContent.h" +#include "nsIFrame.h" +#include "nsIDOMWindowInternal.h" +#include "nsIDOMElement.h" +#include "nsIView.h" +#include "nsIViewManager.h" +#include "nsIScriptGlobalObject.h" + +/////////////////////////////////////////////////////////////////////////////// + +inFlasher::inFlasher() +{ + NS_INIT_REFCNT(); +} + +inFlasher::~inFlasher() +{ +} + +NS_IMPL_ISUPPORTS1(inFlasher, inIFlasher); + +/////////////////////////////////////////////////////////////////////////////// +// inIFlasher + +NS_IMETHODIMP +inFlasher::RepaintElement(nsIDOMElement* aElement, nsIDOMWindowInternal* aWindow) +{ + nsIPresShell* presShell = GetPresShellFor(aWindow); + nsIFrame* frame = GetFrameFor(aElement, presShell); + if (!frame) return NS_OK; + + nsCOMPtr pcontext; + presShell->GetPresContext(getter_AddRefs(pcontext)); + + nsIFrame* parentWithView; + frame->GetParentWithView(pcontext, &parentWithView); + if (parentWithView) { + nsIView* view; + parentWithView->GetView(pcontext, &view); + if (view) { + nsIViewManager* viewManager; + view->GetViewManager(viewManager); + + nsRect rect; + parentWithView->GetRect(rect); + + viewManager->UpdateView(view, rect, NS_VMREFRESH_NO_SYNC); + } + } + + return NS_OK; +} + +NS_IMETHODIMP +inFlasher::DrawElementOutline(nsIDOMElement* aElement, nsIDOMWindowInternal* aWindow, const PRUnichar* aColor, PRInt32 aThickness) +{ + nsIPresShell* presShell = GetPresShellFor(aWindow); + nsIFrame* frame = GetFrameFor(aElement, presShell); + if (!frame) return NS_OK; + + nsCOMPtr pcontext; + presShell->GetPresContext(getter_AddRefs(pcontext)); + nsCOMPtr rcontext; + presShell->CreateRenderingContext(frame, getter_AddRefs(rcontext)); + + nsAutoString colorStr; + colorStr.Assign(aColor); + nscolor color; + PRBool rv = NS_HexToRGB(colorStr, &color); + + nsRect rect; + frame->GetRect(rect); + nsPoint origin(0,0); + GetClientOrigin(frame, origin); + + float p2t; + pcontext->GetPixelsToTwips(&p2t); + + DrawOutline(origin.x, origin.y, rect.width, rect.height, color, aThickness, p2t, rcontext); + + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////////////// +// inFlasher + +NS_IMETHODIMP +inFlasher::DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, nscolor aColor, + PRUint32 aThickness, float aP2T, nsIRenderingContext* aRenderContext) +{ + aRenderContext->SetColor(aColor); + DrawLine(aX, aY, aWidth, aThickness, DIR_HORIZONTAL, BOUND_OUTER, aP2T, aRenderContext); + DrawLine(aX, aY, aHeight, aThickness, DIR_VERTICAL, BOUND_OUTER, aP2T, aRenderContext); + DrawLine(aX, aY+aHeight, aWidth, aThickness, DIR_HORIZONTAL, BOUND_INNER, aP2T, aRenderContext); + DrawLine(aX+aWidth, aY, aHeight, aThickness, DIR_VERTICAL, BOUND_INNER, aP2T, aRenderContext); + + return NS_OK; +} + +NS_IMETHODIMP +inFlasher::DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness, + PRBool aDir, PRBool aBounds, float aP2T, nsIRenderingContext* aRenderContext) +{ + nscoord thickTwips = NSIntPixelsToTwips(aThickness, aP2T); + if (aDir) { // horizontal + aRenderContext->FillRect(aX, aY+(aBounds?0:-thickTwips), aLength, thickTwips); + } else { // vertical + aRenderContext->FillRect(aX+(aBounds?0:-thickTwips), aY, thickTwips, aLength); + } + + return NS_OK; +} + +NS_IMETHODIMP +inFlasher::GetClientOrigin(nsIFrame* aFrame, nsPoint& aPoint) +{ + nsIFrame* parent = aFrame; + while (parent) { + nsPoint origin; + parent->GetOrigin(origin); + aPoint.x += origin.x; + aPoint.y += origin.y; + parent->GetParent(&parent); + } + return NS_OK; +} + +nsIFrame* +inFlasher::GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell) +{ + nsCOMPtr content = do_QueryInterface(aElement); + nsIFrame* frame; + aShell->GetPrimaryFrameFor(content, &frame); + return frame; +} + +nsIPresShell* +inFlasher::GetPresShellFor(nsISupports* aThing) +{ + nsCOMPtr so = do_QueryInterface(aThing); + nsCOMPtr docShell; + so->GetDocShell(getter_AddRefs(docShell)); + + nsIPresShell* presShell; + docShell->GetPresShell(&presShell); + + return presShell; +} \ No newline at end of file diff --git a/extensions/inspector/base/src/inFlasher.h b/extensions/inspector/base/src/inFlasher.h new file mode 100644 index 000000000000..34923b65fd08 --- /dev/null +++ b/extensions/inspector/base/src/inFlasher.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef __inFlasher_h__ +#define __inFlasher_h__ + +#include "inIFlasher.h" + +#include "nsIDOMElement.h" +#include "nsIPresShell.h" +#include "nsIFrame.h" +#include "nsIRenderingContext.h" + +#define BOUND_INNER 0 +#define BOUND_OUTER 1 + +#define DIR_VERTICAL 0 +#define DIR_HORIZONTAL 1 + +class inFlasher : public inIFlasher +{ +public: + inFlasher(); + ~inFlasher(); + +protected: + nsIFrame* GetFrameFor(nsIDOMElement* aElement, nsIPresShell* aShell); + nsIPresShell* GetPresShellFor(nsISupports* aThing); + + NS_IMETHOD DrawOutline(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight, nscolor aColor, + PRUint32 aThickness, float aP2T, nsIRenderingContext* aRenderContext); + NS_IMETHOD DrawLine(nscoord aX, nscoord aY, nscoord aLength, PRUint32 aThickness, + PRBool aDir, PRBool aBounds, float aP2T, nsIRenderingContext* aRenderContext); + NS_IMETHOD GetClientOrigin(nsIFrame* aFrame, nsPoint& aPoint); + +public: + NS_DECL_ISUPPORTS + + NS_DECL_INIFLASHER +}; + +////////////////////////////////////////////////////////////// + +// {9286E71A-621A-4b91-851E-9984C1A2E81A} +#define IN_FLASHER_CID \ +{ 0x9286e71a, 0x621a, 0x4b91, { 0x85, 0x1e, 0x99, 0x84, 0xc1, 0xa2, 0xe8, 0x1a } } + +#define IN_FLASHER_CONTRACTID \ +"@mozilla.org/inspector/flasher;1" + +#endif diff --git a/extensions/inspector/base/src/inSearchItemImage.cpp b/extensions/inspector/base/src/inSearchItemImage.cpp new file mode 100644 index 000000000000..65d94d15fff2 --- /dev/null +++ b/extensions/inspector/base/src/inSearchItemImage.cpp @@ -0,0 +1,83 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "inSearchItemImage.h" + +/////////////////////////////////////////////////////////////////////////////// + +inSearchItemImage::inSearchItemImage(nsAutoString* aURL) +{ + NS_INIT_ISUPPORTS(); + + mURL = *aURL; +} + +inSearchItemImage::~inSearchItemImage() +{ +} + +NS_IMPL_ISUPPORTS1(inSearchItemImage, inISearchItem); + +/////////////////////////////////////////////////////////////////////////////// +// inISearchItem + +NS_IMETHODIMP +inSearchItemImage::GetDescription(PRUnichar** aDescription) +{ + *aDescription = mURL.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +inSearchItemImage::GetIconURL(PRUnichar** aURL) +{ + nsAutoString url; + url.AssignWithConversion("chrome://inspector/content/search/ImageSearchItem.gif"); + *aURL = url.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +inSearchItemImage::IsViewable(PRBool* _retval) +{ + *_retval = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP +inSearchItemImage::IsEditable(PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +inSearchItemImage::ViewItem(nsIDOMElement **_retval) +{ + return NS_OK; +} + +NS_IMETHODIMP +inSearchItemImage::EditItem() +{ + return NS_OK; +} \ No newline at end of file diff --git a/extensions/inspector/base/src/inSearchItemImage.h b/extensions/inspector/base/src/inSearchItemImage.h new file mode 100644 index 000000000000..6a8066c788b7 --- /dev/null +++ b/extensions/inspector/base/src/inSearchItemImage.h @@ -0,0 +1,55 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef __searchItemImage_h__ +#define __searchItemImage_h__ + +#include "inISearchItem.h" + +#include "nsCOMPtr.h" +#include "nsString.h" + +class inSearchItemImage : public inISearchItem +{ +public: + inSearchItemImage(nsAutoString* aURL); + ~inSearchItemImage(); + +protected: + nsAutoString mURL; + +public: + NS_DECL_ISUPPORTS + + NS_DECL_INISEARCHITEM +}; + +//////////////////////////////////////////////////////////////////// + +// {AA526D81-7523-4fc6-9B6A-22D74CC55AB7} +#define IN_SEARCHITEMIMAGE_CID \ +{ 0xaa526d81, 0x7523, 0x4fc6, { 0x9b, 0x6a, 0x22, 0xd7, 0x4c, 0xc5, 0x5a, 0xb7 } } + +#define IN_SEARCHITEMIMAGE_CONTRACTID \ +"@mozilla.org/inspector/searchitem;1?type=image" + +#endif diff --git a/extensions/inspector/base/src/inSearchLoop.cpp b/extensions/inspector/base/src/inSearchLoop.cpp new file mode 100644 index 000000000000..091859f57faf --- /dev/null +++ b/extensions/inspector/base/src/inSearchLoop.cpp @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "inSearchLoop.h" + +#include "nsITimer.h" + +/////////////////////////////////////////////////////////////////////////////// + +inSearchLoop::inSearchLoop(inISearchProcess* aSearchProcess) +{ + mSearchProcess = aSearchProcess; + nsresult rv; + mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); +} + +inSearchLoop::~inSearchLoop() +{ +} + +/////////////////////////////////////////////////////////////////////////////// +// inSearchLoop + +nsresult +inSearchLoop::Start() +{ + mTimer->Init(inSearchLoop::TimerCallback, (void*)this, 0, NS_PRIORITY_NORMAL, NS_TYPE_REPEATING_SLACK); + + return NS_OK; +} + +nsresult +inSearchLoop::Step() +{ + PRBool done = PR_FALSE; + mSearchProcess->SearchStep(&done); + + if (done) + Stop(); + + return NS_OK; +} + +nsresult +inSearchLoop::Stop() +{ + mTimer->Cancel(); + + return NS_OK; +} + +void +inSearchLoop::TimerCallback(nsITimer *aTimer, void *aClosure) +{ + inSearchLoop* loop = (inSearchLoop*) aClosure; + loop->Step(); +} \ No newline at end of file diff --git a/extensions/inspector/base/src/inSearchLoop.h b/extensions/inspector/base/src/inSearchLoop.h new file mode 100644 index 000000000000..57bf5f2de98b --- /dev/null +++ b/extensions/inspector/base/src/inSearchLoop.h @@ -0,0 +1,46 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef __inSearchLoop_h__ +#define __inSearchLoop_h__ + +#include "nsITimer.h" +#include "inISearchProcess.h" + +class inSearchLoop +{ +public: + inSearchLoop(inISearchProcess* aSearchProcess); + ~inSearchLoop(); + +protected: + nsCOMPtr mTimer; + nsCOMPtr mSearchProcess; + +public: + nsresult Start(); + nsresult Step(); + nsresult Stop(); + static void TimerCallback(nsITimer *aTimer, void *aClosure); +}; + +#endif diff --git a/extensions/inspector/base/src/inSearchOrphanImages.cpp b/extensions/inspector/base/src/inSearchOrphanImages.cpp new file mode 100644 index 000000000000..9cf2b19e82b1 --- /dev/null +++ b/extensions/inspector/base/src/inSearchOrphanImages.cpp @@ -0,0 +1,569 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "inSearchOrphanImages.h" + +#include "dsinfo.h" +#include "nsCOMPtr.h" +#include "nsISupportsArray.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsString.h" +#include "nsILocalFile.h" +#include "nsIURI.h" +#include "nsIDocument.h" +#include "nsIDOMDocument.h" +#include "nsICSSStyleSheet.h" +#include "nsICSSStyleRule.h" +#include "nsICSSDeclaration.h" +#include "nsCSSValue.h" +#include "nsITimer.h" +#include "nsIRDFService.h" +#include "nsIRDFResource.h" + +/////////////////////////////////////////////////////////////////////////////// + +#define INS_RDF_SEARCH_ROOT "inspector:searchResults" +#define INS_RDF_RESULTS INS_NAMESPACE_URI "results" +#define INS_RDF_URL INS_NAMESPACE_URI "url" + +nsIRDFResource* kINS_SearchRoot; +nsIRDFResource* kINS_results; +nsIRDFResource* kINS_url; + +/////////////////////////////////////////////////////////////////////////////// + +inSearchOrphanImages::inSearchOrphanImages() +{ + NS_INIT_ISUPPORTS(); + + nsresult rv; + + rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDF); + NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to get RDF service"); + rv = nsServiceManager::GetService(kRDFContainerUtilsCID, NS_GET_IID(nsIRDFContainerUtils), (nsISupports**) &mRDFCU); + NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to get RDF container utils"); + + mRDF->GetResource(INS_RDF_SEARCH_ROOT, &kINS_SearchRoot); + mRDF->GetResource(INS_RDF_RESULTS, &kINS_results); + mRDF->GetResource(INS_RDF_URL, &kINS_url); +} + +inSearchOrphanImages::~inSearchOrphanImages() +{ +} + +NS_IMPL_ISUPPORTS2(inSearchOrphanImages, inISearchOrphanImages, inISearchProcess); + + +/////////////////////////////////////////////////////////////////////////////// +// inISearchOrphanImages + +NS_IMETHODIMP +inSearchOrphanImages::GetSearchPath(PRUnichar** aSearchPath) +{ + *aSearchPath = mSearchPath.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::SetSearchPath(const PRUnichar* aSearchPath) +{ + mSearchPath.Assign(aSearchPath); + mSearchPath.Trim("\\/", PR_FALSE, PR_TRUE, PR_FALSE); + mSearchPath.AppendWithConversion("\\"); + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::GetRemotePath(PRUnichar** aRemotePath) +{ + *aRemotePath = mRemotePath.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::SetRemotePath(const PRUnichar* aRemotePath) +{ + mRemotePath.Assign(aRemotePath); + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::GetIsSkin(PRBool* aIsSkin) +{ + *aIsSkin = mIsSkin; + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::SetIsSkin(PRBool aIsSkin) +{ + mIsSkin = aIsSkin; + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::GetDocument(nsIDOMDocument** aDocument) +{ + *aDocument = mDocument; + NS_IF_ADDREF(*aDocument); + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::SetDocument(nsIDOMDocument* aDocument) +{ + mDocument = aDocument; + + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////////////// +// inISearchProcess + +nsresult +inSearchOrphanImages::GetUid(PRUnichar** aUid) +{ + nsAutoString uid; + uid.AssignWithConversion("findOrphanImages"); + *aUid = uid.ToNewUnicode(); + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::GetDataSource(nsIRDFDataSource** aDataSource) +{ + *aDataSource = mDataSource; + NS_IF_ADDREF(*aDataSource); + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::GetProgressPercent(PRInt16* aProgressPercent) +{ + PRUint32 count; + mDirectories->Count(&count); + *aProgressPercent = (100 * (mCurrentStep+1)) / count; + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::GetResultCount(PRUint32* aResultCount) +{ + *aResultCount = mResultCount; + return NS_OK; +} + +NS_IMETHODIMP +inSearchOrphanImages::GetProgressText(PRUnichar** aProgressText) +{ + // XX return current directory being searched + nsAutoString text; + text.AssignWithConversion("searching"); + *aProgressText = text.ToNewUnicode(); + return NS_OK; +} + +nsresult +inSearchOrphanImages::Start(inISearchObserver* aObserver) +{ + nsresult rv; + + mObserver = aObserver; + mCurrentStep = 0; + mResultCount = 0; + + rv = InitDataSource(); + if (NS_FAILED(rv)) { + ReportError("Unable to create results datasource."); + return NS_OK; + } + + mObserver->OnSearchStart(this); + + rv = CacheAllDirectories(); + if (!NS_FAILED(rv)) + StartSearchTimer(); + + PRUint32 count; + mDirectories->Count(&count); + + return rv; +} + +NS_IMETHODIMP +inSearchOrphanImages::Stop() +{ + return NS_OK; +} + + +/////////////////////////////////////////////////////////////////////////////// +// inSearchOrphanImages + +nsresult +inSearchOrphanImages::SearchStep(PRBool* aDone) +{ + PRUint32 count; + mDirectories->Count(&count); + + if (mCurrentStep == 0) { + BuildRemoteURLHash(); + } else if (mCurrentStep == count) { + *aDone = PR_TRUE; + mObserver->OnSearchEnd(this); + } else { + nsCOMPtr file; + mDirectories->GetElementAt(mCurrentStep-1, getter_AddRefs(file)); + SearchDirectory(file); + } + + mCurrentStep++; + + return NS_OK; +} + + +nsresult +inSearchOrphanImages::CacheAllDirectories() +{ + if (mSearchPath.Length() < 1) return NS_ERROR_FAILURE; + + mDirectories = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID); + + nsCOMPtr file; + NS_NewLocalFile(mSearchPath.ToNewCString(), false, getter_AddRefs(file)); + + CacheDirectory(file); + + return NS_OK; +} + +nsresult +inSearchOrphanImages::CacheDirectory(nsIFile* aDir) +{ + // store this direcotyr + mDirectories->AppendElement(aDir); + + // recurse through subdirectories + nsISimpleEnumerator* entries; + aDir->GetDirectoryEntries(&entries); + + PRBool* hasMoreElements = new PRBool(); + PRBool* isDirectory = new PRBool(); + nsCOMPtr entry; + + entries->HasMoreElements(hasMoreElements); + while (*hasMoreElements) { + entries->GetNext(getter_AddRefs(entry)); + entries->HasMoreElements(hasMoreElements); + + entry->IsDirectory(isDirectory); + if (*isDirectory) { + CacheDirectory(entry); + } + } + + return NS_OK; +} + +nsresult +inSearchOrphanImages::SearchDirectory(nsIFile* aDir) +{ + nsISimpleEnumerator* entries; + aDir->GetDirectoryEntries(&entries); + + PRBool* hasMoreElements = new PRBool(); + PRBool* isFile = new PRBool(); + nsCOMPtr entry; + + entries->HasMoreElements(hasMoreElements); + while (*hasMoreElements) { + entries->GetNext(getter_AddRefs(entry)); + entries->HasMoreElements(hasMoreElements); + + entry->IsFile(isFile); + if (*isFile) { + nsAutoString ext = GetFileExtension(entry); + if (ext.EqualsIgnoreCase("gif", -1) || + ext.EqualsIgnoreCase("png", -1) || + ext.EqualsIgnoreCase("jpg", -1)) { + + char* path; + entry->GetPath(&path); + + nsAutoString localPath; + localPath.AssignWithConversion(path); + nsAutoString equalized = EqualizeLocalURL(&localPath); + + nsStringKey key(equalized); + PRUint32 result = (PRUint32) mFileHash->Get(&key); + if (!result) { + //printf("ORPHAN: '%s'\n", url); + + nsCOMPtr res; + CreateResourceFromFile(entry, getter_AddRefs(res)); + + mResultCount++; + + mObserver->OnSearchResult(this); + } + } + } + + + } + + return NS_OK; +} + +nsAutoString +inSearchOrphanImages::GetFileExtension(nsIFile* aFile) +{ + nsAutoString result; + + char* fileName; + aFile->GetLeafName(&fileName); + nsAutoString name; + name.AssignWithConversion(fileName); + + name.Right(result, 3); + result.ToLowerCase(); + + return result; +} + +nsresult +inSearchOrphanImages::BuildRemoteURLHash() +{ + // XXX dunno if I have to addref here and release the old one.. Scripting habits be damned! + mFileHash = new nsHashtable(3000, true); + + nsCOMPtr doc = do_QueryInterface(mDocument); + if (doc) { + PRInt32 count = doc->GetNumberOfStyleSheets(); + for (PRInt32 i = 0; i < count; i++) { + nsIStyleSheet* sheet = doc->GetStyleSheetAt(i); + HashStyleSheet(sheet); + } + } + + return NS_OK; +} + +nsresult +inSearchOrphanImages::HashStyleSheet(nsIStyleSheet* aStyleSheet) +{ + NS_IF_ADDREF(aStyleSheet); + + nsCOMPtr cssSheet = do_QueryInterface(aStyleSheet); + if (cssSheet) { + // recurse downward through the stylesheet tree + PRInt32 count; + cssSheet->StyleSheetCount(count); + for (PRInt32 i = 0; i < count; i++) { + nsICSSStyleSheet* child; + cssSheet->GetStyleSheetAt(i, child); + HashStyleSheet(child); + } + + cssSheet->StyleRuleCount(count); + for (i = 0; i < count; i++) { + nsICSSRule* rule; + cssSheet->GetStyleRuleAt(i, rule); + HashStyleRule(rule); + } + } + + NS_IF_RELEASE(aStyleSheet); + return NS_OK; +} + +nsresult +inSearchOrphanImages::HashStyleRule(nsIStyleRule* aStyleRule) +{ + NS_IF_ADDREF(aStyleRule); + + nsCOMPtr cssRule = do_QueryInterface(aStyleRule); + if (cssRule) { + nsCOMPtr aDec = cssRule->GetDeclaration(); + HashStyleValue(aDec, eCSSProperty_background_image); + HashStyleValue(aDec, eCSSProperty_list_style_image); + } + + + NS_IF_RELEASE(aStyleRule); + return NS_OK; +} + +nsresult +inSearchOrphanImages::HashStyleValue(nsICSSDeclaration* aDec, nsCSSProperty aProp) +{ + nsCSSValue value; + aDec->GetValue(aProp, value); + + if (value.GetUnit() == eCSSUnit_URL) { + nsAutoString result; + result = value.GetStringValue(result); + EqualizeRemoteURL(&result); + nsStringKey key (result); + mFileHash->Put(&key, (void*)1); + } + + return NS_OK; +} + +nsresult +inSearchOrphanImages::EqualizeRemoteURL(nsAutoString* aURL) +{ + if (mIsSkin) { + if (aURL->Find("chrome://", false, 0, 1) >= 0) { + PRUint32 len = aURL->Length(); + char* result = new char[len-8]; + char* buffer = aURL->ToNewCString(); + PRUint32 i = 9; + PRUint32 milestone = 0; + PRUint32 s = 0; + while (i < len) { + if (buffer[i] == '/') { + milestone += 1; + } + if (milestone == 0 || milestone > 1) { + result[i-9-s] = (buffer[i] == '/') ? '/' : buffer[i]; + } else { + s++; + } + i++; + } + result[i-9-s] = 0; + + aURL->AssignWithConversion(result); + //printf("hash: '%s'\n", result); + } + } else { + } + + return NS_OK; +} + +nsAutoString +inSearchOrphanImages::EqualizeLocalURL(nsAutoString* aURL) +{ + nsAutoString result; + PRInt32 found = aURL->Find(mSearchPath, false, 0, 1); + if (found == 0) { + PRUint32 len = mSearchPath.Length(); + aURL->Mid(result, len, aURL->Length()-len); + result.ReplaceChar('\\', '/'); + //printf("file: '%s'\n", result.ToNewCString()); + } + + return result; +} + +nsresult +inSearchOrphanImages::ReportError(char* aMsg) +{ + nsAutoString msg; + msg.AssignWithConversion(aMsg); + mObserver->OnSearchError(this, msg.ToNewUnicode()); + + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////////////// +// timer stuff + +nsresult +inSearchOrphanImages::StartSearchTimer() +{ + nsresult rv; + mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv); + mTimer->Init(inSearchOrphanImages::SearchTimerCallback, (void*)this, 0, NS_PRIORITY_NORMAL, NS_TYPE_REPEATING_SLACK); + + return NS_OK; +} + +nsresult +inSearchOrphanImages::StopSearchTimer() +{ + mTimer->Cancel(); + mTimer = nsnull; + + return NS_OK; +} + +void +inSearchOrphanImages::SearchTimerCallback(nsITimer *aTimer, void *aClosure) +{ + inSearchOrphanImages* search = (inSearchOrphanImages*) aClosure; + + PRBool done = PR_FALSE; + search->SearchStep(&done); + + if (done) { + search->StopSearchTimer(); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// RDF stuff + +nsresult +inSearchOrphanImages::InitDataSource() +{ + nsresult rv; + mDataSource = do_CreateInstance("@mozilla.org/rdf/datasource;1?name=in-memory-datasource", &rv); + + nsCOMPtr res; + mRDF->GetAnonymousResource(getter_AddRefs(res)); + + mDataSource->Assert(kINS_SearchRoot, kINS_results, res, true); + + mRDFCU->MakeSeq(mDataSource, res, getter_AddRefs(mResultSeq)); + + return rv; +} + +nsresult +inSearchOrphanImages::CreateResourceFromFile(nsIFile* aFile, nsIRDFResource** aRes) +{ + nsCOMPtr res; + mRDF->GetAnonymousResource(getter_AddRefs(res)); + + char* url; + aFile->GetURL(&url); + nsAutoString theURL; + theURL.AssignWithConversion(url); + + nsCOMPtr literal; + mRDF->GetLiteral(theURL.ToNewUnicode(), getter_AddRefs(literal)); + + mDataSource->Assert(res, kINS_url, literal, true); + + mResultSeq->AppendElement(res); + + return NS_OK; +} + + diff --git a/extensions/inspector/base/src/inSearchOrphanImages.h b/extensions/inspector/base/src/inSearchOrphanImages.h new file mode 100644 index 000000000000..b8cde040b934 --- /dev/null +++ b/extensions/inspector/base/src/inSearchOrphanImages.h @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef __searchOrphanImages_h__ +#define __searchOrphanImages_h__ + +#include "inISearchOrphanImages.h" +#include "inISearchProcess.h" + +#include "inISearchObserver.h" +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsSupportsArray.h" +#include "nsHashtable.h" +#include "nsIDOMDocument.h" +#include "nsIStyleSheet.h" +#include "nsIStyleRule.h" +#include "nsICSSDeclaration.h" +#include "nsCSSProps.h" +#include "nsIFile.h" +#include "nsITimer.h" +#include "nsIRDFService.h" +#include "nsIRDFLiteral.h" +#include "nsIRDFContainerUtils.h" +#include "nsIRDFContainer.h" + +class inSearchOrphanImages : public inISearchOrphanImages, + public inISearchProcess + +{ +public: + inSearchOrphanImages(); + ~inSearchOrphanImages(); + + nsresult SearchStep(PRBool* aDone); + nsresult StopSearchTimer(); + +protected: + nsIRDFService* mRDF; + nsIRDFContainerUtils* mRDFCU; + nsCOMPtr mTimer; + + nsHashtable* mFileHash; + nsCOMPtr mDirectories; + + PRUint32 mCurrentStep; + PRUint32 mResultCount; + nsCOMPtr mDataSource; + nsCOMPtr mResultSeq; + nsCOMPtr mObserver; + + nsAutoString mRemotePath; + nsAutoString mSearchPath; + PRBool mIsSkin; + nsCOMPtr mDocument; + + nsresult BuildRemoteURLHash(); + nsresult HashStyleSheet(nsIStyleSheet* aStyleSheet); + nsresult HashStyleRule(nsIStyleRule* aStyleRule); + nsresult HashStyleValue(nsICSSDeclaration* aDec, nsCSSProperty aProp); + nsresult EqualizeRemoteURL(nsAutoString* aURL); + nsAutoString EqualizeLocalURL(nsAutoString* aURL); + nsresult SearchDirectory(nsIFile* aDir); + nsAutoString GetFileExtension(nsIFile* aFile); + nsresult StartSearchTimer(); + nsresult CacheAllDirectories(); + nsresult CacheDirectory(nsIFile* aDir); + nsresult InitDataSource(); + nsresult CreateResourceFromFile(nsIFile* aFile, nsIRDFResource** aRes); + nsresult ReportError(char* aMsg); + + static void SearchTimerCallback(nsITimer *aTimer, void *aClosure); + +public: + NS_DECL_ISUPPORTS + + NS_DECL_INISEARCHORPHANIMAGES + + NS_DECL_INISEARCHPROCESS + +}; + +//////////////////////////////////////////////////////////////////// + +// {865761A8-7A39-426c-8114-396FA2B03768} +#define IN_SEARCHORPHANIMAGES_CID \ +{ 0x865761a8, 0x7a39, 0x426c, { 0x81, 0x14, 0x39, 0x6f, 0xa2, 0xb0, 0x37, 0x68 } } + +#define IN_SEARCHORPHANIMAGES_CONTRACTID \ +"@mozilla.org/inspector/search;1?name=findOrphanImages" + +#endif diff --git a/extensions/inspector/base/src/makefile.win b/extensions/inspector/base/src/makefile.win new file mode 100644 index 000000000000..7da0b830d7cb --- /dev/null +++ b/extensions/inspector/base/src/makefile.win @@ -0,0 +1,72 @@ +#!nmake +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\..\.. + +LIBRARY_NAME=inspector_s +MODULE=inspector + +DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN + +CPPSRCS= \ + .\nsDOMDataSource.cpp \ + .\nsCSSRuleDataSource.cpp \ + .\nsCSSDecDataSource.cpp \ + .\nsDOMDSResource.cpp \ + .\nsCSSDecIntHolder.cpp \ + .\inFlasher.cpp \ + .\inSearchLoop.cpp \ + .\inFileSearch.cpp \ + .\inCSSValueSearch.cpp \ + $(NULL) + + +CPP_OBJS= \ + .\$(OBJDIR)\nsDOMDataSource.obj \ + .\$(OBJDIR)\nsCSSRuleDataSource.obj \ + .\$(OBJDIR)\nsCSSDecDataSource.obj \ + .\$(OBJDIR)\nsDOMDSResource.obj \ + .\$(OBJDIR)\nsCSSDecIntHolder.obj \ + .\$(OBJDIR)\inFlasher.obj \ + .\$(OBJDIR)\inSearchLoop.obj \ + .\$(OBJDIR)\inFileSearch.obj \ + .\$(OBJDIR)\inCSSValueSearch.obj \ + $(NULL) + +EXPORTS = $(NULL) + +LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\js \ + -I$(PUBLIC)\dom -I$(PUBLIC)\uconv + +LCFLAGS = \ + $(LCFLAGS) \ + $(DEFINES) \ + $(NULL) + +include <$(DEPTH)\config\rules.mak> + +install:: $(LIBRARY) + $(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib + +clobber:: + rm -f $(DIST)\lib\$(LIBRARY_NAME).lib + + diff --git a/extensions/inspector/base/src/nsCSSDecDataSource.cpp b/extensions/inspector/base/src/nsCSSDecDataSource.cpp new file mode 100644 index 000000000000..b64a00f2b02d --- /dev/null +++ b/extensions/inspector/base/src/nsCSSDecDataSource.cpp @@ -0,0 +1,438 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-file-style: "stroustrup" -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + */ + +#include "nsCSSDecDataSource.h" +#include "dsinfo.h" + +//////////////////////////////////////////////////////////////////////// +// globals and constants + +#define INS_RDF_DECROOT "inspector:DecRoot" +#define INS_RDF_PROPERTY INS_NAMESPACE_URI "Property" +#define INS_RDF_PROPERTYNAME INS_NAMESPACE_URI "PropertyName" +#define INS_RDF_PROPERTYVALUE INS_NAMESPACE_URI "PropertyValue" +#define INS_RDF_PROPERTYPRIORITY INS_NAMESPACE_URI "PropertyPriority" + +static PRInt32 gCurrentId = 0; + +nsIRDFResource *kINS_DecRoot; +nsIRDFResource *kINS_Property; +nsIRDFResource *kINS_PropertyName; +nsIRDFResource *kINS_PropertyValue; +nsIRDFResource *kINS_PropertyPriority; + +//////////////////////////////////////////////////////////////////////// + +nsCSSDecDataSource::nsCSSDecDataSource() +{ + NS_INIT_REFCNT(); +} + + +nsCSSDecDataSource::~nsCSSDecDataSource() +{ + if (mRDFService) { + nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); + mRDFService = nsnull; + } + + /* NS_IF_RELEASE(kINS_DecRoot); + NS_IF_RELEASE(kINS_Property); + NS_IF_RELEASE(kINS_PropertyName); + NS_IF_RELEASE(kINS_PropertyValue); + NS_IF_RELEASE(kINS_PropertyPriority); +*/ +} + +nsresult +nsCSSDecDataSource::Init() +{ + nsresult rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); + if (NS_FAILED(rv)) return rv; + + mRDFService->GetResource(INS_RDF_DECROOT, &kINS_DecRoot); + mRDFService->GetResource(INS_RDF_PROPERTY, &kINS_Property); + mRDFService->GetResource(INS_RDF_PROPERTYNAME, &kINS_PropertyName); + mRDFService->GetResource(INS_RDF_PROPERTYVALUE, &kINS_PropertyValue); + mRDFService->GetResource(INS_RDF_PROPERTYPRIORITY, &kINS_PropertyPriority); + + return NS_OK; +} + + +//////////////////////////////////////////////////////////////////////// +// nsISupports + +NS_IMPL_ISUPPORTS2(nsCSSDecDataSource, + nsICSSDecDataSource, + nsIRDFDataSource); + +//////////////////////////////////////////////////////////////////////// +// nsICSSRuleDataSource + +NS_IMETHODIMP +nsCSSDecDataSource::GetRefResource(nsIRDFResource** aRefResource) +{ + *aRefResource = nsnull; + return NS_OK; +} + +NS_IMETHODIMP +nsCSSDecDataSource::SetRefResource(nsIRDFResource* aRefResource) +{ + nsresult rv; + nsCOMPtr domRes = do_QueryInterface(aRefResource); + + nsCOMPtr supports; + rv = domRes->GetObject(getter_AddRefs(supports)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr rule = do_QueryInterface(supports, &rv); + if (NS_FAILED(rv)) return rv; + + mStyleRule = rule; + return NS_OK; +} + +NS_IMETHODIMP nsCSSDecDataSource::SetCSSProperty(const PRUnichar* aName, const PRUnichar* aValue, const PRUnichar* aPriority) +{ + nsresult rv; + // get the declaration + nsCOMPtr dec; + rv = mStyleRule->GetStyle(getter_AddRefs(dec)); + + nsAutoString name; name.Assign(aName); + nsAutoString value; value.Assign(aValue); + nsAutoString priority; priority.Assign(aPriority); + return dec->SetProperty(name, value, priority); +} + + +NS_IMETHODIMP nsCSSDecDataSource::RemoveCSSProperty(const PRUnichar* aName) +{ + nsresult rv; + // get the declaration + nsCOMPtr dec; + rv = mStyleRule->GetStyle(getter_AddRefs(dec)); + + nsAutoString ret; + nsAutoString name; name.Assign(aName); + return dec->RemoveProperty(name, ret); +} + +//////////////////////////////////////////////////////////////////////// +// nsIRDFDataSource + +NS_IMETHODIMP +nsCSSDecDataSource::GetURI(char* *aURI) +{ + NS_PRECONDITION(aURI != nsnull, "null ptr"); + if (! aURI) return NS_ERROR_NULL_POINTER; + + *aURI = nsXPIDLCString::Copy("rdf:" NS_CSSDECDATASOURCE_ID); + if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; + + return NS_OK; +} + +NS_IMETHODIMP +nsCSSDecDataSource::GetSource(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsIRDFResource **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::GetSources(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::GetTarget(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsIRDFNode **_retval) +{ + *_retval = nsnull; + + nsresult rv; + + if (aSource == kINS_DecRoot) { + // It's the root, so we ignore it + return NS_OK; + } else { + // It's not the root, so we proceed to find the target node + nsCOMPtr domRes = do_QueryInterface(aSource); + + if (domRes) { + nsCOMPtr supports; + domRes->GetObject(getter_AddRefs(supports)); + + nsCOMPtr rule = do_QueryInterface(supports, &rv); + if (NS_SUCCEEDED(rv)) + return CreatePropertyTarget(rule->mInt, aProperty, _retval); + } + } + + return rv; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::GetTargets(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsISimpleEnumerator **_retval) +{ + nsresult rv; + + nsCOMPtr arcs; + rv = NS_NewISupportsArray(getter_AddRefs(arcs)); + nsArrayEnumerator* cursor = new nsArrayEnumerator(arcs); + if (!cursor) return NS_ERROR_OUT_OF_MEMORY; + + *_retval = cursor; + NS_ADDREF(*_retval); + + if (!mStyleRule) return NS_OK; + + // The only node with targets is the root, since this this data source + // is just a flat list of properties + if (aSource == kINS_DecRoot && aProperty == kINS_Property) { + rv = GetTargetsForStyleRule(mStyleRule, aProperty, arcs); + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::Assert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::Unassert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::Change(nsIRDFResource *, nsIRDFResource *, + nsIRDFNode *, nsIRDFNode*) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::Move(nsIRDFResource *, nsIRDFResource *, + nsIRDFResource *, nsIRDFNode*) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::HasAssertion(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, PRBool *_retval) +{ + *_retval = PR_FALSE; + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::AddObserver(nsIRDFObserver *aObserver) +{ + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::RemoveObserver(nsIRDFObserver *aObserver) +{ + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::ArcLabelsIn(nsIRDFNode *aNode, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::ArcLabelsOut(nsIRDFResource *aSource, nsISimpleEnumerator **_retval) +{ + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::GetAllResources(nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::GetAllCommands(nsIRDFResource *aSource, nsIEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::IsCommandEnabled(nsISupportsArray *aSources, nsIRDFResource *aCommand, nsISupportsArray *aArguments, PRBool *_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::DoCommand(nsISupportsArray *aSources, nsIRDFResource *aCommand, nsISupportsArray *aArguments) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::GetAllCmds(nsIRDFResource *aSource, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *result) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsCSSDecDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *result) +{ + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////// +// nsCSSDecDataSource + +nsIRDFService* +nsCSSDecDataSource::GetRDFService() +{ + if (!mRDFService) { + nsresult rv; + rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); + if (NS_FAILED(rv)) return nsnull; + } + + return mRDFService; +} + +nsresult +nsCSSDecDataSource::GetTargetsForStyleRule(nsIDOMCSSStyleRule* aRule, nsIRDFResource* aProperty, nsISupportsArray* aArcs) +{ + nsresult rv; + + // get the declaration + nsCOMPtr dec; + rv = aRule->GetStyle(getter_AddRefs(dec)); + // loop through the properties + PRUint32 count; + dec->GetLength(&count); + + nsCSSDecIntHolder* holder; + for (PRUint32 i = 0; i < count; i++) { + holder = new nsCSSDecIntHolder(i); + nsCOMPtr resource; + rv = GetResourceForObject(holder, getter_AddRefs(resource)); + rv = aArcs->AppendElement(resource); + } + return NS_OK; +} + +nsresult +nsCSSDecDataSource::GetResourceForObject(nsISupports* aObject, nsIRDFResource** _retval) +{ + nsresult rv; + nsISupportsKey* objKey = new nsISupportsKey(aObject); + nsCOMPtr supports = (nsISupports*) mObjectTable.Get(objKey); + + if (supports) { + nsCOMPtr res = do_QueryInterface(supports, &rv); + *_retval = res; + } else { + // it's not in the hash table, so add it. + char *uri = PR_smprintf(NS_DOMDSRESOURCE_ID "://CSSPROP%8.8X", gCurrentId++); + + // have the resource created by the resource factory + rv = GetRDFService()->GetResource(uri, _retval); + if (NS_FAILED(rv)) return rv; + + // add it to the hash table + mObjectTable.Put(objKey, *_retval); + + // now fill in the resource stuff + nsCOMPtr nodeContainer = do_QueryInterface(*_retval, &rv); + if (NS_FAILED(rv)) return rv; + nodeContainer->SetObject(aObject); + } + + return NS_OK; +} + +nsresult +nsCSSDecDataSource::CreatePropertyTarget(PRUint32 aIndex, nsIRDFResource* aProperty, nsIRDFNode **aResult) +{ + nsCOMPtr dec; + nsresult rv = mStyleRule->GetStyle(getter_AddRefs(dec)); + nsAutoString name; + dec->Item(aIndex, name); + + nsAutoString str; + if (aProperty == kINS_PropertyName) { + str = name; + } else if (aProperty == kINS_PropertyValue) { + dec->GetPropertyValue(name, str); + } else if (aProperty == kINS_PropertyPriority) { + dec->GetPropertyPriority(name, str); + } + return CreateLiteral(str, aResult); +} + +nsresult +nsCSSDecDataSource::CreateLiteral(nsString& str, nsIRDFNode **aResult) +{ + nsresult rv; + nsCOMPtr literal; + + PRUnichar* uniStr = str.ToNewUnicode(); + rv = GetRDFService()->GetLiteral(uniStr, getter_AddRefs(literal)); + nsMemory::Free(uniStr); + + *aResult = literal; + NS_IF_ADDREF(*aResult); + return NS_OK; +} + diff --git a/extensions/inspector/base/src/nsCSSDecDataSource.h b/extensions/inspector/base/src/nsCSSDecDataSource.h new file mode 100644 index 000000000000..b05935afb4cc --- /dev/null +++ b/extensions/inspector/base/src/nsCSSDecDataSource.h @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef cssdecdatasource___h___ +#define cssdecdatasource___h___ + +#define NS_CSSDECDATASOURCE_ID "Inspector_CSSDec" + +#include "nsICSSDecDataSource.h" +#include "nsDOMDSResource.h" +#include "nsCSSDecIntHolder.h" + +#include "nsCOMPtr.h" +#include "nsISupportsArray.h" +#include "nsString.h" + +#include "nsIDOMElement.h" +#include "nsIDOMCSSStyleRule.h" +#include "nsIDOMCSSStyleDeclaration.h" + +#include "nsCOMPtr.h" +#include "nsISupportsArray.h" +#include "nsString.h" +#include "nsIDocument.h" +#include "nsIStyleSheet.h" +#include "nsIURI.h" +#include "nsIPresShell.h" +#include "nsIPresContext.h" +#include "nsIStyleSet.h" +#include "nsIContent.h" +#include "nsIFrame.h" +#include "nsIStyleContext.h" +#include "nsIStyleRule.h" +#include "nsICSSStyleRule.h" +#include "nsICSSDeclaration.h" + +#include "nsIRDFService.h" +#include "nsIRDFDataSource.h" +#include "nsIRDFRemoteDataSource.h" +#include "nsIRDFObserver.h" +#include "nsIRDFNode.h" +#include "nsRDFCID.h" +#include "rdf.h" + +#include "nsIComponentManager.h" +#include "nsIDOMWindowInternal.h" + +#include "nsIScriptGlobalObject.h" +#include "nsIServiceManager.h" +#include "nsSpecialSystemDirectory.h" +#include "nsVoidArray.h" +#include "nsXPIDLString.h" +#include "nsEnumeratorUtils.h" +#include "nsEscape.h" +#include "nsIAtom.h" +#include "prprf.h" + +class nsCSSDecDataSource : public nsICSSDecDataSource, + public nsIRDFDataSource +{ + // nsCSSDecDataSource +public: + nsCSSDecDataSource(); + virtual ~nsCSSDecDataSource(); + nsresult Init(); + +private: + nsIRDFService* mRDFService; + nsIDOMCSSStyleRule* mStyleRule; + nsSupportsHashtable mObjectTable; + + nsIRDFService* GetRDFService(); + nsresult GetTargetsForStyleRule(nsIDOMCSSStyleRule* aRule, nsIRDFResource* aProperty, nsISupportsArray* aArcs); + nsresult GetResourceForObject(nsISupports* aObject, nsIRDFResource** _retval); + nsresult CreatePropertyTarget(PRUint32 aIndex, nsIRDFResource* aProperty, nsIRDFNode **aResult); + nsresult CreateLiteral(nsString& str, nsIRDFNode **aResult); + +public: + // nsISupports + NS_DECL_ISUPPORTS + + // nsICSSDecDataSource + NS_DECL_NSICSSDECDATASOURCE + + // nsIRDFDataSource + NS_DECL_NSIRDFDATASOURCE + +}; + +#endif // cssdecdatasource___h___ diff --git a/extensions/inspector/base/src/nsCSSDecIntHolder.cpp b/extensions/inspector/base/src/nsCSSDecIntHolder.cpp new file mode 100644 index 000000000000..b58548c24ede --- /dev/null +++ b/extensions/inspector/base/src/nsCSSDecIntHolder.cpp @@ -0,0 +1,19 @@ +#include "nsCSSDecIntHolder.h" + +//////////////////////////////////////////////////// +// Quick and dirty definition of holder object + +nsCSSDecIntHolder::nsCSSDecIntHolder() { } + +nsCSSDecIntHolder::nsCSSDecIntHolder(PRUint32 aInt) +{ + mInt = aInt; + NS_INIT_REFCNT(); + +} + +nsCSSDecIntHolder::~nsCSSDecIntHolder() +{ +} + +NS_IMPL_ISUPPORTS1(nsCSSDecIntHolder, nsICSSDecIntHolder); diff --git a/extensions/inspector/base/src/nsCSSDecIntHolder.h b/extensions/inspector/base/src/nsCSSDecIntHolder.h new file mode 100644 index 000000000000..82de5ff50657 --- /dev/null +++ b/extensions/inspector/base/src/nsCSSDecIntHolder.h @@ -0,0 +1,26 @@ + +#ifndef nscssdecintholder___h___ +#define nscssdecintholder___h___ + +#include "nsICSSDecIntHolder.h" + +//////////////////////////////////////////////////// +// Quick and dirty declaration of holder object + +class nsCSSDecIntHolder : public nsICSSDecIntHolder { + +public: + nsCSSDecIntHolder(); + nsCSSDecIntHolder(PRUint32 aInt); + virtual ~nsCSSDecIntHolder(); + + PRUint32 mInt; + + // nsISupports + NS_DECL_ISUPPORTS + + // nsICSSDecIntHolder + NS_DECL_NSICSSDECINTHOLDER +}; + +#endif \ No newline at end of file diff --git a/extensions/inspector/base/src/nsCSSRuleDataSource.cpp b/extensions/inspector/base/src/nsCSSRuleDataSource.cpp new file mode 100644 index 000000000000..cddf35d3a004 --- /dev/null +++ b/extensions/inspector/base/src/nsCSSRuleDataSource.cpp @@ -0,0 +1,435 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-file-style: "stroustrup" -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + */ + +#include "nsCSSRuleDataSource.h" +#include "dsinfo.h" + +//////////////////////////////////////////////////////////////////////// +// globals and constants + +#define INS_RDF_RULEROOT "inspector:RuleRoot" +#define INS_RDF_RULE INS_NAMESPACE_URI "Rule" +#define INS_RDF_SELECTOR INS_NAMESPACE_URI "Selector" +#define INS_RDF_WEIGHT INS_NAMESPACE_URI "Weight" +#define INS_RDF_FILEURL INS_NAMESPACE_URI "FileURL" +#define INS_RDF_LINENUM INS_NAMESPACE_URI "LineNum" + +static PRInt32 gCurrentId = 0; + +nsIRDFResource *kINS_RuleRoot; +nsIRDFResource *kINS_Rule; +nsIRDFResource *kINS_Selector; +nsIRDFResource *kINS_Weight; +nsIRDFResource *kINS_FileURL; +nsIRDFResource *kINS_LineNum; + +//////////////////////////////////////////////////////////////////////// + +nsCSSRuleDataSource::nsCSSRuleDataSource() +{ + NS_INIT_REFCNT(); +} + + +nsCSSRuleDataSource::~nsCSSRuleDataSource() +{ + if (mRDFService) { + nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); + mRDFService = nsnull; + } + + /* NS_IF_RELEASE(kINS_RuleRoot); + NS_IF_RELEASE(kINS_Rule); + NS_IF_RELEASE(kINS_Selector); + NS_IF_RELEASE(kINS_Weight); + NS_IF_RELEASE(kINS_FileURL); + NS_IF_RELEASE(kINS_LineNum); +*/ +} + +nsresult +nsCSSRuleDataSource::Init() +{ + nsresult rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); + if (NS_FAILED(rv)) return rv; + + mRDFService->GetResource(INS_RDF_RULEROOT, &kINS_RuleRoot); + mRDFService->GetResource(INS_RDF_RULE, &kINS_Rule); + mRDFService->GetResource(INS_RDF_SELECTOR, &kINS_Selector); + mRDFService->GetResource(INS_RDF_WEIGHT, &kINS_Weight); + mRDFService->GetResource(INS_RDF_FILEURL, &kINS_FileURL); + mRDFService->GetResource(INS_RDF_LINENUM, &kINS_LineNum); + + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////// +// nsISupports + +NS_IMPL_ISUPPORTS2(nsCSSRuleDataSource, + nsICSSRuleDataSource, + nsIRDFDataSource); + +//////////////////////////////////////////////////////////////////////// +// nsICSSRuleDataSource + +NS_IMETHODIMP +nsCSSRuleDataSource::SetElement(nsIDOMElement* aElement) +{ + mElement = aElement; + return NS_OK; +} + +NS_IMETHODIMP +nsCSSRuleDataSource::GetElement(nsIDOMElement** aElement) +{ + *aElement = mElement; + NS_IF_ADDREF(*aElement); + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////// +// nsIRDFDataSource + +NS_IMETHODIMP +nsCSSRuleDataSource::GetURI(char* *aURI) +{ + NS_PRECONDITION(aURI != nsnull, "null ptr"); + if (! aURI) return NS_ERROR_NULL_POINTER; + + *aURI = nsXPIDLCString::Copy("rdf:" NS_CSSRULEDATASOURCE_ID); + if (! *aURI) return NS_ERROR_OUT_OF_MEMORY; + + return NS_OK; +} + +NS_IMETHODIMP +nsCSSRuleDataSource::GetSource(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsIRDFResource **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::GetSources(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::GetTarget(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsIRDFNode **_retval) +{ + *_retval = nsnull; + + nsresult rv; + + if (aSource == kINS_RuleRoot) { + // It's the root, so we ignore it + return NS_OK; + } else { + // It's not the root, so we proceed to find the target node + nsCOMPtr domRes = do_QueryInterface(aSource); + + if (domRes) { + nsCOMPtr supports; + domRes->GetObject(getter_AddRefs(supports)); + + nsCOMPtr rule = do_QueryInterface(supports, &rv); + if (NS_SUCCEEDED(rv)) + return CreateStyleRuleTarget(rule, aProperty, _retval); + } + } + + return rv; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::GetTargets(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsISimpleEnumerator **_retval) +{ + nsresult rv; + + nsCOMPtr arcs; + rv = NS_NewISupportsArray(getter_AddRefs(arcs)); + nsArrayEnumerator* cursor = new nsArrayEnumerator(arcs); + if (!cursor) return NS_ERROR_OUT_OF_MEMORY; + + *_retval = cursor; + NS_ADDREF(*_retval); + + if (!mElement) return NS_OK; + + // The only node with targets is the root, since this this data source + // is just a flat list of rules + if (aSource == kINS_RuleRoot) { + rv = GetTargetsForElement(mElement, aProperty, arcs); + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::Assert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::Unassert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::Change(nsIRDFResource *, nsIRDFResource *, + nsIRDFNode *, nsIRDFNode*) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::Move(nsIRDFResource *, nsIRDFResource *, + nsIRDFResource *, nsIRDFNode*) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::HasAssertion(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, PRBool *_retval) +{ + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::AddObserver(nsIRDFObserver *aObserver) +{ + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::RemoveObserver(nsIRDFObserver *aObserver) +{ + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::ArcLabelsIn(nsIRDFNode *aNode, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::ArcLabelsOut(nsIRDFResource *aSource, nsISimpleEnumerator **_retval) +{ + return NS_OK; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::GetAllResources(nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::GetAllCommands(nsIRDFResource *aSource, nsIEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::IsCommandEnabled(nsISupportsArray *aSources, nsIRDFResource *aCommand, nsISupportsArray *aArguments, PRBool *_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::DoCommand(nsISupportsArray *aSources, nsIRDFResource *aCommand, nsISupportsArray *aArguments) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::GetAllCmds(nsIRDFResource *aSource, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *result) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsCSSRuleDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *result) +{ + return NS_OK; +} + +//////////////////////////////////////////////////////////////////////// +// nsCSSRuleDataSource + +nsIRDFService* +nsCSSRuleDataSource::GetRDFService() +{ + if (!mRDFService) { + nsresult rv; + rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); + if (NS_FAILED(rv)) return nsnull; + } + + return mRDFService; +} + +nsresult +nsCSSRuleDataSource::GetTargetsForElement(nsIDOMElement* aElement, nsIRDFResource* aProperty, nsISupportsArray* aArcs) +{ + // query to a content node + nsCOMPtr content; + content = do_QueryInterface(aElement); + + // get the document + nsCOMPtr doc1; + aElement->GetOwnerDocument(getter_AddRefs(doc1)); + nsCOMPtr doc; + doc = do_QueryInterface(doc1); + + // loop through the PresShells + nsresult rv; + PRInt32 num = doc->GetNumberOfShells(); + nsCOMPtr shell; + nsIFrame* frame; + nsCOMPtr styleContext; + for (PRInt32 i = 0; i < num; i++) { + // get the style context + shell = doc->GetShellAt(i); + rv = shell->GetPrimaryFrameFor(content, &frame); + if (NS_FAILED(rv) || !frame) return rv; + shell->GetStyleContextFor(frame, getter_AddRefs(styleContext)); + if (NS_FAILED(rv) || !styleContext) return rv; + + // display all the pretty information + PRInt32 count = styleContext->GetStyleRuleCount(); + nsCOMPtr rules(dont_AddRef(styleContext->GetStyleRules())); + nsCOMPtr rule; + + for (PRInt32 k = 0; k < count; k++) { + rule = do_QueryInterface(rules->ElementAt(k)); + nsCOMPtr resource; + rv = GetResourceForObject(rule, getter_AddRefs(resource)); + rv = aArcs->AppendElement(resource); + } + } + + return NS_OK; +} + +nsresult +nsCSSRuleDataSource::GetResourceForObject(nsISupports* aObject, nsIRDFResource** _retval) +{ + nsresult rv; + nsISupportsKey* objKey = new nsISupportsKey(aObject); + nsCOMPtr supports = (nsISupports*) mObjectTable.Get(objKey); + + if (supports) { + nsCOMPtr res = do_QueryInterface(supports, &rv); + *_retval = res; + } else { + // it's not in the hash table, so add it. + char *uri = PR_smprintf(NS_DOMDSRESOURCE_ID "://CSSRULE%8.8X", gCurrentId++); + + // have the resource created by the resource factory + rv = GetRDFService()->GetResource(uri, _retval); + if (NS_FAILED(rv)) return rv; + + // add it to the hash table + mObjectTable.Put(objKey, *_retval); + + // now fill in the resource stuff + nsCOMPtr nodeContainer = do_QueryInterface(*_retval, &rv); + if (NS_FAILED(rv)) return rv; + nodeContainer->SetObject(aObject); + } + + return NS_OK; +} + +nsresult +nsCSSRuleDataSource::CreateStyleRuleTarget(nsICSSStyleRule* aRule, nsIRDFResource* aProperty, nsIRDFNode **aResult) +{ + nsresult rv; + nsAutoString str; + if (aProperty == kINS_Selector) { + aRule->GetSourceSelectorText(str); + } else if (aProperty == kINS_Weight) { + PRUint32 weight = aRule->GetWeight(); + char* ln = PR_smprintf("%d", weight); + str.AssignWithConversion(ln); + } else if (aProperty == kINS_FileURL) { + nsCOMPtr sheet; + nsCOMPtr uri; + char* spec; + rv = aRule->GetStyleSheet(*getter_AddRefs(sheet)); + if (NS_FAILED(rv) || !sheet) return rv; + rv = sheet->GetURL(*getter_AddRefs(uri)); + if (NS_FAILED(rv) || !uri) return rv; + uri->GetSpec(&spec); + str.AssignWithConversion(spec); + } else if (aProperty == kINS_LineNum) { + PRUint32 linenum = aRule->GetLineNumber(); + char* ln = PR_smprintf("%d", linenum); + str.AssignWithConversion(ln); + } + return CreateLiteral(str, aResult); +} + +nsresult +nsCSSRuleDataSource::CreateLiteral(nsString& str, nsIRDFNode **aResult) +{ + nsresult rv; + nsCOMPtr literal; + + PRUnichar* uniStr = str.ToNewUnicode(); + rv = GetRDFService()->GetLiteral(uniStr, getter_AddRefs(literal)); + nsMemory::Free(uniStr); + + *aResult = literal; + NS_IF_ADDREF(*aResult); + return NS_OK; +} \ No newline at end of file diff --git a/extensions/inspector/base/src/nsCSSRuleDataSource.h b/extensions/inspector/base/src/nsCSSRuleDataSource.h new file mode 100644 index 000000000000..a821a94996ee --- /dev/null +++ b/extensions/inspector/base/src/nsCSSRuleDataSource.h @@ -0,0 +1,108 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef cssruledatasource___h___ +#define cssruledatasource___h___ + +#define NS_CSSRULEDATASOURCE_ID "Inspector_CSSRules" + +#include "nsICSSRuleDataSource.h" +#include "nsDOMDSResource.h" + +#include "nsCOMPtr.h" +#include "nsISupportsArray.h" +#include "nsString.h" + +#include "nsIDOMElement.h" + +#include "nsCOMPtr.h" +#include "nsISupportsArray.h" +#include "nsString.h" +#include "nsIDOMElement.h" +#include "nsIDOMDocument.h" +#include "nsIDocument.h" +#include "nsIStyleSheet.h" +#include "nsIURI.h" +#include "nsIPresShell.h" +#include "nsIPresContext.h" +#include "nsIStyleSet.h" +#include "nsIContent.h" +#include "nsIFrame.h" +#include "nsIStyleContext.h" +#include "nsIStyleRule.h" +#include "nsICSSStyleRule.h" +#include "nsICSSDeclaration.h" + +#include "nsIRDFService.h" +#include "nsIRDFDataSource.h" +#include "nsIRDFRemoteDataSource.h" +#include "nsIRDFObserver.h" +#include "nsIRDFNode.h" +#include "nsRDFCID.h" +#include "rdf.h" + +#include "nsIComponentManager.h" +#include "nsIDOMWindowInternal.h" + +#include "nsIScriptGlobalObject.h" +#include "nsIServiceManager.h" +#include "nsSpecialSystemDirectory.h" +#include "nsVoidArray.h" +#include "nsXPIDLString.h" +#include "nsEnumeratorUtils.h" +#include "nsEscape.h" +#include "nsIAtom.h" +#include "prprf.h" + +class nsCSSRuleDataSource : public nsICSSRuleDataSource, + public nsIRDFDataSource +{ + // nsCSSRuleDataSource +public: + nsCSSRuleDataSource(); + virtual ~nsCSSRuleDataSource(); + nsresult Init(); + +private: + nsIRDFService* GetRDFService(); + nsresult GetTargetsForElement(nsIDOMElement* aElement, nsIRDFResource* aProperty, nsISupportsArray* aArcs); + nsresult GetResourceForObject(nsISupports* aObject, nsIRDFResource** _retval); + nsresult CreateStyleRuleTarget(nsICSSStyleRule* aRule, nsIRDFResource* aProperty, nsIRDFNode **aResult); + nsresult CreateLiteral(nsString& str, nsIRDFNode **aResult); + + nsIRDFService* mRDFService; + nsIRDFService* mService; + nsIDOMElement* mElement; + nsSupportsHashtable mObjectTable; + + // nsISupports + NS_DECL_ISUPPORTS + + // nsICSSRuleDataSource + NS_DECL_NSICSSRULEDATASOURCE + + // nsIRDFDataSource + NS_DECL_NSIRDFDATASOURCE + +}; + +#endif // cssruledatasource___h___ diff --git a/extensions/inspector/base/src/nsDOMDSResource.cpp b/extensions/inspector/base/src/nsDOMDSResource.cpp new file mode 100644 index 000000000000..76d1a6ca68dd --- /dev/null +++ b/extensions/inspector/base/src/nsDOMDSResource.cpp @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + */ + +#include "nsDOMDSResource.h" + +nsDOMDSResource::nsDOMDSResource() +{ +} + +nsDOMDSResource::~nsDOMDSResource() +{ +} + +NS_IMPL_ISUPPORTS_INHERITED(nsDOMDSResource, nsRDFResource, nsIDOMDSResource) + +NS_IMETHODIMP +nsDOMDSResource::SetObject(nsISupports* object) +{ + mObject = do_QueryInterface(object); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDSResource::GetObject(nsISupports** object) +{ + if (!object) return NS_ERROR_NULL_POINTER; + + *object = mObject; + NS_IF_ADDREF(*object); + + return NS_OK; +} + +NS_METHOD +nsDOMDSResource::Create(nsISupports* aOuter, const nsIID& iid, void **result) +{ + nsDOMDSResource* ve = new nsDOMDSResource(); + if (!ve) return NS_ERROR_NULL_POINTER; + NS_ADDREF(ve); + nsresult rv = ve->QueryInterface(iid, result); + NS_RELEASE(ve); + return rv; +} + diff --git a/extensions/inspector/base/src/nsDOMDSResource.h b/extensions/inspector/base/src/nsDOMDSResource.h new file mode 100644 index 000000000000..a091cc26115e --- /dev/null +++ b/extensions/inspector/base/src/nsDOMDSResource.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * 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/ + * + * 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. + * + * The Original Code is Mozilla Communicator client code, released + * March 31, 1998. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998-1999 Netscape Communications Corporation. All + * Rights Reserved. + */ + +#ifndef __nsdomdsresource_h +#define __nsdomdsresource_h + +#define NS_DOMDSRESOURCE_ID "InspectorDOMResource" + +#include "nsIDOMDSResource.h" + +#include "nscore.h" +#include "nsCOMPtr.h" +#include "nsWeakPtr.h" +#include "rdf.h" +#include "nsIRDFService.h" +#include "nsRDFResource.h" + +///////////////////////////////////////////////////////////////////// +// This object is registered with the datasource factory to +// be instantiated for all resources created with a uri that begins +// with InspectorDOMResource:// +// +// This is a multi-purpose object that is used by datasources as +// a temporary transport object for data. When ::GetTargets is called, +// a list of these objects is created by the datasource. Each object +// holds a reference back to the real object it represents. This +// object is then sent back to GetTarget, where we get the real +// object and query it for info. +///////////////////////////////////////////////////////////////////// + +class nsDOMDSResource : public nsRDFResource, + public nsIDOMDSResource +{ + // nsDOMDSResource +public: + nsDOMDSResource(); + virtual ~nsDOMDSResource(); + + static NS_METHOD Create(nsISupports* aOuter, const nsIID& iid, void **result); + +private: + nsCOMPtr mObject; + + // nsISupports + NS_DECL_ISUPPORTS_INHERITED + + // nsIDOMDSResource + NS_DECL_NSIDOMDSRESOURCE + +}; + +#endif // __nsdomdsresource_h + diff --git a/extensions/inspector/base/src/nsDOMDataSource.cpp b/extensions/inspector/base/src/nsDOMDataSource.cpp new file mode 100644 index 000000000000..cf7f1ac78d90 --- /dev/null +++ b/extensions/inspector/base/src/nsDOMDataSource.cpp @@ -0,0 +1,1142 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-file-style: "stroustrup" -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributors: + * Joe Hewitt (Original Author) + * + * Note: This code is originally based on Alec Flett's DOM Viewer + * at /mozilla/rdf/tests/domds. I trimmed and pruned a bit to remove + * stuff I didn't need, fixed stuff that was broken, and added new stuff. + * + */ + +#include "nsDOMDataSource.h" +#include "dsinfo.h" + +//////////////////////////////////////////////////////////////////////// +// globals and constants + +#define RDFEVENT_CHANGE 0 +#define RDFEVENT_ASSERT 1 +#define RDFEVENT_UNASSERT 2 + +#define INS_RDF_DOMROOT "inspector:DOMRoot" +#define INS_RDF_CHILD INS_NAMESPACE_URI "Child" +#define INS_RDF_ATTRIBUTE INS_NAMESPACE_URI "Attribute" +#define INS_RDF_NODENAME INS_NAMESPACE_URI "nodeName" +#define INS_RDF_NODEVALUE INS_NAMESPACE_URI "nodeValue" +#define INS_RDF_NODETYPE INS_NAMESPACE_URI "nodeType" +#define INS_RDF_PREFIX INS_NAMESPACE_URI "prefix" +#define INS_RDF_LOCALNAME INS_NAMESPACE_URI "localName" +#define INS_RDF_NAMESPACEURI INS_NAMESPACE_URI "namespaceURI" +#define INS_RDF_ANONYMOUS INS_NAMESPACE_URI "Anonymous" +#define INS_RDF_HASCHILDREN INS_NAMESPACE_URI "HasChildren" + +static PRInt32 gCurrentId = 0; + +nsIRDFResource* kINS_DOMRoot; +nsIRDFResource* kINS_Child; +nsIRDFResource* kINS_Attribute; +nsIRDFResource* kINS_NodeName; +nsIRDFResource* kINS_NodeValue; +nsIRDFResource* kINS_NodeType; +nsIRDFResource* kINS_Prefix; +nsIRDFResource* kINS_LocalName; +nsIRDFResource* kINS_NamespaceURI; +nsIRDFResource* kINS_Anonymous; +nsIRDFResource* kINS_HasChildren; + +//////////////////////////////////////////////////////////////////////// + +nsDOMDataSource::nsDOMDataSource() : + mObservers(nsnull), + mDocument(nsnull) +{ + NS_INIT_REFCNT(); + + mShowAnonymousContent = new PRBool; + *mShowAnonymousContent = PR_TRUE; + + // show all node types by default + mFilters = new PRUint16; + *mFilters = 65535; + +} + +nsresult +nsDOMDataSource::Init() +{ + //printf("creating nsDOMDataSource (%d) *************************\n", this); + nsresult rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF service"); + if (NS_FAILED(rv)) return rv; + + mRDFService->GetResource(INS_RDF_DOMROOT, &kINS_DOMRoot); + mRDFService->GetResource(INS_RDF_ATTRIBUTE, &kINS_Attribute); + mRDFService->GetResource(INS_RDF_CHILD, &kINS_Child); + mRDFService->GetResource(INS_RDF_NODENAME, &kINS_NodeName); + mRDFService->GetResource(INS_RDF_NODEVALUE, &kINS_NodeValue); + mRDFService->GetResource(INS_RDF_NODETYPE, &kINS_NodeType); + mRDFService->GetResource(INS_RDF_PREFIX, &kINS_Prefix); + mRDFService->GetResource(INS_RDF_LOCALNAME, &kINS_LocalName); + mRDFService->GetResource(INS_RDF_NAMESPACEURI, &kINS_NamespaceURI); + mRDFService->GetResource(INS_RDF_ANONYMOUS, &kINS_Anonymous); + mRDFService->GetResource(INS_RDF_HASCHILDREN, &kINS_HasChildren); + + return NS_OK; +} + +nsDOMDataSource::~nsDOMDataSource() +{ + //printf("destroying nsDOMDataSource (%d) *************************\n", this); + if (mRDFService) { + nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); + mRDFService = nsnull; + } + + if (mDocument) { + nsCOMPtr doc = do_QueryInterface(mDocument); + doc->RemoveObserver(this); + } + + // commenting this out temporarily because it was causing crashes. + // TODO: figure out the right way to release these +/* + NS_IF_RELEASE(kINS_DOMRoot); + NS_IF_RELEASE(kINS_Attribute); + NS_IF_RELEASE(kINS_Child); + NS_IF_RELEASE(kINS_NodeName); + NS_IF_RELEASE(kINS_NodeValue); + NS_IF_RELEASE(kINS_NodeType); + NS_IF_RELEASE(kINS_LocalName); + NS_IF_RELEASE(kINS_NamespaceURI); + NS_IF_RELEASE(kINS_Anonymous); + NS_IF_RELEASE(kINS_HasChildren); +*/ +} + +//////////////////////////////////////////////////////////////////////// +// nsISupports + +NS_IMPL_ISUPPORTS3(nsDOMDataSource, + nsIInsDOMDataSource, + nsIRDFDataSource, + nsIDocumentObserver); + +//////////////////////////////////////////////////////////////////////// +// nsIInsDOMDataSource + +NS_IMETHODIMP +nsDOMDataSource::GetDocument(nsIDOMDocument **aDocument) +{ + *aDocument = mDocument; + NS_IF_ADDREF(*aDocument); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::SetDocument(nsIDOMDocument* aDocument) +{ + nsresult rv; + + nsCOMPtr doc; + // remove old document observer + if (mDocument) { + doc = do_QueryInterface(mDocument, &rv); + if (NS_FAILED(rv)) return rv; + doc->RemoveObserver(this); + } + + mDocument = aDocument; + + if (aDocument) { + doc = do_QueryInterface(mDocument, &rv); + // cache the binding manager + rv = doc->GetBindingManager(&mBindingManager); + if (NS_FAILED(rv)) return rv; + // add new document observer + doc = do_QueryInterface(mDocument, &rv); + if (NS_FAILED(rv)) return rv; + doc->AddObserver(this); + } else { + mBindingManager = nsnull; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::GetShowAnonymousContent(PRBool *aShowAnonymousContent) +{ + *aShowAnonymousContent = *mShowAnonymousContent; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::SetShowAnonymousContent(PRBool aShowAnonymousContent) +{ + *mShowAnonymousContent = aShowAnonymousContent ? PR_TRUE : PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::AddFilterByType(PRUint16 aType, PRBool aExclusive) +{ + PRUint16 key = GetNodeTypeKey(aType); + + if (aExclusive) { + *mFilters = key; + } else { + *mFilters |= key; + } + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::RemoveFilterByType(PRUint16 aType) +{ + PRUint16 key = GetNodeTypeKey(aType); + *mFilters -= key; + return NS_OK; +} + + +NS_IMETHODIMP +nsDOMDataSource::IsFiltered(PRUint16 aType, PRBool* _retval) +{ + PRUint16 key = GetNodeTypeKey(aType); + *_retval = *mFilters & key; + + return NS_OK; +} + +nsresult +nsDOMDataSource::GetResourceForObject(nsISupports* aObject, nsIRDFResource** _retval) +{ + nsresult rv; + nsISupportsKey* objKey; + nsCOMPtr node = do_QueryInterface(aObject, &rv); + if (NS_FAILED(rv)) + objKey = new nsISupportsKey(aObject); + else + objKey = new nsISupportsKey(node); + nsCOMPtr supports = (nsISupports*) gDOMObjectTable.Get(objKey); + + if (supports) { + nsCOMPtr res = do_QueryInterface(supports, &rv); + *_retval = res; + } else { + // it's not in the hash table, so add it. + char *uri = PR_smprintf(NS_DOMDSRESOURCE_ID "://%8.8X", gCurrentId++); + + rv = GetRDFService()->GetResource(uri, _retval); + if (NS_FAILED(rv)) return rv; + + // add it to the hash table + gDOMObjectTable.Put(objKey, *_retval); + + // now fill in the resource stuff + nsCOMPtr nodeContainer = do_QueryInterface(*_retval, &rv); + if (NS_FAILED(rv)) return rv; + nodeContainer->SetObject(aObject); + } + + return NS_OK; +} + +PRBool +nsDOMDataSource::IsObjectInCache(nsISupports* aObject) +{ + nsISupportsKey* objKey = new nsISupportsKey(aObject); + nsCOMPtr supports = (nsISupports*) gDOMObjectTable.Get(objKey); + + if (supports) { + return PR_TRUE; + } else { + return PR_FALSE; + } + +} + +//////////////////////////////////////////////////////////////////////// +// nsIRDFDataSource + +NS_IMETHODIMP +nsDOMDataSource::GetURI(char** aURI) +{ + NS_PRECONDITION(aURI != nsnull, "null ptr"); + if (!aURI) return NS_ERROR_NULL_POINTER; + + *aURI = nsXPIDLCString::Copy("rdf:ins_domds"); + if (!*aURI) return NS_ERROR_OUT_OF_MEMORY; + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::GetSource(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsIRDFResource **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::GetSources(nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::GetTarget(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsIRDFNode **_retval) +{ + *_retval = nsnull; + + nsresult rv; + + if (aSource == kINS_DOMRoot) { + // It's the root, so it gets to be treated special + return CreateRootTarget(aSource, aProperty, _retval); + } else { + // It's not the root, so it's just a regular node + nsCOMPtr nodeContainer = do_QueryInterface(aSource); + + if (nodeContainer) { + nsCOMPtr supports; + nodeContainer->GetObject(getter_AddRefs(supports)); + + nsCOMPtr node = do_QueryInterface(supports, &rv); + if (NS_SUCCEEDED(rv)) + return CreateDOMNodeTarget(node, aProperty, _retval); + } + } + + return rv; +} + + +NS_IMETHODIMP +nsDOMDataSource::GetTargets(nsIRDFResource *aSource, nsIRDFResource *aProperty, PRBool aTruthValue, nsISimpleEnumerator **_retval) +{ + nsresult rv; + + nsCOMPtr arcs; + rv = NS_NewISupportsArray(getter_AddRefs(arcs)); + nsArrayEnumerator* cursor = new nsArrayEnumerator(arcs); + if (!cursor) return NS_ERROR_OUT_OF_MEMORY; + + *_retval = cursor; + NS_ADDREF(*_retval); + + if (!mDocument) return NS_OK; + + if (aSource == kINS_DOMRoot) { + // start at the root... + rv = GetTargetsForKnownObject(mDocument, aProperty, *mShowAnonymousContent, arcs); + } else if (aProperty == kINS_Child) { + // start with a node... + nsCOMPtr dsRes; + dsRes = do_QueryInterface(aSource, &rv); + + if (NS_SUCCEEDED(rv) && dsRes) { + nsCOMPtr supports; + dsRes->GetObject(getter_AddRefs(supports)); + rv = GetTargetsForKnownObject(supports, aProperty, *mShowAnonymousContent, arcs); + } + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsDOMDataSource::Assert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::Unassert(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::Change(nsIRDFResource *, nsIRDFResource *, + nsIRDFNode *, nsIRDFNode*) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsDOMDataSource::Move(nsIRDFResource *, nsIRDFResource *, + nsIRDFResource *, nsIRDFNode*) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsDOMDataSource::HasAssertion(nsIRDFResource *aSource, nsIRDFResource *aProperty, nsIRDFNode *aTarget, PRBool aTruthValue, PRBool *_retval) +{ + nsresult rv; + *_retval = PR_FALSE; + + nsCOMPtr sourceRes = do_QueryInterface(aSource, &rv); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr targetRes = do_QueryInterface(aTarget, &rv); + if (NS_FAILED(rv)) return rv; + + if (aProperty == kINS_DOMRoot) { + *_retval = PR_TRUE; + } else if (aProperty == kINS_Child) { + nsCOMPtr supports; + sourceRes->GetObject(getter_AddRefs(supports)); + nsCOMPtr source = do_QueryInterface(supports); + rv = targetRes->GetObject(getter_AddRefs(supports)); + if (!supports || NS_FAILED(rv)) return NS_OK; + nsCOMPtr target = do_QueryInterface(supports); + nsCOMPtr attr = do_QueryInterface(supports); + if (attr) { + *_retval = HasAttribute(source, target) == aTruthValue; + //printf("HasAssertion(%d) -> %d\n", aTruthValue, *_retval); + } else + *_retval = HasChild(source, target) == aTruthValue; + } else { + *_retval = aTruthValue && + (aProperty == kINS_NodeName || + aProperty == kINS_NodeValue || + aProperty == kINS_NodeType || + aProperty == kINS_Prefix || + aProperty == kINS_LocalName || + aProperty == kINS_NamespaceURI || + aProperty == kINS_Anonymous || + aProperty == kINS_HasChildren); + } + + return NS_OK; +} + + +NS_IMETHODIMP +nsDOMDataSource::AddObserver(nsIRDFObserver *aObserver) +{ + if (! mObservers) { + if ((mObservers = new nsVoidArray()) == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + } + mObservers->AppendElement(aObserver); + return NS_OK; +} + + +NS_IMETHODIMP +nsDOMDataSource::RemoveObserver(nsIRDFObserver *aObserver) +{ + if (! mObservers) + return NS_OK; + mObservers->RemoveElement(aObserver); + return NS_OK; +} + + +NS_IMETHODIMP +nsDOMDataSource::ArcLabelsIn(nsIRDFNode *aNode, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::ArcLabelsOut(nsIRDFResource *aSource, nsISimpleEnumerator **_retval) +{ + nsresult rv = NS_OK; + + nsCOMPtr arcs; + rv = NS_NewISupportsArray(getter_AddRefs(arcs)); + if (NS_FAILED(rv)) return rv; + + arcs->AppendElement(kINS_NodeName); + arcs->AppendElement(kINS_NodeValue); + arcs->AppendElement(kINS_NodeType); + arcs->AppendElement(kINS_HasChildren); + arcs->AppendElement(kINS_Child); + + nsArrayEnumerator* cursor = new nsArrayEnumerator(arcs); + + if (!cursor) return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(cursor); + *_retval = cursor; + + return NS_OK; +} + + +NS_IMETHODIMP +nsDOMDataSource::GetAllResources(nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::GetAllCommands(nsIRDFResource *aSource, nsIEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::IsCommandEnabled(nsISupportsArray *aSources, nsIRDFResource *aCommand, nsISupportsArray *aArguments, PRBool *_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::DoCommand(nsISupportsArray *aSources, nsIRDFResource *aCommand, nsISupportsArray *aArguments) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::GetAllCmds(nsIRDFResource *aSource, nsISimpleEnumerator **_retval) +{ + return NS_RDF_NO_VALUE; +} + + +NS_IMETHODIMP +nsDOMDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *result) +{ + return NS_ERROR_NOT_IMPLEMENTED; +} + + +NS_IMETHODIMP +nsDOMDataSource::HasArcOut(nsIRDFResource *aSource, nsIRDFResource *aArc, PRBool *result) +{ + if (aArc == kINS_HasChildren) { + nsCOMPtr nodeContainer = do_QueryInterface(aSource); + nsCOMPtr supports; + nodeContainer->GetObject(getter_AddRefs(supports)); + nsCOMPtr node = do_QueryInterface(supports); + *result = HasChildren(node); + } else { + *result = aArc == kINS_DOMRoot || + aArc == kINS_NodeName || + aArc == kINS_NodeValue || + aArc == kINS_NodeType || + aArc == kINS_LocalName || + aArc == kINS_Prefix || + aArc == kINS_NamespaceURI || + aArc == kINS_Anonymous || + aArc == kINS_Attribute || + aArc == kINS_Child; + } + + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////// +// nsIDocumentObserver + +NS_IMETHODIMP +nsDOMDataSource::AttributeChanged(nsIDocument *aDocument, nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttribute, PRInt32 aHint) +{ + nsresult rv; + + PRBool filtered; + rv = IsFiltered(2, &filtered); + if (filtered) { + // get the attribute node from the content node + nsAutoString attrName; + aAttribute->ToString(attrName); + nsCOMPtr el = do_QueryInterface(aContent); + nsCOMPtr attr; + el->GetAttributeNode(attrName, getter_AddRefs(attr)); + + // the attribute is being changed or added + if (attr) { + PRBool exists = IsObjectInCache(attr); + + // get the resource for the attribute node + nsCOMPtr attrRes; + GetResourceForObject(attr, getter_AddRefs(attrRes)); + + if (exists) { + // the attribute's value is being changed + //printf("CHANGING ATTRIBUTE\n"); + // create the literal node for the new property value + nsCOMPtr propValue; + rv = CreateDOMNodeTarget(attr, kINS_NodeValue, getter_AddRefs(propValue)); + + NotifyObservers(attrRes, kINS_NodeValue, propValue, RDFEVENT_CHANGE); + } else { + // the attribute is new and was just added + //printf("ADDING NEW ATTRIBUTE\n"); + + nsCOMPtr contentRes; + GetResourceForObject(aContent, getter_AddRefs(contentRes)); + + NotifyObservers(contentRes, kINS_Child, attrRes, RDFEVENT_ASSERT); + } + } else { + // the attribute is being removed + //printf("REMOVING ATTRIBUTE\n"); + + nsCOMPtr contentRes; + GetResourceForObject(aContent, getter_AddRefs(contentRes)); + + nsCOMPtr attrRes; + FindAttrRes(aContent, aNameSpaceID, aAttribute, getter_AddRefs(attrRes)); + if (attrRes) { + nsCOMPtr dsres = do_QueryInterface(attrRes); + nsCOMPtr attr; + dsres->GetObject(getter_AddRefs(attr)); + RemoveResourceForObject(attr); + NotifyObservers(contentRes, kINS_Child, attrRes, RDFEVENT_UNASSERT); + } + } + } + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::ContentAppended(nsIDocument *aDocument, nsIContent* aContainer, PRInt32 aNewIndexInContainer) +{ + nsresult rv; + + nsCOMPtr containerRes; + rv = GetResourceForObject(aContainer, getter_AddRefs(containerRes)); + + nsIContent* child; + aContainer->ChildAt(aNewIndexInContainer, child); + + nsCOMPtr childRes; + rv = GetResourceForObject(child, getter_AddRefs(childRes)); + + NotifyObservers(containerRes, kINS_Child, childRes, RDFEVENT_ASSERT); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::ContentInserted(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aChild, PRInt32 aIndexInContainer) +{ + nsresult rv; + + nsCOMPtr containerRes; + rv = GetResourceForObject(aContainer, getter_AddRefs(containerRes)); + + nsCOMPtr childRes; + rv = GetResourceForObject(aChild, getter_AddRefs(childRes)); + + NotifyObservers(containerRes, kINS_Child, childRes, RDFEVENT_ASSERT); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::ContentReplaced(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aOldChild, nsIContent* aNewChild, PRInt32 aIndexInContainer) +{ + //printf("=== CONTENT REPLACED ===\n"); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::ContentRemoved(nsIDocument *aDocument, nsIContent* aContainer, nsIContent* aChild, PRInt32 aIndexInContainer) +{ + nsAutoString nodeName; + nsCOMPtr node = do_QueryInterface(aContainer); + node->GetNodeName(nodeName); + //printf("=== CONTENT REMOVED (%s) ===\n", nodeName.ToNewCString()); + nsresult rv; + + nsCOMPtr containerRes; + rv = GetResourceForObject(aContainer, getter_AddRefs(containerRes)); + + nsCOMPtr childRes; + rv = GetResourceForObject(aChild, getter_AddRefs(childRes)); + + RemoveResourceForObject(aChild); + NotifyObservers(containerRes, kINS_Child, childRes, RDFEVENT_UNASSERT); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDataSource::DocumentWillBeDestroyed(nsIDocument *aDocument) +{ + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////// +// nsDOMDataSource + +nsIRDFService* +nsDOMDataSource::GetRDFService() +{ + if (!mRDFService) { + nsresult rv; + rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDFService); + if (NS_FAILED(rv)) return nsnull; + } + + return mRDFService; +} + +/////////// + +nsresult +nsDOMDataSource::GetTargetsForKnownObject(nsISupports *aObject, nsIRDFResource *aProperty, PRBool aShowAnon, nsISupportsArray *aArcs) +{ + if (!aObject) return NS_ERROR_NULL_POINTER; + nsresult rv; + + nsCOMPtr node = do_QueryInterface(aObject, &rv); + if (NS_FAILED(rv)) return rv; + return CreateDOMNodeArcs(node, aShowAnon, aArcs); +} + +nsresult +nsDOMDataSource::CreateDOMNodeArcs(nsIDOMNode *aNode, PRBool aShowAnon, nsISupportsArray* aArcs) +{ + if (!aNode) return NS_OK; + nsresult rv; + + // Need to do this test to prevent unfortunate NYI assertion + // on nsXULAttribute::GetChildNodes + nsCOMPtr attr = do_QueryInterface(aNode, &rv); + if (NS_FAILED(rv)) { + // attribute nodes + nsCOMPtr attrs; + rv = aNode->GetAttributes(getter_AddRefs(attrs)); + if (NS_FAILED(rv)) return rv; + rv = CreateDOMNamedNodeMapArcs(attrs, aArcs); + + // try to get the anonymous content + if (aShowAnon) { + nsCOMPtr content = do_QueryInterface(aNode, &rv); + if (content) { + nsCOMPtr kids; + mBindingManager->GetAnonymousNodesFor(content, getter_AddRefs(kids)); + if (!kids) + mBindingManager->GetContentListFor(content, getter_AddRefs(kids)); + if (kids) + CreateDOMNodeListArcs(kids, aArcs); + } else { + CreateChildNodeArcs(aNode, aArcs); + } + } else { + CreateChildNodeArcs(aNode, aArcs); + } + } + + return rv; +} + +nsresult +nsDOMDataSource::CreateChildNodeArcs(nsIDOMNode *aNode, nsISupportsArray *aArcs) +{ + nsresult rv; + nsCOMPtr childNodes; + rv = aNode->GetChildNodes(getter_AddRefs(childNodes)); + if (NS_FAILED(rv)) return rv; + return CreateDOMNodeListArcs(childNodes, aArcs); +} + +nsresult +nsDOMDataSource::CreateDOMNodeListArcs(nsIDOMNodeList *aNodeList, nsISupportsArray *aArcs) +{ + if (!aNodeList) return NS_OK; + PRUint32 length=0; + nsresult rv = aNodeList->GetLength(&length); + if (NS_FAILED(rv)) return rv; + + PRUint32 i; + PRUint16 type; + PRBool filtered; + for (i = 0; i < length; i++) { + nsCOMPtr node; + rv = aNodeList->Item(i, getter_AddRefs(node)); + rv = node->GetNodeType(&type); + rv = IsFiltered(type, &filtered); + if (filtered) { + nsCOMPtr resource; + rv = GetResourceForObject(node, getter_AddRefs(resource)); + rv = aArcs->AppendElement(resource); + } + } + + return rv; +} + +nsresult +nsDOMDataSource::CreateDOMNamedNodeMapArcs(nsIDOMNamedNodeMap *aNodeMap, nsISupportsArray *aArcs) +{ + if (!aNodeMap) return NS_OK; + PRUint32 length=0; + nsresult rv = aNodeMap->GetLength(&length); + if (NS_FAILED(rv)) return rv; + + PRUint32 i; + PRUint16 type; + PRBool filtered; + for (i = 0; i < length; i++) { + nsCOMPtr node; + rv = aNodeMap->Item(i, getter_AddRefs(node)); + rv = node->GetNodeType(&type); + rv = IsFiltered(type, &filtered); + if (filtered) { + nsCOMPtr resource; + rv = GetResourceForObject(node, getter_AddRefs(resource)); + rv = aArcs->AppendElement(resource); + } + } + + return rv; +} + +/////////// + +nsresult +nsDOMDataSource::CreateRootTarget(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode **aResult) +{ + nsAutoString str; + str.AssignWithConversion("unknown"); + return CreateLiteral(str, aResult); +} + +nsresult +nsDOMDataSource::CreateDOMNodeTarget(nsIDOMNode *aNode, nsIRDFResource *aProperty, nsIRDFNode **aResult) +{ + nsAutoString str; + + if (aProperty == kINS_NodeName) { + aNode->GetNodeName(str); + } else if (aProperty == kINS_NodeValue) { + aNode->GetNodeValue(str); + } else if (aProperty == kINS_NodeType) { + PRUint16 type; + aNode->GetNodeType(&type); + str.AppendInt(PRInt32(type)); + } else if (aProperty == kINS_LocalName) { + aNode->GetLocalName(str); + } else if (aProperty == kINS_Prefix) { + aNode->GetPrefix(str); + } else if (aProperty == kINS_NamespaceURI) { + aNode->GetNamespaceURI(str); + } else if (aProperty == kINS_Anonymous) { + nsCOMPtr content = do_QueryInterface(aNode); + if (content) { + nsCOMPtr bparent; + content->GetBindingParent(getter_AddRefs(bparent)); + str.AssignWithConversion(bparent ? "true" : "false"); + } else { + str.AssignWithConversion("false"); + } + } else if (aProperty == kINS_HasChildren) { + if (HasChildren(aNode)) + str.AssignWithConversion("true"); + } else { + // can't figure out what this is... so dig into resource url + nsAutoString fieldName; + GetFieldNameFromRes(aProperty, &fieldName); + + // maybe it's an attribute reference? + if (!fieldName.Find("@", false, 0, 1)) { + // first make sure we're looking at an element node... + nsCOMPtr el = do_QueryInterface(aNode); + if (el) { + nsAutoString attrName; + fieldName.Right(attrName, fieldName.Length()-1); + el->GetAttribute(attrName, str); + } + } + } + + if (str.Length() > 0) + return CreateLiteral(str, aResult); + else + return NS_OK; +} + +/////////// + +nsresult +nsDOMDataSource::GetFieldNameFromRes(nsIRDFResource* aProperty, nsAutoString* aResult) +{ + char* resval; + aProperty->GetValue(&resval); + nsAutoString val; + val.AssignWithConversion(resval); + PRInt32 offset = val.Find(INS_NAMESPACE_URI, false, 0, 1); + if (!offset) { + PRInt32 len = strlen(INS_NAMESPACE_URI); + val.Right(*aResult, val.Length() - len); + } + + return NS_OK; +} + +nsresult +nsDOMDataSource::CreateLiteral(nsString& str, nsIRDFNode **aResult) +{ + nsresult rv; + nsCOMPtr literal; + + PRUnichar* uniStr = str.ToNewUnicode(); + rv = GetRDFService()->GetLiteral(uniStr, getter_AddRefs(literal)); + nsMemory::Free(uniStr); + + *aResult = literal; + NS_IF_ADDREF(*aResult); + return NS_OK; +} + +PRUint16 +nsDOMDataSource::GetNodeTypeKey(PRUint16 aType) +{ + PRUint16 result; + switch (aType) { + case nsIDOMNode::ELEMENT_NODE: + result = 1; + break; + case nsIDOMNode::ATTRIBUTE_NODE: + result = 2; + break; + case nsIDOMNode::TEXT_NODE: + result = 4; + break; + case nsIDOMNode::CDATA_SECTION_NODE: + result = 8; + break; + case nsIDOMNode::ENTITY_REFERENCE_NODE: + result = 61; + break; + case nsIDOMNode::ENTITY_NODE: + result = 32; + break; + case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: + result = 64; + break; + case nsIDOMNode::COMMENT_NODE: + result = 128; + break; + case nsIDOMNode::DOCUMENT_NODE: + result = 256; + break; + case nsIDOMNode::DOCUMENT_TYPE_NODE: + result = 512; + break; + case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: + result = 1024; + break; + case nsIDOMNode::NOTATION_NODE: + result = 2048; + break; + default: + result = 0; + } + + return result; +} + +/////// Observer Notification + +nsresult +nsDOMDataSource::NotifyObservers(nsIRDFResource *aSubject, nsIRDFResource *aProperty, nsIRDFNode *aObject, PRUint32 aType) +{ + if(mObservers) + { + nsDOMDSNotification note = { this, aSubject, aProperty, aObject }; + if (aType == RDFEVENT_CHANGE) { + mObservers->EnumerateForwards(ChangeEnumFunc, ¬e); + } else if (aType == RDFEVENT_ASSERT) { + mObservers->EnumerateForwards(AssertEnumFunc, ¬e); + } else if (aType == RDFEVENT_UNASSERT) { + mObservers->EnumerateForwards(UnassertEnumFunc, ¬e); + } + } + return NS_OK; +} + +PRBool +nsDOMDataSource::ChangeEnumFunc(void *aElement, void *aData) +{ + nsDOMDSNotification *note = (nsDOMDSNotification *)aData; + nsIRDFObserver* observer = (nsIRDFObserver *)aElement; + + observer->OnChange(note->datasource, note->subject, note->property, nsnull, note->object); + return PR_TRUE; +} + +PRBool +nsDOMDataSource::AssertEnumFunc(void *aElement, void *aData) +{ + nsDOMDSNotification *note = (nsDOMDSNotification *)aData; + nsIRDFObserver* observer = (nsIRDFObserver *)aElement; + + observer->OnAssert(note->datasource, note->subject, note->property, note->object); + return PR_TRUE; +} + +PRBool +nsDOMDataSource::UnassertEnumFunc(void *aElement, void *aData) +{ + nsDOMDSNotification* note = (nsDOMDSNotification *)aData; + nsIRDFObserver* observer = (nsIRDFObserver *)aElement; + + observer->OnUnassert(note->datasource, note->subject, note->property, note->object); + return PR_TRUE; +} + +void +nsDOMDataSource::DumpResourceValue(nsIRDFResource* aRes) +{ + const char* str; + aRes->GetValueConst(&str); + printf("Resource Value: %s\n", str); +} + +nsresult +nsDOMDataSource::FindAttrRes(nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aAttrRes) +{ + nsDOMDSFindAttrInfo info = { nsnull, aContent, aNameSpaceID, aAttribute, aAttrRes }; + gDOMObjectTable.Enumerate(FindAttrResEnumFunc, &info); + return NS_OK; +} + +/////////////////////////////////////////////////////////////////////////// +// Since AttributeChanged (stupidly) gives me attributes by their +// namespace and atom, instead of the actual attribute node, we have to +// search the object table for an attribute node that seems to match. +// This is really nasty but an unfortunate consequence of the crappy +// AttributeChanged signature. +/////////////////////////////////////////////////////////////////////////// + +PRBool +nsDOMDataSource::FindAttrResEnumFunc(nsHashKey *aKey, void *aData, void* closure) +{ + nsDOMDSFindAttrInfo* info = (nsDOMDSFindAttrInfo*)closure; + nsCOMPtr supports = (nsISupports*) gDOMObjectTable.Get(aKey); + nsCOMPtr dsres = do_QueryInterface(supports); + dsres->GetObject(getter_AddRefs(supports)); + if (supports) { + nsCOMPtr attr = do_QueryInterface(supports); + if (attr) { + nsCOMPtr parent; + attr->GetOwnerElement(getter_AddRefs(parent)); + nsCOMPtr content = do_QueryInterface(parent); + // make sure owner content element of attributes match + if (info->mContent == content.get()) { + nsCOMPtr res = do_QueryInterface(dsres); + nsAutoString name1; + info->mAttribute->ToString(name1); + nsAutoString name2; + attr->GetName(name2); + // make sure the attribute matches + // ToDo: make sure the namespace matches + if (name1.Equals(name2)) + *info->mAttrRes = res; + } + } + } + return PR_TRUE; +} + +PRBool +nsDOMDataSource::HasChild(nsIDOMNode* aContainer, nsIDOMNode* aChild) +{ + nsresult rv; + + nsCOMPtr childNodes; + rv = aContainer->GetChildNodes(getter_AddRefs(childNodes)); + PRUint32 length = 0; + rv = childNodes->GetLength(&length); + if (NS_FAILED(rv)) return rv; + + for (PRUint32 i = 0; i < length; i++) { + nsCOMPtr node; + rv = childNodes->Item(i, getter_AddRefs(node)); + if (node.get() == aChild) + return PR_TRUE; + } + + return PR_FALSE; +} + +PRBool +nsDOMDataSource::HasAttribute(nsIDOMNode* aContainer, nsIDOMNode* aAttr) +{ + nsresult rv; + + nsCOMPtr attrs; + rv = aContainer->GetAttributes(getter_AddRefs(attrs)); + PRUint32 length = 0; + rv = attrs->GetLength(&length); + if (NS_FAILED(rv)) return rv; + + for (PRUint32 i = 0; i < length; i++) { + nsCOMPtr node; + rv = attrs->Item(i, getter_AddRefs(node)); + if (node.get() == aAttr) + return PR_TRUE; + } + + return PR_FALSE; +} + +PRBool +nsDOMDataSource::HasChildren(nsIDOMNode* aNode) +{ + nsresult rv; + nsCOMPtr content = do_QueryInterface(aNode, &rv); + if (NS_SUCCEEDED(rv) && content) { + nsCOMPtr kids; + if (*mShowAnonymousContent) { + mBindingManager->GetAnonymousNodesFor(content, getter_AddRefs(kids)); + if (!kids) + mBindingManager->GetContentListFor(content, getter_AddRefs(kids)); + } else { + aNode->GetChildNodes(getter_AddRefs(kids)); + } + if (kids) { + PRUint32 count; + kids->GetLength(&count); + if (count > 0) + return PR_TRUE; + } + } + + return PR_FALSE; +} + +nsresult +nsDOMDataSource::RemoveResourceForObject(nsISupports* aObject) +{ + nsISupportsKey* objKey = new nsISupportsKey(aObject); + gDOMObjectTable.Remove(objKey); + return NS_OK; +} + diff --git a/extensions/inspector/base/src/nsDOMDataSource.h b/extensions/inspector/base/src/nsDOMDataSource.h new file mode 100644 index 000000000000..707dc7c2a7d3 --- /dev/null +++ b/extensions/inspector/base/src/nsDOMDataSource.h @@ -0,0 +1,204 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#ifndef domdatasource___h___ +#define domdatasource___h___ + +#define NS_DOMDSDATASOURCE_ID "Inspector_DOM" + +#include "nsIInsDOMDataSource.h" +#include "nsDOMDSResource.h" + +#include "nsCOMPtr.h" +#include "nsISupportsArray.h" +#include "nsHashtable.h" +#include "nsString.h" +#include "nsVoidArray.h" + +#include "nsIContent.h" + +#include "nsIDocument.h" +#include "nsIDOMDocument.h" +#include "nsIDOMNode.h" +#include "nsIDOMAttr.h" +#include "nsIDOMElement.h" +#include "nsIDOMNamedNodeMap.h" +#include "nsIDOMNodeList.h" + +#include "nsIDocumentObserver.h" +#include "nsIDocument.h" +#include "nsIBindingManager.h" +#include "nsIXBLBinding.h" + +#include "rdf.h" +#include "nsIRDFDataSource.h" +#include "nsIRDFContainer.h" +#include "nsIRDFContainerUtils.h" +#include "nsIRDFRemoteDataSource.h" +#include "nsIRDFLiteral.h" +#include "nsIRDFResource.h" +#include "nsIRDFNode.h" +#include "nsIRDFObserver.h" +#include "nsIRDFService.h" +#include "nsRDFCID.h" + +#include "nsIComponentManager.h" +#include "nsIDOMWindowInternal.h" +#include "nsIScriptGlobalObject.h" +#include "nsIServiceManager.h" +#include "nsVoidArray.h" +#include "nsXPIDLString.h" +#include "nsEnumeratorUtils.h" +#include "nsIAtom.h" +#include "prprf.h" + +class nsDOMDataSource : public nsIInsDOMDataSource, + public nsIRDFDataSource, + public nsIDocumentObserver +{ + // nsDOMDataSource +public: + nsDOMDataSource(); + virtual ~nsDOMDataSource(); + nsresult Init(); + +private: + nsCOMPtr mDocument; + nsIBindingManager *mBindingManager; + PRBool *mShowAnonymousContent; + PRUint16 *mFilters; + nsIRDFService *mRDFService; + nsVoidArray *mObservers; + + nsIRDFService* GetRDFService(); + // Filters + PRUint16 GetNodeTypeKey(PRUint16 aType); + // Datasource Construction + nsresult GetTargetsForKnownObject(nsISupports *object, nsIRDFResource *aProperty, PRBool aShowAnon, nsISupportsArray *arcs); + nsresult CreateDOMNodeArcs(nsIDOMNode *node, PRBool aShowAnon, nsISupportsArray* arcs); + nsresult CreateChildNodeArcs(nsIDOMNode *aNode, nsISupportsArray *aArcs); + nsresult CreateDOMNodeListArcs(nsIDOMNodeList *nodelist, nsISupportsArray *arcs); + nsresult CreateDOMNamedNodeMapArcs(nsIDOMNamedNodeMap *aNodeMap, nsISupportsArray *aArcs); + nsresult CreateDOMNodeTarget(nsIDOMNode *node, nsIRDFResource *aProperty, nsIRDFNode **aResult); + nsresult CreateRootTarget(nsIRDFResource* aSource, nsIRDFResource* aProperty, nsIRDFNode **aResult); + nsresult CreateLiteral(nsString& str, nsIRDFNode **aResult); + nsresult GetFieldNameFromRes(nsIRDFResource* aProperty, nsAutoString* aResult); + + // Observer Notification + static PRBool ChangeEnumFunc(void *aElement, void *aData); + static PRBool AssertEnumFunc(void *aElement, void *aData); + static PRBool UnassertEnumFunc(void *aElement, void *aData); + nsresult NotifyObservers(nsIRDFResource *subject, nsIRDFResource *property, nsIRDFNode *object, PRUint32 aType); + // Misc + PRBool IsObjectInCache(nsISupports* aObject); + nsresult RemoveResourceForObject(nsISupports* aObject); + PRBool HasChildren(nsIDOMNode* aContainer); + static nsresult FindAttrRes(nsIContent* aContent, PRInt32 aNameSpaceID, nsIAtom* aAttribute, nsIRDFResource** aAttrRes); + static PRBool FindAttrResEnumFunc(nsHashKey *aKey, void *aData, void* closure); + static PRBool HasChild(nsIDOMNode* aContainer, nsIDOMNode* aChild); + static PRBool HasAttribute(nsIDOMNode* aContainer, nsIDOMNode* aAttr); + static void DumpResourceValue(nsIRDFResource* aRes); + +public: + // nsISupports + NS_DECL_ISUPPORTS + + // nsIInsDOMDataSource + NS_DECL_NSIINSDOMDATASOURCE + + // nsIRDFDataSource + NS_DECL_NSIRDFDATASOURCE + + // nsIDocumentObserver + NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; } + NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; } + NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; } + NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; } + NS_IMETHOD BeginReflow(nsIDocument *aDocument, nsIPresShell* aShell) { return NS_OK; } + NS_IMETHOD EndReflow(nsIDocument *aDocument, nsIPresShell* aShell) { return NS_OK; } + NS_IMETHOD ContentChanged(nsIDocument *aDocument, + nsIContent* aContent, + nsISupports* aSubContent) { return NS_OK; } + NS_IMETHOD ContentStatesChanged(nsIDocument* aDocument, + nsIContent* aContent1, + nsIContent* aContent2) { return NS_OK; } + NS_IMETHOD AttributeChanged(nsIDocument *aDocument, + nsIContent* aContent, + PRInt32 aNameSpaceID, + nsIAtom* aAttribute, + PRInt32 aHint); + NS_IMETHOD ContentAppended(nsIDocument *aDocument, + nsIContent* aContainer, + PRInt32 aNewIndexInContainer); + NS_IMETHOD ContentInserted(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer); + NS_IMETHOD ContentReplaced(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aOldChild, + nsIContent* aNewChild, + PRInt32 aIndexInContainer); + NS_IMETHOD ContentRemoved(nsIDocument *aDocument, + nsIContent* aContainer, + nsIContent* aChild, + PRInt32 aIndexInContainer); + NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet) { return NS_OK; } + NS_IMETHOD StyleSheetRemoved(nsIDocument *aDocument, nsIStyleSheet* aStyleSheet) { return NS_OK; } + NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + PRBool aDisabled) { return NS_OK; } + NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule, + PRInt32 aHint) { return NS_OK; } + NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule) { return NS_OK; } + NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument, + nsIStyleSheet* aStyleSheet, + nsIStyleRule* aStyleRule) { return NS_OK; } + NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument); + +}; + + +////////// + +typedef struct _nsDOMDSNotification { + nsIRDFDataSource *datasource; + nsIRDFResource *subject; + nsIRDFResource *property; + nsIRDFNode *object; +} nsDOMDSNotification; + +typedef struct _nsDOMDSFindAttrInfo { + nsIContent *mCrap; + nsIContent *mContent; + PRInt32 mNameSpaceID; + nsIAtom *mAttribute; + nsIRDFResource **mAttrRes; +} nsDOMDSFindAttrInfo; + +#endif // domdatasource___h___ + + diff --git a/extensions/inspector/build/Makefile.in b/extensions/inspector/build/Makefile.in new file mode 100644 index 000000000000..701aa558f746 --- /dev/null +++ b/extensions/inspector/build/Makefile.in @@ -0,0 +1,32 @@ +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH=../../.. +topsrcdir=@top_srcdir@ +srcdir=@srcdir@ +VPATH=@srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS=src + +include $(topsrcdir)/config/rules.mk + diff --git a/extensions/inspector/build/install.js b/extensions/inspector/build/install.js new file mode 100644 index 000000000000..c9f201833a3a --- /dev/null +++ b/extensions/inspector/build/install.js @@ -0,0 +1,22 @@ +var gVersion = "0.5"; + +var err = initInstall("Document Inspector", "inspector", gVersion); +logComment("initInstall: " + err); + +var fProgram = getFolder("Program"); +logComment("fProgram: " + fProgram); + +err = addDirectory("", gVersion, "bin", fProgram, "", true); +logComment("addDirectory: " + err); + +registerChrome(CONTENT | DELAYED_CHROME, getFolder("Chrome","inspector.jar"), "content/inspector/"); +registerChrome(LOCALE | DELAYED_CHROME, getFolder("Chrome","inspector.jar"), "locale/en-US/inspector/"); +registerChrome(SKIN | DELAYED_CHROME, getFolder("Chrome","inspector.jar"), "skin/modern/inspector/"); +registerChrome(SKIN | DELAYED_CHROME, getFolder("Chrome","inspector.jar"), "skin/classic/inspector/"); + +if (getLastError() == SUCCESS) { + err = performInstall(); + logComment("performInstall: " + err); +} else { + cancelInstall(err); +} diff --git a/extensions/inspector/build/makefile.win b/extensions/inspector/build/makefile.win new file mode 100644 index 000000000000..1bf5545760bf --- /dev/null +++ b/extensions/inspector/build/makefile.win @@ -0,0 +1,27 @@ +#!nmake +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\.. +include <$(DEPTH)/config/config.mak> + +DIRS = src + +include <$(DEPTH)\config\rules.mak> diff --git a/extensions/inspector/build/src/Makefile.in b/extensions/inspector/build/src/Makefile.in new file mode 100644 index 000000000000..963cd42dd694 --- /dev/null +++ b/extensions/inspector/build/src/Makefile.in @@ -0,0 +1,54 @@ +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH=../../../.. +topsrcdir=@top_srcdir@ +srcdir=@srcdir@ +VPATH=@srcdir@ + +include $(DEPTH)/config/autoconf.mk + +MODULE = inspector +LIBRARY_NAME = inspector +SHORT_LIBNAME = inspector +IS_COMPONENT = 1 + +CPPSRCS = \ + nsInspectorModule.cpp \ + $(NULL) + +LOCAL_INCLUDES += -I$(srcdir)/../../base/src + +EXTRA_DSO_LIBS = rdfutil_s + +SHARED_LIBRARY_LIBS = \ + $(DIST)/lib/libinspector_s \ + $(NULL) + +EXTRA_DSO_LDOPTS += \ + -L$(DIST)/bin \ + -L$(DIST)/lib \ + $(EXTRA_DSO_LIBS) \ + $(MOZ_COMPONENT_LIBS) \ + $(NULL) + +include $(topsrcdir)/config/rules.mk + diff --git a/extensions/inspector/build/src/makefile.win b/extensions/inspector/build/src/makefile.win new file mode 100644 index 000000000000..6d4c95711a6f --- /dev/null +++ b/extensions/inspector/build/src/makefile.win @@ -0,0 +1,49 @@ +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): + +DEPTH=..\..\..\.. +MODULE=inspector + +LIBNAME = .\$(OBJDIR)\inspector +DLL = $(LIBNAME).dll + +################################################################################ +## library + +LINCS=-I..\..\base\src + +CPP_OBJS= \ + .\$(OBJDIR)\nsInspectorModule.obj \ + $(NULL) + +LLIBS= \ + $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\rdfutil_s.lib \ + $(DIST)\lib\inspector_s.lib \ + $(DIST)\lib\gkgfxwin.lib \ + $(DIST)\lib\raptorhtmlstyle_s.lib \ + $(LIBNSPR) \ + $(NULL) + +include <$(DEPTH)/config/rules.mak> + +install:: $(DLL) + $(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin\components + $(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib + diff --git a/extensions/inspector/build/src/nsInspectorModule.cpp b/extensions/inspector/build/src/nsInspectorModule.cpp new file mode 100644 index 000000000000..59317781501f --- /dev/null +++ b/extensions/inspector/build/src/nsInspectorModule.cpp @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * 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/ + * + * 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. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All + * Rights Reserved. + * + * Contributor(s): + */ + +#include "nsIGenericFactory.h" + +#include "nsDOMDSResource.h" +#include "nsDOMDataSource.h" +#include "nsCSSRuleDataSource.h" +#include "nsCSSDecDataSource.h" +#include "nsCSSDecIntHolder.h" +#include "inFlasher.h" +#include "inCSSValueSearch.h" +#include "inFileSearch.h" + +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsDOMDataSource, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCSSRuleDataSource, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCSSDecDataSource, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsDOMDSResource) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsCSSDecIntHolder) +NS_GENERIC_FACTORY_CONSTRUCTOR(inFlasher) +NS_GENERIC_FACTORY_CONSTRUCTOR(inCSSValueSearch) +NS_GENERIC_FACTORY_CONSTRUCTOR(inFileSearch) + +static nsModuleComponentInfo components[] = +{ + { "DOM DS Resource", NS_DOMDSRESOURCE_CID, NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX NS_DOMDSRESOURCE_ID, nsDOMDSResourceConstructor }, + { "DOM Datasource", NS_INSDOMDATASOURCE_CID, NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_DOMDSDATASOURCE_ID, nsDOMDataSourceConstructor }, + { "CSS Rule Datasource", NS_CSSRULE_DATASOURCE_CID, NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_CSSRULEDATASOURCE_ID, nsCSSRuleDataSourceConstructor }, + { "CSS Dec Datasource", NS_CSSDEC_DATASOURCE_CID, NS_RDF_DATASOURCE_CONTRACTID_PREFIX NS_CSSDECDATASOURCE_ID, nsCSSDecDataSourceConstructor }, + { "Flasher", IN_FLASHER_CID, IN_FLASHER_CONTRACTID, inFlasherConstructor }, + { "Data Holder", NS_CSSDECINTHOLDER_CID, NS_CSSDECINTHOLDER_CONTRACTID, nsCSSDecIntHolderConstructor }, + { "CSS Value Search", IN_CSSVALUESEARCH_CID, IN_CSSVALUESEARCH_CONTRACTID, inCSSValueSearchConstructor }, + { "File Search", IN_FILESEARCH_CID, IN_FILESEARCH_CONTRACTID, inFileSearchConstructor } +}; + + +NS_IMPL_NSGETMODULE("nsInspectorModule", components) diff --git a/extensions/inspector/resources/Makefile.in b/extensions/inspector/resources/Makefile.in new file mode 100644 index 000000000000..a1f0efb2a391 --- /dev/null +++ b/extensions/inspector/resources/Makefile.in @@ -0,0 +1,37 @@ +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH=../../.. +topsrcdir=@top_srcdir@ +srcdir=@srcdir@ +VPATH=@srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS=content skin locale + +include $(topsrcdir)/config/rules.mk + +chrome:: + $(REGCHROME) content inspector inspector.jar + $(REGCHROME) locale en-US/inspector inspector.jar + $(REGCHROME) skin modern/inspector inspector.jar + $(REGCHROME) skin classic/inspector inspector.jar diff --git a/extensions/inspector/resources/content/Flasher.js b/extensions/inspector/resources/content/Flasher.js new file mode 100644 index 000000000000..86f18c8460b2 --- /dev/null +++ b/extensions/inspector/resources/content/Flasher.js @@ -0,0 +1,127 @@ +/*************************************************************** +* Flasher --------------------------------------------------- +* Object for controlling a timed flashing animation which +* paints a border around an element. +* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +* REQUIRED IMPORTS: +****************************************************************/ + +//////////// global variables ///////////////////// + +var gFlasherRegistry = []; + +//////////// global constants //////////////////// + +//////////////////////////////////////////////////////////////////////////// +//// class Flasher + +function Flasher(aShell, aColor, aThickness, aDuration, aSpeed) +{ + this.mShell = aShell; + this.color = aColor; + this.mThickness = aThickness; + this.duration = aDuration; + this.mSpeed = aSpeed; + + this.register(); +} + +Flasher.prototype = +{ + //////////////////////////////////////////////////////////////////////////// + //// Initialization + + mFlashTimeout: null, + mElement:null, + mWindow:null, + mRegistryId: null, + mFlashes: 0, + mStartTime: 0, + mColor: null, + mThickness: 0, + mDuration: 0, + mSpeed: 0, + + //////////////////////////////////////////////////////////////////////////// + //// Properties + + get flashing() { return this.mFlashTimeout; }, + + get element() { return this.mElement; }, + set element(val) + { + if (val && val.nodeType == 1) + this.mElement = val; + else + throw "Invalid node type."; + }, + + get window() { return this.mWindow; }, + set window(aVal) { this.mWindow = aVal; }, + + get color() { return this.mColor; }, + set color(aVal) { if (aVal.charAt(0) == '#') aVal = aVal.substr(1); this.mColor = aVal; }, + + get thickness() { return this.mThickness; }, + set thickness(aVal) { this.mThickness = aVal; }, + + get duration() { return this.mDuration; }, + set duration(aVal) { this.mDuration = aVal*1000; /*seconds->milliseconds*/ }, + + get speed() { return this.mSpeed; }, + set speed(aVal) { this.mSpeed = aVal; }, + + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + // :::::::::::::::::::: Methods :::::::::::::::::::::::::::: + // ::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + + register: function() + { + var length = gFlasherRegistry.length; + gFlasherRegistry[length] = this; + this.mRegistryId = length; + }, + + start: function() + { + this.mFlashes = 0; + this.mStartTime = new Date(); + this.doFlash(); + }, + + doFlash: function() + { + if (this.mFlashes%2) { + this.paintOn(); + } else { + this.paintOff(); + } + this.mFlashes++; + + if (new Date() - this.mStartTime < this.mDuration) { + this.mFlashTimeout = window.setTimeout("gFlasherRegistry["+this.mRegistryId+"].doFlash()", this.mSpeed); + } else { + this.stop(); + } +}, + + stop: function() + { + window.clearTimeout(this.mFlashTimeout); + this.mFlashTimeout = null; + this.paintOff(); + }, + + paintOn: function() + { + this.mShell.drawElementOutline(this.mElement, this.mWindow, this.mColor, this.mThickness); + + }, + + paintOff: function() + { + this.mShell.repaintElement(this.mElement, this.mWindow); + } + +}; + diff --git a/extensions/inspector/resources/content/InspectorApp.js b/extensions/inspector/resources/content/InspectorApp.js new file mode 100644 index 000000000000..5026380d1f53 --- /dev/null +++ b/extensions/inspector/resources/content/InspectorApp.js @@ -0,0 +1,730 @@ +/*************************************************************** +* InspectorApp ------------------------------------------------- +* The primary object that controls the Inspector application. +* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +* REQUIRED IMPORTS: +* chrome://inspector/content/ViewerRegistry.js +* chrome://inspector/content/Flasher.js +* chrome://inspector/content/search/inSearchService.js +* chrome://inspector/content/search/inSearchModule.js +* chrome://inspector/content/jsutil/xpcom/XPCU.js +* chrome://inspector/content/jsutil/rdf/RDFArray.js +* chrome://inspector/content/jsutil/rdf/RDFU.js +* chrome://inspector/content/jsutil/xul/FrameExchange.js +* chrome://inspector/content/jsutil/system/ClipboardUtils.js +* chrome://inspector/content/jsutil/system/file.js +****************************************************************/ + +//////////// global variables ///////////////////// + +var inspector; + +var kHistoryURL = "chrome/inspector/inspector-history.rdf"; +var kViewerRegURL = "chrome/inspector/viewer-registry.rdf"; +var kSearchRegURL = "chrome/inspector/search-registry.rdf"; + +//////////// global constants //////////////////// + +const kInstallDirId = "CurProcD"; + +const kFlasherCID = "@mozilla.org/inspector/flasher;1" +const kWindowMediatorIID = "@mozilla.org/rdf/datasource;1?name=window-mediator"; +const kObserverServiceIID = "@mozilla.org/observer-service;1"; +const kDirServiceCID = "@mozilla.org/file/directory_service;1" + +const nsIWebNavigation = Components.interfaces.nsIWebNavigation; + +////////////////////////////////////////////////// + +window.addEventListener("load", InspectorApp_initialize, false); + +function InspectorApp_initialize() +{ + inspector = new InspectorApp(); + inspector.initialize(); +} + +//////////////////////////////////////////////////////////////////////////// +//// class InspectorApp + +function InspectorApp() // implements inIViewerPaneContainer +{ + this.mInstallURL = this.getSpecialDirectory(kInstallDirId).URL; + kHistoryURL = this.prependBaseURL(kHistoryURL); + kViewerRegURL = this.prependBaseURL(kViewerRegURL); + kSearchRegURL = this.prependBaseURL(kSearchRegURL); + + this.mUFlasher = XPCU.createInstance(kFlasherCID, "inIFlasher"); +} + +InspectorApp.prototype = +{ + //////////////////////////////////////////////////////////////////////////// + //// Initialization + + mShell: null, + mHistory: null, + mViewerReg: null, + mSearchService: null, + mPaneCount: 2, + mCurrentViewer: null, + mCurrentWindow: null, + mShowBrowser: false, + mInstallURL: null, + mFlashSelected: null, + mFlashes: 0, + mInitialized: false, + mFlasher: null, + mIsViewingContent: false, + + get document() { return this.mDocViewerPane.viewer.viewee }, + get searchRegistry() { return this.mSearchService }, + + initialize: function() + { + this.initPrefs(); + this.loadViewerRegistry(); + this.loadHistory(); + this.initSearch(); + + var el = document.getElementById("bxBrowser"); + el.addEventListener("load", BrowserLoadListener, true); + + this.toggleBrowser(true, false); + this.toggleSearch(true, false); + this.setFlashSelected(PrefUtils.getPref("inspector.blink.on")); + }, + + initViewerPanes: function() + { + var elPane = document.getElementById("bxDocPane"); + this.mDocViewerPane = new ViewerPane(); + this.mDocViewerPane.initialize("Document", this, elPane, this.mViewerReg); + + elPane = document.getElementById("bxObjectPane"); + this.mObjViewerPane = new ViewerPane(); + this.mObjViewerPane.initialize("Object", this, elPane, this.mViewerReg); + + this.setAllViewerCmdAttributes("disabled", "true"); + }, + + //////////////////////////////////////////////////////////////////////////// + //// interface inIViewerPaneContainer + + get viewerPaneCount() { return this.mPaneCount; }, + + onViewerChanged: function(aPane, aOldViewer, aOldEntry, aNewViewer, aNewEntry) + { + var ids, el, i; + + if (!this.mInitialized) { + this.mIsViewingContent = true; + var bx = document.getElementById("bxInspectorPanes"); + bx.setAttribute("hide", "false"); + } else { + this.mInitialized = true; + } + + this.mViewerReg.cacheViewer(aNewViewer, aNewEntry); + + // disable all commands for for the old viewer + if (aOldViewer) + this.setViewerCmdAttribute(aOldEntry, "disabled", "true"); + + // enable all commands for for the new viewer + if (aNewViewer) + this.setViewerCmdAttribute(aNewEntry, "disabled", "false"); + }, + + onVieweeChanged: function(aPane, aNewObject) + { + if (aPane == this.mDocViewerPane) { + this.mObjViewerPane.viewee = aNewObject; + if (this.mFlashSelected) + this.flashElement(aNewObject, this.mCurrentWindow); + } + }, + + getViewerPaneAt: function(aIndex) + { + if (aIndex == 0) { + return this.mDocViewerPane; + } else if (aIndex == 1) { + return this.mObjViewerPane; + } else { + return null; + } + }, + + setCommandAttribute: function(aCmdId, aAttribute, aValue) + { + var cmd = document.getElementById(aCmdId); + if (cmd) + cmd.setAttribute(aAttribute, aValue); + }, + + getCommandAttribute: function(aCmdId, aAttribute) + { + var cmd = document.getElementById(aCmdId); + return cmd ? cmd.getAttribute(aAttribute) : null; + }, + + //////////////////////////////////////////////////////////////////////////// + //// UI Commands + + gotoTypedURL: function() + { + var url = document.getElementById("tfURLBar").value; + this.gotoURL(url); + }, + + goToWindow: function(aMenuitem) + { + this.setTargetWindowById(aMenuitem.id); + }, + + goToHistoryItem: function(aMenuitem) + { + var url = aMenuitem.getAttribute("value"); + this.gotoURL(url, true); + }, + + showOpenURLDialog: function() + { + var defaultURL = "chrome://inspector/content/tests/allskin.xul"; // for testing + var url = prompt("Enter a URL:", defaultURL); + if (url) { + this.gotoURL(url); + } + }, + + showPrefsDialog: function() + { + goPreferences("inspector.xul", "chrome://inspector/content/prefs/pref-inspector.xul", "inspector"); + }, + + runSearch: function() + { + var path = null; // TODO: should persist last path chosen in a pref + var file = FilePickerUtils.pickFile("Find Search File", path, ["filterXML"], "Open"); + if (file) { + var url = file.URL; + // XX temporary until 56354 is fixed + url = url.replace("file://", "file:///"); + this.startSearchModule(url); + } + }, + + toggleBrowser: function(aExplicit, aValue, aSetOnly) + { + var val = aExplicit ? aValue : !this.mShowBrowser; + this.mShowBrowser = val; + if (!aSetOnly) + this.openSplitter("Browser", val); + var cmd = document.getElementById("cmdToggleBrowser"); + cmd.setAttribute("checked", val); + }, + + toggleSearch: function(aExplicit, aValue, aSetOnly) + { + var val = aExplicit ? aValue : !this.mShowSearch; + this.mShowSearch = val; + if (!aSetOnly) + this.openSplitter("Search", val); + var cmd = document.getElementById("cmdToggleSearch"); + cmd.setAttribute("checked", val); + }, + + openSplitter: function(aName, aTruth) + { + var splitter = document.getElementById("spl" + aName); + if (aTruth) + splitter.open(); + else + splitter.close(); + }, + + toggleFlashSelected: function(aExplicit, aValue) + { + var val = aExplicit ? aValue : !this.mFlashSelected; + PrefUtils.setPref("inspector.blink.on", val); + this.setFlashSelected(val); + }, + + setFlashSelected: function(aValue) + { + this.mFlashSelected = aValue; + var cmd = document.getElementById("cmdFlashSelected"); + cmd.setAttribute("checked", aValue); + }, +/* + viewSearchItem: function() + { + if (this.mCurrentSearch.canViewItems) + window.openDialog("chrome://inspector/content/utilWindow.xul", "viewItem", "chrome,resizable"); + }, + + doViewSearchItem: function(aWindow) + { + var idx = this.getSelectedSearchIndex(); + var el = this.mCurrentSearch.viewItemAt(idx); + + aWindow.title = this.mCurrentSearch.getItemDescription(idx); + aWindow.document.getElementById("bxCenter").appendChild(el); + }, + + editSearchItem: function() + { + }, + + onSearchTreeClick: function(aEvent) + { + if (aEvent.detail == 2) { // double click + this.viewSearchItem(); + } + }, +*/ + copySearchItemLine: function() + { + var mod = this.mSearchService.currentModule; + var idx = this.mSearchService.getSelectedIndex(0); + var text = mod.getItemText(idx); + ClipboardUtils.writeString(text); + }, + + copySearchItemAll: function() + { + var text = this.getAllSearchItemText(); + ClipboardUtils.writeString(text); + }, + + saveSearchItemText: function() + { + var target = FilePickerUtils.pickFile("Save Results As", null, ["filterAll", "filterText"], "Save"); + + var text = this.getAllSearchItemText(); + + var file = new File(target.path); + file.open('w'); + file.write(text); + file.close(); + }, + + getAllSearchItemText: function() + { + var mod = this.mSearchService.currentModule; + var len = mod.resultCount; + var text = ""; + for (var i = 0; i < len; i++) { + text += mod.getItemText(i) + "\r"; + } + + return text; + }, + + showNotes: function() + { + window.open("http://www.joehewitt.com/inspector/releasenotes.html"); + }, + + showAbout: function() + { + alert("Document Inspector - a debugging tool that's fun for the whole family!"); + }, + + exit: function() + { + window.close(); + // Todo: remove observer service here + }, + + //////////////////////////////////////////////////////////////////////////// + //// Navigation + + gotoURL: function(aURL, aNoSaveHistory) + { + this.mPendingURL = aURL; + this.mPendingNoSave = aNoSaveHistory; + this.browseToURL(aURL); + this.toggleBrowser(true, true); + }, + + browseToURL: function(aURL) + { + this.webNavigation.loadURI(aURL, nsIWebNavigation.LOAD_FLAGS_NONE); + }, + + setTargetWindowById: function(aResId) + { + var windowManager = XPCU.getService(kWindowMediatorIID, "nsIWindowMediator"); + var win = windowManager.getWindowForResource(aResId); + + if (win) { + this.setTargetWindow(win); + this.setURLText("window: " + aResId); + this.toggleBrowser(true, false); + } else + alert("Unable to switch to window."); + }, + + setTargetWindow: function(aWindow) + { + this.mCurrentWindow = aWindow; + this.setTargetDocument(aWindow.document); + }, + + setTargetDocument: function(aDoc) + { + this.mDocViewerPane.viewee = aDoc; + + var doc = this.mDocViewerPane.viewee; + }, + + // turn these into getters and setters + + setURLText: function(aText) + { + document.getElementById("tfURLBar").value = aText; + }, + + setStatus: function(aText) + { + document.getElementById("txStatus").setAttribute("value", aText); + }, + + getStatus: function(aText) + { + return document.getElementById("txStatus").getAttribute("value"); + }, + + setProgress: function(aPercent) + { + document.getElementById("pmStatus").setAttribute("value", aPercent); + }, + + setSearchTitle: function(aTitle) + { + var splitter = document.getElementById("splSearch"); + splitter.setAttribute("value", "Search" + (aTitle ? " - " + aTitle : "")); + }, + + get webNavigation() + { + var browser = document.getElementById("ifBrowser"); + return browser.webNavigation; + }, + + + //////////////////////////////////////////////////////////////////////////// + //// Document Loading + + documentLoaded: function() + { + this.setTargetWindow(_content); + + // add url to the history, unless explicity told not to + if (!this.mPendingNoSave) + this.addToHistory(this.mPendingURL); + // put the url into the urlbar + this.setURLText(this.mPendingURL); + + this.mPendingURL = null; + this.mPendingNoSave = null; + }, + + //////////////////////////////////////////////////////////////////////////// + //// Search + + initSearch: function() + { + var ss = new inSearchService(); + this.mSearchService = ss; + + ss.addSearchObserver(this); + ss.resultsTree = document.getElementById("trSearch"); + ss.contextMenu = document.getElementById("ppSearchResults"); + ss.contextMenuInsertPt = document.getElementById("ppSearchResults-insertion"); + ss.contextMenuInsert = inSearchService.INSERT_BEFORE; + }, + + startSearchModule: function(aModuleURL) + { + this.mSearchService.startModule(aModuleURL); + }, + + clearSearchResults: function() + { + this.setSearchTitle(null); + this.setStatus(""); + this.setProgress(0); + + this.mSearchService.clearSearch(); + }, + + //////////////////////////////////////////////////////////////////////////// + //// interface inISearchObserver + + onSearchStart: function(aModule) + { + this.setSearchTitle(aModule.title); + this.toggleSearch(true, true); + }, + + onSearchResult: function(aModule) + { + if (aModule.isPastMilestone) { + this.setStatus("Searching - " + aModule.resultCount + " results found."); + this.setProgress(aModule.progressPercent); + } + }, + + onSearchEnd: function(aModule, aResult) + { + var diff = Math.round(aModule.elapsed / 100) / 10; + this.setProgress(100); + this.setStatus("Search complete - " + aModule.resultCount + " results found ("+diff+"s)"); + }, + + onSearchError: function(aModule, aMessage) + { + alert("Unable to complete this search due to the following error:\n" + aMessage); + }, + + //////////////////////////////////////////////////////////////////////////// + //// Viewer Registry Interaction + + loadViewerRegistry: function() + { + this.mViewerReg = new ViewerRegistry(); + this.mViewerReg.load(kViewerRegURL, this); + }, + + onViewerRegistryLoad: function() + { + this.initViewerPanes(); + }, + + onViewerRegistryLoadError: function(aStatus, aErrorMsg) + { + // fatal error + alert("Unable to load viewer registry."); + this.exit(); + }, + + getViewer: function(aUID) + { + return this.mViewerReg.getViewerByUID(aUID); + }, + + //////////////////////////////////////////////////////////////////////////// + //// History + + loadHistory: function() + { + RDFU.loadDataSource(kHistoryURL, HistoryLoadListener); + }, + + prepareHistory: function(aDS) + { + this.mHistory = RDFArray.fromContainer(aDS, "inspector:history", kInspectorNSURI); + var mppHistory = document.getElementById("mppHistory"); + mppHistory.database.AddDataSource(aDS); + mppHistory.builder.rebuild(); + }, + + addToHistory: function(aURL) + { + this.mHistory.add({ URL: aURL}); + this.mHistory.save(); + }, + + //////////////////////////////////////////////////////////////////////////// + //// Preferences + + initPrefs: function() + { + PrefUtils.addObserver("inspector", PrefChangeObserver); + }, + + onPrefChanged: function(aName) + { + if (aName == "inspector.blink.on") + this.setFlashSelected(PrefUtils.getPref("inspector.blink.on")); + + if (this.mFlasher) { + if (aName == "inspector.blink.border-color") { + this.mFlasher.color = PrefUtils.getPref("inspector.blink.border-color"); + } else if (aName == "inspector.blink.border-width") { + this.mFlasher.thickness = PrefUtils.getPref("inspector.blink.border-width"); + } else if (aName == "inspector.blink.duration") { + this.mFlasher.duration = PrefUtils.getPref("inspector.blink.duration"); + } else if (aName == "inspector.blink.speed") { + this.mFlasher.speed = PrefUtils.getPref("inspector.blink.speed"); + } + } + }, + + //////////////////////////////////////////////////////////////////////////// + //// Uncategorized + + get isViewingContent() { return this.mIsViewingContent }, + + getSpecialDirectory: function(aName) + { + var dirService = XPCU.getService(kDirServiceCID, "nsIProperties"); + return dirService.get(aName, Components.interfaces.nsIFile); + }, + + fillInTooltip: function(tipElement) + { + var retVal = false; + var textNode = document.getElementById("txTooltip"); + if (textNode) { + try { + var tipText = tipElement.getAttribute("tooltiptext"); + if (tipText != "") { + textNode.setAttribute("value", tipText); + retVal = true; + } + } + catch (e) { } + } + + return retVal; + }, + + initPopup: function(aPopup) + { + var items = aPopup.getElementsByTagName("menuitem"); + var js, fn, item; + for (var i = 0; i < items.length; i++) { + item = items[i]; + fn = item.isDisabled; + if (!fn) { + js = item.getAttribute("isDisabled"); + if (js) { + fn = new Function(js); + item.isDisabled = fn; + } else { + item.isDisabled = null; // to prevent annoying "strict" warning messages + } + } + if (fn) { + item.setAttribute("disabled", item.isDisabled()); + } + + fn = null; + } + }, + + onTreeItemSelected: function() + { + var tree = this.mDOMTree; + var items = tree.selectedItems; + if (items.length > 0) { + var node = this.getNodeFromTreeItem(items[0]); + this.startViewingNode(node, items[0].id); + } + }, + + /////////////////////////////////////////////////////////////////////////// + // The string we get back from shell.getInstallationURL starts with + // "file://" and so we need to add an extra slash, or the load fails. + // + // @param wstring aURL - the url to repair + /////////////////////////////////////////////////////////////////////////// + + prependBaseURL: function(aURL) + { + return "file:///" + this.mInstallURL.substr(7) + aURL; + }, + + flashElement: function(aElement, aWindow) + { + // make sure we only try to flash element nodes + if (aElement.nodeType == 1) { + if (!this.mFlasher) + this.mFlasher = new Flasher(this.mUFlasher, + PrefUtils.getPref("inspector.blink.border-color"), + PrefUtils.getPref("inspector.blink.border-width"), + PrefUtils.getPref("inspector.blink.duration"), + PrefUtils.getPref("inspector.blink.speed")); + + if (this.mFlasher.flashing) + this.mFlasher.stop(); + + try { + this.mFlasher.element = aElement; + this.mFlasher.window = aWindow; + this.mFlasher.start(); + } catch (ex) { + } + } + }, + + setViewerCmdAttribute: function(aEntry, aAttr, aValue) + { + var uid = this.mViewerReg.getEntryProperty(aEntry, "uid"); + var cmds = document.getElementById("brsGlobalCommands"); + var els = cmds.getElementsByAttribute("viewer", uid); + for (var i = 0; i < els.length; i++) { + if (els[i].getAttribute("exclusive") != "false") + els[i].setAttribute(aAttr, aValue); + } + }, + + setAllViewerCmdAttributes: function(aAttr, aValue) + { + var count = this.mViewerReg.getEntryCount(); + for (var i = 0; i < count; i++) { + this.setViewerCmdAttribute(i, aAttr, aValue); + } + }, + + emptyChildren: function(aNode) + { + while (aNode.childNodes.length > 0) { + aNode.removeChild(aNode.lastChild); + } + }, + + onSplitterOpen: function(aSplitter) + { + if (aSplitter.id == "splBrowser") { + this.toggleBrowser(true, aSplitter.isOpened, true); + } else if (aSplitter.id == "splSearch") { + this.toggleSearch(true, aSplitter.isOpened, true); + } + } +}; + +//////////////////////////////////////////////////////////////////////////// +//// event listeners + +var HistoryLoadListener = { + onDataSourceReady: function(aDS) + { + inspector.prepareHistory(aDS); + }, + + onError: function() + { + } +}; + +var PrefChangeObserver = { + Observe: function(aSubject, aTopic, aData) + { + inspector.onPrefChanged(aData); + } +}; + +function BrowserLoadListener(aEvent) +{ + inspector.documentLoaded(); +} + +function UtilWindowOpenListener(aWindow) +{ + inspector.doViewSearchItem(aWindow); +} diff --git a/extensions/inspector/resources/content/Makefile.in b/extensions/inspector/resources/content/Makefile.in new file mode 100644 index 000000000000..fe3a2a2c8579 --- /dev/null +++ b/extensions/inspector/resources/content/Makefile.in @@ -0,0 +1,37 @@ +# +# 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/ +# +# 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. +# +# The Original Code is mozilla.org code. +# +# The Initial Developer of the Original Code is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All +# Rights Reserved. +# +# Contributor(s): +# + +DEPTH=../../../.. +topsrcdir=@top_srcdir@ +srcdir=@srcdir@ +VPATH=@srcdir@ + +include $(DEPTH)/config/autoconf.mk + +install:: + $(INSTALL) $(srcdir)/inspector-history.rdf $(DIST)/bin/chrome/inspector + $(INSTALL) $(srcdir)/inspector-prefs.rdf $(DIST)/bin/chrome/inspector + $(INSTALL) $(srcdir)/viewer-registry.rdf $(DIST)/bin/chrome/inspector + $(INSTALL) $(srcdir)/search-registry.rdf $(DIST)/bin/chrome/inspector + $(INSTALL) $(srcdir)/prefs/inspector.js $(DIST)/bin/defaults/pref + +include $(topsrcdir)/config/rules.mk + diff --git a/extensions/inspector/resources/content/ViewerPane.js b/extensions/inspector/resources/content/ViewerPane.js new file mode 100644 index 000000000000..82220d660e0e --- /dev/null +++ b/extensions/inspector/resources/content/ViewerPane.js @@ -0,0 +1,266 @@ +/*************************************************************** +* ViewerPane --------------------------------------------------- +* Interface for a pane accepts a node and displays all eligible +* viewers in a list and activates the selected viewer. +* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +* REQUIRED IMPORTS: +* chrome://inspector/content/jsutil/xpcom/XPCU.js +****************************************************************/ + +//////////// global variables ///////////////////// + +//////////// global constants //////////////////// + +//////////////////////////////////////////////////////////////////////////// +//// class ViewerPane + +function ViewerPane() // implements inIViewerPane +{ +} + +ViewerPane.prototype = +{ + //////////////////////////////////////////////////////////////////////////// + //// Initialization + + mContextMenu: null, + mCurrentEntry: null, + mCurrentViewer: null, + + //////////////////////////////////////////////////////////////////////////// + //// interface inIViewerPane + + //// attributes + + get viewee() { return this.mViewee; }, + set viewee(aVal) { this.startViewingObject(aVal) }, + + get container() { return this.mContainer; }, + get viewer() { return this.mCurrentViewer; }, + get title() { return this.mTitle; }, + get uiElement() { return this.mUIElement; }, + get viewerReg() { return this.mViewerReg; }, + + //// methods + + initialize: function (aTitle, aContainer, aUIElement, aRegistry) + { + this.mTitle = aTitle; + this.mUIElement = aUIElement; + this.mContainer = aContainer; + this.mViewerReg = aRegistry; + + this.mListEl = aUIElement.getElementsByAttribute("ins-role", "viewer-list")[0]; + this.mTitleEl = aUIElement.getElementsByAttribute("ins-role", "viewer-title")[0]; + this.mMenuEl = aUIElement.getElementsByAttribute("ins-role", "viewer-menu")[0]; + this.mIFrameEl = aUIElement.getElementsByAttribute("ins-role", "viewer-iframe")[0]; + + this.fillViewerList(); + }, + + onViewerConstructed: function(aViewer) + { + var old = this.mCurrentViewer; + this.mCurrentViewer = aViewer; + var oldEntry = this.mCurrentEntry; + this.mCurrentEntry = this.mPendingEntry; + + this.rebuildViewerContextMenu(); + + var title = this.mViewerReg.getEntryProperty(this.mCurrentEntry, "description"); + this.setTitle(title); + + this.mContainer.onViewerChanged(this, old, oldEntry, this.mCurrentViewer, this.mCurrentEntry); + + aViewer.viewee = this.mViewee; +}, + + onVieweeChanged: function(aObject) + { + this.mContainer.onVieweeChanged(this, aObject); + }, + + setCommandAttribute: function(aCmdId, aAttribute, aValue) + { + this.mContainer.setCommandAttribute(aCmdId, aAttribute, aValue); + }, + + getCommandAttribute: function(aCmdId, aAttribute) + { + return this.mContainer.getCommandAttribute(aCmdId, aAttribute); + }, + + //////////////////////////////////////////////////////////////////////////// + //// UI Commands + + /////////////////////////////////////////////////////////////////////////// + // Sets the new view to the item just selected from the "viewer list" + /////////////////////////////////////////////////////////////////////////// + + onViewerListCommand: function(aItem) + { + this.switchViewer(aItem.entry); + + }, + + /////////////////////////////////////////////////////////////////////////// + // Prepares the list of viewers for a node, rebuilds the menulist to display + // them, and load the default viewer for the node. + // + // @param Object aObject - the object to begin viewing + /////////////////////////////////////////////////////////////////////////// + + startViewingObject: function(aObject) + { + this.mViewee = aObject; + + // get the list of viewers which match the node + var entries = this.mViewerReg.findViewersForObject(aObject); + this.rebuildViewerList(entries); + + if (entries.length > 0 && !this.entryInList(this.mCurrentEntry, entries)) { + this.switchViewer(entries[0]); + } else { + this.mCurrentViewer.viewee = aObject; + } + }, + + /////////////////////////////////////////////////////////////////////////// + // Clear out and rebuild the menulist full of the available views + // for the currently selected node. + // + // @param Array aEntries - an array of entries from the viewer registry + /////////////////////////////////////////////////////////////////////////// + + rebuildViewerList: function(aEntries) + { + var mpp = this.mListElPopup; + + this.mListEl.setAttribute("disabled", aEntries.length <= 0); + + // empty the list + while (mpp.childNodes.length) + mpp.removeChild(mpp.childNodes[0]); + + for (var i = 0; i < aEntries.length; i++) { + var entry = aEntries[i]; + var menuitem = document.createElement("menuitem"); + menuitem.setAttribute("value", this.mViewerReg.getEntryProperty(entry, "description")); + menuitem.entry = entry; + mpp.appendChild(menuitem); + } + }, + + /////////////////////////////////////////////////////////////////////////// + // Loads the viewer described by an entry in the viewer registry. + // + // @param nsIRDFNode aEntry - entry in the viewer registry + /////////////////////////////////////////////////////////////////////////// + + switchViewer: function(aEntry) + { + var url = this.mViewerReg.getEntryURL(aEntry); + + var loadNew = true; + if (this.mCurrentViewer) { + var oldURL = this.mViewerReg.getEntryURL(this.mCurrentEntry); + if (oldURL == url) { + loadNew = false; + } + } + + if (loadNew) { + this.mPendingEntry = aEntry; + this.loadViewerURL(url); + } + }, + + /////////////////////////////////////////////////////////////////////////// + // Begin loading a new viewer from a given url. + // + // @param String aURL - the url of the viewer document + /////////////////////////////////////////////////////////////////////////// + + loadViewerURL: function(aURL) + { + if (this.mCurrentViewer) { + // tell the old viewer it's about to go away + this.mCurrentViewer.destroy(); + } + + // load the new document + FrameExchange.loadURL(this.mIFrameEl, aURL, this); + }, + + /////////////////////////////////////////////////////////////////////////// + // Rebuild the viewer context menu + /////////////////////////////////////////////////////////////////////////// + + rebuildViewerContextMenu: function() + { + // remove old context menu + if (this.mContextMenu) { + this.mMenuEl.removeChild(this.mContextMenu); + this.mFormerContextParent.appendChild(this.mContextMenu); + } + + var uid = this.mViewerReg.getEntryProperty(this.mCurrentEntry, "uid"); + var ppId = "ppViewerContext-" + uid; + var pp = document.getElementById(ppId); + if (pp) { + this.mMenuEl.setAttribute("disabled", "false"); + var parent = pp.parentNode; + parent.removeChild(pp); + this.mMenuEl.appendChild(pp); + + this.mFormerContextParent = parent; + this.mContextMenu = pp; + } else { + this.mMenuEl.setAttribute("disabled", "true"); + } + }, + + /////////////////////////////////////////////////////////////////////////// + // Check to see if an entry exists in an arry of entries + // + // @param nsIRDFResource aEntry - the entry being searched for + // @param Array aList - array of entries + /////////////////////////////////////////////////////////////////////////// + + entryInList: function(aEntry, aList) + { + for (var i in aList) { + if (aList[i] == aEntry) return true; + } + + return false; + }, + + /////////////////////////////////////////////////////////////////////////// + // Set the text in the viewer title bar + // + // @param String title - the text to use + /////////////////////////////////////////////////////////////////////////// + + setTitle: function(aTitle) + { + this.mTitleEl.setAttribute("value", (this.mTitle ? this.mTitle + " - " : "") + aTitle); + }, + + /////////////////////////////////////////////////////////////////////////// + // Fill out the content of the "viewer list" menu + /////////////////////////////////////////////////////////////////////////// + + fillViewerList: function() + { + this.mListEl.pViewer = this; + this.mListEl.setAttribute("oncommand", "this.pViewer.onViewerListCommand(event.target)"); + + var mpp = document.createElement("menupopup"); + this.mListEl.appendChild(mpp); + this.mListElPopup = mpp; + } + +}; + + diff --git a/extensions/inspector/resources/content/ViewerRegistry.js b/extensions/inspector/resources/content/ViewerRegistry.js new file mode 100644 index 000000000000..7698cdc9f710 --- /dev/null +++ b/extensions/inspector/resources/content/ViewerRegistry.js @@ -0,0 +1,212 @@ +/*************************************************************** +* ViewerRegistry ----------------------------------------------- +* The centry registry where information about all installed +* viewers is kept. +* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +* REQUIRED IMPORTS: +* chrome://inspector/content/jsutil/xpcom/XPCU.js +* chrome://inspector/content/jsutil/rdf/RDFU.js +****************************************************************/ + +//////////// global variables ///////////////////// + +//////////// global constants //////////////////// + +var kViewerURLPrefix = "chrome://inspector/content/viewers/"; + +//////////////////////////////////////////////////////////////////////////// +//// class ViewerRegistry + +function ViewerRegistry() // implements inIViewerRegistry +{ + this.mViewerHash = {}; +} + +ViewerRegistry.prototype = +{ + //////////////////////////////////////////////////////////////////////////// + //// interface inIViewerRegistry + + // not yet formalized... + + //////////////////////////////////////////////////////////////////////////// + //// Initialization + + mDS: null, + mObserver: null, + mViewerDS: null, + mViewerHash: null, + mFilters: null, + + get url() { return this.mURL; }, + + //// Loading Methods + + load: function(aURL, aObserver) + { + this.mURL = aURL; + this.mObserver = aObserver; + RDFU.loadDataSource(aURL, new ViewerRegistryLoadObserver(this)); + }, + + onError: function(aErrorMsg) + { + this.mObserver.onViewerRegistryLoadError(aStatus, aErrorMsg); + }, + + onLoad: function(aDS) + { + this.mDS = aDS; + this.prepareRegistry(); + this.mObserver.onViewerRegistryLoad(); + }, + + prepareRegistry: function() + { + this.mViewerDS = RDFArray.fromContainer(this.mDS, "inspector:viewers", kInspectorNSURI); + + // create and cache the filter functions + var js, fn; + this.mFilters = []; + for (var i = 0; i < this.mViewerDS.length; ++i) { + js = this.getEntryProperty(i, "filter"); + try { + fn = new Function("object", js); + } catch (ex) { + fn = new Function("return false"); + debug("### ERROR - Syntax error in filter for viewer \"" + this.getEntryProperty(i, "description") + "\"\n"); + } + this.mFilters.push(fn); + } + }, + + /////////////////////////////////////////////////////////////////////////// + // Returns the absolute url where the xul file for a viewer can be found. + // + // @param long aIndex - the index of the entry representing the viewer + // @return wstring - the fully cannonized url + /////////////////////////////////////////////////////////////////////////// + getEntryURL: function(aIndex) + { + var uid = this.getEntryProperty(aIndex, "uid"); + return kViewerURLPrefix + uid + "/" + uid + ".xul"; + }, + + //// Lookup Methods + + /////////////////////////////////////////////////////////////////////////// + // Searches the viewer registry for all viewers that can view a particular + // object. + // + // @param Object aObject - the object being searched against + // @return nsIRDFResource[] - array of entries in the viewer registry + /////////////////////////////////////////////////////////////////////////// + findViewersForObject: function(aObject) + { + // check each entry in the registry + var len = this.mViewerDS.length; + var entry; + var urls = []; + for (var i = 0; i < len; ++i) { + if (this.objectMatchesEntry(aObject, i)) { + if (this.getEntryProperty(i, "important")) { + urls.unshift(i); + } else { + urls.push(i); + } + } + } + + return urls; + }, + + /////////////////////////////////////////////////////////////////////////// + // Determines if an object is eligible to be viewed by a particular viewer. + // + // @param Object aObject - the object being checked for eligibility + // @param long aIndex - the index of the entry + // @return boolean - true if object can be viewed + /////////////////////////////////////////////////////////////////////////// + objectMatchesEntry: function(aObject, aIndex) + { + return this.mFilters[aIndex](aObject); + }, + + /////////////////////////////////////////////////////////////////////////// + // Notifies the registry that a viewer has been instantiated, and that + // it corresponds to a particular entry in the viewer registry. + // + // @param + /////////////////////////////////////////////////////////////////////////// + cacheViewer: function(aViewer, aIndex) + { + var uid = this.getEntryProperty(aIndex, "uid"); + this.mViewerHash[uid] = { viewer: aViewer, entry: aIndex }; + }, + + // for previously loaded viewers only + getViewerByUID: function(aUID) + { + return this.mViewerHash[aUID].viewer; + }, + + // for previously loaded viewers only + getEntryForViewer: function(aViewer) + { + return this.mViewerHash[aViewer.uid].entry; + }, + + // for previously loaded viewers only + getEntryByUID: function(aUID) + { + return this.mViewerHash[aUID].aIndex; + }, + + getEntryProperty: function(aIndex, aProp) + { + return this.mViewerDS.get(aIndex, aProp); + }, + + getEntryCount: function() + { + return this.mViewerDS.length; + }, + + //////////////////////////////////////////////////////////////////////////// + //// Viewer Registration + + addNewEntry: function(aUID, aDescription, aFilter) + { + }, + + removeEntry: function(aIndex) + { + }, + + saveRegistry: function() + { + } + +}; + +//////////////////////////////////////////////////////////////////////////// +//// Listener Objects + +function ViewerRegistryLoadObserver(aTarget) +{ + this.mTarget = aTarget; +} + +ViewerRegistryLoadObserver.prototype = { + mTarget: null, + + onError: function(aErrorMsg) + { + this.mTarget.onLoadError(aErrorMsg); + }, + + onDataSourceReady: function(aDS) + { + this.mTarget.onLoad(aDS); + } +}; diff --git a/extensions/inspector/resources/content/commandOverlay.xul b/extensions/inspector/resources/content/commandOverlay.xul new file mode 100644 index 000000000000..55071d2c18ea --- /dev/null +++ b/extensions/inspector/resources/content/commandOverlay.xul @@ -0,0 +1,63 @@ + + + %dtd1; + %dtd2; +]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/extensions/inspector/resources/content/contents.rdf b/extensions/inspector/resources/content/contents.rdf new file mode 100644 index 000000000000..e360344fbd67 --- /dev/null +++ b/extensions/inspector/resources/content/contents.rdf @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + chrome://inspector/content/tasksOverlay.xul + + + + chrome://inspector/content/prefs/prefsOverlay.xul + + + + + + chrome://inspector/content/viewers/dom/commandOverlay.xul + chrome://inspector/content/search/modules/commandOverlay.xul + + + + chrome://inspector/content/viewers/dom/keysetOverlay.xul + + + + chrome://inspector/content/viewers/dom/popupOverlay.xul + chrome://inspector/content/search/modules/popupOverlay.xul + + + diff --git a/extensions/inspector/resources/content/inspector-history.rdf b/extensions/inspector/resources/content/inspector-history.rdf new file mode 100644 index 000000000000..e6772203c5e9 --- /dev/null +++ b/extensions/inspector/resources/content/inspector-history.rdf @@ -0,0 +1,14 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/extensions/inspector/resources/content/inspector-prefs.rdf b/extensions/inspector/resources/content/inspector-prefs.rdf new file mode 100644 index 000000000000..dd46d8ab3dd9 --- /dev/null +++ b/extensions/inspector/resources/content/inspector-prefs.rdf @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/extensions/inspector/resources/content/inspector.css b/extensions/inspector/resources/content/inspector.css new file mode 100644 index 000000000000..26c21e693749 --- /dev/null +++ b/extensions/inspector/resources/content/inspector.css @@ -0,0 +1,10 @@ + +@namespace ins url("http://www.mozilla.org/inspector#"); + +*[hide="true"] { + visibility: hidden; +} + +row { + vertical-align: middle; +} \ No newline at end of file diff --git a/extensions/inspector/resources/content/inspector.xul b/extensions/inspector/resources/content/inspector.xul new file mode 100644 index 000000000000..839d24cb9a29 --- /dev/null +++ b/extensions/inspector/resources/content/inspector.xul @@ -0,0 +1,43 @@ + + + %dtd1; + %dtd2; +]> + + + + + + + + + + + +