Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#ifndef mozilla_dom_WindowContext_h
8
#define mozilla_dom_WindowContext_h
9
10
#include "mozilla/dom/MaybeDiscarded.h"
11
#include "mozilla/dom/SyncedContext.h"
12
#include "mozilla/net/NeckoChannelParams.h"
13
14
namespace mozilla {
15
namespace dom {
16
17
#define MOZ_EACH_WC_FIELD(FIELD) \
18
FIELD(OuterWindowId, uint64_t) \
19
FIELD(CookieJarSettings, Maybe<mozilla::net::CookieJarSettingsArgs>) \
20
FIELD(HasStoragePermission, bool)
21
22
class WindowContext : public nsISupports, public nsWrapperCache {
23
MOZ_DECL_SYNCED_CONTEXT(WindowContext, MOZ_EACH_WC_FIELD)
24
25
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
26
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WindowContext)
27
28
public:
29
static already_AddRefed<WindowContext> GetById(uint64_t aInnerWindowId);
30
static LogModule* GetLog();
31
32
BrowsingContext* GetBrowsingContext() const { return mBrowsingContext; }
33
BrowsingContextGroup* Group() const;
34
uint64_t Id() const { return InnerWindowId(); }
35
uint64_t InnerWindowId() const { return mInnerWindowId; }
36
uint64_t OuterWindowId() const { return GetOuterWindowId(); }
37
bool IsDiscarded() const { return mIsDiscarded; }
38
39
// Cast this object to it's parent-process canonical form.
40
WindowGlobalParent* Canonical();
41
42
nsIGlobalObject* GetParentObject() const;
43
JSObject* WrapObject(JSContext* cx,
44
JS::Handle<JSObject*> aGivenProto) override;
45
46
void Discard();
47
48
struct IPCInitializer {
49
uint64_t mInnerWindowId;
50
uint64_t mBrowsingContextId;
51
52
FieldTuple mFields;
53
};
54
IPCInitializer GetIPCInitializer() {
55
return {mInnerWindowId, mBrowsingContext->Id(), mFields.Fields()};
56
}
57
58
static already_AddRefed<WindowContext> Create(WindowGlobalChild* aWindow);
59
static void CreateFromIPC(IPCInitializer&& aInit);
60
61
protected:
62
WindowContext(BrowsingContext* aBrowsingContext, uint64_t aInnerWindowId,
63
FieldTuple&& aFields);
64
virtual ~WindowContext();
65
66
void Init();
67
68
private:
69
// Send a given `BaseTransaction` object to the correct remote.
70
void SendCommitTransaction(ContentParent* aParent,
71
const BaseTransaction& aTxn, uint64_t aEpoch);
72
void SendCommitTransaction(ContentChild* aChild, const BaseTransaction& aTxn,
73
uint64_t aEpoch);
74
75
// Overload `CanSet` to get notifications for a particular field being set.
76
bool CanSet(FieldIndex<IDX_OuterWindowId>, const uint64_t& aValue,
77
ContentParent* aSource) {
78
return GetOuterWindowId() == 0 && aValue != 0;
79
}
80
81
bool CanSet(FieldIndex<IDX_CookieJarSettings>,
82
const Maybe<mozilla::net::CookieJarSettingsArgs>& aValue,
83
ContentParent* aSource) {
84
return true;
85
}
86
87
bool CanSet(FieldIndex<IDX_HasStoragePermission>, const bool& aValue,
88
ContentParent* aSource) {
89
return true;
90
}
91
92
// Overload `DidSet` to get notifications for a particular field being set.
93
template <size_t I>
94
void DidSet(FieldIndex<I>) {}
95
96
uint64_t mInnerWindowId;
97
RefPtr<BrowsingContext> mBrowsingContext;
98
99
bool mIsDiscarded = false;
100
};
101
102
using WindowContextTransaction = WindowContext::BaseTransaction;
103
using WindowContextInitializer = WindowContext::IPCInitializer;
104
using MaybeDiscardedWindowContext = MaybeDiscarded<WindowContext>;
105
106
// Don't specialize the `Transaction` object for every translation unit it's
107
// used in. This should help keep code size down.
108
extern template class syncedcontext::Transaction<WindowContext>;
109
110
} // namespace dom
111
112
namespace ipc {
113
template <>
114
struct IPDLParamTraits<dom::MaybeDiscarded<dom::WindowContext>> {
115
static void Write(IPC::Message* aMsg, IProtocol* aActor,
116
const dom::MaybeDiscarded<dom::WindowContext>& aParam);
117
static bool Read(const IPC::Message* aMsg, PickleIterator* aIter,
118
IProtocol* aActor,
119
dom::MaybeDiscarded<dom::WindowContext>* aResult);
120
};
121
122
template <>
123
struct IPDLParamTraits<dom::WindowContext::IPCInitializer> {
124
static void Write(IPC::Message* aMessage, IProtocol* aActor,
125
const dom::WindowContext::IPCInitializer& aInitializer);
126
127
static bool Read(const IPC::Message* aMessage, PickleIterator* aIterator,
128
IProtocol* aActor,
129
dom::WindowContext::IPCInitializer* aInitializer);
130
};
131
} // namespace ipc
132
} // namespace mozilla
133
134
#endif // !defined(mozilla_dom_WindowContext_h)