2020-01-20 17:58:52 +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_WindowContext_h
|
|
|
|
#define mozilla_dom_WindowContext_h
|
|
|
|
|
2020-02-21 02:30:33 +03:00
|
|
|
#include "mozilla/dom/MaybeDiscarded.h"
|
2020-01-20 17:58:52 +03:00
|
|
|
#include "mozilla/dom/SyncedContext.h"
|
2020-03-04 11:59:18 +03:00
|
|
|
#include "mozilla/net/NeckoChannelParams.h"
|
2020-01-20 17:58:52 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2020-04-22 22:32:52 +03:00
|
|
|
class WindowGlobalParent;
|
|
|
|
|
2020-03-30 17:12:08 +03:00
|
|
|
#define MOZ_EACH_WC_FIELD(FIELD) \
|
|
|
|
FIELD(OuterWindowId, uint64_t) \
|
|
|
|
FIELD(CookieJarSettings, Maybe<mozilla::net::CookieJarSettingsArgs>) \
|
2020-04-23 17:24:56 +03:00
|
|
|
FIELD(HasStoragePermission, bool) \
|
|
|
|
/* Whether the given window hierarchy is third party. See \
|
|
|
|
* ThirdPartyUtil::IsThirdPartyWindow for details */ \
|
|
|
|
FIELD(IsThirdPartyWindow, bool) \
|
|
|
|
/* Whether this window's channel has been marked as a third-party \
|
|
|
|
* tracking resource */ \
|
|
|
|
FIELD(IsThirdPartyTrackingResourceWindow, bool)
|
2020-01-20 17:58:52 +03:00
|
|
|
|
|
|
|
class WindowContext : public nsISupports, public nsWrapperCache {
|
|
|
|
MOZ_DECL_SYNCED_CONTEXT(WindowContext, MOZ_EACH_WC_FIELD)
|
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WindowContext)
|
|
|
|
|
|
|
|
public:
|
|
|
|
static already_AddRefed<WindowContext> GetById(uint64_t aInnerWindowId);
|
|
|
|
static LogModule* GetLog();
|
|
|
|
|
|
|
|
BrowsingContext* GetBrowsingContext() const { return mBrowsingContext; }
|
|
|
|
BrowsingContextGroup* Group() const;
|
2020-02-21 02:30:33 +03:00
|
|
|
uint64_t Id() const { return InnerWindowId(); }
|
2020-01-20 17:58:52 +03:00
|
|
|
uint64_t InnerWindowId() const { return mInnerWindowId; }
|
2020-02-26 21:19:17 +03:00
|
|
|
uint64_t OuterWindowId() const { return GetOuterWindowId(); }
|
2020-01-20 17:58:52 +03:00
|
|
|
bool IsDiscarded() const { return mIsDiscarded; }
|
|
|
|
|
2020-02-21 02:30:33 +03:00
|
|
|
// Cast this object to it's parent-process canonical form.
|
|
|
|
WindowGlobalParent* Canonical();
|
|
|
|
|
2020-01-20 17:58:52 +03:00
|
|
|
nsIGlobalObject* GetParentObject() const;
|
|
|
|
JSObject* WrapObject(JSContext* cx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) override;
|
|
|
|
|
|
|
|
void Discard();
|
|
|
|
|
|
|
|
struct IPCInitializer {
|
|
|
|
uint64_t mInnerWindowId;
|
|
|
|
uint64_t mBrowsingContextId;
|
|
|
|
|
|
|
|
FieldTuple mFields;
|
|
|
|
};
|
|
|
|
IPCInitializer GetIPCInitializer() {
|
|
|
|
return {mInnerWindowId, mBrowsingContext->Id(), mFields.Fields()};
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<WindowContext> Create(WindowGlobalChild* aWindow);
|
|
|
|
static void CreateFromIPC(IPCInitializer&& aInit);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
WindowContext(BrowsingContext* aBrowsingContext, uint64_t aInnerWindowId,
|
|
|
|
FieldTuple&& aFields);
|
|
|
|
virtual ~WindowContext();
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Send a given `BaseTransaction` object to the correct remote.
|
|
|
|
void SendCommitTransaction(ContentParent* aParent,
|
|
|
|
const BaseTransaction& aTxn, uint64_t aEpoch);
|
|
|
|
void SendCommitTransaction(ContentChild* aChild, const BaseTransaction& aTxn,
|
|
|
|
uint64_t aEpoch);
|
|
|
|
|
|
|
|
// Overload `CanSet` to get notifications for a particular field being set.
|
|
|
|
bool CanSet(FieldIndex<IDX_OuterWindowId>, const uint64_t& aValue,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
return GetOuterWindowId() == 0 && aValue != 0;
|
|
|
|
}
|
|
|
|
|
2020-03-04 11:59:18 +03:00
|
|
|
bool CanSet(FieldIndex<IDX_CookieJarSettings>,
|
|
|
|
const Maybe<mozilla::net::CookieJarSettingsArgs>& aValue,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-03-30 17:12:08 +03:00
|
|
|
bool CanSet(FieldIndex<IDX_HasStoragePermission>, const bool& aValue,
|
|
|
|
ContentParent* aSource) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-23 17:24:56 +03:00
|
|
|
bool CanSet(FieldIndex<IDX_IsThirdPartyWindow>,
|
|
|
|
const bool& IsThirdPartyWindow, ContentParent* aSource);
|
|
|
|
bool CanSet(FieldIndex<IDX_IsThirdPartyTrackingResourceWindow>,
|
|
|
|
const bool& aIsThirdPartyTrackingResourceWindow,
|
|
|
|
ContentParent* aSource);
|
|
|
|
|
2020-04-20 23:09:32 +03:00
|
|
|
// Overload `DidSet` to get notifications for a particular field being set.
|
2020-04-20 23:25:22 +03:00
|
|
|
//
|
|
|
|
// You can also overload the variant that gets the old value if you need it.
|
2020-04-20 23:09:32 +03:00
|
|
|
template <size_t I>
|
|
|
|
void DidSet(FieldIndex<I>) {}
|
2020-04-20 23:25:22 +03:00
|
|
|
template <size_t I, typename T>
|
|
|
|
void DidSet(FieldIndex<I>, T&& aOldValue) {}
|
2020-01-20 17:58:52 +03:00
|
|
|
|
|
|
|
uint64_t mInnerWindowId;
|
|
|
|
RefPtr<BrowsingContext> mBrowsingContext;
|
|
|
|
|
|
|
|
bool mIsDiscarded = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
using WindowContextTransaction = WindowContext::BaseTransaction;
|
|
|
|
using WindowContextInitializer = WindowContext::IPCInitializer;
|
2020-02-21 02:30:33 +03:00
|
|
|
using MaybeDiscardedWindowContext = MaybeDiscarded<WindowContext>;
|
2020-01-20 17:58:52 +03:00
|
|
|
|
|
|
|
// Don't specialize the `Transaction` object for every translation unit it's
|
|
|
|
// used in. This should help keep code size down.
|
|
|
|
extern template class syncedcontext::Transaction<WindowContext>;
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
|
|
|
|
namespace ipc {
|
2020-02-21 02:30:33 +03:00
|
|
|
template <>
|
|
|
|
struct IPDLParamTraits<dom::MaybeDiscarded<dom::WindowContext>> {
|
|
|
|
static void Write(IPC::Message* aMsg, IProtocol* aActor,
|
|
|
|
const dom::MaybeDiscarded<dom::WindowContext>& aParam);
|
|
|
|
static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
|
|
|
|
IProtocol* aActor,
|
|
|
|
dom::MaybeDiscarded<dom::WindowContext>* aResult);
|
|
|
|
};
|
|
|
|
|
2020-01-20 17:58:52 +03:00
|
|
|
template <>
|
|
|
|
struct IPDLParamTraits<dom::WindowContext::IPCInitializer> {
|
|
|
|
static void Write(IPC::Message* aMessage, IProtocol* aActor,
|
|
|
|
const dom::WindowContext::IPCInitializer& aInitializer);
|
|
|
|
|
|
|
|
static bool Read(const IPC::Message* aMessage, PickleIterator* aIterator,
|
|
|
|
IProtocol* aActor,
|
|
|
|
dom::WindowContext::IPCInitializer* aInitializer);
|
|
|
|
};
|
|
|
|
} // namespace ipc
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // !defined(mozilla_dom_WindowContext_h)
|