tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WindowIdentifier.cpp (1532B)


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