Bug 595397: Add a pref to enable XUL and XBL for file:. r=dveditz a=blocker

This commit is contained in:
Jonas Sicking 2010-11-23 00:50:55 -08:00
parent 6948fc9a18
commit 6aeb8ea89c
4 changed files with 27 additions and 22 deletions

View File

@ -1708,6 +1708,12 @@ public:
*/
static void FlushLayoutForTree(nsIDOMWindow* aWindow);
/**
* Returns true if content with the given principal is allowed to use XUL
* and XBL and false otherwise.
*/
static bool AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal);
private:
static PRBool InitializeEventTable();
@ -1797,6 +1803,7 @@ private:
static nsIInterfaceRequestor* sSameOriginChecker;
static PRBool sIsHandlingKeyBoardEvent;
static PRBool sAllowXULXBL_for_file;
};
#define NS_HOLD_JS_OBJECTS(obj, clazz) \

View File

@ -264,6 +264,7 @@ nsIJSRuntimeService *nsAutoGCRoot::sJSRuntimeService;
JSRuntime *nsAutoGCRoot::sJSScriptRuntime;
PRBool nsContentUtils::sIsHandlingKeyBoardEvent = PR_FALSE;
PRBool nsContentUtils::sAllowXULXBL_for_file = PR_FALSE;
PRBool nsContentUtils::sInitialized = PR_FALSE;
@ -506,6 +507,9 @@ nsContentUtils::Init()
sBlockedScriptRunners = new nsCOMArray<nsIRunnable>;
NS_ENSURE_TRUE(sBlockedScriptRunners, NS_ERROR_OUT_OF_MEMORY);
nsContentUtils::AddBoolPrefVarCache("dom.allow_XUL_XBL_for_file",
&sAllowXULXBL_for_file);
sInitialized = PR_TRUE;
return NS_OK;
@ -6416,6 +6420,20 @@ nsContentUtils::LayerManagerForDocument(nsIDocument *aDoc)
return manager.forget();
}
bool
nsContentUtils::AllowXULXBLForPrincipal(nsIPrincipal* aPrincipal)
{
if (IsSystemPrincipal(aPrincipal)) {
return true;
}
nsCOMPtr<nsIURI> princURI;
aPrincipal->GetURI(getter_AddRefs(princURI));
return princURI &&
((sAllowXULXBL_for_file && SchemeIs(princURI, "file")) ||
IsSitePermAllow(princURI, "allowXULXBL"));
}
NS_IMPL_ISUPPORTS1(nsIContentUtils, nsIContentUtils)

View File

@ -3878,19 +3878,7 @@ nsDocument::ScriptLoader()
PRBool
nsDocument::InternalAllowXULXBL()
{
if (nsContentUtils::IsSystemPrincipal(NodePrincipal())) {
mAllowXULXBL = eTriTrue;
return PR_TRUE;
}
nsCOMPtr<nsIURI> princURI;
NodePrincipal()->GetURI(getter_AddRefs(princURI));
if (!princURI) {
mAllowXULXBL = eTriFalse;
return PR_FALSE;
}
if (nsContentUtils::IsSitePermAllow(princURI, "allowXULXBL")) {
if (nsContentUtils::AllowXULXBLForPrincipal(NodePrincipal())) {
mAllowXULXBL = eTriTrue;
return PR_TRUE;
}

View File

@ -170,15 +170,7 @@ MayUseXULXBL(nsIChannel* aChannel)
securityManager->GetChannelPrincipal(aChannel, getter_AddRefs(principal));
NS_ENSURE_TRUE(principal, PR_FALSE);
if (nsContentUtils::IsSystemPrincipal(principal)) {
return PR_TRUE;
}
nsCOMPtr<nsIURI> uri;
principal->GetURI(getter_AddRefs(uri));
NS_ENSURE_TRUE(uri, PR_FALSE);
return nsContentUtils::IsSitePermAllow(uri, "allowXULXBL");
return nsContentUtils::AllowXULXBLForPrincipal(principal);
}
NS_IMETHODIMP