From 794238c23f88964908696226a115eab44ed12168 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 12 Aug 2006 03:45:57 +0000 Subject: [PATCH] - Added file.js to chnmIScholarService.js - Fixed bug in File.hasInternalHandler() (no access to navigator from XPCOM) - Changed "View Attachment" action to check File.hasInternalHandler() and use window.loadURI() for internally handled files and nsIFile.launch() for external -- this prevents the user from getting a helper app dialog when they try to view external files. I basically had to duplicate most of Mozilla's content detection logic and "guess" whether or not it will be able to handle the file internally, which seems a little silly, but, while I feel there are probably better ways to do various parts of this, what's here seems to do the trick. Let me know if you notice it guessing incorrectly (i.e. you get a helper app dialog rather than having a file just open or it launches a file that should've just been loaded into the window). Also look for text files that should be launched rather than opened, especially XML-based data files, as this is a chance for Scholar to be smarter than Firefox itself--for example, OmniGraffle files, which are actually just XML files, normally open up in Firefox as an XML tree, but Scholar will launch them instead. (I imagine the same will need to be done for OmniOutliner, among other things...) --- chrome/chromeFiles/content/scholar/overlay.js | 10 +++++++++- chrome/chromeFiles/content/scholar/xpcom/file.js | 9 +++++++-- components/chnmIScholarService.js | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/chrome/chromeFiles/content/scholar/overlay.js b/chrome/chromeFiles/content/scholar/overlay.js index 15d9c2dc1..f1b9fb607 100644 --- a/chrome/chromeFiles/content/scholar/overlay.js +++ b/chrome/chromeFiles/content/scholar/overlay.js @@ -529,7 +529,15 @@ var ScholarPane = new function() if(attachment.getAttachmentLinkMode() != Scholar.Attachments.LINK_MODE_LINKED_URL) { - window.loadURI(attachment.getLocalFileURL()); + var file = attachment.getFile(); + if (attachment.getAttachmentLinkMode() == Scholar.Attachments.LINK_MODE_IMPORTED_URL + || Scholar.File.hasInternalHandler(file)) + { + window.loadURI(attachment.getLocalFileURL()); + } + else { + file.launch(); + } } else { diff --git a/chrome/chromeFiles/content/scholar/xpcom/file.js b/chrome/chromeFiles/content/scholar/xpcom/file.js index 038743d36..628fcfa4c 100644 --- a/chrome/chromeFiles/content/scholar/xpcom/file.js +++ b/chrome/chromeFiles/content/scholar/xpcom/file.js @@ -148,8 +148,13 @@ Scholar.File = new function(){ return true; } - for (var i in navigator.mimeTypes){ - if (navigator.mimeTypes[i].type==mimeType){ + // Is there a better way to get to navigator? + var types = Components.classes["@mozilla.org/appshell/appShellService;1"] + .getService(Components.interfaces.nsIAppShellService) + .hiddenDOMWindow.navigator.mimeTypes; + + for (var i in types){ + if (types[i].type==mimeType){ Scholar.debug('MIME type ' + mimeType + ' can be handled by plugins'); return true; } diff --git a/components/chnmIScholarService.js b/components/chnmIScholarService.js index 860faa8e8..aacaeda87 100644 --- a/components/chnmIScholarService.js +++ b/components/chnmIScholarService.js @@ -30,6 +30,10 @@ Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader) .loadSubScript("chrome://scholar/content/xpcom/data_access.js"); +Cc["@mozilla.org/moz/jssubscript-loader;1"] + .getService(Ci.mozIJSSubScriptLoader) + .loadSubScript("chrome://scholar/content/xpcom/file.js"); + Cc["@mozilla.org/moz/jssubscript-loader;1"] .getService(Ci.mozIJSSubScriptLoader) .loadSubScript("chrome://scholar/content/xpcom/notifier.js");