From b815db526b317014e1da65ea28516c587a6a9d14 Mon Sep 17 00:00:00 2001 From: Dave Huseby Date: Sat, 26 Mar 2016 15:07:00 +0100 Subject: [PATCH] Bug 1233885 - fix up docInfo and permission manager to use default user context. r=sicking (HEAD -> oa, refs/patches/oa/Bug_1233885) fix up docInfo and permission manager to use default user context --- browser/base/content/content.js | 1 + browser/base/content/pageinfo/pageInfo.js | 3 ++- browser/base/content/pageinfo/permissions.js | 15 +++++---------- extensions/cookie/nsPermissionManager.cpp | 13 +++++++++++-- netwerk/base/nsIPermission.idl | 2 +- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/browser/base/content/content.js b/browser/base/content/content.js index a6b5f30879bc..ff23c9034e30 100644 --- a/browser/base/content/content.js +++ b/browser/base/content/content.js @@ -1019,6 +1019,7 @@ var PageInfoListener = { docInfo.contentType = document.contentType; docInfo.characterSet = document.characterSet; docInfo.lastModified = document.lastModified; + docInfo.principal = document.nodePrincipal; let documentURIObject = {}; documentURIObject.spec = document.documentURIObject.spec; diff --git a/browser/base/content/pageinfo/pageInfo.js b/browser/base/content/pageinfo/pageInfo.js index 096d3c66251e..595ff5dff117 100644 --- a/browser/base/content/pageinfo/pageInfo.js +++ b/browser/base/content/pageinfo/pageInfo.js @@ -375,6 +375,7 @@ function loadPageInfo(frameOuterWindowID, imageElement) let windowInfo = pageInfoData.windowInfo; let uri = makeURI(docInfo.documentURIObject.spec, docInfo.documentURIObject.originCharset); + let principal = docInfo.principal; gDocInfo = docInfo; gImageElement = pageInfoData.imageInfo; @@ -387,7 +388,7 @@ function loadPageInfo(frameOuterWindowID, imageElement) makeGeneralTab(pageInfoData.metaViewRows, docInfo); initFeedTab(pageInfoData.feeds); - onLoadPermission(uri); + onLoadPermission(uri, principal); securityOnLoad(uri, windowInfo); }); diff --git a/browser/base/content/pageinfo/permissions.js b/browser/base/content/pageinfo/permissions.js index 392feea1f512..532a26431929 100644 --- a/browser/base/content/pageinfo/permissions.js +++ b/browser/base/content/pageinfo/permissions.js @@ -8,6 +8,7 @@ Components.utils.import("resource://gre/modules/BrowserUtils.jsm"); const nsIQuotaManagerService = Components.interfaces.nsIQuotaManagerService; var gPermURI; +var gPermPrincipal; var gUsageRequest; var gPermissions = SitePermissions.listPermissions(); @@ -28,11 +29,12 @@ var permissionObserver = { } }; -function onLoadPermission(uri) +function onLoadPermission(uri, principal) { var permTab = document.getElementById("permTab"); if (SitePermissions.isSupportedURI(uri)) { gPermURI = uri; + gPermPrincipal = principal; var hostText = document.getElementById("hostText"); hostText.value = gPermURI.prePath; @@ -189,11 +191,8 @@ function initIndexedDBRow() var quotaManagerService = Components.classes["@mozilla.org/dom/quota-manager-service;1"] .getService(nsIQuotaManagerService); - let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"] - .getService(Components.interfaces.nsIScriptSecurityManager) - .createCodebasePrincipal(gPermURI, {}); gUsageRequest = - quotaManagerService.getUsageForPrincipal(principal, + quotaManagerService.getUsageForPrincipal(gPermPrincipal, onIndexedDBUsageCallback); var status = document.getElementById("indexedDBStatus"); @@ -206,13 +205,9 @@ function initIndexedDBRow() function onIndexedDBClear() { - let principal = Components.classes["@mozilla.org/scriptsecuritymanager;1"] - .getService(Components.interfaces.nsIScriptSecurityManager) - .createCodebasePrincipal(gPermURI, {}); - Components.classes["@mozilla.org/dom/quota-manager-service;1"] .getService(nsIQuotaManagerService) - .clearStoragesForPrincipal(principal); + .clearStoragesForPrincipal(gPermPrincipal); Components.classes["@mozilla.org/serviceworkers/manager;1"] .getService(Components.interfaces.nsIServiceWorkerManager) diff --git a/extensions/cookie/nsPermissionManager.cpp b/extensions/cookie/nsPermissionManager.cpp index e158deb7beb1..ce6b585211ef 100644 --- a/extensions/cookie/nsPermissionManager.cpp +++ b/extensions/cookie/nsPermissionManager.cpp @@ -112,6 +112,9 @@ GetPrincipalFromOrigin(const nsACString& aOrigin, nsIPrincipal** aPrincipal) return NS_ERROR_FAILURE; } + // set to default to disable user context isolation for permissions + attrs.mUserContextId = nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID; + nsCOMPtr uri; nsresult rv = NS_NewURI(getter_AddRefs(uri), originNoSuffix); NS_ENSURE_SUCCESS(rv, rv); @@ -2165,8 +2168,14 @@ nsPermissionManager::GetPermissionHashKey(nsIPrincipal* aPrincipal, } // Copy the attributes over - mozilla::PrincipalOriginAttributes attrs = mozilla::BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(); - nsCOMPtr principal = mozilla::BasePrincipal::CreateCodebasePrincipal(newURI, attrs); + mozilla::PrincipalOriginAttributes attrs = + mozilla::BasePrincipal::Cast(aPrincipal)->OriginAttributesRef(); + + // ensure that the user context isolation is disabled + attrs.mUserContextId = nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID; + + nsCOMPtr principal = + mozilla::BasePrincipal::CreateCodebasePrincipal(newURI, attrs); return GetPermissionHashKey(principal, aType, aExactHostMatch); } diff --git a/netwerk/base/nsIPermission.idl b/netwerk/base/nsIPermission.idl index 1e8a41b76c10..c5ddd90fe5ef 100644 --- a/netwerk/base/nsIPermission.idl +++ b/netwerk/base/nsIPermission.idl @@ -64,7 +64,7 @@ interface nsIPermission : nsISupports /** * Test whether a URI would be affected by this permission. - * This performs a matches with a NO_APP_ID identifier. + * NOTE: This performs matches with default origin attribute values. * * @param uri the uri to test * @param exactHost If true, only the specific host will be matched,