home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * Copyright (c) 2003 Paul Roub <paul@roub.net>
- *
- * $Header: /cvs/ieview/ieview/content/ieviewOverlay.js,v 1.1 2004/06/11 04:20:05 roub Exp $
- *
- * Portions based on GPLed code by
- * Ted Mielczarek
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * *****
- *
- * Notes:
- *
- * Since we can't know ahead of time where IE will be installed, we Kiboze the
- * Start Menu tree. If the shortcut has been renamed (i.e. it is no longer
- * titled "Internet Explorer"), we're out of luck. The only option at that
- * point would be to open and dereference every symlink we find, and see if the
- * target leaf name is "iexplore.exe". Not doing that at the moment, since
- * it just seems insane.
- */
-
- var ieviewMenuItems = new Array("ieview-do-view", "ieview-do-viewlink");
- var userPrograms = "Progs";
- var allUserPrograms = "CmPrgs";
- var applicationData = "AppData";
-
- var gIeViewBundle;
-
- function ieviewContext() {
- if(gContextMenu) {
- for(var i=0; i<ieviewMenuItems.length; i++) {
- var menuitem = document.getElementById(ieviewMenuItems[i]);
- if(menuitem && (i == 0))
- menuitem.hidden = (gContextMenu.isTextSelected || gContextMenu.onLink || gContextMenu.onImage || gContextMenu.onTextInput );
- else if (menuitem)
- {
- menuitem.hidden = ! gContextMenu.onLink;
- }
- }
- }
- }
-
- function ieView() {
- if(gContextMenu) {
- var href = gBrowser.currentURI.spec;
-
- ieViewLaunch("Internet Explorer.lnk", href);
- }
- }
-
-
- function ieViewLink() {
- if(gContextMenu) {
- var href = gContextMenu.linkURL();
-
- ieViewLaunch("Internet Explorer.lnk", href);
- }
- }
-
-
-
- // attempt to grab the real path of a predefined directory
- //
- function tryDir(dsp, key)
- {
- try
- {
- var nif = dsp.get(key, Components.interfaces.nsIFile);
- return(nif.path);
- }
- catch (ar)
- {
- return("");
- }
- }
-
-
- function searchPath(path, fname)
- {
- var result = null;
-
- try
- {
- var f = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
-
- f.initWithPath(path);
-
- if (f.exists() && f.isDirectory())
- {
- var entries = f.directoryEntries;
-
- while (entries.hasMoreElements())
- {
- var ent = entries.getNext().QueryInterface(Components.interfaces.nsIFile);
-
- if (ent.isDirectory())
- {
- result = searchPath(ent.path, fname);
-
- if (result)
- {
- break;
- }
- }
- else if (ent.isSymlink())
- {
- if (ent.leafName.toLowerCase() == fname.toLowerCase())
- {
- result = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
- result.followLinks = true;
- result.initWithPath(ent.path);
-
- if (result.target == "")
- {
- result = null;
- }
- else
- {
- break;
- }
- }
- }
- else if (ent.isFile())
- {
- if (ent.leafName.toLowerCase() == fname.toLowerCase())
- {
- result = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
- result.initWithPath(ent.path);
- break;
- }
- }
- }
- }
- }
- catch (ar)
- {
- return(null);
- }
-
- return( result );
- }
-
-
-
- function ieViewLaunch (path,argumentstext)
- {
- var cantMessage = "can't find";
-
- try
- {
- cantMessage = gIeViewBundle.getString("ieview.cantFindExplorer");
- }
- catch(e)
- {
- alert(e);
- }
-
- var prefservice = Components.classes["@mozilla.org/preferences-service;1"].
- getService(Components.interfaces.nsIPrefService);
-
- var prefs = prefservice.getBranch("");
-
- try{
- if(path=="") return false;
-
- var ieloc = null;
-
- if (prefs.getPrefType("ieview.ieapp") == prefs.PREF_STRING)
- {
- ieloc = prefs.getCharPref("ieview.ieapp");
- }
-
- var natTarget = null;
- var usePath = null;
-
- if (ieloc != null)
- {
- natTarget = ieloc;
- }
- else
- {
- var dsprops = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties);
-
- usePath = tryDir(dsprops, userPrograms); // try user-specific program menu first
-
- var file = null;
-
- if (usePath != "")
- {
- file = searchPath(usePath, path);
- }
-
- if (! file)
- {
- usePath = tryDir(dsprops, allUserPrograms); // no joy? try "all users" program menu
-
- if (usePath != "")
- {
- file = searchPath(usePath, path);
- }
- }
-
- if (! file)
- {
- usePath = tryDir(dsprops, applicationData); // last resort, check the "quick start" bar
-
- if (usePath != "")
- {
- var quickPath = "\\microsoft\\internet explorer\\quick launch";
-
- usePath = usePath + quickPath;
-
- file = searchPath(usePath, path);
-
- if (! file) // check alternate QuickLaunch bar title
- {
- var launchLink = "Launch Internet Explorer Browser.lnk";
-
- file = searchPath(usePath, launchLink);
- }
- }
- }
-
- // last ditch -- find the windows directory
- // assume that the main Program Files directory is on the same drive
- // look in there, under Program Files\Internet Explorer, for iexplore.exe
- //
- if (! file)
- {
- var usePath = tryDir(dsprops, "WinD");
-
- if ((usePath != "") && (usePath.charAt(1) == ":"))
- {
- usePath = usePath.substr(0, 2) + "\\program files\\internet explorer";
-
- file = searchPath(usePath, "iexplore.exe");
- }
- }
-
- if ((! file) || (! file.exists()))
- {
- alert(cantMessage);
- return false;
- }
-
- natTarget = file.target;
- }
-
- var targetFile = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
-
- targetFile.initWithPath(natTarget);
-
- if (! targetFile.exists())
- {
- alert(cantMessage);
- return(false);
- }
-
- usePath = targetFile.target;
-
- var process = Components.classes['@mozilla.org/process/util;1'].getService(Components.interfaces.nsIProcess);
- process.init(targetFile);
- var arguments= [] ;
-
- arguments.push(argumentstext);
-
- process.run(false, arguments, arguments.length, {});
- return true;
-
- }catch(e){
- alert(e);return false;
- }
-
- return false; // avoid JavaScript Error.
- }
-
-
- function ieviewInit() {
- var menu = document.getElementById("contentAreaContextMenu");
- menu.addEventListener("popupshowing",ieviewContext,false);
-
- gIeViewBundle = document.getElementById("bundle_ieview");
-
- if (! gIeViewBundle)
- {
- alert("no bundle");
- }
- }
-
- function setIeviewOptions()
- {
- if (document.getElementById('ieloc').value)
- {
- var prefService = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService);
-
- var prefs = prefService.getBranch("");
-
- prefs.setCharPref("ieview.ieapp", document.getElementById('ieloc').value);
- }
-
- window.close();
- }
-
- function pickIe()
- {
- var picker = Components.classes["@mozilla.org/filepicker;1"].getService(Components.interfaces.nsIFilePicker);
-
- picker.init(window, "Choose Browser", 0);
- picker.appendFilters(64);
-
- if (picker.show() == 0)
- {
- document.getElementById('ieloc').value = picker.file.target;
- }
- }
-
-
- function initPath()
- {
- var prefservice = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService);
-
- var prefs = prefservice.getBranch("");
-
- var ieloc = null;
-
- if (prefs.getPrefType("ieview.ieapp") == prefs.PREF_STRING)
- {
- ieloc = prefs.getCharPref("ieview.ieapp");
- }
-
- if ((ieloc != null) && (ieloc.length > 0))
- {
- document.getElementById('ieloc').value = ieloc;
- }
-
- prefs = null;
- }
-
- // do the init on load
- window.addEventListener("load", ieviewInit, false);
-
-