Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
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 }