Skip to content

Commit

Permalink
Merge pull request #3342 from caolanm/enh/wasm-headers-conditional-on…
Browse files Browse the repository at this point in the history
…-cowasm-support
  • Loading branch information
juliusknorr authored Dec 6, 2023
2 parents 15af22b + 6a742c0 commit cac5f43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/Listener/BeforeTemplateRenderedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,24 @@
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
use OCA\Richdocuments\Service\CapabilitiesService;

/** @template-implements IEventListener<BeforeTemplateRenderedEvent|Event> */
class BeforeTemplateRenderedListener implements IEventListener {
private CapabilitiesService $capabilitiesService;

public function __construct(CapabilitiesService $capabilitiesService) {
$this->capabilitiesService = $capabilitiesService;
}

public function handle(Event $event): void {
if (!$event instanceof BeforeTemplateRenderedEvent) {
return;
}

// FIXME: Might be too wide, we should only do this when needed

//$event->getResponse()->addHeader('Cross-Origin-Opener-Policy', 'unsafe-none');
//$event->getResponse()->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
if ($this->capabilitiesService->hasWASMSupport()) {
$event->getResponse()->addHeader('Cross-Origin-Opener-Policy', 'same-origin');
$event->getResponse()->addHeader('Cross-Origin-Embedder-Policy', 'require-corp');
}
}
}
4 changes: 4 additions & 0 deletions lib/Service/CapabilitiesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public function hasZoteroSupport(): bool {
return $this->getCapabilities()['hasZoteroSupport'] ?? false;
}

public function hasWASMSupport(): bool {
return $this->getCapabilities()['hasWASMSupport'] ?? false;
}

public function getProductName(): string {
$theme = $this->config->getAppValue(Application::APPNAME, 'theme', 'nextcloud');

Expand Down

0 comments on commit cac5f43

Please sign in to comment.