Bug 1599046 - P4. Report content blocking log to console while running in the parent process r=Ehsan

Depends on D57630

Differential Revision: https://phabricator.services.mozilla.com/D57807

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Dimi Lee 2020-01-27 19:23:05 +00:00
Родитель d58587be36
Коммит 3f336cb71f
2 изменённых файлов: 62 добавлений и 14 удалений

Просмотреть файл

@ -215,6 +215,11 @@ nsresult UrlClassifierCommon::SetBlockedContent(nsIChannel* channel,
return NS_OK;
}
// TODO: ReportToConsole is called in the child process,
// If nsContentUtils::ReportToConsole is not fission compatiable(cannot report
// to correct top-level window), we need to do this in the parent process
// instead (find the top-level window in the parent and send an IPC to child
// processes to report console).
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil = services::GetThirdPartyUtil();
if (NS_WARN_IF(!thirdPartyUtil)) {
return NS_OK;

Просмотреть файл

@ -378,9 +378,10 @@ void RunConsoleReportingRunnable(already_AddRefed<nsIRunnable>&& aRunnable) {
}
}
void ReportBlockingToConsole(nsPIDOMWindowOuter* aWindow, nsIURI* aURI,
void ReportBlockingToConsole(uint64_t aWindowID, nsIURI* aURI,
uint32_t aRejectedReason) {
MOZ_ASSERT(aWindow && aURI);
MOZ_ASSERT(aWindowID);
MOZ_ASSERT(aURI);
MOZ_ASSERT(
aRejectedReason == 0 ||
aRejectedReason ==
@ -394,11 +395,6 @@ void ReportBlockingToConsole(nsPIDOMWindowOuter* aWindow, nsIURI* aURI,
aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_ALL ||
aRejectedReason == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN);
RefPtr<Document> doc = aWindow->GetExtantDoc();
if (NS_WARN_IF(!doc)) {
return;
}
nsAutoString sourceLine;
uint32_t lineNumber = 0, columnNumber = 0;
JSContext* cx = nsContentUtils::GetCurrentJSContext();
@ -409,8 +405,8 @@ void ReportBlockingToConsole(nsPIDOMWindowOuter* aWindow, nsIURI* aURI,
nsCOMPtr<nsIURI> uri(aURI);
RefPtr<Runnable> runnable = NS_NewRunnableFunction(
"ReportBlockingToConsoleDelayed",
[doc, sourceLine, lineNumber, columnNumber, uri, aRejectedReason]() {
"ReportBlockingToConsoleDelayed", [aWindowID, sourceLine, lineNumber,
columnNumber, uri, aRejectedReason]() {
const char* message = nullptr;
nsAutoCString category;
// When changing this list, please make sure to update the corresponding
@ -455,15 +451,60 @@ void ReportBlockingToConsole(nsPIDOMWindowOuter* aWindow, nsIURI* aURI,
CopyUTF8toUTF16(exposableURI->GetSpecOrDefault(),
*params.AppendElement());
nsContentUtils::ReportToConsole(nsIScriptError::warningFlag, category,
doc, nsContentUtils::eNECKO_PROPERTIES,
message, params, nullptr, sourceLine,
lineNumber, columnNumber);
nsAutoString errorText;
rv = nsContentUtils::FormatLocalizedString(
nsContentUtils::eNECKO_PROPERTIES, message, params, errorText);
NS_ENSURE_SUCCESS_VOID(rv);
nsContentUtils::ReportToConsoleByWindowID(
errorText, nsIScriptError::warningFlag, category, aWindowID,
nullptr, sourceLine, lineNumber, columnNumber);
});
RunConsoleReportingRunnable(runnable.forget());
}
void ReportBlockingToConsole(nsIChannel* aChannel, nsIURI* aURI,
uint32_t aRejectedReason) {
MOZ_ASSERT(aChannel && aURI);
uint64_t windowID;
if (XRE_IsParentProcess()) {
// Get the top-level window ID from the top-level BrowsingContext
nsCOMPtr<nsILoadInfo> loadInfo = aChannel->LoadInfo();
RefPtr<dom::BrowsingContext> bc;
loadInfo->GetBrowsingContext(getter_AddRefs(bc));
if (!bc || bc->IsDiscarded()) {
return;
}
bc = bc->Top();
RefPtr<dom::WindowGlobalParent> wgp =
bc->Canonical()->GetCurrentWindowGlobal();
if (!wgp) {
return;
}
windowID = wgp->InnerWindowId();
} else {
nsresult rv;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(aChannel, &rv);
if (!httpChannel) {
return;
}
rv = httpChannel->GetTopLevelContentWindowId(&windowID);
if (NS_FAILED(rv) || !windowID) {
windowID = nsContentUtils::GetInnerWindowID(httpChannel);
}
}
ReportBlockingToConsole(windowID, aURI, aRejectedReason);
}
void ReportUnblockingToConsole(
nsPIDOMWindowInner* aWindow, const nsAString& aTrackingOrigin,
AntiTrackingCommon::StorageAccessGrantedReason aReason) {
@ -902,7 +943,7 @@ void NotifyBlockingDecisionInternal(
aTrackingChannel, true,
aRejectedReason, aURI);
ReportBlockingToConsole(aWindow, aURI, aRejectedReason);
ReportBlockingToConsole(aReportingChannel, aURI, aRejectedReason);
}
NotifyAllowDecisionInternal(aReportingChannel, aTrackingChannel, aURI,
@ -920,6 +961,8 @@ void NotifyBlockingDecisionInternal(
AntiTrackingCommon::NotifyContentBlockingEvent(nullptr, aReportingChannel,
aTrackingChannel, true,
aRejectedReason, aURI);
ReportBlockingToConsole(aReportingChannel, aURI, aRejectedReason);
}
NotifyAllowDecisionInternal(aReportingChannel, aTrackingChannel, aURI,