Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose some headers to fetch requests from the PDF.js Chrome extension #9447

Merged
merged 1 commit into from
Feb 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions extensions/chromium/preserve-referer.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,17 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
delete g_referrers[tabId][frameId];
}
chrome.webRequest.onBeforeSendHeaders.removeListener(onBeforeSendHeaders);
chrome.webRequest.onHeadersReceived.removeListener(exposeOnHeadersReceived);
});

// Expose some response headers for fetch API calls from PDF.js;
// This is a work-around for https://crbug.com/784528
chrome.webRequest.onHeadersReceived.addListener(exposeOnHeadersReceived, {
urls: ['https://*/*'],
types: ['xmlhttprequest'],
tabId: tabId,
}, ['blocking', 'responseHeaders']);

function onBeforeSendHeaders(details) {
if (details.frameId !== frameId) {
return;
Expand All @@ -137,4 +146,22 @@ chrome.runtime.onConnect.addListener(function onReceivePort(port) {
refererHeader.value = referer;
return { requestHeaders: headers, };
}

function exposeOnHeadersReceived(details) {
if (details.frameId !== frameId) {
return;
}
var headers = details.responseHeaders;
var aceh = getHeaderFromHeaders(headers, 'access-control-expose-headers');
// List of headers that PDF.js uses in src/display/network_utils.js
var acehValue =
'accept-ranges,content-encoding,content-length,content-disposition';
if (aceh) {
aceh.value += ',' + acehValue;
} else {
aceh = { name: 'Access-Control-Expose-Headers', value: acehValue, };
headers.push(aceh);
}
return { responseHeaders: headers, };
}
});