Merge pull request #3484 from Rob--W/crx-improved-navigation-detection

[Chrome extension] Improved navigation detection by using webNavigation instead of tabs API.
This commit is contained in:
Yury Delendik 2013-07-18 06:32:22 -07:00
commit e6be2666de
3 changed files with 30 additions and 1 deletions

View File

@ -27,6 +27,12 @@ function getViewerURL(pdf_url) {
}
function showViewer(url) {
if (document.documentElement === null) {
// If the root element hasn't been rendered yet, delay the next operation.
// Otherwise, document.readyState will get stuck in "interactive".
setTimeout(showViewer, 0, url);
return;
}
// Cancel page load and empty document.
window.stop();
document.body.textContent = '';

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);