2015-06-17 21:12:23 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "ChromeUtils.h"
|
|
|
|
|
|
|
|
#include "mozilla/BasePrincipal.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2015-06-24 23:34:54 +03:00
|
|
|
/* static */ void
|
2015-11-11 14:55:00 +03:00
|
|
|
ThreadSafeChromeUtils::NondeterministicGetWeakMapKeys(GlobalObject& aGlobal,
|
|
|
|
JS::Handle<JS::Value> aMap,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!aMap.isObject()) {
|
|
|
|
aRetval.setUndefined();
|
|
|
|
} else {
|
|
|
|
JSContext* cx = aGlobal.Context();
|
|
|
|
JS::Rooted<JSObject*> objRet(cx);
|
|
|
|
JS::Rooted<JSObject*> mapObj(cx, &aMap.toObject());
|
|
|
|
if (!JS_NondeterministicGetWeakMapKeys(cx, mapObj, &objRet)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
} else {
|
|
|
|
aRetval.set(objRet ? JS::ObjectValue(*objRet) : JS::UndefinedValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 17:50:00 +03:00
|
|
|
/* static */ void
|
|
|
|
ThreadSafeChromeUtils::NondeterministicGetWeakSetKeys(GlobalObject& aGlobal,
|
|
|
|
JS::Handle<JS::Value> aSet,
|
|
|
|
JS::MutableHandle<JS::Value> aRetval,
|
|
|
|
ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
if (!aSet.isObject()) {
|
|
|
|
aRetval.setUndefined();
|
|
|
|
} else {
|
|
|
|
JSContext* cx = aGlobal.Context();
|
|
|
|
JS::Rooted<JSObject*> objRet(cx);
|
|
|
|
JS::Rooted<JSObject*> setObj(cx, &aSet.toObject());
|
|
|
|
if (!JS_NondeterministicGetWeakSetKeys(cx, setObj, &objRet)) {
|
|
|
|
aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
} else {
|
|
|
|
aRetval.set(objRet ? JS::ObjectValue(*objRet) : JS::UndefinedValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-29 14:26:00 +03:00
|
|
|
/* static */ void
|
2015-06-24 23:34:54 +03:00
|
|
|
ChromeUtils::OriginAttributesToSuffix(dom::GlobalObject& aGlobal,
|
|
|
|
const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
nsCString& aSuffix)
|
|
|
|
|
|
|
|
{
|
2015-11-03 04:50:54 +03:00
|
|
|
GenericOriginAttributes attrs(aAttrs);
|
2015-06-24 23:34:54 +03:00
|
|
|
attrs.CreateSuffix(aSuffix);
|
|
|
|
}
|
2015-07-13 18:25:42 +03:00
|
|
|
|
2015-07-09 21:36:35 +03:00
|
|
|
/* static */ bool
|
|
|
|
ChromeUtils::OriginAttributesMatchPattern(dom::GlobalObject& aGlobal,
|
|
|
|
const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
const dom::OriginAttributesPatternDictionary& aPattern)
|
|
|
|
{
|
2015-11-03 04:50:54 +03:00
|
|
|
GenericOriginAttributes attrs(aAttrs);
|
2015-07-09 21:36:35 +03:00
|
|
|
OriginAttributesPattern pattern(aPattern);
|
|
|
|
return pattern.Matches(attrs);
|
|
|
|
}
|
|
|
|
|
2016-01-06 13:08:30 +03:00
|
|
|
/* static */ void
|
2016-02-29 14:26:00 +03:00
|
|
|
ChromeUtils::CreateDefaultOriginAttributes(dom::GlobalObject& aGlobal,
|
|
|
|
dom::OriginAttributesDictionary& aAttrs)
|
|
|
|
{
|
|
|
|
aAttrs = GenericOriginAttributes();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
ChromeUtils::CreateOriginAttributesFromOrigin(dom::GlobalObject& aGlobal,
|
|
|
|
const nsAString& aOrigin,
|
|
|
|
dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
ErrorResult& aRv)
|
2016-01-06 13:08:30 +03:00
|
|
|
{
|
|
|
|
GenericOriginAttributes attrs;
|
|
|
|
nsAutoCString suffix;
|
|
|
|
if (!attrs.PopulateFromOrigin(NS_ConvertUTF16toUTF8(aOrigin), suffix)) {
|
|
|
|
aRv.Throw(NS_ERROR_FAILURE);
|
|
|
|
return;
|
|
|
|
}
|
2016-02-19 17:55:25 +03:00
|
|
|
aAttrs = attrs;
|
2016-02-18 15:42:00 +03:00
|
|
|
}
|
|
|
|
|
2016-02-29 14:26:00 +03:00
|
|
|
/* static */ void
|
|
|
|
ChromeUtils::CreateOriginAttributesFromDict(dom::GlobalObject& aGlobal,
|
|
|
|
const dom::OriginAttributesDictionary& aAttrs,
|
|
|
|
dom::OriginAttributesDictionary& aNewAttrs)
|
|
|
|
{
|
|
|
|
aNewAttrs = aAttrs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-25 18:41:13 +03:00
|
|
|
/* static */ bool
|
|
|
|
ChromeUtils::IsOriginAttributesEqual(dom::GlobalObject& aGlobal,
|
|
|
|
const dom::OriginAttributesDictionary& aA,
|
|
|
|
const dom::OriginAttributesDictionary& aB)
|
|
|
|
{
|
|
|
|
return aA.mAddonId == aB.mAddonId &&
|
|
|
|
aA.mAppId == aB.mAppId &&
|
2016-02-05 04:42:44 +03:00
|
|
|
aA.mInIsolatedMozBrowser == aB.mInIsolatedMozBrowser &&
|
2016-02-25 18:41:13 +03:00
|
|
|
aA.mSignedPkg == aB.mSignedPkg &&
|
|
|
|
aA.mUserContextId == aB.mUserContextId;
|
|
|
|
}
|
|
|
|
|
2015-06-17 21:12:23 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|