Bug 1911759 - Add nsIIOService.originAttributesForNetworkState r=necko-reviewers,kershaw

Differential Revision: https://phabricator.services.mozilla.com/D209819
This commit is contained in:
Valentin Gosu
2024-08-07 09:16:19 +00:00
parent 314cc13a06
commit 14e970c5ba
2 changed files with 25 additions and 0 deletions

View File

@@ -168,6 +168,14 @@ interface nsIIOService : nsISupports
*/
nsIWebTransport newWebTransport();
/**
* Calls GetOriginAttributesForNetworkState
* see StoragePrincipalHelper.h
*/
[implicit_jscontext]
jsval originAttributesForNetworkState(in nsIChannel aChannel);
/**
* Returns true if networking is in "offline" mode. When in offline mode,
* attempts to access the network will fail (although this does not

View File

@@ -59,6 +59,7 @@
#include "mozilla/net/SocketProcessHost.h"
#include "mozilla/net/SocketProcessParent.h"
#include "mozilla/net/SSLTokensCache.h"
#include "mozilla/StoragePrincipalHelper.h"
#include "mozilla/Unused.h"
#include "nsContentSecurityManager.h"
#include "nsContentUtils.h"
@@ -1254,6 +1255,22 @@ nsIOService::NewWebTransport(nsIWebTransport** result) {
return NS_OK;
}
NS_IMETHODIMP
nsIOService::OriginAttributesForNetworkState(
nsIChannel* aChannel, JSContext* cx, JS::MutableHandle<JS::Value> _retval) {
OriginAttributes attrs;
if (!StoragePrincipalHelper::GetOriginAttributesForNetworkState(aChannel,
attrs)) {
return NS_ERROR_FAILURE;
}
if (NS_WARN_IF(!mozilla::dom::ToJSValue(cx, attrs, _retval))) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
bool nsIOService::IsLinkUp() {
InitializeNetworkLinkService();