michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "js/TypeDecls.h" michael@0: #include "nsGlobalWindow.h" michael@0: #include "nsIPrincipal.h" michael@0: #include "nsIURI.h" michael@0: #include "nsString.h" michael@0: #include "xpcpublic.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: struct FeedWriterEnabled { michael@0: static bool IsEnabled(JSContext* cx, JSObject* aGlobal) michael@0: { michael@0: // Make sure the global is a window michael@0: nsGlobalWindow* win = xpc::WindowGlobalOrNull(aGlobal); michael@0: if (!win) { michael@0: return false; michael@0: } michael@0: michael@0: // Make sure that the principal is about:feeds. michael@0: nsCOMPtr principal = win->GetPrincipal(); michael@0: NS_ENSURE_TRUE(principal, false); michael@0: nsCOMPtr uri; michael@0: principal->GetURI(getter_AddRefs(uri)); michael@0: if (!uri) { michael@0: return false; michael@0: } michael@0: michael@0: // First check the scheme to avoid getting long specs in the common case. michael@0: bool isAbout = false; michael@0: uri->SchemeIs("about", &isAbout); michael@0: if (!isAbout) { michael@0: return false; michael@0: } michael@0: michael@0: // Now check the spec itself michael@0: nsAutoCString spec; michael@0: uri->GetSpec(spec); michael@0: return spec.Equals("about:feeds"); michael@0: } michael@0: }; michael@0: michael@0: }