mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1182347 - Implement OriginAttributesPattern. r=sicking,f=allstars.chh
This commit is contained in:
parent
bd0df6e67e
commit
087490dde5
@ -56,6 +56,39 @@ public:
|
||||
nsACString& aOriginNoSuffix);
|
||||
};
|
||||
|
||||
class OriginAttributesPattern : public dom::OriginAttributesPatternDictionary
|
||||
{
|
||||
public:
|
||||
// To convert a JSON string to an OriginAttributesPattern, do the following:
|
||||
//
|
||||
// OriginAttributesPattern pattern;
|
||||
// if (!pattern.Init(aJSONString)) {
|
||||
// ... // handle failure.
|
||||
// }
|
||||
OriginAttributesPattern() {}
|
||||
|
||||
explicit OriginAttributesPattern(const OriginAttributesPatternDictionary& aOther)
|
||||
: OriginAttributesPatternDictionary(aOther) {}
|
||||
|
||||
// Performs a match of |aAttrs| against this pattern.
|
||||
bool Matches(const OriginAttributes& aAttrs) const
|
||||
{
|
||||
if (mAppId.WasPassed() && mAppId.Value() != aAttrs.mAppId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mInBrowser.WasPassed() && mInBrowser.Value() != aAttrs.mInBrowser) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mAddonId.WasPassed() && mAddonId.Value() != aAttrs.mAddonId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Base class from which all nsIPrincipal implementations inherit. Use this for
|
||||
* default implementations and other commonalities between principal
|
||||
|
@ -29,5 +29,15 @@ ChromeUtils::OriginAttributesToSuffix(dom::GlobalObject& aGlobal,
|
||||
attrs.CreateSuffix(aSuffix);
|
||||
}
|
||||
|
||||
/* static */ bool
|
||||
ChromeUtils::OriginAttributesMatchPattern(dom::GlobalObject& aGlobal,
|
||||
const dom::OriginAttributesDictionary& aAttrs,
|
||||
const dom::OriginAttributesPatternDictionary& aPattern)
|
||||
{
|
||||
OriginAttributes attrs(aAttrs);
|
||||
OriginAttributesPattern pattern(aPattern);
|
||||
return pattern.Matches(attrs);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
@ -49,6 +49,11 @@ public:
|
||||
OriginAttributesToSuffix(dom::GlobalObject& aGlobal,
|
||||
const dom::OriginAttributesDictionary& aAttrs,
|
||||
nsCString& aSuffix);
|
||||
|
||||
static bool
|
||||
OriginAttributesMatchPattern(dom::GlobalObject& aGlobal,
|
||||
const dom::OriginAttributesDictionary& aAttrs,
|
||||
const dom::OriginAttributesPatternDictionary& aPattern);
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -26,19 +26,40 @@ interface ChromeUtils : ThreadSafeChromeUtils {
|
||||
*/
|
||||
static ByteString
|
||||
originAttributesToSuffix(optional OriginAttributesDictionary originAttrs);
|
||||
|
||||
/**
|
||||
* Returns true if the members of |originAttrs| match the provided members
|
||||
* of |pattern|.
|
||||
*
|
||||
* @param originAttrs The originAttributes under consideration.
|
||||
* @param pattern The pattern to use for matching.
|
||||
*/
|
||||
static boolean
|
||||
originAttributesMatchPattern(optional OriginAttributesDictionary originAttrs,
|
||||
optional OriginAttributesPatternDictionary pattern);
|
||||
};
|
||||
|
||||
/**
|
||||
* Used by principals and the script security manager to represent origin
|
||||
* attributes.
|
||||
* attributes. The first dictionary is designed to contain the full set of
|
||||
* OriginAttributes, the second is used for pattern-matching (i.e. does this
|
||||
* OriginAttributesDictionary match the non-empty attributes in this pattern).
|
||||
*
|
||||
* IMPORTANT: If you add any members here, you need to update the
|
||||
* methods on mozilla::OriginAttributes, and bump the CIDs of all
|
||||
* the principal implementations that use OriginAttributes in their
|
||||
* nsISerializable implementations.
|
||||
* IMPORTANT: If you add any members here, you need to do the following:
|
||||
* (1) Add them to both dictionaries.
|
||||
* (2) Update the methods on mozilla::OriginAttributes, including equality,
|
||||
* serialization, and deserialization.
|
||||
* (3) Update the methods on mozilla::OriginAttributesPattern, including matching.
|
||||
* (4) Bump the CIDs (_not_ IIDs) of all the principal implementations that
|
||||
* use OriginAttributes in their nsISerializable implementations.
|
||||
*/
|
||||
dictionary OriginAttributesDictionary {
|
||||
unsigned long appId = 0;
|
||||
boolean inBrowser = false;
|
||||
DOMString addonId = "";
|
||||
};
|
||||
dictionary OriginAttributesPatternDictionary {
|
||||
unsigned long appId;
|
||||
boolean inBrowser;
|
||||
DOMString addonId;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user