Bug 1165269 - Use OriginAttributes in nsILoadContextInfo, r=michal+allstars

This commit is contained in:
Honza Bambas 2015-10-11 18:13:09 +02:00
parent 35526b035e
commit 7033e80df1
29 changed files with 420 additions and 462 deletions

View File

@ -2,7 +2,7 @@
var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var Cu = SpecialPowers.Cu;
var LoadContextInfo = Cu.import("resource://gre/modules/LoadContextInfo.jsm", {}).LoadContextInfo;
var LoadContextInfo = Cc["@mozilla.org/load-context-info-factory;1"].getService(Ci.nsILoadContextInfoFactory);
var CommonUtils = Cu.import("resource://services-common/utils.js", {}).CommonUtils;
const kNetBase = 2152398848; // 0x804B0000

View File

@ -6,17 +6,19 @@
#include "nsIChannel.h"
#include "nsILoadContext.h"
#include "nsIWebNavigation.h"
namespace mozilla {
namespace net {
// LoadContextInfo
NS_IMPL_ISUPPORTS(LoadContextInfo, nsILoadContextInfo)
LoadContextInfo::LoadContextInfo(bool aIsPrivate, uint32_t aAppId, bool aIsInBrowser, bool aIsAnonymous)
: mAppId(aAppId)
, mIsPrivate(aIsPrivate)
, mIsInBrowser(aIsInBrowser)
LoadContextInfo::LoadContextInfo(bool aIsPrivate, bool aIsAnonymous, OriginAttributes aOriginAttributes)
: mIsPrivate(aIsPrivate)
, mIsAnonymous(aIsAnonymous)
, mOriginAttributes(aOriginAttributes)
{
}
@ -30,84 +32,149 @@ NS_IMETHODIMP LoadContextInfo::GetIsPrivate(bool *aIsPrivate)
return NS_OK;
}
NS_IMETHODIMP LoadContextInfo::GetAppId(uint32_t *aAppId)
{
*aAppId = mAppId;
return NS_OK;
}
NS_IMETHODIMP LoadContextInfo::GetIsInBrowserElement(bool *aIsInBrowser)
{
*aIsInBrowser = mIsInBrowser;
return NS_OK;
}
NS_IMETHODIMP LoadContextInfo::GetIsAnonymous(bool *aIsAnonymous)
{
*aIsAnonymous = mIsAnonymous;
return NS_OK;
}
OriginAttributes const* LoadContextInfo::OriginAttributesPtr()
{
return &mOriginAttributes;
}
NS_IMETHODIMP LoadContextInfo::GetOriginAttributes(JSContext *aCx,
JS::MutableHandle<JS::Value> aVal)
{
if (NS_WARN_IF(!ToJSValue(aCx, mOriginAttributes, aVal))) {
return NS_ERROR_FAILURE;
}
return NS_OK;
}
// LoadContextInfoFactory
NS_IMPL_ISUPPORTS(LoadContextInfoFactory, nsILoadContextInfoFactory)
/* readonly attribute nsILoadContextInfo default; */
NS_IMETHODIMP LoadContextInfoFactory::GetDefault(nsILoadContextInfo * *aDefault)
{
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(false, false, OriginAttributes());
info.forget(aDefault);
return NS_OK;
}
/* readonly attribute nsILoadContextInfo private; */
NS_IMETHODIMP LoadContextInfoFactory::GetPrivate(nsILoadContextInfo * *aPrivate)
{
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(true, false, OriginAttributes());
info.forget(aPrivate);
return NS_OK;
}
/* readonly attribute nsILoadContextInfo anonymous; */
NS_IMETHODIMP LoadContextInfoFactory::GetAnonymous(nsILoadContextInfo * *aAnonymous)
{
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(false, true, OriginAttributes());
info.forget(aAnonymous);
return NS_OK;
}
/* nsILoadContextInfo custom (in boolean aPrivate, in boolean aAnonymous, in jsval aOriginAttributes); */
NS_IMETHODIMP LoadContextInfoFactory::Custom(bool aPrivate, bool aAnonymous,
JS::HandleValue aOriginAttributes, JSContext *cx,
nsILoadContextInfo * *_retval)
{
OriginAttributes attrs;
bool status = attrs.Init(cx, aOriginAttributes);
NS_ENSURE_TRUE(status, NS_ERROR_FAILURE);
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(aPrivate, aAnonymous, attrs);
info.forget(_retval);
return NS_OK;
}
/* nsILoadContextInfo fromLoadContext (in nsILoadContext aLoadContext, in boolean aAnonymous); */
NS_IMETHODIMP LoadContextInfoFactory::FromLoadContext(nsILoadContext *aLoadContext, bool aAnonymous,
nsILoadContextInfo * *_retval)
{
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(aLoadContext, aAnonymous);
info.forget(_retval);
return NS_OK;
}
/* nsILoadContextInfo fromWindow (in nsIDOMWindow aWindow, in boolean aAnonymous); */
NS_IMETHODIMP LoadContextInfoFactory::FromWindow(nsIDOMWindow *aWindow, bool aAnonymous,
nsILoadContextInfo * *_retval)
{
nsCOMPtr<nsILoadContextInfo> info = GetLoadContextInfo(aWindow, aAnonymous);
info.forget(_retval);
return NS_OK;
}
// Helper functions
LoadContextInfo *
GetLoadContextInfo(nsIChannel * aChannel)
{
nsresult rv;
bool pb = NS_UsePrivateBrowsing(aChannel);
uint32_t appId;
bool ib;
if (!NS_GetAppInfo(aChannel, &appId, &ib)) {
appId = nsILoadContextInfo::NO_APP_ID;
ib = false;
}
bool anon = false;
nsLoadFlags loadFlags;
nsresult rv = aChannel->GetLoadFlags(&loadFlags);
if (NS_SUCCEEDED(rv))
rv = aChannel->GetLoadFlags(&loadFlags);
if (NS_SUCCEEDED(rv)) {
anon = !!(loadFlags & nsIChannel::LOAD_ANONYMOUS);
}
return new LoadContextInfo(pb, appId, ib, anon);
OriginAttributes oa;
NS_GetOriginAttributes(aChannel, oa);
return new LoadContextInfo(pb, anon, oa);
}
LoadContextInfo *
GetLoadContextInfo(nsILoadContext * aLoadContext, bool aIsAnonymous)
GetLoadContextInfo(nsILoadContext *aLoadContext, bool aIsAnonymous)
{
if (!aLoadContext)
return new LoadContextInfo(false, nsILoadContextInfo::NO_APP_ID, false, aIsAnonymous); // nullptr?
if (!aLoadContext) {
return new LoadContextInfo(false, aIsAnonymous,
OriginAttributes(nsILoadContextInfo::NO_APP_ID, false));
}
bool pb = aLoadContext->UsePrivateBrowsing();
OriginAttributes oa;
aLoadContext->GetOriginAttributes(oa);
bool ib;
nsresult rv = aLoadContext->GetIsInBrowserElement(&ib);
if (NS_FAILED(rv))
ib = false; // todo NS_WARNING...
return new LoadContextInfo(pb, aIsAnonymous, oa);
}
uint32_t appId;
rv = aLoadContext->GetAppId(&appId);
if (NS_FAILED(rv))
appId = nsILoadContextInfo::NO_APP_ID;
LoadContextInfo*
GetLoadContextInfo(nsIDOMWindow *aWindow,
bool aIsAnonymous)
{
nsCOMPtr<nsIWebNavigation> webNav = do_GetInterface(aWindow);
nsCOMPtr<nsILoadContext> loadContext = do_QueryInterface(webNav);
return new LoadContextInfo(pb, appId, ib, aIsAnonymous);
return GetLoadContextInfo(loadContext, aIsAnonymous);
}
LoadContextInfo *
GetLoadContextInfo(nsILoadContextInfo* aInfo)
GetLoadContextInfo(nsILoadContextInfo *aInfo)
{
return new LoadContextInfo(aInfo->IsPrivate(),
aInfo->AppId(),
aInfo->IsInBrowserElement(),
aInfo->IsAnonymous());
aInfo->IsAnonymous(),
*aInfo->OriginAttributesPtr());
}
LoadContextInfo *
GetLoadContextInfo(bool const aIsPrivate,
uint32_t const aAppId,
bool const aIsInBrowserElement,
bool const aIsAnonymous)
bool const aIsAnonymous,
OriginAttributes const &aOriginAttributes)
{
return new LoadContextInfo(aIsPrivate,
aAppId,
aIsInBrowserElement,
aIsAnonymous);
aIsAnonymous,
aOriginAttributes);
}
} // namespace net

View File

@ -19,33 +19,43 @@ public:
NS_DECL_THREADSAFE_ISUPPORTS
NS_DECL_NSILOADCONTEXTINFO
LoadContextInfo(bool aIsPrivate, uint32_t aAppId, bool aIsInBrowser, bool aIsAnonymous);
LoadContextInfo(bool aIsPrivate, bool aIsAnonymous, OriginAttributes aOriginAttributes);
private:
virtual ~LoadContextInfo();
protected:
uint32_t mAppId;
bool mIsPrivate : 1;
bool mIsInBrowser : 1;
bool mIsAnonymous : 1;
OriginAttributes mOriginAttributes;
};
LoadContextInfo *
GetLoadContextInfo(nsIChannel * aChannel);
class LoadContextInfoFactory : public nsILoadContextInfoFactory
{
virtual ~LoadContextInfoFactory() {}
public:
NS_DECL_ISUPPORTS // deliberately not thread-safe
NS_DECL_NSILOADCONTEXTINFOFACTORY
};
LoadContextInfo *
GetLoadContextInfo(nsILoadContext * aLoadContext,
bool aAnonymous);
LoadContextInfo*
GetLoadContextInfo(nsIChannel *aChannel);
LoadContextInfo *
GetLoadContextInfo(nsILoadContextInfo* aInfo);
LoadContextInfo*
GetLoadContextInfo(nsILoadContext *aLoadContext,
bool aIsAnonymous);
LoadContextInfo *
GetLoadContextInfo(bool const aIsPrivate = false,
uint32_t const aAppId = nsILoadContextInfo::NO_APP_ID,
bool const aIsInBrowserElement = false,
bool const aIsAnonymous = false);
LoadContextInfo*
GetLoadContextInfo(nsIDOMWindow *aLoadContext,
bool aIsAnonymous);
LoadContextInfo*
GetLoadContextInfo(nsILoadContextInfo *aInfo);
LoadContextInfo*
GetLoadContextInfo(bool const aIsPrivate,
bool const aIsAnonymous,
OriginAttributes const &aOriginAttributes);
} // namespace net
} // namespace mozilla

View File

@ -596,7 +596,7 @@ Predictor::Init()
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<LoadContextInfo> lci =
new LoadContextInfo(false, nsILoadContextInfo::NO_APP_ID, false, false);
new LoadContextInfo(false, false, OriginAttributes());
rv = cacheStorageService->DiskCacheStorage(lci, false,
getter_AddRefs(mCacheDiskStorage));

View File

@ -5,37 +5,45 @@
#include "nsISupports.idl"
%{ C++
#include "mozilla/BasePrincipal.h"
%}
native OriginAttributesNativePtr(const mozilla::OriginAttributes*);
interface nsILoadContext;
interface nsIDOMWindow;
/**
* Helper interface to carry informatin about the load context
* encapsulating an AppID, IsInBrowser and IsPrivite properties.
* encapsulating origin attributes and IsAnonymous, IsPrivite properties.
* It shall be used where nsILoadContext cannot be used or is not
* available.
*/
[scriptable, uuid(1ea9cbdb-9df4-46a0-8c45-f4091aad9459)]
[scriptable, builtinclass, uuid(555e2f8a-a1f6-41dd-88ca-ed4ed6b98a22)]
interface nsILoadContextInfo : nsISupports
{
const unsigned long NO_APP_ID = 0;
const unsigned long UNKNOWN_APP_ID = 4294967295; // UINT32_MAX
/**
* Whether the context is in a Private Browsing mode
*/
readonly attribute boolean isPrivate;
/**
* Whether the context belongs under an App
*/
const unsigned long NO_APP_ID = 0;
const unsigned long UNKNOWN_APP_ID = 4294967295; // UINT32_MAX
readonly attribute uint32_t appId;
/**
* Whether the context is in a browser tag
*/
readonly attribute boolean isInBrowserElement;
/**
* Whether the load is initiated as anonymous
*/
readonly attribute boolean isAnonymous;
/**
* OriginAttributes hiding all the security context attributes
*/
[implicit_jscontext]
readonly attribute jsval originAttributes;
[noscript, notxpcom, nostdcall, binaryname(OriginAttributesPtr)]
OriginAttributesNativePtr binaryOriginAttributesPtr();
%{C++
/**
* De-XPCOMed getters
@ -47,20 +55,6 @@ interface nsILoadContextInfo : nsISupports
return pb;
}
uint32_t AppId()
{
uint32_t appId;
GetAppId(&appId);
return appId;
}
bool IsInBrowserElement()
{
bool ib;
GetIsInBrowserElement(&ib);
return ib;
}
bool IsAnonymous()
{
bool anon;
@ -70,10 +64,27 @@ interface nsILoadContextInfo : nsISupports
bool Equals(nsILoadContextInfo *aOther)
{
return (IsPrivate() == aOther->IsPrivate() &&
AppId() == aOther->AppId() &&
IsInBrowserElement() == aOther->IsInBrowserElement() &&
IsAnonymous() == aOther->IsAnonymous());
return IsPrivate() == aOther->IsPrivate() &&
IsAnonymous() == aOther->IsAnonymous() &&
*OriginAttributesPtr() == *aOther->OriginAttributesPtr();
}
%}
};
/**
* Since OriginAttributes struct limits the implementation of
* nsILoadContextInfo (that needs to be thread safe) to C++,
* we need a scriptable factory to create instances of that
* interface from JS.
*/
[scriptable, uuid(c1c7023d-4318-4f99-8307-b5ccf0558793)]
interface nsILoadContextInfoFactory : nsISupports
{
readonly attribute nsILoadContextInfo default;
readonly attribute nsILoadContextInfo private;
readonly attribute nsILoadContextInfo anonymous;
[implicit_jscontext]
nsILoadContextInfo custom(in boolean aPrivate, in boolean aAnonymous, in jsval aOriginAttributes);
nsILoadContextInfo fromLoadContext(in nsILoadContext aLoadContext, in boolean aAnonymous);
nsILoadContextInfo fromWindow(in nsIDOMWindow aWindow, in boolean aAnonymous);
};

View File

@ -1081,4 +1081,17 @@
*/
#define NS_NSS_ERRORS_SERVICE_CONTRACTID "@mozilla.org/nss_errors_service;1"
/**
* LoadContextInfo factory
*/
#define NS_NSILOADCONTEXTINFOFACTORY_CONTRACTID \
"@mozilla.org/load-context-info-factory;1"
#define NS_NSILOADCONTEXTINFOFACTORY_CID \
{ /* 62d4b190-3642-4450-b019-d1c1fba56025 */ \
0x62d4b190, \
0x3642, \
0x4450, \
{0xb0, 0x19, 0xd1, 0xc1, 0xfb, 0xa5, 0x60, 0x25} \
}
#endif // nsNetCID_h__

View File

@ -131,6 +131,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(RedirectChannelRegistrar)
typedef mozilla::net::CacheStorageService CacheStorageService;
NS_GENERIC_FACTORY_CONSTRUCTOR(CacheStorageService)
#include "LoadContextInfo.h"
typedef mozilla::net::LoadContextInfoFactory LoadContextInfoFactory;
NS_GENERIC_FACTORY_CONSTRUCTOR(LoadContextInfoFactory)
///////////////////////////////////////////////////////////////////////////////
#include "mozilla/net/CaptivePortalService.h"
@ -834,6 +838,7 @@ NS_DEFINE_NAMED_CID(NS_NETWORK_LINK_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_SERIALIZATION_HELPER_CID);
NS_DEFINE_NAMED_CID(NS_REDIRECTCHANNELREGISTRAR_CID);
NS_DEFINE_NAMED_CID(NS_CACHE_STORAGE_SERVICE_CID);
NS_DEFINE_NAMED_CID(NS_NSILOADCONTEXTINFOFACTORY_CID);
NS_DEFINE_NAMED_CID(NS_NETWORKPREDICTOR_CID);
NS_DEFINE_NAMED_CID(NS_CAPTIVEPORTAL_CID);
NS_DEFINE_NAMED_CID(NS_SCHEDULINGCONTEXTSERVICE_CID);
@ -985,6 +990,7 @@ static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
{ &kNS_SERIALIZATION_HELPER_CID, false, nullptr, nsSerializationHelperConstructor },
{ &kNS_REDIRECTCHANNELREGISTRAR_CID, false, nullptr, RedirectChannelRegistrarConstructor },
{ &kNS_CACHE_STORAGE_SERVICE_CID, false, nullptr, CacheStorageServiceConstructor },
{ &kNS_NSILOADCONTEXTINFOFACTORY_CID, false, nullptr, LoadContextInfoFactoryConstructor },
{ &kNS_NETWORKPREDICTOR_CID, false, nullptr, mozilla::net::Predictor::Create },
{ &kNS_CAPTIVEPORTAL_CID, false, nullptr, mozilla::net::CaptivePortalServiceConstructor },
{ &kNS_SCHEDULINGCONTEXTSERVICE_CID, false, nullptr, SchedulingContextServiceConstructor },
@ -1142,6 +1148,7 @@ static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
{ NS_REDIRECTCHANNELREGISTRAR_CONTRACTID, &kNS_REDIRECTCHANNELREGISTRAR_CID },
{ NS_CACHE_STORAGE_SERVICE_CONTRACTID, &kNS_CACHE_STORAGE_SERVICE_CID },
{ NS_CACHE_STORAGE_SERVICE_CONTRACTID2, &kNS_CACHE_STORAGE_SERVICE_CID },
{ NS_NSILOADCONTEXTINFOFACTORY_CONTRACTID, &kNS_NSILOADCONTEXTINFOFACTORY_CID },
{ NS_NETWORKPREDICTOR_CONTRACTID, &kNS_NETWORKPREDICTOR_CID },
{ NS_CAPTIVEPORTAL_CONTRACTID, &kNS_CAPTIVEPORTAL_CID },
{ NS_SCHEDULINGCONTEXTSERVICE_CONTRACTID, &kNS_SCHEDULINGCONTEXTSERVICE_CID },

View File

@ -40,16 +40,12 @@ nsApplicationCacheService::BuildGroupID(nsIURI *aManifestURL,
{
nsresult rv;
uint32_t appId = NECKO_NO_APP_ID;
bool isInBrowserElement = false;
if (aLoadContextInfo) {
appId = aLoadContextInfo->AppId();
isInBrowserElement = aLoadContextInfo->IsInBrowserElement();
}
mozilla::OriginAttributes const *oa = aLoadContextInfo
? aLoadContextInfo->OriginAttributesPtr()
: nullptr;
rv = nsOfflineCacheDevice::BuildApplicationCacheGroupID(
aManifestURL, appId, isInBrowserElement, _result);
aManifestURL, oa, _result);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
@ -61,8 +57,11 @@ nsApplicationCacheService::BuildGroupIDForApp(nsIURI *aManifestURL,
bool aIsInBrowser,
nsACString &_result)
{
OriginAttributes oa;
oa.mAppId = aAppId;
oa.mInBrowser = aIsInBrowser;
nsresult rv = nsOfflineCacheDevice::BuildApplicationCacheGroupID(
aManifestURL, aAppId, aIsInBrowser, _result);
aManifestURL, &oa, _result);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;

View File

@ -46,6 +46,7 @@
using namespace mozilla;
using namespace mozilla::storage;
using mozilla::OriginAttributes;
static const char OFFLINE_CACHE_DEVICE_ID[] = { "offline" };
@ -1299,33 +1300,12 @@ GetGroupForCache(const nsCSubstring &clientID, nsCString &group)
return NS_OK;
}
nsresult
AppendJARIdentifier(nsACString &_result, int32_t appId, bool isInBrowserElement)
void
AppendJARIdentifier(nsACString &_result, OriginAttributes const *aOriginAttributes)
{
_result.Append('#');
_result.AppendInt(appId);
_result.Append('+');
_result.Append(isInBrowserElement ? 't' : 'f');
return NS_OK;
}
nsresult
GetJARIdentifier(nsIURI *aURI,
uint32_t appId, bool isInBrowserElement,
nsACString &_result)
{
_result.Truncate();
// These lines are here for compatibility only. We must not fill the
// JAR identifier when this is no-app context, otherwise web content
// offline application cache loads would not be satisfied (cache would
// not be found).
if (!isInBrowserElement && appId == NECKO_NO_APP_ID)
return NS_OK;
// This load context has some special attributes, create a jar identifier
return AppendJARIdentifier(_result, appId, isInBrowserElement);
nsAutoCString suffix;
aOriginAttributes->CreateSuffix(suffix);
_result.Append(suffix);
}
} // namespace
@ -1333,7 +1313,7 @@ GetJARIdentifier(nsIURI *aURI,
// static
nsresult
nsOfflineCacheDevice::BuildApplicationCacheGroupID(nsIURI *aManifestURL,
uint32_t appId, bool isInBrowserElement,
OriginAttributes const *aOriginAttributes,
nsACString &_result)
{
nsCOMPtr<nsIURI> newURI;
@ -1346,13 +1326,9 @@ nsOfflineCacheDevice::BuildApplicationCacheGroupID(nsIURI *aManifestURL,
_result.Assign(manifestSpec);
nsAutoCString jarid;
rv = GetJARIdentifier(aManifestURL, appId, isInBrowserElement, jarid);
NS_ENSURE_SUCCESS(rv, rv);
// Include JAR ID, i.e. the extended origin if present.
if (!jarid.IsEmpty())
_result.Append(jarid);
if (aOriginAttributes) {
AppendJARIdentifier(_result, aOriginAttributes);
}
return NS_OK;
}
@ -2430,9 +2406,17 @@ nsOfflineCacheDevice::DiscardByAppId(int32_t appID, bool browserEntriesOnly)
nsresult rv;
nsAutoCString jaridsuffix;
jaridsuffix.Append('%');
rv = AppendJARIdentifier(jaridsuffix, appID, browserEntriesOnly);
NS_ENSURE_SUCCESS(rv, rv);
// TODO - this method should accept OriginAttributes* from outside instead.
// If passed null, we should then delegate to
// nsCacheService::GlobalInstance()->EvictEntriesInternal(nsICache::STORE_OFFLINE);
OriginAttributes oa;
oa.mAppId = appID;
oa.mInBrowser = browserEntriesOnly;
AppendJARIdentifier(jaridsuffix, &oa);
{
AutoResetStatement statement(mStatement_EnumerateApps);
@ -2489,8 +2473,9 @@ nsOfflineCacheDevice::CanUseCache(nsIURI *keyURI,
nsCOMPtr<nsIURI> groupURI;
rv = NS_NewURI(getter_AddRefs(groupURI), groupID);
if (NS_FAILED(rv))
if (NS_FAILED(rv)) {
return false;
}
// When we are choosing an initial cache to load the top
// level document from, the URL of that document must have
@ -2499,28 +2484,24 @@ nsOfflineCacheDevice::CanUseCache(nsIURI *keyURI,
// and dynamic entries might have origin different from the
// manifest origin.
if (!NS_SecurityCompareURIs(keyURI, groupURI,
GetStrictFileOriginPolicy()))
GetStrictFileOriginPolicy())) {
return false;
// Get extended origin attributes
uint32_t appId = NECKO_NO_APP_ID;
bool isInBrowserElement = false;
if (loadContextInfo) {
appId = loadContextInfo->AppId();
isInBrowserElement = loadContextInfo->IsInBrowserElement();
}
// Check the groupID we found is equal to groupID based
// on the load context demanding load from app cache.
// This is check of extended origin.
nsAutoCString demandedGroupID;
rv = BuildApplicationCacheGroupID(groupURI, appId, isInBrowserElement,
demandedGroupID);
const OriginAttributes *oa = loadContextInfo
? loadContextInfo->OriginAttributesPtr()
: nullptr;
rv = BuildApplicationCacheGroupID(groupURI, oa, demandedGroupID);
NS_ENSURE_SUCCESS(rv, false);
if (groupID != demandedGroupID)
if (groupID != demandedGroupID) {
return false;
}
return true;
}

View File

@ -25,6 +25,7 @@
class nsIURI;
class nsOfflineCacheDevice;
class mozIStorageService;
namespace mozilla { class OriginAttributes; }
class nsApplicationCacheNamespace final : public nsIApplicationCacheNamespace
{
@ -140,7 +141,7 @@ public:
nsresult EvictUnownedEntries(const char *clientID);
static nsresult BuildApplicationCacheGroupID(nsIURI *aManifestURL,
uint32_t appId, bool isInBrowserElement,
mozilla::OriginAttributes const *aOriginAttributes,
nsACString &_result);
nsresult ActivateCache(const nsCSubstring &group,

View File

@ -124,9 +124,10 @@ NS_IMETHODIMP AppCacheStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCal
NS_ENSURE_SUCCESS(rv, rv);
if (!mAppCache) {
if (LoadInfo()->AppId() == nsILoadContextInfo::NO_APP_ID &&
!LoadInfo()->IsInBrowserElement()) {
// TODO - bug 1165256, have an API on nsIApplicationCacheService that takes
// optional OAs and decides internally what to do.
const OriginAttributes* oa = LoadInfo()->OriginAttributesPtr();
if (oa->mAppId == nsILoadContextInfo::NO_APP_ID && !oa->mInBrowser) {
// Clear everything.
nsCOMPtr<nsICacheService> serv =
do_GetService(NS_CACHESERVICE_CONTRACTID, &rv);
@ -137,8 +138,7 @@ NS_IMETHODIMP AppCacheStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCal
}
else {
// Clear app or inbrowser staff.
rv = appCacheService->DiscardByAppId(LoadInfo()->AppId(),
LoadInfo()->IsInBrowserElement());
rv = appCacheService->DiscardByAppId(oa->mAppId, oa->mInBrowser);
NS_ENSURE_SUCCESS(rv, rv);
}
}

View File

@ -1966,10 +1966,11 @@ CacheFile::InitIndexEntry()
nsresult rv;
// Bug 1201042 - will pass OriginAttributes directly.
rv = CacheFileIOManager::InitIndexEntry(mHandle,
mMetadata->AppId(),
mMetadata->OriginAttributes().mAppId,
mMetadata->IsAnonymous(),
mMetadata->IsInBrowser());
mMetadata->OriginAttributes().mInBrowser);
NS_ENSURE_SUCCESS(rv, rv);
uint32_t expTime;

View File

@ -2811,10 +2811,11 @@ CacheFileIOManager::EvictByContext(nsILoadContextInfo *aLoadContextInfo)
nsresult
CacheFileIOManager::EvictByContextInternal(nsILoadContextInfo *aLoadContextInfo)
{
nsAutoCString suffix;
aLoadContextInfo->OriginAttributesPtr()->CreateSuffix(suffix);
LOG(("CacheFileIOManager::EvictByContextInternal() [loadContextInfo=%p, "
"anonymous=%u, inBrowser=%u, appId=%u]", aLoadContextInfo,
aLoadContextInfo->IsAnonymous(), aLoadContextInfo->IsInBrowserElement(),
aLoadContextInfo->AppId()));
"anonymous=%u, suffix=%s]", aLoadContextInfo, aLoadContextInfo->IsAnonymous(),
suffix.get()));
nsresult rv;

View File

@ -54,10 +54,8 @@ CacheFileMetadata::CacheFileMetadata(CacheFileHandle *aHandle, const nsACString
, mElementsSize(0)
, mIsDirty(false)
, mAnonymous(false)
, mInBrowser(false)
, mAllocExactSize(false)
, mFirstRead(true)
, mAppId(nsILoadContextInfo::NO_APP_ID)
{
LOG(("CacheFileMetadata::CacheFileMetadata() [this=%p, handle=%p, key=%s]",
this, aHandle, PromiseFlatCString(aKey).get()));
@ -86,10 +84,8 @@ CacheFileMetadata::CacheFileMetadata(bool aMemoryOnly, const nsACString &aKey)
, mElementsSize(0)
, mIsDirty(true)
, mAnonymous(false)
, mInBrowser(false)
, mAllocExactSize(false)
, mFirstRead(true)
, mAppId(nsILoadContextInfo::NO_APP_ID)
{
LOG(("CacheFileMetadata::CacheFileMetadata() [this=%p, key=%s]",
this, PromiseFlatCString(aKey).get()));
@ -119,10 +115,8 @@ CacheFileMetadata::CacheFileMetadata()
, mElementsSize(0)
, mIsDirty(false)
, mAnonymous(false)
, mInBrowser(false)
, mAllocExactSize(false)
, mFirstRead(true)
, mAppId(nsILoadContextInfo::NO_APP_ID)
{
LOG(("CacheFileMetadata::CacheFileMetadata() [this=%p]", this));
@ -1017,8 +1011,7 @@ CacheFileMetadata::ParseKey(const nsACString &aKey)
NS_ENSURE_TRUE(info, NS_ERROR_FAILURE);
mAnonymous = info->IsAnonymous();
mAppId = info->AppId();
mInBrowser = info->IsInBrowserElement();
mOriginAttributes = *info->OriginAttributesPtr();
return NS_OK;
}

View File

@ -10,6 +10,7 @@
#include "CacheHashUtils.h"
#include "CacheObserver.h"
#include "mozilla/Endian.h"
#include "mozilla/BasePrincipal.h"
#include "nsAutoPtr.h"
#include "nsString.h"
@ -127,8 +128,7 @@ public:
nsresult SyncReadMetadata(nsIFile *aFile);
bool IsAnonymous() { return mAnonymous; }
bool IsInBrowser() { return mInBrowser; }
uint32_t AppId() { return mAppId; }
mozilla::OriginAttributes const & OriginAttributes() const { return mOriginAttributes; }
const char * GetElement(const char *aKey);
nsresult SetElement(const char *aKey, const char *aValue);
@ -189,11 +189,10 @@ private:
uint32_t mElementsSize;
bool mIsDirty : 1;
bool mAnonymous : 1;
bool mInBrowser : 1;
bool mAllocExactSize : 1;
bool mFirstRead : 1;
mozilla::OriginAttributes mOriginAttributes;
mozilla::TimeStamp mReadStart;
uint32_t mAppId;
nsCOMPtr<CacheFileMetadataListener> mListener;
};

View File

@ -5,6 +5,7 @@
#include "CacheLog.h"
#include "CacheFileUtils.h"
#include "LoadContextInfo.h"
#include "mozilla/Tokenizer.h"
#include "nsCOMPtr.h"
#include "nsAutoPtr.h"
#include "nsString.h"
@ -20,174 +21,152 @@ namespace {
/**
* A simple recursive descent parser for the mapping key.
*/
class KeyParser
class KeyParser : protected Tokenizer
{
public:
KeyParser(nsACString::const_iterator aCaret, nsACString::const_iterator aEnd)
: caret(aCaret)
, end(aEnd)
explicit KeyParser(nsACString const& aInput)
: Tokenizer(aInput)
// Initialize attributes to their default values
, appId(nsILoadContextInfo::NO_APP_ID)
, originAttribs(0, false)
, isPrivate(false)
, isInBrowser(false)
, isAnonymous(false)
// Initialize the cache key to a zero length by default
, cacheKey(aEnd)
, lastTag(0)
{
}
private:
// Current character being parsed
nsACString::const_iterator caret;
// The end of the buffer
nsACString::const_iterator const end;
// Results
uint32_t appId;
OriginAttributes originAttribs;
bool isPrivate;
bool isInBrowser;
bool isAnonymous;
nsCString idEnhance;
// Position of the cache key, if present
nsACString::const_iterator cacheKey;
nsDependentCSubstring cacheKey;
// Keeps the last tag name, used for alphabetical sort checking
char lastTag;
// Classifier for the 'tag' character valid range
static bool TagChar(const char aChar)
{
return aChar >= ' ' && aChar <= '~';
}
bool ParseTags()
{
// Expects to be at the tag name or at the end
if (caret == end)
if (CheckEOF()) {
return true;
}
// 'Read' the tag name and move to the next char
char const tag = *caret++;
// Check the alphabetical order, hard-fail on disobedience
if (!(lastTag < tag || tag == ':'))
char tag;
if (!ReadChar(&TagChar, &tag)) {
return false;
}
// Check the alphabetical order, hard-fail on disobedience
if (!(lastTag < tag || tag == ':')) {
return false;
}
lastTag = tag;
switch (tag) {
case ':':
// last possible tag, when present there is the cacheKey following,
// not terminated with ',' and no need to unescape.
cacheKey = caret;
caret = end;
cacheKey.Rebind(mCursor, mEnd - mCursor);
return true;
case 'O': {
nsAutoCString originSuffix;
if (!ParseValue(&originSuffix) || !originAttribs.PopulateFromSuffix(originSuffix)) {
return false;
}
break;
}
case 'p':
isPrivate = true;
break;
case 'b':
isInBrowser = true;
// Leaving to be able to read and understand oldformatted entries
originAttribs.mInBrowser = true;
break;
case 'a':
isAnonymous = true;
break;
case 'i': {
nsAutoCString appIdString;
if (!ParseValue(&appIdString))
return false;
nsresult rv;
int64_t appId64 = appIdString.ToInteger64(&rv);
if (NS_FAILED(rv))
return false; // appid value is mandatory
if (appId64 < 0 || appId64 > PR_UINT32_MAX)
return false; // not in the range
appId = static_cast<uint32_t>(appId64);
// Leaving to be able to read and understand oldformatted entries
if (!ReadInteger(&originAttribs.mAppId)) {
return false; // not a valid 32-bit integer
}
break;
}
case '~':
if (!ParseValue(&idEnhance))
if (!ParseValue(&idEnhance)) {
return false;
}
break;
default:
if (!ParseValue()) // skip any tag values, optional
if (!ParseValue()) { // skip any tag values, optional
return false;
}
break;
}
// Recurse to the next tag
return ParseNextTagOrEnd();
}
bool ParseNextTagOrEnd()
{
// We expect a comma after every tag
if (caret == end || *caret++ != ',')
if (!CheckChar(',')) {
return false;
}
// Go to another tag
// Recurse to the next tag
return ParseTags();
}
bool ParseValue(nsACString * result = nullptr)
bool ParseValue(nsACString *result = nullptr)
{
// If at the end, fail since we expect a comma ; value may be empty tho
if (caret == end)
if (CheckEOF()) {
return false;
}
// Remeber where the value starts
nsACString::const_iterator val = caret;
nsACString::const_iterator comma = end;
bool escape = false;
while (caret != end) {
nsACString::const_iterator at = caret;
++caret; // we can safely break/continue the loop now
if (*at == ',') {
if (comma != end) {
// another comma (we have found ",," -> escape)
comma = end;
escape = true;
} else {
comma = at;
Token t;
while (Next(t)) {
if (!Token::Char(',').Equals(t)) {
if (result) {
result->Append(t.Fragment());
}
continue;
}
if (comma != end) {
// after a single comma
break;
if (CheckChar(',')) {
// Two commas in a row, escaping
if (result) {
result->Append(',');
}
continue;
}
// We must give the comma back since the upper calls expect it
Rollback();
return true;
}
// At this point |comma| points to the last and lone ',' we've hit.
// If a lone comma was not found, |comma| is at the end of the buffer,
// that is not expected and we return failure.
caret = comma;
if (result) {
if (escape) {
// No ReplaceSubstring on nsACString..
nsAutoCString _result(Substring(val, caret));
_result.ReplaceSubstring(NS_LITERAL_CSTRING(",,"), NS_LITERAL_CSTRING(","));
result->Assign(_result);
} else {
result->Assign(Substring(val, caret));
}
}
return caret != end;
return false;
}
public:
already_AddRefed<LoadContextInfo> Parse()
{
nsRefPtr<LoadContextInfo> info;
if (ParseTags())
info = GetLoadContextInfo(isPrivate, appId, isInBrowser, isAnonymous);
if (ParseTags()) {
info = GetLoadContextInfo(isPrivate, isAnonymous, originAttribs);
}
return info.forget();
}
void URISpec(nsACString &result)
{
// cacheKey is either pointing to end or the position where the cache key is.
result.Assign(Substring(cacheKey, end));
result.Assign(cacheKey);
}
void IdEnhance(nsACString &result)
@ -203,11 +182,7 @@ ParseKey(const nsCSubstring &aKey,
nsCSubstring *aIdEnhance,
nsCSubstring *aURISpec)
{
nsACString::const_iterator caret, end;
aKey.BeginReading(caret);
aKey.EndReading(end);
KeyParser parser(caret, end);
KeyParser parser(aKey);
nsRefPtr<LoadContextInfo> info = parser.Parse();
if (info) {
@ -231,20 +206,17 @@ AppendKeyPrefix(nsILoadContextInfo* aInfo, nsACString &_retval)
* Keep the attributes list sorted according their ASCII code.
*/
OriginAttributes const *oa = aInfo->OriginAttributesPtr();
nsAutoCString suffix;
oa->CreateSuffix(suffix);
if (!suffix.IsEmpty()) {
AppendTagWithValue(_retval, 'O', suffix);
}
if (aInfo->IsAnonymous()) {
_retval.AppendLiteral("a,");
}
if (aInfo->IsInBrowserElement()) {
_retval.AppendLiteral("b,");
}
if (aInfo->AppId() != nsILoadContextInfo::NO_APP_ID) {
_retval.Append('i');
_retval.AppendInt(aInfo->AppId());
_retval.Append(',');
}
if (aInfo->IsPrivate()) {
_retval.AppendLiteral("p,");
}

View File

@ -2571,8 +2571,11 @@ CacheIndex::InitEntryFromDiskData(CacheIndexEntry *aEntry,
aEntry->InitNew();
aEntry->MarkDirty();
aEntry->MarkFresh();
aEntry->Init(aMetaData->AppId(), aMetaData->IsAnonymous(),
aMetaData->IsInBrowser());
// Bug 1201042 - will pass OriginAttributes directly.
aEntry->Init(aMetaData->OriginAttributes().mAppId,
aMetaData->IsAnonymous(),
aMetaData->OriginAttributes().mInBrowser);
uint32_t expirationTime;
aMetaData->GetExpirationTime(&expirationTime);

View File

@ -259,9 +259,9 @@ public:
nsILoadContextInfo *aInfo)
{
if (!aInfo->IsPrivate() &&
aInfo->AppId() == aRec->mAppId &&
aInfo->OriginAttributesPtr()->mAppId == aRec->mAppId &&
aInfo->IsAnonymous() == !!(aRec->mFlags & kAnonymousMask) &&
aInfo->IsInBrowserElement() == !!(aRec->mFlags & kInBrowserMask)) {
aInfo->OriginAttributesPtr()->mInBrowser == !!(aRec->mFlags & kInBrowserMask)) {
return true;
}

View File

@ -9,7 +9,6 @@
#include "LoadContextInfo.h"
#include "nsICacheStorage.h"
#include "nsIObserverService.h"
#include "mozIApplicationClearPrivateDataParams.h"
#include "mozilla/Services.h"
#include "mozilla/Preferences.h"
#include "nsServiceManagerUtils.h"
@ -118,7 +117,7 @@ CacheObserver::Init()
obs->AddObserver(sSelf, "profile-before-change", true);
obs->AddObserver(sSelf, "xpcom-shutdown", true);
obs->AddObserver(sSelf, "last-pb-context-exited", true);
obs->AddObserver(sSelf, "webapps-clear-data", true);
obs->AddObserver(sSelf, "clear-origin-data", true);
obs->AddObserver(sSelf, "memory-pressure", true);
return NS_OK;
@ -392,55 +391,15 @@ void CacheObserver::ParentDirOverride(nsIFile** aDir)
}
namespace {
namespace CacheStorageEvictHelper {
class CacheStorageEvictHelper
{
public:
nsresult Run(mozIApplicationClearPrivateDataParams* aParams);
private:
uint32_t mAppId;
nsresult ClearStorage(bool const aPrivate,
bool const aInBrowser,
bool const aAnonymous);
};
nsresult
CacheStorageEvictHelper::Run(mozIApplicationClearPrivateDataParams* aParams)
nsresult ClearStorage(bool const aPrivate,
bool const aAnonymous,
OriginAttributes const &aOa)
{
nsresult rv;
rv = aParams->GetAppId(&mAppId);
NS_ENSURE_SUCCESS(rv, rv);
bool aBrowserOnly;
rv = aParams->GetBrowserOnly(&aBrowserOnly);
NS_ENSURE_SUCCESS(rv, rv);
MOZ_ASSERT(mAppId != nsILoadContextInfo::UNKNOWN_APP_ID);
// Clear all [private X anonymous] combinations
rv = ClearStorage(false, aBrowserOnly, false);
NS_ENSURE_SUCCESS(rv, rv);
rv = ClearStorage(false, aBrowserOnly, true);
NS_ENSURE_SUCCESS(rv, rv);
rv = ClearStorage(true, aBrowserOnly, false);
NS_ENSURE_SUCCESS(rv, rv);
rv = ClearStorage(true, aBrowserOnly, true);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
nsresult
CacheStorageEvictHelper::ClearStorage(bool const aPrivate,
bool const aInBrowser,
bool const aAnonymous)
{
nsresult rv;
nsRefPtr<LoadContextInfo> info = GetLoadContextInfo(
aPrivate, mAppId, aInBrowser, aAnonymous);
nsRefPtr<LoadContextInfo> info = GetLoadContextInfo(aPrivate, aAnonymous, aOa);
nsCOMPtr<nsICacheStorage> storage;
nsRefPtr<CacheStorageService> service = CacheStorageService::Self();
@ -458,15 +417,28 @@ CacheStorageEvictHelper::ClearStorage(bool const aPrivate,
rv = storage->AsyncEvictStorage(nullptr);
NS_ENSURE_SUCCESS(rv, rv);
if (!aInBrowser) {
rv = ClearStorage(aPrivate, true, aAnonymous);
NS_ENSURE_SUCCESS(rv, rv);
}
return NS_OK;
}
nsresult Run(OriginAttributes const &aOa)
{
nsresult rv;
// Clear all [private X anonymous] combinations
rv = ClearStorage(false, false, aOa);
NS_ENSURE_SUCCESS(rv, rv);
rv = ClearStorage(false, true, aOa);
NS_ENSURE_SUCCESS(rv, rv);
rv = ClearStorage(true, false, aOa);
NS_ENSURE_SUCCESS(rv, rv);
rv = ClearStorage(true, true, aOa);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
} // namespace
} // CacheStorageEvictHelper
} // anon
// static
bool const CacheObserver::EntryIsTooBig(int64_t aSize, bool aUsingDisk)
@ -542,16 +514,14 @@ CacheObserver::Observe(nsISupports* aSubject,
return NS_OK;
}
if (!strcmp(aTopic, "webapps-clear-data")) {
nsCOMPtr<mozIApplicationClearPrivateDataParams> params =
do_QueryInterface(aSubject);
if (!params) {
NS_ERROR("'webapps-clear-data' notification's subject should be a mozIApplicationClearPrivateDataParams");
return NS_ERROR_UNEXPECTED;
if (!strcmp(aTopic, "clear-origin-data")) {
OriginAttributes oa;
if (!oa.Init(nsDependentString(aData))) {
NS_ERROR("Could not parse OriginAttributes JSON in clear-origin-data notification");
return NS_OK;
}
CacheStorageEvictHelper helper;
nsresult rv = helper.Run(params);
nsresult rv = CacheStorageEvictHelper::Run(oa);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;

View File

@ -528,8 +528,7 @@ GetCacheSessionNameForStoragePolicy(
nsCSubstring const &scheme,
nsCacheStoragePolicy storagePolicy,
bool isPrivate,
uint32_t appId,
bool inBrowser,
OriginAttributes const *originAttribs,
nsACString& sessionName)
{
MOZ_ASSERT(!isPrivate || storagePolicy == nsICache::STORE_IN_MEMORY);
@ -582,12 +581,9 @@ GetCacheSessionNameForStoragePolicy(
sessionName.AppendLiteral("-private");
}
if (appId != nsILoadContextInfo::NO_APP_ID || inBrowser) {
sessionName.Append('~');
sessionName.AppendInt(appId);
sessionName.Append('~');
sessionName.AppendInt(inBrowser);
}
nsAutoCString suffix;
originAttribs->CreateSuffix(suffix);
sessionName.Append(suffix);
return NS_OK;
}
@ -618,8 +614,7 @@ GetCacheSession(nsCSubstring const &aScheme,
aScheme,
storagePolicy,
aLoadInfo->IsPrivate(),
aLoadInfo->AppId(),
aLoadInfo->IsInBrowserElement(),
aLoadInfo->OriginAttributesPtr(),
clientId);
NS_ENSURE_SUCCESS(rv, rv);
}
@ -1000,9 +995,12 @@ NS_IMETHODIMP _OldStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCallbac
nsresult rv;
if (!mAppCache && mOfflineStorage) {
// TODO - bug 1165256, have an API on nsIApplicationCacheService that takes
// optional OAs and decides internally what to do.
// Special casing for pure offline storage
if (mLoadInfo->AppId() == nsILoadContextInfo::NO_APP_ID &&
!mLoadInfo->IsInBrowserElement()) {
if (mLoadInfo->OriginAttributesPtr()->mAppId == nsILoadContextInfo::NO_APP_ID &&
!mLoadInfo->OriginAttributesPtr()->mInBrowser) {
// Clear everything.
nsCOMPtr<nsICacheService> serv =
@ -1018,8 +1016,8 @@ NS_IMETHODIMP _OldStorage::AsyncEvictStorage(nsICacheEntryDoomCallback* aCallbac
do_GetService(NS_APPLICATIONCACHESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = appCacheService->DiscardByAppId(mLoadInfo->AppId(),
mLoadInfo->IsInBrowserElement());
rv = appCacheService->DiscardByAppId(mLoadInfo->OriginAttributesPtr()->mAppId,
mLoadInfo->OriginAttributesPtr()->mInBrowser);
NS_ENSURE_SUCCESS(rv, rv);
}
}

View File

@ -2914,7 +2914,6 @@ nsHttpChannel::OpenCacheEntry(bool isHttps)
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<LoadContextInfo> info = GetLoadContextInfo(this);
nsCOMPtr<nsICacheStorage> cacheStorage;
nsCOMPtr<nsIURI> openURI;
if (!mFallbackKey.IsEmpty() && mFallbackChannel) {
@ -2934,7 +2933,12 @@ nsHttpChannel::OpenCacheEntry(bool isHttps)
}
}
uint32_t appId = info->AppId();
nsRefPtr<LoadContextInfo> info = GetLoadContextInfo(this);
if (!info) {
return NS_ERROR_FAILURE;
}
uint32_t appId = info->OriginAttributesPtr()->mAppId;
bool appOffline = false;
if (appId != NECKO_NO_APP_ID) {

View File

@ -26,6 +26,7 @@
#include "nsIURI.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/unused.h"
#include "mozilla/BasePrincipal.h"
#include "nsProxyRelease.h"
#include "nsContentSecurityManager.h"
@ -100,9 +101,7 @@ nsWyciwygChannel::nsWyciwygChannel()
mNeedToWriteCharset(false),
mCharsetSource(kCharsetUninitialized),
mContentLength(-1),
mLoadFlags(LOAD_NORMAL),
mAppId(NECKO_NO_APP_ID),
mInBrowser(false)
mLoadFlags(LOAD_NORMAL)
{
}
@ -233,7 +232,8 @@ nsWyciwygChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
NS_GET_IID(nsIProgressEventSink),
getter_AddRefs(mProgressSink));
mPrivateBrowsing = NS_UsePrivateBrowsing(this);
NS_GetAppInfo(this, &mAppId, &mInBrowser);
NS_GetOriginAttributes(this, mOriginAttributes);
return NS_OK;
}
@ -329,7 +329,7 @@ nsWyciwygChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationC
getter_AddRefs(mProgressSink));
mPrivateBrowsing = NS_UsePrivateBrowsing(this);
NS_GetAppInfo(this, &mAppId, &mInBrowser);
NS_GetOriginAttributes(this, mOriginAttributes);
return NS_OK;
}
@ -796,7 +796,7 @@ nsWyciwygChannel::OpenCacheEntry(nsIURI *aURI,
bool anonymous = mLoadFlags & LOAD_ANONYMOUS;
nsRefPtr<LoadContextInfo> loadInfo = mozilla::net::GetLoadContextInfo(
mPrivateBrowsing, mAppId, mInBrowser, anonymous);
mPrivateBrowsing, anonymous, mOriginAttributes);
nsCOMPtr<nsICacheStorage> cacheStorage;
if (mLoadFlags & INHIBIT_PERSISTENT_CACHING)

View File

@ -15,6 +15,7 @@
#include "nsIStreamListener.h"
#include "nsICacheEntryOpenCallback.h"
#include "PrivateBrowsingChannel.h"
#include "mozilla/BasePrincipal.h"
class nsICacheEntry;
class nsIEventTarget;
@ -86,8 +87,7 @@ protected:
nsCString mCharset;
int64_t mContentLength;
uint32_t mLoadFlags;
uint32_t mAppId;
bool mInBrowser;
mozilla::OriginAttributes mOriginAttributes;
nsCOMPtr<nsIURI> mURI;
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsISupports> mOwner;

View File

@ -19,7 +19,7 @@ var Cc = SpecialPowers.Cc;
var Ci = SpecialPowers.Ci;
var Cu = SpecialPowers.Cu;
var Cr = SpecialPowers.Cr;
var LoadContextInfo = Cu.import("resource://gre/modules/LoadContextInfo.jsm", {}).LoadContextInfo;
var LoadContextInfo = Cc["@mozilla.org/load-context-info-factory;1"].getService(Ci.nsILoadContextInfoFactory);
var CommonUtils = Cu.import("resource://services-common/utils.js", {}).CommonUtils;
function CacheCallback(expect) {
@ -43,7 +43,7 @@ CacheCallback.prototype = {
};
function checkCacheEntry(url, exists, appId) {
var loadContext = appId ? LoadContextInfo.custom(false, false, appId, false) : LoadContextInfo.default;
var loadContext = appId ? LoadContextInfo.custom(false, false, {appId: appId}) : LoadContextInfo.default;
var cacheService = Cc["@mozilla.org/netwerk/cache-storage-service;1"]
.getService(Ci.nsICacheStorageService);
var cache = cacheService.diskCacheStorage(loadContext, false);

View File

@ -47,7 +47,7 @@ function store_entries(cb)
asyncOpenCacheEntry(entries[store_idx][0],
entries[store_idx][2],
Ci.nsICacheStorage.OPEN_TRUNCATE,
LoadContextInfo.custom(!entries[store_idx][3]),
LoadContextInfo.custom(!entries[store_idx][3], false, {}),
store_data,
appCache);
}
@ -87,7 +87,7 @@ function check_entries(cb, pbExited)
asyncOpenCacheEntry(entries[check_idx][0],
entries[check_idx][2],
Ci.nsICacheStorage.OPEN_READONLY,
LoadContextInfo.custom(!entries[check_idx][3]),
LoadContextInfo.custom(!entries[check_idx][3], false, {}),
check_data,
appCache);
}

View File

@ -63,12 +63,10 @@ function run_all_tests() {
if (procType != Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT)
return;
let subject = {
appId: 1,
browserOnly: true,
QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams])
};
Services.obs.notifyObservers(subject, "webapps-clear-data", null);
let attrs_inBrowser = JSON.stringify({ appId:1, inBrowser:true });
let attrs_notInBrowser = JSON.stringify({ appId:1 });
Services.obs.notifyObservers(null, "clear-origin-data", attrs_inBrowser);
for (let test of secondTests) {
handlers_called = 0;
@ -77,12 +75,8 @@ function run_all_tests() {
yield undefined;
}
subject = {
appId: 1,
browserOnly: false,
QueryInterface: XPCOMUtils.generateQI([Ci.mozIApplicationClearPrivateDataParams])
};
Services.obs.notifyObservers(subject, "webapps-clear-data", null);
Services.obs.notifyObservers(null, "clear-origin-data", attrs_notInBrowser);
Services.obs.notifyObservers(null, "clear-origin-data", attrs_inBrowser);
for (let test of thirdTests) {
handlers_called = 0;

View File

@ -4,6 +4,7 @@ var Cu = Components.utils;
var Cr = Components.results;
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/LoadContextInfo.jsm");
var running_single_process = false;
@ -150,21 +151,7 @@ var prepListener = {
};
function open_and_continue(uris, continueCallback) {
var lci = {
QueryInterface: function (iid) {
if (iid.equals(Ci.nsILoadContextInfo)) {
return this;
}
throw Cr.NS_ERROR_NO_INTERFACE;
},
isPrivate: false,
appId: Ci.nsILoadContextInfo.NO_APP_ID,
isInBrowserElement: false,
isAnonymous: false
};
var ds = Services.cache2.diskCacheStorage(lci, false);
var ds = Services.cache2.diskCacheStorage(LoadContextInfo.default, false);
prepListener.init(uris.length, continueCallback);
for (var i = 0; i < uris.length; ++i) {

View File

@ -2,68 +2,14 @@
* 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/. */
/**
* This jsm is here only for compatibility. Extension developers may use it
* to build nsILoadContextInfo to pass down to HTTP cache APIs. Originally
* it was possible to implement nsILoadContextInfo in JS. But now it turned
* out to be a built-in class only, so we need a component (service) as
* a factory to build nsILoadContextInfo in a JS code.
*/
this.EXPORTED_SYMBOLS = ["LoadContextInfo"];
const Ci = Components.interfaces;
const Cc = Components.classes;
const Cr = Components.results;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
this.LoadContextInfo = {};
_LoadContextInfo.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsILoadContextInfo, Ci.nsISupports]),
get isPrivate() { return this._isPrivate },
get isAnonymous() { return this._isAnonymous },
get isInBrowserElement() { return this._isInBrowserElement },
get appId() { return this._appId }
}
function _LoadContextInfo(_private, _anonymous, _appId, _inBrowser) {
this._isPrivate = _private || false;
this._isAnonymous = _anonymous || false;
this._appId = _appId || 0;
this._isInBrowserElement = _inBrowser || false;
}
// LoadContextInfo.default
// Non-private, non-anonymous, no app ID, not in browser
XPCOMUtils.defineLazyGetter(LoadContextInfo, "default", function () {
return new _LoadContextInfo(false, false, 0, false);
});
// LoadContextInfo.private
// Private, non-anonymous, no app ID, not in browser
XPCOMUtils.defineLazyGetter(LoadContextInfo, "private", function () {
return new _LoadContextInfo(true, false, 0, false);
});
// LoadContextInfo.anonymous
// Non-private, anonymous, no app ID, not in browser
XPCOMUtils.defineLazyGetter(LoadContextInfo, "anonymous", function () {
return new _LoadContextInfo(false, true, 0, false);
});
// Fully customizable
LoadContextInfo.custom = function(_private, _anonymous, _appId, _inBrowser) {
return new _LoadContextInfo(_private, _anonymous, _appId, _inBrowser);
}
// Copies info from provided nsILoadContext
LoadContextInfo.fromLoadContext = function(_loadContext, _anonymous) {
return new _LoadContextInfo(_loadContext.usePrivateBrowsing,
_anonymous,
_loadContext.appId,
_loadContext.isInBrowserElement);
}
// Copies info from provided window object
LoadContextInfo.fromWindow = function(_window, _anonymous) {
var loadContext = PrivateBrowsingUtils.privacyContextFromWindow(_window);
return this.fromLoadContext(loadContext, _anonymous);
}
this.LoadContextInfo = Components.classes["@mozilla.org/load-context-info-factory;1"]
.getService(Components.interfaces.nsILoadContextInfoFactory);

View File

@ -101,6 +101,7 @@ var initTable = [
["uriFixup", "@mozilla.org/docshell/urifixup;1", "nsIURIFixup"],
["blocklist", "@mozilla.org/extensions/blocklist;1", "nsIBlocklistService"],
["netUtils", "@mozilla.org/network/util;1", "nsINetUtil"],
["loadContextInfo", "@mozilla.org/load-context-info-factory;1", "nsILoadContextInfoFactory"],
];
initTable.forEach(([name, contract, intf, enabled = true]) => {