|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @copyright 2014 Lukas Reschke [email protected] |
|
7
|
|
|
* |
|
8
|
|
|
* @author Lukas Reschke <[email protected]> |
|
9
|
|
|
* @author John Molakvoæ <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* @license GNU AGPL version 3 or any later version |
|
12
|
|
|
* |
|
13
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
14
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
15
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
16
|
|
|
* License, or (at your option) any later version. |
|
17
|
|
|
* |
|
18
|
|
|
* This program is distributed in the hope that it will be useful, |
|
19
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
20
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
21
|
|
|
* GNU Affero General Public License for more details. |
|
22
|
|
|
* |
|
23
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
24
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
25
|
|
|
* |
|
26
|
|
|
*/ |
|
27
|
|
|
|
|
28
|
|
|
namespace OCA\Files_PDFViewer\Controller; |
|
29
|
|
|
|
|
30
|
|
|
use OCA\Files_PDFViewer\AppInfo\Application; |
|
31
|
|
|
use OCP\AppFramework\Controller; |
|
32
|
|
|
use OCP\AppFramework\Http\ContentSecurityPolicy; |
|
33
|
|
|
use OCP\AppFramework\Http\TemplateResponse; |
|
34
|
|
|
use OCP\IRequest; |
|
35
|
|
|
use OCP\IURLGenerator; |
|
36
|
|
|
|
|
37
|
|
|
class DisplayController extends Controller { |
|
38
|
|
|
|
|
39
|
|
|
/** @var IURLGenerator */ |
|
40
|
|
|
private $urlGenerator; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param IRequest $request |
|
44
|
|
|
* @param IURLGenerator $urlGenerator |
|
45
|
|
|
*/ |
|
46
|
|
|
public function __construct(IRequest $request, |
|
47
|
|
|
IURLGenerator $urlGenerator) { |
|
48
|
|
|
parent::__construct(Application::APP_ID, $request); |
|
49
|
|
|
$this->urlGenerator = $urlGenerator; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @PublicPage |
|
54
|
|
|
* @NoCSRFRequired |
|
55
|
|
|
* |
|
56
|
|
|
* @param bool $minmode |
|
57
|
|
|
* @return TemplateResponse |
|
58
|
|
|
*/ |
|
59
|
|
|
public function showPdfViewer(bool $minmode = false): TemplateResponse { |
|
60
|
|
|
$params = [ |
|
61
|
|
|
'urlGenerator' => $this->urlGenerator, |
|
62
|
|
|
'minmode' => $minmode |
|
63
|
|
|
]; |
|
64
|
|
|
$response = new TemplateResponse(Application::APP_ID, 'viewer', $params, 'blank'); |
|
65
|
|
|
|
|
66
|
|
|
$policy = new ContentSecurityPolicy(); |
|
67
|
|
|
$policy->addAllowedChildSrcDomain('\'self\''); |
|
68
|
|
|
$policy->addAllowedFontDomain('data:'); |
|
69
|
|
|
$policy->addAllowedImageDomain('*'); |
|
70
|
|
|
$policy->allowEvalScript(false); |
|
71
|
|
|
$response->setContentSecurityPolicy($policy); |
|
72
|
|
|
|
|
73
|
|
|
return $response; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|