Don't stop loading a XUL document when an overlay is missing and report

warnings about missing overlays to the JS console.  Bug 221669, r=ben, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2004-07-15 06:09:36 +00:00
Родитель 67f658ce24
Коммит 6ce58346b2
4 изменённых файлов: 72 добавлений и 14 удалений

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

@ -69,6 +69,7 @@ REQUIRES = xpcom \
xultmpl \
webshell \
unicharutil \
intl \
$(NULL)
CPPSRCS = nsXULControllers.cpp

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

@ -115,6 +115,9 @@
#include "nsContentUtils.h"
#include "nsIParser.h"
#include "nsICSSStyleSheet.h"
#include "nsIConsoleService.h"
#include "nsIScriptError.h"
#include "nsIStringBundle.h"
//----------------------------------------------------------------------
//
@ -2942,7 +2945,13 @@ nsXULDocument::ResumeWalk()
nsCOMPtr<nsILoadGroup> group = do_QueryReferent(mDocumentLoadGroup);
rv = NS_OpenURI(listener, nsnull, uri, nsnull, group);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
// Just move on to the next overlay. NS_OpenURI could fail
// just because a channel could not be opened, which can happen
// if a file or chrome package does not exist.
ReportMissingOverlay(uri);
continue;
}
// If it's a 'chrome:' prototype document, then put it into
// the prototype cache; other XUL documents will be reloaded
@ -2999,6 +3008,60 @@ nsXULDocument::ResumeWalk()
return rv;
}
void
nsXULDocument::ReportMissingOverlay(nsIURI* aURI)
{
NS_PRECONDITION(aURI, "Must have a URI");
nsresult rv;
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIScriptError> errorObject =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIStringBundleService> stringBundleService =
do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
if (NS_FAILED(rv))
return;
nsCOMPtr<nsIStringBundle> bundle;
rv = stringBundleService->CreateBundle(
"chrome://global/locale/xul.properties", getter_AddRefs(bundle));
if (NS_FAILED(rv))
return;
nsCAutoString spec;
aURI->GetSpec(spec);
NS_ConvertUTF8toUTF16 utfSpec(spec);
const PRUnichar* params[] = { utfSpec.get() };
nsXPIDLString errorText;
rv = bundle->FormatStringFromName(NS_LITERAL_STRING("MissingOverlay").get(),
params, NS_ARRAY_LENGTH(params),
getter_Copies(errorText));
if (NS_FAILED(rv))
return;
nsCAutoString documentURI;
mDocumentURI->GetSpec(documentURI);
rv = errorObject->Init(errorText.get(),
NS_ConvertUTF8toUTF16(documentURI).get(),/* file name */
EmptyString().get(), /* source line */
0, /* line number */
0, /* column number */
nsIScriptError::warningFlag,
"XUL Document");
if (NS_FAILED(rv))
return;
consoleService->LogMessage(errorObject);
}
nsresult
nsXULDocument::LoadScript(nsXULPrototypeScript* aScriptProto, PRBool* aBlock)
{
@ -4141,20 +4204,14 @@ nsXULDocument::ParserObserver::OnStopRequest(nsIRequest *request,
if (NS_FAILED(aStatus)) {
// If an overlay load fails, we need to nudge the prototype
// walk along.
#define YELL_IF_MISSING_OVERLAY 1
#if defined(DEBUG) || defined(YELL_IF_MISSING_OVERLAY)
nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(request);
if (!aChannel) return NS_ERROR_FAILURE;
if (aChannel) {
nsCOMPtr<nsIURI> uri;
aChannel->GetOriginalURI(getter_AddRefs(uri));
nsCAutoString spec;
uri->GetSpec(spec);
printf("*** Failed to load overlay %s\n", spec.get());
#endif
if (uri) {
mDocument->ReportMissingOverlay(uri);
}
}
rv = mDocument->ResumeWalk();
}

0
content/xul/jar.mn Normal file
Просмотреть файл

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