Skip to content

Commit

Permalink
Merge pull request mozilla#9410 from Rob--W/cleanup-chrome-compat
Browse files Browse the repository at this point in the history
Cleanup code to drop support for Chrome < 49 in the Chrome extension
  • Loading branch information
Rob--W authored Jan 26, 2018
2 parents 28c87ce + ff5ecc3 commit fd242ad
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 203 deletions.
125 changes: 0 additions & 125 deletions extensions/chromium/feature-detect.js

This file was deleted.

1 change: 0 additions & 1 deletion extensions/chromium/pdfHandler.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
<script src="feature-detect.js"></script>
<script src="options/migration.js"></script>
<script src="preserve-referer.js"></script>
<script src="pdfHandler.js"></script>
Expand Down
54 changes: 13 additions & 41 deletions extensions/chromium/pdfHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/* import-globals-from feature-detect.js */
/* import-globals-from preserve-referer.js */

'use strict';
Expand Down Expand Up @@ -131,21 +130,7 @@ chrome.webRequest.onHeadersReceived.addListener(
// Implemented in preserve-referer.js
saveReferer(details);

// Replace frame with viewer
if (Features.webRequestRedirectUrl) {
return { redirectUrl: viewerUrl, };
}
// Aww.. redirectUrl is not yet supported, so we have to use a different
// method as fallback (Chromium <35).

if (details.frameId === 0) {
// Main frame. Just replace the tab and be done!
chrome.tabs.update(details.tabId, {
url: viewerUrl,
});
return { cancel: true, };
}
console.warn('Child frames are not supported in ancient Chrome builds!');
return { redirectUrl: viewerUrl, };
},
{
urls: [
Expand All @@ -155,44 +140,24 @@ chrome.webRequest.onHeadersReceived.addListener(
},
['blocking', 'responseHeaders']);

chrome.webRequest.onBeforeRequest.addListener(
function onBeforeRequestForFTP(details) {
if (!Features.extensionSupportsFTP) {
chrome.webRequest.onBeforeRequest.removeListener(onBeforeRequestForFTP);
return;
}
if (isPdfDownloadable(details)) {
return;
}
var viewerUrl = getViewerURL(details.url);
return { redirectUrl: viewerUrl, };
},
{
urls: [
'ftp://*/*.pdf',
'ftp://*/*.PDF'
],
types: ['main_frame', 'sub_frame'],
},
['blocking']);

chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (isPdfDownloadable(details)) {
return;
}

// NOTE: The manifest file has declared an empty content script
// at file://*/* to make sure that the viewer can load the PDF file
// through XMLHttpRequest. Necessary to deal with http://crbug.com/302548
var viewerUrl = getViewerURL(details.url);

return { redirectUrl: viewerUrl, };
},
{
urls: [
'file://*/*.pdf',
'file://*/*.PDF'
'file://*/*.PDF',
// Note: Chrome 59 has disabled ftp resource loading by default:
// https://www.chromestatus.com/feature/5709390967472128
'ftp://*/*.pdf',
'ftp://*/*.PDF',
],
types: ['main_frame', 'sub_frame'],
},
Expand Down Expand Up @@ -271,3 +236,10 @@ chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
}
}
});

// Remove keys from storage that were once part of the deleted feature-detect.js
chrome.storage.local.remove([
'featureDetectLastUA',
'webRequestRedirectUrl',
'extensionSupportsFTP',
]);
21 changes: 0 additions & 21 deletions web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { DefaultExternalServices, PDFViewerApplication } from './app';
import { BasePreferences } from './preferences';
import { DownloadManager } from './download_manager';
import { GenericL10n } from './genericl10n';
import { PDFJS } from 'pdfjs-lib';

if (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('CHROME')) {
throw new Error('Module "pdfjs-web/chromecom" shall not be used outside ' +
Expand Down Expand Up @@ -65,26 +64,6 @@ let ChromeCom = {
file = file.replace(/^drive:/i,
'filesystem:' + location.origin + '/external/');

if (/^filesystem:/.test(file) && !PDFJS.disableWorker) {
// The security origin of filesystem:-URLs are not preserved when the
// URL is passed to a Web worker, (http://crbug.com/362061), so we have
// to create an intermediate blob:-URL as a work-around.
let resolveLocalFileSystemURL = window.resolveLocalFileSystemURL ||
window.webkitResolveLocalFileSystemURL;
resolveLocalFileSystemURL(file, function onResolvedFSURL(fileEntry) {
fileEntry.file(function(fileObject) {
let blobUrl = URL.createObjectURL(fileObject);
callback(blobUrl, fileObject.size);
});
}, function onFileSystemError(error) {
// This should not happen. When it happens, just fall back to the
// usual way of getting the File's data (via the Web worker).
console.warn('Cannot resolve file ' + file + ', ' + error.name + ' ' +
error.message);
callback(file);
});
return;
}
if (/^https?:/.test(file)) {
// Assumption: The file being opened is the file that was requested.
// There is no UI to input a different URL, so this assumption will hold
Expand Down
17 changes: 2 additions & 15 deletions web/pdf_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,23 +281,10 @@ class PDFHistory {
this._updateInternalState(destination, newState.uid);

if (shouldReplace) {
if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
// Providing the third argument causes a SecurityError for file:// URLs.
window.history.replaceState(newState, '');
} else {
window.history.replaceState(newState, '', document.URL);
}
window.history.replaceState(newState, '');
} else {
this._maxUid = this._uid;

if (typeof PDFJSDev !== 'undefined' &&
PDFJSDev.test('FIREFOX || MOZCENTRAL')) {
// Providing the third argument causes a SecurityError for file:// URLs.
window.history.pushState(newState, '');
} else {
window.history.pushState(newState, '', document.URL);
}
window.history.pushState(newState, '');
}

if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME') &&
Expand Down

0 comments on commit fd242ad

Please sign in to comment.