Bug 544112 part 1: Make speculative and chrome style sheet loads go through the document object. Rearrange some C++ unit tests so they'll still link after part 2. r=bzbarsky sr=dbaron

--HG--
rename : layout/html/tests/ParseCSS.cpp => layout/style/test/ParseCSS.cpp
rename : layout/html/tests/TestCSSPropertyLookup.cpp => layout/style/test/TestCSSPropertyLookup.cpp
This commit is contained in:
Zack Weinberg 2010-03-02 13:00:39 -08:00
Родитель c0470ea7e7
Коммит 0b183c627f
13 изменённых файлов: 134 добавлений и 176 удалений

Просмотреть файл

@ -76,7 +76,6 @@
#include "nsIAtom.h"
#include "nsICommandLine.h"
#include "nsICSSLoader.h"
#include "nsICSSStyleSheet.h"
#include "nsIConsoleService.h"
#include "nsIDirectoryService.h"
@ -865,10 +864,6 @@ static void FlushSkinBindingsForWindow(nsIDOMWindowInternal* aWindow)
// XXXbsmedberg: move this to nsIWindowMediator
NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
{
nsCOMPtr<nsICSSLoader> cssLoader(do_CreateInstance(kCSSLoaderCID));
if (!cssLoader)
return NS_OK;
nsCOMPtr<nsIWindowMediator> windowMediator
(do_GetService(NS_WINDOWMEDIATOR_CONTRACTID));
if (!windowMediator)
@ -890,7 +885,7 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
}
FlushSkinCaches();
windowMediator->GetEnumerator(nsnull, getter_AddRefs(windowEnumerator));
windowEnumerator->HasMoreElements(&more);
while (more) {
@ -899,7 +894,7 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins()
if (protoWindow) {
nsCOMPtr<nsIDOMWindowInternal> domWindow = do_QueryInterface(protoWindow);
if (domWindow)
RefreshWindow(domWindow, cssLoader);
RefreshWindow(domWindow);
}
windowEnumerator->HasMoreElements(&more);
}
@ -927,8 +922,7 @@ static PRBool IsChromeURI(nsIURI* aURI)
}
// XXXbsmedberg: move this to windowmediator
nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow,
nsICSSLoader* aCSSLoader)
nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow)
{
// Deal with our subframes first.
nsCOMPtr<nsIDOMWindowCollection> frames;
@ -940,7 +934,7 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow,
nsCOMPtr<nsIDOMWindow> childWin;
frames->Item(j, getter_AddRefs(childWin));
nsCOMPtr<nsIDOMWindowInternal> childInt(do_QueryInterface(childWin));
RefreshWindow(childInt, aCSSLoader);
RefreshWindow(childInt);
}
nsresult rv;
@ -973,8 +967,8 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow,
if (IsChromeURI(uri)) {
// Reload the sheet.
nsCOMPtr<nsICSSStyleSheet> newSheet;
rv = aCSSLoader->LoadSheetSync(uri, PR_TRUE, PR_TRUE,
getter_AddRefs(newSheet));
rv = document->LoadChromeSheetSync(uri, PR_TRUE,
getter_AddRefs(newSheet));
if (NS_FAILED(rv)) return rv;
if (newSheet) {
rv = newAgentSheets.AppendObject(newSheet) ? NS_OK : NS_ERROR_FAILURE;
@ -1002,13 +996,13 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow,
for (i = 0; i < count; i++) {
// Get the style sheet
nsIStyleSheet *styleSheet = document->GetStyleSheetAt(i);
if (!oldSheets.AppendObject(styleSheet)) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
// Iterate over our old sheets and kick off a sync load of the new
// Iterate over our old sheets and kick off a sync load of the new
// sheet if and only if it's a chrome URL.
for (i = 0; i < count; i++) {
nsCOMPtr<nsICSSStyleSheet> sheet = do_QueryInterface(oldSheets[i]);
@ -1019,8 +1013,7 @@ nsresult nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow,
nsCOMPtr<nsICSSStyleSheet> newSheet;
// XXX what about chrome sheets that have a title or are disabled? This
// only works by sheer dumb luck.
// XXXbz this should really use the document's CSSLoader!
aCSSLoader->LoadSheetSync(uri, getter_AddRefs(newSheet));
document->LoadChromeSheetSync(uri, PR_FALSE, getter_AddRefs(newSheet));
// Even if it's null, we put in in there.
newSheets.AppendObject(newSheet);
}

Просмотреть файл

@ -58,8 +58,6 @@
struct PRFileDesc;
class nsIAtom;
class nsICSSLoader;
class nsICSSStyleSheet;
class nsIDOMWindowInternal;
class nsILocalFile;
class nsIPrefBranch;
@ -119,8 +117,7 @@ protected:
private:
nsresult SelectLocaleFromPref(nsIPrefBranch* prefs);
static nsresult RefreshWindow(nsIDOMWindowInternal* aWindow,
nsICSSLoader* aCSSLoader);
static nsresult RefreshWindow(nsIDOMWindowInternal* aWindow);
static nsresult GetProviderAndPath(nsIURL* aChromeURL,
nsACString& aProvider, nsACString& aPath);

Просмотреть файл

@ -69,6 +69,7 @@ class nsIDocShell;
class nsStyleSet;
class nsIStyleSheet;
class nsIStyleRule;
class nsICSSStyleSheet;
class nsIViewManager;
class nsIScriptGlobalObject;
class nsPIDOMWindow;
@ -110,10 +111,10 @@ class Link;
} // namespace dom
} // namespace mozilla
// IID for the nsIDocument interface
// 0bce8f8b-8e27-44e6-92bc-65d0805b7fb4
#define NS_IDOCUMENT_IID \
{ 0xd7978655, 0x9b7d, 0x41e6, \
{ 0xad, 0x48, 0xdf, 0x32, 0x0b, 0x06, 0xb4, 0xda } }
{ 0x0bce8f8b, 0x8e27, 0x44e6, \
{ 0x92, 0xbc, 0x65, 0xd0, 0x80, 0x5b, 0x7f, 0xb4 } }
// Flag for AddStyleSheet().
#define NS_STYLESHEET_FROM_CATALOG (1 << 0)
@ -1208,6 +1209,23 @@ public:
*/
virtual void MaybePreLoadImage(nsIURI* uri) = 0;
/**
* Called by nsParser to preload style sheets. Can also be merged into
* the parser if and when the parser is merged with libgklayout.
*/
virtual void PreloadStyle(nsIURI* aURI, const nsAString& aCharset) = 0;
/**
* Called by the chrome registry to load style sheets. Can be put
* back there if and when when that module is merged with libgklayout.
*
* This always does a synchronous load. If aIsAgentSheet is true,
* it also uses the system principal and enables unsafe rules.
* DO NOT USE FOR UNTRUSTED CONTENT.
*/
virtual nsresult LoadChromeSheetSync(nsIURI* aURI, PRBool aIsAgentSheet,
nsICSSStyleSheet** aSheet) = 0;
/**
* Returns true if the locale used for the document specifies a direction of
* right to left. For chrome documents, this comes from the chrome registry.

Просмотреть файл

@ -7618,6 +7618,44 @@ nsDocument::MaybePreLoadImage(nsIURI* uri)
}
}
namespace {
/**
* Stub for LoadSheet(), since all we want is to get the sheet into
* the CSSLoader's style cache
*/
class StubCSSLoaderObserver : public nsICSSLoaderObserver {
public:
NS_IMETHOD
StyleSheetLoaded(nsICSSStyleSheet*, PRBool, nsresult)
{
return NS_OK;
}
NS_DECL_ISUPPORTS
};
NS_IMPL_ISUPPORTS1(StubCSSLoaderObserver, nsICSSLoaderObserver)
}
void
nsDocument::PreloadStyle(nsIURI* uri, const nsAString& charset)
{
// The CSSLoader will retain this object after we return.
nsCOMPtr<nsICSSLoaderObserver> obs = new StubCSSLoaderObserver();
// Charset names are always ASCII.
CSSLoader()->LoadSheet(uri, NodePrincipal(),
NS_LossyConvertUTF16toASCII(charset),
obs);
}
nsresult
nsDocument::LoadChromeSheetSync(nsIURI* uri, PRBool isAgentSheet,
nsICSSStyleSheet** sheet)
{
return CSSLoader()->LoadSheetSync(uri, isAgentSheet, isAgentSheet, sheet);
}
class nsDelayedEventDispatcher : public nsRunnable
{
public:

Просмотреть файл

@ -933,6 +933,11 @@ public:
virtual void MaybePreLoadImage(nsIURI* uri);
virtual void PreloadStyle(nsIURI* uri, const nsAString& charset);
virtual nsresult LoadChromeSheetSync(nsIURI* uri, PRBool isAgentSheet,
nsICSSStyleSheet** sheet);
virtual nsISupports* GetCurrentContentSink();
protected:

Просмотреть файл

@ -83,12 +83,8 @@ PARALLEL_DIRS += \
xul/base/test \
$(NULL)
TOOL_DIRS += tools/reftest
TOOL_DIRS += tools/reftest reftests/fonts reftests/fonts/mplus
DIRS += tools/pageloader
ifndef MOZ_ENABLE_LIBXUL
TOOL_DIRS += html/tests
endif
TOOL_DIRS += reftests/fonts reftests/fonts/mplus
endif
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -1,80 +0,0 @@
#
# ***** 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.org 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):
#
# 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 *****
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MOZILLA_INTERNAL_API = 1
SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=$(BIN_SUFFIX))
CPPSRCS = \
ParseCSS.cpp \
TestCSSPropertyLookup.cpp \
$(NULL)
LIBS = \
$(LIBS_DIR) \
$(DEPTH)/content/html/content/src/$(LIB_PREFIX)gkconhtmlcon_s.$(LIB_SUFFIX) \
$(DEPTH)/content/html/document/src/$(LIB_PREFIX)gkconhtmldoc_s.$(LIB_SUFFIX) \
../../forms/$(LIB_PREFIX)gkforms_s.$(LIB_SUFFIX) \
../../style/$(LIB_PREFIX)gkstyle_s.$(LIB_SUFFIX) \
../../tables/$(LIB_PREFIX)gktable_s.$(LIB_SUFFIX) \
../../base/$(LIB_PREFIX)gkbase_s.$(LIB_SUFFIX) \
../../generic/$(LIB_PREFIX)gkgeneric_s.$(LIB_SUFFIX) \
$(DEPTH)/content/base/src/$(LIB_PREFIX)gkconbase_s.$(LIB_SUFFIX) \
$(DEPTH)/content/events/src/$(LIB_PREFIX)gkconevents_s.$(LIB_SUFFIX) \
$(DEPTH)/content/xml/content/src/$(LIB_PREFIX)gkconxmlcon_s.$(LIB_SUFFIX) \
$(DEPTH)/content/xml/document/src/$(LIB_PREFIX)gkconxmldoc_s.$(LIB_SUFFIX) \
../../xul/base/src/$(LIB_PREFIX)gkxulbase_s.$(LIB_SUFFIX) \
$(MOZ_JS_LIBS) \
$(call EXPAND_LIBNAME_PATH,gkgfx,$(DEPTH)/gfx/src) \
$(TK_LIBS) \
$(MOZ_UNICHARUTIL_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk
DEFINES += -D_IMPL_NS_LAYOUT

Просмотреть файл

@ -41,10 +41,10 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = xbl-marquee
DIRS = xbl-marquee
ifdef ENABLE_TESTS
DIRS += test
TOOL_DIRS = test
endif
MODULE = layout

Просмотреть файл

@ -62,10 +62,27 @@ HOST_CPPSRCS = \
HOST_SIMPLE_PROGRAMS = $(addprefix host_, $(HOST_CPPSRCS:.cpp=$(HOST_BIN_SUFFIX)))
# ParseCSS.cpp used to be built as a test program, but it was not
# being used for anything, and recent changes to the CSS loader have
# made it fail to link. Further changes are planned which should make
# it buildable again.
#
# TestCSSPropertyLookup.cpp needs the internal XPCOM APIs and so cannot
# be built with libxul enabled.
ifndef MOZ_ENABLE_LIBXUL
CPP_UNIT_TESTS = TestCSSPropertyLookup.cpp
LIBS += ../nsCSSKeywords.o ../nsCSSProps.o $(XPCOM_LIBS)
endif
include $(topsrcdir)/config/rules.mk
DEFINES += -DMOZILLA_INTERNAL_API -D_IMPL_NS_LAYOUT
# FIXME: We don't seem to do auto-generated dependencies here.
host_ListCSSProperties.$(OBJ_SUFFIX): $(srcdir)/../nsCSSPropList.h
TestCSSPropertyLookup.$(OBJ_SUFFIX): $(srcdir)/../nsCSSProps.h $(srcdir)/../nsCSSKeywords.h
css_properties.js: host_ListCSSProperties$(HOST_BIN_SUFFIX) css_properties_like_longhand.js Makefile
$(RM) $@
@ -74,6 +91,7 @@ css_properties.js: host_ListCSSProperties$(HOST_BIN_SUFFIX) css_properties_like_
GARBAGE += css_properties.js
_TEST_FILES = test_acid3_test46.html \
test_at_rule_parse_serialize.html \
test_bug73586.html \

Просмотреть файл

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsCSSProps.h"
#include "nsCSSKeywords.h"
#include "nsString.h"
#include "nsXPCOM.h"
static const char* const kJunkNames[] = {
nsnull,
@ -49,8 +50,10 @@ static const char* const kJunkNames[] = {
"#@$&@#*@*$@$#"
};
int TestProps() {
int rv = 0;
static bool
TestProps()
{
bool success = true;
nsCSSProperty id;
nsCSSProperty index;
@ -72,11 +75,11 @@ int TestProps() {
id = nsCSSProps::LookupProperty(nsCString(tagName));
if (id == eCSSProperty_UNKNOWN) {
printf("bug: can't find '%s'\n", tagName);
rv = -1;
success = false;
}
if (id != index) {
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
rv = -1;
success = false;
}
// fiddle with the case to make sure we can still find it
@ -86,11 +89,11 @@ int TestProps() {
id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName));
if (id < 0) {
printf("bug: can't find '%s'\n", tagName);
rv = -1;
success = false;
}
if (index != id) {
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
rv = -1;
success = false;
}
et++;
}
@ -101,18 +104,20 @@ int TestProps() {
id = nsCSSProps::LookupProperty(nsCAutoString(tag));
if (id >= 0) {
printf("bug: found '%s'\n", tag ? tag : "(null)");
rv = -1;
success = false;
}
}
nsCSSProps::ReleaseTable();
return rv;
return success;
}
int TestKeywords() {
bool
TestKeywords()
{
nsCSSKeywords::AddRefTable();
int rv = 0;
bool success = true;
nsCSSKeyword id;
nsCSSKeyword index;
@ -140,11 +145,11 @@ int TestKeywords() {
id = nsCSSKeywords::LookupKeyword(nsCString(tagName));
if (id <= eCSSKeyword_UNKNOWN) {
printf("bug: can't find '%s'\n", tagName);
rv = -1;
success = false;
}
if (id != index) {
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
rv = -1;
success = false;
}
// fiddle with the case to make sure we can still find it
@ -154,11 +159,11 @@ int TestKeywords() {
id = nsCSSKeywords::LookupKeyword(nsCString(tagName));
if (id <= eCSSKeyword_UNKNOWN) {
printf("bug: can't find '%s'\n", tagName);
rv = -1;
success = false;
}
if (id != index) {
printf("bug: name='%s' id=%d index=%d\n", tagName, id, index);
rv = -1;
success = false;
}
et++;
}
@ -169,17 +174,26 @@ int TestKeywords() {
id = nsCSSKeywords::LookupKeyword(nsCAutoString(tag));
if (eCSSKeyword_UNKNOWN < id) {
printf("bug: found '%s'\n", tag ? tag : "(null)");
rv = -1;
success = false;
}
}
nsCSSKeywords::ReleaseTable();
return rv;
return success;
}
int main(int argc, char** argv)
int
main(void)
{
TestProps();
TestKeywords();
return 0;
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
NS_ENSURE_SUCCESS(rv, 2);
bool testOK = true;
testOK &= TestProps();
testOK &= TestKeywords();
rv = NS_ShutdownXPCOM(nsnull);
NS_ENSURE_SUCCESS(rv, 2);
return testOK ? 0 : 1;
}

Просмотреть файл

@ -39,28 +39,12 @@
* ***** END LICENSE BLOCK ***** */
#include "nsHtml5SpeculativeLoader.h"
#include "nsICSSLoader.h"
#include "nsNetUtil.h"
#include "nsScriptLoader.h"
#include "nsICSSLoaderObserver.h"
#include "nsIDocument.h"
/**
* Used if we need to pass an nsICSSLoaderObserver as parameter,
* but don't really need its services
*/
class nsHtml5DummyCSSLoaderObserver : public nsICSSLoaderObserver {
public:
NS_IMETHOD
StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate, nsresult aStatus) {
return NS_OK;
}
NS_DECL_ISUPPORTS
};
NS_IMPL_ISUPPORTS1(nsHtml5DummyCSSLoaderObserver, nsICSSLoaderObserver)
nsHtml5SpeculativeLoader::nsHtml5SpeculativeLoader(nsHtml5TreeOpExecutor* aExecutor)
nsHtml5SpeculativeLoader::
nsHtml5SpeculativeLoader(nsHtml5TreeOpExecutor* aExecutor)
: mExecutor(aExecutor)
{
MOZ_COUNT_CTOR(nsHtml5SpeculativeLoader);
@ -125,13 +109,9 @@ nsHtml5SpeculativeLoader::PreloadStyle(const nsAString& aURL,
if (!uri) {
return;
}
nsCOMPtr<nsICSSLoaderObserver> obs = new nsHtml5DummyCSSLoaderObserver();
nsIDocument* doc = mExecutor->GetDocument();
if (doc) {
doc->CSSLoader()->LoadSheet(uri,
doc->NodePrincipal(),
NS_LossyConvertUTF16toASCII(aCharset),
obs);
doc->PreloadStyle(uri, aCharset);
}
}

Просмотреть файл

@ -72,8 +72,6 @@
#include "nsIThreadPool.h"
#include "nsXPCOMCIDInternal.h"
#include "nsICSSStyleSheet.h"
#include "nsICSSLoaderObserver.h"
#include "nsICSSLoader.h"
#include "nsMimeTypes.h"
#ifdef MOZ_VIEW_SOURCE
@ -295,21 +293,6 @@ private:
PRBool mTerminated;
};
/**
* Used if we need to pass an nsICSSLoaderObserver as parameter,
* but don't really need its services
*/
class nsDummyCSSLoaderObserver : public nsICSSLoaderObserver {
public:
NS_IMETHOD
StyleSheetLoaded(nsICSSStyleSheet* aSheet, PRBool aWasAlternate, nsresult aStatus) {
return NS_OK;
}
NS_DECL_ISUPPORTS
};
NS_IMPL_ISUPPORTS1(nsDummyCSSLoaderObserver, nsICSSLoaderObserver)
class nsPreloadURIs : public nsIRunnable {
public:
nsPreloadURIs(nsAutoTArray<nsSpeculativeScriptThread::PrefetchEntry, 5> &aURIs,
@ -386,13 +369,9 @@ nsPreloadURIs::PreloadURIs(const nsAutoTArray<nsSpeculativeScriptThread::Prefetc
case nsSpeculativeScriptThread::IMAGE:
doc->MaybePreLoadImage(uri);
break;
case nsSpeculativeScriptThread::STYLESHEET: {
nsCOMPtr<nsICSSLoaderObserver> obs = new nsDummyCSSLoaderObserver();
doc->CSSLoader()->LoadSheet(uri, doc->NodePrincipal(),
NS_LossyConvertUTF16toASCII(pe.charset),
obs);
case nsSpeculativeScriptThread::STYLESHEET:
doc->PreloadStyle(uri, pe.charset);
break;
}
case nsSpeculativeScriptThread::NONE:
NS_NOTREACHED("Uninitialized preload entry?");
break;