diff --git a/appinfo/app.php b/appinfo/app.php deleted file mode 100644 index a7344ee..0000000 --- a/appinfo/app.php +++ /dev/null @@ -1,32 +0,0 @@ -getEventDispatcher(); - -if (\OC::$server->getUserSession()->isLoggedIn()) { - $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function() { - \OCP\Util::addStyle('files_mindmap', 'style'); - \OCP\Util::addScript('files_mindmap', 'jszip'); - \OCP\Util::addScript('files_mindmap', 'mindmap'); - }); -} - - -$eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () { - \OCP\Util::addStyle('files_mindmap', 'style'); - \OCP\Util::addScript('files_mindmap', 'jszip'); - \OCP\Util::addScript('files_mindmap', 'mindmap'); -}); - - -$cspManager = \OC::$server->getContentSecurityPolicyManager(); -$csp = new ContentSecurityPolicy(); -$csp->addAllowedChildSrcDomain("'self'"); -$csp->addAllowedFrameDomain("data:"); -$cspManager->addDefaultPolicy($csp); - -$app = new Application(); -$app->registerProvider(); \ No newline at end of file diff --git a/appinfo/info.xml b/appinfo/info.xml index 885a222..5a5c902 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -18,7 +18,7 @@ https://raw.githubusercontent.com/ACTom/files_mindmap/master/screenshots/2.png https://raw.githubusercontent.com/ACTom/files_mindmap/master/screenshots/3.png - + diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 1f1f920..78fc80b 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -3,23 +3,57 @@ namespace OCA\Files_MindMap\AppInfo; use OC\Files\Type\Detection; +use OCA\Files\Event\LoadAdditionalScriptsEvent; +use OCA\Files_MindMap\Listener\LoadAdditionalScripts; use OCP\AppFramework\App; +use OCP\AppFramework\Bootstrap\IBootContext; +use OCP\AppFramework\Bootstrap\IBootstrap; +use OCP\AppFramework\Bootstrap\IRegistrationContext; +use OCP\AppFramework\Http\ContentSecurityPolicy; +use OCP\EventDispatcher\IEventDispatcher; +use OCP\Files\IMimeTypeDetector; +use OCP\Security\CSP\AddContentSecurityPolicyEvent; -class Application extends App { + +class Application extends App implements IBootstrap { const APPNAME = 'files_mindmap'; public function __construct(array $urlParams = array()) { parent::__construct(self::APPNAME, $urlParams); } - + public function registerProvider() { $container = $this->getContainer(); // Register mimetypes /** @var Detection $detector */ - $detector = $container->query(\OCP\Files\IMimeTypeDetector::class); + $detector = $container->get(IMimeTypeDetector::class); $detector->getAllMappings(); $detector->registerType('km','application/km'); } -} \ No newline at end of file + + public function register(IRegistrationContext $context): void { + + $context->registerEventListener( + LoadAdditionalScriptsEvent::class, + LoadAdditionalScripts::class + ); + } + + public function boot(IBootContext $context): void { + $this->registerProvider(); + + $context->injectFn([$this, 'registerEventsSecurity']); + } + + public function registerEventsSecurity(IEventDispatcher $dispatcher): void { + $dispatcher->addListener(AddContentSecurityPolicyEvent::class, function (AddContentSecurityPolicyEvent $e) { + $policy = new ContentSecurityPolicy(); + $policy->addAllowedChildSrcDomain("'self'"); + $policy->addAllowedFrameDomain("data:"); + $e->addPolicy($policy); + }); + + } +} diff --git a/lib/Listener/LoadAdditionalScripts.php b/lib/Listener/LoadAdditionalScripts.php new file mode 100644 index 0000000..5f944b3 --- /dev/null +++ b/lib/Listener/LoadAdditionalScripts.php @@ -0,0 +1,23 @@ +