Bug 1238177 - fix extension content needs to use the correct user context id origin attribute. r=sicking

(HEAD -> oa, refs/patches/oa/Bug_1238177)
Fixes Bug 1238177 -- extension content needs to use the correct user context id origin attribute
This commit is contained in:
Dave Huseby 2016-04-04 12:20:00 +02:00
Родитель f65ad0e5e1
Коммит c01e63f1a5
5 изменённых файлов: 12 добавлений и 28 удалений

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

@ -203,7 +203,7 @@ function run_test() {
// check that we can create an empty origin attributes dict with default
// members and values.
emptyAttrs = ChromeUtils.createDefaultOriginAttributes();
emptyAttrs = ChromeUtils.fillNonDefaultOriginAttributes({});
checkValues(emptyAttrs);
var uri = "http://example.org";
@ -226,7 +226,7 @@ function run_test() {
// check that we can create an origin attributes from a dict properly
tests.forEach(function(t) {
let attrs = ChromeUtils.createOriginAttributesFromDict(t[1]);
let attrs = ChromeUtils.fillNonDefaultOriginAttributes(t[1]);
checkValues(attrs, t[1]);
do_check_eq(ChromeUtils.originAttributesToSuffix(attrs), t[0]);
});

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

@ -70,13 +70,6 @@ ChromeUtils::OriginAttributesMatchPattern(dom::GlobalObject& aGlobal,
return pattern.Matches(attrs);
}
/* static */ void
ChromeUtils::CreateDefaultOriginAttributes(dom::GlobalObject& aGlobal,
dom::OriginAttributesDictionary& aAttrs)
{
aAttrs = GenericOriginAttributes();
}
/* static */ void
ChromeUtils::CreateOriginAttributesFromOrigin(dom::GlobalObject& aGlobal,
const nsAString& aOrigin,
@ -93,7 +86,7 @@ ChromeUtils::CreateOriginAttributesFromOrigin(dom::GlobalObject& aGlobal,
}
/* static */ void
ChromeUtils::CreateOriginAttributesFromDict(dom::GlobalObject& aGlobal,
ChromeUtils::FillNonDefaultOriginAttributes(dom::GlobalObject& aGlobal,
const dom::OriginAttributesDictionary& aAttrs,
dom::OriginAttributesDictionary& aNewAttrs)
{

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

@ -58,10 +58,6 @@ public:
const dom::OriginAttributesDictionary& aAttrs,
const dom::OriginAttributesPatternDictionary& aPattern);
static void
CreateDefaultOriginAttributes(dom::GlobalObject& aGlobal,
dom::OriginAttributesDictionary& aAttrs);
static void
CreateOriginAttributesFromOrigin(dom::GlobalObject& aGlobal,
const nsAString& aOrigin,
@ -69,7 +65,7 @@ public:
ErrorResult& aRv);
static void
CreateOriginAttributesFromDict(dom::GlobalObject& aGlobal,
FillNonDefaultOriginAttributes(dom::GlobalObject& aGlobal,
const dom::OriginAttributesDictionary& aAttrs,
dom::OriginAttributesDictionary& aNewAttrs);

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

@ -29,16 +29,6 @@ interface ChromeUtils : ThreadSafeChromeUtils {
originAttributesMatchPattern(optional OriginAttributesDictionary originAttrs,
optional OriginAttributesPatternDictionary pattern);
/**
* Returns an OriginAttributesDictionary with all default attributes added
* and assigned default values.
*
* @returns An OriginAttributesDictionary populated with the
* default attributes added and assigned default values.
*/
static OriginAttributesDictionary
createDefaultOriginAttributes();
/**
* Returns an OriginAttributesDictionary with values from the |origin| suffix
* and unspecified attributes added and assigned default values.
@ -62,7 +52,7 @@ interface ChromeUtils : ThreadSafeChromeUtils {
* default values.
*/
static OriginAttributesDictionary
createOriginAttributesFromDict(optional OriginAttributesDictionary originAttrs);
fillNonDefaultOriginAttributes(optional OriginAttributesDictionary originAttrs);
/**
* Returns true if the 2 OriginAttributes are equal.

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

@ -296,13 +296,18 @@ class ExtensionContext extends BaseContext {
let contentPrincipal = contentWindow.document.nodePrincipal;
let ssm = Services.scriptSecurityManager;
let extensionPrincipal = ssm.createCodebasePrincipal(this.extension.baseURI, {addonId: extensionId});
// copy origin attributes from the content window origin attributes to
// preserve the user context id. overwrite the addonId.
let attrs = contentPrincipal.originAttributes;
attrs.addonId = extensionId;
let extensionPrincipal = ssm.createCodebasePrincipal(this.extension.baseURI, attrs);
Object.defineProperty(this, "principal",
{value: extensionPrincipal, enumerable: true, configurable: true});
if (ssm.isSystemPrincipal(contentPrincipal)) {
// Make sure we don't hand out the system principal by accident.
prin = Cc["@mozilla.org/nullprincipal;1"].createInstance(Ci.nsIPrincipal);
// also make sure that the null principal has the right origin attributes
prin = ssm.createNullPrincipal(attrs);
} else {
prin = [contentPrincipal, extensionPrincipal];
}