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:
commit
e6be2666de
@ -27,6 +27,12 @@ function getViewerURL(pdf_url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function showViewer(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.
|
// Cancel page load and empty document.
|
||||||
window.stop();
|
window.stop();
|
||||||
document.body.textContent = '';
|
document.body.textContent = '';
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
"permissions": [
|
"permissions": [
|
||||||
"webRequest", "webRequestBlocking",
|
"webRequest", "webRequestBlocking",
|
||||||
"<all_urls>",
|
"<all_urls>",
|
||||||
"tabs"
|
"tabs",
|
||||||
|
"webNavigation"
|
||||||
],
|
],
|
||||||
"content_scripts": [{
|
"content_scripts": [{
|
||||||
"matches": [
|
"matches": [
|
||||||
|
@ -62,6 +62,28 @@ function insertPDFJSForTab(tabId, url) {
|
|||||||
* @param {string} url The URL of the pdf file.
|
* @param {string} url The URL of the pdf file.
|
||||||
*/
|
*/
|
||||||
function activatePDFJSForTab(tabId, url) {
|
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) {
|
chrome.tabs.onUpdated.addListener(function listener(_tabId) {
|
||||||
if (tabId === _tabId) {
|
if (tabId === _tabId) {
|
||||||
insertPDFJSForTab(tabId, url);
|
insertPDFJSForTab(tabId, url);
|
||||||
|
Loading…
Reference in New Issue
Block a user