content/base/src/FeedWriterEnabled.h

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 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "js/TypeDecls.h"
     7 #include "nsGlobalWindow.h"
     8 #include "nsIPrincipal.h"
     9 #include "nsIURI.h"
    10 #include "nsString.h"
    11 #include "xpcpublic.h"
    13 namespace mozilla {
    15 struct FeedWriterEnabled {
    16   static bool IsEnabled(JSContext* cx, JSObject* aGlobal)
    17   {
    18     // Make sure the global is a window
    19     nsGlobalWindow* win = xpc::WindowGlobalOrNull(aGlobal);
    20     if (!win) {
    21       return false;
    22     }
    24     // Make sure that the principal is about:feeds.
    25     nsCOMPtr<nsIPrincipal> principal = win->GetPrincipal();
    26     NS_ENSURE_TRUE(principal, false);
    27     nsCOMPtr<nsIURI> uri;
    28     principal->GetURI(getter_AddRefs(uri));
    29     if (!uri) {
    30       return false;
    31     }
    33     // First check the scheme to avoid getting long specs in the common case.
    34     bool isAbout = false;
    35     uri->SchemeIs("about", &isAbout);
    36     if (!isAbout) {
    37       return false;
    38     }
    40     // Now check the spec itself
    41     nsAutoCString spec;
    42     uri->GetSpec(spec);
    43     return spec.Equals("about:feeds");
    44   }
    45 };
    47 }

mercurial