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 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at:
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is Mozilla Code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * The Mozilla Foundation
20 : * Portions created by the Initial Developer are Copyright (C) 2011
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : * Justin Lebar <justin.lebar@gmail.com>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either the GNU General Public License Version 2 or later (the "GPL"), or
28 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #ifndef mozilla_hal_WindowIdentifier_h
41 : #define mozilla_hal_WindowIdentifier_h
42 :
43 : #include "mozilla/Types.h"
44 : #include "nsTArray.h"
45 : #include "nsCOMPtr.h"
46 : #include "nsIDOMWindow.h"
47 :
48 : namespace mozilla {
49 : namespace hal {
50 :
51 : /**
52 : * This class serves two purposes.
53 : *
54 : * First, this class wraps a pointer to a window.
55 : *
56 : * Second, WindowIdentifier lets us uniquely identify a window across
57 : * processes. A window exposes an ID which is unique only within its
58 : * process. Thus to identify a window, we need to know the ID of the
59 : * process which contains it. But the scope of a process's ID is its
60 : * parent; that is, two processes with different parents might have
61 : * the same ID.
62 : *
63 : * So to identify a window, we need its ID plus the IDs of all the
64 : * processes in the path from the window's process to the root
65 : * process. We throw in the IDs of the intermediate windows (a
66 : * content window is contained in a window at each level of the
67 : * process tree) for good measures.
68 : *
69 : * You can access this list of IDs by calling AsArray().
70 : */
71 : class WindowIdentifier
72 0 : {
73 : public:
74 : /**
75 : * Create an empty WindowIdentifier. Calls to any of this object's
76 : * public methods will assert -- an empty WindowIdentifier may be
77 : * used only as a placeholder to code which promises not to touch
78 : * the object.
79 : */
80 : WindowIdentifier();
81 :
82 : /**
83 : * Copy constructor.
84 : */
85 : WindowIdentifier(const WindowIdentifier& other);
86 :
87 : /**
88 : * Wrap the given window in a WindowIdentifier. These two
89 : * constructors automatically grab the window's ID and append it to
90 : * the array of IDs.
91 : *
92 : * Note that these constructors allow an implicit conversion to a
93 : * WindowIdentifier.
94 : */
95 : explicit WindowIdentifier(nsIDOMWindow* window);
96 :
97 : /**
98 : * Create a new WindowIdentifier with the given id array and window.
99 : * This automatically grabs the window's ID and appends it to the
100 : * array.
101 : */
102 : WindowIdentifier(const nsTArray<uint64>& id, nsIDOMWindow* window);
103 :
104 : /**
105 : * Get the list of window and process IDs we contain.
106 : */
107 : typedef InfallibleTArray<uint64> IDArrayType;
108 : const IDArrayType& AsArray() const;
109 :
110 : /**
111 : * Append the ID of the ContentChild singleton to our array of
112 : * window/process IDs.
113 : */
114 : void AppendProcessID();
115 :
116 : /**
117 : * Does this WindowIdentifier identify both a window and the process
118 : * containing that window? If so, we say it has traveled through
119 : * IPC.
120 : */
121 : bool HasTraveledThroughIPC() const;
122 :
123 : /**
124 : * Get the window this object wraps.
125 : */
126 : nsIDOMWindow* GetWindow() const;
127 :
128 : private:
129 : /**
130 : * Get the ID of the window object we wrap.
131 : */
132 : uint64 GetWindowID() const;
133 :
134 : AutoInfallibleTArray<uint64, 3> mID;
135 : nsCOMPtr<nsIDOMWindow> mWindow;
136 : bool mIsEmpty;
137 : };
138 :
139 : } // namespace hal
140 : } // namespace mozilla
141 :
142 : #endif // mozilla_hal_WindowIdentifier_h
|