Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Bug 1238177 - fix extension content needs to use the correct user con…
Browse files Browse the repository at this point in the history
…text 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
  • Loading branch information
Dave Huseby committed Apr 4, 2016
1 parent f65ad0e commit c01e63f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 28 deletions.
4 changes: 2 additions & 2 deletions caps/tests/unit/test_origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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]);
});
Expand Down
9 changes: 1 addition & 8 deletions dom/base/ChromeUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
{
Expand Down
6 changes: 1 addition & 5 deletions dom/base/ChromeUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,14 @@ class ChromeUtils : public ThreadSafeChromeUtils
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,
dom::OriginAttributesDictionary& aAttrs,
ErrorResult& aRv);

static void
CreateOriginAttributesFromDict(dom::GlobalObject& aGlobal,
FillNonDefaultOriginAttributes(dom::GlobalObject& aGlobal,
const dom::OriginAttributesDictionary& aAttrs,
dom::OriginAttributesDictionary& aNewAttrs);

Expand Down
12 changes: 1 addition & 11 deletions dom/webidl/ChromeUtils.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
9 changes: 7 additions & 2 deletions toolkit/components/extensions/ExtensionContent.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down

0 comments on commit c01e63f

Please sign in to comment.