Bug 1737692 [wpt PR 31378] - Fetch: Plumb request initiator through passthrough servi...
[gecko.git] / hal / WindowIdentifier.cpp
blobdc108016910f9e58ff21048997d4996f084f4d20
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 #include "WindowIdentifier.h"
9 #include "mozilla/dom/ContentChild.h"
10 #include "nsPIDOMWindow.h"
12 namespace mozilla {
13 namespace hal {
15 WindowIdentifier::WindowIdentifier()
16 : mWindow(nullptr)
17 #ifdef DEBUG
19 mIsEmpty(true)
20 #endif
24 WindowIdentifier::WindowIdentifier(nsPIDOMWindowInner* window)
25 : mWindow(window) {
26 mID.AppendElement(GetWindowID());
29 WindowIdentifier::WindowIdentifier(nsTArray<uint64_t>&& id,
30 nsPIDOMWindowInner* window)
31 : mID(std::move(id)), mWindow(window) {
32 mID.AppendElement(GetWindowID());
35 const nsTArray<uint64_t>& WindowIdentifier::AsArray() const {
36 MOZ_ASSERT(!mIsEmpty);
37 return mID;
40 bool WindowIdentifier::HasTraveledThroughIPC() const {
41 MOZ_ASSERT(!mIsEmpty);
42 return mID.Length() >= 2;
45 void WindowIdentifier::AppendProcessID() {
46 MOZ_ASSERT(!mIsEmpty);
47 mID.AppendElement(dom::ContentChild::GetSingleton()->GetID());
50 uint64_t WindowIdentifier::GetWindowID() const {
51 MOZ_ASSERT(!mIsEmpty);
52 return mWindow ? mWindow->WindowID() : UINT64_MAX;
55 nsPIDOMWindowInner* WindowIdentifier::GetWindow() const {
56 MOZ_ASSERT(!mIsEmpty);
57 return mWindow;
60 } // namespace hal
61 } // namespace mozilla