2013-06-06 23:59:32 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2017-05-06 23:17:52 +03:00
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
2001-03-29 06:11:48 +04:00
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
#ifndef mozilla_PermissionManager_h
|
|
|
|
#define mozilla_PermissionManager_h
|
2001-03-29 06:11:48 +04:00
|
|
|
|
|
|
|
#include "nsIPermissionManager.h"
|
2020-07-13 23:18:40 +03:00
|
|
|
#include "nsIAsyncShutdown.h"
|
2001-03-29 06:11:48 +04:00
|
|
|
#include "nsIObserver.h"
|
|
|
|
#include "nsWeakReference.h"
|
2001-10-19 06:28:06 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2003-04-23 03:33:31 +04:00
|
|
|
#include "nsTHashtable.h"
|
2007-12-05 09:37:36 +03:00
|
|
|
#include "nsTArray.h"
|
2003-04-23 03:33:31 +04:00
|
|
|
#include "nsString.h"
|
2012-08-23 22:47:55 +04:00
|
|
|
#include "nsHashKeys.h"
|
2017-04-11 23:36:37 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2020-04-11 16:41:19 +03:00
|
|
|
#include "mozilla/Atomics.h"
|
|
|
|
#include "mozilla/Monitor.h"
|
2017-04-11 23:36:37 +03:00
|
|
|
#include "mozilla/MozPromise.h"
|
2020-04-11 16:41:19 +03:00
|
|
|
#include "mozilla/ThreadBound.h"
|
2019-02-22 01:54:26 +03:00
|
|
|
#include "mozilla/Variant.h"
|
2019-02-22 01:54:16 +03:00
|
|
|
#include "mozilla/Vector.h"
|
2001-03-29 06:11:48 +04:00
|
|
|
|
2020-03-17 15:42:12 +03:00
|
|
|
#include <utility>
|
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
class mozIStorageConnection;
|
|
|
|
class mozIStorageStatement;
|
2020-04-11 16:42:30 +03:00
|
|
|
class nsIInputStream;
|
|
|
|
class nsIPermission;
|
|
|
|
class nsIPrefBranch;
|
2020-04-11 16:42:12 +03:00
|
|
|
|
2019-11-18 01:22:34 +03:00
|
|
|
namespace IPC {
|
|
|
|
struct Permission;
|
|
|
|
}
|
|
|
|
|
2015-10-13 05:27:42 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class OriginAttributesPattern;
|
2020-04-11 16:41:19 +03:00
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class ContentChild;
|
2020-04-11 16:42:12 +03:00
|
|
|
} // namespace dom
|
2003-10-22 10:53:19 +04:00
|
|
|
|
2001-03-29 06:11:48 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
class PermissionManager final : public nsIPermissionManager,
|
|
|
|
public nsIObserver,
|
2020-07-13 23:18:40 +03:00
|
|
|
public nsSupportsWeakReference,
|
|
|
|
public nsIAsyncShutdownBlocker {
|
2020-04-11 16:42:12 +03:00
|
|
|
friend class dom::ContentChild;
|
2020-04-11 16:41:19 +03:00
|
|
|
|
2003-04-23 03:33:31 +04:00
|
|
|
public:
|
2012-08-23 22:47:55 +04:00
|
|
|
class PermissionEntry {
|
|
|
|
public:
|
|
|
|
PermissionEntry(int64_t aID, uint32_t aType, uint32_t aPermission,
|
2014-09-15 05:33:12 +04:00
|
|
|
uint32_t aExpireType, int64_t aExpireTime,
|
|
|
|
int64_t aModificationTime)
|
2012-08-23 22:47:55 +04:00
|
|
|
: mID(aID),
|
2019-03-11 21:36:44 +03:00
|
|
|
mExpireTime(aExpireTime),
|
|
|
|
mModificationTime(aModificationTime),
|
2012-08-23 22:47:55 +04:00
|
|
|
mType(aType),
|
|
|
|
mPermission(aPermission),
|
|
|
|
mExpireType(aExpireType),
|
2013-01-06 02:02:29 +04:00
|
|
|
mNonSessionPermission(aPermission),
|
2013-01-08 06:29:22 +04:00
|
|
|
mNonSessionExpireType(aExpireType),
|
2013-06-06 23:59:32 +04:00
|
|
|
mNonSessionExpireTime(aExpireTime) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-23 22:47:55 +04:00
|
|
|
int64_t mID;
|
2019-03-11 21:36:44 +03:00
|
|
|
int64_t mExpireTime;
|
|
|
|
int64_t mModificationTime;
|
2012-08-23 22:47:55 +04:00
|
|
|
uint32_t mType;
|
|
|
|
uint32_t mPermission;
|
|
|
|
uint32_t mExpireType;
|
2013-01-06 02:02:29 +04:00
|
|
|
uint32_t mNonSessionPermission;
|
2013-01-08 06:29:22 +04:00
|
|
|
uint32_t mNonSessionExpireType;
|
2013-06-06 23:59:32 +04:00
|
|
|
uint32_t mNonSessionExpireTime;
|
2012-08-23 22:47:55 +04:00
|
|
|
};
|
2003-07-09 04:20:57 +04:00
|
|
|
|
2012-08-23 22:47:55 +04:00
|
|
|
/**
|
|
|
|
* PermissionKey is the key used by PermissionHashKey hash table.
|
|
|
|
*/
|
|
|
|
class PermissionKey {
|
|
|
|
public:
|
2016-12-08 23:45:52 +03:00
|
|
|
static PermissionKey* CreateFromPrincipal(nsIPrincipal* aPrincipal,
|
2020-01-08 16:06:28 +03:00
|
|
|
bool aForceStripOA,
|
2016-12-08 23:45:52 +03:00
|
|
|
nsresult& aResult);
|
2017-05-06 23:17:52 +03:00
|
|
|
static PermissionKey* CreateFromURI(nsIURI* aURI, nsresult& aResult);
|
2019-09-19 20:07:22 +03:00
|
|
|
static PermissionKey* CreateFromURIAndOriginAttributes(
|
2020-04-11 16:42:12 +03:00
|
|
|
nsIURI* aURI, const OriginAttributes* aOriginAttributes,
|
2020-01-08 16:06:28 +03:00
|
|
|
bool aForceStripOA, nsresult& aResult);
|
2016-12-08 23:45:52 +03:00
|
|
|
|
2019-02-22 01:54:10 +03:00
|
|
|
explicit PermissionKey(const nsACString& aOrigin)
|
2020-04-11 16:42:12 +03:00
|
|
|
: mOrigin(aOrigin), mHashCode(HashString(aOrigin)) {}
|
2012-08-23 22:47:55 +04:00
|
|
|
|
|
|
|
bool operator==(const PermissionKey& aKey) const {
|
2015-06-16 22:27:45 +03:00
|
|
|
return mOrigin.Equals(aKey.mOrigin);
|
2012-08-23 22:47:55 +04:00
|
|
|
}
|
|
|
|
|
2019-02-22 01:54:10 +03:00
|
|
|
PLDHashNumber GetHashCode() const { return mHashCode; }
|
2012-08-23 22:47:55 +04:00
|
|
|
|
2013-01-11 14:14:04 +04:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PermissionKey)
|
2012-08-23 22:47:55 +04:00
|
|
|
|
2019-02-22 01:54:10 +03:00
|
|
|
const nsCString mOrigin;
|
|
|
|
const PLDHashNumber mHashCode;
|
2012-08-23 22:47:55 +04:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Default ctor shouldn't be used.
|
2015-01-07 02:35:02 +03:00
|
|
|
PermissionKey() = delete;
|
2012-08-23 22:47:55 +04:00
|
|
|
|
|
|
|
// Dtor shouldn't be used outside of the class.
|
|
|
|
~PermissionKey(){};
|
|
|
|
};
|
2003-07-09 04:20:57 +04:00
|
|
|
|
2012-08-23 22:47:55 +04:00
|
|
|
class PermissionHashKey : public nsRefPtrHashKey<PermissionKey> {
|
|
|
|
public:
|
2014-09-03 02:20:38 +04:00
|
|
|
explicit PermissionHashKey(const PermissionKey* aPermissionKey)
|
2012-08-23 22:47:55 +04:00
|
|
|
: nsRefPtrHashKey<PermissionKey>(aPermissionKey) {}
|
|
|
|
|
2017-10-09 17:39:38 +03:00
|
|
|
PermissionHashKey(PermissionHashKey&& toCopy)
|
2018-05-30 22:15:35 +03:00
|
|
|
: nsRefPtrHashKey<PermissionKey>(std::move(toCopy)),
|
|
|
|
mPermissions(std::move(toCopy.mPermissions)) {}
|
2012-08-23 22:47:55 +04:00
|
|
|
|
|
|
|
bool KeyEquals(const PermissionKey* aKey) const {
|
|
|
|
return *aKey == *GetKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLDHashNumber HashKey(const PermissionKey* aKey) {
|
|
|
|
return aKey->GetHashCode();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force the hashtable to use the copy constructor when shuffling entries
|
2016-02-02 18:36:30 +03:00
|
|
|
// around, otherwise the Auto part of our AutoTArray won't be happy!
|
2012-08-23 22:47:55 +04:00
|
|
|
enum { ALLOW_MEMMOVE = false };
|
|
|
|
|
|
|
|
inline nsTArray<PermissionEntry>& GetPermissions() { return mPermissions; }
|
|
|
|
|
|
|
|
inline int32_t GetPermissionIndex(uint32_t aType) const {
|
|
|
|
for (uint32_t i = 0; i < mPermissions.Length(); ++i)
|
|
|
|
if (mPermissions[i].mType == aType) return i;
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline PermissionEntry GetPermission(uint32_t aType) const {
|
|
|
|
for (uint32_t i = 0; i < mPermissions.Length(); ++i)
|
|
|
|
if (mPermissions[i].mType == aType) return mPermissions[i];
|
|
|
|
|
2014-10-17 17:47:35 +04:00
|
|
|
// unknown permission... return relevant data
|
2012-08-23 22:47:55 +04:00
|
|
|
return PermissionEntry(-1, aType, nsIPermissionManager::UNKNOWN_ACTION,
|
2014-09-15 05:33:12 +04:00
|
|
|
nsIPermissionManager::EXPIRE_NEVER, 0, 0);
|
2012-08-23 22:47:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-02-02 18:36:30 +03:00
|
|
|
AutoTArray<PermissionEntry, 1> mPermissions;
|
2012-08-23 22:47:55 +04:00
|
|
|
};
|
2001-03-29 06:11:48 +04:00
|
|
|
|
|
|
|
// nsISupports
|
2020-04-11 16:41:19 +03:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2001-03-29 06:11:48 +04:00
|
|
|
NS_DECL_NSIPERMISSIONMANAGER
|
|
|
|
NS_DECL_NSIOBSERVER
|
2020-07-13 23:18:40 +03:00
|
|
|
NS_DECL_NSIASYNCSHUTDOWNBLOCKER
|
2001-03-29 06:11:48 +04:00
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
PermissionManager();
|
2017-10-17 07:08:42 +03:00
|
|
|
static already_AddRefed<nsIPermissionManager> GetXPCOMSingleton();
|
2020-04-11 16:42:12 +03:00
|
|
|
static PermissionManager* GetInstance();
|
2001-03-29 06:11:48 +04:00
|
|
|
nsresult Init();
|
2001-10-19 06:28:06 +04:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
// enums for AddInternal()
|
|
|
|
enum OperationType {
|
|
|
|
eOperationNone,
|
|
|
|
eOperationAdding,
|
|
|
|
eOperationRemoving,
|
2014-09-12 07:24:10 +04:00
|
|
|
eOperationChanging,
|
|
|
|
eOperationReplacingDefault
|
2007-12-05 09:37:36 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
enum DBOperationType { eNoDBOperation, eWriteToDB };
|
|
|
|
|
|
|
|
enum NotifyOperationType { eDontNotify, eNotify };
|
|
|
|
|
2019-02-22 01:54:30 +03:00
|
|
|
// Similar to TestPermissionFromPrincipal, except that it is used only for
|
|
|
|
// permissions which can never have default values.
|
|
|
|
nsresult TestPermissionWithoutDefaultsFromPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aType,
|
2020-04-11 16:42:53 +03:00
|
|
|
uint32_t* aPermission);
|
2019-02-22 01:54:30 +03:00
|
|
|
|
2019-09-19 20:07:22 +03:00
|
|
|
nsresult LegacyTestPermissionFromURI(
|
2020-04-11 16:42:12 +03:00
|
|
|
nsIURI* aURI, const OriginAttributes* aOriginAttributes,
|
2019-09-19 20:07:22 +03:00
|
|
|
const nsACString& aType, uint32_t* aPermission);
|
|
|
|
|
2012-08-31 18:34:28 +04:00
|
|
|
/**
|
2019-04-11 19:43:13 +03:00
|
|
|
* Initialize the permission-manager service.
|
2019-09-19 20:07:22 +03:00
|
|
|
* The permission manager is always initialized at startup because when it
|
|
|
|
* was lazy-initialized on demand, it was possible for it to be created
|
|
|
|
* once shutdown had begun, resulting in the manager failing to correctly
|
|
|
|
* shutdown because it missed its shutdown observer notification.
|
2012-08-31 18:34:28 +04:00
|
|
|
*/
|
2019-04-11 19:43:13 +03:00
|
|
|
static void Startup();
|
2015-10-13 05:27:42 +03:00
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
nsresult RemovePermissionsWithAttributes(OriginAttributesPattern& aAttrs);
|
Bug 1474608 - P1 - Clear origin attributes directly for deleteDataFromOriginAttributesPattern if it's possible; r=asuth,baku
The idea of this patch is to try to not use oberver mechanism as possible. To
achieve that, it introduces deleteByOriginAttributes() to cleaners. Different
from other methods, it would only be executed if it's implemented from a
cleaner.
It doesn't remove oberver mechanism entirely since some cleaners are still using
that for other deleteByXXX() functions. So, it only applies removing stuff to
PushService, QuotaManagerService, ServiceWorkerManager, nsPermissionManager,
nsApplicationCacheService, and nsCookieService.
Since the original issue is related to QuotaManagerService, it adds xpcshell
test under the dom/quota/test/unit/ to ensure the behavior won't be changed
accidentally in the future.
Differential Revision: https://phabricator.services.mozilla.com/D33758
--HG--
extra : moz-landing-system : lando
2019-12-02 22:47:13 +03:00
|
|
|
|
2017-03-03 00:48:01 +03:00
|
|
|
/**
|
|
|
|
* See `nsIPermissionManager::GetPermissionsWithKey` for more info on
|
|
|
|
* permission keys.
|
|
|
|
*
|
|
|
|
* Get the permission key corresponding to the given Principal. This method is
|
|
|
|
* intentionally infallible, as we want to provide an permission key to every
|
|
|
|
* principal. Principals which don't have meaningful URIs with http://,
|
|
|
|
* https://, or ftp:// schemes are given the default "" Permission Key.
|
|
|
|
*
|
|
|
|
* @param aPrincipal The Principal which the key is to be extracted from.
|
2020-01-08 16:06:28 +03:00
|
|
|
* @param aForceStripOA Whether to force stripping the principals origin
|
|
|
|
* attributes prior to generating the key.
|
|
|
|
* @param aKey A string which will be filled with the permission
|
2017-03-03 00:48:01 +03:00
|
|
|
* key.
|
|
|
|
*/
|
2020-01-08 16:06:28 +03:00
|
|
|
static void GetKeyForPrincipal(nsIPrincipal* aPrincipal, bool aForceStripOA,
|
|
|
|
nsACString& aKey);
|
2017-03-03 00:48:01 +03:00
|
|
|
|
2017-06-20 20:28:47 +03:00
|
|
|
/**
|
|
|
|
* See `nsIPermissionManager::GetPermissionsWithKey` for more info on
|
|
|
|
* permission keys.
|
|
|
|
*
|
|
|
|
* Get the permission key corresponding to the given Origin. This method is
|
|
|
|
* like GetKeyForPrincipal, except that it avoids creating a nsIPrincipal
|
|
|
|
* object when you already have access to an origin string.
|
|
|
|
*
|
|
|
|
* If this method is passed a nonsensical origin string it may produce a
|
|
|
|
* nonsensical permission key result.
|
|
|
|
*
|
|
|
|
* @param aOrigin The origin which the key is to be extracted from.
|
2020-01-08 16:06:28 +03:00
|
|
|
* @param aForceStripOA Whether to force stripping the origins attributes
|
|
|
|
* prior to generating the key.
|
|
|
|
* @param aKey A string which will be filled with the permission
|
2017-06-20 20:28:47 +03:00
|
|
|
* key.
|
|
|
|
*/
|
2020-01-08 16:06:28 +03:00
|
|
|
static void GetKeyForOrigin(const nsACString& aOrigin, bool aForceStripOA,
|
|
|
|
nsACString& aKey);
|
2017-06-20 20:28:47 +03:00
|
|
|
|
2017-04-04 18:46:26 +03:00
|
|
|
/**
|
|
|
|
* See `nsIPermissionManager::GetPermissionsWithKey` for more info on
|
|
|
|
* permission keys.
|
|
|
|
*
|
|
|
|
* Get the permission key corresponding to the given Principal and type. This
|
|
|
|
* method is intentionally infallible, as we want to provide an permission key
|
|
|
|
* to every principal. Principals which don't have meaningful URIs with
|
|
|
|
* http://, https://, or ftp:// schemes are given the default "" Permission
|
|
|
|
* Key.
|
|
|
|
*
|
|
|
|
* This method is different from GetKeyForPrincipal in that it also takes
|
|
|
|
* permissions which must be sent down before loading a document into account.
|
|
|
|
*
|
|
|
|
* @param aPrincipal The Principal which the key is to be extracted from.
|
|
|
|
* @param aType The type of the permission to get the key for.
|
|
|
|
* @param aPermissionKey A string which will be filled with the permission
|
|
|
|
* key.
|
|
|
|
*/
|
2019-02-22 01:54:28 +03:00
|
|
|
static void GetKeyForPermission(nsIPrincipal* aPrincipal,
|
|
|
|
const nsACString& aType, nsACString& aKey);
|
2017-04-04 18:46:26 +03:00
|
|
|
|
2017-03-08 22:28:04 +03:00
|
|
|
/**
|
|
|
|
* See `nsIPermissionManager::GetPermissionsWithKey` for more info on
|
|
|
|
* permission keys.
|
|
|
|
*
|
|
|
|
* Get all permissions keys which could correspond to the given principal.
|
|
|
|
* This method, like GetKeyForPrincipal, is infallible and should always
|
2020-02-24 18:21:51 +03:00
|
|
|
* produce at least one (key, origin) pair.
|
2017-03-08 22:28:04 +03:00
|
|
|
*
|
|
|
|
* Unlike GetKeyForPrincipal, this method also gets the keys for base domains
|
2018-01-17 13:27:48 +03:00
|
|
|
* of the given principal. All keys returned by this method must be available
|
2017-03-08 22:28:04 +03:00
|
|
|
* in the content process for a given URL to successfully have its permissions
|
|
|
|
* checked in the `aExactHostMatch = false` situation.
|
|
|
|
*
|
|
|
|
* @param aPrincipal The Principal which the key is to be extracted from.
|
2020-02-24 18:21:51 +03:00
|
|
|
* @return returns an array of (key, origin) pairs.
|
2017-03-08 22:28:04 +03:00
|
|
|
*/
|
2020-03-17 15:42:12 +03:00
|
|
|
static nsTArray<std::pair<nsCString, nsCString>> GetAllKeysForPrincipal(
|
2020-02-24 18:21:51 +03:00
|
|
|
nsIPrincipal* aPrincipal);
|
2017-03-08 22:28:04 +03:00
|
|
|
|
2018-07-10 11:09:59 +03:00
|
|
|
// From ContentChild.
|
|
|
|
nsresult RemoveAllFromIPC();
|
|
|
|
|
2019-10-28 13:57:51 +03:00
|
|
|
/**
|
|
|
|
* Returns false if this permission manager wouldn't have the permission
|
|
|
|
* requested available.
|
|
|
|
*
|
|
|
|
* If aType is empty, checks that the permission manager would have all
|
|
|
|
* permissions available for the given principal.
|
|
|
|
*/
|
|
|
|
bool PermissionAvailable(nsIPrincipal* aPrincipal, const nsACString& aType);
|
|
|
|
|
2019-11-18 01:22:34 +03:00
|
|
|
/**
|
|
|
|
* The content process doesn't have access to every permission. Instead, when
|
|
|
|
* LOAD_DOCUMENT_URI channels for http://, https://, and ftp:// URIs are
|
|
|
|
* opened, the permissions for those channels are sent down to the content
|
|
|
|
* process before the OnStartRequest message. Permissions for principals with
|
|
|
|
* other schemes are sent down at process startup.
|
|
|
|
*
|
|
|
|
* Permissions are keyed and grouped by "Permission Key"s.
|
2020-04-11 16:42:12 +03:00
|
|
|
* `PermissionManager::GetKeyForPrincipal` provides the mechanism for
|
2019-11-18 01:22:34 +03:00
|
|
|
* determining the permission key for a given principal.
|
|
|
|
*
|
|
|
|
* This method may only be called in the parent process. It fills the nsTArray
|
2020-02-24 18:21:51 +03:00
|
|
|
* argument with the IPC::Permission objects which have a matching origin.
|
2019-11-18 01:22:34 +03:00
|
|
|
*
|
2020-02-24 18:21:51 +03:00
|
|
|
* @param origin The origin to use to find the permissions of interest.
|
|
|
|
* @param key The key to use to find the permissions of interest. Only used
|
|
|
|
* when the origin argument is empty.
|
2019-11-18 01:22:34 +03:00
|
|
|
* @param perms An array which will be filled with the permissions which
|
2020-02-24 18:21:51 +03:00
|
|
|
* match the given origin.
|
2019-11-18 01:22:34 +03:00
|
|
|
*/
|
2020-02-24 18:21:51 +03:00
|
|
|
bool GetPermissionsFromOriginOrKey(const nsACString& aOrigin,
|
|
|
|
const nsACString& aKey,
|
|
|
|
nsTArray<IPC::Permission>& aPerms);
|
2019-11-18 01:22:34 +03:00
|
|
|
|
|
|
|
/**
|
2020-04-11 16:42:12 +03:00
|
|
|
* See `PermissionManager::GetPermissionsWithKey` for more info on
|
2019-11-18 01:22:34 +03:00
|
|
|
* Permission keys.
|
|
|
|
*
|
|
|
|
* `SetPermissionsWithKey` may only be called in the Child process, and
|
|
|
|
* initializes the permission manager with the permissions for a given
|
|
|
|
* Permission key. marking permissions with that key as available.
|
|
|
|
*
|
|
|
|
* @param permissionKey The key for the permissions which have been sent
|
|
|
|
* over.
|
|
|
|
* @param perms An array with the permissions which match the given key.
|
|
|
|
*/
|
|
|
|
void SetPermissionsWithKey(const nsACString& aPermissionKey,
|
|
|
|
nsTArray<IPC::Permission>& aPerms);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a callback which should be run when all permissions are available for
|
|
|
|
* the given nsIPrincipal. This method invokes the callback runnable
|
|
|
|
* synchronously when the permissions are already available. Otherwise the
|
|
|
|
* callback will be run asynchronously in SystemGroup when all permissions
|
|
|
|
* are available in the future.
|
|
|
|
*
|
|
|
|
* NOTE: This method will not request the permissions be sent by the parent
|
|
|
|
* process. This should only be used to wait for permissions which may not
|
|
|
|
* have arrived yet in order to ensure they are present.
|
|
|
|
*
|
|
|
|
* @param aPrincipal The principal to wait for permissions to be available
|
|
|
|
* for.
|
|
|
|
* @param aRunnable The runnable to run when permissions are available for
|
|
|
|
* the given principal.
|
|
|
|
*/
|
|
|
|
void WhenPermissionsAvailable(nsIPrincipal* aPrincipal,
|
|
|
|
nsIRunnable* aRunnable);
|
|
|
|
|
2010-10-09 22:07:38 +04:00
|
|
|
private:
|
2020-04-11 16:42:12 +03:00
|
|
|
~PermissionManager();
|
2014-06-24 02:40:02 +04:00
|
|
|
|
2020-01-08 16:06:28 +03:00
|
|
|
/**
|
|
|
|
* Get all permissions for a given principal, which should not be isolated
|
|
|
|
* by user context or private browsing. The principal has its origin
|
|
|
|
* attributes stripped before perm db lookup. This is currently only affects
|
|
|
|
* the "cookie" permission.
|
|
|
|
* @param aPrincipal Used for creating the permission key.
|
|
|
|
*/
|
|
|
|
nsresult GetStripPermsForPrincipal(nsIPrincipal* aPrincipal,
|
|
|
|
nsTArray<PermissionEntry>& aResult);
|
|
|
|
|
2019-02-22 01:54:14 +03:00
|
|
|
// Returns -1 on failure
|
2020-04-11 16:42:53 +03:00
|
|
|
int32_t GetTypeIndex(const nsACString& aType, bool aAdd);
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2020-04-27 20:26:04 +03:00
|
|
|
// Returns whether the given combination of expire type and expire time are
|
|
|
|
// expired. Note that EXPIRE_SESSION only honors expireTime if it is nonzero.
|
|
|
|
bool HasExpired(uint32_t aExpireType, int64_t aExpireTime);
|
|
|
|
|
2020-04-11 16:42:53 +03:00
|
|
|
// Returns PermissionHashKey for a given { host, isInBrowserElement } tuple.
|
|
|
|
// This is not simply using PermissionKey because we will walk-up domains in
|
|
|
|
// case of |host| contains sub-domains. Returns null if nothing found. Also
|
|
|
|
// accepts host on the format "<foo>". This will perform an exact match lookup
|
|
|
|
// as the string doesn't contain any dots.
|
2015-06-16 22:27:45 +03:00
|
|
|
PermissionHashKey* GetPermissionHashKey(nsIPrincipal* aPrincipal,
|
|
|
|
uint32_t aType, bool aExactHostMatch);
|
2020-04-11 16:42:53 +03:00
|
|
|
|
|
|
|
// Returns PermissionHashKey for a given { host, isInBrowserElement } tuple.
|
|
|
|
// This is not simply using PermissionKey because we will walk-up domains in
|
|
|
|
// case of |host| contains sub-domains. Returns null if nothing found. Also
|
|
|
|
// accepts host on the format "<foo>". This will perform an exact match lookup
|
|
|
|
// as the string doesn't contain any dots.
|
2019-09-19 20:07:22 +03:00
|
|
|
PermissionHashKey* GetPermissionHashKey(
|
2020-04-11 16:42:12 +03:00
|
|
|
nsIURI* aURI, const OriginAttributes* aOriginAttributes, uint32_t aType,
|
|
|
|
bool aExactHostMatch);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-02-22 01:54:26 +03:00
|
|
|
// The int32_t is the type index, the nsresult is an early bail-out return
|
|
|
|
// code.
|
2020-04-11 16:42:12 +03:00
|
|
|
typedef Variant<int32_t, nsresult> TestPreparationResult;
|
2019-02-22 01:54:24 +03:00
|
|
|
TestPreparationResult CommonPrepareToTestPermission(
|
2019-02-22 01:54:28 +03:00
|
|
|
nsIPrincipal* aPrincipal, int32_t aTypeIndex, const nsACString& aType,
|
2019-02-22 01:54:24 +03:00
|
|
|
uint32_t* aPermission, uint32_t aDefaultPermission,
|
2019-02-22 01:54:26 +03:00
|
|
|
bool aDefaultPermissionIsValid, bool aExactHostMatch,
|
2020-04-11 16:41:19 +03:00
|
|
|
bool aIncludingSession);
|
2019-02-22 01:54:08 +03:00
|
|
|
|
2019-02-22 01:54:12 +03:00
|
|
|
// If aTypeIndex is passed -1, we try to inder the type index from aType.
|
|
|
|
nsresult CommonTestPermission(nsIPrincipal* aPrincipal, int32_t aTypeIndex,
|
2019-02-22 01:54:28 +03:00
|
|
|
const nsACString& aType, uint32_t* aPermission,
|
2019-02-22 01:54:24 +03:00
|
|
|
uint32_t aDefaultPermission,
|
|
|
|
bool aDefaultPermissionIsValid,
|
2020-04-11 16:42:53 +03:00
|
|
|
bool aExactHostMatch, bool aIncludingSession);
|
2019-02-22 01:54:08 +03:00
|
|
|
|
2019-02-22 01:54:12 +03:00
|
|
|
// If aTypeIndex is passed -1, we try to inder the type index from aType.
|
|
|
|
nsresult CommonTestPermission(nsIURI* aURI, int32_t aTypeIndex,
|
2019-02-22 01:54:28 +03:00
|
|
|
const nsACString& aType, uint32_t* aPermission,
|
2019-02-22 01:54:24 +03:00
|
|
|
uint32_t aDefaultPermission,
|
|
|
|
bool aDefaultPermissionIsValid,
|
2020-04-11 16:42:53 +03:00
|
|
|
bool aExactHostMatch, bool aIncludingSession);
|
2019-02-22 01:54:08 +03:00
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
nsresult CommonTestPermission(nsIURI* aURI,
|
|
|
|
const OriginAttributes* aOriginAttributes,
|
|
|
|
int32_t aTypeIndex, const nsACString& aType,
|
|
|
|
uint32_t* aPermission,
|
|
|
|
uint32_t aDefaultPermission,
|
|
|
|
bool aDefaultPermissionIsValid,
|
2020-04-11 16:42:53 +03:00
|
|
|
bool aExactHostMatch, bool aIncludingSession);
|
2019-09-19 20:07:22 +03:00
|
|
|
|
2017-05-06 23:17:52 +03:00
|
|
|
// Only one of aPrincipal or aURI is allowed to be passed in.
|
2019-09-19 20:07:22 +03:00
|
|
|
nsresult CommonTestPermissionInternal(
|
|
|
|
nsIPrincipal* aPrincipal, nsIURI* aURI,
|
2020-04-11 16:42:12 +03:00
|
|
|
const OriginAttributes* aOriginAttributes, int32_t aTypeIndex,
|
2019-09-19 20:07:22 +03:00
|
|
|
const nsACString& aType, uint32_t* aPermission, bool aExactHostMatch,
|
|
|
|
bool aIncludingSession);
|
2004-02-10 22:57:33 +03:00
|
|
|
|
2015-06-11 18:00:00 +03:00
|
|
|
nsresult OpenDatabase(nsIFile* permissionsFile);
|
2020-04-11 16:41:19 +03:00
|
|
|
|
|
|
|
void InitDB(bool aRemoveFile);
|
|
|
|
nsresult TryInitDB(bool aRemoveFile, nsIInputStream* aDefaultsInputStream);
|
|
|
|
|
2020-02-28 20:50:19 +03:00
|
|
|
void AddIdleDailyMaintenanceJob();
|
|
|
|
void RemoveIdleDailyMaintenanceJob();
|
|
|
|
void PerformIdleDailyMaintenance();
|
|
|
|
|
2020-04-11 16:41:19 +03:00
|
|
|
nsresult ImportLatestDefaults();
|
|
|
|
already_AddRefed<nsIInputStream> GetDefaultsInputStream();
|
|
|
|
void ConsumeDefaultsInputStream(nsIInputStream* aDefaultsInputStream,
|
2020-04-11 16:42:12 +03:00
|
|
|
const MonitorAutoLock& aProofOfLock);
|
2020-04-11 16:41:19 +03:00
|
|
|
|
2007-12-05 09:37:36 +03:00
|
|
|
nsresult CreateTable();
|
2015-06-16 22:27:45 +03:00
|
|
|
void NotifyObserversWithPermission(nsIPrincipal* aPrincipal,
|
2019-02-22 01:54:28 +03:00
|
|
|
const nsACString& aType,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t aPermission, uint32_t aExpireType,
|
|
|
|
int64_t aExpireTime,
|
2019-04-18 16:43:10 +03:00
|
|
|
int64_t aModificationTime,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* aData);
|
|
|
|
void NotifyObservers(nsIPermission* aPermission, const char16_t* aData);
|
2011-12-22 02:04:49 +04:00
|
|
|
|
|
|
|
// Finalize all statements, close the DB and null it.
|
2020-07-13 23:18:40 +03:00
|
|
|
enum CloseDBNextOp {
|
|
|
|
eNone,
|
|
|
|
eRebuldOnSuccess,
|
|
|
|
eShutdown,
|
|
|
|
};
|
|
|
|
void CloseDB(CloseDBNextOp aNextOp);
|
2011-12-22 02:04:49 +04:00
|
|
|
|
2012-04-30 20:21:50 +04:00
|
|
|
nsresult RemoveAllInternal(bool aNotifyObservers);
|
2003-03-22 04:24:51 +03:00
|
|
|
nsresult RemoveAllFromMemory();
|
2020-04-11 16:41:19 +03:00
|
|
|
|
|
|
|
void UpdateDB(OperationType aOp, int64_t aID, const nsACString& aOrigin,
|
|
|
|
const nsACString& aType, uint32_t aPermission,
|
|
|
|
uint32_t aExpireType, int64_t aExpireTime,
|
|
|
|
int64_t aModificationTime);
|
2003-03-22 04:24:51 +03:00
|
|
|
|
2014-09-15 05:33:12 +04:00
|
|
|
/**
|
|
|
|
* This method removes all permissions modified after the specified time.
|
|
|
|
*/
|
|
|
|
nsresult RemoveAllModifiedSince(int64_t aModificationTime);
|
|
|
|
|
2018-08-21 02:15:06 +03:00
|
|
|
template <class T>
|
|
|
|
nsresult RemovePermissionEntries(T aCondition);
|
|
|
|
|
2020-11-18 01:24:55 +03:00
|
|
|
template <class T>
|
|
|
|
nsresult GetPermissionEntries(T aCondition,
|
|
|
|
nsTArray<RefPtr<nsIPermission>>& aResult);
|
|
|
|
|
2020-04-11 16:41:19 +03:00
|
|
|
// This method must be called before doing any operation to be sure that the
|
|
|
|
// DB reading has been completed. This method is also in charge to complete
|
|
|
|
// the migrations if needed.
|
|
|
|
void EnsureReadCompleted();
|
|
|
|
|
|
|
|
nsresult AddInternal(nsIPrincipal* aPrincipal, const nsACString& aType,
|
|
|
|
uint32_t aPermission, int64_t aID, uint32_t aExpireType,
|
|
|
|
int64_t aExpireTime, int64_t aModificationTime,
|
|
|
|
NotifyOperationType aNotifyOperation,
|
|
|
|
DBOperationType aDBOperation,
|
|
|
|
const bool aIgnoreSessionPermissions = false,
|
|
|
|
const nsACString* aOriginString = nullptr);
|
|
|
|
|
|
|
|
void MaybeAddReadEntryFromMigration(const nsACString& aOrigin,
|
|
|
|
const nsCString& aType,
|
|
|
|
uint32_t aPermission,
|
|
|
|
uint32_t aExpireType, int64_t aExpireTime,
|
|
|
|
int64_t aModificationTime, int64_t aId);
|
|
|
|
|
2020-07-13 23:18:40 +03:00
|
|
|
nsCOMPtr<nsIAsyncShutdownClient> GetShutdownPhase() const;
|
|
|
|
|
|
|
|
void MaybeCompleteShutdown();
|
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
nsRefPtrHashtable<nsCStringHashKey, GenericNonExclusivePromise::Private>
|
2017-04-11 23:36:37 +03:00
|
|
|
mPermissionKeyPromiseMap;
|
|
|
|
|
2020-04-11 16:41:19 +03:00
|
|
|
nsCOMPtr<nsIFile> mPermissionsFile;
|
|
|
|
|
|
|
|
// This monitor is used to ensure the database reading before any other
|
|
|
|
// operation. The reading of the database happens OMT. See |State| to know the
|
|
|
|
// steps of the database reading.
|
2020-04-11 16:42:12 +03:00
|
|
|
Monitor mMonitor;
|
2020-04-11 16:41:19 +03:00
|
|
|
|
|
|
|
enum State {
|
|
|
|
// Initial state. The database has not been read yet.
|
|
|
|
// |TryInitDB| is called at startup time to read the database OMT.
|
|
|
|
// During the reading, |mReadEntries| will be populated with all the
|
|
|
|
// existing permissions.
|
|
|
|
eInitializing,
|
|
|
|
|
|
|
|
// At the end of the database reading, we are in this state. A runnable is
|
|
|
|
// executed to call |EnsureReadCompleted| on the main thread.
|
|
|
|
// |EnsureReadCompleted| processes |mReadEntries| and goes to the next
|
|
|
|
// state.
|
|
|
|
eDBInitialized,
|
|
|
|
|
|
|
|
// The permissions are fully read and any pending operation can proceed.
|
|
|
|
eReady,
|
|
|
|
|
|
|
|
// The permission manager has been terminated. No extra database operations
|
|
|
|
// will be allowed.
|
|
|
|
eClosed,
|
|
|
|
};
|
2020-04-11 16:42:12 +03:00
|
|
|
Atomic<State> mState;
|
2020-04-11 16:41:19 +03:00
|
|
|
|
|
|
|
// A single entry, from the database.
|
|
|
|
struct ReadEntry {
|
|
|
|
ReadEntry()
|
|
|
|
: mId(0),
|
|
|
|
mPermission(0),
|
|
|
|
mExpireType(0),
|
|
|
|
mExpireTime(0),
|
|
|
|
mModificationTime(0) {}
|
|
|
|
|
|
|
|
nsCString mOrigin;
|
|
|
|
nsCString mType;
|
|
|
|
int64_t mId;
|
|
|
|
uint32_t mPermission;
|
|
|
|
uint32_t mExpireType;
|
|
|
|
int64_t mExpireTime;
|
|
|
|
int64_t mModificationTime;
|
|
|
|
|
|
|
|
// true if this entry is the result of a migration.
|
|
|
|
bool mFromMigration;
|
|
|
|
};
|
|
|
|
|
|
|
|
// List of entries read from the database. It will be populated OMT and
|
|
|
|
// consumed on the main-thread.
|
|
|
|
// This array is protected by the monitor.
|
|
|
|
nsTArray<ReadEntry> mReadEntries;
|
|
|
|
|
|
|
|
// A single entry, from the database.
|
|
|
|
struct MigrationEntry {
|
|
|
|
MigrationEntry()
|
|
|
|
: mId(0),
|
|
|
|
mPermission(0),
|
|
|
|
mExpireType(0),
|
|
|
|
mExpireTime(0),
|
|
|
|
mModificationTime(0),
|
|
|
|
mIsInBrowserElement(false) {}
|
|
|
|
|
|
|
|
nsCString mHost;
|
|
|
|
nsCString mType;
|
|
|
|
int64_t mId;
|
|
|
|
uint32_t mPermission;
|
|
|
|
uint32_t mExpireType;
|
|
|
|
int64_t mExpireTime;
|
|
|
|
int64_t mModificationTime;
|
|
|
|
|
|
|
|
// Legacy, for migration.
|
|
|
|
bool mIsInBrowserElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
// List of entries read from the database. It will be populated OMT and
|
|
|
|
// consumed on the main-thread. The migration entries will be converted to
|
|
|
|
// ReadEntry in |CompleteMigrations|.
|
|
|
|
// This array is protected by the monitor.
|
|
|
|
nsTArray<MigrationEntry> mMigrationEntries;
|
|
|
|
|
|
|
|
// A single entry from the defaults URL.
|
|
|
|
struct DefaultEntry {
|
|
|
|
DefaultEntry() : mOp(eImportMatchTypeHost), mPermission(0) {}
|
|
|
|
|
|
|
|
enum Op {
|
|
|
|
eImportMatchTypeHost,
|
|
|
|
eImportMatchTypeOrigin,
|
|
|
|
};
|
|
|
|
|
|
|
|
Op mOp;
|
|
|
|
|
|
|
|
nsCString mHostOrOrigin;
|
|
|
|
nsCString mType;
|
|
|
|
uint32_t mPermission;
|
|
|
|
};
|
|
|
|
|
|
|
|
// List of entries read from the default settings.
|
|
|
|
// This array is protected by the monitor.
|
|
|
|
nsTArray<DefaultEntry> mDefaultEntries;
|
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
nsresult Read(const MonitorAutoLock& aProofOfLock);
|
2020-04-11 16:41:19 +03:00
|
|
|
void CompleteRead();
|
|
|
|
|
|
|
|
void CompleteMigrations();
|
2007-12-05 09:37:36 +03:00
|
|
|
|
2015-06-11 18:00:00 +03:00
|
|
|
bool mMemoryOnlyDB;
|
|
|
|
|
2020-07-14 10:23:57 +03:00
|
|
|
bool mBlockerAdded;
|
|
|
|
|
2012-08-23 22:47:55 +04:00
|
|
|
nsTHashtable<PermissionHashKey> mPermissionTable;
|
2007-12-05 09:37:36 +03:00
|
|
|
// a unique, monotonically increasing id used to identify each database entry
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t mLargestID;
|
2003-07-09 04:20:57 +04:00
|
|
|
|
2017-07-11 00:13:43 +03:00
|
|
|
nsCOMPtr<nsIPrefBranch> mDefaultPrefBranch;
|
|
|
|
|
2019-02-22 01:54:16 +03:00
|
|
|
// NOTE: Ensure this is the last member since it has a large inline buffer.
|
|
|
|
// An array to store the strings identifying the different types.
|
2020-04-11 16:42:12 +03:00
|
|
|
Vector<nsCString, 512> mTypeArray;
|
2020-04-10 09:36:03 +03:00
|
|
|
|
2020-04-11 16:41:19 +03:00
|
|
|
nsCOMPtr<nsIThread> mThread;
|
|
|
|
|
|
|
|
struct ThreadBoundData {
|
|
|
|
nsCOMPtr<mozIStorageConnection> mDBConn;
|
|
|
|
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStmtInsert;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStmtDelete;
|
|
|
|
nsCOMPtr<mozIStorageStatement> mStmtUpdate;
|
|
|
|
};
|
2020-04-11 16:42:12 +03:00
|
|
|
ThreadBound<ThreadBoundData> mThreadBoundData;
|
2020-04-11 16:41:19 +03:00
|
|
|
|
2012-04-30 20:21:50 +04:00
|
|
|
friend class DeleteFromMozHostListener;
|
|
|
|
friend class CloseDatabaseListener;
|
2001-03-29 06:11:48 +04:00
|
|
|
};
|
|
|
|
|
2003-03-22 04:24:51 +03:00
|
|
|
// {4F6B5E00-0C36-11d5-A535-0010A401EB10}
|
|
|
|
#define NS_PERMISSIONMANAGER_CID \
|
|
|
|
{ \
|
|
|
|
0x4f6b5e00, 0xc36, 0x11d5, { \
|
|
|
|
0xa5, 0x35, 0x0, 0x10, 0xa4, 0x1, 0xeb, 0x10 \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2020-04-11 16:42:12 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_PermissionManager_h
|