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.

     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 /* This Source Code Form is subject to the terms of the Mozilla Public
     4  * License, v. 2.0. If a copy of the MPL was not distributed with this
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "mozilla/dom/ContentChild.h"
     8 #include "WindowIdentifier.h"
     9 #include "nsPIDOMWindow.h"
    11 namespace mozilla {
    12 namespace hal {
    14 WindowIdentifier::WindowIdentifier()
    15   : mWindow(nullptr)
    16   , mIsEmpty(true)
    17 {
    18 }
    20 WindowIdentifier::WindowIdentifier(nsIDOMWindow *window)
    21   : mWindow(window)
    22   , mIsEmpty(false)
    23 {
    24   mID.AppendElement(GetWindowID());
    25 }
    27 WindowIdentifier::WindowIdentifier(const InfallibleTArray<uint64_t> &id, nsIDOMWindow *window)
    28   : mID(id)
    29   , mWindow(window)
    30   , mIsEmpty(false)
    31 {
    32   mID.AppendElement(GetWindowID());
    33 }
    35 WindowIdentifier::WindowIdentifier(const WindowIdentifier &other)
    36   : mID(other.mID)
    37   , mWindow(other.mWindow)
    38   , mIsEmpty(other.mIsEmpty)
    39 {
    40 }
    42 const InfallibleTArray<uint64_t>&
    43 WindowIdentifier::AsArray() const
    44 {
    45   MOZ_ASSERT(!mIsEmpty);
    46   return mID;
    47 }
    49 bool
    50 WindowIdentifier::HasTraveledThroughIPC() const
    51 {
    52   MOZ_ASSERT(!mIsEmpty);
    53   return mID.Length() >= 2;
    54 }
    56 void
    57 WindowIdentifier::AppendProcessID()
    58 {
    59   MOZ_ASSERT(!mIsEmpty);
    60   mID.AppendElement(dom::ContentChild::GetSingleton()->GetID());
    61 }
    63 uint64_t
    64 WindowIdentifier::GetWindowID() const
    65 {
    66   MOZ_ASSERT(!mIsEmpty);
    67   nsCOMPtr<nsPIDOMWindow> pidomWindow = do_QueryInterface(mWindow);
    68   if (!pidomWindow) {
    69     return UINT64_MAX;
    70   }
    71   return pidomWindow->WindowID();
    72 }
    74 nsIDOMWindow*
    75 WindowIdentifier::GetWindow() const
    76 {
    77   MOZ_ASSERT(!mIsEmpty);
    78   return mWindow;
    79 }
    81 } // namespace hal
    82 } // namespace mozilla

mercurial