22
22
23
23
public class SandboxDirective extends Directive {
24
24
private static final String ALLOW_DOWNLOADS = "allow-downloads" ;
25
- private boolean allowDownloads_ = false ;
26
- private boolean allowForms_ = false ;
27
- private boolean allowModals_ = false ;
28
- private boolean allowOrientationLock_ = false ;
29
- private boolean allowPointerLock_ = false ;
30
- private boolean allowPopups_ = false ;
31
- private boolean allowPopupsToEscapeSandbox_ = false ;
32
- private boolean allowPresentation_ = false ;
33
- private boolean allowSameOrigin_ = false ;
34
- private boolean allowScripts_ = false ;
35
- private boolean allowStorageAccessByUserActivation_ = false ;
36
- private boolean allowTopNavigation_ = false ;
37
- private boolean allowTopNavigationByUserActivation_ = false ;
25
+ private boolean allowDownloads_ ;
26
+ private boolean allowForms_ ;
27
+ private boolean allowModals_ ;
28
+ private boolean allowOrientationLock_ ;
29
+ private boolean allowPointerLock_ ;
30
+ private boolean allowPopups_ ;
31
+ private boolean allowPopupsToEscapeSandbox_ ;
32
+ private boolean allowPresentation_ ;
33
+ private boolean allowSameOrigin_ ;
34
+ private boolean allowScripts_ ;
35
+ private boolean allowStorageAccessByUserActivation_ ;
36
+ private boolean allowTopNavigation_ ;
37
+ private boolean allowTopNavigationByUserActivation_ ;
38
38
39
39
public SandboxDirective (final List <String > values , final DirectiveErrorConsumer errors ) {
40
40
super (values );
@@ -46,111 +46,111 @@ public SandboxDirective(final List<String> values, final DirectiveErrorConsumer
46
46
final String lowcaseToken = token .toLowerCase (Locale .ROOT );
47
47
switch (lowcaseToken ) {
48
48
case ALLOW_DOWNLOADS :
49
- if (! allowDownloads_ ) {
50
- allowDownloads_ = true ;
49
+ if (allowDownloads_ ) {
50
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-downloads" , index ) ;
51
51
}
52
52
else {
53
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-downloads" , index ) ;
53
+ allowDownloads_ = true ;
54
54
}
55
55
break ;
56
56
case "allow-forms" :
57
- if (! allowForms_ ) {
58
- allowForms_ = true ;
57
+ if (allowForms_ ) {
58
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-forms" , index ) ;
59
59
}
60
60
else {
61
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-forms" , index ) ;
61
+ allowForms_ = true ;
62
62
}
63
63
break ;
64
64
case "allow-modals" :
65
- if (! allowModals_ ) {
66
- allowModals_ = true ;
65
+ if (allowModals_ ) {
66
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-modals" , index ) ;
67
67
}
68
68
else {
69
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-modals" , index ) ;
69
+ allowModals_ = true ;
70
70
}
71
71
break ;
72
72
case "allow-orientation-lock" :
73
- if (! allowOrientationLock_ ) {
74
- allowOrientationLock_ = true ;
73
+ if (allowOrientationLock_ ) {
74
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-orientation-lock" , index ) ;
75
75
}
76
76
else {
77
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-orientation-lock" , index ) ;
77
+ allowOrientationLock_ = true ;
78
78
}
79
79
break ;
80
80
case "allow-pointer-lock" :
81
- if (! allowPointerLock_ ) {
82
- allowPointerLock_ = true ;
81
+ if (allowPointerLock_ ) {
82
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-pointer-lock" , index ) ;
83
83
}
84
84
else {
85
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-pointer-lock" , index ) ;
85
+ allowPointerLock_ = true ;
86
86
}
87
87
break ;
88
88
case "allow-popups" :
89
- if (! allowPopups_ ) {
90
- allowPopups_ = true ;
89
+ if (allowPopups_ ) {
90
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-popups" , index ) ;
91
91
}
92
92
else {
93
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-popups" , index ) ;
93
+ allowPopups_ = true ;
94
94
}
95
95
break ;
96
96
case "allow-popups-to-escape-sandbox" :
97
- if (!allowPopupsToEscapeSandbox_ ) {
98
- allowPopupsToEscapeSandbox_ = true ;
99
- }
100
- else {
97
+ if (allowPopupsToEscapeSandbox_ ) {
101
98
errors .add (Policy .Severity .Warning ,
102
99
"Duplicate sandbox keyword allow-popups-to-escape-sandbox" , index );
103
100
}
101
+ else {
102
+ allowPopupsToEscapeSandbox_ = true ;
103
+ }
104
104
break ;
105
105
case "allow-presentation" :
106
- if (! allowPresentation_ ) {
107
- allowPresentation_ = true ;
106
+ if (allowPresentation_ ) {
107
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-presentation" , index ) ;
108
108
}
109
109
else {
110
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-presentation" , index ) ;
110
+ allowPresentation_ = true ;
111
111
}
112
112
break ;
113
113
case "allow-same-origin" :
114
- if (! allowSameOrigin_ ) {
115
- allowSameOrigin_ = true ;
114
+ if (allowSameOrigin_ ) {
115
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-same-origin" , index ) ;
116
116
}
117
117
else {
118
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-same-origin" , index ) ;
118
+ allowSameOrigin_ = true ;
119
119
}
120
120
break ;
121
121
case "allow-scripts" :
122
- if (! allowScripts_ ) {
123
- allowScripts_ = true ;
122
+ if (allowScripts_ ) {
123
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-scripts" , index ) ;
124
124
}
125
125
else {
126
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-scripts" , index ) ;
126
+ allowScripts_ = true ;
127
127
}
128
128
break ;
129
129
case "allow-storage-access-by-user-activation" :
130
- if (!allowStorageAccessByUserActivation_ ) {
131
- allowStorageAccessByUserActivation_ = true ;
132
- }
133
- else {
130
+ if (allowStorageAccessByUserActivation_ ) {
134
131
errors .add (Policy .Severity .Warning ,
135
132
"Duplicate sandbox keyword allow-storage-access-by-user-activation" , index );
136
133
}
134
+ else {
135
+ allowStorageAccessByUserActivation_ = true ;
136
+ }
137
137
break ;
138
138
case "allow-top-navigation" :
139
- if (! allowTopNavigation_ ) {
140
- allowTopNavigation_ = true ;
139
+ if (allowTopNavigation_ ) {
140
+ errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-top-navigation" , index ) ;
141
141
}
142
142
else {
143
- errors . add ( Policy . Severity . Warning , "Duplicate sandbox keyword allow-top-navigation" , index ) ;
143
+ allowTopNavigation_ = true ;
144
144
}
145
145
break ;
146
146
case "allow-top-navigation-by-user-activation" :
147
- if (!allowTopNavigationByUserActivation_ ) {
148
- allowTopNavigationByUserActivation_ = true ;
149
- }
150
- else {
147
+ if (allowTopNavigationByUserActivation_ ) {
151
148
errors .add (Policy .Severity .Warning ,
152
149
"Duplicate sandbox keyword allow-top-navigation-by-user-activation" , index );
153
150
}
151
+ else {
152
+ allowTopNavigationByUserActivation_ = true ;
153
+ }
154
154
break ;
155
155
default :
156
156
if (token .startsWith ("'" )) {
0 commit comments