Skip to content

Commit

Permalink
handle blob urls
Browse files Browse the repository at this point in the history
  • Loading branch information
StigNygaard committed Sep 17, 2023
1 parent a3e0437 commit 815d263
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion WebExtension/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,11 @@
},

"displayFileTrouble": {
"message": "Image from your file system probably ain't displayed in this popup, but it might still be possible to get the meta-data."
"message": "Image from your file system probably doesn't display in this popup, but any meta-data might still be read and displayed correctly."
},

"displayBlobTrouble": {
"message": "Images defined by blob: URLs probably doesn't display in this popup, but any meta-data might still be read and displayed correctly."
},

"UserComment": {
Expand Down
3 changes: 3 additions & 0 deletions WebExtension/backgroundscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ browser.runtime.onMessage.addListener(
if (Object.keys(message.data).length === 0) {
popupData.infos.push(browser.i18n.getMessage("noEXIFdata"));
}
if (popupData.properties.URL?.startsWith('blob:http')) {
popupData.warnings.push(browser.i18n.getMessage('displayBlobTrouble'));
}
if (popupData.properties.URL?.startsWith('file:') && context.isFirefox()) {
popupData.warnings.push(browser.i18n.getMessage('displayFileTrouble'));
// TODO: Er det faktisk muligt at vise lokalt image med URL.createObjectURL(blob) ?
Expand Down
8 changes: 3 additions & 5 deletions WebExtension/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@

context.debug(' *** fetchMode: ' + imgrequest.fetchMode + ' ***');

// TODO: If file:, always do frontend fetch !?
// TODO: If file: or blob:, always do frontend fetch !?!
if (imgrequest.fetchMode === 'devFrontendFetch' || imgrequest.fetchMode === 'devAutoFetch' && context.isFirefox()) { // Do frontend fetch...
if (imgrequest.fetchMode !== 'devAutoFetch') {
console.warn(`xIFr: Forced FRONTEND fetch (${imgrequest.fetchMode})`);
Expand Down Expand Up @@ -439,12 +439,10 @@
}

function blacklistedImage(src) { // todo: Make blacklist configurable!
if (src.startsWith('data:') || src.startsWith('blob:')) {
if (src.length < 500 || src.substring(5,11) !== 'image/') {
if (src.startsWith('data:') && (src.length < 500 || !src.startsWith('data:image/'))) {
console.warn('xIFr: Skipping ' + src);
// ignore tiny inline data: and blob: images - and those that doesn't have some 'image' mimetype
// ignore tiny inline data: images - and those that doesn't have some 'image' mimetype
return true;
}
} else if (src.startsWith('moz-extension:') || src.startsWith('chrome-extension:')) {
console.warn('xIFr: Skipping ' + src);
return true; // Apparently we can detect images inserted by other extensions, but we cannot access them
Expand Down

0 comments on commit 815d263

Please sign in to comment.