From 40fabb888cd8749811f042b3689776cd1d2fe5f4 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Sat, 24 Jun 2006 21:39:36 +0000 Subject: [PATCH] Addresses #65, back button fools ingester, and fixes bugs loading new tabs in the background. --- .../content/scholar/ingester/browser.js | 60 ++++++++++++++----- 1 file changed, 44 insertions(+), 16 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/ingester/browser.js b/chrome/chromeFiles/content/scholar/ingester/browser.js index 8d36a7e6eb..c98d8534fc 100644 --- a/chrome/chromeFiles/content/scholar/ingester/browser.js +++ b/chrome/chromeFiles/content/scholar/ingester/browser.js @@ -25,6 +25,7 @@ Scholar_Ingester_Interface = function() {} Scholar_Ingester_Interface.init = function() { Scholar_Ingester_Interface.browsers = new Array(); Scholar_Ingester_Interface.browserDocuments = new Object(); + Scholar_Ingester_Interface.browserUris = new Array(); window.addEventListener("load", Scholar_Ingester_Interface.chromeLoad, false); window.addEventListener("unload", Scholar_Ingester_Interface.chromeUnload, false); @@ -42,7 +43,7 @@ Scholar_Ingester_Interface.chromeLoad = function() { Scholar_Ingester_Interface.tabBrowser.addProgressListener(Scholar_Ingester_Interface.Listener, Components.interfaces.nsIWebProgress.NOTIFY_LOCATION); // let's use load instead of DOMContentLoaded - Scholar_Ingester_Interface.appContent.addEventListener("load", + Scholar_Ingester_Interface.appContent.addEventListener("pageshow", Scholar_Ingester_Interface.contentLoad, true); } @@ -69,8 +70,8 @@ Scholar_Ingester_Interface.scrapeThisPage = function() { * Updates the status of the capture icon to reflect the scrapability or lack * thereof of the current page */ -Scholar_Ingester_Interface.updateStatus = function(browser) { - var documentObject = Scholar_Ingester_Interface._getDocument(browser); +Scholar_Ingester_Interface.updateStatus = function() { + var documentObject = Scholar_Ingester_Interface._getDocument(Scholar_Ingester_Interface.tabBrowser.selectedBrowser); if(documentObject && documentObject.scraper) { //Scholar_Ingester_Interface.statusImage.src = "chrome://scholar/skin/treeitem-"+TYPE+".png"; Scholar_Ingester_Interface.statusImage.hidden = false; @@ -82,15 +83,39 @@ Scholar_Ingester_Interface.updateStatus = function(browser) { /* * An event handler called when a new document is loaded. Creates a new document * object, and updates the status of the capture icon - * - * FIXME: This approach, again borrowed from PiggyBank, does not work properly - * when the newly loaded page is not the currently selected page. For example, - * if a tab is loaded behind the currently selected page, the ingester will not - * create a new object for it. + */ -Scholar_Ingester_Interface.contentLoad = function() { - Scholar_Ingester_Interface._setDocument(Scholar_Ingester_Interface.tabBrowser.selectedBrowser); - Scholar_Ingester_Interface.updateStatus(Scholar_Ingester_Interface.tabBrowser.selectedBrowser); +Scholar_Ingester_Interface.contentLoad = function(event) { + if (event.originalTarget instanceof HTMLDocument) { + // Stolen off the Mozilla extension developer's website, a routine to + // determine the root document loaded from a frameset + if (event.originalTarget.defaultView.frameElement) { + var doc = event.originalTarget; + while (doc.defaultView.frameElement) { + doc=doc.defaultView.frameElement.ownerDocument; + } + // Frame within a tab was loaded. doc is the root document of the frameset + } else { + var doc = event.originalTarget; + // Page was loaded. doc is the document that loaded. + } + + // Figure out what browser this contentDocument is associated with + var browser; + for(var i=0; i