Copy "zSoyz" constants into an internal utility class

This limits the dependency of Gitiles on internal Soy packages, which
makes it easier for the Soy team to refactor their code without breaking
Gitiles.

Change-Id: I5fee52f994277fa2e19762e272585acd1176474e
diff --git a/java/com/google/gitiles/doc/ImageLoader.java b/java/com/google/gitiles/doc/ImageLoader.java
index b7b2531..3e536d7 100644
--- a/java/com/google/gitiles/doc/ImageLoader.java
+++ b/java/com/google/gitiles/doc/ImageLoader.java
@@ -18,7 +18,6 @@
 import com.google.common.io.BaseEncoding;
 import com.google.gitiles.GitilesView;
 import com.google.gitiles.MimeTypes;
-import com.google.template.soy.shared.restricted.EscapingConventions.FilterImageDataUri;
 import java.io.IOException;
 import javax.annotation.Nullable;
 import org.eclipse.jgit.errors.LargeObjectException;
@@ -54,7 +53,8 @@
     if (data != null) {
       return data;
     }
-    return FilterImageDataUri.INSTANCE.getInnocuousOutput();
+    // Otherwise return something that is both clearly an image, but clearly invalid.
+    return SoyConstants.IMAGE_URI_INNOCUOUS_OUTPUT;
   }
 
   private String inlineMaybe(@Nullable String markdownPath, String imagePath) {
diff --git a/java/com/google/gitiles/doc/MarkdownToHtml.java b/java/com/google/gitiles/doc/MarkdownToHtml.java
index f6289e2..64758b2 100644
--- a/java/com/google/gitiles/doc/MarkdownToHtml.java
+++ b/java/com/google/gitiles/doc/MarkdownToHtml.java
@@ -24,8 +24,6 @@
 import com.google.gitiles.doc.html.HtmlBuilder;
 import com.google.gitiles.doc.html.SoyHtmlBuilder;
 import com.google.template.soy.data.SanitizedContent;
-import com.google.template.soy.shared.restricted.EscapingConventions.FilterImageDataUri;
-import com.google.template.soy.shared.restricted.EscapingConventions.FilterNormalizeUri;
 import java.util.List;
 import javax.annotation.Nullable;
 import org.commonmark.ext.gfm.strikethrough.Strikethrough;
@@ -402,7 +400,7 @@
       if (HtmlBuilder.isValidGitUri(target)) {
         return target;
       }
-      return FilterNormalizeUri.INSTANCE.getInnocuousOutput();
+      return SoyConstants.NORMAL_URI_INNOCUOUS_OUTPUT;
     }
 
     String anchor = "";
@@ -414,7 +412,7 @@
 
     String dest = PathResolver.resolve(filePath, target);
     if (dest == null || view == null) {
-      return FilterNormalizeUri.INSTANCE.getInnocuousOutput();
+      return SoyConstants.NORMAL_URI_INNOCUOUS_OUTPUT;
     }
 
     GitilesView.Builder b;
@@ -442,7 +440,7 @@
     } else if (imageLoader != null) {
       return imageLoader.inline(filePath, dest);
     }
-    return FilterImageDataUri.INSTANCE.getInnocuousOutput();
+    return SoyConstants.IMAGE_URI_INNOCUOUS_OUTPUT;
   }
 
   public void visit(TableBlock node) {
diff --git a/java/com/google/gitiles/doc/Navbar.java b/java/com/google/gitiles/doc/Navbar.java
index cd63e3f..d936d9f 100644
--- a/java/com/google/gitiles/doc/Navbar.java
+++ b/java/com/google/gitiles/doc/Navbar.java
@@ -19,7 +19,6 @@
 import com.google.common.base.CharMatcher;
 import com.google.common.base.Splitter;
 import com.google.gitiles.doc.html.HtmlBuilder;
-import com.google.template.soy.shared.restricted.EscapingConventions.FilterImageDataUri;
 import com.google.template.soy.shared.restricted.Sanitizers;
 import java.util.HashMap;
 import java.util.Map;
@@ -85,7 +84,7 @@
     } else if (HtmlBuilder.isImageDataUri(url)) {
       return Sanitizers.filterImageDataUri(url);
     } else {
-      return FilterImageDataUri.INSTANCE.getInnocuousOutput();
+      return SoyConstants.IMAGE_URI_INNOCUOUS_OUTPUT;
     }
   }
 
diff --git a/java/com/google/gitiles/doc/SoyConstants.java b/java/com/google/gitiles/doc/SoyConstants.java
new file mode 100644
index 0000000..d56382c
--- /dev/null
+++ b/java/com/google/gitiles/doc/SoyConstants.java
@@ -0,0 +1,50 @@
+// Copyright 2018 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package com.google.gitiles.doc;
+
+/**
+ * Constant definitions for Soy utilities.
+ *
+ * <p>These constant definitions are copied from Soy internal packages, and are repeated here at the
+ * request of Soy team to limit our dependencies on their internal packages. The text still refers
+ * to "zSoyz" for consistency with other non-Markdown parts of Gitiles.
+ */
+final class SoyConstants {
+  /**
+   * Innocuous output when an image data URI fails escaping.
+   *
+   * <p>When escaper fails, we need to return something that is both clearly an image, but clearly
+   * invalid. We don't want the browser to fetch anything. We also don't necessarily want a
+   * transparent gif, since it doesn't alert developers to an issue. And finally, by not starting
+   * with GIF89a, we ensure the browser doesn't attempt to actually decode it and crash.
+   *
+   * <p>Based on {@link
+   * com.google.template.soy.shared.restricted.EscapingConventions.FilterImageDataUri}.
+   */
+  static String IMAGE_URI_INNOCUOUS_OUTPUT = "data:image/gif;base64,zSoyz";
+
+  /**
+   * Innocuous output when a URI fails escaping.
+   *
+   * <p>about:invalid is registered in http://www.w3.org/TR/css3-values/#about-invalid: "The
+   * about:invalid URI references a non-existent document with a generic error condition. It can be
+   * used when a URI is necessary, but the default value shouldn't be resolveable as any type of
+   * document."
+   *
+   * <p>Based on {@link
+   * com.google.template.soy.shared.restricted.EscapingConventions.FilterNormalizeUri}.
+   */
+  static String NORMAL_URI_INNOCUOUS_OUTPUT = "about:invalid#zSoyz";
+}