Merge "Support config to explicitly enable/disable gerrit-theme.html"
diff --git a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java
index 66e9f90..d6071d5 100644
--- a/java/com/google/gerrit/server/restapi/config/GetServerInfo.java
+++ b/java/com/google/gerrit/server/restapi/config/GetServerInfo.java
@@ -157,9 +157,7 @@
     info.gerrit = getGerritInfo();
     info.noteDbEnabled = toBoolean(isNoteDbEnabled());
     info.plugin = getPluginInfo();
-    if (Files.exists(sitePaths.site_theme)) {
-      info.defaultTheme = "/static/" + SitePaths.THEME_FILENAME;
-    }
+    info.defaultTheme = getDefaultTheme();
     info.sshd = getSshdInfo();
     info.suggest = getSuggestInfo();
 
@@ -342,6 +340,22 @@
     return info;
   }
 
+  private static final String DEFAULT_THEME = "/static/" + SitePaths.THEME_FILENAME;
+
+  private String getDefaultTheme() {
+    if (config.getString("theme", null, "enableDefault") == null) {
+      // If not explicitly enabled or disabled, check for the existence of the theme file.
+      return Files.exists(sitePaths.site_theme) ? DEFAULT_THEME : null;
+    }
+    if (config.getBoolean("theme", null, "enableDefault", true)) {
+      // Return non-null theme path without checking for file existence. Even if the file doesn't
+      // exist under the site path, it may be served from a CDN (in which case it's up to the admin
+      // to also pass a proper asset path to the index Soy template).
+      return DEFAULT_THEME;
+    }
+    return null;
+  }
+
   private Map<String, String> getUrlAliasesInfo() {
     Map<String, String> urlAliases = new HashMap<>();
     for (String subsection : config.getSubsections(URL_ALIAS)) {