Bug 1561443 - Expose error code string to about:neterror with webidl. r=baku

Differential Revision: https://phabricator.services.mozilla.com/D45540

--HG--
extra : moz-landing-system : lando
This commit is contained in:
prathiksha 2019-09-17 07:51:57 +00:00
Родитель 40b8474578
Коммит 3e3db51f40
5 изменённых файлов: 91 добавлений и 0 удалений

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

@ -1380,6 +1380,64 @@ Document::Document(const char* aContentType)
mReferrerInfo = new dom::ReferrerInfo(nullptr);
}
bool Document::CallerIsTrustedAboutNetError(JSContext* aCx, JSObject* aObject) {
nsIPrincipal* principal = nsContentUtils::SubjectPrincipal(aCx);
if (NS_WARN_IF(!principal)) {
return false;
}
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_OK;
rv = principal->GetURI(getter_AddRefs(uri));
NS_ENSURE_SUCCESS(rv, false);
if (!uri) {
return false;
}
// getSpec is an expensive operation, hence we first check the scheme
// to see if the caller is actually an about: page.
if (!uri->SchemeIs("about")) {
return false;
}
nsAutoCString aboutSpec;
rv = uri->GetSpec(aboutSpec);
NS_ENSURE_SUCCESS(rv, false);
return StringBeginsWith(aboutSpec, NS_LITERAL_CSTRING("about:neterror"));
}
void Document::GetNetErrorInfo(mozilla::dom::NetErrorInfo& aInfo,
ErrorResult& aRv) {
nsCOMPtr<nsISupports> info;
nsCOMPtr<nsITransportSecurityInfo> tsi;
nsresult rv = NS_OK;
if (NS_WARN_IF(!mFailedChannel)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
rv = mFailedChannel->GetSecurityInfo(getter_AddRefs(info));
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(rv);
return;
}
tsi = do_QueryInterface(info);
if (NS_WARN_IF(!tsi)) {
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
return;
}
nsAutoString errorCodeString;
rv = tsi->GetErrorCodeString(errorCodeString);
if (NS_WARN_IF(NS_FAILED(rv))) {
aRv.Throw(rv);
return;
}
aInfo.mErrorCodeString.Assign(errorCodeString);
}
bool Document::CallerIsTrustedAboutCertError(JSContext* aCx,
JSObject* aObject) {
nsIPrincipal* principal = nsContentUtils::SubjectPrincipal(aCx);

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

@ -66,6 +66,7 @@
#include "mozilla/TimeStamp.h"
#include "mozilla/UniquePtr.h"
#include "mozilla/dom/FailedCertSecurityInfoBinding.h"
#include "mozilla/dom/NetErrorInfoBinding.h"
#include <bitset> // for member
// windows.h #defines CreateEvent
@ -2500,6 +2501,18 @@ class Document : public nsINode,
*/
nsIChannel* GetFailedChannel() const { return mFailedChannel; }
/**
* This function checks if the document that is trying to access
* GetNetErrorInfo is a trusted about net error page or not.
*/
static bool CallerIsTrustedAboutNetError(JSContext* aCx, JSObject* aObject);
/**
* Get security info like error code for a failed channel. This
* property is only exposed to about:neterror documents.
*/
void GetNetErrorInfo(mozilla::dom::NetErrorInfo& aInfo, ErrorResult& aRv);
/**
* This function checks if the document that is trying to access
* GetFailedCertSecurityInfo is a trusted cert error page or not.

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

@ -322,6 +322,11 @@ partial interface Document {
FailedCertSecurityInfo getFailedCertSecurityInfo();
};
partial interface Document {
[Func="Document::CallerIsTrustedAboutNetError", Throws]
NetErrorInfo getNetErrorInfo();
};
// https://w3c.github.io/page-visibility/#extensions-to-the-document-interface
partial interface Document {
readonly attribute boolean hidden;

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

@ -0,0 +1,14 @@
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/**
* This dictionary is used for exposing failed channel info
* to about:neterror to built UI.
*/
dictionary NetErrorInfo {
DOMString errorCodeString = "";
};

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

@ -686,6 +686,7 @@ WEBIDL_FILES = [
'NativeOSFileInternals.webidl',
'Navigator.webidl',
'NetDashboard.webidl',
'NetErrorInfo.webidl',
'NetworkInformation.webidl',
'NetworkOptions.webidl',
'NodeFilter.webidl',