Remove references to |blessStringAsTrustedResourceUrlForLegacy in <link href>.

This directive will be deleted in the future, this change prepares for it.

Change-Id: I294e1255fdbef58cf073879d9f6f8fb6997b4827
diff --git a/java/com/google/gitiles/Renderer.java b/java/com/google/gitiles/Renderer.java
index 655b8d2..9ead8bf 100644
--- a/java/com/google/gitiles/Renderer.java
+++ b/java/com/google/gitiles/Renderer.java
@@ -26,6 +26,7 @@
 import com.google.common.hash.HashCode;
 import com.google.common.hash.Hasher;
 import com.google.common.hash.Hashing;
+import com.google.common.html.types.LegacyConversions;
 import com.google.common.io.ByteStreams;
 import com.google.common.net.HttpHeaders;
 import com.google.template.soy.tofu.SoyTofu;
@@ -210,7 +211,15 @@
   }
 
   SoyTofu.Renderer newRenderer(String templateName) {
-    return getTofu().newRenderer(templateName);
+    ImmutableMap.Builder<String, Object> staticUrls = ImmutableMap.builder();
+    for (String key : STATIC_URL_GLOBALS.keySet()) {
+      staticUrls.put(
+          key.replaceFirst("^gitiles\\.", ""),
+          LegacyConversions.riskilyAssumeTrustedResourceUrl(globals.get(key)));
+    }
+    return getTofu()
+        .newRenderer(templateName)
+        .setIjData(ImmutableMap.of("staticUrls", staticUrls.build()));
   }
 
   protected abstract SoyTofu getTofu();
diff --git a/resources/com/google/gitiles/templates/BlameDetail.soy b/resources/com/google/gitiles/templates/BlameDetail.soy
index 7979de6..cdeeb3e 100644
--- a/resources/com/google/gitiles/templates/BlameDetail.soy
+++ b/resources/com/google/gitiles/templates/BlameDetail.soy
@@ -29,9 +29,10 @@
       of the revision. blameUrl: URL for a blame of this file at this commit. commitUrl: URL for
       detail about the commit. diffUrl: URL for a diff of this file at this commit. class: class
       name for tr. All keys but "class" are optional. */
+  {@inject staticUrls: ?}
 {if $regions}
   {call .header data="all"}
-    {param css: [gitiles.PRETTIFY_CSS_URL] /}
+    {param css: [$staticUrls.PRETTIFY_CSS_URL] /}
     {param containerClass: 'Container--fullWidth' /}
   {/call}
 
diff --git a/resources/com/google/gitiles/templates/Common.soy b/resources/com/google/gitiles/templates/Common.soy
index 67d5b0b..82c77ba 100644
--- a/resources/com/google/gitiles/templates/Common.soy
+++ b/resources/com/google/gitiles/templates/Common.soy
@@ -24,8 +24,9 @@
       */
   {@param? customVariant: ?}  /** variant name for custom styling. */
   {@param breadcrumbs: ?}  /** navigation breadcrumbs for this page. */
-  {@param? css: ?}  /** optional list of CSS URLs to include. */
+  {@param? css: list<?>}  /** optional list of CSS URLs to include. */
   {@param? containerClass: ?}  /** optional class to append to the main container. */
+  {@inject staticUrls: ?}
 <!DOCTYPE html>
 <html lang="en">
 <head>
@@ -38,10 +39,10 @@
     {sp}- {msg desc="name of the application"}{gitiles.SITE_TITLE}{/msg}
   </title>
 
-  <link rel="stylesheet" type="text/css" href="{gitiles.BASE_CSS_URL |blessStringAsTrustedResourceUrlForLegacy}">
+  <link rel="stylesheet" type="text/css" href="{$staticUrls.BASE_CSS_URL}">
   {if $css and length($css)}
     {for $url in $css}
-      <link rel="stylesheet" type="text/css" href="{$url |blessStringAsTrustedResourceUrlForLegacy}">
+      <link rel="stylesheet" type="text/css" href="{$url}">
     {/for}
   {/if}
   {delcall gitiles.customHeadTagPart variant="$customVariant ?: ''" /}
diff --git a/resources/com/google/gitiles/templates/Doc.soy b/resources/com/google/gitiles/templates/Doc.soy
index e7eb0d9..db1bfc6 100644
--- a/resources/com/google/gitiles/templates/Doc.soy
+++ b/resources/com/google/gitiles/templates/Doc.soy
@@ -44,6 +44,7 @@
   {@param? analyticsId: ?}  /** Google Analytics Property ID. */
   {@param? navbarHtml: ?}  /** navar.md converted to SafeHtml. */
   {@param? customVariant: ?}  /** variant name for custom styling. */
+  {@inject staticUrls: ?}
 <!DOCTYPE html>
 <html lang="en">
 <head>
@@ -52,9 +53,9 @@
     {if $siteTitle}{$siteTitle} -{sp}{/if}
     {$pageTitle}
   </title>
-  <link rel="stylesheet" type="text/css" href="{gitiles.BASE_CSS_URL |blessStringAsTrustedResourceUrlForLegacy}" />
-  <link rel="stylesheet" type="text/css" href="{gitiles.DOC_CSS_URL |blessStringAsTrustedResourceUrlForLegacy}" />
-  <link rel="stylesheet" type="text/css" href="{gitiles.PRETTIFY_CSS_URL |blessStringAsTrustedResourceUrlForLegacy}" />
+  <link rel="stylesheet" type="text/css" href="{$staticUrls.BASE_CSS_URL}" />
+  <link rel="stylesheet" type="text/css" href="{$staticUrls.DOC_CSS_URL}" />
+  <link rel="stylesheet" type="text/css" href="{$staticUrls.PRETTIFY_CSS_URL}" />
   {delcall gitiles.customHeadTagPart variant="$customVariant ?: ''" /}
 </head>
 <body class="Site">
diff --git a/resources/com/google/gitiles/templates/PathDetail.soy b/resources/com/google/gitiles/templates/PathDetail.soy
index 67bad2e..7dd283b 100644
--- a/resources/com/google/gitiles/templates/PathDetail.soy
+++ b/resources/com/google/gitiles/templates/PathDetail.soy
@@ -26,13 +26,14 @@
       org.eclipse.jgit.lib.FileMode. */
   {@param data: ?}  /** path data, matching the params for one of .treeDetail, .blobDetail,
       .symlinkDetail, or .gitlinkDetail as appropriate. */
+  {@inject staticUrls: ?}
 {if $type == 'REGULAR_FILE' or $type == 'EXECUTABLE_FILE'}
   {call .header data="all"}
-    {param css: [gitiles.PRETTIFY_CSS_URL] /}
+    {param css: [$staticUrls.PRETTIFY_CSS_URL] /}
   {/call}
 {elseif $data.readmeHtml}
   {call .header data="all"}
-    {param css: [gitiles.DOC_CSS_URL, gitiles.PRETTIFY_CSS_URL] /}
+    {param css: [$staticUrls.DOC_CSS_URL, $staticUrls.PRETTIFY_CSS_URL] /}
   {/call}
 {else}
   {call .header data="all" /}
diff --git a/resources/com/google/gitiles/templates/RepositoryIndex.soy b/resources/com/google/gitiles/templates/RepositoryIndex.soy
index 3d617d7..0a27d47 100644
--- a/resources/com/google/gitiles/templates/RepositoryIndex.soy
+++ b/resources/com/google/gitiles/templates/RepositoryIndex.soy
@@ -30,6 +30,7 @@
   {@param? moreTagsUrl: ?}  /** URL to show more branches, if necessary. */
   {@param hasLog: ?}  /** whether a log should be shown for HEAD. */
   {@param? readmeHtml: ?}  /** optional rendered README.md contents. */
+  {@inject staticUrls: ?}
 {if $readmeHtml}
   {call .header data="all"}
     {param title: $repositoryName /}
@@ -37,7 +38,7 @@
     {param menuEntries: $menuEntries /}
     {param customVariant: $customVariant /}
     {param breadcrumbs: $breadcrumbs /}
-    {param css: [gitiles.DOC_CSS_URL] /}
+    {param css: [$staticUrls.DOC_CSS_URL] /}
   {/call}
 {else}
   {call .header}
diff --git a/resources/com/google/gitiles/templates/RevisionDetail.soy b/resources/com/google/gitiles/templates/RevisionDetail.soy
index 353432c..06fa996 100644
--- a/resources/com/google/gitiles/templates/RevisionDetail.soy
+++ b/resources/com/google/gitiles/templates/RevisionDetail.soy
@@ -28,13 +28,14 @@
       "type" key with one of the org.eclipse.jgit.lib.Contants.TYPE_* constant strings, and a "data"
       key with an object whose keys correspond to the appropriate object detail template from
       ObjectDetail.soy. */
+  {@inject staticUrls: ?}
 {if $hasBlob}
   {call .header data="all"}
-    {param css: [gitiles.PRETTIFY_CSS_URL] /}
+    {param css: [$staticUrls.PRETTIFY_CSS_URL] /}
   {/call}
 {elseif $hasReadme}
   {call .header data="all"}
-    {param css: [gitiles.DOC_CSS_URL, gitiles.PRETTIFY_CSS_URL] /}
+    {param css: [$staticUrls.DOC_CSS_URL, $staticUrls.PRETTIFY_CSS_URL] /}
   {/call}
 {else}
   {call .header data="all" /}