DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Implementation

Mercurial (5b81998bb7ab)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set sw=2 ts=8 et ft=cpp : */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_hal_WindowIdentifier_h
#define mozilla_hal_WindowIdentifier_h

#include "mozilla/Types.h"
#include "nsTArray.h"
#include "nsCOMPtr.h"
#include "nsIDOMWindow.h"

namespace mozilla {
namespace hal {

/**
 * This class serves two purposes.
 *
 * First, this class wraps a pointer to a window.
 *
 * Second, WindowIdentifier lets us uniquely identify a window across
 * processes.  A window exposes an ID which is unique only within its
 * process.  Thus to identify a window, we need to know the ID of the
 * process which contains it.  But the scope of a process's ID is its
 * parent; that is, two processes with different parents might have
 * the same ID.
 *
 * So to identify a window, we need its ID plus the IDs of all the
 * processes in the path from the window's process to the root
 * process.  We throw in the IDs of the intermediate windows (a
 * content window is contained in a window at each level of the
 * process tree) for good measures.
 *
 * You can access this list of IDs by calling AsArray().
 */
class WindowIdentifier
{
public:
  /**
   * Create an empty WindowIdentifier.  Calls to any of this object's
   * public methods will assert -- an empty WindowIdentifier may be
   * used only as a placeholder to code which promises not to touch
   * the object.
   */
  WindowIdentifier();

  /**
   * Copy constructor.
   */
  WindowIdentifier(const WindowIdentifier& other);

  /**
   * Wrap the given window in a WindowIdentifier.  These two
   * constructors automatically grab the window's ID and append it to
   * the array of IDs.
   *
   * Note that these constructors allow an implicit conversion to a
   * WindowIdentifier.
   */
  explicit WindowIdentifier(nsIDOMWindow* window);

  /**
   * Create a new WindowIdentifier with the given id array and window.
   * This automatically grabs the window's ID and appends it to the
   * array.
   */
  WindowIdentifier(const nsTArray<uint64_t>& id, nsIDOMWindow* window);

  /**
   * Get the list of window and process IDs we contain.
   */
  typedef InfallibleTArray<uint64_t> IDArrayType;
  const IDArrayType& AsArray() const;

  /**
   * Append the ID of the ContentChild singleton to our array of
   * window/process IDs.
   */
  void AppendProcessID();

  /**
   * Does this WindowIdentifier identify both a window and the process
   * containing that window?  If so, we say it has traveled through
   * IPC.
   */
  bool HasTraveledThroughIPC() const;

  /**
   * Get the window this object wraps.
   */
  nsIDOMWindow* GetWindow() const;

private:
  /**
   * Get the ID of the window object we wrap.
   */
  uint64_t GetWindowID() const;

  AutoInfallibleTArray<uint64_t, 3> mID;
  nsCOMPtr<nsIDOMWindow> mWindow;
  bool mIsEmpty;
};

} // namespace hal
} // namespace mozilla

#endif // mozilla_hal_WindowIdentifier_h