зеркало из https://github.com/mozilla/pjs.git
bug 494130 - log downloadable font errors to console. r=jdaggett
This commit is contained in:
Родитель
9b49716aae
Коммит
17d202b843
|
@ -55,11 +55,11 @@
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
|
||||||
#ifdef PR_LOGGING
|
#ifdef PR_LOGGING
|
||||||
static PRLogModuleInfo *gUserFontsLog = PR_NewLogModule("userfonts");
|
PRLogModuleInfo *gfxUserFontSet::sUserFontsLog = PR_NewLogModule("userfonts");
|
||||||
#endif /* PR_LOGGING */
|
#endif /* PR_LOGGING */
|
||||||
|
|
||||||
#define LOG(args) PR_LOG(gUserFontsLog, PR_LOG_DEBUG, args)
|
#define LOG(args) PR_LOG(sUserFontsLog, PR_LOG_DEBUG, args)
|
||||||
#define LOG_ENABLED() PR_LOG_TEST(gUserFontsLog, PR_LOG_DEBUG)
|
#define LOG_ENABLED() PR_LOG_TEST(sUserFontsLog, PR_LOG_DEBUG)
|
||||||
|
|
||||||
static PRUint64 sFontSetGeneration = LL_INIT(0, 0);
|
static PRUint64 sFontSetGeneration = LL_INIT(0, 0);
|
||||||
|
|
||||||
|
@ -482,14 +482,9 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
|
||||||
const PRUint8* saneData =
|
const PRUint8* saneData =
|
||||||
SanitizeOpenTypeData(aFontData, aLength, saneLen,
|
SanitizeOpenTypeData(aFontData, aLength, saneLen,
|
||||||
fontType == GFX_USERFONT_WOFF);
|
fontType == GFX_USERFONT_WOFF);
|
||||||
#ifdef DEBUG
|
|
||||||
if (!saneData) {
|
if (!saneData) {
|
||||||
char buf[1000];
|
LogMessage(aProxy, "rejected by sanitizer");
|
||||||
sprintf(buf, "downloaded font rejected for \"%s\"",
|
|
||||||
NS_ConvertUTF16toUTF8(aProxy->FamilyName()).get());
|
|
||||||
NS_WARNING(buf);
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
if (saneData) {
|
if (saneData) {
|
||||||
// The sanitizer ensures that we have a valid sfnt and a usable
|
// The sanitizer ensures that we have a valid sfnt and a usable
|
||||||
// name table, so this should never fail unless we're out of
|
// name table, so this should never fail unless we're out of
|
||||||
|
@ -503,7 +498,7 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
|
||||||
saneData,
|
saneData,
|
||||||
saneLen);
|
saneLen);
|
||||||
if (!fe) {
|
if (!fe) {
|
||||||
NS_WARNING("failed to make platform font from download");
|
LogMessage(aProxy, "not usable by platform");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -523,11 +518,14 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
|
||||||
fe = gfxPlatform::GetPlatform()->MakePlatformFont(aProxy,
|
fe = gfxPlatform::GetPlatform()->MakePlatformFont(aProxy,
|
||||||
aFontData,
|
aFontData,
|
||||||
aLength);
|
aLength);
|
||||||
|
if (!fe) {
|
||||||
|
LogMessage(aProxy, "not usable by platform");
|
||||||
|
}
|
||||||
aFontData = nsnull; // we must NOT free this below!
|
aFontData = nsnull; // we must NOT free this below!
|
||||||
} else {
|
} else {
|
||||||
// the data was unusable, so just discard it
|
// the data was unusable, so just discard it
|
||||||
// (error will be reported below, if logging is enabled)
|
// (error will be reported below, if logging is enabled)
|
||||||
NS_WARNING("failed to make platform font from download");
|
LogMessage(aProxy, "SFNT header or tables invalid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -572,16 +570,8 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// download failed
|
// download failed
|
||||||
#ifdef PR_LOGGING
|
LogMessage(aProxy, "download failed", nsIScriptError::errorFlag,
|
||||||
if (LOG_ENABLED()) {
|
aDownloadStatus);
|
||||||
nsCAutoString fontURI;
|
|
||||||
aProxy->mSrcList[aProxy->mSrcIndex].mURI->GetSpec(fontURI);
|
|
||||||
LOG(("userfonts (%p) [src %d] failed uri: (%s) for (%s) error %8.8x downloading font data\n",
|
|
||||||
this, aProxy->mSrcIndex, fontURI.get(),
|
|
||||||
NS_ConvertUTF16toUTF8(aProxy->mFamily->Name()).get(),
|
|
||||||
aDownloadStatus));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (aFontData) {
|
if (aFontData) {
|
||||||
|
@ -606,7 +596,8 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
|
||||||
{
|
{
|
||||||
PRUint32 numSrc = aProxyEntry->mSrcList.Length();
|
PRUint32 numSrc = aProxyEntry->mSrcList.Length();
|
||||||
|
|
||||||
NS_ASSERTION(aProxyEntry->mSrcIndex < numSrc, "already at the end of the src list for user font");
|
NS_ASSERTION(aProxyEntry->mSrcIndex < numSrc,
|
||||||
|
"already at the end of the src list for user font");
|
||||||
|
|
||||||
if (aProxyEntry->mLoadingState == gfxProxyFontEntry::NOT_LOADING) {
|
if (aProxyEntry->mLoadingState == gfxProxyFontEntry::NOT_LOADING) {
|
||||||
aProxyEntry->mLoadingState = gfxProxyFontEntry::LOADING_STARTED;
|
aProxyEntry->mLoadingState = gfxProxyFontEntry::LOADING_STARTED;
|
||||||
|
@ -617,7 +608,8 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
|
||||||
aProxyEntry->mSrcIndex++;
|
aProxyEntry->mSrcIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// load each src entry in turn, until a local face is found or a download begins successfully
|
// load each src entry in turn, until a local face is found
|
||||||
|
// or a download begins successfully
|
||||||
while (aProxyEntry->mSrcIndex < numSrc) {
|
while (aProxyEntry->mSrcIndex < numSrc) {
|
||||||
const gfxFontFaceSrc& currSrc = aProxyEntry->mSrcList[aProxyEntry->mSrcIndex];
|
const gfxFontFaceSrc& currSrc = aProxyEntry->mSrcList[aProxyEntry->mSrcIndex];
|
||||||
|
|
||||||
|
@ -652,7 +644,6 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
|
||||||
currSrc.mFormatFlags)) {
|
currSrc.mFormatFlags)) {
|
||||||
nsresult rv = StartLoad(aProxyEntry, &currSrc);
|
nsresult rv = StartLoad(aProxyEntry, &currSrc);
|
||||||
PRBool loadOK = NS_SUCCEEDED(rv);
|
PRBool loadOK = NS_SUCCEEDED(rv);
|
||||||
|
|
||||||
if (loadOK) {
|
if (loadOK) {
|
||||||
#ifdef PR_LOGGING
|
#ifdef PR_LOGGING
|
||||||
if (LOG_ENABLED()) {
|
if (LOG_ENABLED()) {
|
||||||
|
@ -665,26 +656,12 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
|
||||||
#endif
|
#endif
|
||||||
return STATUS_LOADING;
|
return STATUS_LOADING;
|
||||||
} else {
|
} else {
|
||||||
#ifdef PR_LOGGING
|
LogMessage(aProxyEntry, "download failed",
|
||||||
if (LOG_ENABLED()) {
|
nsIScriptError::errorFlag, rv);
|
||||||
nsCAutoString fontURI;
|
|
||||||
currSrc.mURI->GetSpec(fontURI);
|
|
||||||
LOG(("userfonts (%p) [src %d] failed uri: (%s) for (%s) download failed\n",
|
|
||||||
this, aProxyEntry->mSrcIndex, fontURI.get(),
|
|
||||||
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifdef PR_LOGGING
|
LogMessage(aProxyEntry, "format not supported",
|
||||||
if (LOG_ENABLED()) {
|
nsIScriptError::warningFlag);
|
||||||
nsCAutoString fontURI;
|
|
||||||
currSrc.mURI->GetSpec(fontURI);
|
|
||||||
LOG(("userfonts (%p) [src %d] failed uri: (%s) for (%s) format not supported\n",
|
|
||||||
this, aProxyEntry->mSrcIndex, fontURI.get(),
|
|
||||||
NS_ConvertUTF16toUTF8(aProxyEntry->mFamily->Name()).get()));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,6 +47,7 @@
|
||||||
#include "nsIURI.h"
|
#include "nsIURI.h"
|
||||||
#include "nsIFile.h"
|
#include "nsIFile.h"
|
||||||
#include "nsISupportsImpl.h"
|
#include "nsISupportsImpl.h"
|
||||||
|
#include "nsIScriptError.h"
|
||||||
|
|
||||||
class nsIURI;
|
class nsIURI;
|
||||||
class gfxMixedFontFamily;
|
class gfxMixedFontFamily;
|
||||||
|
@ -252,10 +253,18 @@ protected:
|
||||||
|
|
||||||
gfxMixedFontFamily *GetFamily(const nsAString& aName) const;
|
gfxMixedFontFamily *GetFamily(const nsAString& aName) const;
|
||||||
|
|
||||||
|
// report a problem of some kind (implemented in nsUserFontSet)
|
||||||
|
virtual nsresult LogMessage(gfxProxyFontEntry *aProxy,
|
||||||
|
const char *aMessage,
|
||||||
|
PRUint32 aFlags = nsIScriptError::errorFlag,
|
||||||
|
nsresult aStatus = 0) = 0;
|
||||||
|
|
||||||
// font families defined by @font-face rules
|
// font families defined by @font-face rules
|
||||||
nsRefPtrHashtable<nsStringHashKey, gfxMixedFontFamily> mFontFamilies;
|
nsRefPtrHashtable<nsStringHashKey, gfxMixedFontFamily> mFontFamilies;
|
||||||
|
|
||||||
PRUint64 mGeneration;
|
PRUint64 mGeneration;
|
||||||
|
|
||||||
|
static PRLogModuleInfo *sUserFontsLog;
|
||||||
};
|
};
|
||||||
|
|
||||||
// acts a placeholder until the real font is downloaded
|
// acts a placeholder until the real font is downloaded
|
||||||
|
|
|
@ -73,6 +73,8 @@
|
||||||
#include "nsIChannelPolicy.h"
|
#include "nsIChannelPolicy.h"
|
||||||
#include "nsChannelPolicy.h"
|
#include "nsChannelPolicy.h"
|
||||||
|
|
||||||
|
#include "nsIConsoleService.h"
|
||||||
|
|
||||||
#include "nsStyleSet.h"
|
#include "nsStyleSet.h"
|
||||||
|
|
||||||
using namespace mozilla;
|
using namespace mozilla;
|
||||||
|
@ -342,17 +344,7 @@ nsUserFontSet::StartLoad(gfxProxyFontEntry *aProxy,
|
||||||
rv = nsFontFaceLoader::CheckLoadAllowed(principal, aFontFaceSrc->mURI,
|
rv = nsFontFaceLoader::CheckLoadAllowed(principal, aFontFaceSrc->mURI,
|
||||||
ps->GetDocument());
|
ps->GetDocument());
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
#ifdef PR_LOGGING
|
LogMessage(aProxy, "download not allowed", nsIScriptError::errorFlag, rv);
|
||||||
if (LOG_ENABLED()) {
|
|
||||||
nsCAutoString fontURI, referrerURI;
|
|
||||||
aFontFaceSrc->mURI->GetSpec(fontURI);
|
|
||||||
if (aFontFaceSrc->mReferrer)
|
|
||||||
aFontFaceSrc->mReferrer->GetSpec(referrerURI);
|
|
||||||
LOG(("fontdownloader download blocked - font uri: (%s) "
|
|
||||||
"referrer uri: (%s) err: %8.8x\n",
|
|
||||||
fontURI.get(), referrerURI.get(), rv));
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -697,3 +689,105 @@ nsUserFontSet::FindRuleForEntry(gfxFontEntry *aFontEntry)
|
||||||
}
|
}
|
||||||
return nsnull;
|
return nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsUserFontSet::LogMessage(gfxProxyFontEntry *aProxy,
|
||||||
|
const char *aMessage,
|
||||||
|
PRUint32 aFlags,
|
||||||
|
nsresult aStatus)
|
||||||
|
{
|
||||||
|
nsCOMPtr<nsIConsoleService>
|
||||||
|
console(do_GetService(NS_CONSOLESERVICE_CONTRACTID));
|
||||||
|
if (!console) {
|
||||||
|
return NS_ERROR_NOT_AVAILABLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_ConvertUTF16toUTF8 familyName(aProxy->FamilyName());
|
||||||
|
nsCAutoString fontURI;
|
||||||
|
aProxy->mSrcList[aProxy->mSrcIndex].mURI->GetSpec(fontURI);
|
||||||
|
|
||||||
|
char weightKeywordBuf[8]; // plenty to sprintf() a PRUint16
|
||||||
|
const char *weightKeyword;
|
||||||
|
const nsAFlatCString& weightKeywordString =
|
||||||
|
nsCSSProps::ValueToKeyword(aProxy->Weight(),
|
||||||
|
nsCSSProps::kFontWeightKTable);
|
||||||
|
if (weightKeywordString.Length() > 0) {
|
||||||
|
weightKeyword = weightKeywordString.get();
|
||||||
|
} else {
|
||||||
|
sprintf(weightKeywordBuf, "%u", aProxy->Weight());
|
||||||
|
weightKeyword = weightKeywordBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsPrintfCString
|
||||||
|
msg(1024,
|
||||||
|
"downloadable font: %s "
|
||||||
|
"(font-family: \"%s\" style:%s weight:%s stretch:%s src index:%d)",
|
||||||
|
aMessage,
|
||||||
|
familyName.get(),
|
||||||
|
aProxy->IsItalic() ? "italic" : "normal",
|
||||||
|
weightKeyword,
|
||||||
|
nsCSSProps::ValueToKeyword(aProxy->Stretch(),
|
||||||
|
nsCSSProps::kFontStretchKTable).get(),
|
||||||
|
aProxy->mSrcIndex);
|
||||||
|
|
||||||
|
if (aStatus != 0) {
|
||||||
|
msg.Append(": ");
|
||||||
|
switch (aStatus) {
|
||||||
|
case NS_ERROR_DOM_BAD_URI:
|
||||||
|
msg.Append("bad URI or cross-site access not allowed");
|
||||||
|
break;
|
||||||
|
case NS_ERROR_CONTENT_BLOCKED:
|
||||||
|
msg.Append("content blocked");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
msg.Append("status=");
|
||||||
|
msg.AppendInt(aStatus);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
msg.Append("\nsource: ");
|
||||||
|
msg.Append(fontURI);
|
||||||
|
|
||||||
|
#ifdef PR_LOGGING
|
||||||
|
if (PR_LOG_TEST(sUserFontsLog, PR_LOG_DEBUG)) {
|
||||||
|
PR_LOG(sUserFontsLog, PR_LOG_DEBUG,
|
||||||
|
("userfonts (%p) %s", this, msg.get()));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// try to give the user an indication of where the rule came from
|
||||||
|
nsCSSFontFaceRule* rule = FindRuleForEntry(aProxy);
|
||||||
|
nsString href;
|
||||||
|
nsString text;
|
||||||
|
nsresult rv;
|
||||||
|
if (rule) {
|
||||||
|
rv = rule->GetCssText(text);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
nsCOMPtr<nsIDOMCSSStyleSheet> sheet;
|
||||||
|
rv = rule->GetParentStyleSheet(getter_AddRefs(sheet));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
rv = sheet->GetHref(href);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIScriptError2> scriptError =
|
||||||
|
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
PRUint64 windowID = GetPresContext()->Document()->OuterWindowID();
|
||||||
|
rv = scriptError->InitWithWindowID(NS_ConvertUTF8toUTF16(msg).get(),
|
||||||
|
href.get(), // file
|
||||||
|
text.get(), // src line
|
||||||
|
0, 0, // line & column number
|
||||||
|
aFlags, // flags
|
||||||
|
"CSS Loader", // category (make separate?)
|
||||||
|
windowID);
|
||||||
|
if (NS_SUCCEEDED(rv)){
|
||||||
|
nsCOMPtr<nsIScriptError> logError = do_QueryInterface(scriptError);
|
||||||
|
if (logError) {
|
||||||
|
console->LogMessage(logError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
|
@ -102,6 +102,11 @@ protected:
|
||||||
nsTArray<FontFaceRuleRecord>& oldRules,
|
nsTArray<FontFaceRuleRecord>& oldRules,
|
||||||
PRBool& aFontSetModified);
|
PRBool& aFontSetModified);
|
||||||
|
|
||||||
|
virtual nsresult LogMessage(gfxProxyFontEntry *aProxy,
|
||||||
|
const char *aMessage,
|
||||||
|
PRUint32 aFlags = nsIScriptError::errorFlag,
|
||||||
|
nsresult aStatus = 0);
|
||||||
|
|
||||||
nsPresContext *mPresContext; // weak reference
|
nsPresContext *mPresContext; // weak reference
|
||||||
|
|
||||||
// Set of all loaders pointing to us. These are not strong pointers,
|
// Set of all loaders pointing to us. These are not strong pointers,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче