From ea33553ba7e5ae25286836c62d1d5634d8d2c0b0 Mon Sep 17 00:00:00 2001 From: Gilles Dubuc Date: Wed, 20 Feb 2019 09:49:28 +0100 Subject: [PATCH] Chrome Origin Trial support Bug: T216595 Change-Id: I74b8824a87e6f52a84d2f8a9708501fc05f73266 --- includes/DefaultSettings.php | 8 ++++++++ includes/OutputPage.php | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 537f411cb4..1761b00778 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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 diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 9b766bb2d4..461df946e7 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -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 ) { -- 2.20.1