forked from mirrors/gecko-dev
Bug 1480095 - Allow loading custom error pages via nsILoadURIDelegate r=esawin,bz,jchen
MozReview-Commit-ID: IhVC9nU60fy
This commit is contained in:
parent
ddda29dcf1
commit
89e3bb5c75
3 changed files with 44 additions and 27 deletions
|
|
@ -4282,7 +4282,7 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
|
||||||
bool* aDisplayedErrorPage)
|
bool* aDisplayedErrorPage)
|
||||||
{
|
{
|
||||||
*aDisplayedErrorPage = false;
|
*aDisplayedErrorPage = false;
|
||||||
// Get prompt and string bundle servcies
|
// Get prompt and string bundle services
|
||||||
nsCOMPtr<nsIPrompt> prompter;
|
nsCOMPtr<nsIPrompt> prompter;
|
||||||
nsCOMPtr<nsIStringBundle> stringBundle;
|
nsCOMPtr<nsIStringBundle> stringBundle;
|
||||||
GetPromptAndStringBundle(getter_AddRefs(prompter),
|
GetPromptAndStringBundle(getter_AddRefs(prompter),
|
||||||
|
|
@ -4303,20 +4303,24 @@ nsDocShell::DisplayLoadError(nsresult aError, nsIURI* aURI,
|
||||||
nsAutoCString cssClass;
|
nsAutoCString cssClass;
|
||||||
nsAutoCString errorPage;
|
nsAutoCString errorPage;
|
||||||
|
|
||||||
errorPage.AssignLiteral("neterror");
|
|
||||||
|
|
||||||
if (mLoadURIDelegate) {
|
if (mLoadURIDelegate) {
|
||||||
bool loadErrorHandled = false;
|
nsCOMPtr<nsIURI> errorPageURI;
|
||||||
rv = mLoadURIDelegate->HandleLoadError(aURI, aError,
|
rv = mLoadURIDelegate->HandleLoadError(aURI, aError,
|
||||||
NS_ERROR_GET_MODULE(aError),
|
NS_ERROR_GET_MODULE(aError),
|
||||||
&loadErrorHandled);
|
getter_AddRefs(errorPageURI));
|
||||||
if (NS_SUCCEEDED(rv) && loadErrorHandled) {
|
if (NS_FAILED(rv)) {
|
||||||
// The request has been handled, nothing to do here.
|
|
||||||
*aDisplayedErrorPage = false;
|
*aDisplayedErrorPage = false;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (errorPageURI) {
|
||||||
|
*aDisplayedErrorPage = NS_SUCCEEDED(LoadErrorPage(errorPageURI, aURI, aFailedChannel));
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorPage.AssignLiteral("neterror");
|
||||||
|
|
||||||
// Turn the error code into a human readable error message.
|
// Turn the error code into a human readable error message.
|
||||||
if (NS_ERROR_UNKNOWN_PROTOCOL == aError) {
|
if (NS_ERROR_UNKNOWN_PROTOCOL == aError) {
|
||||||
NS_ENSURE_ARG_POINTER(aURI);
|
NS_ENSURE_ARG_POINTER(aURI);
|
||||||
|
|
@ -4757,16 +4761,6 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
|
||||||
chanName.get()));
|
chanName.get()));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
mFailedChannel = aFailedChannel;
|
|
||||||
mFailedURI = aURI;
|
|
||||||
mFailedLoadType = mLoadType;
|
|
||||||
|
|
||||||
if (mLSHE) {
|
|
||||||
// Abandon mLSHE's BFCache entry and create a new one. This way, if
|
|
||||||
// we go back or forward to another SHEntry with the same doc
|
|
||||||
// identifier, the error page won't persist.
|
|
||||||
mLSHE->AbandonBFCacheEntry();
|
|
||||||
}
|
|
||||||
|
|
||||||
nsAutoCString url;
|
nsAutoCString url;
|
||||||
if (aURI) {
|
if (aURI) {
|
||||||
|
|
@ -4833,7 +4827,24 @@ nsDocShell::LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
|
||||||
nsresult rv = NS_NewURI(getter_AddRefs(errorPageURI), errorPageUrl);
|
nsresult rv = NS_NewURI(getter_AddRefs(errorPageURI), errorPageUrl);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
return InternalLoad(errorPageURI, nullptr, Nothing(), false, false, nullptr, RP_Unset,
|
return LoadErrorPage(errorPageURI, aURI, aFailedChannel);
|
||||||
|
}
|
||||||
|
|
||||||
|
nsresult
|
||||||
|
nsDocShell::LoadErrorPage(nsIURI* aErrorURI, nsIURI* aFailedURI, nsIChannel* aFailedChannel)
|
||||||
|
{
|
||||||
|
mFailedChannel = aFailedChannel;
|
||||||
|
mFailedURI = aFailedURI;
|
||||||
|
mFailedLoadType = mLoadType;
|
||||||
|
|
||||||
|
if (mLSHE) {
|
||||||
|
// Abandon mLSHE's BFCache entry and create a new one. This way, if
|
||||||
|
// we go back or forward to another SHEntry with the same doc
|
||||||
|
// identifier, the error page won't persist.
|
||||||
|
mLSHE->AbandonBFCacheEntry();
|
||||||
|
}
|
||||||
|
|
||||||
|
return InternalLoad(aErrorURI, nullptr, Nothing(), false, false, nullptr, RP_Unset,
|
||||||
nsContentUtils::GetSystemPrincipal(), nullptr,
|
nsContentUtils::GetSystemPrincipal(), nullptr,
|
||||||
INTERNAL_LOAD_FLAGS_NONE, EmptyString(),
|
INTERNAL_LOAD_FLAGS_NONE, EmptyString(),
|
||||||
nullptr, VoidString(), nullptr, nullptr,
|
nullptr, VoidString(), nullptr, nullptr,
|
||||||
|
|
@ -9526,7 +9537,7 @@ nsDocShell::InternalLoad(nsIURI* aURI,
|
||||||
const bool checkLoadDelegates = !(aFlags & INTERNAL_LOAD_FLAGS_DELEGATES_CHECKED);
|
const bool checkLoadDelegates = !(aFlags & INTERNAL_LOAD_FLAGS_DELEGATES_CHECKED);
|
||||||
aFlags = aFlags & ~INTERNAL_LOAD_FLAGS_DELEGATES_CHECKED;
|
aFlags = aFlags & ~INTERNAL_LOAD_FLAGS_DELEGATES_CHECKED;
|
||||||
|
|
||||||
if (aURI && mLoadURIDelegate && checkLoadDelegates &&
|
if (aURI && mLoadURIDelegate && checkLoadDelegates && aLoadType != LOAD_ERROR_PAGE &&
|
||||||
(!targetDocShell || targetDocShell == static_cast<nsIDocShell*>(this))) {
|
(!targetDocShell || targetDocShell == static_cast<nsIDocShell*>(this))) {
|
||||||
// Dispatch only load requests for the current or a new window to the
|
// Dispatch only load requests for the current or a new window to the
|
||||||
// delegate, e.g., to allow for GeckoView apps to handle the load event
|
// delegate, e.g., to allow for GeckoView apps to handle the load event
|
||||||
|
|
|
||||||
|
|
@ -590,12 +590,18 @@ private: // member functions
|
||||||
nsresult aResult);
|
nsresult aResult);
|
||||||
|
|
||||||
|
|
||||||
|
// Builds an error page URI (e.g. about:neterror?etc) for the given aURI
|
||||||
|
// and displays it via the LoadErrorPage() overload below.
|
||||||
nsresult LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
|
nsresult LoadErrorPage(nsIURI* aURI, const char16_t* aURL,
|
||||||
const char* aErrorPage,
|
const char* aErrorPage,
|
||||||
const char* aErrorType,
|
const char* aErrorType,
|
||||||
const char16_t* aDescription,
|
const char16_t* aDescription,
|
||||||
const char* aCSSClass,
|
const char* aCSSClass,
|
||||||
nsIChannel* aFailedChannel);
|
nsIChannel* aFailedChannel);
|
||||||
|
|
||||||
|
// This method directly loads aErrorURI as an error page. aFailedURI and aFailedChannel
|
||||||
|
// come from DisplayLoadError() or the LoadErrorPage() overload above.
|
||||||
|
nsresult LoadErrorPage(nsIURI* aErrorURI, nsIURI* aFailedURI, nsIChannel* aFailedChannel);
|
||||||
|
|
||||||
bool DisplayLoadError(nsresult aError, nsIURI* aURI, const char16_t* aURL,
|
bool DisplayLoadError(nsresult aError, nsIURI* aURI, const char16_t* aURL,
|
||||||
nsIChannel* aFailedChannel)
|
nsIChannel* aFailedChannel)
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ interface nsILoadURIDelegate : nsISupports
|
||||||
* @param aError The error code.
|
* @param aError The error code.
|
||||||
* @param aErrorModule The error module code.
|
* @param aErrorModule The error module code.
|
||||||
|
|
||||||
* Returns whether the page load error has been successfully handled.
|
* Returns an error page URL to load, or null to show the default error page.
|
||||||
|
* No error page is shown at all if an error is thrown.
|
||||||
*/
|
*/
|
||||||
boolean
|
nsIURI
|
||||||
handleLoadError(in nsIURI aURI, in nsresult aError, in short aErrorModule);
|
handleLoadError(in nsIURI aURI, in nsresult aError, in short aErrorModule);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue