This commit is contained in:
gorhill 2017-07-22 16:58:08 -04:00
parent 47dfb1b22c
commit b429e1c7ba
No known key found for this signature in database
GPG key ID: 25E1490B761470C2

View file

@ -410,15 +410,24 @@ var onHeadersReceived = function(details) {
return foilLargeMediaElement(pageStore, details);
}
// https://github.com/gorhill/uBO-Extra/issues/19
// Turns out scripts must also be considered as potential embedded
// contexts (as workers) and as such we may need to inject content
// security policy directives.
if ( requestType === 'main_frame' || requestType === 'sub_frame' ) {
// https://github.com/gorhill/uBlock/issues/2813
// Disable the blocking of large media elements if the document is itself
// a media element: the resource was not prevented from loading so no
// point to further block large media elements for the current document.
if ( requestType === 'main_frame' ) {
if ( reMediaContentTypes.test(headerValueFromName('content-type', details.responseHeaders)) ) {
pageStore.allowLargeMediaElementsUntil = Date.now() + 86400000;
}
return injectCSP(pageStore, details);
}
if ( requestType === 'sub_frame' ) {
return injectCSP(pageStore, details);
}
};
var reMediaContentTypes = /^(?:audio|image|video)\//;
/******************************************************************************/
var injectCSP = function(pageStore, details) {
@ -603,6 +612,11 @@ var headerIndexFromName = function(headerName, headers) {
return -1;
};
var headerValueFromName = function(headerName, headers) {
var i = headerIndexFromName(headerName, headers);
return i !== -1 ? headers[i].value : '';
};
/******************************************************************************/
vAPI.net.onBeforeRequest = {