From 306474a7829b51d9e9c4461f2c1dfec19d77cb0e Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Fri, 12 Aug 2011 09:12:59 -0400 Subject: [PATCH 1/5] Bug 650494: Remove nsIXULPrototypeCache. r=smaug --- chrome/src/nsChromeProtocolHandler.cpp | 8 -- content/base/public/nsContentCID.h | 4 - content/xul/document/public/Makefile.in | 1 - .../document/public/nsIXULPrototypeCache.h | 91 ------------------- content/xul/document/src/nsXULDocument.h | 1 - .../xul/document/src/nsXULPrototypeCache.cpp | 18 +--- .../xul/document/src/nsXULPrototypeCache.h | 9 +- .../xul/templates/src/nsXULContentUtils.cpp | 1 - layout/build/nsLayoutModule.cpp | 5 - 9 files changed, 6 insertions(+), 132 deletions(-) delete mode 100644 content/xul/document/public/nsIXULPrototypeCache.h diff --git a/chrome/src/nsChromeProtocolHandler.cpp b/chrome/src/nsChromeProtocolHandler.cpp index ac88986e8f1..9c0997b93d8 100644 --- a/chrome/src/nsChromeProtocolHandler.cpp +++ b/chrome/src/nsChromeProtocolHandler.cpp @@ -69,14 +69,6 @@ #include "nsString.h" #include "prlog.h" -#ifdef MOZ_XUL -#include "nsIXULPrototypeCache.h" -#endif - -//---------------------------------------------------------------------- - -static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); - //////////////////////////////////////////////////////////////////////////////// NS_IMPL_THREADSAFE_ISUPPORTS2(nsChromeProtocolHandler, diff --git a/content/base/public/nsContentCID.h b/content/base/public/nsContentCID.h index 1933d2c91cf..a65f781f07f 100644 --- a/content/base/public/nsContentCID.h +++ b/content/base/public/nsContentCID.h @@ -186,10 +186,6 @@ #define NS_XULDOCUMENT_CID \ { 0x541afcb2, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } } -// {3A0A0FC1-8349-11d3-BE47-00104BDE6048} -#define NS_XULPROTOTYPECACHE_CID \ -{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } - // {a6cf9126-15b3-11d2-932e-00805f8add32} #define NS_RANGEUTILS_CID \ { 0xa6cf9126, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } diff --git a/content/xul/document/public/Makefile.in b/content/xul/document/public/Makefile.in index cb46aebd811..d148aa40030 100644 --- a/content/xul/document/public/Makefile.in +++ b/content/xul/document/public/Makefile.in @@ -57,7 +57,6 @@ XPIDLSRCS += \ EXPORTS = \ nsIXULDocument.h \ - nsIXULPrototypeCache.h \ $(NULL) endif diff --git a/content/xul/document/public/nsIXULPrototypeCache.h b/content/xul/document/public/nsIXULPrototypeCache.h deleted file mode 100644 index ba34f29c508..00000000000 --- a/content/xul/document/public/nsIXULPrototypeCache.h +++ /dev/null @@ -1,91 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1/GPL 2.0/LGPL 2.1 - * - * The contents of this file are subject to the Mozilla 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/MPL/ - * - * 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. - * - * The Initial Developer of the Original Code is - * Netscape Communications Corporation. - * Portions created by the Initial Developer are Copyright (C) 1998 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Ben Goodger - * - * Alternatively, the contents of this file may be used under the terms of - * either of the GNU General Public License Version 2 or later (the "GPL"), - * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), - * in which case the provisions of the GPL or the LGPL are applicable instead - * of those above. If you wish to allow use of your version of this file only - * under the terms of either the GPL or the LGPL, and not to allow others to - * use your version of this file under the terms of the MPL, indicate your - * decision by deleting the provisions above and replace them with the notice - * and other provisions required by the GPL or the LGPL. If you do not delete - * the provisions above, a recipient may use your version of this file under - * the terms of any one of the MPL, the GPL or the LGPL. - * - * ***** END LICENSE BLOCK ***** */ - -#ifndef nsIXULPrototypeCache_h__ -#define nsIXULPrototypeCache_h__ - -#include "nsISupports.h" -class nsIURI; - -// {3A0A0FC1-8349-11d3-BE47-00104BDE6048} -#define NS_XULPROTOTYPECACHE_CID \ -{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } - -// {f8bee3d7-4be8-46ae-92c2-60c25d5cd647} -#define NS_IXULPROTOTYPECACHE_IID \ -{ 0xf8bee3d7, 0x4be8, 0x46ae, \ - { 0x92, 0xc2, 0x60, 0xc2, 0x5d, 0x5c, 0xd6, 0x47 } } - -/** - * This interface lets code from outside gklayout access the prototype cache. - */ -class nsIXULPrototypeCache : public nsISupports -{ -public: - NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXULPROTOTYPECACHE_IID) - - /** - * Whether the XUL document at the specified URI is in the cache. - */ - virtual PRBool IsCached(nsIURI* aURI) = 0; - - /** - * Stop the caching process abruptly, removing the cache file. - */ - virtual void AbortCaching() = 0; -}; - -NS_DEFINE_STATIC_IID_ACCESSOR(nsIXULPrototypeCache, NS_IXULPROTOTYPECACHE_IID) - -nsresult -NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult); - - -const char XUL_FASTLOAD_FILE_BASENAME[] = "XUL"; - -// Increase the subtractor when changing version, say when changing the -// (opaque to XPCOM FastLoad code) format of XUL-specific XDR serializations. -// See also JSXDR_BYTECODE_VERSION in jsxdrapi.h, which tracks incompatible JS -// bytecode version changes. -#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 25) - -#define XUL_SERIALIZATION_BUFFER_SIZE (64 * 1024) -#define XUL_DESERIALIZATION_BUFFER_SIZE (8 * 1024) - - -#endif // nsIXULPrototypeCache_h__ diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 22bd805ae35..f6c44823907 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -60,7 +60,6 @@ class nsIRDFResource; class nsIRDFService; -class nsIXULPrototypeCache; class nsPIWindowRoot; #if 0 // XXXbe save me, scc (need NSCAP_FORWARD_DECL(nsXULPrototypeScript)) class nsIObjectInputStream; diff --git a/content/xul/document/src/nsXULPrototypeCache.cpp b/content/xul/document/src/nsXULPrototypeCache.cpp index d6698597b4e..edcf0ad1291 100644 --- a/content/xul/document/src/nsXULPrototypeCache.cpp +++ b/content/xul/document/src/nsXULPrototypeCache.cpp @@ -69,8 +69,6 @@ using namespace mozilla; using namespace mozilla::scache; -static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); - static PRBool gDisableXULCache = PR_FALSE; // enabled by default static const char kDisableXULCachePref[] = "nglayout.debug.disable_xul_cache"; static const char kXULCacheInfoKey[] = "nsXULPrototypeCache.startupCache"; @@ -109,10 +107,7 @@ nsXULPrototypeCache::~nsXULPrototypeCache() } -NS_IMPL_THREADSAFE_ISUPPORTS2(nsXULPrototypeCache, - nsIXULPrototypeCache, - nsIObserver) - +NS_IMPL_THREADSAFE_ISUPPORTS1(nsXULPrototypeCache, nsIObserver) nsresult NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult) @@ -161,13 +156,8 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult) /* static */ nsXULPrototypeCache* nsXULPrototypeCache::GetInstance() { - // Theoretically this can return nsnull and callers should handle that. if (!sInstance) { - nsIXULPrototypeCache* cache; - - CallGetService(kXULPrototypeCacheCID, &cache); - - sInstance = static_cast(cache); + NS_ADDREF(sInstance = new nsXULPrototypeCache()); } return sInstance; } @@ -587,9 +577,7 @@ CachePrefChangedCallback(const char* aPref, void* aClosure) gDisableXULDiskCache); if (wasEnabled && gDisableXULDiskCache) { - static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); - nsCOMPtr cache = - do_GetService(kXULPrototypeCacheCID); + nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance(); if (cache) cache->AbortCaching(); diff --git a/content/xul/document/src/nsXULPrototypeCache.h b/content/xul/document/src/nsXULPrototypeCache.h index 38e1ff18321..4683068aebe 100644 --- a/content/xul/document/src/nsXULPrototypeCache.h +++ b/content/xul/document/src/nsXULPrototypeCache.h @@ -46,7 +46,6 @@ #include "nsCOMPtr.h" #include "nsIObserver.h" #include "nsXBLDocumentInfo.h" -#include "nsIXULPrototypeCache.h" #include "nsDataHashtable.h" #include "nsInterfaceHashtable.h" #include "nsRefPtrHashtable.h" @@ -74,19 +73,17 @@ struct CacheScriptEntry * 1. In-memory hashtables * 2. The on-disk cache file. */ -class nsXULPrototypeCache : public nsIXULPrototypeCache, - nsIObserver +class nsXULPrototypeCache : public nsIObserver { public: // nsISupports NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER - // nsIXULPrototypeCache - virtual PRBool IsCached(nsIURI* aURI) { + PRBool IsCached(nsIURI* aURI) { return GetPrototype(aURI) != nsnull; } - virtual void AbortCaching(); + void AbortCaching(); /** diff --git a/content/xul/templates/src/nsXULContentUtils.cpp b/content/xul/templates/src/nsXULContentUtils.cpp index c64665474a7..2f2160886ee 100644 --- a/content/xul/templates/src/nsXULContentUtils.cpp +++ b/content/xul/templates/src/nsXULContentUtils.cpp @@ -71,7 +71,6 @@ #include "nsIServiceManager.h" #include "nsIURL.h" #include "nsXULContentUtils.h" -#include "nsIXULPrototypeCache.h" #include "nsLayoutCID.h" #include "nsNetUtil.h" #include "nsRDFCID.h" diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 8f8138fdd6f..187e6abf32e 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -260,7 +260,6 @@ static NS_DEFINE_CID(kWindowCommandTableCID, NS_WINDOWCOMMANDTABLE_CID); #ifdef MOZ_XUL #include "nsIXULDocument.h" -#include "nsIXULPrototypeCache.h" #include "nsIXULSortService.h" nsresult @@ -539,7 +538,6 @@ MAKE_CTOR(CreateXULSortService, nsIXULSortService, NS_NewXUL // NS_NewXULTreeBuilder MAKE_CTOR(CreateXULDocument, nsIXULDocument, NS_NewXULDocument) // NS_NewXULControllers -// NS_NewXULPrototypeCache MAKE_CTOR(CreateXULPopupManager, nsISupports, NS_NewXULPopupManager) #endif #ifdef MOZ_XTF @@ -785,7 +783,6 @@ NS_DEFINE_NAMED_CID(NS_XULTEMPLATEBUILDER_CID); NS_DEFINE_NAMED_CID(NS_XULTREEBUILDER_CID); NS_DEFINE_NAMED_CID(NS_XULPOPUPMANAGER_CID); NS_DEFINE_NAMED_CID(NS_XULDOCUMENT_CID); -NS_DEFINE_NAMED_CID(NS_XULPROTOTYPECACHE_CID); #endif #ifdef MOZ_XTF NS_DEFINE_NAMED_CID(NS_XTFSERVICE_CID); @@ -920,7 +917,6 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { { &kNS_XULTREEBUILDER_CID, false, NULL, NS_NewXULTreeBuilder }, { &kNS_XULPOPUPMANAGER_CID, false, NULL, CreateXULPopupManager }, { &kNS_XULDOCUMENT_CID, false, NULL, CreateXULDocument }, - { &kNS_XULPROTOTYPECACHE_CID, false, NULL, NS_NewXULPrototypeCache }, #endif #ifdef MOZ_XTF { &kNS_XTFSERVICE_CID, false, NULL, CreateXTFService }, @@ -1056,7 +1052,6 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { { "@mozilla.org/xul/xul-tree-builder;1", &kNS_XULTREEBUILDER_CID }, { "@mozilla.org/xul/xul-popup-manager;1", &kNS_XULPOPUPMANAGER_CID }, { "@mozilla.org/xul/xul-document;1", &kNS_XULDOCUMENT_CID }, - { "@mozilla.org/xul/xul-prototype-cache;1", &kNS_XULPROTOTYPECACHE_CID }, #endif #ifdef MOZ_XTF { NS_XTFSERVICE_CONTRACTID, &kNS_XTFSERVICE_CID }, From d893538cb711ddb6b890addfc056b08188e0997f Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Fri, 12 Aug 2011 12:06:46 -0400 Subject: [PATCH 2/5] Bug 678479: Add a --regen argument to header.py and typelib.py to regenerate the IDL parser. r=ted --- xpcom/idl-parser/header.py | 10 ++++++++++ xpcom/idl-parser/typelib.py | 10 ++++++++++ xpcom/idl-parser/xpidl.py | 6 +++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/xpcom/idl-parser/header.py b/xpcom/idl-parser/header.py index 7ecfa30e424..8d43013134d 100644 --- a/xpcom/idl-parser/header.py +++ b/xpcom/idl-parser/header.py @@ -483,6 +483,8 @@ if __name__ == '__main__': help="Output file (default is stdout)") o.add_option('-d', dest='depfile', default=None, help="Generate a make dependency file") + o.add_option('--regen', action='store_true', dest='regen', default=False, + help="Regenerate IDL Parser cache") options, args = o.parse_args() file, = args @@ -491,6 +493,14 @@ if __name__ == '__main__': os.mkdir(options.cachedir) sys.path.append(options.cachedir) + if options.regen: + if options.cachedir is None: + print >>sys.stderr, "--regen requires --cachedir" + sys.exit(1) + + p = xpidl.IDLParser(outputdir=options.cachedir, regen=True) + sys.exit(0) + if options.depfile is not None and options.outfile is None: print >>sys.stderr, "-d requires -o" sys.exit(1) diff --git a/xpcom/idl-parser/typelib.py b/xpcom/idl-parser/typelib.py index 2b55673f1e7..0c6bc386dfd 100644 --- a/xpcom/idl-parser/typelib.py +++ b/xpcom/idl-parser/typelib.py @@ -281,6 +281,8 @@ if __name__ == '__main__': help="Output file") o.add_option('-d', dest='depfile', default=None, help="Generate a make dependency file") + o.add_option('--regen', action='store_true', dest='regen', default=False, + help="Regenerate IDL Parser cache") options, args = o.parse_args() file, = args @@ -289,6 +291,14 @@ if __name__ == '__main__': os.mkdir(options.cachedir) sys.path.append(options.cachedir) + if options.regen: + if options.cachedir is None: + print >>sys.stderr, "--regen requires --cachedir" + sys.exit(1) + + p = xpidl.IDLParser(outputdir=options.cachedir, regen=True) + sys.exit(0) + if options.depfile is not None and options.outfile is None: print >>sys.stderr, "-d requires -o" sys.exit(1) diff --git a/xpcom/idl-parser/xpidl.py b/xpcom/idl-parser/xpidl.py index d3cbff743fe..f568befc5c8 100644 --- a/xpcom/idl-parser/xpidl.py +++ b/xpcom/idl-parser/xpidl.py @@ -1336,17 +1336,17 @@ class IDLParser(object): location = Location(self.lexer, t.lineno, t.lexpos) raise IDLError("invalid syntax", location) - def __init__(self, outputdir=''): + def __init__(self, outputdir='', regen=False): self._doccomments = [] self.lexer = lex.lex(object=self, outputdir=outputdir, lextab='xpidllex', - optimize=1) + optimize=0 if regen else 1) self.parser = yacc.yacc(module=self, outputdir=outputdir, debugfile='xpidl_debug', tabmodule='xpidlyacc', - optimize=1) + optimize=0 if regen else 1) def clearComments(self): self._doccomments = [] From 2473c43cb54bf816437576e310833a239b48f606 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Fri, 12 Aug 2011 12:07:09 -0400 Subject: [PATCH 3/5] Bug 678479: Add a makefile target in xpcom/ to regenerate the IDL parser. r=ted --- xpcom/Makefile.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xpcom/Makefile.in b/xpcom/Makefile.in index 8af06ee85bd..ac811ddf906 100644 --- a/xpcom/Makefile.in +++ b/xpcom/Makefile.in @@ -90,3 +90,9 @@ endif include $(topsrcdir)/config/rules.mk +regenerate-idl-parser: + $(PYTHON_PATH) \ + -I$(topsrcdir)/other-licenses/ply \ + -I$(topsrcdir)/xpcom/idl-parser \ + $(topsrcdir)/xpcom/idl-parser/header.py --cachedir=$(topsrcdir)/xpcom/idl-parser --regen + From dac3414a21dffe7bd0cc1388f0c7103674130094 Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Fri, 12 Aug 2011 12:58:06 -0400 Subject: [PATCH 4/5] Backed out changeset b021d1f9f57d --- chrome/src/nsChromeProtocolHandler.cpp | 8 ++ content/base/public/nsContentCID.h | 4 + content/xul/document/public/Makefile.in | 1 + .../document/public/nsIXULPrototypeCache.h | 91 +++++++++++++++++++ content/xul/document/src/nsXULDocument.h | 1 + .../xul/document/src/nsXULPrototypeCache.cpp | 18 +++- .../xul/document/src/nsXULPrototypeCache.h | 9 +- .../xul/templates/src/nsXULContentUtils.cpp | 1 + layout/build/nsLayoutModule.cpp | 5 + 9 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 content/xul/document/public/nsIXULPrototypeCache.h diff --git a/chrome/src/nsChromeProtocolHandler.cpp b/chrome/src/nsChromeProtocolHandler.cpp index 9c0997b93d8..ac88986e8f1 100644 --- a/chrome/src/nsChromeProtocolHandler.cpp +++ b/chrome/src/nsChromeProtocolHandler.cpp @@ -69,6 +69,14 @@ #include "nsString.h" #include "prlog.h" +#ifdef MOZ_XUL +#include "nsIXULPrototypeCache.h" +#endif + +//---------------------------------------------------------------------- + +static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); + //////////////////////////////////////////////////////////////////////////////// NS_IMPL_THREADSAFE_ISUPPORTS2(nsChromeProtocolHandler, diff --git a/content/base/public/nsContentCID.h b/content/base/public/nsContentCID.h index a65f781f07f..1933d2c91cf 100644 --- a/content/base/public/nsContentCID.h +++ b/content/base/public/nsContentCID.h @@ -186,6 +186,10 @@ #define NS_XULDOCUMENT_CID \ { 0x541afcb2, 0xa9a3, 0x11d2, { 0x8e, 0xc5, 0x0, 0x80, 0x5f, 0x29, 0xf3, 0x70 } } +// {3A0A0FC1-8349-11d3-BE47-00104BDE6048} +#define NS_XULPROTOTYPECACHE_CID \ +{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } + // {a6cf9126-15b3-11d2-932e-00805f8add32} #define NS_RANGEUTILS_CID \ { 0xa6cf9126, 0x15b3, 0x11d2, {0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } diff --git a/content/xul/document/public/Makefile.in b/content/xul/document/public/Makefile.in index d148aa40030..cb46aebd811 100644 --- a/content/xul/document/public/Makefile.in +++ b/content/xul/document/public/Makefile.in @@ -57,6 +57,7 @@ XPIDLSRCS += \ EXPORTS = \ nsIXULDocument.h \ + nsIXULPrototypeCache.h \ $(NULL) endif diff --git a/content/xul/document/public/nsIXULPrototypeCache.h b/content/xul/document/public/nsIXULPrototypeCache.h new file mode 100644 index 00000000000..ba34f29c508 --- /dev/null +++ b/content/xul/document/public/nsIXULPrototypeCache.h @@ -0,0 +1,91 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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. + * + * The Initial Developer of the Original Code is + * Netscape Communications Corporation. + * Portions created by the Initial Developer are Copyright (C) 1998 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Ben Goodger + * + * Alternatively, the contents of this file may be used under the terms of + * either of the GNU General Public License Version 2 or later (the "GPL"), + * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef nsIXULPrototypeCache_h__ +#define nsIXULPrototypeCache_h__ + +#include "nsISupports.h" +class nsIURI; + +// {3A0A0FC1-8349-11d3-BE47-00104BDE6048} +#define NS_XULPROTOTYPECACHE_CID \ +{ 0x3a0a0fc1, 0x8349, 0x11d3, { 0xbe, 0x47, 0x0, 0x10, 0x4b, 0xde, 0x60, 0x48 } } + +// {f8bee3d7-4be8-46ae-92c2-60c25d5cd647} +#define NS_IXULPROTOTYPECACHE_IID \ +{ 0xf8bee3d7, 0x4be8, 0x46ae, \ + { 0x92, 0xc2, 0x60, 0xc2, 0x5d, 0x5c, 0xd6, 0x47 } } + +/** + * This interface lets code from outside gklayout access the prototype cache. + */ +class nsIXULPrototypeCache : public nsISupports +{ +public: + NS_DECLARE_STATIC_IID_ACCESSOR(NS_IXULPROTOTYPECACHE_IID) + + /** + * Whether the XUL document at the specified URI is in the cache. + */ + virtual PRBool IsCached(nsIURI* aURI) = 0; + + /** + * Stop the caching process abruptly, removing the cache file. + */ + virtual void AbortCaching() = 0; +}; + +NS_DEFINE_STATIC_IID_ACCESSOR(nsIXULPrototypeCache, NS_IXULPROTOTYPECACHE_IID) + +nsresult +NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult); + + +const char XUL_FASTLOAD_FILE_BASENAME[] = "XUL"; + +// Increase the subtractor when changing version, say when changing the +// (opaque to XPCOM FastLoad code) format of XUL-specific XDR serializations. +// See also JSXDR_BYTECODE_VERSION in jsxdrapi.h, which tracks incompatible JS +// bytecode version changes. +#define XUL_FASTLOAD_FILE_VERSION (0xfeedbeef - 25) + +#define XUL_SERIALIZATION_BUFFER_SIZE (64 * 1024) +#define XUL_DESERIALIZATION_BUFFER_SIZE (8 * 1024) + + +#endif // nsIXULPrototypeCache_h__ diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index f6c44823907..22bd805ae35 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -60,6 +60,7 @@ class nsIRDFResource; class nsIRDFService; +class nsIXULPrototypeCache; class nsPIWindowRoot; #if 0 // XXXbe save me, scc (need NSCAP_FORWARD_DECL(nsXULPrototypeScript)) class nsIObjectInputStream; diff --git a/content/xul/document/src/nsXULPrototypeCache.cpp b/content/xul/document/src/nsXULPrototypeCache.cpp index edcf0ad1291..d6698597b4e 100644 --- a/content/xul/document/src/nsXULPrototypeCache.cpp +++ b/content/xul/document/src/nsXULPrototypeCache.cpp @@ -69,6 +69,8 @@ using namespace mozilla; using namespace mozilla::scache; +static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); + static PRBool gDisableXULCache = PR_FALSE; // enabled by default static const char kDisableXULCachePref[] = "nglayout.debug.disable_xul_cache"; static const char kXULCacheInfoKey[] = "nsXULPrototypeCache.startupCache"; @@ -107,7 +109,10 @@ nsXULPrototypeCache::~nsXULPrototypeCache() } -NS_IMPL_THREADSAFE_ISUPPORTS1(nsXULPrototypeCache, nsIObserver) +NS_IMPL_THREADSAFE_ISUPPORTS2(nsXULPrototypeCache, + nsIXULPrototypeCache, + nsIObserver) + nsresult NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult) @@ -156,8 +161,13 @@ NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult) /* static */ nsXULPrototypeCache* nsXULPrototypeCache::GetInstance() { + // Theoretically this can return nsnull and callers should handle that. if (!sInstance) { - NS_ADDREF(sInstance = new nsXULPrototypeCache()); + nsIXULPrototypeCache* cache; + + CallGetService(kXULPrototypeCacheCID, &cache); + + sInstance = static_cast(cache); } return sInstance; } @@ -577,7 +587,9 @@ CachePrefChangedCallback(const char* aPref, void* aClosure) gDisableXULDiskCache); if (wasEnabled && gDisableXULDiskCache) { - nsXULPrototypeCache* cache = nsXULPrototypeCache::GetInstance(); + static NS_DEFINE_CID(kXULPrototypeCacheCID, NS_XULPROTOTYPECACHE_CID); + nsCOMPtr cache = + do_GetService(kXULPrototypeCacheCID); if (cache) cache->AbortCaching(); diff --git a/content/xul/document/src/nsXULPrototypeCache.h b/content/xul/document/src/nsXULPrototypeCache.h index 4683068aebe..38e1ff18321 100644 --- a/content/xul/document/src/nsXULPrototypeCache.h +++ b/content/xul/document/src/nsXULPrototypeCache.h @@ -46,6 +46,7 @@ #include "nsCOMPtr.h" #include "nsIObserver.h" #include "nsXBLDocumentInfo.h" +#include "nsIXULPrototypeCache.h" #include "nsDataHashtable.h" #include "nsInterfaceHashtable.h" #include "nsRefPtrHashtable.h" @@ -73,17 +74,19 @@ struct CacheScriptEntry * 1. In-memory hashtables * 2. The on-disk cache file. */ -class nsXULPrototypeCache : public nsIObserver +class nsXULPrototypeCache : public nsIXULPrototypeCache, + nsIObserver { public: // nsISupports NS_DECL_ISUPPORTS NS_DECL_NSIOBSERVER - PRBool IsCached(nsIURI* aURI) { + // nsIXULPrototypeCache + virtual PRBool IsCached(nsIURI* aURI) { return GetPrototype(aURI) != nsnull; } - void AbortCaching(); + virtual void AbortCaching(); /** diff --git a/content/xul/templates/src/nsXULContentUtils.cpp b/content/xul/templates/src/nsXULContentUtils.cpp index 2f2160886ee..c64665474a7 100644 --- a/content/xul/templates/src/nsXULContentUtils.cpp +++ b/content/xul/templates/src/nsXULContentUtils.cpp @@ -71,6 +71,7 @@ #include "nsIServiceManager.h" #include "nsIURL.h" #include "nsXULContentUtils.h" +#include "nsIXULPrototypeCache.h" #include "nsLayoutCID.h" #include "nsNetUtil.h" #include "nsRDFCID.h" diff --git a/layout/build/nsLayoutModule.cpp b/layout/build/nsLayoutModule.cpp index 187e6abf32e..8f8138fdd6f 100644 --- a/layout/build/nsLayoutModule.cpp +++ b/layout/build/nsLayoutModule.cpp @@ -260,6 +260,7 @@ static NS_DEFINE_CID(kWindowCommandTableCID, NS_WINDOWCOMMANDTABLE_CID); #ifdef MOZ_XUL #include "nsIXULDocument.h" +#include "nsIXULPrototypeCache.h" #include "nsIXULSortService.h" nsresult @@ -538,6 +539,7 @@ MAKE_CTOR(CreateXULSortService, nsIXULSortService, NS_NewXUL // NS_NewXULTreeBuilder MAKE_CTOR(CreateXULDocument, nsIXULDocument, NS_NewXULDocument) // NS_NewXULControllers +// NS_NewXULPrototypeCache MAKE_CTOR(CreateXULPopupManager, nsISupports, NS_NewXULPopupManager) #endif #ifdef MOZ_XTF @@ -783,6 +785,7 @@ NS_DEFINE_NAMED_CID(NS_XULTEMPLATEBUILDER_CID); NS_DEFINE_NAMED_CID(NS_XULTREEBUILDER_CID); NS_DEFINE_NAMED_CID(NS_XULPOPUPMANAGER_CID); NS_DEFINE_NAMED_CID(NS_XULDOCUMENT_CID); +NS_DEFINE_NAMED_CID(NS_XULPROTOTYPECACHE_CID); #endif #ifdef MOZ_XTF NS_DEFINE_NAMED_CID(NS_XTFSERVICE_CID); @@ -917,6 +920,7 @@ static const mozilla::Module::CIDEntry kLayoutCIDs[] = { { &kNS_XULTREEBUILDER_CID, false, NULL, NS_NewXULTreeBuilder }, { &kNS_XULPOPUPMANAGER_CID, false, NULL, CreateXULPopupManager }, { &kNS_XULDOCUMENT_CID, false, NULL, CreateXULDocument }, + { &kNS_XULPROTOTYPECACHE_CID, false, NULL, NS_NewXULPrototypeCache }, #endif #ifdef MOZ_XTF { &kNS_XTFSERVICE_CID, false, NULL, CreateXTFService }, @@ -1052,6 +1056,7 @@ static const mozilla::Module::ContractIDEntry kLayoutContracts[] = { { "@mozilla.org/xul/xul-tree-builder;1", &kNS_XULTREEBUILDER_CID }, { "@mozilla.org/xul/xul-popup-manager;1", &kNS_XULPOPUPMANAGER_CID }, { "@mozilla.org/xul/xul-document;1", &kNS_XULDOCUMENT_CID }, + { "@mozilla.org/xul/xul-prototype-cache;1", &kNS_XULPROTOTYPECACHE_CID }, #endif #ifdef MOZ_XTF { NS_XTFSERVICE_CONTRACTID, &kNS_XTFSERVICE_CID }, From 0f16086ee8f1225829252685d59854e7222fb0cc Mon Sep 17 00:00:00 2001 From: Kyle Huey Date: Fri, 12 Aug 2011 12:58:43 -0400 Subject: [PATCH 5/5] Bug 673742: Allow postMessage()ing File and FileLists between same-origin windows. r=sicking --- dom/base/Makefile.in | 5 ++ dom/base/StructuredCloneTags.h | 55 ++++++++++++++++ dom/base/nsGlobalWindow.cpp | 116 ++++++++++++++++++++++++++++++++- 3 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 dom/base/StructuredCloneTags.h diff --git a/dom/base/Makefile.in b/dom/base/Makefile.in index d2d81f42744..c492f3ec512 100644 --- a/dom/base/Makefile.in +++ b/dom/base/Makefile.in @@ -88,6 +88,11 @@ EXPORTS = \ nsDOMMemoryReporter.h \ $(NULL) +EXPORTS_NAMESPACES = mozilla/dom +EXPORTS_mozilla/dom = \ + StructuredCloneTags.h \ + $(NULL) + CPPSRCS = \ nsBarProps.cpp \ nsDOMException.cpp \ diff --git a/dom/base/StructuredCloneTags.h b/dom/base/StructuredCloneTags.h new file mode 100644 index 00000000000..d866c75f86e --- /dev/null +++ b/dom/base/StructuredCloneTags.h @@ -0,0 +1,55 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 Structured Clone Code. + * + * The Initial Developer of the Original Code is the Mozilla Foundation. + * Portions created by the Initial Developer are Copyright (C) 2011 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Kyle Huey + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#ifndef StructuredCloneTags_h__ +#define StructuredCloneTags_h__ + +#include "jsapi.h" + +namespace mozilla { +namespace dom { + +enum StructuredCloneTags { + SCTAG_BASE = JS_SCTAG_USER_MIN, + SCTAG_DOM_BLOB, + SCTAG_DOM_FILELIST, + SCTAG_DOM_MAX +}; + +} // namespace dom +} // namespace mozilla + +#endif // StructuredCloneTags_h__ diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index adbd43debb1..2fcfb5631d7 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -179,6 +179,7 @@ #include "nsCSSProps.h" #include "nsFileDataProtocolHandler.h" #include "nsIDOMFile.h" +#include "nsIDOMFileList.h" #include "nsIURIFixup.h" #include "mozilla/FunctionTimer.h" #include "nsCDefaultURIFixup.h" @@ -240,6 +241,8 @@ #include "mozilla/dom/indexedDB/IDBFactory.h" #include "mozilla/dom/indexedDB/IndexedDatabaseManager.h" +#include "mozilla/dom/StructuredCloneTags.h" + #include "nsRefreshDriver.h" #include "mozAutoDocUpdate.h" @@ -5911,7 +5914,6 @@ nsGlobalWindow::CallerInnerWindow() return static_cast(win.get()); } - /** * Class used to represent events generated by calls to Window.postMessage, * which asynchronously creates and dispatches events. @@ -5949,6 +5951,12 @@ class PostMessageEvent : public nsRunnable aBuffer.steal(&mMessage, &mMessageLen); } + bool StoreISupports(nsISupports* aSupports) + { + mSupportsArray.AppendElement(aSupports); + return true; + } + private: nsRefPtr mSource; nsString mCallerOrigin; @@ -5957,8 +5965,102 @@ class PostMessageEvent : public nsRunnable nsRefPtr mTargetWindow; nsCOMPtr mProvidedOrigin; PRBool mTrustedCaller; + nsTArray > mSupportsArray; }; +namespace { + +struct StructuredCloneInfo { + PostMessageEvent* event; + PRBool subsumes; +}; + +static JSObject* +PostMessageReadStructuredClone(JSContext* cx, + JSStructuredCloneReader* reader, + uint32 tag, + uint32 data, + void* closure) +{ + StructuredCloneInfo* scInfo = static_cast(closure); + NS_ASSERTION(scInfo, "Must have scInfo!"); + + if (tag == SCTAG_DOM_BLOB || tag == SCTAG_DOM_FILELIST) { + NS_ASSERTION(!data, "Data should be empty"); + + nsISupports* supports; + if (JS_ReadBytes(reader, &supports, sizeof(supports))) { + JSObject* global = JS_GetGlobalForObject(cx, JS_GetScopeChain(cx)); + if (global) { + jsval val; + nsCOMPtr wrapper; + if (NS_SUCCEEDED(nsContentUtils::WrapNative(cx, global, supports, + &val, + getter_AddRefs(wrapper)))) { + return JSVAL_TO_OBJECT(val); + } + } + } + } + + const JSStructuredCloneCallbacks* runtimeCallbacks = + cx->runtime->structuredCloneCallbacks; + + if (runtimeCallbacks) { + return runtimeCallbacks->read(cx, reader, tag, data, nsnull); + } + + return JS_FALSE; +} + +static JSBool +PostMessageWriteStructuredClone(JSContext* cx, + JSStructuredCloneWriter* writer, + JSObject* obj, + void *closure) +{ + StructuredCloneInfo* scInfo = static_cast(closure); + NS_ASSERTION(scInfo, "Must have scInfo!"); + + nsCOMPtr wrappedNative; + nsContentUtils::XPConnect()-> + GetWrappedNativeOfJSObject(cx, obj, getter_AddRefs(wrappedNative)); + if (wrappedNative) { + PRUint32 scTag = 0; + nsISupports* supports = wrappedNative->Native(); + + nsCOMPtr blob = do_QueryInterface(supports); + if (blob && scInfo->subsumes) + scTag = SCTAG_DOM_BLOB; + + nsCOMPtr list = do_QueryInterface(supports); + if (list && scInfo->subsumes) + scTag = SCTAG_DOM_FILELIST; + + if (scTag) + return JS_WriteUint32Pair(writer, scTag, 0) && + JS_WriteBytes(writer, &supports, sizeof(supports)) && + scInfo->event->StoreISupports(supports); + } + + const JSStructuredCloneCallbacks* runtimeCallbacks = + cx->runtime->structuredCloneCallbacks; + + if (runtimeCallbacks) { + return runtimeCallbacks->write(cx, writer, obj, nsnull); + } + + return JS_FALSE; +} + +JSStructuredCloneCallbacks kPostMessageCallbacks = { + PostMessageReadStructuredClone, + PostMessageWriteStructuredClone, + nsnull +}; + +} // anonymous namespace + NS_IMETHODIMP PostMessageEvent::Run() { @@ -6046,8 +6148,10 @@ PostMessageEvent::Run() jsval messageData; { JSAutoRequest ar(cx); + StructuredCloneInfo scInfo; + scInfo.event = this; - if (!buffer.read(cx, &messageData, nsnull)) + if (!buffer.read(cx, &messageData, &kPostMessageCallbacks, &scInfo)) return NS_ERROR_DOM_DATA_CLONE_ERR; } @@ -6173,8 +6277,14 @@ nsGlobalWindow::PostMessageMoz(const jsval& aMessage, // We *must* clone the data here, or the jsval could be modified // by script JSAutoStructuredCloneBuffer buffer; + StructuredCloneInfo scInfo; + scInfo.event = event; - if (!buffer.write(aCx, aMessage, nsnull, nsnull)) + nsIPrincipal* principal = GetPrincipal(); + if (NS_FAILED(callerPrin->Subsumes(principal, &scInfo.subsumes))) + return NS_ERROR_DOM_DATA_CLONE_ERR; + + if (!buffer.write(aCx, aMessage, &kPostMessageCallbacks, &scInfo)) return NS_ERROR_DOM_DATA_CLONE_ERR; event->SetJSData(buffer);