|
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/. */ |
|
5 |
|
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" |
|
12 |
|
13 namespace mozilla { |
|
14 |
|
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 } |
|
23 |
|
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 } |
|
32 |
|
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 } |
|
39 |
|
40 // Now check the spec itself |
|
41 nsAutoCString spec; |
|
42 uri->GetSpec(spec); |
|
43 return spec.Equals("about:feeds"); |
|
44 } |
|
45 }; |
|
46 |
|
47 } |