[CRX] Improved navigation detection.

A user reported that the PDF Viewer is not rendered on Dropbox,
(Chrome on Mac OS X). This is apparently caused by the fact that the
PDF file is loaded in an iframe in such a way that the tabs.onUpdated
event is not triggered.

This patch switches to the webNavigation event API, which improves the
reliability of the navigation detection.

Unfortunately Opera 15 does not support the webNavigation API, so the
old (tabs.onUpdated) method is used (feature-detection is used, so
whenever Opera decides to implement this API, it will profit from it).
This commit is contained in:
Rob Wu 2013-07-17 18:57:18 +02:00
parent 78d3b600d4
commit ec5ef58b84
2 changed files with 24 additions and 1 deletions

View File

@ -11,7 +11,8 @@
"permissions": [
"webRequest", "webRequestBlocking",
"<all_urls>",
"tabs"
"tabs",
"webNavigation"
],
"content_scripts": [{
"matches": [

View File

@ -62,6 +62,28 @@ function insertPDFJSForTab(tabId, url) {
* @param {string} url The URL of the pdf file.
*/
function activatePDFJSForTab(tabId, url) {
if (!chrome.webNavigation) {
// Opera... does not support the webNavigation API.
activatePDFJSForTabFallbackForOpera(tabId, url);
return;
}
var listener = function webNavigationEventListener(details) {
if (details.tabId === tabId) {
insertPDFJSForTab(tabId, url);
chrome.webNavigation.onCommitted.removeListener(listener);
}
};
var urlFilter = {
url: [{ urlEquals: url }]
};
chrome.webNavigation.onCommitted.addListener(listener, urlFilter);
}
/**
* Fallback for Opera.
* @see activatePDFJSForTab
**/
function activatePDFJSForTabFallbackForOpera(tabId, url) {
chrome.tabs.onUpdated.addListener(function listener(_tabId) {
if (tabId === _tabId) {
insertPDFJSForTab(tabId, url);