2017-11-09 08:19:59 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 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/. */
|
|
|
|
#ifndef _mozilla_dom_ClientManagerService_h
|
|
|
|
#define _mozilla_dom_ClientManagerService_h
|
|
|
|
|
2021-05-24 16:55:05 +03:00
|
|
|
#include "ClientHandleParent.h"
|
2017-12-06 04:45:23 +03:00
|
|
|
#include "ClientOpPromise.h"
|
2020-10-21 16:17:18 +03:00
|
|
|
#include "mozilla/AlreadyAddRefed.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/Maybe.h"
|
2021-05-24 16:55:05 +03:00
|
|
|
#include "mozilla/MozPromise.h"
|
2020-10-21 16:17:18 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2021-05-24 16:55:05 +03:00
|
|
|
#include "mozilla/Variant.h"
|
2020-10-21 16:17:18 +03:00
|
|
|
#include "mozilla/dom/ClientIPCTypes.h"
|
|
|
|
#include "mozilla/dom/ipc/IdType.h"
|
2021-03-10 13:47:47 +03:00
|
|
|
#include "nsTHashMap.h"
|
2020-10-21 16:17:18 +03:00
|
|
|
#include "nsHashKeys.h"
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
struct nsID;
|
2017-11-09 08:19:59 +03:00
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
2019-02-08 23:02:06 +03:00
|
|
|
namespace ipc {
|
|
|
|
|
|
|
|
class PrincipalInfo;
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
namespace dom {
|
|
|
|
|
2017-12-04 17:51:32 +03:00
|
|
|
class ClientManagerParent;
|
2017-11-09 08:19:59 +03:00
|
|
|
class ClientSourceParent;
|
2019-08-27 01:53:37 +03:00
|
|
|
class ClientHandleParent;
|
2022-11-29 23:41:47 +03:00
|
|
|
class ThreadsafeContentParentHandle;
|
2017-11-09 08:19:59 +03:00
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
// Define a singleton service to manage client activity throughout the
|
|
|
|
// browser. This service runs on the PBackground thread. To interact
|
|
|
|
// it with it please use the ClientManager and ClientHandle classes.
|
|
|
|
class ClientManagerService final {
|
2021-05-24 16:55:05 +03:00
|
|
|
// Placeholder type that represents a ClientSourceParent that may be created
|
|
|
|
// in the future (e.g. while a redirect chain is being resolved).
|
|
|
|
//
|
|
|
|
// Each FutureClientSourceParent has a promise that callbacks may be chained
|
|
|
|
// to; the promise will be resolved when the associated ClientSourceParent is
|
|
|
|
// created or rejected when it's known that it'll never be created.
|
|
|
|
class FutureClientSourceParent {
|
|
|
|
public:
|
|
|
|
explicit FutureClientSourceParent(const IPCClientInfo& aClientInfo);
|
|
|
|
|
|
|
|
const mozilla::ipc::PrincipalInfo& PrincipalInfo() const {
|
|
|
|
return mPrincipalInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<SourcePromise> Promise() {
|
|
|
|
return mPromiseHolder.Ensure(__func__);
|
|
|
|
}
|
|
|
|
|
2021-05-24 16:55:08 +03:00
|
|
|
void ResolvePromiseIfExists() {
|
|
|
|
mPromiseHolder.ResolveIfExists(true, __func__);
|
2021-05-24 16:55:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void RejectPromiseIfExists(const CopyableErrorResult& aRv) {
|
|
|
|
MOZ_ASSERT(aRv.Failed());
|
|
|
|
mPromiseHolder.RejectIfExists(aRv, __func__);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetAsAssociated() { mAssociated = true; }
|
|
|
|
|
|
|
|
bool IsAssociated() const { return mAssociated; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
const mozilla::ipc::PrincipalInfo mPrincipalInfo;
|
|
|
|
MozPromiseHolder<SourcePromise> mPromiseHolder;
|
2021-05-24 16:55:07 +03:00
|
|
|
RefPtr<ClientManagerService> mService = ClientManagerService::GetInstance();
|
2021-05-24 16:55:05 +03:00
|
|
|
bool mAssociated;
|
|
|
|
};
|
|
|
|
|
|
|
|
using SourceTableEntry =
|
|
|
|
Variant<FutureClientSourceParent, ClientSourceParent*>;
|
|
|
|
|
2021-05-24 16:55:06 +03:00
|
|
|
// Store the possible ClientSourceParent objects in a hash table. We want to
|
2019-10-02 14:36:27 +03:00
|
|
|
// optimize for insertion, removal, and lookup by UUID.
|
2021-05-24 16:55:06 +03:00
|
|
|
nsTHashMap<nsIDHashKey, SourceTableEntry> mSourceTable;
|
2020-03-30 21:53:46 +03:00
|
|
|
|
2019-10-02 14:36:27 +03:00
|
|
|
nsTArray<ClientManagerParent*> mManagerList;
|
|
|
|
|
|
|
|
bool mShutdown;
|
|
|
|
|
|
|
|
ClientManagerService();
|
|
|
|
~ClientManagerService();
|
|
|
|
|
|
|
|
void Shutdown();
|
|
|
|
|
2021-05-24 16:55:06 +03:00
|
|
|
// Returns nullptr if aEntry isn't a ClientSourceParent (i.e. it's a
|
|
|
|
// FutureClientSourceParent).
|
|
|
|
ClientSourceParent* MaybeUnwrapAsExistingSource(
|
|
|
|
const SourceTableEntry& aEntry) const;
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
public:
|
|
|
|
static already_AddRefed<ClientManagerService> GetOrCreateInstance();
|
|
|
|
|
2017-12-04 17:51:32 +03:00
|
|
|
// Returns nullptr if the service is not already created.
|
|
|
|
static already_AddRefed<ClientManagerService> GetInstance();
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
bool AddSource(ClientSourceParent* aSource);
|
|
|
|
|
|
|
|
bool RemoveSource(ClientSourceParent* aSource);
|
|
|
|
|
2021-05-24 16:55:06 +03:00
|
|
|
// Returns true when a FutureClientSourceParent is successfully added.
|
|
|
|
bool ExpectFutureSource(const IPCClientInfo& aClientInfo);
|
|
|
|
|
|
|
|
// May still be called if it's possible that the FutureClientSourceParent
|
|
|
|
// no longer exists.
|
|
|
|
void ForgetFutureSource(const IPCClientInfo& aClientInfo);
|
|
|
|
|
2021-05-24 16:55:08 +03:00
|
|
|
// Returns a promise that resolves if/when the ClientSourceParent exists and
|
|
|
|
// rejects if/when it's known that the ClientSourceParent will never exist or
|
|
|
|
// if it's frozen. Note that the ClientSourceParent may not exist anymore
|
|
|
|
// by the time promise callbacks run.
|
2021-05-24 16:55:06 +03:00
|
|
|
RefPtr<SourcePromise> FindSource(
|
2019-10-02 14:36:27 +03:00
|
|
|
const nsID& aID, const mozilla::ipc::PrincipalInfo& aPrincipalInfo);
|
2017-11-09 08:19:59 +03:00
|
|
|
|
2021-05-24 16:55:08 +03:00
|
|
|
// Returns nullptr if the ClientSourceParent doesn't exist yet (i.e. it's a
|
|
|
|
// FutureClientSourceParent or has already been destroyed) or is frozen.
|
|
|
|
ClientSourceParent* FindExistingSource(
|
|
|
|
const nsID& aID, const mozilla::ipc::PrincipalInfo& aPrincipalInfo) const;
|
|
|
|
|
2017-12-04 17:51:32 +03:00
|
|
|
void AddManager(ClientManagerParent* aManager);
|
|
|
|
|
|
|
|
void RemoveManager(ClientManagerParent* aManager);
|
|
|
|
|
2022-11-29 23:41:47 +03:00
|
|
|
RefPtr<ClientOpPromise> Navigate(
|
|
|
|
ThreadsafeContentParentHandle* aOriginContent,
|
|
|
|
const ClientNavigateArgs& aArgs);
|
2017-12-08 22:46:42 +03:00
|
|
|
|
2022-11-29 23:41:47 +03:00
|
|
|
RefPtr<ClientOpPromise> MatchAll(
|
|
|
|
ThreadsafeContentParentHandle* aOriginContent,
|
|
|
|
const ClientMatchAllArgs& aArgs);
|
2017-12-08 22:46:42 +03:00
|
|
|
|
2022-11-29 23:41:47 +03:00
|
|
|
RefPtr<ClientOpPromise> Claim(ThreadsafeContentParentHandle* aOriginContent,
|
|
|
|
const ClientClaimArgs& aArgs);
|
2017-12-08 22:46:42 +03:00
|
|
|
|
2017-12-06 04:45:23 +03:00
|
|
|
RefPtr<ClientOpPromise> GetInfoAndState(
|
2022-11-29 23:41:47 +03:00
|
|
|
ThreadsafeContentParentHandle* aOriginContent,
|
2017-12-06 04:45:23 +03:00
|
|
|
const ClientGetInfoAndStateArgs& aArgs);
|
|
|
|
|
2022-11-29 23:41:47 +03:00
|
|
|
RefPtr<ClientOpPromise> OpenWindow(
|
|
|
|
ThreadsafeContentParentHandle* aOriginContent,
|
|
|
|
const ClientOpenWindowArgs& aArgs);
|
2017-12-08 22:46:43 +03:00
|
|
|
|
2019-02-08 23:02:06 +03:00
|
|
|
bool HasWindow(const Maybe<ContentParentId>& aContentParentId,
|
|
|
|
const mozilla::ipc::PrincipalInfo& aPrincipalInfo,
|
|
|
|
const nsID& aClientId);
|
|
|
|
|
2017-11-09 08:19:59 +03:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(mozilla::dom::ClientManagerService)
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // _mozilla_dom_ClientManagerService_h
|