diff --git a/r2/r2/controllers/front.py b/r2/r2/controllers/front.py index 00a8665dc..a86ef5118 100755 --- a/r2/r2/controllers/front.py +++ b/r2/r2/controllers/front.py @@ -407,9 +407,12 @@ class FrontController(RedditController, OAuth2ResourceController): if c.site.stylesheet_is_static: # TODO: X-Private-Subreddit? - return redirect_to(c.site.stylesheet_url) + redirect_to(Reddit.get_subreddit_stylesheet_url()) else: - stylesheet_contents = c.site.stylesheet_contents + if not c.secure: + stylesheet_contents = c.site.stylesheet_contents + else: + stylesheet_contents = c.site.stylesheet_contents_secure if stylesheet_contents: c.allow_loggedin_cache = True diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index c21627eb4..c298d12eb 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -246,6 +246,23 @@ class Reddit(Templated): ) self.toolbars = self.build_toolbars() + self.subreddit_stylesheet_url = self.get_subreddit_stylesheet_url() + + @staticmethod + def get_subreddit_stylesheet_url(): + if c.can_apply_styles and c.allow_styles: + if c.secure: + if c.site.stylesheet_url_https: + return c.site.stylesheet_url_https + elif c.site.stylesheet_contents_secure: + return c.site.stylesheet_url + else: + if c.site.stylesheet_url_http: + return c.site.stylesheet_url_http + elif c.site.stylesheet_is_static: + return c.site.legacy_static_stylesheet_url + elif c.site.stylesheet_contents: + return c.site.stylesheet_url def wiki_actions_menu(self, moderator=False): buttons = [] diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index 945da8078..9e5e0d873 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -167,15 +167,17 @@ class BaseSite(object): ".css")) @property - def stylesheet_url(self): - from r2.lib.template_helpers import static, get_domain + def legacy_static_stylesheet_url(self): + from r2.lib.template_helpers import static + assert self.stylesheet_is_static + return static(self.static_stylesheet_name, kind='sr_stylesheet') - if self.stylesheet_is_static: - return static(self.static_stylesheet_name, kind='sr_stylesheet') - else: - return "http://%s/stylesheet.css?v=%s" % (get_domain(cname=False, - subreddit=True), - self.stylesheet_hash) + @property + def stylesheet_url(self): + from r2.lib.template_helpers import get_domain + return "//%s/stylesheet.css?v=%s" % (get_domain(cname=False, + subreddit=True), + self.stylesheet_hash) class SubredditExists(Exception): pass @@ -188,7 +190,10 @@ class Subreddit(Thing, Printable, BaseSite): _defaults = dict(BaseSite._defaults, stylesheet_rtl=None, stylesheet_contents='', + stylesheet_contents_secure='', stylesheet_modified=None, + stylesheet_url_http="", + stylesheet_url_https="", header_size=None, allow_top=False, # overridden in "_new" reported=0, diff --git a/r2/r2/templates/frametoolbar.html b/r2/r2/templates/frametoolbar.html index e5211441a..e4dbcfa07 100644 --- a/r2/r2/templates/frametoolbar.html +++ b/r2/r2/templates/frametoolbar.html @@ -36,6 +36,9 @@ toolbar = new toolbar_p("${panel_size('expanded')}", "${panel_size('collapsed')}"); %def> +<%def name="sr_stylesheets()"> +%def> + <%def name="bodyContent()">