mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1238042 - Extract a helper function to check if a JSObject is a global with a particular about: URI. r=ehsan
This commit is contained in:
parent
578bf7a99a
commit
b547e2b7c8
@ -5,43 +5,14 @@
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "js/TypeDecls.h"
|
||||
#include "nsGlobalWindow.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsString.h"
|
||||
#include "xpcpublic.h"
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
struct FeedWriterEnabled {
|
||||
static bool IsEnabled(JSContext* cx, JSObject* aGlobal)
|
||||
{
|
||||
// Make sure the global is a window
|
||||
nsGlobalWindow* win = xpc::WindowGlobalOrNull(aGlobal);
|
||||
if (!win) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure that the principal is about:feeds.
|
||||
nsCOMPtr<nsIPrincipal> principal = win->GetPrincipal();
|
||||
NS_ENSURE_TRUE(principal, false);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
principal->GetURI(getter_AddRefs(uri));
|
||||
if (!uri) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// First check the scheme to avoid getting long specs in the common case.
|
||||
bool isAbout = false;
|
||||
uri->SchemeIs("about", &isAbout);
|
||||
if (!isAbout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now check the spec itself
|
||||
nsAutoCString spec;
|
||||
uri->GetSpec(spec);
|
||||
return spec.EqualsLiteral("about:feeds");
|
||||
return nsContentUtils::IsSpecificAboutPage(aGlobal, "about:feeds");
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -8894,3 +8894,37 @@ nsContentUtils::SerializeNodeToMarkup(nsINode* aRoot,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
nsContentUtils::IsSpecificAboutPage(JSObject* aGlobal, const char* aUri)
|
||||
{
|
||||
// aUri must start with about: or this isn't the right function to be using.
|
||||
MOZ_ASSERT(strncmp(aUri, "about:", 6) == 0);
|
||||
|
||||
// Make sure the global is a window
|
||||
nsGlobalWindow* win = xpc::WindowGlobalOrNull(aGlobal);
|
||||
if (!win) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure that the principal is about:feeds.
|
||||
nsCOMPtr<nsIPrincipal> principal = win->GetPrincipal();
|
||||
NS_ENSURE_TRUE(principal, false);
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
principal->GetURI(getter_AddRefs(uri));
|
||||
if (!uri) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// First check the scheme to avoid getting long specs in the common case.
|
||||
bool isAbout = false;
|
||||
uri->SchemeIs("about", &isAbout);
|
||||
if (!isAbout) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Now check the spec itself
|
||||
nsAutoCString spec;
|
||||
uri->GetSpec(spec);
|
||||
return spec.EqualsASCII(aUri);
|
||||
}
|
||||
|
@ -2565,6 +2565,14 @@ public:
|
||||
bool aDescendentsOnly,
|
||||
nsAString& aOut);
|
||||
|
||||
/*
|
||||
* Returns true iff the provided JSObject is a global, and its URI matches
|
||||
* the provided about: URI.
|
||||
* @param aGlobal the JSObject whose URI to check, if it is a global.
|
||||
* @param aUri the URI to match, e.g. "about:feeds"
|
||||
*/
|
||||
static bool IsSpecificAboutPage(JSObject* aGlobal, const char* aUri);
|
||||
|
||||
private:
|
||||
static bool InitializeEventTable();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user