diff --git a/extensions/chromium/pdfHandler-local.js b/extensions/chromium/pdfHandler-local.js deleted file mode 100644 index c0ebe0b1d..000000000 --- a/extensions/chromium/pdfHandler-local.js +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */ -/* -Copyright 2012 Mozilla Foundation - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -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. -*/ -/* globals chrome, isPdfDownloadable */ - -'use strict'; - -// The onHeadersReceived event is not generated for local resources. -// Fortunately, local PDF files will have the .pdf extension, so there's -// no need to detect the Content-Type -// Unfortunately, the omnibox won't show the URL. -// Unfortunately, this method will not work for pages in incognito mode, -// unless "incognito":"split" is used AND http:/crbug.com/224094 is fixed. - -// Keeping track of incognito tab IDs will become obsolete when -// "incognito":"split" can be used. -var incognitoTabIds = []; -chrome.windows.getAll({ populate: true }, function(windows) { - windows.forEach(function(win) { - if (win.incognito) { - win.tabs.forEach(function(tab) { - incognitoTabIds.push(tab.id); - }); - } - }); -}); -chrome.tabs.onCreated.addListener(function(tab) { - if (tab.incognito) incognitoTabIds.push(tab.id); -}); -chrome.tabs.onRemoved.addListener(function(tabId) { - var index = incognitoTabIds.indexOf(tabId); - if (index !== -1) incognitoTabIds.splice(index, 1); -}); - -chrome.webRequest.onBeforeRequest.addListener( - function(details) { - if (isPdfDownloadable(details)) // Defined in pdfHandler.js - return; - - if (incognitoTabIds.indexOf(details.tabId) !== -1) - return; // Doesn't work in incognito mode, so don't redirect. - - var viewerPage = 'content/web/viewer.html'; - var url = chrome.runtime.getURL(viewerPage) + - '?file=' + encodeURIComponent(details.url); - return { redirectUrl: url }; - }, - { - urls: [ - 'file://*/*.pdf', - 'file://*/*.PDF' - ], - types: ['main_frame', 'sub_frame'] - }, - ['blocking']); diff --git a/extensions/chromium/pdfHandler.html b/extensions/chromium/pdfHandler.html index 38329213b..7e6f6254d 100644 --- a/extensions/chromium/pdfHandler.html +++ b/extensions/chromium/pdfHandler.html @@ -16,4 +16,3 @@ limitations under the License. --> - diff --git a/extensions/chromium/pdfHandler.js b/extensions/chromium/pdfHandler.js index 2180fc3a0..c61373d28 100644 --- a/extensions/chromium/pdfHandler.js +++ b/extensions/chromium/pdfHandler.js @@ -169,3 +169,24 @@ chrome.webRequest.onHeadersReceived.addListener( types: ['main_frame', 'sub_frame'] }, ['blocking','responseHeaders']); + +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' + ], + types: ['main_frame', 'sub_frame'] + }, + ['blocking']);