WindowIdentifier.h 3.1 KB

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