mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1460940 - Convert nsIPrincipal to use nsIDocument. r=bz
MozReview-Commit-ID: z1TGWtS1KG --HG-- extra : rebase_source : e5291c40eb017c1e3fd69333ac108dda852fb8cd
This commit is contained in:
parent
b3a78c6c93
commit
074d88de5a
@ -189,7 +189,7 @@ BasePrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BasePrincipal::EnsureCSP(nsIDOMDocument* aDocument,
|
||||
BasePrincipal::EnsureCSP(nsIDocument* aDocument,
|
||||
nsIContentSecurityPolicy** aCSP)
|
||||
{
|
||||
if (mCSP) {
|
||||
@ -219,7 +219,7 @@ BasePrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
BasePrincipal::EnsurePreloadCSP(nsIDOMDocument* aDocument,
|
||||
BasePrincipal::EnsurePreloadCSP(nsIDocument* aDocument,
|
||||
nsIContentSecurityPolicy** aPreloadCSP)
|
||||
{
|
||||
if (mPreloadCSP) {
|
||||
|
@ -71,9 +71,9 @@ public:
|
||||
NS_IMETHOD GetAddonPolicy(nsISupports** aResult) final;
|
||||
NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp) override;
|
||||
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp) override;
|
||||
NS_IMETHOD EnsureCSP(nsIDOMDocument* aDocument, nsIContentSecurityPolicy** aCSP) override;
|
||||
NS_IMETHOD EnsureCSP(nsIDocument* aDocument, nsIContentSecurityPolicy** aCSP) override;
|
||||
NS_IMETHOD GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP) override;
|
||||
NS_IMETHOD EnsurePreloadCSP(nsIDOMDocument* aDocument, nsIContentSecurityPolicy** aCSP) override;
|
||||
NS_IMETHOD EnsurePreloadCSP(nsIDocument* aDocument, nsIContentSecurityPolicy** aCSP) override;
|
||||
NS_IMETHOD GetCspJSON(nsAString& outCSPinJSON) override;
|
||||
NS_IMETHOD GetIsNullPrincipal(bool* aResult) override;
|
||||
NS_IMETHOD GetIsCodebasePrincipal(bool* aResult) override;
|
||||
|
@ -81,7 +81,7 @@ SystemPrincipal::SetCsp(nsIContentSecurityPolicy* aCsp)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SystemPrincipal::EnsureCSP(nsIDOMDocument* aDocument,
|
||||
SystemPrincipal::EnsureCSP(nsIDocument* aDocument,
|
||||
nsIContentSecurityPolicy** aCSP)
|
||||
{
|
||||
// CSP on a system principal makes no sense
|
||||
@ -96,7 +96,7 @@ SystemPrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP)
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
SystemPrincipal::EnsurePreloadCSP(nsIDOMDocument* aDocument,
|
||||
SystemPrincipal::EnsurePreloadCSP(nsIDocument* aDocument,
|
||||
nsIContentSecurityPolicy** aPreloadCSP)
|
||||
{
|
||||
// CSP on a system principal makes no sense
|
||||
|
@ -40,9 +40,9 @@ public:
|
||||
NS_IMETHOD SetDomain(nsIURI* aDomain) override;
|
||||
NS_IMETHOD GetCsp(nsIContentSecurityPolicy** aCsp) override;
|
||||
NS_IMETHOD SetCsp(nsIContentSecurityPolicy* aCsp) override;
|
||||
NS_IMETHOD EnsureCSP(nsIDOMDocument* aDocument, nsIContentSecurityPolicy** aCSP) override;
|
||||
NS_IMETHOD EnsureCSP(nsIDocument* aDocument, nsIContentSecurityPolicy** aCSP) override;
|
||||
NS_IMETHOD GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP) override;
|
||||
NS_IMETHOD EnsurePreloadCSP(nsIDOMDocument* aDocument, nsIContentSecurityPolicy** aCSP) override;
|
||||
NS_IMETHOD EnsurePreloadCSP(nsIDocument* aDocument, nsIContentSecurityPolicy** aCSP) override;
|
||||
NS_IMETHOD GetBaseDomain(nsACString& aBaseDomain) override;
|
||||
NS_IMETHOD GetAddonId(nsAString& aAddonId) override;
|
||||
|
||||
|
@ -38,7 +38,8 @@ class OriginAttributes;
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIContentSecurityPolicy;
|
||||
interface nsIDOMDocument;
|
||||
|
||||
webidl Document;
|
||||
|
||||
[ptr] native JSContext(JSContext);
|
||||
[ptr] native JSPrincipals(JSPrincipals);
|
||||
@ -165,7 +166,7 @@ interface nsIPrincipal : nsISerializable
|
||||
* Please note if aDocument is null, then setRequestContext on the
|
||||
* CSP object is called using the current principal.
|
||||
*/
|
||||
[noscript] nsIContentSecurityPolicy ensureCSP(in nsIDOMDocument aDocument);
|
||||
[noscript] nsIContentSecurityPolicy ensureCSP(in Document aDocument);
|
||||
|
||||
/**
|
||||
* A speculative Content Security Policy associated with this
|
||||
@ -186,7 +187,7 @@ interface nsIPrincipal : nsISerializable
|
||||
* Please note if aDocument is null, then setRequestContext on the
|
||||
* speculative CSP object is called using the current principal.
|
||||
*/
|
||||
[noscript] nsIContentSecurityPolicy ensurePreloadCSP(in nsIDOMDocument aDocument);
|
||||
[noscript] nsIContentSecurityPolicy ensurePreloadCSP(in Document aDocument);
|
||||
|
||||
/**
|
||||
* The CSP of the principal in JSON notation.
|
||||
|
@ -108,8 +108,7 @@ HTMLMetaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
||||
|
||||
nsIPrincipal* principal = aDocument->NodePrincipal();
|
||||
nsCOMPtr<nsIContentSecurityPolicy> csp;
|
||||
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(aDocument);
|
||||
principal->EnsureCSP(domDoc, getter_AddRefs(csp));
|
||||
principal->EnsureCSP(aDocument, getter_AddRefs(csp));
|
||||
if (csp) {
|
||||
if (LOG_ENABLED()) {
|
||||
nsAutoCString documentURIspec;
|
||||
|
@ -7,10 +7,11 @@
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIDocShell;
|
||||
interface nsIDOMDocument;
|
||||
interface nsIEventTarget;
|
||||
interface nsIPrincipal;
|
||||
|
||||
webidl Document;
|
||||
|
||||
/**
|
||||
* nsIContentSecurityPolicy
|
||||
* Describes an XPCOM component used to model and enforce CSPs. Instances of
|
||||
@ -207,7 +208,7 @@ interface nsIContentSecurityPolicy : nsISerializable
|
||||
* * aDocument (preferred), or if no document is available, then provide
|
||||
* * aPrincipal
|
||||
*/
|
||||
void setRequestContext(in nsIDOMDocument aDocument,
|
||||
void setRequestContext(in Document aDocument,
|
||||
in nsIPrincipal aPrincipal);
|
||||
|
||||
/**
|
||||
|
@ -18,7 +18,7 @@
|
||||
#include "nsIClassInfoImpl.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMNode.h"
|
||||
#include "nsIHttpChannel.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
@ -689,29 +689,28 @@ nsCSPContext::LogViolationDetails(uint16_t aViolationType,
|
||||
#undef CASE_CHECK_AND_REPORT
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCSPContext::SetRequestContext(nsIDOMDocument* aDOMDocument,
|
||||
nsCSPContext::SetRequestContext(nsIDocument* aDocument,
|
||||
nsIPrincipal* aPrincipal)
|
||||
{
|
||||
MOZ_ASSERT(aDOMDocument || aPrincipal,
|
||||
MOZ_ASSERT(aDocument || aPrincipal,
|
||||
"Can't set context without doc or principal");
|
||||
NS_ENSURE_ARG(aDOMDocument || aPrincipal);
|
||||
NS_ENSURE_ARG(aDocument || aPrincipal);
|
||||
|
||||
if (aDOMDocument) {
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDOMDocument);
|
||||
mLoadingContext = do_GetWeakReference(doc);
|
||||
mSelfURI = doc->GetDocumentURI();
|
||||
mLoadingPrincipal = doc->NodePrincipal();
|
||||
doc->GetReferrer(mReferrer);
|
||||
mInnerWindowID = doc->InnerWindowID();
|
||||
if (aDocument) {
|
||||
mLoadingContext = do_GetWeakReference(aDocument);
|
||||
mSelfURI = aDocument->GetDocumentURI();
|
||||
mLoadingPrincipal = aDocument->NodePrincipal();
|
||||
aDocument->GetReferrer(mReferrer);
|
||||
mInnerWindowID = aDocument->InnerWindowID();
|
||||
// the innerWindowID is not available for CSPs delivered through the
|
||||
// header at the time setReqeustContext is called - let's queue up
|
||||
// console messages until it becomes available, see flushConsoleMessages
|
||||
mQueueUpMessages = !mInnerWindowID;
|
||||
mCallingChannelLoadGroup = doc->GetDocumentLoadGroup();
|
||||
mCallingChannelLoadGroup = aDocument->GetDocumentLoadGroup();
|
||||
|
||||
// set the flag on the document for CSP telemetry
|
||||
doc->SetHasCSP(true);
|
||||
mEventTarget = doc->EventTargetFor(TaskCategory::Other);
|
||||
aDocument->SetHasCSP(true);
|
||||
mEventTarget = aDocument->EventTargetFor(TaskCategory::Other);
|
||||
}
|
||||
else {
|
||||
CSPCONTEXTLOG(("No Document in SetRequestContext; can not query loadgroup; sending reports may fail."));
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "nsHtml5TreeOpExecutor.h"
|
||||
#include "nsIContentSecurityPolicy.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocShellTreeItem.h"
|
||||
#include "nsIHTMLDocument.h"
|
||||
@ -1144,8 +1143,7 @@ nsHtml5TreeOpExecutor::AddSpeculationCSP(const nsAString& aCSP)
|
||||
|
||||
nsIPrincipal* principal = mDocument->NodePrincipal();
|
||||
nsCOMPtr<nsIContentSecurityPolicy> preloadCsp;
|
||||
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(mDocument);
|
||||
nsresult rv = principal->EnsurePreloadCSP(domDoc, getter_AddRefs(preloadCsp));
|
||||
nsresult rv = principal->EnsurePreloadCSP(mDocument, getter_AddRefs(preloadCsp));
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
||||
// please note that meta CSPs and CSPs delivered through a header need
|
||||
|
Loading…
Reference in New Issue
Block a user