|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* @author Lukas Reschke |
|
5
|
|
|
* @copyright 2014 Lukas Reschke [email protected] |
|
6
|
|
|
* |
|
7
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
8
|
|
|
* later. |
|
9
|
|
|
* See the COPYING-README file. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace OCA\Files_PdfViewer\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use OCP\AppFramework\Controller; |
|
15
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy; |
|
16
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
|
17
|
|
|
use OCP\IRequest; |
|
18
|
|
|
use OCP\IURLGenerator; |
|
19
|
|
|
|
|
20
|
|
|
class DisplayController extends Controller { |
|
21
|
|
|
|
|
22
|
|
|
/** @var IURLGenerator */ |
|
23
|
|
|
private $urlGenerator; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @param string $AppName |
|
27
|
|
|
* @param IRequest $request |
|
28
|
|
|
* @param IURLGenerator $urlGenerator |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct(string $AppName, |
|
31
|
|
|
IRequest $request, |
|
32
|
|
|
IURLGenerator $urlGenerator) { |
|
33
|
|
|
parent::__construct($AppName, $request); |
|
34
|
|
|
$this->urlGenerator = $urlGenerator; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @PublicPage |
|
39
|
|
|
* @NoCSRFRequired |
|
40
|
|
|
* |
|
41
|
|
|
* @param bool $minmode |
|
42
|
|
|
* @return TemplateResponse |
|
43
|
|
|
*/ |
|
44
|
|
|
public function showPdfViewer(bool $minmode = false): TemplateResponse { |
|
45
|
|
|
$params = [ |
|
46
|
|
|
'urlGenerator' => $this->urlGenerator, |
|
47
|
|
|
'minmode' => $minmode |
|
48
|
|
|
]; |
|
49
|
|
|
$response = new TemplateResponse($this->appName, 'viewer', $params, 'blank'); |
|
50
|
|
|
|
|
51
|
|
|
$policy = new ContentSecurityPolicy(); |
|
52
|
|
|
$policy->addAllowedChildSrcDomain('\'self\''); |
|
53
|
|
|
$policy->addAllowedFontDomain('data:'); |
|
54
|
|
|
$policy->addAllowedImageDomain('*'); |
|
55
|
|
|
$policy->allowEvalScript(false); |
|
56
|
|
|
$response->setContentSecurityPolicy($policy); |
|
57
|
|
|
|
|
58
|
|
|
return $response; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
|