Line data Source code
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 0 : WindowIdentifier::WindowIdentifier()
16 : : mWindow(nullptr)
17 0 : , mIsEmpty(true)
18 : {
19 0 : }
20 :
21 0 : WindowIdentifier::WindowIdentifier(nsPIDOMWindowInner* window)
22 : : mWindow(window)
23 0 : , mIsEmpty(false)
24 : {
25 0 : mID.AppendElement(GetWindowID());
26 0 : }
27 :
28 0 : WindowIdentifier::WindowIdentifier(const InfallibleTArray<uint64_t> &id,
29 0 : nsPIDOMWindowInner* window)
30 : : mID(id)
31 : , mWindow(window)
32 0 : , mIsEmpty(false)
33 : {
34 0 : mID.AppendElement(GetWindowID());
35 0 : }
36 :
37 0 : WindowIdentifier::WindowIdentifier(const WindowIdentifier &other)
38 : : mID(other.mID)
39 : , mWindow(other.mWindow)
40 0 : , mIsEmpty(other.mIsEmpty)
41 : {
42 0 : }
43 :
44 : const InfallibleTArray<uint64_t>&
45 0 : WindowIdentifier::AsArray() const
46 : {
47 0 : MOZ_ASSERT(!mIsEmpty);
48 0 : return mID;
49 : }
50 :
51 : bool
52 0 : WindowIdentifier::HasTraveledThroughIPC() const
53 : {
54 0 : MOZ_ASSERT(!mIsEmpty);
55 0 : return mID.Length() >= 2;
56 : }
57 :
58 : void
59 0 : WindowIdentifier::AppendProcessID()
60 : {
61 0 : MOZ_ASSERT(!mIsEmpty);
62 0 : mID.AppendElement(dom::ContentChild::GetSingleton()->GetID());
63 0 : }
64 :
65 : uint64_t
66 0 : WindowIdentifier::GetWindowID() const
67 : {
68 0 : MOZ_ASSERT(!mIsEmpty);
69 0 : return mWindow ? mWindow->WindowID() : UINT64_MAX;
70 : }
71 :
72 : nsPIDOMWindowInner*
73 0 : WindowIdentifier::GetWindow() const
74 : {
75 0 : MOZ_ASSERT(!mIsEmpty);
76 0 : return mWindow;
77 : }
78 :
79 : } // namespace hal
80 : } // namespace mozilla
|