Skip to content

Commit 2dfe3f2

Browse files
committed
v0.31: now compliant with manifest v3.
1 parent 7236d02 commit 2dfe3f2

File tree

3 files changed

+174
-199
lines changed

3 files changed

+174
-199
lines changed

extension/ps-wasm-chrome/background.js

Lines changed: 21 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,29 @@ function getHeaderFromHeaders(headers, headerName) {
77
}
88
}
99

10-
function loadScript(url, onLoadCallback)
11-
{
12-
// Adding the script tag to the head as suggested before
13-
var head = document.head;
14-
var script = document.createElement('script');
15-
script.type = 'text/javascript';
16-
script.src = url;
17-
18-
// Then bind the event to the callback function.
19-
// There are several events for cross browser compatibility.
20-
//script.onreadystatechange = callback;
21-
script.onload = onLoadCallback;
22-
23-
// Fire the loading
24-
head.appendChild(script);
10+
function getRedirectURL() {
11+
return chrome.runtime.getURL('viewer.html') + "?url=";
2512
}
2613

27-
function getRedirectURL(url) {
28-
return chrome.runtime.getURL('viewer.html') + "?url=" + url;
29-
}
14+
chrome.declarativeNetRequest.updateDynamicRules({
15+
removeRuleIds: [1001],
16+
addRules: [{
17+
'id': 1001,
18+
'priority': 1,
19+
'action': {
20+
'type': 'redirect',
21+
'redirect': {
22+
'regexSubstitution': getRedirectURL() + '\\0'
23+
}
24+
},
25+
'condition': {
26+
'regexFilter': ".*\\.ps(\\.gz)?$",
27+
'resourceTypes': ['main_frame']
28+
}
29+
}]
30+
});
3031

31-
chrome.webRequest.onHeadersReceived.addListener(function(details){
32+
/*chrome.webRequest.onHeadersReceived.addListener(function(details){
3233
var mime_type = getHeaderFromHeaders(details.responseHeaders, 'content-type');
3334
if (mime_type.value == 'application/postscript') {
3435
// places like arXiv don't have .ps filenames in their URLs,
@@ -56,80 +57,4 @@ chrome.webRequest.onBeforeRequest.addListener(function(info) {
5657
},
5758
{urls: ["<all_urls>"], types: ["main_frame"]},
5859
["blocking"]
59-
);
60-
61-
var Module;
62-
63-
function _GSPS2PDF(dataStruct, responseCallback, progressCallback, statusUpdateCallback) {
64-
// first download the ps data
65-
var xhr = new XMLHttpRequest();
66-
xhr.open("GET", dataStruct.psDataURL);
67-
xhr.responseType = "arraybuffer";
68-
xhr.onload = function() {
69-
// release the URL
70-
window.URL.revokeObjectURL(dataStruct.psDataURL);
71-
//set up EMScripten environment
72-
Module = {
73-
preRun: [function(){
74-
var data = FS.writeFile('input.ps', new Uint8Array(xhr.response));
75-
}],
76-
postRun: [function() {
77-
var uarray = FS.readFile('output.pdf', {encoding: 'binary'}); //Uint8Array
78-
var blob = new Blob([uarray], {type: "application/octet-stream"});
79-
var pdfDataURL = window.URL.createObjectURL(blob);
80-
responseCallback({pdfDataURL: pdfDataURL, url: dataStruct.url});
81-
}],
82-
arguments: ['-sDEVICE=pdfwrite', '-DBATCH', '-DNOPAUSE',
83-
'-q',
84-
'-sOutputFile=output.pdf', '-c', '.setpdfwrite <</AlwaysEmbed [/Helvetica /Times-Roman]>> setdistillerparams', '-f', 'input.ps'],
85-
print: function(text) {
86-
statusUpdateCallback(text);
87-
},
88-
printErr: function(text) {
89-
statusUpdateCallback('Error: ' + text);
90-
console.error(text);
91-
},
92-
setStatus: function(text) {
93-
if (!Module.setStatus.last) Module.setStatus.last = { time: Date.now(), text: '' };
94-
if (text === Module.setStatus.last.text) return;
95-
var m = text.match(/([^(]+)\((\d+(\.\d+)?)\/(\d+)\)/);
96-
var now = Date.now();
97-
if (m && now - Module.setStatus.last.time < 30) // if this is a progress update, skip it if too soon
98-
return;
99-
Module.setStatus.last.time = now;
100-
Module.setStatus.last.text = text;
101-
if (m) {
102-
text = m[1];
103-
progressCallback(false, parseInt(m[2])*100, parseInt(m[4])*100);
104-
} else {
105-
progressCallback(true, 0, 0);
106-
}
107-
statusUpdateCallback(text);
108-
},
109-
totalDependencies: 0
110-
};
111-
Module.setStatus('Loading Postscript Converter...');
112-
loadScript('gs.js', null);
113-
};
114-
xhr.send();
115-
}
116-
117-
chrome.runtime.onConnect.addListener(function(port) {
118-
if (port.name == 'ps2pdfport') {
119-
port.onMessage.addListener(function(msg) {
120-
if (msg.requestType == 'ps2pdf') {
121-
requestData = msg.requestData;
122-
_GSPS2PDF(requestData, function(replyData) {
123-
port.postMessage({msgType: 'result', data: replyData});
124-
},
125-
function(is_done, value, max_val) {
126-
port.postMessage({
127-
msgType: 'convprog', isDone: is_done, value: value, maxVal: max_val});
128-
}, function(status) {
129-
port.postMessage({
130-
msgType: 'status', status: status});
131-
});
132-
return true;
133-
}
134-
});}
135-
});
60+
);*/
Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
{
2-
"update_url": "https://clients2.google.com/service/update2/crx",
3-
4-
"name": "PostScript Viewer",
5-
"short_name": "ps-wasm",
6-
"version": "0.21",
7-
"icons": { "128": "logo.png" },
8-
"description": "Rendering PostScript using GhostScript in WebAssembly.",
9-
"manifest_version": 2,
10-
"background": {
11-
"scripts": [
12-
"background.js"
13-
]
14-
},
15-
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
16-
"permissions": [
17-
"<all_urls>",
18-
"webRequest",
19-
"webRequestBlocking"
20-
],
21-
"web_accessible_resources": ["viewer.html", "viewer.js"]
2+
"background": {
3+
"service_worker": "background.js"
4+
},
5+
"content_security_policy": {
6+
"extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'"
7+
},
8+
"description": "Rendering PostScript using GhostScript in WebAssembly.",
9+
"host_permissions": [ "<all_urls>" ],
10+
"icons": { "128": "logo.png" },
11+
"manifest_version": 3,
12+
"name": "PostScript Viewer",
13+
"permissions": [
14+
"declarativeNetRequestWithHostAccess"
15+
],
16+
"short_name": "ps-wasm",
17+
"update_url": "https://clients2.google.com/service/update2/crx",
18+
"version": "0.31",
19+
"web_accessible_resources": [
20+
{
21+
"resources": [ "viewer.html" ],
22+
"matches": [ "<all_urls>" ]
23+
}
24+
]
2225
}

0 commit comments

Comments
 (0)