5
5
6
6
namespace OCA \OCSAPIViewer \Controller ;
7
7
8
- use OC \Security \CSP \ContentSecurityPolicyNonceManager ;
9
8
use OCA \OCSAPIViewer \AppInfo \Application ;
10
- use OCA \Theming \Service \ThemesService ;
11
- use OCP \App \IAppManager ;
12
9
use OCP \AppFramework \Controller ;
13
- use OCP \AppFramework \Http \ContentSecurityPolicy ;
14
10
use OCP \AppFramework \Http \TemplateResponse ;
15
11
use OCP \IRequest ;
16
12
use OCP \Util ;
17
13
18
14
class PageController extends Controller {
19
- private ThemesService $ themesService ;
20
- private IAppManager $ appManager ;
21
- private ContentSecurityPolicyNonceManager $ nonceManager ;
22
15
23
16
public function __construct (
24
17
IRequest $ request ,
25
- ThemesService $ themesService ,
26
- IAppManager $ appManager ,
27
- ContentSecurityPolicyNonceManager $ nonceManager
28
18
) {
29
- $ this ->appManager = $ appManager ;
30
- $ this ->themesService = $ themesService ;
31
- $ this ->nonceManager = $ nonceManager ;
32
19
parent ::__construct (Application::APP_ID , $ request );
33
20
}
34
21
@@ -39,40 +26,7 @@ public function __construct(
39
26
public function index (): TemplateResponse {
40
27
Util::addScript (Application::APP_ID , Application::APP_ID . '-main ' );
41
28
42
- $ response = new TemplateResponse (Application::APP_ID , 'main ' );
43
- $ csp = new ContentSecurityPolicy ();
44
- $ csp ->addAllowedFrameDomain ("'self' " );
45
- $ response ->setContentSecurityPolicy ($ csp );
46
- return $ response ;
29
+ return new TemplateResponse (Application::APP_ID , 'main ' );
47
30
}
48
31
49
- /**
50
- * @NoAdminRequired
51
- * @NoCSRFRequired
52
- */
53
- public function view (string $ app ): TemplateResponse {
54
- // We can't load the script and initial state here, because otherwise all the other scripts would load too
55
-
56
- $ theme = 'system ' ;
57
- $ enabledThemes = array_map (fn (string $ id ) => explode ('- ' , $ id )[0 ], $ this ->themesService ->getEnabledThemes ());
58
- if (count (array_filter ($ enabledThemes , fn (string $ id ) => $ id == 'dark ' )) > 0 ) {
59
- $ theme = 'dark ' ;
60
- } else if (count (array_filter ($ enabledThemes , fn (string $ id ) => $ id == 'light ' )) > 0 ) {
61
- $ theme = 'light ' ;
62
- }
63
-
64
- $ response = new TemplateResponse (Application::APP_ID , 'iframe ' , [
65
- 'app ' => $ app ,
66
- 'viewer-root ' => $ this ->appManager ->getAppWebPath (Application::APP_ID ),
67
- 'theme ' => $ theme ,
68
- 'nonce ' => $ this ->nonceManager ->getNonce (),
69
- ], TemplateResponse::RENDER_AS_BLANK );
70
- $ csp = new ContentSecurityPolicy ();
71
- $ csp ->addAllowedFrameAncestorDomain ("'self' " );
72
- $ csp ->addAllowedScriptDomain ("'unsafe-eval' " );
73
- $ csp ->addAllowedScriptDomain ("'unsafe-inline' " );
74
- $ csp ->addAllowedScriptDomain ('* ' );
75
- $ response ->setContentSecurityPolicy ($ csp );
76
- return $ response ;
77
- }
78
32
}
0 commit comments