Source code

Revision control

Other Tools

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/. */
6
7
#include "WindowIdentifier.h"
8
9
#include "mozilla/dom/ContentChild.h"
10
#include "nsPIDOMWindow.h"
11
12
namespace mozilla {
13
namespace hal {
14
15
WindowIdentifier::WindowIdentifier() : mWindow(nullptr), mIsEmpty(true) {}
16
17
WindowIdentifier::WindowIdentifier(nsPIDOMWindowInner* window)
18
: mWindow(window), mIsEmpty(false) {
19
mID.AppendElement(GetWindowID());
20
}
21
22
WindowIdentifier::WindowIdentifier(const nsTArray<uint64_t>& id,
23
nsPIDOMWindowInner* window)
24
: mID(id), mWindow(window), mIsEmpty(false) {
25
mID.AppendElement(GetWindowID());
26
}
27
28
WindowIdentifier::WindowIdentifier(const WindowIdentifier& other)
29
: mID(other.mID), mWindow(other.mWindow), mIsEmpty(other.mIsEmpty) {}
30
31
const nsTArray<uint64_t>& WindowIdentifier::AsArray() const {
32
MOZ_ASSERT(!mIsEmpty);
33
return mID;
34
}
35
36
bool WindowIdentifier::HasTraveledThroughIPC() const {
37
MOZ_ASSERT(!mIsEmpty);
38
return mID.Length() >= 2;
39
}
40
41
void WindowIdentifier::AppendProcessID() {
42
MOZ_ASSERT(!mIsEmpty);
43
mID.AppendElement(dom::ContentChild::GetSingleton()->GetID());
44
}
45
46
uint64_t WindowIdentifier::GetWindowID() const {
47
MOZ_ASSERT(!mIsEmpty);
48
return mWindow ? mWindow->WindowID() : UINT64_MAX;
49
}
50
51
nsPIDOMWindowInner* WindowIdentifier::GetWindow() const {
52
MOZ_ASSERT(!mIsEmpty);
53
return mWindow;
54
}
55
56
} // namespace hal
57
} // namespace mozilla