[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:
parent
78d3b600d4
commit
ec5ef58b84
@ -11,7 +11,8 @@
|
||||
"permissions": [
|
||||
"webRequest", "webRequestBlocking",
|
||||
"<all_urls>",
|
||||
"tabs"
|
||||
"tabs",
|
||||
"webNavigation"
|
||||
],
|
||||
"content_scripts": [{
|
||||
"matches": [
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user