michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et ft=cpp : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_hal_WindowIdentifier_h michael@0: #define mozilla_hal_WindowIdentifier_h michael@0: michael@0: #include "mozilla/Types.h" michael@0: #include "nsTArray.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsIDOMWindow.h" michael@0: michael@0: namespace mozilla { michael@0: namespace hal { michael@0: michael@0: /** michael@0: * This class serves two purposes. michael@0: * michael@0: * First, this class wraps a pointer to a window. michael@0: * michael@0: * Second, WindowIdentifier lets us uniquely identify a window across michael@0: * processes. A window exposes an ID which is unique only within its michael@0: * process. Thus to identify a window, we need to know the ID of the michael@0: * process which contains it. But the scope of a process's ID is its michael@0: * parent; that is, two processes with different parents might have michael@0: * the same ID. michael@0: * michael@0: * So to identify a window, we need its ID plus the IDs of all the michael@0: * processes in the path from the window's process to the root michael@0: * process. We throw in the IDs of the intermediate windows (a michael@0: * content window is contained in a window at each level of the michael@0: * process tree) for good measures. michael@0: * michael@0: * You can access this list of IDs by calling AsArray(). michael@0: */ michael@0: class WindowIdentifier michael@0: { michael@0: public: michael@0: /** michael@0: * Create an empty WindowIdentifier. Calls to any of this object's michael@0: * public methods will assert -- an empty WindowIdentifier may be michael@0: * used only as a placeholder to code which promises not to touch michael@0: * the object. michael@0: */ michael@0: WindowIdentifier(); michael@0: michael@0: /** michael@0: * Copy constructor. michael@0: */ michael@0: WindowIdentifier(const WindowIdentifier& other); michael@0: michael@0: /** michael@0: * Wrap the given window in a WindowIdentifier. These two michael@0: * constructors automatically grab the window's ID and append it to michael@0: * the array of IDs. michael@0: * michael@0: * Note that these constructors allow an implicit conversion to a michael@0: * WindowIdentifier. michael@0: */ michael@0: explicit WindowIdentifier(nsIDOMWindow* window); michael@0: michael@0: /** michael@0: * Create a new WindowIdentifier with the given id array and window. michael@0: * This automatically grabs the window's ID and appends it to the michael@0: * array. michael@0: */ michael@0: WindowIdentifier(const InfallibleTArray& id, nsIDOMWindow* window); michael@0: michael@0: /** michael@0: * Get the list of window and process IDs we contain. michael@0: */ michael@0: typedef InfallibleTArray IDArrayType; michael@0: const IDArrayType& AsArray() const; michael@0: michael@0: /** michael@0: * Append the ID of the ContentChild singleton to our array of michael@0: * window/process IDs. michael@0: */ michael@0: void AppendProcessID(); michael@0: michael@0: /** michael@0: * Does this WindowIdentifier identify both a window and the process michael@0: * containing that window? If so, we say it has traveled through michael@0: * IPC. michael@0: */ michael@0: bool HasTraveledThroughIPC() const; michael@0: michael@0: /** michael@0: * Get the window this object wraps. michael@0: */ michael@0: nsIDOMWindow* GetWindow() const; michael@0: michael@0: private: michael@0: /** michael@0: * Get the ID of the window object we wrap. michael@0: */ michael@0: uint64_t GetWindowID() const; michael@0: michael@0: AutoInfallibleTArray mID; michael@0: nsCOMPtr mWindow; michael@0: bool mIsEmpty; michael@0: }; michael@0: michael@0: } // namespace hal michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_hal_WindowIdentifier_h