mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
4c9d88c9a4
- Bug 1246051 - have MediaQueue<T>::Peek/PeekFront return a RefPtr<> to avoid dangling pointers per comment 0. r=gerald. (00f334efb1) - Bug 1264199: P1. Perform audio conversion in the MSDM taskqueue and ahead of use. r=kinetik (001936e3ea) - Bug 1267983 - include MediaQueue.h; r=jwwang (036107d765) - Bug 1264199: P0. Fix nsDequeue/MediaQueue methods constness. r=jwwang (9aa33dfcb5) - Bug 1264199: P0.1. Export SaferMultDiv method. r=gerald (0b7a35ae4d) - Bug 1264199: P2. Ensure the AudioStream only ever receive the same content format. r=kinetik (a180d09279) - Bug 1264199: P3. Attempt to minimize audio quality loss and unnecessary processing. r=kinetik (29d57b5a33) - Bug 1264199: P4. Add mono to stereo upmix to AudioConverter. r=rillian (49c029bd86) - Bug 1264199: P5. Perform all downmixing operations in DecodedAudioDataSink. r=kinetik (05a479f095) - Bug 1264199: P6. Drain resampler when changing format or reaching the end. r=kinetik (8639102a94) - Bug 1264199: P8. Handle potential resampling errors. r=kinetik (1267e4e73d) - Bug 1264199: P9. Include pending frames in HasUnplayedFrames calculation. r=jwwang (ce7097fc90) - Bug 1263496 - Part 1: fix for @mozilla.org/nullprincipal;1 r=bholley (c4c462a1bc) - Bug 1263496 - Part 2: fix for NS_NULLPRINCIPAL_CONTRACTID. r=bholley (c1504240ec) - Bug 1263496 - Part 3: fix for nsNullPrincipal::Create (0196a5a3ce) - Bug 1261009 - Remove the Data Store API, r=fabrice (b22e580107) - Bug 1261405 - Rename PushPermissionDescriptor.userVisible to `userVisibleOnly`. r=baku (4de70267cc) - Bug 1266821 - Remove PushPermissionDescriptor from the Permissions API. r=baku (196cd83442) - Bug 1268393 - Some compilation issues in ServiceWorker code, r=ehsan (d9c2f2554b) - Merge branch 'dev' of https://github.com/rmottola/Arctic-Fox into dev (6f6c606911) - Bug 1267733 P1 Treat last-update-time as infinitely in the past when checking for service worker update after restart. r=jdm (255da0a9e2) - Bug 1209095 - Accept opaqueredirection fetch results if the request redirection type is manual. r=bkelly (6fe92d1368) - Bug 1267733 P2 Pass ServiceWorkerRegistrationInfo down to CancelChannelRunnable. r=jdm (0ec51f09ef) - Bug 1267733 P3 Trigger service worker update after failed interception. r=jdm (f89a7998d4) - Bug 1267733 P4 Add a wpt test that verifies a service worker update can recover from a broken navigation interception. r=jdm (9dc0ce97bd) - Bug 1267691: Assert on failed attempts to shutdown a thread from itself r=froyd (0cbd1e458c) - Bug 1180533 - Disable BackgroundHangMonitor on gonk (a2d666e741) - Bug 1121216 - disable BackgroundHangMonitor for TSan builds; r=jchen (ef15d1016f) - Bug 1265621 - Use StaticRefPtr in Omnijar.cpp; r=froydnj (81bc32836e) - Bug 1265621 - Expose outer zip readers in Omnijar::GetReader; r=froydnj (ce3f82929e) - Bug 1267021 - Use fallible allocation and move semantics for Push events. r=wchen (3a1ae23d8d) - Bug 1222899 - Handle geolocation-device-events callback. r=kchen (a33bcf4297) - Bug 1237831 - Update GonkGPSGeolocationProvider.cpp to use B2G-style. r=jst (d389eedf47) - Bug 1245033 - Build break in dom/system/gonk/GonkGPSGeolocationProvider.cpp:541:126: error: format '%d' expects argument of type 'int', but argument 5 has type 'nsresult'. r=fabrice (ecde789edf) - Bug 1264287: Convert Wifi to use |UniquePtr|, r=nfroyd (9bad7792bf) - Bug 1267577 - Move nsRunnable to mozilla::Runnable. r=gsvelto (f58e2161f2) - Bug 1210370 - Close wpa_supplicant before we shutdown nsIWifiProxyService. r=mrbkap (5cd4dce58f) - Bug 1218629 - Save audio volume for each device to setting db r=alwu (2f1847dd6f) - Bug 1249437 - Remove workaround of volume control r=alwu (13cd144a89) - Bug 1268432: Replace |Task| with |Runnable| in B2G code r=fabrice (bcc768e9cb) - Bug 1226483 - Add ASSERT check to AudioManager::SelectDeviceFromDevices() r=alwu (446e8f634e) - Bug 1229234 - Enable audio_is_output_device() on ICS r=alwu (84aae07f23) - Bug 1267369 - Only generate typelib data for scriptable interfaces; r=khuey (e49b44c9ce) - Bug 1155969 - Make runtests.py flake8 compliant. r=ted (1de456b206) - Bug 1266569 - Avoid including the ChromeUtils binding in Base64.h. r=froydnj (7ba39a7687) - Bug 1267568 part 1 - Add a weak ptr to nsGlobalChromeWindow to remember the pres shell we set the fullscreen change flag. r=smaug (83995d5296) - Bug 1267568 part 2 - Add helper method to nsIPresShell to get the RefreshDriver. r=smaug (c60589fb40) - Bug 1267568 part 3 - Use an individual method for check whether resize should be delayed. r=smaug (f0ab5156d1) - Bug 1267568 part 4 - Replace InFullscreenChange flag of PresShell with IsResizeSuppressed flag in RefreshDriver. r=smaug (0a54f5a08b) - Bug 1267568 part 5 - Replace the old FullscreenChangePrepare class with a single function. r=smaug (4196e82852) - Bug 1267568 part 6 - Send fullscreen message before triggering any potential reflow. r=dao (fe9133ca2d) - Bug 1243352 - attribute a value for ProxyHandlerInfo::mPrefAction in ProxyHandlerInfo::SetPreferredAction. r=blassey (577c23e4cb) - Bug 1266433 - Send Push observer notifications to parent and content processes. f=janx r=dragana (768c173c2c) - Bug 1267493 - Replace isURIPotentiallyTrustworthy usage in Push with a testing pref. r=dragana (96434b90d9) - Bug 1266433 - Send an observer notification when a push subscription is lost. f=janx r=dragana (a7c7277e02) - Bug 1247685 - Send subscription keys to the Push server. r=mt (651fc0cad3) - Bug 1266540 - Stub out Push error reporting for the GCM and H2 backends. r=wchen (fd00c311aa) - Bug 1266623 - Up/down mix WASAPI capture streams when stream formats don't match. r=padenot (ca92ec20ab) - Bug 1267930 - When the wasapi rendering loop is stuck and we're shuttin down, leak the thread and continue the shutdown process. r=kinetik (04419ad94d) - Bug 1269692 - Update cubeb to revision 17e3048d0afa1152776fb1867cdb61c49fae69e4. (3de098f4bb) - Bug 1251502 - Update cubeb's udpate.sh script to account for new files. r=kinetik (a3ae5f27c1) - Bug 1243234 - Hide MP4Metadata behind an impl pointer. r=giles (1543bedf28) - Bug 1243234 - Update rust mp4parse telemetry reporting. r=kinetik (bb5c999c06) - Bug 1242807 - Fix mp4parse-rust's error reporting via telemetry. r=giles (a3ca1b133b) - Bug 1243234 - Move mp4parse-rust code into MP4MetadataRust impl. r=giles (ec4d6bcf0e) - Bug 1243234 - Remove now-unnecessary StagefrightPrivate wrapper. r=giles (1e2c54232b) - Bug 1243234 - Move mp4parse-rust initialization into constructor and clean up try_rust. r=giles (291c01f45a) - Bug 1243234 - Update rust mp4parse to v0.2.1. r=kinetik (d2774346cd) - Bug 1264622: [MP4] Resync stagefright's updateAudioTrackInfoFromESDS_MPEG4Audio with upstream. r=kentuckyfriedtakahe (b4b596507b) - Bug 1254721: Ensure consistency between Cenc offsets and sizes table. r=gerald (59bd7122d1) - Bug 1151202 - libstagefright: Fix compilation for systems without <sys/cdefs.h>. r=cpearce (e219658c31) - Bug 1255866 - stagefright: Fix unused variable warnings. r=ajones (62afc26384) - Bug 1251821: increase UDP socket send buffer on Win 7 r=jdm,jesup (e0d6e545f4) - Bug 929977: Add support for RFC 7675 ICE consent freshness. r=bwc,mt (ea8a565a65) - Bug 1231981 - Part 1: Very basic test TURN server for running in CI. r=ahal,drno (c98a79810b) - Bug 1231981 - Part 2: A websocket-to-process bridge script that can be used by JS to launch an ICE server for testing. r=ahal (5bdb00dfd1) - Bug 1231981 - Part 2.1: Only run the websocket/process bridge for media tests. r=ahal (86f97e2eb6) - Bug 1225729: Whitelist specific bad RTCP timestamp value r=drno (f0c8402fd0) - Bug 1193045 - Check selected attribute for all calls. r=bwc (7eb4095c34) - Bug 1213056 - update tests to use maplike getStats. r=bwc (d27f997290) - Bug 1231981 - Part 3: Set up TURN server for webrtc mochitests, when configured to. r=drno (38e4455eec) - Bug 1231975 - Part 1: Basic audio mochitests for NAT scenarios. r=drno (16efaf581e) - Bug 1231975 - Part 2: Break a reference cycle between NrTcpSocketIpc and TCPSocketChild, in the same manner as the UDP case. r=mcmanus (1fa55e3e5f)
616 lines
16 KiB
C++
616 lines
16 KiB
C++
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
|
/* 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 "mozilla/BasePrincipal.h"
|
|
|
|
#include "nsDocShell.h"
|
|
#ifdef MOZ_CRASHREPORTER
|
|
#include "nsExceptionHandler.h"
|
|
#endif
|
|
#include "nsIAddonPolicyService.h"
|
|
#include "nsIContentSecurityPolicy.h"
|
|
#include "nsIObjectInputStream.h"
|
|
#include "nsIObjectOutputStream.h"
|
|
|
|
#include "nsPrincipal.h"
|
|
#include "nsNetUtil.h"
|
|
#include "nsIURIWithPrincipal.h"
|
|
#include "nsNullPrincipal.h"
|
|
#include "nsScriptSecurityManager.h"
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "mozilla/dom/CSPDictionariesBinding.h"
|
|
#include "mozilla/dom/quota/QuotaManager.h"
|
|
#include "mozilla/dom/ToJSValue.h"
|
|
#include "mozilla/dom/URLSearchParams.h"
|
|
|
|
namespace mozilla {
|
|
|
|
using dom::URLParams;
|
|
|
|
void
|
|
PrincipalOriginAttributes::InheritFromDocShellToDoc(const DocShellOriginAttributes& aAttrs,
|
|
const nsIURI* aURI)
|
|
{
|
|
mAppId = aAttrs.mAppId;
|
|
mInIsolatedMozBrowser = aAttrs.mInIsolatedMozBrowser;
|
|
|
|
// addonId is computed from the principal URI and never propagated
|
|
mUserContextId = aAttrs.mUserContextId;
|
|
|
|
// TODO:
|
|
// Bug 1225349 - PrincipalOriginAttributes should inherit mSignedPkg
|
|
// accordingly by URI
|
|
mSignedPkg = aAttrs.mSignedPkg;
|
|
}
|
|
|
|
void
|
|
PrincipalOriginAttributes::InheritFromNecko(const NeckoOriginAttributes& aAttrs)
|
|
{
|
|
mAppId = aAttrs.mAppId;
|
|
mInIsolatedMozBrowser = aAttrs.mInIsolatedMozBrowser;
|
|
|
|
// addonId is computed from the principal URI and never propagated
|
|
mUserContextId = aAttrs.mUserContextId;
|
|
mSignedPkg = aAttrs.mSignedPkg;
|
|
}
|
|
|
|
void
|
|
DocShellOriginAttributes::InheritFromDocToChildDocShell(const PrincipalOriginAttributes& aAttrs)
|
|
{
|
|
mAppId = aAttrs.mAppId;
|
|
mInIsolatedMozBrowser = aAttrs.mInIsolatedMozBrowser;
|
|
|
|
// addonId is computed from the principal URI and never propagated
|
|
mUserContextId = aAttrs.mUserContextId;
|
|
|
|
// TODO:
|
|
// Bug 1225353 - DocShell/NeckoOriginAttributes should inherit
|
|
// mSignedPkg accordingly by mSignedPkgInBrowser
|
|
mSignedPkg = aAttrs.mSignedPkg;
|
|
}
|
|
|
|
void
|
|
NeckoOriginAttributes::InheritFromDocToNecko(const PrincipalOriginAttributes& aAttrs)
|
|
{
|
|
mAppId = aAttrs.mAppId;
|
|
mInIsolatedMozBrowser = aAttrs.mInIsolatedMozBrowser;
|
|
|
|
// addonId is computed from the principal URI and never propagated
|
|
mUserContextId = aAttrs.mUserContextId;
|
|
|
|
// TODO:
|
|
// Bug 1225353 - DocShell/NeckoOriginAttributes should inherit
|
|
// mSignedPkg accordingly by mSignedPkgInBrowser
|
|
}
|
|
|
|
void
|
|
NeckoOriginAttributes::InheritFromDocShellToNecko(const DocShellOriginAttributes& aAttrs)
|
|
{
|
|
mAppId = aAttrs.mAppId;
|
|
mInIsolatedMozBrowser = aAttrs.mInIsolatedMozBrowser;
|
|
|
|
// addonId is computed from the principal URI and never propagated
|
|
mUserContextId = aAttrs.mUserContextId;
|
|
|
|
// TODO:
|
|
// Bug 1225353 - DocShell/NeckoOriginAttributes should inherit
|
|
// mSignedPkg accordingly by mSignedPkgInBrowser
|
|
}
|
|
|
|
void
|
|
OriginAttributes::CreateSuffix(nsACString& aStr) const
|
|
{
|
|
UniquePtr<URLParams> params(new URLParams());
|
|
nsAutoString value;
|
|
|
|
//
|
|
// Important: While serializing any string-valued attributes, perform a
|
|
// release-mode assertion to make sure that they don't contain characters that
|
|
// will break the quota manager when it uses the serialization for file
|
|
// naming (see addonId below).
|
|
//
|
|
|
|
if (mAppId != nsIScriptSecurityManager::NO_APP_ID) {
|
|
value.AppendInt(mAppId);
|
|
params->Set(NS_LITERAL_STRING("appId"), value);
|
|
}
|
|
|
|
if (mInIsolatedMozBrowser) {
|
|
params->Set(NS_LITERAL_STRING("inBrowser"), NS_LITERAL_STRING("1"));
|
|
}
|
|
|
|
if (!mAddonId.IsEmpty()) {
|
|
if (mAddonId.FindCharInSet(dom::quota::QuotaManager::kReplaceChars) != kNotFound) {
|
|
#ifdef MOZ_CRASHREPORTER
|
|
CrashReporter::AnnotateCrashReport(NS_LITERAL_CSTRING("Crash_AddonId"),
|
|
NS_ConvertUTF16toUTF8(mAddonId));
|
|
#endif
|
|
MOZ_CRASH();
|
|
}
|
|
params->Set(NS_LITERAL_STRING("addonId"), mAddonId);
|
|
}
|
|
|
|
if (mUserContextId != nsIScriptSecurityManager::DEFAULT_USER_CONTEXT_ID) {
|
|
value.Truncate();
|
|
value.AppendInt(mUserContextId);
|
|
params->Set(NS_LITERAL_STRING("userContextId"), value);
|
|
}
|
|
|
|
if (!mSignedPkg.IsEmpty()) {
|
|
MOZ_RELEASE_ASSERT(mSignedPkg.FindCharInSet(dom::quota::QuotaManager::kReplaceChars) == kNotFound);
|
|
params->Set(NS_LITERAL_STRING("signedPkg"), mSignedPkg);
|
|
}
|
|
|
|
aStr.Truncate();
|
|
|
|
params->Serialize(value);
|
|
if (!value.IsEmpty()) {
|
|
aStr.AppendLiteral("^");
|
|
aStr.Append(NS_ConvertUTF16toUTF8(value));
|
|
}
|
|
|
|
// In debug builds, check the whole string for illegal characters too (just in case).
|
|
#ifdef DEBUG
|
|
nsAutoCString str;
|
|
str.Assign(aStr);
|
|
MOZ_ASSERT(str.FindCharInSet(dom::quota::QuotaManager::kReplaceChars) == kNotFound);
|
|
#endif
|
|
}
|
|
|
|
namespace {
|
|
|
|
class MOZ_STACK_CLASS PopulateFromSuffixIterator final
|
|
: public URLParams::ForEachIterator
|
|
{
|
|
public:
|
|
explicit PopulateFromSuffixIterator(OriginAttributes* aOriginAttributes)
|
|
: mOriginAttributes(aOriginAttributes)
|
|
{
|
|
MOZ_ASSERT(aOriginAttributes);
|
|
}
|
|
|
|
bool URLParamsIterator(const nsString& aName,
|
|
const nsString& aValue) override
|
|
{
|
|
if (aName.EqualsLiteral("appId")) {
|
|
nsresult rv;
|
|
int64_t val = aValue.ToInteger64(&rv);
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
NS_ENSURE_TRUE(val <= UINT32_MAX, false);
|
|
mOriginAttributes->mAppId = static_cast<uint32_t>(val);
|
|
|
|
return true;
|
|
}
|
|
|
|
if (aName.EqualsLiteral("inBrowser")) {
|
|
if (!aValue.EqualsLiteral("1")) {
|
|
return false;
|
|
}
|
|
|
|
mOriginAttributes->mInIsolatedMozBrowser = true;
|
|
return true;
|
|
}
|
|
|
|
if (aName.EqualsLiteral("addonId")) {
|
|
MOZ_RELEASE_ASSERT(mOriginAttributes->mAddonId.IsEmpty());
|
|
mOriginAttributes->mAddonId.Assign(aValue);
|
|
return true;
|
|
}
|
|
|
|
if (aName.EqualsLiteral("userContextId")) {
|
|
nsresult rv;
|
|
int64_t val = aValue.ToInteger64(&rv);
|
|
NS_ENSURE_SUCCESS(rv, false);
|
|
NS_ENSURE_TRUE(val <= UINT32_MAX, false);
|
|
mOriginAttributes->mUserContextId = static_cast<uint32_t>(val);
|
|
|
|
return true;
|
|
}
|
|
|
|
if (aName.EqualsLiteral("signedPkg")) {
|
|
MOZ_RELEASE_ASSERT(mOriginAttributes->mSignedPkg.IsEmpty());
|
|
mOriginAttributes->mSignedPkg.Assign(aValue);
|
|
return true;
|
|
}
|
|
|
|
// No other attributes are supported.
|
|
return false;
|
|
}
|
|
|
|
private:
|
|
OriginAttributes* mOriginAttributes;
|
|
};
|
|
|
|
} // namespace
|
|
|
|
bool
|
|
OriginAttributes::PopulateFromSuffix(const nsACString& aStr)
|
|
{
|
|
if (aStr.IsEmpty()) {
|
|
return true;
|
|
}
|
|
|
|
if (aStr[0] != '^') {
|
|
return false;
|
|
}
|
|
|
|
UniquePtr<URLParams> params(new URLParams());
|
|
params->ParseInput(Substring(aStr, 1, aStr.Length() - 1));
|
|
|
|
PopulateFromSuffixIterator iterator(this);
|
|
return params->ForEach(iterator);
|
|
}
|
|
|
|
bool
|
|
OriginAttributes::PopulateFromOrigin(const nsACString& aOrigin,
|
|
nsACString& aOriginNoSuffix)
|
|
{
|
|
// RFindChar is only available on nsCString.
|
|
nsCString origin(aOrigin);
|
|
int32_t pos = origin.RFindChar('^');
|
|
|
|
if (pos == kNotFound) {
|
|
aOriginNoSuffix = origin;
|
|
return true;
|
|
}
|
|
|
|
aOriginNoSuffix = Substring(origin, 0, pos);
|
|
return PopulateFromSuffix(Substring(origin, pos));
|
|
}
|
|
|
|
BasePrincipal::BasePrincipal()
|
|
{}
|
|
|
|
BasePrincipal::~BasePrincipal()
|
|
{}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetOrigin(nsACString& aOrigin)
|
|
{
|
|
nsresult rv = GetOriginInternal(aOrigin);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
nsAutoCString suffix;
|
|
mOriginAttributes.CreateSuffix(suffix);
|
|
aOrigin.Append(suffix);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetOriginNoSuffix(nsACString& aOrigin)
|
|
{
|
|
return GetOriginInternal(aOrigin);
|
|
}
|
|
|
|
bool
|
|
BasePrincipal::Subsumes(nsIPrincipal* aOther, DocumentDomainConsideration aConsideration)
|
|
{
|
|
MOZ_ASSERT(aOther);
|
|
return SubsumesInternal(aOther, aConsideration);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::Equals(nsIPrincipal *aOther, bool *aResult)
|
|
{
|
|
NS_ENSURE_TRUE(aOther, NS_ERROR_INVALID_ARG);
|
|
*aResult = Subsumes(aOther, DontConsiderDocumentDomain) &&
|
|
Cast(aOther)->Subsumes(this, DontConsiderDocumentDomain);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::EqualsConsideringDomain(nsIPrincipal *aOther, bool *aResult)
|
|
{
|
|
NS_ENSURE_TRUE(aOther, NS_ERROR_INVALID_ARG);
|
|
*aResult = Subsumes(aOther, ConsiderDocumentDomain) &&
|
|
Cast(aOther)->Subsumes(this, ConsiderDocumentDomain);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::Subsumes(nsIPrincipal *aOther, bool *aResult)
|
|
{
|
|
NS_ENSURE_TRUE(aOther, NS_ERROR_INVALID_ARG);
|
|
*aResult = Subsumes(aOther, DontConsiderDocumentDomain);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::SubsumesConsideringDomain(nsIPrincipal *aOther, bool *aResult)
|
|
{
|
|
NS_ENSURE_TRUE(aOther, NS_ERROR_INVALID_ARG);
|
|
*aResult = Subsumes(aOther, ConsiderDocumentDomain);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::CheckMayLoad(nsIURI* aURI, bool aReport, bool aAllowIfInheritsPrincipal)
|
|
{
|
|
// Check the internal method first, which allows us to quickly approve loads
|
|
// for the System Principal.
|
|
if (MayLoadInternal(aURI)) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult rv;
|
|
if (aAllowIfInheritsPrincipal) {
|
|
// If the caller specified to allow loads of URIs that inherit
|
|
// our principal, allow the load if this URI inherits its principal.
|
|
bool doesInheritSecurityContext;
|
|
rv = NS_URIChainHasFlags(aURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
|
|
&doesInheritSecurityContext);
|
|
if (NS_SUCCEEDED(rv) && doesInheritSecurityContext) {
|
|
return NS_OK;
|
|
}
|
|
}
|
|
|
|
bool fetchableByAnyone;
|
|
rv = NS_URIChainHasFlags(aURI, nsIProtocolHandler::URI_FETCHABLE_BY_ANYONE, &fetchableByAnyone);
|
|
if (NS_SUCCEEDED(rv) && fetchableByAnyone) {
|
|
return NS_OK;
|
|
}
|
|
|
|
if (aReport) {
|
|
nsCOMPtr<nsIURI> prinURI;
|
|
rv = GetURI(getter_AddRefs(prinURI));
|
|
if (NS_SUCCEEDED(rv) && prinURI) {
|
|
nsScriptSecurityManager::ReportError(nullptr, NS_LITERAL_STRING("CheckSameOriginError"), prinURI, aURI);
|
|
}
|
|
}
|
|
|
|
return NS_ERROR_DOM_BAD_URI;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetCsp(nsIContentSecurityPolicy** aCsp)
|
|
{
|
|
NS_IF_ADDREF(*aCsp = mCSP);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::EnsureCSP(nsIDOMDocument* aDocument,
|
|
nsIContentSecurityPolicy** aCSP)
|
|
{
|
|
if (mCSP) {
|
|
// if there is a CSP already associated with this principal
|
|
// then just return that - do not overwrite it!!!
|
|
NS_IF_ADDREF(*aCSP = mCSP);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult rv = NS_OK;
|
|
mCSP = do_CreateInstance("@mozilla.org/cspcontext;1", &rv);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Store the request context for violation reports
|
|
rv = aDocument ? mCSP->SetRequestContext(aDocument, nullptr)
|
|
: mCSP->SetRequestContext(nullptr, this);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
NS_IF_ADDREF(*aCSP = mCSP);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetPreloadCsp(nsIContentSecurityPolicy** aPreloadCSP)
|
|
{
|
|
NS_IF_ADDREF(*aPreloadCSP = mPreloadCSP);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::EnsurePreloadCSP(nsIDOMDocument* aDocument,
|
|
nsIContentSecurityPolicy** aPreloadCSP)
|
|
{
|
|
if (mPreloadCSP) {
|
|
// if there is a speculative CSP already associated with this principal
|
|
// then just return that - do not overwrite it!!!
|
|
NS_IF_ADDREF(*aPreloadCSP = mPreloadCSP);
|
|
return NS_OK;
|
|
}
|
|
|
|
nsresult rv = NS_OK;
|
|
mPreloadCSP = do_CreateInstance("@mozilla.org/cspcontext;1", &rv);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
// Store the request context for violation reports
|
|
rv = aDocument ? mPreloadCSP->SetRequestContext(aDocument, nullptr)
|
|
: mPreloadCSP->SetRequestContext(nullptr, this);
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
NS_IF_ADDREF(*aPreloadCSP = mPreloadCSP);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetCspJSON(nsAString& outCSPinJSON)
|
|
{
|
|
outCSPinJSON.Truncate();
|
|
dom::CSPPolicies jsonPolicies;
|
|
|
|
if (!mCSP) {
|
|
jsonPolicies.ToJSON(outCSPinJSON);
|
|
return NS_OK;
|
|
}
|
|
return mCSP->ToJSON(outCSPinJSON);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetIsNullPrincipal(bool* aResult)
|
|
{
|
|
*aResult = Kind() == eNullPrincipal;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetIsCodebasePrincipal(bool* aResult)
|
|
{
|
|
*aResult = Kind() == eCodebasePrincipal;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetIsExpandedPrincipal(bool* aResult)
|
|
{
|
|
*aResult = Kind() == eExpandedPrincipal;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetIsSystemPrincipal(bool* aResult)
|
|
{
|
|
*aResult = Kind() == eSystemPrincipal;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetJarPrefix(nsACString& aJarPrefix)
|
|
{
|
|
mozilla::GetJarPrefix(mOriginAttributes.mAppId, mOriginAttributes.mInIsolatedMozBrowser, aJarPrefix);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetOriginAttributes(JSContext* aCx, JS::MutableHandle<JS::Value> aVal)
|
|
{
|
|
if (NS_WARN_IF(!ToJSValue(aCx, mOriginAttributes, aVal))) {
|
|
return NS_ERROR_FAILURE;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetOriginSuffix(nsACString& aOriginAttributes)
|
|
{
|
|
mOriginAttributes.CreateSuffix(aOriginAttributes);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetAppStatus(uint16_t* aAppStatus)
|
|
{
|
|
if (AppId() == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
|
|
NS_WARNING("Asking for app status on a principal with an unknown app id");
|
|
*aAppStatus = nsIPrincipal::APP_STATUS_NOT_INSTALLED;
|
|
return NS_OK;
|
|
}
|
|
|
|
*aAppStatus = nsScriptSecurityManager::AppStatusForPrincipal(this);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetAppId(uint32_t* aAppId)
|
|
{
|
|
if (AppId() == nsIScriptSecurityManager::UNKNOWN_APP_ID) {
|
|
MOZ_ASSERT(false);
|
|
*aAppId = nsIScriptSecurityManager::NO_APP_ID;
|
|
return NS_OK;
|
|
}
|
|
|
|
*aAppId = AppId();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetAddonId(nsAString& aAddonId)
|
|
{
|
|
aAddonId.Assign(mOriginAttributes.mAddonId);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetUserContextId(uint32_t* aUserContextId)
|
|
{
|
|
*aUserContextId = UserContextId();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetIsInIsolatedMozBrowserElement(bool* aIsInIsolatedMozBrowserElement)
|
|
{
|
|
*aIsInIsolatedMozBrowserElement = IsInIsolatedMozBrowserElement();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
BasePrincipal::GetUnknownAppId(bool* aUnknownAppId)
|
|
{
|
|
*aUnknownAppId = AppId() == nsIScriptSecurityManager::UNKNOWN_APP_ID;
|
|
return NS_OK;
|
|
}
|
|
|
|
already_AddRefed<BasePrincipal>
|
|
BasePrincipal::CreateCodebasePrincipal(nsIURI* aURI, const PrincipalOriginAttributes& aAttrs)
|
|
{
|
|
// If the URI is supposed to inherit the security context of whoever loads it,
|
|
// we shouldn't make a codebase principal for it.
|
|
bool inheritsPrincipal;
|
|
nsresult rv = NS_URIChainHasFlags(aURI, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT,
|
|
&inheritsPrincipal);
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
if (NS_FAILED(rv) || inheritsPrincipal) {
|
|
return nsNullPrincipal::Create(aAttrs);
|
|
}
|
|
|
|
// Check whether the URI knows what its principal is supposed to be.
|
|
nsCOMPtr<nsIURIWithPrincipal> uriPrinc = do_QueryInterface(aURI);
|
|
if (uriPrinc) {
|
|
nsCOMPtr<nsIPrincipal> principal;
|
|
uriPrinc->GetPrincipal(getter_AddRefs(principal));
|
|
if (!principal) {
|
|
return nsNullPrincipal::Create(aAttrs);
|
|
}
|
|
RefPtr<BasePrincipal> concrete = Cast(principal);
|
|
return concrete.forget();
|
|
}
|
|
|
|
// Mint a codebase principal.
|
|
RefPtr<nsPrincipal> codebase = new nsPrincipal();
|
|
rv = codebase->Init(aURI, aAttrs);
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
return codebase.forget();
|
|
}
|
|
|
|
already_AddRefed<BasePrincipal>
|
|
BasePrincipal::CreateCodebasePrincipal(const nsACString& aOrigin)
|
|
{
|
|
MOZ_ASSERT(!StringBeginsWith(aOrigin, NS_LITERAL_CSTRING("[")),
|
|
"CreateCodebasePrincipal does not support System and Expanded principals");
|
|
|
|
MOZ_ASSERT(!StringBeginsWith(aOrigin, NS_LITERAL_CSTRING(NS_NULLPRINCIPAL_SCHEME ":")),
|
|
"CreateCodebasePrincipal does not support nsNullPrincipal");
|
|
|
|
nsAutoCString originNoSuffix;
|
|
mozilla::PrincipalOriginAttributes attrs;
|
|
if (!attrs.PopulateFromOrigin(aOrigin, originNoSuffix)) {
|
|
return nullptr;
|
|
}
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
nsresult rv = NS_NewURI(getter_AddRefs(uri), originNoSuffix);
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
return BasePrincipal::CreateCodebasePrincipal(uri, attrs);
|
|
}
|
|
|
|
bool
|
|
BasePrincipal::AddonAllowsLoad(nsIURI* aURI)
|
|
{
|
|
if (mOriginAttributes.mAddonId.IsEmpty()) {
|
|
return false;
|
|
}
|
|
|
|
nsCOMPtr<nsIAddonPolicyService> aps = do_GetService("@mozilla.org/addons/policy-service;1");
|
|
NS_ENSURE_TRUE(aps, false);
|
|
|
|
bool allowed = false;
|
|
nsresult rv = aps->AddonMayLoadURI(mOriginAttributes.mAddonId, aURI, &allowed);
|
|
return NS_SUCCEEDED(rv) && allowed;
|
|
}
|
|
|
|
} // namespace mozilla
|