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