hal/WindowIdentifier.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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 #include "mozilla/dom/ContentChild.h"
michael@0 8 #include "WindowIdentifier.h"
michael@0 9 #include "nsPIDOMWindow.h"
michael@0 10
michael@0 11 namespace mozilla {
michael@0 12 namespace hal {
michael@0 13
michael@0 14 WindowIdentifier::WindowIdentifier()
michael@0 15 : mWindow(nullptr)
michael@0 16 , mIsEmpty(true)
michael@0 17 {
michael@0 18 }
michael@0 19
michael@0 20 WindowIdentifier::WindowIdentifier(nsIDOMWindow *window)
michael@0 21 : mWindow(window)
michael@0 22 , mIsEmpty(false)
michael@0 23 {
michael@0 24 mID.AppendElement(GetWindowID());
michael@0 25 }
michael@0 26
michael@0 27 WindowIdentifier::WindowIdentifier(const InfallibleTArray<uint64_t> &id, nsIDOMWindow *window)
michael@0 28 : mID(id)
michael@0 29 , mWindow(window)
michael@0 30 , mIsEmpty(false)
michael@0 31 {
michael@0 32 mID.AppendElement(GetWindowID());
michael@0 33 }
michael@0 34
michael@0 35 WindowIdentifier::WindowIdentifier(const WindowIdentifier &other)
michael@0 36 : mID(other.mID)
michael@0 37 , mWindow(other.mWindow)
michael@0 38 , mIsEmpty(other.mIsEmpty)
michael@0 39 {
michael@0 40 }
michael@0 41
michael@0 42 const InfallibleTArray<uint64_t>&
michael@0 43 WindowIdentifier::AsArray() const
michael@0 44 {
michael@0 45 MOZ_ASSERT(!mIsEmpty);
michael@0 46 return mID;
michael@0 47 }
michael@0 48
michael@0 49 bool
michael@0 50 WindowIdentifier::HasTraveledThroughIPC() const
michael@0 51 {
michael@0 52 MOZ_ASSERT(!mIsEmpty);
michael@0 53 return mID.Length() >= 2;
michael@0 54 }
michael@0 55
michael@0 56 void
michael@0 57 WindowIdentifier::AppendProcessID()
michael@0 58 {
michael@0 59 MOZ_ASSERT(!mIsEmpty);
michael@0 60 mID.AppendElement(dom::ContentChild::GetSingleton()->GetID());
michael@0 61 }
michael@0 62
michael@0 63 uint64_t
michael@0 64 WindowIdentifier::GetWindowID() const
michael@0 65 {
michael@0 66 MOZ_ASSERT(!mIsEmpty);
michael@0 67 nsCOMPtr<nsPIDOMWindow> pidomWindow = do_QueryInterface(mWindow);
michael@0 68 if (!pidomWindow) {
michael@0 69 return UINT64_MAX;
michael@0 70 }
michael@0 71 return pidomWindow->WindowID();
michael@0 72 }
michael@0 73
michael@0 74 nsIDOMWindow*
michael@0 75 WindowIdentifier::GetWindow() const
michael@0 76 {
michael@0 77 MOZ_ASSERT(!mIsEmpty);
michael@0 78 return mWindow;
michael@0 79 }
michael@0 80
michael@0 81 } // namespace hal
michael@0 82 } // namespace mozilla

mercurial