Load fonts directly from Gerrit instead of 3rd party domains

In environments without public Internet access or where tight control
of loaded resources is necessary, loading fonts from 3rd party domains
might be restricted. Hence, we switch to the fonts directly supplied
by Gerrit.

gitiles loads only the fonts 'Open Sans' and 'Source Code Pro'. Gerrit
provides 'Open Sans' directly and offers 'Roboto Mono' as monospace
alternative to 'Source Code Pro'.

Change-Id: I4f4a0b7dd575cbc27641063e05d13b8a43a51d8b
diff --git a/BUILD b/BUILD
index e45eca3..109f79a 100644
--- a/BUILD
+++ b/BUILD
@@ -25,6 +25,17 @@
     outs = ["gitiles-servlet-resources.jar"],
     cmd = " && ".join([
         "unzip -qd $$TMP $(location @gitiles-servlet//jar) \"com/google/gitiles/static/*\"",
+        "cd $$TMP/com/google/gitiles/static",
+        # To avoid loading 3rd party resources, we adapt gitiles' CSS to
+        # load fonts from Gerrit directly:
+        # 1. Strip out Google font CSS imports
+        "sed -e '\\%^@import .//fonts\\.googleapis\\.com/%d' -i base.css",
+        # 2. Add Gerrit's fonts CSS
+        "sed -e 's%^\\(.*Common styles and definitions.*\\)$$%" +
+          "\\1\\n\\n@import \"../../../styles/fonts.css\";%' -i base.css",
+        # 3. Use Gerrit's Roboto Mono for Source Code Pro
+        "sed -e 's/Source Code Pro/Roboto Mono/g' -i base.css",
+        # Switching from `static` to `+static` (see comment in plugin definiton)
         "cd $$TMP/com/google/gitiles",
         "mv static +static",
         "zip -qr $$ROOT/$@ .",