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