Skip to content

Instantly share code, notes, and snippets.

@wanderview
Created June 25, 2018 14:21
Show Gist options
  • Save wanderview/d8ced28231bd4fd9519ff76435fabb21 to your computer and use it in GitHub Desktop.
Save wanderview/d8ced28231bd4fd9519ff76435fabb21 to your computer and use it in GitHub Desktop.
firefox CSP impl gist
//
// nsILoadInfo.idl
//
interface nsILoadInfo
{
// CSP data that was parsed from the LoadInfo's channel. This is purely
// for communicating the value back to the client that triggered the
// load. This should only be set for non-subresource loads. This
// should not be used for enforcing CSP on subresource loads. Instead
// use GetClientInfo() and the CSP value there.
attribute parsedCSP;
};
//
// ClientSource.cpp
//
void
ClientSource::SetParsedCSP(const nsACString& aParsedCSP)
{
mClientInfo.SetCSP(aParsedCSP);
}
//
// nsGlobalWindowInner.cpp
//
void
nsGlobalWindowInner::EnsureClientSource()
{
nsCString parsedCSP;
Unused << loadInfo->GetParsedCSP(parsedCSP);
if (!parsedCSP.IsEmpty()) {
mClientSource->SetParsedCSP(parsedCSP);
}
}
//
// WorkerPrivate.cpp
//
// You need to get the parsed CSP value to the worker thread and call
// ClientSource::SetParsedCSP there. Look at how SetController() is
// called.
//
// ClientInfo.cpp
//
void
ClientInfo::SetCSP(const nsACString& aCSP)
{
mData->csp() = aCSP;
}
const nsCString&
ClientInfo::GetCSP() const
{
return mData->csp();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment