hal/WindowIdentifier.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/hal/WindowIdentifier.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set sw=2 ts=8 et ft=cpp : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_hal_WindowIdentifier_h
    1.11 +#define mozilla_hal_WindowIdentifier_h
    1.12 +
    1.13 +#include "mozilla/Types.h"
    1.14 +#include "nsTArray.h"
    1.15 +#include "nsCOMPtr.h"
    1.16 +#include "nsIDOMWindow.h"
    1.17 +
    1.18 +namespace mozilla {
    1.19 +namespace hal {
    1.20 +
    1.21 +/**
    1.22 + * This class serves two purposes.
    1.23 + *
    1.24 + * First, this class wraps a pointer to a window.
    1.25 + *
    1.26 + * Second, WindowIdentifier lets us uniquely identify a window across
    1.27 + * processes.  A window exposes an ID which is unique only within its
    1.28 + * process.  Thus to identify a window, we need to know the ID of the
    1.29 + * process which contains it.  But the scope of a process's ID is its
    1.30 + * parent; that is, two processes with different parents might have
    1.31 + * the same ID.
    1.32 + *
    1.33 + * So to identify a window, we need its ID plus the IDs of all the
    1.34 + * processes in the path from the window's process to the root
    1.35 + * process.  We throw in the IDs of the intermediate windows (a
    1.36 + * content window is contained in a window at each level of the
    1.37 + * process tree) for good measures.
    1.38 + *
    1.39 + * You can access this list of IDs by calling AsArray().
    1.40 + */
    1.41 +class WindowIdentifier
    1.42 +{
    1.43 +public:
    1.44 +  /**
    1.45 +   * Create an empty WindowIdentifier.  Calls to any of this object's
    1.46 +   * public methods will assert -- an empty WindowIdentifier may be
    1.47 +   * used only as a placeholder to code which promises not to touch
    1.48 +   * the object.
    1.49 +   */
    1.50 +  WindowIdentifier();
    1.51 +
    1.52 +  /**
    1.53 +   * Copy constructor.
    1.54 +   */
    1.55 +  WindowIdentifier(const WindowIdentifier& other);
    1.56 +
    1.57 +  /**
    1.58 +   * Wrap the given window in a WindowIdentifier.  These two
    1.59 +   * constructors automatically grab the window's ID and append it to
    1.60 +   * the array of IDs.
    1.61 +   *
    1.62 +   * Note that these constructors allow an implicit conversion to a
    1.63 +   * WindowIdentifier.
    1.64 +   */
    1.65 +  explicit WindowIdentifier(nsIDOMWindow* window);
    1.66 +
    1.67 +  /**
    1.68 +   * Create a new WindowIdentifier with the given id array and window.
    1.69 +   * This automatically grabs the window's ID and appends it to the
    1.70 +   * array.
    1.71 +   */
    1.72 +  WindowIdentifier(const InfallibleTArray<uint64_t>& id, nsIDOMWindow* window);
    1.73 +
    1.74 +  /**
    1.75 +   * Get the list of window and process IDs we contain.
    1.76 +   */
    1.77 +  typedef InfallibleTArray<uint64_t> IDArrayType;
    1.78 +  const IDArrayType& AsArray() const;
    1.79 +
    1.80 +  /**
    1.81 +   * Append the ID of the ContentChild singleton to our array of
    1.82 +   * window/process IDs.
    1.83 +   */
    1.84 +  void AppendProcessID();
    1.85 +
    1.86 +  /**
    1.87 +   * Does this WindowIdentifier identify both a window and the process
    1.88 +   * containing that window?  If so, we say it has traveled through
    1.89 +   * IPC.
    1.90 +   */
    1.91 +  bool HasTraveledThroughIPC() const;
    1.92 +
    1.93 +  /**
    1.94 +   * Get the window this object wraps.
    1.95 +   */
    1.96 +  nsIDOMWindow* GetWindow() const;
    1.97 +
    1.98 +private:
    1.99 +  /**
   1.100 +   * Get the ID of the window object we wrap.
   1.101 +   */
   1.102 +  uint64_t GetWindowID() const;
   1.103 +
   1.104 +  AutoInfallibleTArray<uint64_t, 3> mID;
   1.105 +  nsCOMPtr<nsIDOMWindow> mWindow;
   1.106 +  bool mIsEmpty;
   1.107 +};
   1.108 +
   1.109 +} // namespace hal
   1.110 +} // namespace mozilla
   1.111 +
   1.112 +#endif // mozilla_hal_WindowIdentifier_h

mercurial