michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et ft=cpp : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "mozilla/dom/ContentChild.h" michael@0: #include "WindowIdentifier.h" michael@0: #include "nsPIDOMWindow.h" michael@0: michael@0: namespace mozilla { michael@0: namespace hal { michael@0: michael@0: WindowIdentifier::WindowIdentifier() michael@0: : mWindow(nullptr) michael@0: , mIsEmpty(true) michael@0: { michael@0: } michael@0: michael@0: WindowIdentifier::WindowIdentifier(nsIDOMWindow *window) michael@0: : mWindow(window) michael@0: , mIsEmpty(false) michael@0: { michael@0: mID.AppendElement(GetWindowID()); michael@0: } michael@0: michael@0: WindowIdentifier::WindowIdentifier(const InfallibleTArray &id, nsIDOMWindow *window) michael@0: : mID(id) michael@0: , mWindow(window) michael@0: , mIsEmpty(false) michael@0: { michael@0: mID.AppendElement(GetWindowID()); michael@0: } michael@0: michael@0: WindowIdentifier::WindowIdentifier(const WindowIdentifier &other) michael@0: : mID(other.mID) michael@0: , mWindow(other.mWindow) michael@0: , mIsEmpty(other.mIsEmpty) michael@0: { michael@0: } michael@0: michael@0: const InfallibleTArray& michael@0: WindowIdentifier::AsArray() const michael@0: { michael@0: MOZ_ASSERT(!mIsEmpty); michael@0: return mID; michael@0: } michael@0: michael@0: bool michael@0: WindowIdentifier::HasTraveledThroughIPC() const michael@0: { michael@0: MOZ_ASSERT(!mIsEmpty); michael@0: return mID.Length() >= 2; michael@0: } michael@0: michael@0: void michael@0: WindowIdentifier::AppendProcessID() michael@0: { michael@0: MOZ_ASSERT(!mIsEmpty); michael@0: mID.AppendElement(dom::ContentChild::GetSingleton()->GetID()); michael@0: } michael@0: michael@0: uint64_t michael@0: WindowIdentifier::GetWindowID() const michael@0: { michael@0: MOZ_ASSERT(!mIsEmpty); michael@0: nsCOMPtr pidomWindow = do_QueryInterface(mWindow); michael@0: if (!pidomWindow) { michael@0: return UINT64_MAX; michael@0: } michael@0: return pidomWindow->WindowID(); michael@0: } michael@0: michael@0: nsIDOMWindow* michael@0: WindowIdentifier::GetWindow() const michael@0: { michael@0: MOZ_ASSERT(!mIsEmpty); michael@0: return mWindow; michael@0: } michael@0: michael@0: } // namespace hal michael@0: } // namespace mozilla