For stylesheet loads with text/css or empty advisory type, end error message to error console when we don't load a stylesheet (standards mode) or warning message when we do load it (quirks mode). b=154942 r=bzbarsky sr=waterson

This commit is contained in:
dbaron%fas.harvard.edu 2002-07-02 03:11:57 +00:00
parent 539f09beff
commit 4aba7cc14e
7 changed files with 224 additions and 12 deletions

View File

@ -570,6 +570,7 @@ sub ProcessJarManifests()
CreateJarFromManifest(":mozilla:accessible:src:base:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:caps:src:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:content:html:style:src:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:docshell:base:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:editor:jar.mn", $chrome_dir, \%jars);
CreateJarFromManifest(":mozilla:embedding:browser:chrome:jar.mn", $chrome_dir, \%jars);

View File

@ -46,6 +46,7 @@ REQUIRES = xpcom \
xuldoc \
xpconnect \
view \
intl \
$(NULL)
CPPSRCS = \

View File

@ -0,0 +1,38 @@
# ***** 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 css.properties.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by the Initial Developer are Copyright
# (C) 2002 Netscape Communications Corporation. All Rights Reserved.
#
# Contributor(s):
# L. David Baron <dbaron@fas.harvard.edu> (original author)
#
# 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 *****
MimeNotCss=The stylesheet %1$S was not loaded because its MIME type, "%2$S", is not "text/css".
MimeNotCssWarn=The stylesheet %1$S was loaded as CSS even though its MIME type, "%2$S", is not "text/css".

View File

@ -0,0 +1,3 @@
en-US.jar:
locale/en-US/global/css.properties

View File

@ -40,6 +40,7 @@ REQUIRES = xpcom \
gfx \
content_xul \
view \
intl \
$(NULL)
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN

View File

@ -56,6 +56,9 @@
#include "nsITimelineService.h"
#include "nsIHttpChannel.h"
#include "nsHTMLAtoms.h"
#include "nsIConsoleService.h"
#include "nsIScriptError.h"
#include "nsIStringBundle.h"
#ifdef INCLUDE_XUL
#include "nsIXULPrototypeCache.h"
@ -65,6 +68,7 @@
#include "nsIDOMStyleSheet.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
class CSSLoaderImpl;
@ -605,6 +609,55 @@ CSSLoaderImpl::RecycleParser(nsICSSParser* aParser)
return result;
}
/**
* Report an error to the error console.
* @param aErrorName The name of a string in css.properties.
* @param aParams The parameters for that string in css.properties.
* @param aParamsLength The length of aParams.
* @param aErrorFlags Error/warning flag to pass to nsIScriptError::Init.
*
* XXX This should be a static method on a class called something like
* nsCSSUtils, since it's a general way of accessing css.properties and
* will be useful for localizability work on CSS parser error reporting.
* However, it would need some way of reporting source file name, text,
* line, and column information.
*/
static nsresult
ReportToConsole(const PRUnichar* aMessageName, const PRUnichar **aParams,
PRUint32 aParamsLength, PRUint32 aErrorFlags)
{
nsresult rv;
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIScriptError> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundleService> stringBundleService =
do_GetService(kCStringBundleServiceCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = stringBundleService->CreateBundle(
"chrome://global/locale/css.properties", getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString errorText;
rv = bundle->FormatStringFromName(aMessageName, aParams, aParamsLength,
getter_Copies(errorText));
NS_ENSURE_SUCCESS(rv, rv);
rv = errorObject->Init(errorText.get(),
NS_LITERAL_STRING("").get(), /* file name */
NS_LITERAL_STRING("").get(), /* source line */
0, /* line number */
0, /* column number */
aErrorFlags,
"CSS Loader");
NS_ENSURE_SUCCESS(rv, rv);
consoleService->LogMessage(errorObject);
return NS_OK;
}
NS_IMETHODIMP
SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
nsISupports* aContext,
@ -635,15 +688,32 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
if (realDocument && aString && aStringLen>0) {
nsCAutoString contentType;
if (mLoader->mCompatMode != eCompatibility_NavQuirks) {
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
if (channel) {
channel->GetContentType(contentType);
}
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
if (channel) {
channel->GetContentType(contentType);
}
if (mLoader->mCompatMode == eCompatibility_NavQuirks ||
contentType.Equals(NS_LITERAL_CSTRING("text/css")) ||
contentType.IsEmpty()) {
if (!contentType.IsEmpty() &&
contentType != NS_LITERAL_CSTRING("text/css")) {
nsCAutoString spec;
if (channel) {
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
if (uri)
uri->GetSpec(spec);
}
const nsAFlatString& specUCS2 = NS_ConvertUTF8toUCS2(spec);
const nsAFlatString& ctypeUCS2 = NS_ConvertASCIItoUCS2(contentType);
const PRUnichar *strings[] = { specUCS2.get(), ctypeUCS2.get() };
ReportToConsole(NS_LITERAL_STRING("MimeNotCssWarn").get(), strings, 2,
nsIScriptError::warningFlag);
}
/*
* First determine the charset (if one is indicated)
* 1) Check nsIChannel::contentCharset
@ -655,7 +725,6 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
* charset)
*/
nsAutoString strChannelCharset;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel) {
nsCAutoString charsetVal;
channel->GetContentCharset(charsetVal);
@ -746,6 +815,21 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
}
}
}
} else {
nsCAutoString spec;
if (channel) {
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
if (uri)
uri->GetSpec(spec);
}
const nsAFlatString& specUCS2 = NS_ConvertUTF8toUCS2(spec);
const nsAFlatString& ctypeUCS2 = NS_ConvertASCIItoUCS2(contentType);
const PRUnichar *strings[] = { specUCS2.get(), ctypeUCS2.get() };
ReportToConsole(NS_LITERAL_STRING("MimeNotCss").get(), strings, 2,
nsIScriptError::errorFlag);
}
}

View File

@ -56,6 +56,9 @@
#include "nsITimelineService.h"
#include "nsIHttpChannel.h"
#include "nsHTMLAtoms.h"
#include "nsIConsoleService.h"
#include "nsIScriptError.h"
#include "nsIStringBundle.h"
#ifdef INCLUDE_XUL
#include "nsIXULPrototypeCache.h"
@ -65,6 +68,7 @@
#include "nsIDOMStyleSheet.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
class CSSLoaderImpl;
@ -605,6 +609,55 @@ CSSLoaderImpl::RecycleParser(nsICSSParser* aParser)
return result;
}
/**
* Report an error to the error console.
* @param aErrorName The name of a string in css.properties.
* @param aParams The parameters for that string in css.properties.
* @param aParamsLength The length of aParams.
* @param aErrorFlags Error/warning flag to pass to nsIScriptError::Init.
*
* XXX This should be a static method on a class called something like
* nsCSSUtils, since it's a general way of accessing css.properties and
* will be useful for localizability work on CSS parser error reporting.
* However, it would need some way of reporting source file name, text,
* line, and column information.
*/
static nsresult
ReportToConsole(const PRUnichar* aMessageName, const PRUnichar **aParams,
PRUint32 aParamsLength, PRUint32 aErrorFlags)
{
nsresult rv;
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIScriptError> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundleService> stringBundleService =
do_GetService(kCStringBundleServiceCID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIStringBundle> bundle;
rv = stringBundleService->CreateBundle(
"chrome://global/locale/css.properties", getter_AddRefs(bundle));
NS_ENSURE_SUCCESS(rv, rv);
nsXPIDLString errorText;
rv = bundle->FormatStringFromName(aMessageName, aParams, aParamsLength,
getter_Copies(errorText));
NS_ENSURE_SUCCESS(rv, rv);
rv = errorObject->Init(errorText.get(),
NS_LITERAL_STRING("").get(), /* file name */
NS_LITERAL_STRING("").get(), /* source line */
0, /* line number */
0, /* column number */
aErrorFlags,
"CSS Loader");
NS_ENSURE_SUCCESS(rv, rv);
consoleService->LogMessage(errorObject);
return NS_OK;
}
NS_IMETHODIMP
SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
nsISupports* aContext,
@ -635,15 +688,32 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
if (realDocument && aString && aStringLen>0) {
nsCAutoString contentType;
if (mLoader->mCompatMode != eCompatibility_NavQuirks) {
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
if (channel) {
channel->GetContentType(contentType);
}
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
if (channel) {
channel->GetContentType(contentType);
}
if (mLoader->mCompatMode == eCompatibility_NavQuirks ||
contentType.Equals(NS_LITERAL_CSTRING("text/css")) ||
contentType.IsEmpty()) {
if (!contentType.IsEmpty() &&
contentType != NS_LITERAL_CSTRING("text/css")) {
nsCAutoString spec;
if (channel) {
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
if (uri)
uri->GetSpec(spec);
}
const nsAFlatString& specUCS2 = NS_ConvertUTF8toUCS2(spec);
const nsAFlatString& ctypeUCS2 = NS_ConvertASCIItoUCS2(contentType);
const PRUnichar *strings[] = { specUCS2.get(), ctypeUCS2.get() };
ReportToConsole(NS_LITERAL_STRING("MimeNotCssWarn").get(), strings, 2,
nsIScriptError::warningFlag);
}
/*
* First determine the charset (if one is indicated)
* 1) Check nsIChannel::contentCharset
@ -655,7 +725,6 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
* charset)
*/
nsAutoString strChannelCharset;
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (channel) {
nsCAutoString charsetVal;
channel->GetContentCharset(charsetVal);
@ -746,6 +815,21 @@ SheetLoadData::OnStreamComplete(nsIStreamLoader* aLoader,
}
}
}
} else {
nsCAutoString spec;
if (channel) {
nsCOMPtr<nsIURI> uri;
channel->GetURI(getter_AddRefs(uri));
if (uri)
uri->GetSpec(spec);
}
const nsAFlatString& specUCS2 = NS_ConvertUTF8toUCS2(spec);
const nsAFlatString& ctypeUCS2 = NS_ConvertASCIItoUCS2(contentType);
const PRUnichar *strings[] = { specUCS2.get(), ctypeUCS2.get() };
ReportToConsole(NS_LITERAL_STRING("MimeNotCss").get(), strings, 2,
nsIScriptError::errorFlag);
}
}