content/base/src/FeedWriterEnabled.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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