Bug 623945: Null-check animationController before using it, in SVGDocumentWrapper::StartAnimation/StopAnimation. r=roc a=joe
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 10 Jan 2011 21:58:00 -0800
changeset 60275 2bf97aec7fdda56a69923a05fbe98a86d6d609c1
parent 60274 1d5cbf9617ea03b39f6fe532aa646766bbe4682d
child 60276 d9ec3e791cee28acabdea730df351900fa4f7627
push id17906
push userdholbert@mozilla.com
push dateTue, 11 Jan 2011 06:05:32 +0000
treeherdermozilla-central@d9ec3e791cee [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, joe
bugs623945
milestone2.0b10pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 623945: Null-check animationController before using it, in SVGDocumentWrapper::StartAnimation/StopAnimation. r=roc a=joe
content/svg/content/test/Makefile.in
content/svg/content/test/animated-svg-image-helper.html
content/svg/content/test/animated-svg-image-helper.svg
content/svg/content/test/test_SVGAnimatedImageSMILDisabled.html
modules/libpr0n/src/SVGDocumentWrapper.cpp
--- a/content/svg/content/test/Makefile.in
+++ b/content/svg/content/test/Makefile.in
@@ -63,16 +63,19 @@ include $(topsrcdir)/config/rules.mk
 		test_getSubStringLength.xhtml \
 		getSubStringLength-helper.svg \
 		test_isSupported.xhtml \
 		test_nonAnimStrings.xhtml \
 		test_pathSeg.xhtml \
 		test_pointer-events.xhtml \
 		test_scientific.html \
 		scientific-helper.svg \
+		test_SVGAnimatedImageSMILDisabled.html \
+		animated-svg-image-helper.html \
+		animated-svg-image-helper.svg \
 		test_SVGLengthList.xhtml \
 		test_SVGPathSegList.xhtml \
 		test_SVGStyleElement.xhtml \
 		test_SVGxxxList.xhtml \
 		test_switch.xhtml \
 		switch-helper.svg \
 		test_text.html \
 		text-helper.svg \
new file mode 100644
--- /dev/null
+++ b/content/svg/content/test/animated-svg-image-helper.html
@@ -0,0 +1,3 @@
+<html>
+  <img src="animated-svg-image-helper.svg">
+</html>
new file mode 100644
--- /dev/null
+++ b/content/svg/content/test/animated-svg-image-helper.svg
@@ -0,0 +1,3 @@
+<svg xmlns="http://www.w3.org/2000/svg">
+  <set attributeName="font-size" to="50"/>
+</svg>
new file mode 100644
--- /dev/null
+++ b/content/svg/content/test/test_SVGAnimatedImageSMILDisabled.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=623945
+-->
+<head>
+  <title>Test for Bug 623945</title>
+  <script type="application/javascript" src="/MochiKit/packed.js"></script>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=623945">Mozilla Bug 623945</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 623945 **/
+/* This test makes sure we don't crash when using an animated SVG image with
+ * the 'svg.smil.enabled' pref turned off. */
+
+SimpleTest.waitForExplicitFinish();
+
+function setSMILEnabled(enabled) {
+  netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
+  var prefs = Components.classes["@mozilla.org/preferences-service;1"]
+                 .getService(Components.interfaces.nsIPrefBranch);
+  prefs.setBoolPref("svg.smil.enabled", enabled);
+}
+
+function iframeLoaded() {
+  // Woo-hoo, we didn't crash! Declare success!
+  ok(true, "got through the test without crashing");
+
+  // Re-enable SMIL pref for future tests.
+  setSMILEnabled(true);
+  SimpleTest.finish();
+}
+
+function main() {
+  // First, we turn off the SMIL pref:
+  setSMILEnabled(false);
+
+  // Then, we load an HTML document with an animated SVG image.
+  var iframe = document.createElement("iframe");
+  iframe.onload = iframeLoaded;
+  iframe.src = "animated-svg-image-helper.html";
+  document.getElementById("content").appendChild(iframe);
+}
+
+main();
+
+</script>
+</pre>
+</body>
+</html>
--- a/modules/libpr0n/src/SVGDocumentWrapper.cpp
+++ b/modules/libpr0n/src/SVGDocumentWrapper.cpp
@@ -199,34 +199,40 @@ SVGDocumentWrapper::StartAnimation()
   // Can be called for animated images during shutdown, after we've
   // already Observe()'d XPCOM shutdown and cleared out our mViewer pointer.
   if (!mViewer)
     return;
 
   nsIDocument* doc = mViewer->GetDocument();
   if (doc) {
 #ifdef MOZ_SMIL
-    doc->GetAnimationController()->Resume(nsSMILTimeContainer::PAUSE_IMAGE);
+    nsSMILAnimationController* controller = doc->GetAnimationController();
+    if (controller) {
+      controller->Resume(nsSMILTimeContainer::PAUSE_IMAGE);
+    }
 #endif // MOZ_SMIL
     doc->SetImagesNeedAnimating(PR_TRUE);
   }
 }
 
 void
 SVGDocumentWrapper::StopAnimation()
 {
   // Can be called for animated images during shutdown, after we've
   // already Observe()'d XPCOM shutdown and cleared out our mViewer pointer.
   if (!mViewer)
     return;
 
   nsIDocument* doc = mViewer->GetDocument();
   if (doc) {
 #ifdef MOZ_SMIL
-    doc->GetAnimationController()->Pause(nsSMILTimeContainer::PAUSE_IMAGE);
+    nsSMILAnimationController* controller = doc->GetAnimationController();
+    if (controller) {
+      controller->Pause(nsSMILTimeContainer::PAUSE_IMAGE);
+    }
 #endif // MOZ_SMIL
     doc->SetImagesNeedAnimating(PR_FALSE);
   }
 }
 
 void
 SVGDocumentWrapper::ResetAnimation()
 {