зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1475073: Pass individual CORS errors as categories to web console error messages. r=baku
This commit is contained in:
Родитель
1de27c0297
Коммит
c1c9ee3d96
|
@ -3974,20 +3974,22 @@ HttpChannelChild::ActorDestroy(ActorDestroyReason aWhy)
|
|||
}
|
||||
|
||||
mozilla::ipc::IPCResult
|
||||
HttpChannelChild::RecvLogBlockedCORSRequest(const nsString& aMessage)
|
||||
HttpChannelChild::RecvLogBlockedCORSRequest(const nsString& aMessage,
|
||||
const nsCString& aCategory)
|
||||
{
|
||||
Unused << LogBlockedCORSRequest(aMessage);
|
||||
Unused << LogBlockedCORSRequest(aMessage, aCategory);
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
HttpChannelChild::LogBlockedCORSRequest(const nsAString & aMessage)
|
||||
HttpChannelChild::LogBlockedCORSRequest(const nsAString & aMessage,
|
||||
const nsACString& aCategory)
|
||||
{
|
||||
if (mLoadInfo) {
|
||||
uint64_t innerWindowID = mLoadInfo->GetInnerWindowID();
|
||||
bool privateBrowsing = !!mLoadInfo->GetOriginAttributes().mPrivateBrowsingId;
|
||||
nsCORSListenerProxy::LogBlockedCORSRequest(innerWindowID, privateBrowsing,
|
||||
aMessage);
|
||||
aMessage, aCategory);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -191,8 +191,8 @@ protected:
|
|||
// Get event target for processing network events.
|
||||
already_AddRefed<nsIEventTarget> GetNeckoTarget() override;
|
||||
|
||||
virtual mozilla::ipc::IPCResult RecvLogBlockedCORSRequest(const nsString& aMessage) override;
|
||||
NS_IMETHOD LogBlockedCORSRequest(const nsAString & aMessage) override;
|
||||
virtual mozilla::ipc::IPCResult RecvLogBlockedCORSRequest(const nsString& aMessage, const nsCString& aCategory) override;
|
||||
NS_IMETHOD LogBlockedCORSRequest(const nsAString & aMessage, const nsACString& aCategory) override;
|
||||
|
||||
private:
|
||||
// this section is for main-thread-only object
|
||||
|
|
|
@ -2354,10 +2354,12 @@ HttpChannelParent::DoSendSetPriority(int16_t aValue)
|
|||
}
|
||||
|
||||
nsresult
|
||||
HttpChannelParent::LogBlockedCORSRequest(const nsAString& aMessage)
|
||||
HttpChannelParent::LogBlockedCORSRequest(const nsAString& aMessage,
|
||||
const nsACString& aCategory)
|
||||
{
|
||||
if (mIPCClosed ||
|
||||
NS_WARN_IF(!SendLogBlockedCORSRequest(nsString(aMessage)))) {
|
||||
NS_WARN_IF(!SendLogBlockedCORSRequest(nsString(aMessage),
|
||||
nsCString(aCategory)))) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return NS_OK;
|
||||
|
|
|
@ -222,7 +222,7 @@ protected:
|
|||
MOZ_MUST_USE nsresult
|
||||
ReportSecurityMessage(const nsAString& aMessageTag,
|
||||
const nsAString& aMessageCategory) override;
|
||||
nsresult LogBlockedCORSRequest(const nsAString& aMessage) override;
|
||||
nsresult LogBlockedCORSRequest(const nsAString& aMessage, const nsACString& aCategory) override;
|
||||
|
||||
// Calls SendDeleteSelf and sets mIPCClosed to true because we should not
|
||||
// send any more messages after that. Bug 1274886
|
||||
|
|
|
@ -593,7 +593,8 @@ InterceptedHttpChannel::AsyncOpen2(nsIStreamListener* aListener)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
InterceptedHttpChannel::LogBlockedCORSRequest(const nsAString& aMessage)
|
||||
InterceptedHttpChannel::LogBlockedCORSRequest(const nsAString& aMessage,
|
||||
const nsACString& aCategory)
|
||||
{
|
||||
// Synthetic responses should not trigger CORS blocking.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
|
|
@ -168,7 +168,7 @@ public:
|
|||
AsyncOpen2(nsIStreamListener *aListener) override;
|
||||
|
||||
NS_IMETHOD
|
||||
LogBlockedCORSRequest(const nsAString & aMessage) override;
|
||||
LogBlockedCORSRequest(const nsAString & aMessage, const nsACString& aCategory) override;
|
||||
|
||||
NS_IMETHOD
|
||||
SetupFallbackChannel(const char * aFallbackKey) override;
|
||||
|
|
|
@ -906,7 +906,8 @@ NullHttpChannel::SetIsMainDocumentChannel(bool aValue)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
NullHttpChannel::LogBlockedCORSRequest(const nsAString& aMessage)
|
||||
NullHttpChannel::LogBlockedCORSRequest(const nsAString& aMessage,
|
||||
const nsACString& aCategory)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ child:
|
|||
// When CORS blocks the request in the parent process, it doesn't have the
|
||||
// correct window ID, so send the message to the child for logging to the web
|
||||
// console.
|
||||
async LogBlockedCORSRequest(nsString message);
|
||||
async LogBlockedCORSRequest(nsString message, nsCString category);
|
||||
|
||||
async AttachStreamFilter(Endpoint<PStreamFilterParent> aEndpoint);
|
||||
|
||||
|
|
|
@ -86,10 +86,11 @@ LogBlockedRequest(nsIRequest* aRequest,
|
|||
}
|
||||
|
||||
nsAutoString msg(blockedMessage.get());
|
||||
nsDependentCString category(aProperty);
|
||||
|
||||
if (XRE_IsParentProcess()) {
|
||||
if (aCreatingChannel) {
|
||||
rv = aCreatingChannel->LogBlockedCORSRequest(msg);
|
||||
rv = aCreatingChannel->LogBlockedCORSRequest(msg, category);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
return;
|
||||
}
|
||||
|
@ -105,10 +106,11 @@ LogBlockedRequest(nsIRequest* aRequest,
|
|||
privateBrowsing = nsContentUtils::IsInPrivateBrowsing(loadGroup);
|
||||
}
|
||||
|
||||
// log message ourselves
|
||||
// we are passing aProperty as the category so we can link to the
|
||||
// appropriate MDN docs depending on the specific error.
|
||||
uint64_t innerWindowID = nsContentUtils::GetInnerWindowID(aRequest);
|
||||
nsCORSListenerProxy::LogBlockedCORSRequest(innerWindowID, privateBrowsing,
|
||||
msg);
|
||||
msg, category);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
@ -1578,7 +1580,8 @@ nsCORSListenerProxy::StartCORSPreflight(nsIChannel* aRequestChannel,
|
|||
void
|
||||
nsCORSListenerProxy::LogBlockedCORSRequest(uint64_t aInnerWindowID,
|
||||
bool aPrivateBrowsing,
|
||||
const nsAString& aMessage)
|
||||
const nsAString& aMessage,
|
||||
const nsACString& aCategory)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
|
@ -1605,17 +1608,18 @@ nsCORSListenerProxy::LogBlockedCORSRequest(uint64_t aInnerWindowID,
|
|||
0, // lineNumber
|
||||
0, // columnNumber
|
||||
nsIScriptError::warningFlag,
|
||||
"CORS",
|
||||
aCategory,
|
||||
aInnerWindowID);
|
||||
}
|
||||
else {
|
||||
nsCString category = PromiseFlatCString(aCategory);
|
||||
rv = scriptError->Init(aMessage,
|
||||
EmptyString(), // sourceName
|
||||
EmptyString(), // sourceLine
|
||||
0, // lineNumber
|
||||
0, // columnNumber
|
||||
nsIScriptError::warningFlag,
|
||||
"CORS",
|
||||
category.get(),
|
||||
aPrivateBrowsing);
|
||||
}
|
||||
if (NS_FAILED(rv)) {
|
||||
|
|
|
@ -76,7 +76,8 @@ public:
|
|||
// browser console if no valid inner window ID is found.
|
||||
static void LogBlockedCORSRequest(uint64_t aInnerWindowID,
|
||||
bool aPrivateBrowsing,
|
||||
const nsAString& aMessage);
|
||||
const nsAString& aMessage,
|
||||
const nsACString& aCategory);
|
||||
private:
|
||||
// Only HttpChannelParent can call RemoveFromCorsPreflightCache
|
||||
friend class mozilla::net::HttpChannelParent;
|
||||
|
|
|
@ -426,10 +426,10 @@ nsHttpChannel::AddSecurityMessage(const nsAString& aMessageTag,
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHttpChannel::LogBlockedCORSRequest(const nsAString& aMessage)
|
||||
nsHttpChannel::LogBlockedCORSRequest(const nsAString& aMessage, const nsACString& aCategory)
|
||||
{
|
||||
if (mWarningReporter) {
|
||||
return mWarningReporter->LogBlockedCORSRequest(aMessage);
|
||||
return mWarningReporter->LogBlockedCORSRequest(aMessage, aCategory);
|
||||
}
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
virtual MOZ_MUST_USE nsresult
|
||||
ReportSecurityMessage(const nsAString& aMessageTag,
|
||||
const nsAString& aMessageCategory) = 0;
|
||||
virtual nsresult LogBlockedCORSRequest(const nsAString& aMessage) = 0;
|
||||
virtual nsresult LogBlockedCORSRequest(const nsAString& aMessage, const nsACString& aCategory) = 0;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -190,7 +190,7 @@ public:
|
|||
MOZ_MUST_USE nsresult
|
||||
AddSecurityMessage(const nsAString& aMessageTag,
|
||||
const nsAString& aMessageCategory) override;
|
||||
NS_IMETHOD LogBlockedCORSRequest(const nsAString& aMessage) override;
|
||||
NS_IMETHOD LogBlockedCORSRequest(const nsAString& aMessage, const nsACString& aCategory) override;
|
||||
|
||||
void SetWarningReporter(HttpChannelSecurityWarningReporter *aReporter);
|
||||
HttpChannelSecurityWarningReporter* GetWarningReporter();
|
||||
|
|
|
@ -508,6 +508,9 @@ interface nsIHttpChannel : nsIChannel
|
|||
*
|
||||
* @param aMessage
|
||||
* The message to print in the console.
|
||||
*
|
||||
* @param aCategory
|
||||
* The category under which the message should be displayed.
|
||||
*/
|
||||
void logBlockedCORSRequest(in AString aMessage);
|
||||
void logBlockedCORSRequest(in AString aMessage, in ACString aCategory);
|
||||
};
|
||||
|
|
|
@ -1134,11 +1134,12 @@ nsViewSourceChannel::SetAltDataForChild(bool aIsForChild)
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsViewSourceChannel::LogBlockedCORSRequest(const nsAString& aMessage)
|
||||
nsViewSourceChannel::LogBlockedCORSRequest(const nsAString& aMessage,
|
||||
const nsACString& aCategory)
|
||||
{
|
||||
if (!mHttpChannel) {
|
||||
NS_WARNING("nsViewSourceChannel::LogBlockedCORSRequest mHttpChannel is null");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return mHttpChannel->LogBlockedCORSRequest(aMessage);
|
||||
return mHttpChannel->LogBlockedCORSRequest(aMessage, aCategory);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче