Chrome Origin Trial support
authorGilles Dubuc <gilles@wikimedia.org>
Wed, 20 Feb 2019 08:49:28 +0000 (09:49 +0100)
committerGilles Dubuc <gilles@wikimedia.org>
Mon, 25 Feb 2019 17:11:35 +0000 (18:11 +0100)
Bug: T216595
Change-Id: I74b8824a87e6f52a84d2f8a9708501fc05f73266

includes/DefaultSettings.php
includes/OutputPage.php

index 537f411..1761b00 100644 (file)
@@ -9019,6 +9019,14 @@ $wgEnableRollbackConfirmationPrompt = true;
  */
 $wgEnableBlockNoticeStats = false;
 
+/**
+ * Origin Trials tokens.
+ *
+ * @since 1.34
+ * @var array
+ */
+$wgOriginTrials = [];
+
 /**
  * For really cool vim folding this needs to be at the end:
  * vim: foldmarker=@{,@} foldmethod=marker
index 9b766bb..461df94 100644 (file)
@@ -2522,6 +2522,18 @@ class OutputPage extends ContextSource {
                return false;
        }
 
+       /**
+        * Get the Origin-Trial header values. This is used to enable Chrome Origin
+        * Trials: https://github.com/GoogleChrome/OriginTrials
+        *
+        * @return array
+        */
+       private function getOriginTrials() {
+               $config = $this->getConfig();
+
+               return $config->get( 'OriginTrials' );
+       }
+
        /**
         * Send cache control HTTP headers
         */
@@ -2688,6 +2700,11 @@ class OutputPage extends ContextSource {
                        $response->header( "X-Frame-Options: $frameOptions" );
                }
 
+               $originTrials = $this->getOriginTrials();
+               foreach ( $originTrials as $originTrial ) {
+                       $response->header( "Origin-Trial: $originTrial", false );
+               }
+
                ContentSecurityPolicy::sendHeaders( $this );
 
                if ( $this->mArticleBodyOnly ) {