home *** CD-ROM | disk | FTP | other *** search
- var search = {
-
- // Set this to false to disable debug output
- SEARCH_DEBUG : true,
-
- // Constants
- MAX_HISTORY_SIZE : 10,
- SEARCH_PLUGINS_FOLDER : "searchplugins",
- SEARCH_PROVIDER_RDF_FILE : "search-providers.rdf",
- SEARCH_HISTORY_FILE : "search-history.txt",
- SEARCH_TAG : "search:",
-
- // File open flags (from prio.h)
- PR_RDONLY : 1,
- PR_WRONLY : 2,
- PR_TRUNCATE : 4,
-
- // RDF Predicates
- SPUI_NS : "http://home.netscape.com/NC-spui#",
- RES_NAME : null,
- RES_ICON : null,
- RES_SRC : null,
-
- // Globals
- profileDir : null,
- ioService : null,
- prefService : null,
- RDFService : null,
- httpService : null,
- localRDFLoadObserver : null,
- remoteRDFLoadObserver : null,
- remoteRDFFetchURL : null,
- searchProviderList : new Array(),
- mRemoteLoadError : false,
- mRemoteLoadErrorCount : null,
-
-
- Init : function() {
- this.mRemoteLoadErrorCount = 10;
- this.mRemoteLoadError = false;
- this.debug('Init()');
-
- // Get the user's profile directory
- if (!this.profileDir) {
- this.profileDir = Components.classes["@mozilla.org/file/directory_service;1"]
- .getService(Components.interfaces.nsIProperties)
- .get("ProfD", Components.interfaces.nsILocalFile);
- }
- this.debug('profileDir: '+this.profileDir.path);
-
- // IO Service
- if (!this.ioService) {
- this.ioService = Components.classes["@mozilla.org/network/io-service;1"]
- .getService(Components.interfaces.nsIIOService);
- }
-
- // Pref Service
- if (!this.prefService) {
- this.prefService = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- }
-
- // RDF Service
- if (!this.RDFService) {
- this.RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
- .getService(Components.interfaces.nsIRDFService);
- }
-
- // HTTP Service
- if (!this.httpService) {
- this.httpService = Components.classes["@mozilla.org/network/protocol;1?name=http"]
- .getService(Components.interfaces.nsIHttpProtocolHandler);
- }
-
- // RDF Predicates
- this.RES_NAME = this.RDFService.GetResource(this.SPUI_NS+'name');
- this.RES_ICON = this.RDFService.GetResource(this.SPUI_NS+'icon');
- this.RES_SRC = this.RDFService.GetResource(this.SPUI_NS+'src');
-
- // Local RDF Load Observer
- // ... watches loading of the *local* search-providers.rdf file
- if (!this.localRDFLoadObserver) {
- this.debug(' instanciating local RDF load observer');
- this.localRDFLoadObserver = {
- onBeginLoad : function(sink){},
- onInterrupt : function(sink){},
- onResume : function(sink){},
- onError : function(sink,status,msg){},
- onEndLoad : function(sink) {
- this.debug('onEndLoad()');
- // Load datasource
- sink.removeXMLSinkObserver(this);
- sink.QueryInterface(Components.interfaces.nsIRDFDataSource);
- this.debug(' loaded local datasource: '+sink.URI);
- // Parse the datasource
- this.parent.ParseDataSource(sink);
- // Get the current search provider list to compare against the remote list
- this.parent.GetCurrentSearchProviderList(sink);
- // Now update from the server
- this.parent.LoadRemoteSearchProviders();
- },
- debug : function(msg) {
- this.parent.debug('localRDFLoadObserver: '+msg);
- }
- };
- this.localRDFLoadObserver.parent = this;
- }
-
- // Remote RDF Load Observer
- // ... watches loading of the *remote* search-providers.rdf file
- if (!this.remoteRDFLoadObserver) {
- this.debug(' instanciating remote RDF load observer');
- this.remoteRDFLoadObserver = {
- onBeginLoad : function(sink){},
- onInterrupt : function(sink){},
- onResume : function(sink){},
- onError : function(sink,status,msg)
- {
- this.parent.mRemoteLoadError = true;
- this.parent.mRemoteLoadErrorCount = this.parent.mRemoteLoadErrorCount - 1;
- this.debug("remoteLoad Error: " + msg);
- },
- onEndLoad : function(sink) {
- if (!this.parent.mRemoteLoadError){
- this.debug('onEndLoad()');
- // Load datasource
- sink.removeXMLSinkObserver(this);
- sink.QueryInterface(Components.interfaces.nsIRDFDataSource);
- this.debug(' loaded remote datasource: '+sink.URI);
- // Copy over top of the local file
- var localFile = this.parent.GetLocalSearchProviderRDFFile();
- this.debug(' saving a local copy of the RDF file');
- var localFileURI = this.parent.ioService.newFileURI(localFile);
- sink.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
- sink.FlushTo(localFileURI.spec);
- // Parse the datasource
- this.parent.ParseDataSource(sink);
- }
- else if (this.parent.mRemoteLoadErrorCount)
- {
- this.parent.mRemoteLoadError = false;
- sink.removeXMLSinkObserver(this);
- this.parent.LoadRemoteSearchProviders();
- }
- },
- debug : function(msg) {
- this.parent.debug('remoteRDFLoadObserver: '+msg);
- }
- };
- this.remoteRDFLoadObserver.parent = this;
- }
-
- // Construct URL to fetch the remote search provider RDF file
- if (!this.remoteRDFFetchURL) {
- var user_guid = this.prefService.getCharPref("browser.info.guid");
- var partnerId;
- try {
- partnerId = this.prefService.getCharPref("browser.partnerId");
- } catch (ex) {
- partnerId = 'chapera';
- }
- this.remoteRDFFetchURL =
- this.prefService.getCharPref("browser.search.providers.url");
- // + "?guid="+user_guid + "&partnerId="+partnerId;
- this.debug(' remote RDF URL: '+this.remoteRDFFetchURL);
- }
-
- this.LoadLocalSearchProviders();
- },
-
-
- // returns the array position if item is found in the list, otherwise returns -1
- ExistsInList : function(list, name, bIgnoreCase) {
- for (var idx = 0; idx < list.length; idx++) {
- var item1 = list[idx];
- var item2 = name;
- if (bIgnoreCase) {
- item1 = item1.toLowerCase();
- item2 = item2.toLowerCase();
- }
- if (item1 == item2)
- return idx;
- }
- return -1;
- },
-
-
- GetCurrentSearchProviderList : function(datasource) {
- if (!this.searchProviderList)
- this.searchProviderList = new Array();
-
- var pluginsFolder = this.EnsureSearchPluginsFolderExists();
- var entries = pluginsFolder.directoryEntries;
- while (entries.hasMoreElements()) {
- var entry = entries.getNext();
- entry.QueryInterface(Components.interfaces.nsILocalFile);
- var fileName = entry.leafName;
- var idx = fileName.lastIndexOf(".");
- if (idx >= 0)
- fileName = fileName.substring(0, idx);
- if (fileName.length > 0 && this.ExistsInList(this.searchProviderList, fileName, true) < 0) {
- this.debug(' Adding to the search provider list: ' + fileName);
- this.searchProviderList[this.searchProviderList.length] = fileName;
- }
- }
- },
-
-
- LoadLocalSearchProviders : function() {
- this.debug('RefreshLocalSearchProviders()');
- var file = this.GetLocalSearchProviderRDFFile();
- var fileURI = this.ioService.newFileURI(file);
- try {
- // Start loading local RDF file of search providers
- var ds = this.RDFService.GetDataSource(fileURI.spec);
- // Register a listener to pick things up when the file is done
- // loading. (Control will go to the onEndLoad function...)
- ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
- ds.addXMLSinkObserver(this.localRDFLoadObserver);
- } catch (ex) {
- // If there was a problem loading the local file, just go
- // directly to the online one
- this.debug(' problem loading local '+this.SEARCH_PROVIDER_RDF_FILE);
- this.LoadRemoteSearchProviders();
- }
- },
-
-
- LoadRemoteSearchProviders : function() {
- this.debug('RefreshRemoteSearchProviders()');
- try {
- ds = this.RDFService.GetDataSourceNoCache(this.remoteRDFFetchURL);
- ds.QueryInterface(Components.interfaces.nsIRDFXMLSink);
- ds.addXMLSinkObserver(this.remoteRDFLoadObserver);
- } catch (ex) {
- this.debug(' problem loading remote search providers file');
- }
- },
-
-
- ParseDataSource : function(datasource) {
- // Remove existing search providers that are not in the datasource
- this.ScrubSearchProviderDirectory(datasource);
-
- // Iterate through resources
- var resources = datasource.GetAllResources();
- var res;
- while (resources.hasMoreElements()) {
- res = resources.getNext();
- res.QueryInterface(Components.interfaces.nsIRDFResource);
- this.LoadSingleProviderResource(datasource, res);
- this.RDFService.UnregisterResource(res);
- }
- this.RDFService.UnregisterDataSource(datasource);
- },
-
-
- ScrubSearchProviderDirectory : function(datasource) {
- if (!this.searchProviderList)
- return;
-
- if (this.prefService.getPrefType('browser.search.providers.preserve') &&
- this.prefService.getBoolPref('browser.search.providers.preserve')) {
- this.searchProviderList = null;
- return;
- }
-
- if (datasource)
- {
- // Iterate through resources
- var resources = datasource.GetAllResources();
- while (resources.hasMoreElements()) {
- var res = resources.getNext();
- res.QueryInterface(Components.interfaces.nsIRDFResource);
- var resVal = res.Value;
- if (!resVal)
- continue;
- if (resVal.indexOf(this.SEARCH_TAG) < 0)
- continue;
-
- resVal = resVal.substring(this.SEARCH_TAG.length);
- this.debug('ScrubSearchProoviderDirectory: resVal: ' + resVal);
-
- var idx = this.ExistsInList(this.searchProviderList, resVal, true);
- if (idx > -1) {
- this.debug('ScrubSearchProoviderDirectory: Val: ' + resVal + ', InList: ' + this.searchProviderList[idx]);
- this.searchProviderList.splice(idx, 1);
- }
- }
-
- for (var idx = 0; idx < this.searchProviderList.length; idx++)
- this.RemoveSearchProvider(this.searchProviderList[idx]);
- }
-
- this.searchProviderList = null;
- },
-
-
- RemoveSearchProvider : function(searchProvider) {
- if (!searchProvider)
- return;
-
- var pluginsFolder = this.EnsureSearchPluginsFolderExists();
-
- const SearchProviderExt = [".src", ".gif", ".jpg", ".bmp", ".png"];
- for (var idx = 0; idx < SearchProviderExt.length; idx++) {
- var filename = searchProvider + SearchProviderExt[idx];
- var spFile = pluginsFolder.clone();
- spFile.append(filename);
- if (spFile.exists()) {
- this.debug('(remove pre-existing file: '+spFile.path+')');
- spFile.remove(false);
- }
- }
- },
-
-
- LoadSingleProviderResource : function(datasource, resource) {
- this.debug('LoadSingleProviderResource('+resource.Value+')');
- // See if this resource specifies an actual search provider
- if (datasource.hasArcOut(resource, this.RES_NAME) &&
- datasource.hasArcOut(resource, this.RES_ICON) &&
- datasource.hasArcOut(resource, this.RES_SRC))
- {
- var name = datasource.GetTarget(resource, this.RES_NAME, true);
- name.QueryInterface(Components.interfaces.nsIRDFLiteral);
- this.debug(' name: '+name.Value);
- var icon = datasource.GetTarget(resource, this.RES_ICON, true);
- icon.QueryInterface(Components.interfaces.nsIRDFLiteral);
- this.debug(' icon: '+icon.Value);
- var src = datasource.GetTarget(resource, this.RES_SRC, true);
- src.QueryInterface(Components.interfaces.nsIRDFLiteral);
- this.debug(' src: '+src.Value);
- // Create the searchplugins folder if it doesn't exist
- var pluginsFolder = this.EnsureSearchPluginsFolderExists();
- // Download the icon and src files and stick them in the
- // searchplugins folder
- this.DownloadToSearchPluginsFolder(icon.Value, ["gif", "jpg", "bmp", "png"]);
- this.DownloadToSearchPluginsFolder(src.Value);
- }
- },
-
-
- DownloadToSearchPluginsFolder : function(urlSpec, clearFiles) {
- this.debug('DownloadToSearchPluginsFolder('+urlSpec+')');
-
- // Create URL object
- var remoteURL = Components.classes["@mozilla.org/network/standard-url;1"]
- .createInstance(Components.interfaces.nsIStandardURL);
- remoteURL.init(Components.interfaces.nsIStandardURL.URLTYPE_STANDARD,
- null, urlSpec, null, null);
- remoteURL.QueryInterface(Components.interfaces.nsIURL);
- this.debug(' filename is: '+remoteURL.fileName);
-
- // Download
- var downloadObserver = {
- QueryInterface : function(iid) {
- if (!iid.equals(nsIDownloadObserver) &&
- !iid.equals(nsISupports))
- throw Components.results.NS_ERROR_NO_INTERFACE;
- return this;
- },
- onDownloadComplete : function(downloader, request, ctxt, status, file) {
- // file.path now references a temporary cached copy of the file,
- // so copy it to the searchplugins folder
- this.debug('file is at: '+file.path);
- var pluginsFolder = this.parent.GetSearchPluginsFolder();
- this.debug('copying to: '+pluginsFolder.path+' '+this.fileName);
-
- // BLT 152031 fix: replace the existing icon files
- if(!clearFiles) {
- clearFiles = [""];
- }
-
- for(var i in clearFiles) {
- var ext = clearFiles[i];
- var destFname = this.fileName;
- if(ext != "") {
- var ind = destFname.lastIndexOf(".");
- if(ind >= 0) {
- destFname = destFname.substring(0, ind);
- }
- destFname += "." + ext;
- }
- // Test if the file already exists
- var destinationFile = pluginsFolder.clone();
- destinationFile.append(destFname);
- if (destinationFile.exists()) {
- this.debug(' (removing pre-existing file: '+destFname+')');
- destinationFile.remove(false);
- file.copyTo(pluginsFolder, destFname);
- }
- else if(this.fileName == destFname) {
- file.copyTo(pluginsFolder, destFname);
- }
- }
- },
- debug : function(msg) {
- this.parent.debug('downloadObserver: '+msg);
- }
- };
- downloadObserver.parent = this;
- downloadObserver.fileName = remoteURL.fileName;
- var channel = this.ioService.newChannel(remoteURL.spec, null, null);
- var downloader = Components.classes["@mozilla.org/network/downloader;1"]
- .createInstance(Components.interfaces.nsIDownloader);
- downloader.init(downloadObserver, null);
- channel.asyncOpen(downloader, null);
- },
-
-
- GetSearchPluginsFolder : function() {
- this.debug('GetSearchPluginsFolder()');
- // Create file descriptor
- var folder = this.profileDir.clone();
- folder.append(this.SEARCH_PLUGINS_FOLDER);
- return folder; // returns nsILocalFile
- },
-
-
- EnsureSearchPluginsFolderExists : function() {
- this.debug('EnsureSearchPluginsFolderExists()');
- var folder = this.GetSearchPluginsFolder();
- if (!folder.exists()) {
- folder.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0);
- }
- return folder; // returns nsILocalFile
- },
-
-
- GetLocalSearchProviderRDFFile : function() {
- this.debug('GetLocalSearchProviderRDFFile(): '+this.SEARCH_PROVIDER_RDF_FILE);
- // Create file descriptor
- var file = this.profileDir.clone();
- file.append(this.SEARCH_PROVIDER_RDF_FILE);
- return file; // returns nsILocalFile
- },
-
-
- GetSearchHistoryFile : function() {
- this.debug('GetSearchHistoryFile(): '+this.SEARCH_HISTORY_FILE);
- // Create file descriptor
- var file = this.profileDir.clone();
- file.append(this.SEARCH_HISTORY_FILE);
- return file; // returns nsILocalFile
- },
-
-
- EnsureSearchHistoryFileExists : function() {
- this.debug('EnsureSearchHistoryFileExists()');
- var file = this.GetSearchHistoryFile();
- if (!file.exists()) {
- this.debug(' creating file: '+this.SEARCH_HISTORY_FILE);
- file.create(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0);
- }
- return file; // returns nsILocalFile
- },
-
-
- ReadSearchHistory : function() {
- this.debug('ReadSearchHistory()');
-
- var file = this.EnsureSearchHistoryFileExists();
-
- // Init the file input stream
- var fis = Components.classes["@mozilla.org/network/file-input-stream;1"]
- .createInstance(Components.interfaces.nsIFileInputStream);
- fis.init(file, this.PR_RDONLY, 0, 0);
-
- // Init a scriptable input stream
- var sis = Components.classes["@mozilla.org/scriptableinputstream;1"]
- .createInstance(Components.interfaces.nsIScriptableInputStream);
- sis.init(fis);
-
- // Read the file
- var fileContents = sis.read(sis.available());
-
- // Close file
- fis.close();
-
- // Return the lines as an array
- return fileContents.split('\n');
- },
-
-
- PopulateHistoryPopup : function(evt) {
- this.debug('PopulateHistoryPopup()');
-
- // Purge the history menu
- var popup = evt.target;
- while (popup.lastChild)
- popup.removeChild(popup.lastChild);
-
- // Load in the fresh history items
- var entries = this.ReadSearchHistory();
- for (var i = 0; i < entries.length; i++) {
- if (!entries[i].length) continue;
- var newItem = document.createElement('menuitem');
- newItem.setAttribute('label', entries[i]);
- newItem.setAttribute('oncommand', 'search.HistoryCommand("'+entries[i]+'");');
- popup.appendChild(newItem);
- }
-
- // Only add the separator if there were history items
- if (popup.lastChild)
- popup.appendChild(document.createElement('menuseparator'));
-
- // Always add the 'clear history' menu item
- var clearHist = document.createElement('menuitem');
- clearHist.setAttribute('label', 'Clear Search History');
- clearHist.setAttribute('oncommand', 'search.ClearSearchHistory();');
-
- // ... but if there were no history items, then make it disabled
- if (!popup.lastChild)
- clearHist.setAttribute('disabled','true');
- popup.appendChild(clearHist);
- },
-
-
- HistoryCommand : function(value) {
- this.debug('HistoryCommand("'+value+'")');
- var searchbar = document.getElementById('searchbar');
- if (searchbar) {
- // Put the value into the text box
- searchbar.mTextbox.value = value;
- // Execute search
- searchbar.mTextbox.onTextEntered();
- }
- },
-
-
- AddToHistory : function(value) {
- this.debug('AddToHistory("'+value+'")');
-
- // If it's whitespace, don't bother
- if (!this.trim(value).length) return;
-
- // Create the new list
- var oldList = this.ReadSearchHistory();
- var newList = new Array();
- newList[0] = value;
- for (var i = 0; i < oldList.length; i++) {
- if (oldList[i] != value)
- newList[newList.length] = oldList[i];
- if (newList.length >= this.MAX_HISTORY_SIZE)
- break;
- }
-
- // Open the history file for writing
- var file = this.GetSearchHistoryFile();
- file.remove(false);
- file = this.EnsureSearchHistoryFileExists();
- var fos = Components.classes["@mozilla.org/network/file-output-stream;1"]
- .createInstance(Components.interfaces.nsIFileOutputStream);
- fos.init(file, this.PR_WRONLY, 0, 0);
- var contents = newList.join('\n');
- this.debug(' - writing contents:\n'+contents+'\n\n');
- fos.write(contents, contents.length);
- fos.close();
- },
-
-
- ClearSearchHistory : function() {
- this.debug('ClearSearchHistory()');
- var file = this.GetSearchHistoryFile();
- if (file.exists()) {
- // Init the file input stream
- var fis = Components.classes["@mozilla.org/network/file-input-stream;1"]
- .createInstance(Components.interfaces.nsIFileInputStream);
- fis.init(file, this.PR_RDONLY, 0,
- Components.interfaces.nsIFileInputStream.DELETE_ON_CLOSE);
- fis.close();
- }
- // MERC (rpaul) clear the searchbar text
- var searchbar = document.getElementById('searchbar');
- if (searchbar)
- searchbar.clear();
-
- // <input name=q> is the entries stored for search engine forms. Clear them.
- var formHistSvc = Components.classes["@mozilla.org/satchel/form-history;1"]
- .getService(Components.interfaces.nsIFormHistory);
- formHistSvc.removeEntriesForName("q");
-
- },
-
-
- debug : function(msg) {
- if (this.SEARCH_DEBUG)
- {
- dump('search.js: '+msg+'\n');
- }
- },
-
-
-
-
- trim : function(str) {
- if (!str) return "";
- str = str.replace(/^\s+/, "");
- return str.replace(/\s+$/, "");
- },
-
- /* MERC - RTOMASELLI
- Method to populate the search provider list
- */
- PopulateEnginePopup : function(evt) {
-
- var DESKTOP_SEARCH_ID = "DesktopSearch";
- var popup = evt.target;
-
- while (popup.lastChild)
- popup.removeChild(popup.lastChild);
- var ds = this.RDFService.GetDataSource("rdf:internetsearch");
- var kNC_Root = this.RDFService.GetResource("NC:SearchEngineRoot");
- var kNC_child = this.RDFService.GetResource("http://home.netscape.com/NC-rdf#child");
- var kNC_Name = this.RDFService.GetResource("http://home.netscape.com/NC-rdf#Name");
- var kNC_Icon = this.RDFService.GetResource("http://home.netscape.com/NC-rdf#Icon");
- var kNC_Version = this.RDFService.GetResource("http://home.netscape.com/NC-rdf#Version");
- var kNC_Description = this.RDFService.GetResource("http://home.netscape.com/NC-rdf#Description");
-
- var arcs =ds.GetTargets(kNC_Root, kNC_child, true);
- // BC: Loading Search engine from a pref
- // Get preferences
- var prefServ = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
-
-
- while (arcs.hasMoreElements()) {
- var engine = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
- var name = ds.GetTarget(engine, kNC_Name,true).QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
- var icon = ds.GetTarget(engine, kNC_Icon,true).QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
- var ver = ds.GetTarget(engine, kNC_Version,true).QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
- var desc = ds.GetTarget(engine, kNC_Description,true).QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
- var engineValue = engine.Value;
-
- var newEngineItem = document.createElement('menuitem');
- var childBox = document.createElement('hbox');
- var searchIcon = document.createElement('image');
- var labelText = document.createElement('label');
- var checkboxContainer = document.createElement('hbox');
- var checkbox = document.createElement('image');
- newEngineItem.setAttribute('id', engineValue);
- newEngineItem.setAttribute('value', engineValue);
- //newEngineItem.setAttribute('label', name);
- newEngineItem.setAttribute('type', 'checkbox');
- newEngineItem.setAttribute('desc', desc);
- newEngineItem.setAttribute('ver', ver);
- newEngineItem.setAttribute('src', icon);
-
- // Set the icon for the search provider
- searchIcon.setAttribute('src', icon);
-
- // Set the text for the label
- labelText.setAttribute('value', name);
- labelText.setAttribute('class', 'searchbar-menu-iconic-text');
-
- // Set the checked attribute
- checkboxContainer.setAttribute('class', 'searchbar-menu-iconic-left');
- checkbox.setAttribute('class', 'searchbar-menu-iconic-icon');
-
- // BC: If this element is the same as the saved pref, check it.
- // check that the pref exists
- if (prefServ.prefHasUserValue("browser.searchbar.lastSelectedEngine")) {
- loadedPref = prefServ.getCharPref("browser.searchbar.lastSelectedEngine");
- // if the loadedPref setting is the same as the current engine value, lets check it
- if(loadedPref == engineValue) {
- checkbox.setAttribute('checked', 'true');
- }
- }
-
- checkboxContainer.appendChild(checkbox);
- newEngineItem.appendChild(searchIcon);
- newEngineItem.appendChild(labelText);
- newEngineItem.appendChild(checkboxContainer);
- popup.appendChild(newEngineItem);
-
- }
-
-
- // 10.5.2005 NAJ : The following if statement was removed to expose desktop search
- // regardles of it's installed/uninstalled state per CCv3. A handler for the lack of
- // an installed Copernic will be required, this will be atached to the oncommand
- // in the UI.
-
- // if (desktopSearch.isDesktopSearchAvailable()) {
-
- if (popup.lastChild)
- popup.appendChild(document.createElement('menuseparator'));
-
- var desktopSearchItem = document.createElement('menuitem');
- desktopSearchItem.setAttribute('id', DESKTOP_SEARCH_ID);
- desktopSearchItem.setAttribute('value', DESKTOP_SEARCH_ID);
- desktopSearchItem.setAttribute('type', 'checkbox');
- desktopSearchItem.setAttribute('label', 'Desktop Search');
- desktopSearchItem.setAttribute('src', 'chrome://browser/skin/search/copernic.png');
- popup.appendChild(desktopSearchItem);
-
- //}
-
-
- },
- /* MERC - BCharan
- * @param - ID of the selected element
- */
- saveSelectionToPref : function(element) {
- // BC: Saving Search into a pref
- // Get preferences
- var prefServ = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
-
- // Check if the pref exists first
- if (prefServ.prefHasUserValue("browser.searchbar.lastSelectedEngine")) {
- // Get the stored pref
- storedPref = prefServ.getCharPref("browser.searchbar.lastSelectedEngine");
- // If the pref exists, then compare it to the current pref,
- // Overwrite if they are not equal
- if (storedPref != element.getAttribute('id')) {
- prefServ.setCharPref("browser.searchbar.lastSelectedEngine", element.getAttribute('id'));
- }
- } else {
- prefServ.setCharPref("browser.searchbar.lastSelectedEngine", element.getAttribute('id'));
- }
- },
-
- /* MERC - RTOMASELLI
- This method is called when 'Web Search' is selected from the 'Tools'
- menu. Loop through the list of web providers and if one of them
- matches the browser default search provider then use it otherwise
- use any other web search provider. This also handles the case if the
- default provider is the desktop search.
- */
- OnWebSearchSelected : function(){
-
- var prefbranch = Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefBranch);
- var defaultName = prefbranch.getComplexValue("browser.search.defaultenginename",
- Components.interfaces.nsIPrefLocalizedString).data;
-
- var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
- .getService(Components.interfaces.nsIRDFService);
- var ds = rdf.GetDataSource("rdf:internetsearch");
- var kNC_Root = rdf.GetResource("NC:SearchEngineRoot");
- var kNC_child = rdf.GetResource("http://home.netscape.com/NC-rdf#child");
- var kNC_Name = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
- var kNC_Icon = rdf.GetResource("http://home.netscape.com/NC-rdf#Icon");
- var arcs =ds.GetTargets(kNC_Root, kNC_child, true);
- var engine;
- var name;
- var icon;
-
- var foundDefault = false;
- while (arcs.hasMoreElements() && !foundDefault) {
- engine = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
- name = ds.GetTarget(engine, kNC_Name,true).QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
- icon = ds.GetTarget(engine, kNC_Icon,true).QueryInterface(Components.interfaces.nsIRDFLiteral).Value;
-
- if (name == defaultName){foundDefault = true;}
- }
-
- if (engine) {
- var broadcaster = window.top.document.getElementById('searchEngineBroadcaster');
- broadcaster.setAttribute("src",icon);
- broadcaster.setAttribute("searchengine", engine.Value);
- }
-
- focusSearchBar();
-
- },
-
- /* MERC - RTOMASELLI
- This method is called when 'Desktop Search' is selected from the 'Tools' menu */
- OnDesktopSearchSelected: function(){
-
- var broadcaster = window.top.document.getElementById('searchEngineBroadcaster');
- broadcaster.setAttribute("src","chrome://browser/skin/search/copernic.png");
- broadcaster.setAttribute("searchengine", "DesktopSearch");
- },
-
-
- logError : function(exceptionObject, optionalAdditionalText) {
- // logs (or otherwise handles) errors
- // do logging ?!
- // for now, just alert
- var output;
- var errSource = this.logError.caller; //Source function from the error
-
- output = "Function: " + errSource.name ;
-
- if (errSource.arity > 0){
- output += "\nArguments: \n"
- for (i=0; i < errSource.arity; i++){
- output += " (" + i + ") " + errSource.arguments[i] ;
- }
- }
- output += "\nException: " + exceptionObject.message ;
-
- if (optionalAdditionalText != null) {
- output += "\nNotes: " + optionalAdditionalText;
- }
- this.debug("\n" + output);
- alert (output);
-
- }
-
- };
-
-