Bug 1839170 - Refactor Snap pulling, Add Firefox Snap Core22 and GNOME 42 SDK symbols...
[gecko.git] / hal / WindowIdentifier.h
blob11c5140f61b10db934cb6577d3c672b48f2c5619
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et ft=cpp : */
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/. */
7 #ifndef mozilla_hal_WindowIdentifier_h
8 #define mozilla_hal_WindowIdentifier_h
10 #include "mozilla/Types.h"
11 #include "nsCOMPtr.h"
12 #include "nsTArray.h"
14 class nsPIDOMWindowInner;
16 namespace mozilla {
17 namespace hal {
19 /**
20 * This class serves two purposes.
22 * First, this class wraps a pointer to a window.
24 * Second, WindowIdentifier lets us uniquely identify a window across
25 * processes. A window exposes an ID which is unique only within its
26 * process. Thus to identify a window, we need to know the ID of the
27 * process which contains it. But the scope of a process's ID is its
28 * parent; that is, two processes with different parents might have
29 * the same ID.
31 * So to identify a window, we need its ID plus the IDs of all the
32 * processes in the path from the window's process to the root
33 * process. We throw in the IDs of the intermediate windows (a
34 * content window is contained in a window at each level of the
35 * process tree) for good measures.
37 * You can access this list of IDs by calling AsArray().
39 class WindowIdentifier {
40 public:
41 /**
42 * Create an empty WindowIdentifier. Calls to any of this object's
43 * public methods will assert -- an empty WindowIdentifier may be
44 * used only as a placeholder to code which promises not to touch
45 * the object.
47 WindowIdentifier();
49 /**
50 * Wrap the given window in a WindowIdentifier. These two
51 * constructors automatically grab the window's ID and append it to
52 * the array of IDs.
54 * Note that these constructors allow an implicit conversion to a
55 * WindowIdentifier.
57 explicit WindowIdentifier(nsPIDOMWindowInner* window);
59 /**
60 * Create a new WindowIdentifier with the given id array and window.
61 * This automatically grabs the window's ID and appends it to the
62 * array.
64 WindowIdentifier(nsTArray<uint64_t>&& id, nsPIDOMWindowInner* window);
66 /**
67 * Get the list of window and process IDs we contain.
69 typedef nsTArray<uint64_t> IDArrayType;
70 const IDArrayType& AsArray() const;
72 /**
73 * Append the ID of the ContentChild singleton to our array of
74 * window/process IDs.
76 void AppendProcessID();
78 /**
79 * Does this WindowIdentifier identify both a window and the process
80 * containing that window? If so, we say it has traveled through
81 * IPC.
83 bool HasTraveledThroughIPC() const;
85 /**
86 * Get the window this object wraps.
88 nsPIDOMWindowInner* GetWindow() const;
90 private:
91 /**
92 * Get the ID of the window object we wrap.
94 uint64_t GetWindowID() const;
96 AutoTArray<uint64_t, 3> mID;
97 nsCOMPtr<nsPIDOMWindowInner> mWindow;
98 #ifdef DEBUG
99 bool mIsEmpty = false;
100 #endif
103 } // namespace hal
104 } // namespace mozilla
106 #endif // mozilla_hal_WindowIdentifier_h