from pylons import c, g

from r2.lib.pages import Ads as BaseAds


class Ads(BaseAds):
    def __init__(self):
        BaseAds.__init__(self)
        adzerk_test_srs = g.live_config.get("adzerk_test_srs")
        if adzerk_test_srs and c.site.name in adzerk_test_srs:
            if c.secure:
                self.ad_url = g.config["adzerk_https_url"].format(
                                origin=g.https_endpoint)
            else:
                self.ad_url = g.config["adzerk_url"].format(
                                origin=g.origin)
            self.frame_id = "ad_main"

@@ -277,271 +277,172 @@
     
-if c.secure:%0A                self.ad_url = g.config%5B%22adzerk_https_url%22%5D.format(%0A                                origin=g.https_endpoint)%0A            else:%0A                self.ad_url = g.config%5B%22adzerk_url%22%5D.format(%0A                                origin=g.origin
+url_key = %22adzerk_https_url%22 if c.secure else %22adzerk_url%22%0A            self.ad_url = g.config%5Burl_key%5D.format(%0A                origin=c.request_origin,%0A            
 )%0A  

Use c.request_origin for frame origin.