From 639a006efb027446995259c361a6c4ac3a522be7 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Fri, 2 Jun 2006 03:19:12 +0000 Subject: [PATCH] XPCOM-ize ingester, fix swapped first and last name in ingested info, stop ingesting pages field (this should be for pages of the source used, not the total number of pages, right?) --- .../content/scholar/ingester/browser.js | 60 +++++++++++++++++-- .../content/scholar/ingester/browser.xul | 3 +- .../scholar/{ingester => xpcom}/ingester.js | 30 +++++----- components/chnmIScholarService.js | 4 ++ 4 files changed, 74 insertions(+), 23 deletions(-) rename chrome/chromeFiles/content/scholar/{ingester => xpcom}/ingester.js (95%) diff --git a/chrome/chromeFiles/content/scholar/ingester/browser.js b/chrome/chromeFiles/content/scholar/ingester/browser.js index a88414d511..ee407c089e 100644 --- a/chrome/chromeFiles/content/scholar/ingester/browser.js +++ b/chrome/chromeFiles/content/scholar/ingester/browser.js @@ -2,19 +2,23 @@ // Utilities based on code taken from Greasemonkey // This code is licensed according to the GPL -// Prepare the browser and collector instrumentation caches -------------------- Scholar.Ingester.Interface = function() {} +/* + * Initialize some variables and prepare event listeners for when chrome is done + * loading + */ Scholar.Ingester.Interface.init = function() { Scholar.Ingester.Interface.browsers = new Array(); + Scholar.Ingester.Interface.browserDocuments = new Object(); window.addEventListener("load", Scholar.Ingester.Interface.chromeLoad, false); window.addEventListener("unload", Scholar.Ingester.Interface.chromeUnload, false); - - Scholar.Ingester.Interface.browsers = new Array(); - Scholar.Ingester.Interface.browserDocuments = new Object(); } +/* + * When chrome loads, register our event handlers with the appropriate interfaces + */ Scholar.Ingester.Interface.chromeLoad = function() { Scholar.Ingester.Interface.tabBrowser = document.getElementById("content"); Scholar.Ingester.Interface.appContent = document.getElementById("appcontent"); @@ -28,10 +32,23 @@ Scholar.Ingester.Interface.chromeLoad = function() { Scholar.Ingester.Interface.contentLoad, true); } +/* + * When chrome unloads, delete our document objects and remove our listeners + */ Scholar.Ingester.Interface.chromeUnload = function() { - this.tabBrowser.removeProgressListener(this); + delete Scholar.Ingester.Interface.browserDocuments; + this.tabBrowser.removeProgressListener(this); } + +/* + * Gets a document object given a browser window object + * + * NOTE: Browser objects are associated with document objects via keys generated + * from the time the browser object is opened. I'm not sure if this is the + * appropriate mechanism for handling this, but it's what PiggyBank used and it + * appears to work. + */ Scholar.Ingester.Interface.getDocument = function(browser) { try { var key = browser.getAttribute("scholar-key"); @@ -42,6 +59,10 @@ Scholar.Ingester.Interface.getDocument = function(browser) { return false; } +/* + * Creates a new document object for a browser window object, attempts to + * retrieve appropriate scraper + */ Scholar.Ingester.Interface.setDocument = function(browser) { try { var key = browser.getAttribute("scholar-key"); @@ -55,6 +76,9 @@ Scholar.Ingester.Interface.setDocument = function(browser) { Scholar.Ingester.Interface.browserDocuments[key].retrieveScraper(); } +/* + * Deletes the document object associated with a given browser window object + */ Scholar.Ingester.Interface.deleteDocument = function(browser) { try { var key = browser.getAttribute("scholar-key"); @@ -66,6 +90,9 @@ Scholar.Ingester.Interface.deleteDocument = function(browser) { return false; } +/* + * Scrapes a page (called when the capture icon is clicked) + */ Scholar.Ingester.Interface.scrapeThisPage = function() { var document = Scholar.Ingester.Interface.getDocument(Scholar.Ingester.Interface.tabBrowser.selectedBrowser); if(document.scraper) { @@ -73,6 +100,10 @@ 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 document = Scholar.Ingester.Interface.getDocument(browser); if(document && document.scraper) { @@ -82,16 +113,33 @@ 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); } +/* + * Dummy event handlers for all the events we don't care about + */ Scholar.Ingester.Interface.Listener = function() {} Scholar.Ingester.Interface.Listener.onStatusChange = function() {} Scholar.Ingester.Interface.Listener.onSecurityChange = function() {} Scholar.Ingester.Interface.Listener.onProgressChange = function() {} Scholar.Ingester.Interface.Listener.onStateChange = function() {} + +/* + * onLocationChange is called when tabs are switched. Use it to retrieve the + * appropriate status indicator for the current tab, and to free useless objects + */ Scholar.Ingester.Interface.Listener.onLocationChange = function() { var browsers = Scholar.Ingester.Interface.tabBrowser.browsers; @@ -114,7 +162,7 @@ Scholar.Ingester.Interface.Listener.onLocationChange = function() { Scholar.Ingester.Interface.deleteDocument(browser); } } - + /*// Add a collector to any new browser for (var i = 0; i < browsers.length; i++) { var browser = browsers[i]; diff --git a/chrome/chromeFiles/content/scholar/ingester/browser.xul b/chrome/chromeFiles/content/scholar/ingester/browser.xul index 150b3c5504..649a123718 100755 --- a/chrome/chromeFiles/content/scholar/ingester/browser.xul +++ b/chrome/chromeFiles/content/scholar/ingester/browser.xul @@ -6,8 +6,7 @@