diff options
author | Morris Jobke <hey@morrisjobke.de> | 2016-10-26 00:20:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-26 00:20:27 +0200 |
commit | 9a70c137d2afa3dc1a6f6361c3fa36d5a9ca4f71 (patch) | |
tree | bdfcaaca14022c13bcc2088b791ce2a16dd562db /core | |
parent | 1b6ba5ad322cb3d6e2139393798d243f1d4cc68a (diff) | |
parent | 015affb082a7c9bbfeef552b3c74e5ae77e01ab3 (diff) | |
download | nextcloud-server-9a70c137d2afa3dc1a6f6361c3fa36d5a9ca4f71.tar.gz nextcloud-server-9a70c137d2afa3dc1a6f6361c3fa36d5a9ca4f71.zip |
Merge pull request #1917 from nextcloud/ocjs_inline
Inline oc.js when possible!
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/OCJSController.php | 92 | ||||
-rw-r--r-- | core/routes.php | 4 | ||||
-rw-r--r-- | core/templates/layout.base.php | 5 | ||||
-rw-r--r-- | core/templates/layout.guest.php | 5 | ||||
-rw-r--r-- | core/templates/layout.user.php | 5 |
5 files changed, 108 insertions, 3 deletions
diff --git a/core/Controller/OCJSController.php b/core/Controller/OCJSController.php new file mode 100644 index 00000000000..b1c2208377e --- /dev/null +++ b/core/Controller/OCJSController.php @@ -0,0 +1,92 @@ +<?php +/** + * @copyright Copyright (c) 2016, Roeland Jago Douma <roeland@famdouma.nl> + * + * @author Roeland Jago Douma <roeland@famdouma.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +namespace OC\Core\Controller; + +use bantu\IniGetWrapper\IniGetWrapper; +use OC\Template\JSConfigHelper; +use OCP\App\IAppManager; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataDisplayResponse; +use OCP\IConfig; +use OCP\IGroupManager; +use OCP\IL10N; +use OCP\IRequest; +use OCP\IURLGenerator; +use OCP\IUserSession; + +class OCJSController extends Controller { + + /** @var JSConfigHelper */ + private $helper; + + /** + * OCJSController constructor. + * + * @param string $appName + * @param IRequest $request + * @param IL10N $l + * @param \OC_Defaults $defaults + * @param IAppManager $appManager + * @param IUserSession $session + * @param IConfig $config + * @param IGroupManager $groupManager + * @param IniGetWrapper $iniWrapper + * @param IURLGenerator $urlGenerator + */ + public function __construct($appName, + IRequest $request, + IL10N $l, + \OC_Defaults $defaults, + IAppManager $appManager, + IUserSession $session, + IConfig $config, + IGroupManager $groupManager, + IniGetWrapper $iniWrapper, + IURLGenerator $urlGenerator) { + parent::__construct($appName, $request); + + $this->helper = new JSConfigHelper( + $l, + $defaults, + $appManager, + $session->getUser(), + $config, + $groupManager, + $iniWrapper, + $urlGenerator + ); + } + + /** + * @NoCSRFRequired + * @PublicPage + * + * @return DataDisplayResponse + */ + public function getConfig() { + $data = $this->helper->getConfig(); + + return new DataDisplayResponse($data, Http::STATUS_OK, ['Content-type' => 'text/javascript']); + } +} diff --git a/core/routes.php b/core/routes.php index 3ca83815ad4..7978001af7d 100644 --- a/core/routes.php +++ b/core/routes.php @@ -51,6 +51,7 @@ $application->registerRoutes($this, [ ['name' => 'TwoFactorChallenge#selectChallenge', 'url' => '/login/selectchallenge', 'verb' => 'GET'], ['name' => 'TwoFactorChallenge#showChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'GET'], ['name' => 'TwoFactorChallenge#solveChallenge', 'url' => '/login/challenge/{challengeProviderId}', 'verb' => 'POST'], + ['name' => 'OCJS#getConfig', 'url' => '/core/js/oc.js', 'verb' => 'GET'], ], 'ocs' => [ ['root' => '/cloud', 'name' => 'OCS#getCapabilities', 'url' => '/capabilities', 'verb' => 'GET'], @@ -66,9 +67,6 @@ $application->registerRoutes($this, [ // Search $this->create('search_ajax_search', '/core/search') ->actionInclude('core/search/ajax/search.php'); -// oC JS config -$this->create('js_config', '/core/js/oc.js') - ->actionInclude('core/js/config.php'); // Routing $this->create('core_ajax_preview', '/core/preview') ->actionInclude('core/ajax/preview.php'); diff --git a/core/templates/layout.base.php b/core/templates/layout.base.php index 3f13523afcb..d6d70f31362 100644 --- a/core/templates/layout.base.php +++ b/core/templates/layout.base.php @@ -18,6 +18,11 @@ <?php foreach($_['printcssfiles'] as $cssfile): ?> <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print"> <?php endforeach; ?> + <?php if (isset($_['inline_ocjs'])): ?> + <script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" type="text/javascript"> + <?php print_unescaped($_['inline_ocjs']); ?> + </script> + <?php endif; ?> <?php foreach ($_['jsfiles'] as $jsfile): ?> <script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" src="<?php print_unescaped($jsfile); ?>"></script> <?php endforeach; ?> diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php index 6d46ac6cf2c..1692e4268d4 100644 --- a/core/templates/layout.guest.php +++ b/core/templates/layout.guest.php @@ -19,6 +19,11 @@ <?php foreach($_['printcssfiles'] as $cssfile): ?> <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print"> <?php endforeach; ?> + <?php if (isset($_['inline_ocjs'])): ?> + <script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" type="text/javascript"> + <?php print_unescaped($_['inline_ocjs']); ?> + </script> + <?php endif; ?> <?php foreach($_['jsfiles'] as $jsfile): ?> <script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" src="<?php print_unescaped($jsfile); ?>"></script> <?php endforeach; ?> diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index d258e3582d0..bc8edf085d0 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -26,6 +26,11 @@ <?php foreach($_['printcssfiles'] as $cssfile): ?> <link rel="stylesheet" href="<?php print_unescaped($cssfile); ?>" media="print"> <?php endforeach; ?> + <?php if (isset($_['inline_ocjs'])): ?> + <script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" type="text/javascript"> + <?php print_unescaped($_['inline_ocjs']); ?> + </script> + <?php endif; ?> <?php foreach($_['jsfiles'] as $jsfile): ?> <script nonce="<?php p(\OC::$server->getContentSecurityPolicyNonceManager()->getNonce()) ?>" src="<?php print_unescaped($jsfile); ?>"></script> <?php endforeach; ?> |