Bug 1335678 - Revert patch for bug 1302566, r=ehsan

This commit is contained in:
Andrea Marchesini 2017-02-06 16:37:15 +01:00
parent 2618be0754
commit 869af55a16
4 changed files with 51 additions and 25 deletions

View file

@ -1797,8 +1797,7 @@ nsContentUtils::ParseLegacyFontSize(const nsAString& aValue)
bool bool
nsContentUtils::IsControlledByServiceWorker(nsIDocument* aDocument) nsContentUtils::IsControlledByServiceWorker(nsIDocument* aDocument)
{ {
if (aDocument && if (nsContentUtils::IsInPrivateBrowsing(aDocument)) {
aDocument->NodePrincipal()->OriginAttributesRef().mPrivateBrowsingId) {
return false; return false;
} }
@ -3202,6 +3201,40 @@ nsContentUtils::GetOriginAttributes(nsILoadGroup* aLoadGroup)
return attrs; return attrs;
} }
// static
bool
nsContentUtils::IsInPrivateBrowsing(nsIDocument* aDoc)
{
if (!aDoc) {
return false;
}
nsCOMPtr<nsILoadGroup> loadGroup = aDoc->GetDocumentLoadGroup();
if (loadGroup) {
return IsInPrivateBrowsing(loadGroup);
}
nsCOMPtr<nsIChannel> channel = aDoc->GetChannel();
return channel && NS_UsePrivateBrowsing(channel);
}
// static
bool
nsContentUtils::IsInPrivateBrowsing(nsILoadGroup* aLoadGroup)
{
if (!aLoadGroup) {
return false;
}
bool isPrivate = false;
nsCOMPtr<nsIInterfaceRequestor> callbacks;
aLoadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
if (callbacks) {
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
isPrivate = loadContext && loadContext->UsePrivateBrowsing();
}
return isPrivate;
}
bool bool
nsContentUtils::DocumentInactiveForImageLoads(nsIDocument* aDocument) nsContentUtils::DocumentInactiveForImageLoads(nsIDocument* aDocument)
{ {
@ -3221,26 +3254,9 @@ nsContentUtils::GetImgLoaderForDocument(nsIDocument* aDoc)
if (!aDoc) { if (!aDoc) {
return imgLoader::NormalLoader(); return imgLoader::NormalLoader();
} }
bool isPrivate = IsInPrivateBrowsing(aDoc);
nsCOMPtr<nsILoadGroup> loadGroup = aDoc->GetDocumentLoadGroup(); return isPrivate ? imgLoader::PrivateBrowsingLoader()
if (loadGroup) { : imgLoader::NormalLoader();
nsCOMPtr<nsIInterfaceRequestor> callbacks;
loadGroup->GetNotificationCallbacks(getter_AddRefs(callbacks));
if (callbacks) {
nsCOMPtr<nsILoadContext> loadContext = do_GetInterface(callbacks);
if (loadContext && loadContext->UsePrivateBrowsing()) {
return imgLoader::PrivateBrowsingLoader();
}
}
return imgLoader::NormalLoader();
}
nsCOMPtr<nsIChannel> channel = aDoc->GetChannel();
if (channel && NS_UsePrivateBrowsing(channel)) {
return imgLoader::PrivateBrowsingLoader();
}
return imgLoader::NormalLoader();
} }
// static // static
@ -8647,7 +8663,7 @@ nsContentUtils::InternalStorageAllowedForPrincipal(nsIPrincipal* aPrincipal,
} }
// Check if we are in private browsing, and record that fact // Check if we are in private browsing, and record that fact
if (document->NodePrincipal()->OriginAttributesRef().mPrivateBrowsingId) { if (IsInPrivateBrowsing(document)) {
access = StorageAccess::ePrivateBrowsing; access = StorageAccess::ePrivateBrowsing;
} }
} }

View file

@ -817,6 +817,16 @@ public:
static mozilla::OriginAttributes static mozilla::OriginAttributes
GetOriginAttributes(nsILoadGroup* aLoadGroup); GetOriginAttributes(nsILoadGroup* aLoadGroup);
/**
* Returns true if this document is in a Private Browsing window.
*/
static bool IsInPrivateBrowsing(nsIDocument* aDoc);
/**
* Returns true if this loadGroup uses Private Browsing.
*/
static bool IsInPrivateBrowsing(nsILoadGroup* aLoadGroup);
/** /**
* If aNode is not an element, return true exactly when aContent's binding * If aNode is not an element, return true exactly when aContent's binding
* parent is null. * parent is null.

View file

@ -49,7 +49,7 @@ ServiceWorkerContainer::IsEnabled(JSContext* aCx, JSObject* aGlobal)
} }
nsIDocument* doc = window->GetExtantDoc(); nsIDocument* doc = window->GetExtantDoc();
if (!doc || doc->NodePrincipal()->OriginAttributesRef().mPrivateBrowsingId) { if (!doc || nsContentUtils::IsInPrivateBrowsing(doc)) {
return false; return false;
} }

View file

@ -2561,7 +2561,7 @@ ServiceWorkerManager::IsControlled(nsIDocument* aDoc, ErrorResult& aRv)
{ {
MOZ_ASSERT(aDoc); MOZ_ASSERT(aDoc);
if (aDoc->NodePrincipal()->OriginAttributesRef().mPrivateBrowsingId) { if (nsContentUtils::IsInPrivateBrowsing(aDoc)) {
// Handle the case where a service worker was previously registered in // Handle the case where a service worker was previously registered in
// a non-private window (bug 1255621). // a non-private window (bug 1255621).
return false; return false;