mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 821877 - Log CSP errors to Web Console. r=bz
This commit is contained in:
parent
def2932c46
commit
fa7624ae06
@ -2361,6 +2361,24 @@ nsDocument::StartDocumentLoad(const char* aCommand, nsIChannel* aChannel,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
CSPErrorQueue::Add(const char* aMessageName)
|
||||
{
|
||||
mErrors.AppendElement(aMessageName);
|
||||
}
|
||||
|
||||
void
|
||||
CSPErrorQueue::Flush(nsIDocument* aDocument)
|
||||
{
|
||||
for (uint32_t i = 0; i < mErrors.Length(); i++) {
|
||||
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag,
|
||||
"CSP", aDocument,
|
||||
nsContentUtils::eDOM_PROPERTIES,
|
||||
mErrors[i]);
|
||||
}
|
||||
mErrors.Clear();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDocument::InitCSP(nsIChannel* aChannel)
|
||||
{
|
||||
@ -2519,6 +2537,9 @@ nsDocument::InitCSP(nsIChannel* aChannel)
|
||||
nsContentUtils::eDOM_PROPERTIES,
|
||||
"OldCSPHeaderDeprecated");
|
||||
|
||||
// Additionally log deprecated warning to Web Console.
|
||||
mCSPWebConsoleErrorQueue.Add("OldCSPHeaderDeprecated");
|
||||
|
||||
// Also, if the new headers AND the old headers were present, warn
|
||||
// that the old headers will be ignored.
|
||||
if (cspSpecCompliant) {
|
||||
@ -2526,6 +2547,8 @@ nsDocument::InitCSP(nsIChannel* aChannel)
|
||||
"CSP", this,
|
||||
nsContentUtils::eDOM_PROPERTIES,
|
||||
"BothCSPHeadersPresent");
|
||||
// Additionally log to Web Console.
|
||||
mCSPWebConsoleErrorQueue.Add("BothCSPHeadersPresent");
|
||||
}
|
||||
}
|
||||
|
||||
@ -2565,6 +2588,8 @@ nsDocument::InitCSP(nsIChannel* aChannel)
|
||||
"CSP", this,
|
||||
nsContentUtils::eDOM_PROPERTIES,
|
||||
"ReportOnlyCSPIgnored");
|
||||
// Additionally log to Web Console.
|
||||
mCSPWebConsoleErrorQueue.Add("ReportOnlyCSPIgnored");
|
||||
#ifdef PR_LOGGING
|
||||
PR_LOG(gCspPRLog, PR_LOG_DEBUG,
|
||||
("Skipped report-only CSP init for document %p because another, enforced policy is set", this));
|
||||
@ -4135,6 +4160,10 @@ nsDocument::SetScriptGlobalObject(nsIScriptGlobalObject *aScriptGlobalObject)
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mScriptGlobalObject);
|
||||
mWindow = window;
|
||||
|
||||
// Now that we know what our window is, we can flush the CSP errors to the
|
||||
// Web Console.
|
||||
FlushCSPWebConsoleErrorQueue();
|
||||
|
||||
// Set our visibility state, but do not fire the event. This is correct
|
||||
// because either we're coming out of bfcache (in which case IsVisible() will
|
||||
// still test false at this point and no state change will happen) or we're
|
||||
|
@ -463,6 +463,29 @@ protected:
|
||||
bool mHaveShutDown;
|
||||
};
|
||||
|
||||
class CSPErrorQueue
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Note this was designed to be passed string literals. If you give it
|
||||
* a dynamically allocated string, it is your responsibility to make sure
|
||||
* it never dies and is properly freed!
|
||||
*/
|
||||
void Add(const char* aMessageName);
|
||||
void Flush(nsIDocument* aDocument);
|
||||
|
||||
CSPErrorQueue()
|
||||
{
|
||||
}
|
||||
|
||||
~CSPErrorQueue()
|
||||
{
|
||||
}
|
||||
|
||||
private:
|
||||
nsAutoTArray<const char*,5> mErrors;
|
||||
};
|
||||
|
||||
// Base class for our document implementations.
|
||||
//
|
||||
// Note that this class *implements* nsIDOMXMLDocument, but it's not
|
||||
@ -1320,6 +1343,11 @@ private:
|
||||
nsresult CheckFrameOptions();
|
||||
nsresult InitCSP(nsIChannel* aChannel);
|
||||
|
||||
void FlushCSPWebConsoleErrorQueue()
|
||||
{
|
||||
mCSPWebConsoleErrorQueue.Flush(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the (non-anonymous) content in this document for aFrame. It will
|
||||
* be aFrame's content node if that content is in this document and not
|
||||
@ -1418,6 +1446,8 @@ private:
|
||||
nsrefcnt mStackRefCnt;
|
||||
bool mNeedsReleaseAfterStackRefCntRelease;
|
||||
|
||||
CSPErrorQueue mCSPWebConsoleErrorQueue;
|
||||
|
||||
#ifdef DEBUG
|
||||
protected:
|
||||
bool mWillReparent;
|
||||
|
Loading…
Reference in New Issue
Block a user