tor-browser

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

WindowIdentifier.h (3059B)


      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 #ifndef mozilla_hal_WindowIdentifier_h
      8 #define mozilla_hal_WindowIdentifier_h
      9 
     10 #include "nsCOMPtr.h"
     11 #include "nsTArray.h"
     12 
     13 class nsPIDOMWindowInner;
     14 
     15 namespace mozilla {
     16 namespace hal {
     17 
     18 /**
     19 * This class serves two purposes.
     20 *
     21 * First, this class wraps a pointer to a window.
     22 *
     23 * Second, WindowIdentifier lets us uniquely identify a window across
     24 * processes.  A window exposes an ID which is unique only within its
     25 * process.  Thus to identify a window, we need to know the ID of the
     26 * process which contains it.  But the scope of a process's ID is its
     27 * parent; that is, two processes with different parents might have
     28 * the same ID.
     29 *
     30 * So to identify a window, we need its ID plus the IDs of all the
     31 * processes in the path from the window's process to the root
     32 * process.  We throw in the IDs of the intermediate windows (a
     33 * content window is contained in a window at each level of the
     34 * process tree) for good measures.
     35 *
     36 * You can access this list of IDs by calling AsArray().
     37 */
     38 class WindowIdentifier {
     39 public:
     40  /**
     41   * Create an empty WindowIdentifier.  Calls to any of this object's
     42   * public methods will assert -- an empty WindowIdentifier may be
     43   * used only as a placeholder to code which promises not to touch
     44   * the object.
     45   */
     46  WindowIdentifier();
     47 
     48  /**
     49   * Wrap the given window in a WindowIdentifier.  These two
     50   * constructors automatically grab the window's ID and append it to
     51   * the array of IDs.
     52   *
     53   * Note that these constructors allow an implicit conversion to a
     54   * WindowIdentifier.
     55   */
     56  explicit WindowIdentifier(nsPIDOMWindowInner* window);
     57 
     58  /**
     59   * Create a new WindowIdentifier with the given id array and window.
     60   * This automatically grabs the window's ID and appends it to the
     61   * array.
     62   */
     63  WindowIdentifier(nsTArray<uint64_t>&& id, nsPIDOMWindowInner* window);
     64 
     65  /**
     66   * Get the list of window and process IDs we contain.
     67   */
     68  typedef nsTArray<uint64_t> IDArrayType;
     69  const IDArrayType& AsArray() const;
     70 
     71  /**
     72   * Append the ID of the ContentChild singleton to our array of
     73   * window/process IDs.
     74   */
     75  void AppendProcessID();
     76 
     77  /**
     78   * Does this WindowIdentifier identify both a window and the process
     79   * containing that window?  If so, we say it has traveled through
     80   * IPC.
     81   */
     82  bool HasTraveledThroughIPC() const;
     83 
     84  /**
     85   * Get the window this object wraps.
     86   */
     87  nsPIDOMWindowInner* GetWindow() const;
     88 
     89 private:
     90  /**
     91   * Get the ID of the window object we wrap.
     92   */
     93  uint64_t GetWindowID() const;
     94 
     95  AutoTArray<uint64_t, 3> mID;
     96  nsCOMPtr<nsPIDOMWindowInner> mWindow;
     97 #ifdef DEBUG
     98  bool mIsEmpty = false;
     99 #endif
    100 };
    101 
    102 }  // namespace hal
    103 }  // namespace mozilla
    104 
    105 #endif  // mozilla_hal_WindowIdentifier_h