mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 659842 - about:support was creating a WebGL context even if webgl.disabled=true - r=karlt
This patch removes SafeToCreateCanvas3DContext, and checks webgl.disabled in WebGLContext::SetDimensions.
This commit is contained in:
parent
66919c207e
commit
46f5712e1f
@ -297,9 +297,6 @@ WebGLContext::GetCanvas(nsIDOMHTMLCanvasElement **canvas)
|
||||
NS_IMETHODIMP
|
||||
WebGLContext::SetCanvasElement(nsHTMLCanvasElement* aParentCanvas)
|
||||
{
|
||||
if (aParentCanvas && !SafeToCreateCanvas3DContext(aParentCanvas))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mCanvasElement = aParentCanvas;
|
||||
|
||||
return NS_OK;
|
||||
@ -364,6 +361,8 @@ WebGLContext::SetContextOptions(nsIPropertyBag *aOptions)
|
||||
NS_IMETHODIMP
|
||||
WebGLContext::SetDimensions(PRInt32 width, PRInt32 height)
|
||||
{
|
||||
/*** early success return cases ***/
|
||||
|
||||
if (mCanvasElement) {
|
||||
HTMLCanvasElement()->InvalidateCanvas();
|
||||
}
|
||||
@ -389,8 +388,37 @@ WebGLContext::SetDimensions(PRInt32 width, PRInt32 height)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*** end of early success return cases ***/
|
||||
|
||||
ScopedGfxFeatureReporter reporter("WebGL");
|
||||
|
||||
// At this point we know that the old context is not going to survive, even though we still don't
|
||||
// know if creating the new context will succeed.
|
||||
DestroyResourcesAndContext();
|
||||
|
||||
// Get some prefs for some preferred/overriden things
|
||||
nsCOMPtr<nsIPrefBranch> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(prefService != nsnull, NS_ERROR_FAILURE);
|
||||
|
||||
PRBool forceOSMesa = PR_FALSE;
|
||||
PRBool preferEGL = PR_FALSE;
|
||||
PRBool preferOpenGL = PR_FALSE;
|
||||
PRBool forceEnabled = PR_FALSE;
|
||||
PRBool disabled = PR_FALSE;
|
||||
PRBool verbose = PR_FALSE;
|
||||
|
||||
prefService->GetBoolPref("webgl.force_osmesa", &forceOSMesa);
|
||||
prefService->GetBoolPref("webgl.prefer-egl", &preferEGL);
|
||||
prefService->GetBoolPref("webgl.prefer-native-gl", &preferOpenGL);
|
||||
prefService->GetBoolPref("webgl.force-enabled", &forceEnabled);
|
||||
prefService->GetBoolPref("webgl.disabled", &disabled);
|
||||
prefService->GetBoolPref("webgl.verbose", &verbose);
|
||||
|
||||
if (disabled)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mVerbose = verbose;
|
||||
|
||||
// We're going to create an entirely new context. If our
|
||||
// generation is not 0 right now (that is, if this isn't the first
|
||||
// context we're creating), we may have to dispatch a context lost
|
||||
@ -402,10 +430,6 @@ WebGLContext::SetDimensions(PRInt32 width, PRInt32 height)
|
||||
if (!(mGeneration+1).valid())
|
||||
return NS_ERROR_FAILURE; // exit without changing the value of mGeneration
|
||||
|
||||
// We're going to recreate our context, so make sure we clean up
|
||||
// after ourselves.
|
||||
DestroyResourcesAndContext();
|
||||
|
||||
gl::ContextFormat format(gl::ContextFormat::BasicRGBA32);
|
||||
if (mOptions.depth) {
|
||||
format.depth = 24;
|
||||
@ -428,22 +452,6 @@ WebGLContext::SetDimensions(PRInt32 width, PRInt32 height)
|
||||
format.minAlpha = 0;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefBranch> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
||||
NS_ENSURE_TRUE(prefService != nsnull, NS_ERROR_FAILURE);
|
||||
|
||||
PRBool verbose = PR_FALSE;
|
||||
prefService->GetBoolPref("webgl.verbose", &verbose);
|
||||
mVerbose = verbose;
|
||||
|
||||
// Get some prefs for some preferred/overriden things
|
||||
PRBool forceOSMesa = PR_FALSE;
|
||||
PRBool preferEGL = PR_FALSE;
|
||||
PRBool preferOpenGL = PR_FALSE;
|
||||
PRBool forceEnabled = PR_FALSE;
|
||||
prefService->GetBoolPref("webgl.force_osmesa", &forceOSMesa);
|
||||
prefService->GetBoolPref("webgl.prefer-egl", &preferEGL);
|
||||
prefService->GetBoolPref("webgl.prefer-native-gl", &preferOpenGL);
|
||||
prefService->GetBoolPref("webgl.force-enabled", &forceEnabled);
|
||||
if (PR_GetEnv("MOZ_WEBGL_PREFER_EGL")) {
|
||||
preferEGL = PR_TRUE;
|
||||
}
|
||||
|
@ -448,7 +448,6 @@ protected:
|
||||
return mEnabledExtensions[ext] != nsnull;
|
||||
}
|
||||
|
||||
PRBool SafeToCreateCanvas3DContext(nsHTMLCanvasElement *canvasElement);
|
||||
PRBool InitAndValidateGL();
|
||||
PRBool ValidateBuffers(PRInt32* maxAllowedCount, const char *info);
|
||||
PRBool ValidateCapabilityEnum(WebGLenum cap, const char *info);
|
||||
|
@ -67,138 +67,6 @@
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
PRBool
|
||||
WebGLContext::SafeToCreateCanvas3DContext(nsHTMLCanvasElement *canvasElement)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// first see if we're a chrome context
|
||||
PRBool is_caller_chrome = PR_FALSE;
|
||||
nsCOMPtr<nsIScriptSecurityManager> ssm =
|
||||
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
rv = ssm->SubjectPrincipalIsSystem(&is_caller_chrome);
|
||||
if (NS_SUCCEEDED(rv) && is_caller_chrome)
|
||||
return PR_TRUE;
|
||||
|
||||
// not chrome? check pref.
|
||||
|
||||
// first check our global pref
|
||||
nsCOMPtr<nsIPrefBranch> prefService = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
PRBool disabled = PR_FALSE;
|
||||
rv = prefService->GetBoolPref("webgl.disabled", &disabled);
|
||||
if (NS_SUCCEEDED(rv) && !disabled) {
|
||||
// the all-sites pref was set, we're good to go
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// otherwise we'll check content prefs
|
||||
nsCOMPtr<nsIContentPrefService> cpsvc = do_GetService("@mozilla.org/content-pref/service;1", &rv);
|
||||
if (NS_FAILED(rv)) {
|
||||
LogMessage("Canvas 3D: Failed to get Content Pref service, can't verify that canvas3d is ok for this site!");
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
// grab our content URI
|
||||
nsCOMPtr<nsIURI> contentURI;
|
||||
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
rv = ssm->GetSubjectPrincipal(getter_AddRefs(principal));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
if (!principal) {
|
||||
// seriously? no script executing, but not the system principal?
|
||||
return PR_FALSE;
|
||||
}
|
||||
rv = principal->GetURI(getter_AddRefs(contentURI));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
// our pref is 'webgl.enabled'
|
||||
nsCOMPtr<nsIVariant> val;
|
||||
rv = cpsvc->GetPref(contentURI, NS_LITERAL_STRING("webgl.enabled"), getter_AddRefs(val));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
PRInt32 iv;
|
||||
rv = val->GetAsInt32(&iv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// 1 means "yes, allowed"
|
||||
if (iv == 1)
|
||||
return PR_TRUE;
|
||||
|
||||
// -1 means "no, don't ask me again"
|
||||
if (iv == -1)
|
||||
return PR_FALSE;
|
||||
|
||||
// otherwise, we'll throw an event and maybe ask the user
|
||||
}
|
||||
|
||||
// grab the document that we can use to create the event
|
||||
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(canvasElement);
|
||||
nsCOMPtr<nsIDOMDocument> domDoc;
|
||||
rv = node->GetOwnerDocument(getter_AddRefs(domDoc));
|
||||
|
||||
/*
|
||||
// figure out where to throw the event. we just go for the outermost
|
||||
// document. ideally, I want to throw the event to the <browser> if one exists,
|
||||
// otherwise the topmost document, but that's more work than I want to deal with.
|
||||
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc);
|
||||
while (doc->GetParentDocument())
|
||||
doc = doc->GetParentDocument();
|
||||
*/
|
||||
|
||||
// set up the event
|
||||
nsCOMPtr<nsIDOMDocumentEvent> docEvent = do_QueryInterface(domDoc);
|
||||
NS_ENSURE_TRUE(docEvent, PR_FALSE);
|
||||
|
||||
nsCOMPtr<nsIDOMEvent> eventBase;
|
||||
rv = docEvent->CreateEvent(NS_LITERAL_STRING("DataContainerEvent"), getter_AddRefs(eventBase));
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
rv = eventBase->InitEvent(NS_LITERAL_STRING("Canvas3DContextRequest"), PR_TRUE, PR_TRUE);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
nsCOMPtr<nsIDOMDataContainerEvent> event = do_QueryInterface(eventBase);
|
||||
nsCOMPtr<nsIPrivateDOMEvent> privateEvent = do_QueryInterface(eventBase);
|
||||
NS_ENSURE_TRUE(event && privateEvent, PR_FALSE);
|
||||
|
||||
// mark it as trusted, so that it'll bubble upwards into chrome
|
||||
privateEvent->SetTrusted(PR_TRUE);
|
||||
|
||||
// set some extra data on the event
|
||||
nsCOMPtr<nsIContentURIGrouper> grouper = do_GetService("@mozilla.org/content-pref/hostname-grouper;1", &rv);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
nsAutoString group;
|
||||
rv = grouper->Group(contentURI, group);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
nsCOMPtr<nsIWritableVariant> groupVariant = do_CreateInstance(NS_VARIANT_CONTRACTID);
|
||||
nsCOMPtr<nsIWritableVariant> uriVariant = do_CreateInstance(NS_VARIANT_CONTRACTID);
|
||||
|
||||
groupVariant->SetAsAString(group);
|
||||
uriVariant->SetAsISupports(contentURI);
|
||||
|
||||
rv = event->SetData(NS_LITERAL_STRING("group"), groupVariant);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
rv = event->SetData(NS_LITERAL_STRING("uri"), uriVariant);
|
||||
NS_ENSURE_SUCCESS(rv, PR_FALSE);
|
||||
|
||||
// our target...
|
||||
nsCOMPtr<nsIDOMEventTarget> targ = do_QueryInterface(canvasElement);
|
||||
|
||||
// and go.
|
||||
PRBool defaultActionEnabled;
|
||||
targ->DispatchEvent(event, &defaultActionEnabled);
|
||||
#endif
|
||||
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
WebGLContext::LogMessage(const char *fmt, ...)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user