Bug 652442 - Script feature support should depend on whether javascript is enabled. r=dholbert

This commit is contained in:
Robert Longson 2011-04-30 14:56:16 +01:00
Родитель 13943f5cd5
Коммит 0b89051dc5
8 изменённых файлов: 75 добавлений и 15 удалений

Просмотреть файл

@ -2283,18 +2283,15 @@ nsGenericElement::InternalIsSupported(nsISupports* aObject,
PL_strcmp(v, "3.0") == 0) {
*aReturn = PR_TRUE;
}
}
#ifdef MOZ_SVG
else if (PL_strcasecmp(f, "SVGEvents") == 0 ||
PL_strcasecmp(f, "SVGZoomEvents") == 0 ||
nsSVGFeatures::HaveFeature(aFeature)) {
} else if (PL_strcasecmp(f, "SVGEvents") == 0 ||
PL_strcasecmp(f, "SVGZoomEvents") == 0 ||
nsSVGFeatures::HaveFeature(aObject, aFeature)) {
if (aVersion.IsEmpty() ||
PL_strcmp(v, "1.0") == 0 ||
PL_strcmp(v, "1.1") == 0) {
*aReturn = PR_TRUE;
}
}
#endif /* MOZ_SVG */
#ifdef MOZ_SMIL
else if (NS_SMILEnabled() && PL_strcasecmp(f, "TimeControl") == 0) {
if (aVersion.IsEmpty() || PL_strcmp(v, "1.0") == 0) {

Просмотреть файл

@ -54,11 +54,31 @@
#include "nsCharSeparatedTokenizer.h"
#include "nsStyleUtil.h"
#include "nsSVGUtils.h"
#include "nsServiceManagerUtils.h"
#include "nsIPrefService.h"
/*static*/ PRBool
nsSVGFeatures::HaveFeature(const nsAString& aFeature)
nsSVGFeatures::HaveFeature(nsISupports* aObject, const nsAString& aFeature)
{
#define SVG_SUPPORTED_FEATURE(str) if (aFeature.Equals(NS_LITERAL_STRING(str).get())) return PR_TRUE;
if (aFeature.EqualsLiteral("http://www.w3.org/TR/SVG11/feature#Script")) {
nsCOMPtr<nsIContent> content(do_QueryInterface(aObject));
if (content) {
nsIDocument *doc = content->GetCurrentDoc();
if (doc && doc->IsResourceDoc()) {
// no scripting in SVG images or external resource documents
return PR_FALSE;
}
}
nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
if (prefs) {
PRBool js;
if (NS_SUCCEEDED(prefs->GetBoolPref("javascript.enabled", &js))) {
return js;
}
}
return PR_FALSE;
}
#define SVG_SUPPORTED_FEATURE(str) if (aFeature.EqualsLiteral(str)) return PR_TRUE;
#define SVG_UNSUPPORTED_FEATURE(str)
#include "nsSVGFeaturesList.h"
#undef SVG_SUPPORTED_FEATURE
@ -67,11 +87,11 @@ nsSVGFeatures::HaveFeature(const nsAString& aFeature)
}
/*static*/ PRBool
nsSVGFeatures::HaveFeatures(const nsSubstring& aFeatures)
nsSVGFeatures::HaveFeatures(nsISupports* aObject, const nsSubstring& aFeatures)
{
nsWhitespaceTokenizer tokenizer(aFeatures);
while (tokenizer.hasMoreTokens()) {
if (!HaveFeature(tokenizer.nextToken())) {
if (!HaveFeature(aObject, tokenizer.nextToken())) {
return PR_FALSE;
}
}
@ -81,7 +101,7 @@ nsSVGFeatures::HaveFeatures(const nsSubstring& aFeatures)
/*static*/ PRBool
nsSVGFeatures::HaveExtension(const nsAString& aExtension)
{
#define SVG_SUPPORTED_EXTENSION(str) if (aExtension.Equals(NS_LITERAL_STRING(str).get())) return PR_TRUE;
#define SVG_SUPPORTED_EXTENSION(str) if (aExtension.EqualsLiteral(str)) return PR_TRUE;
SVG_SUPPORTED_EXTENSION("http://www.w3.org/1999/xhtml")
#ifdef MOZ_MATHML
SVG_SUPPORTED_EXTENSION("http://www.w3.org/1998/Math/MathML")
@ -186,7 +206,7 @@ nsSVGFeatures::PassesConditionalProcessingTests(nsIContent *aContent,
// Required Features
nsAutoString value;
if (aContent->GetAttr(kNameSpaceID_None, nsGkAtoms::requiredFeatures, value)) {
if (value.IsEmpty() || !HaveFeatures(value)) {
if (value.IsEmpty() || !HaveFeatures(aContent, value)) {
return PR_FALSE;
}
}

Просмотреть файл

@ -50,11 +50,13 @@ public:
/**
* Check whether we support the given feature string.
*
* @param aObject the object, which should support the feature,
* for example nsIDOMNode or nsIDOMDOMImplementation
* @param aFeature one of the feature strings specified at
* http://www.w3.org/TR/SVG11/feature.html
*/
static PRBool
HaveFeature(const nsAString& aFeature);
HaveFeature(nsISupports* aObject, const nsAString& aFeature);
/**
* Compare the language name(s) in a systemLanguage attribute to the
@ -97,11 +99,13 @@ private:
/**
* Check whether we support the given list of feature strings.
*
* @param aObject the object, which should support the feature,
* for example nsIDOMNode or nsIDOMDOMImplementation
* @param aFeatures a whitespace separated list containing one or more of the
* feature strings specified at http://www.w3.org/TR/SVG11/feature.html
*/
static PRBool
HaveFeatures(const nsSubstring& aFeatures);
HaveFeatures(nsISupports* aObject, const nsSubstring& aFeatures);
/**
* Check whether we support the given extension string.

Просмотреть файл

@ -81,7 +81,6 @@ SVG_SUPPORTED_FEATURE("http://www.w3.org/TR/SVG11/feature#Hyperlinking")
SVG_SUPPORTED_FEATURE("http://www.w3.org/TR/SVG11/feature#XlinkAttribute")
SVG_UNSUPPORTED_FEATURE("http://www.w3.org/TR/SVG11/feature#ExternalResourcesRequired")
SVG_UNSUPPORTED_FEATURE("http://www.w3.org/TR/SVG11/feature#View")
SVG_SUPPORTED_FEATURE("http://www.w3.org/TR/SVG11/feature#Script")
SVG_UNSUPPORTED_FEATURE("http://www.w3.org/TR/SVG11/feature#Font")
SVG_UNSUPPORTED_FEATURE("http://www.w3.org/TR/SVG11/feature#BasicFont")
SVG_SUPPORTED_FEATURE("http://www.w3.org/TR/SVG11/feature#Extensibility")

Просмотреть файл

@ -103,6 +103,10 @@ fails-if(d2d) == img-novb-width-slice-1.html img-novb-width-all-1-ref.html #
== svg-image-recursive-2a.svg svg-image-recursive-2-ref.svg
== svg-image-recursive-2b.html svg-image-recursive-2-ref.svg
# test that scripting feature is not supported in images or referenced documents
== svg-image-script-1.svg lime100x100.svg
== svg-image-script-2.svg lime100x100.svg
# tests for external resources vs. data URIs in SVG as an image
== svg-image-datauri-1.html lime100x100.svg
HTTP == svg-image-datauri-1.html lime100x100.svg

Просмотреть файл

@ -0,0 +1,11 @@
<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
width="100" height="100">
<defs>
<pattern id="p1" patternUnits="userSpaceOnUse" width="100%" height="100%">
<rect width="100%" height="100%" fill="lime"/>
<rect id="r1" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Script" width="100%" height="100%" fill="orange"/>
</pattern>
</defs>
<rect width="100%" height="100%" fill="lime"/>
<rect requiredFeatures="http://www.w3.org/TR/SVG11/feature#Script" width="100%" height="100%" fill="blue"/>
</svg>

После

Ширина:  |  Высота:  |  Размер: 541 B

Просмотреть файл

@ -0,0 +1,6 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="100" height="100">
<rect width="100%" height="100%" fill="red"/>
<image width="100%" height="100%" xlink:href="script100x100.svg"/>
</svg>

После

Ширина:  |  Высота:  |  Размер: 244 B

Просмотреть файл

@ -0,0 +1,19 @@
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
width="100" height="100" class="reftest-wait">
<rect width="100%" height="100%" fill="red"/>
<rect width="100%" height="100%" fill="url(script100x100.svg#p1)"/>
<rect id="r1" width="100%" height="100%" fill="transparent"/>
<script type="application/javascript">
document.addEventListener("MozReftestInvalidate", doTest, false);
// in case we're not gecko
setTimeout(doTest, 5000);
function doTest() {
// force a repaint
var r1 = document.getElementById("r1");
document.documentElement.removeChild(r1);
document.documentElement.removeAttribute('class');
}
</script>
</svg>

После

Ширина:  |  Высота:  |  Размер: 720 B