bug 410613 - SeaMonkey should support "OpenSearch", r=Mnyromyr sr=Neil
authorRobert Kaiser <kairo@kairo.at>
Thu, 30 Sep 2010 11:57:09 +0200
changeset 6457 098388acf16b
parent 6456 9021466c11d8
child 6458 addb24b470d6
push id4987
push userkairo@kairo.at
push dateThu, 30 Sep 2010 09:57:37 +0000
treeherdercomm-central@098388acf16b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMnyromyr, Neil
bugs410613
bug 410613 - SeaMonkey should support "OpenSearch", r=Mnyromyr sr=Neil
suite/browser/Makefile.in
suite/browser/browser-prefs.js
suite/browser/jar.mn
suite/browser/navigator.js
suite/browser/navigator.xul
suite/browser/navigatorDD.js
suite/browser/public/Makefile.in
suite/browser/public/nsISearchService.idl
suite/browser/searchconfig.properties
suite/browser/src/Makefile.in
suite/browser/src/nsInternetSearchService.cpp
suite/browser/src/nsInternetSearchService.h
suite/browser/src/nsLocalSearchService.cpp
suite/browser/src/nsLocalSearchService.h
suite/browser/urlbarBindings.xml
suite/build/nsSuiteModule.cpp
suite/common/contentAreaContextOverlay.xul
suite/common/jar.mn
suite/common/nsContextMenu.js
suite/common/pref/pref-search.js
suite/common/pref/pref-search.xul
suite/common/search/internetresults.js
suite/common/search/internetresults.xul
suite/common/search/search-editor.js
suite/common/search/search-editor.xul
suite/common/search/search-panel.js
suite/common/search/search-panel.xul
suite/common/search/shared.js
suite/common/src/SuiteCommon.manifest
suite/common/src/nsSidebar.js
suite/confvars.sh
suite/installer/package-manifest.in
suite/installer/removed-files.in
suite/locales/Makefile.in
suite/locales/en-US/chrome/browser/region.properties
suite/locales/en-US/chrome/common/contentAreaCommands.properties
suite/locales/en-US/chrome/common/pref/pref-search.dtd
suite/locales/en-US/chrome/common/region.properties
suite/locales/en-US/chrome/common/search/default.htm
suite/locales/en-US/chrome/common/search/internetresults.dtd
suite/locales/en-US/chrome/common/search/search-editor.dtd
suite/locales/en-US/chrome/common/search/search-editor.properties
suite/locales/en-US/chrome/common/search/search-panel.dtd
suite/locales/en-US/chrome/common/search/search-panel.properties
suite/locales/en-US/chrome/common/search/search-rdf.dtd
suite/locales/en-US/chrome/common/sidebar/sidebar.properties
suite/locales/en-US/searchplugins/creativecommons.xml
suite/locales/en-US/searchplugins/dmoz.png
suite/locales/en-US/searchplugins/dmoz.src
suite/locales/en-US/searchplugins/google.png
suite/locales/en-US/searchplugins/google.src
suite/locales/en-US/searchplugins/google.xml
suite/locales/en-US/searchplugins/jeeves.png
suite/locales/en-US/searchplugins/jeeves.src
suite/locales/en-US/searchplugins/list.txt
suite/locales/en-US/searchplugins/wikipedia.xml
suite/locales/en-US/searchplugins/yahoo.xml
suite/locales/generic/profile/search.rdf.in
suite/locales/jar.mn
suite/mailnews/mailWindowOverlay.js
suite/mailnews/mailWindowOverlay.xul
suite/themes/classic/communicator/search/category.gif
suite/themes/classic/communicator/search/internetresults.css
suite/themes/classic/communicator/search/result.gif
suite/themes/classic/communicator/search/search-editor.css
suite/themes/classic/communicator/search/search.css
suite/themes/classic/jar.mn
suite/themes/modern/communicator/search/category.gif
suite/themes/modern/communicator/search/internetresults.css
suite/themes/modern/communicator/search/result.gif
suite/themes/modern/communicator/search/search-editor.css
suite/themes/modern/communicator/search/search.css
suite/themes/modern/jar.mn
--- a/suite/browser/Makefile.in
+++ b/suite/browser/Makefile.in
@@ -37,17 +37,19 @@
 
 DEPTH		= ../..
 topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
+ifeq ($(OS_ARCH),WINNT)
 PARALLEL_DIRS = public src
+endif
 
 ifdef ENABLE_TESTS
 PARALLEL_DIRS += test
 endif
 
 EXTRA_COMPONENTS = \
 	SuiteBrowser.manifest \
 	nsAboutRights.js \
--- a/suite/browser/browser-prefs.js
+++ b/suite/browser/browser-prefs.js
@@ -101,25 +101,50 @@ pref("browser.download.progress.closeWhe
 // the Content-Disposition filename) before giving up and falling back to
 // picking a filename without that info in hand so that the user sees some
 // feedback from their action.
 pref("browser.download.saveLinkAsFilenameTimeout", 1000);
 
 // Use the findbar instead of the dialog box
 pref("browser.findbar.enabled", true);
 
-// various default search settings
-pref("browser.search.defaulturl", "chrome://navigator-region/locale/region.properties");
-pref("browser.search.opensidebarsearchpanel", true);
-pref("browser.search.opentabforcontextsearch", false);
-pref("browser.search.last_search_category", "NC:SearchCategory?category=urn:search:category:1");
-pref("browser.search.mode", 0);
-// basic search popup constraint: minimum sherlock plugin version displayed
-// (note: must be a string representation of a float or it'll default to 0.0)
-pref("browser.search.basic.min_ver", "0.0");
+// search engines URL
+pref("browser.search.searchEnginesURL", "https://addons.mozilla.org/%LOCALE%/%APP%/search-engines/");
+
+// pointer to the default engine name
+pref("browser.search.defaultenginename", "chrome://communicator-region/locale/region.properties");
+
+// Disable logging for the search service by default.
+pref("browser.search.log", false);
+
+// Ordering of Search Engines in the Engine list.
+pref("browser.search.order.1", "chrome://communicator-region/locale/region.properties");
+pref("browser.search.order.2", "chrome://communicator-region/locale/region.properties");
+
+// Search (side)bar results always open in a new tab.
+pref("browser.search.openintab", false);
+
+// Invoking a search reveals the sidebar panel.
+pref("browser.search.opensidebarsearchpanel", false);
+
+// Send ping to the server to update.
+pref("browser.search.update", true);
+
+// Disable logging for the search service update system by default.
+pref("browser.search.update.log", false);
+
+// Check whether we need to perform engine updates every 6 hours
+pref("browser.search.update.interval", 21600);
+
+// Smart Browsing prefs
+pref("keyword.enabled", true);
+// Override the default keyword.URL. Empty value means
+// "use the search service's default engine"
+pref("keyword.URL", "");
+
 pref("browser.urlbar.autocomplete.enabled", true);
 pref("browser.urlbar.clickSelectsAll", true);
 // when clickSelectsAll=true, does it also apply when the click is past end of text?
 pref("browser.urlbar.clickAtEndSelects", true);
 
 pref("browser.urlbar.autoFill", false);
 pref("browser.urlbar.showPopup", true);
 pref("browser.urlbar.showSearch", true);
@@ -150,19 +175,16 @@ pref("browser.urlbar.search.timeout", 10
 pref("browser.urlbar.restrict.history", "^");
 pref("browser.urlbar.restrict.bookmark", "*");
 pref("browser.urlbar.restrict.tag", "+");
 pref("browser.urlbar.restrict.openpage", "%");
 pref("browser.urlbar.restrict.typed", "~");
 pref("browser.urlbar.match.title", "#");
 pref("browser.urlbar.match.url", "@");
 
-pref("browser.search.param.Google.1.custom", "chrome://navigator/content/searchconfig.properties");
-pref("browser.search.param.Google.1.default", "chrome://navigator/content/searchconfig.properties");
-
 // Whether or not microsummary and generator updates are enabled.
 pref("browser.microsummary.enabled", true);
 pref("browser.microsummary.updateGenerators", true);
 
 pref("browser.history.grouping", "day");
 pref("browser.sessionhistory.max_entries", 50);
 
 // Whether history is enabled or not.
@@ -274,24 +296,16 @@ pref("browser.link.open_newwindow", 3);
 // 0: no restrictions - divert everything
 // 1: don't divert window.open at all
 // 2: don't divert window.open with features
 pref("browser.link.open_newwindow.restriction", 2);
 
 // Translation service
 pref("browser.translation.service", "chrome://navigator-region/locale/region.properties");
 pref("browser.translation.serviceDomain", "chrome://navigator-region/locale/region.properties");
-  
-// Smart Browsing prefs
-pref("browser.related.provider", "http://www-rl.netscape.com/wtgn?");
-pref("browser.related.disabledForDomains", "");
-pref("keyword.enabled", true);
-
-//Internet Search
-pref("browser.search.defaultenginename", "chrome://communicator-region/locale/region.properties");
 
 // 0 goes back
 // 1 act like pgup
 // 2 and other values, nothing
 pref("browser.backspace_action", 0);
 
 // Controls behavior of the "Add Exception" dialog launched from SSL error pages:
 // 0 - don't pre-populate anything.
--- a/suite/browser/jar.mn
+++ b/suite/browser/jar.mn
@@ -14,17 +14,16 @@ comm.jar:
    content/navigator/metadata.xul
    content/navigator/navigator.css
    content/navigator/navigator.js
    content/navigator/navigator.xul
    content/navigator/navigatorDD.js
    content/navigator/navigatorOverlay.xul
    content/navigator/nsBrowserContentListener.js
    content/navigator/nsBrowserStatusHandler.js
-   content/navigator/searchconfig.properties
    content/navigator/sessionHistoryUI.js
    content/navigator/tabbrowser.xml
    content/navigator/urlbarBindings.xml
 #ifdef XP_MACOSX
    content/navigator/platformNavigationBindings.xul                 (mac/platformNavigationBindings.xul)
    content/navigator/platformMailOverlay.xul                        (mac/platformMailOverlay.xul)
 #else
 #ifdef XP_WIN32
--- a/suite/browser/navigator.js
+++ b/suite/browser/navigator.js
@@ -51,17 +51,16 @@ Components.utils.import("resource://gre/
 });
 
 const REMOTESERVICE_CONTRACTID = "@mozilla.org/toolkit/remote-service;1";
 const XUL_NAMESPACE = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 var gURLBar = null;
 var gProxyButton = null;
 var gProxyFavIcon = null;
 var gProxyDeck = null;
-var gSearchService = null;
 var gNavigatorBundle;
 var gBrandBundle;
 var gNavigatorRegionBundle;
 var gLastValidURLStr = "";
 var gLastValidURL = null;
 var gClickSelectsAll = false;
 var gClickAtEndSelects = false;
 var gIgnoreFocus = false;
@@ -199,17 +198,16 @@ function removePopupPermListener(observe
 * We can avoid adding multiple load event listeners and save some time by adding
 * one listener that calls all real handlers.
 */
 
 function pageShowEventHandlers(event)
 {
   // Filter out events that are not about the document load we are interested in
   if (event.originalTarget == content.document) {
-    UpdateInternetSearchResults(event);
     checkForDirectoryListing();
     postURLToNativeWidget();
   }
 }
 
 /**
  * Determine whether or not the content area is displaying a page with frames,
  * and if so, toggle the display of the 'save frame as' menu item.
@@ -243,29 +241,16 @@ function updateHomeButtonTooltip()
 
   for (var i in homePage) {
     var label = document.createElementNS(XUL_NAMESPACE, "label");
     label.setAttribute("value", homePage[i]);
     tooltip.appendChild(label);
   }
 }
 
-function UpdateInternetSearchResults(event)
-{
-  var url = getWebNavigation().currentURI.spec;
-  if (url && isSearchPanelOpen())
-  {
-    if (!gSearchService)
-      gSearchService = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
-                                 .getService(Components.interfaces.nsIInternetSearchService);
-
-    gSearchService.FindInternetSearchResults(url);
-  }
-}
-
 function getBrowser()
 {
   if (!gBrowser)
     gBrowser = document.getElementById("content");
   return gBrowser;
 }
 
 function getHomePage()
@@ -388,17 +373,17 @@ function HandleAppCommandEvent(aEvent)
       break;
     case "Reload":
       BrowserReloadSkipCache();
       break;
     case "Stop":
       BrowserStop();
       break;
     case "Search":
-      BrowserSearchInternet();
+      BrowserSearch.webSearch();
       break;
     case "Bookmarks":
       toBookmarksManager();
       break;
     case "Home":
       BrowserHome(null);
       break;
     default:
@@ -955,250 +940,202 @@ var gBookmarkAllTabsHandler = {
   },
 
   // nsIDOMEventListener
   handleEvent: function(aEvent) {
     this._updateCommandState(aEvent.type == "TabClose");
   }
 };
 
-function readRDFString(aDS,aRes,aProp)
-{
-  var n = aDS.GetTarget(aRes, aProp, true);
-  return n ? n.QueryInterface(Components.interfaces.nsIRDFLiteral).Value : "";
-}
+const BrowserSearch = {
+  addEngine: function(engine, targetDoc) {
+    Services.console.logStringMessage("BrowserSearch.addEngine will be implemented in bug 401417.");
+  },
+
+  /**
+   * Update the browser UI to show whether or not additional engines are
+   * available when a page is loaded or the user switches tabs to a page that
+   * has search engines.
+   */
+  updateSearchButton: function() {
+    Services.console.logStringMessage("BrowserSearch.updateSearchButton will be implemented in bug 401417.");
+  },
+
+  /**
+   * Gives focus to the search bar, if it is present on the toolbar, or to the
+   * search sidebar, if it is open, or loads the default engine's search form
+   * otherwise. For Mac, opens a new window or focuses an existing window, if
+   * necessary.
+   */
+  webSearch: function BrowserSearch_webSearch() {
+    if (/Mac/.test(navigator.platform)) {
+      if (window.location.href != getBrowserURL()) {
+        var win = getTopWin();
+        if (win) {
+          // If there's an open browser window, it should handle this command
+          win.focus();
+          win.BrowserSearch.webSearch();
+        } else {
+          // If there are no open browser windows, open a new one
+
+          // This needs to be in a timeout so that we don't end up refocused
+          // in the url bar
+          function webSearchCallback() {
+            setTimeout(BrowserSearch.webSearch, 0);
+          }
 
-function ensureDefaultEnginePrefs(aRDF,aDS) 
-{
-  var defaultName = Services.prefs.getComplexValue("browser.search.defaultenginename",
-                                                   nsIPrefLocalizedString).data;
-  var kNC_Root = aRDF.GetResource("NC:SearchEngineRoot");
-  var kNC_child = aRDF.GetResource("http://home.netscape.com/NC-rdf#child");
-  var kNC_Name = aRDF.GetResource("http://home.netscape.com/NC-rdf#Name");
+          win = window.openDialog(getBrowserURL(), "_blank",
+                                  "chrome,all,dialog=no", "about:blank");
+          win.addEventListener("load", webSearchCallback, false);
+        }
+        return;
+      }
+    }
+
+    if (isElementVisible(this.searchBar)) {
+      searchBar.select();
+      searchBar.focus();
+    } else if (isElementVisible(this.searchSidebar)) {
+      searchSidebar.focus();
+    } else {
+      loadURI(Services.search.defaultEngine.searchForm);
+    }
+  },
 
-  var arcs = aDS.GetTargets(kNC_Root, kNC_child, true);
-  while (arcs.hasMoreElements()) {
-    var engineRes = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
-    var name = readRDFString(aDS, engineRes, kNC_Name);
-    if (name == defaultName)
-      mPrefs.setCharPref("browser.search.defaultengine", engineRes.Value);
-  }
-}
+  /**
+   * Loads a search results page, given a set of search terms. Uses the current
+   * engine if the search bar is visible, or the default engine otherwise.
+   *
+   * @param searchText
+   *        The search terms to use for the search.
+   *
+   * @param useNewTab
+   *        Boolean indicating whether or not the search should load in a new
+   *        tab.
+   */
+  loadSearch: function BrowserSearch_search(searchText, useNewTab) {
+    var engine;
+
+    // If the search bar is visible, use the current engine, otherwise, fall
+    // back to the default engine.
+    if ((this.searchBar && isElementVisible(this.searchBar)) ||
+        (this.searchSidebar && isElementVisible(this.searchSidebar)))
+      engine = Services.search.currentEngine;
+    else
+      engine = Services.search.defaultEngine;
+
+    var submission = engine.getSubmission(searchText); // HTML response
+
+    // getSubmission can return null if the engine doesn't have a URL
+    // with a text/html response type.  This is unlikely (since
+    // SearchService._addEngineToStore() should fail for such an engine),
+    // but let's be on the safe side.
+    if (!submission)
+      return;
 
-function ensureSearchPref()
-{
-  var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
-                      .getService(Components.interfaces.nsIRDFService);
-  var ds = rdf.GetDataSource("rdf:internetsearch");
-  var kNC_Name = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
-  var defaultEngine;
-  try {
-    defaultEngine = Services.prefs.getCharPref("browser.search.defaultengine");
-  } catch(ex) {
-    ensureDefaultEnginePrefs(rdf, ds);
-    defaultEngine = Services.prefs.getCharPref("browser.search.defaultengine");
+    if (useNewTab) {
+      gBrowser.loadOneTab(submission.uri.spec,
+                          { postData: submission.postData,
+                            relatedToCurrent: true,
+                            inBackground: false });
+    } else
+      loadURI(submission.uri.spec, null, submission.postData, false);
+
+    // should we try and open up the sidebar to show the "Search Results" panel?
+    var autoOpenSidebar = false;
+    try {
+      autoOpenSidebar = Services.prefs.getBoolPref("browser.search.opensidebarsearchpanel");
+    } catch (e) {}
+    if (autoOpenSidebar)
+      this.revealSidebar();
+  },
+
+  /**
+   * Returns the search bar element if it is present in the toolbar, null otherwise.
+   */
+  get searchBar() {
+    return document.getElementById("searchbar");
+  },
+
+  /**
+   * Returns the search sidebar element if it is present in the toolbar, null otherwise.
+   */
+  get searchSidebar() {
+    return document.getElementById("urn:sidebar:panel:search");
+  },
+
+  /**
+   * Reveal the search sidebar panel.
+   */
+  revealSidebar: function BrowserSearch_revealSidebar() {
+    // first lets check if the search panel will be shown at all
+    // by checking the sidebar datasource to see if there is an entry
+    // for the search panel, and if it is excluded for navigator or not
+
+    var searchPanelExists = false;
+
+    var myPanel = document.getElementById("urn:sidebar:panel:search");
+    if (myPanel) {
+      var panel = sidebarObj.panels.get_panel_from_header_node(myPanel);
+      searchPanelExists = !panel.is_excluded();
+
+    } else if (sidebarObj.never_built) {
+      // XXXsearch: in theory, this should work when the sidebar isn't loaded,
+      //            in practice, it fails as sidebarObj.datasource_uri isn't defined
+      try {
+        var datasource = RDF.GetDataSourceBlocking(sidebarObj.datasource_uri);
+        var aboutValue = RDF.GetResource("urn:sidebar:panel:search");
+
+        // check if the panel is even in the list by checking for its content
+        var contentProp = RDF.GetResource("http://home.netscape.com/NC-rdf#content");
+        var content = datasource.GetTarget(aboutValue, contentProp, true);
+
+        if (content instanceof Components.interfaces.nsIRDFLiteral) {
+          // the search panel entry exists, now check if it is excluded
+          // for navigator
+          var excludeProp = RDF.GetResource("http://home.netscape.com/NC-rdf#exclude");
+          var exclude = datasource.GetTarget(aboutValue, excludeProp, true);
+
+          if (exclude instanceof Components.interfaces.nsIRDFLiteral) {
+            searchPanelExists = (exclude.Value.indexOf("navigator:browser") < 0);
+          } else {
+            // panel exists and no exclude set
+            searchPanelExists = true;
+          }
+        }
+      } catch (e) {
+        searchPanelExists = false;
+      }
+    }
+
+    if (searchPanelExists) {
+      // make sure the sidebar is open, else SidebarSelectPanel() will fail
+      if (sidebar_is_hidden())
+        SidebarShowHide();
+
+      if (sidebar_is_collapsed())
+        SidebarExpandCollapse();
+
+      var searchPanel = document.getElementById("urn:sidebar:panel:search");
+      if (searchPanel)
+        SidebarSelectPanel(searchPanel, true, true); // lives in sidebarOverlay.js
+    }
   }
 }
 
-function getSearchUrl(attr)
-{
-  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 defaultEngine = Services.prefs.getCharPref("browser.search.defaultengine");
-  var engineRes = rdf.GetResource(defaultEngine);
-  var prop = "http://home.netscape.com/NC-rdf#" + attr;
-  var kNC_attr = rdf.GetResource(prop);
-  var searchURL = readRDFString(ds, engineRes, kNC_attr);
-  return searchURL;
-}
-
 function QualifySearchTerm()
 {
   // If the text in the URL bar is the same as the currently loaded
   // page's URL then treat this as an empty search term.  This way
   // the user is taken to the search page where s/he can enter a term.
   if (gBrowser.userTypedValue !== null)
     return gURLBar.value;
   return "";
 }
 
-function OpenSearch(tabName, searchStr, newWindowOrTabFlag, reverseBackgroundPref)
-{
-  //This function needs to be split up someday.
-
-  var autoOpenSearchPanel = false;
-  var defaultSearchURL = null;
-  var fallbackDefaultSearchURL = gNavigatorRegionBundle.getString("fallbackDefaultSearchURL");
-  ensureSearchPref()
-  //Check to see if search string contains "://" or "ftp." or white space.
-  //If it does treat as url and match for pattern
-
-  var urlmatch= /(:\/\/|^ftp\.)[^ \S]+$/ 
-  var forceAsURL = urlmatch.test(searchStr);
-
-  try {
-    autoOpenSearchPanel = Services.prefs.getBoolPref("browser.search.opensidebarsearchpanel");
-    defaultSearchURL = Services.prefs.getComplexValue("browser.search.defaulturl",
-                                                      nsIPrefLocalizedString).data;
-  } catch (ex) {
-  }
-
-  // Fallback to a default url (one that we can get sidebar search results for)
-  if (!defaultSearchURL)
-    defaultSearchURL = fallbackDefaultSearchURL;
-
-  if (!searchStr) {
-    BrowserSearchInternet();
-  } else {
-
-    //Check to see if location bar field is a url
-    //If it is a url go to URL.  A Url is "://" or "." as commented above
-    //Otherwise search on entry
-    if (forceAsURL) {
-       BrowserLoadURL()
-    } else {
-      if (searchStr) {
-        var escapedSearchStr = encodeURIComponent(searchStr);
-        defaultSearchURL += escapedSearchStr;
-        var searchDS = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
-                                 .getService(Components.interfaces.nsIInternetSearchService);
-
-        searchDS.RememberLastSearchText(escapedSearchStr);
-        try {
-          var searchEngineURI = Services.prefs.getCharPref("browser.search.defaultengine");
-          if (searchEngineURI) {
-            var searchURL = getSearchUrl("actionButton");
-            if (searchURL) {
-              defaultSearchURL = searchURL + escapedSearchStr; 
-            } else {
-              searchURL = searchDS.GetInternetSearchURL(searchEngineURI, escapedSearchStr, 0, 0, {value:0});
-              if (searchURL)
-                defaultSearchURL = searchURL;
-            }
-          }
-        } catch (ex) {
-        }
-
-        if (!newWindowOrTabFlag)
-          loadURI(defaultSearchURL);
-        else if (!Services.prefs.getBoolPref("browser.search.opentabforcontextsearch"))
-          window.open(defaultSearchURL, "_blank");
-        else {
-          var newTab = gBrowser.addTab(defaultSearchURL);
-          var loadInBackground = Services.prefs.getBoolPref("browser.tabs.loadInBackground");
-          if (reverseBackgroundPref)
-            loadInBackground = !loadInBackground;
-          if (!loadInBackground)
-            gBrowser.selectedTab = newTab;
-        }
-      }
-    }
-  }
-
-  // should we try and open up the sidebar to show the "Search Results" panel?
-  if (autoOpenSearchPanel)
-    RevealSearchPanel();
-}
-
-function RevealSearchPanel()
-{
-  // first lets check if the search panel will be shown at all
-  // by checking the sidebar datasource to see if there is an entry
-  // for the search panel, and if it is excluded for navigator or not
-  
-  var searchPanelExists = false;
-  
-  if (document.getElementById("urn:sidebar:panel:search")) {
-    var myPanel = document.getElementById("urn:sidebar:panel:search");
-    var panel = sidebarObj.panels.get_panel_from_header_node(myPanel);
-
-    searchPanelExists = !panel.is_excluded();
-  } else if (sidebarObj.never_built) {
-
-    try{
-      var datasource = RDF.GetDataSourceBlocking(sidebarObj.datasource_uri);
-      var aboutValue = RDF.GetResource("urn:sidebar:panel:search");
-
-      // check if the panel is even in the list by checking for its content
-      var contentProp = RDF.GetResource("http://home.netscape.com/NC-rdf#content");
-      var content = datasource.GetTarget(aboutValue, contentProp, true);
-     
-      if (content instanceof Components.interfaces.nsIRDFLiteral){
-        // the search panel entry exists, now check if it is excluded
-        // for navigator
-        var excludeProp = RDF.GetResource("http://home.netscape.com/NC-rdf#exclude");
-        var exclude = datasource.GetTarget(aboutValue, excludeProp, true);
-
-        if (exclude instanceof Components.interfaces.nsIRDFLiteral) {
-          searchPanelExists = (exclude.Value.indexOf("navigator:browser") < 0);
-        } else {
-          // panel exists and no exclude set
-          searchPanelExists = true;
-        }
-      }
-    } catch(e){
-      searchPanelExists = false;
-    }
-  }
-
-  if (searchPanelExists) {
-    // make sure the sidebar is open, else SidebarSelectPanel() will fail
-    if (sidebar_is_hidden())
-      SidebarShowHide();
-  
-    if (sidebar_is_collapsed())
-      SidebarExpandCollapse();
-
-    var searchPanel = document.getElementById("urn:sidebar:panel:search");
-    if (searchPanel)
-      SidebarSelectPanel(searchPanel, true, true); // lives in sidebarOverlay.js      
-  }
-}
-
-function isSearchPanelOpen()
-{
-  return ( !sidebar_is_hidden()    && 
-           !sidebar_is_collapsed() && 
-           SidebarGetLastSelectedPanel() == "urn:sidebar:panel:search"
-         );
-}
-
-function BrowserSearchInternet()
-{
-  try {
-    var searchEngineURI = Services.prefs.getCharPref("browser.search.defaultengine");
-    if (searchEngineURI) {
-      var searchRoot = getSearchUrl("searchForm");
-      if (searchRoot) {
-        openTopWin(searchRoot);
-        return;
-      } else {
-        // Get a search URL and guess that the front page of the site has a search form.
-        var searchDS = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
-                                 .getService(Components.interfaces.nsIInternetSearchService);
-        var searchURL = searchDS.GetInternetSearchURL(searchEngineURI, "ABC", 0, 0, {value:0});
-        if (searchURL) {
-          searchRoot = searchURL.match(/^[^:]+:\/\/[^?/]+/i);
-          if (searchRoot) {
-            openTopWin(searchRoot + "/");
-            return;
-          }
-        }
-      }
-    }
-  } catch (ex) {
-  }
-
-  // Fallback if the stuff above fails: use the hard-coded search engine
-  openTopWin(gNavigatorRegionBundle.getString("otherSearchURL"));
-}
-
-
 //Note: BrowserNewEditorWindow() was moved to globalOverlay.xul and renamed to NewEditorWindow()
 
 function BrowserOpenWindow()
 {
   //opens a window where users can select a web location to open
   var params = { browser: window, action: null, url: "" };
   openDialog("chrome://communicator/content/openLocation.xul", "_blank", "chrome,modal,titlebar", params);
   var postData = { };
--- a/suite/browser/navigator.xul
+++ b/suite/browser/navigator.xul
@@ -350,17 +350,17 @@
 
       <toolbaritem id="search-button-container"
                    class="nav-bar-class"
                    title="&searchButton.label;">
         <button id="search-button"
                 class="button-toolbar chromeclass-location"
                 label="&searchButton.label;"
                 tooltiptext="&searchButton.tooltip;"
-                oncommand="OpenSearch('internet', QualifySearchTerm());"
+                oncommand="BrowserSearch.loadSearch(QualifySearchTerm());"
                 ondragover="nsDragAndDrop.dragOver(event, searchButtonObserver);"
                 ondragdrop="nsDragAndDrop.drop(event, searchButtonObserver);"
                 ondragexit="nsDragAndDrop.dragExit(event, searchButtonObserver);"/>
       </toolbaritem>
 
       <toolbarbutton id="print-button" type="menu-button"
                      class="toolbarbutton-1 chromeclass-toolbar-additional"
                      label="&printButton.label;"
--- a/suite/browser/navigatorDD.js
+++ b/suite/browser/navigatorDD.js
@@ -199,17 +199,17 @@ var searchButtonObserver = {
     {
       aEvent.target.removeAttribute("dragover");
     },
   onDrop: function (aEvent, aXferData, aDragSession)
     {
       var xferData = aXferData.data.split("\n");
       var uri = xferData[1] ? xferData[1] : xferData[0];
       if (uri)
-        OpenSearch('internet', uri);
+        BrowserSearch.loadSearch(uri);
     },
   getSupportedFlavours: function ()
     {
       var flavourSet = new FlavourSet();
       flavourSet.appendFlavour("application/x-moz-file", "nsIFile");
       flavourSet.appendFlavour("text/x-moz-url");
       flavourSet.appendFlavour("text/unicode");
       return flavourSet;
--- a/suite/browser/public/Makefile.in
+++ b/suite/browser/public/Makefile.in
@@ -40,18 +40,14 @@ topsrcdir	= @top_srcdir@
 srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= suitebrowser
 XPIDL_MODULE	= suitebrowser
 
-XPIDLSRCS = \
-	nsISearchService.idl \
-	$(NULL)
-
 ifeq ($(OS_ARCH),WINNT)
 XPIDLSRCS += nsIUrlWidget.idl
 endif
 
 include $(topsrcdir)/config/rules.mk
 
deleted file mode 100755
--- a/suite/browser/public/nsISearchService.idl
+++ /dev/null
@@ -1,129 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Robert John Churchill      <rjc@netscape.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
-
-  The Browser Search service
-
-*/
-
-#include "nsISupports.idl"
-#include "nsIRDFDataSource.idl"
-
-interface  nsIUnicodeDecoder;
-
-[scriptable, uuid(1222e6f0-a5e3-11d2-8b7c-00805f8a7db6)]
-interface nsILocalSearchService : nsISupports
-{
-};
-
-[scriptable, uuid(a0d28a88-702e-49bd-bee2-929562688ae1)]
-interface nsIInternetSearchService : nsISupports
-{
-  // constants set in the whichButtons out param of GetInternetSearchURL() 
-  const unsigned short kHaveNext = 1;
-  const unsigned short kHavePrev = 2;
-
-  wstring   GetInternetSearchURL(in string searchEngineURI, in wstring searchStr, in short direction, in unsigned short pageNumber, out unsigned short whichButtons);
-  void      RememberLastSearchText(in wstring escapedSearchStr);
-  boolean      FindInternetSearchResults(in string url);
-  void      Stop();
-  void      ClearResults(in boolean flushLastSearchRef);
-  void      ClearResultSearchSites();
-  nsIRDFDataSource  GetCategoryDataSource();
-  void      AddSearchEngine(in string engineURL, in string iconURL,
-                         in wstring suggestedTitle, in wstring suggestedCategory);
-};
-
-[noscript, uuid(7b171610-80ca-4d33-b16c-4186cd7b7e73)]
-interface nsIInternetSearchContext : nsISupports
-{
-  const unsigned long WEB_SEARCH_CONTEXT      = 1;
-
-  // The download of the .src file for a *new* engine.
-  const unsigned long ENGINE_DOWNLOAD_NEW_CONTEXT = 2;
-
-  // The download of the icon file for a new engine.
-  const unsigned long ICON_DOWNLOAD_NEW_CONTEXT = 3;
-
-  // The head request to see if we need to update the engine.
-  const unsigned long ENGINE_UPDATE_HEAD_CONTEXT = 4;
-
-  // The download of the .src file for an engine update.
-  const unsigned long ENGINE_DOWNLOAD_UPDATE_CONTEXT = 5;
-
-  // The download of the icon file for an engine update.
-  const unsigned long ICON_DOWNLOAD_UPDATE_CONTEXT = 6;
-
-  // attributes
-  readonly attribute unsigned long ContextType;
-
-  // methods
-  nsIUnicodeDecoder  GetUnicodeDecoder();
-  nsIRDFResource    GetParent();
-  nsIRDFResource    GetEngine();
-  void      GetHintConst([shared] out wstring buffer);
-  void      AppendBytes(in string buffer, in long numBytes);
-  void      AppendUnicodeBytes(in wstring buffer, in long numUniBytes);
-  long      GetBufferLength();
-  void      GetBufferConst([shared] out wstring buffer);
-  void      Truncate();
-};
-
-%{C++
-
-#define NS_IINTERNETSEARCHDATASOURCECALLBACK_IID \
-{ 0x88774583, 0x1edd, 0x11d3, { 0x98, 0x20, 0xbf, 0x1b, 0xe7, 0x7e, 0x61, 0xc4 } }
-
-#define NS_IINTERNETSEARCHDATAOURCE_IID \
-{ 0x6bd1d803, 0x1c67, 0x11d3, { 0x98, 0x20, 0xed, 0x1b, 0x35, 0x7e, 0xb3, 0xc4 } }
-
-#define NS_ILOCALSEARCHDATASOURCE_IID \
-{ 0x1222e6f0, 0xa5e3, 0x11d2, { 0x8b, 0x7c, 0x00, 0x80, 0x5f, 0x8a, 0x7d, 0xb6 } }
-
-#define NS_LOCALSEARCH_SERVICE_CONTRACTID \
-    "@mozilla.org/browser/localsearch-service;1"
-#define NS_LOCALSEARCH_DATASOURCE_CONTRACTID \
-    "@mozilla.org/rdf/datasource;1?name=localsearch"
-
-#define NS_INTERNETSEARCH_SERVICE_CONTRACTID \
-    "@mozilla.org/browser/internetsearch-service;1"
-#define NS_INTERNETSEARCH_DATASOURCE_CONTRACTID \
-    "@mozilla.org/rdf/datasource;1?name=internetsearch"
-
-%}
deleted file mode 100644
--- a/suite/browser/searchconfig.properties
+++ /dev/null
@@ -1,5 +0,0 @@
-# Do NOT localize or otherwise change these values
-browser.search.param.Google.1.custom=client=mozilla
-browser.search.param.Google.1.default=client=mozilla
-browser.search.param.Google.release=rls=%S:%S:unofficial
-
--- a/suite/browser/src/Makefile.in
+++ b/suite/browser/src/Makefile.in
@@ -41,22 +41,16 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
 
 MODULE		= suitebrowser
 LIBRARY_NAME	= suitebrowser_s
 META_COMPONENT  = suite
 
-
-CPPSRCS = \
-	nsInternetSearchService.cpp \
-	nsLocalSearchService.cpp \
-	$(NULL)
-
 ifeq ($(OS_ARCH),WINNT)
 CPPSRCS += nsUrlWidget.cpp
 endif
 
 FORCE_STATIC_LIB = 1
 FORCE_USE_PIC=1
 
 include $(topsrcdir)/config/rules.mk
deleted file mode 100755
--- a/suite/browser/src/nsInternetSearchService.cpp
+++ /dev/null
@@ -1,6121 +0,0 @@
-/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Robert John Churchill      <rjc@netscape.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
-  Implementation for an internet search RDF data store.
- */
-
-#include "nsInternetSearchService.h"
-
-#include "nscore.h"
-#include "nsIEnumerator.h"
-#include "nsIRDFObserver.h"
-#include "nsIRDFContainer.h"
-#include "nsIRDFContainerUtils.h"
-#include "nsIServiceManager.h"
-#include "nsVoidArray.h"  // XXX introduces dependency on raptorbase
-#include "plhash.h"
-#include "plstr.h"
-#include "prmem.h"
-#include "prprf.h"
-#include "prio.h"
-#include "prlog.h"
-#include "prdtoa.h"
-#include "rdf.h"
-#include "nsIDirectoryService.h"
-#include "nsDirectoryServiceDefs.h"
-#include "nsDirectoryServiceUtils.h"
-#include "nsAppDirectoryServiceDefs.h"
-#include "nsCOMArray.h"
-#include "nsCRTGlue.h"
-#include "nsEnumeratorUtils.h"
-#include "nsIRDFRemoteDataSource.h"
-#include "nsICharsetConverterManager.h"
-#include "nsICharsetAlias.h"
-#include "nsITextToSubURI.h"
-#include "nsNetUtil.h"
-#include "nsINetUtil.h"
-#include "nsIChannel.h"
-#include "nsIFileChannel.h"
-#include "nsIHttpChannel.h"
-#include "nsIUploadChannel.h"
-#include "nsIInputStream.h"
-#include "nsIStringBundle.h"
-#include "nsIObserverService.h"
-#include "nsIURL.h"
-#include "nsILocalFile.h"
-#include "nsUnicharUtils.h"
-#include "nsIPrefLocalizedString.h"
-#include "nsIPrefBranch2.h"
-#include "nsIPrefService.h"
-
-#ifdef  XP_WIN
-#include "windef.h"
-#include "winbase.h"
-#endif
-
-#ifdef  DEBUG
-// #define  DEBUG_SEARCH_OUTPUT 1
-// #define  DEBUG_SEARCH_UPDATES  1
-#endif
-
-#define MAX_SEARCH_RESULTS_ALLOWED  100
-
-#define POSTHEADER_PREFIX "Content-type: application/x-www-form-urlencoded\r\nContent-Length: "
-#define POSTHEADER_SUFFIX "\r\n\r\n"
-#define SEARCH_PROPERTIES "chrome://communicator/locale/search/search-panel.properties"
-#define SEARCHCONFIG_PROPERTIES "chrome://branding/content/searchconfig.properties"
-#define INTL_PROPERTIES "chrome://global/locale/intl.properties"
-
-static NS_DEFINE_CID(kTextToSubURICID, NS_TEXTTOSUBURI_CID);
-
-static const char kURINC_SearchEngineRoot[]                   = "NC:SearchEngineRoot";
-static const char kURINC_SearchResultsSitesRoot[]             = "NC:SearchResultsSitesRoot";
-static const char kURINC_LastSearchRoot[]                     = "NC:LastSearchRoot";
-static const char kURINC_SearchCategoryRoot[]                 = "NC:SearchCategoryRoot";
-static const char kURINC_SearchCategoryPrefix[]               = "NC:SearchCategory?category=";
-static const char kURINC_SearchCategoryEnginePrefix[]         = "NC:SearchCategory?engine=";
-static const char kURINC_SearchCategoryEngineBasenamePrefix[] = "NC:SearchCategory?engine=urn:search:engine:";
- 
-static const char kURINC_FilterSearchURLsRoot[]       = "NC:FilterSearchURLsRoot";
-static const char kURINC_FilterSearchSitesRoot[]      = "NC:FilterSearchSitesRoot";
-static const char kSearchCommand[]                    = "http://home.netscape.com/NC-rdf#command?";
-
-// helper routines to ease the transition to frozen linkage strings (nsStringAPI.h)
-
-/// @see nsReadableUtils.h
-PRBool RFindInReadable(const nsAString& aPattern,
-                       const PRUnichar **start,
-                       const PRUnichar **end,
-                       nsAString::ComparatorFunc c = nsAString::DefaultComparator)
-{
-  NS_PRECONDITION(start, "invalid pointer");
-  NS_PRECONDITION(end, "invalid pointer");
-  NS_PRECONDITION(end >= start, "searching in negative length string");
-  if (!start || !end || !(end >= start))
-  {
-    // bad input
-    return PR_FALSE;
-  }
-  
-  if (aPattern.IsEmpty())
-  {
-    NS_WARNING("searching for empty pattern");
-    *start = *end;
-    return PR_TRUE;
-  }
-
-  // dumb algorithm - just check from back to front.
-  const PRUnichar *current;
-  PRUint32 len = aPattern.Length();
-  for (current = *end - len; current >= *start; --current)
-  {
-    if (!c(current, aPattern.BeginReading(), len))
-    {
-      *start = current;
-      *end = current + len;
-      return PR_TRUE;
-    }
-  }
-  // nothing found
-  return PR_FALSE;
-}
-
-
-
-/// @see nsString::FindCharInSet
-PRInt32 nsString_FindCharInSet(const nsAString& aString, const char *aPattern, PRInt32 aOffset = 0)
-{
-  const PRUnichar *begin, *end;
-  aString.BeginReading(&begin, &end);
-  for (const PRUnichar *current = begin + aOffset; current < end; ++current)
-  {
-    for (const char *pattern = aPattern; *pattern; ++pattern)
-    {
-      if (NS_UNLIKELY(*current == PRUnichar(*pattern)))
-      {
-        return current - begin;
-      }
-    }
-  }
-  return -1;
-}
-
-
-
-class InternetSearchContext : public nsIInternetSearchContext
-{
-public:
-      InternetSearchContext(PRUint32 contextType, nsIRDFResource *aParent, nsIRDFResource *aEngine,
-        nsIUnicodeDecoder *aUnicodeDecoder, const PRUnichar *hint);
-  virtual   ~InternetSearchContext(void);
-  NS_METHOD Init();
-
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIINTERNETSEARCHCONTEXT
-
-private:
-  PRUint32      mContextType;
-  nsCOMPtr<nsIRDFResource>  mParent;
-  nsCOMPtr<nsIRDFResource>  mEngine;
-  nsCOMPtr<nsIUnicodeDecoder> mUnicodeDecoder;
-  nsString      mBuffer;
-  nsString      mHint;
-};
-
-
-
-InternetSearchContext::~InternetSearchContext(void)
-{
-}
-
-
-
-InternetSearchContext::InternetSearchContext(PRUint32 contextType, nsIRDFResource *aParent, nsIRDFResource *aEngine,
-        nsIUnicodeDecoder *aUnicodeDecoder, const PRUnichar *hint)
-  : mContextType(contextType), mParent(aParent), mEngine(aEngine), mUnicodeDecoder(aUnicodeDecoder), mHint(hint)
-{
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::Init()
-{
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::GetContextType(PRUint32 *aContextType)
-{
-  *aContextType = mContextType;
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::GetUnicodeDecoder(nsIUnicodeDecoder **decoder)
-{
-  *decoder = mUnicodeDecoder;
-  NS_IF_ADDREF(*decoder);
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::GetEngine(nsIRDFResource **node)
-{
-  *node = mEngine;
-  NS_IF_ADDREF(*node);
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::GetHintConst(const PRUnichar **hint)
-{
-  *hint = mHint.get();
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::GetParent(nsIRDFResource **node)
-{
-  *node = mParent;
-  NS_IF_ADDREF(*node);
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::AppendBytes(const char *buffer, PRInt32 numBytes)
-{
-  mBuffer.Append(NS_ConvertASCIItoUTF16(Substring(buffer, buffer + numBytes)));
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::AppendUnicodeBytes(const PRUnichar *buffer, PRInt32 numUniBytes)
-{
-  mBuffer.Append(buffer, numUniBytes);
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::GetBufferConst(const PRUnichar **buffer)
-{
-  *buffer = mBuffer.get();
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::GetBufferLength(PRInt32 *bufferLen)
-{
-  *bufferLen = mBuffer.Length();
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchContext::Truncate()
-{
-  mBuffer.Truncate();
-  return(NS_OK);
-}
-
-
-
-NS_IMPL_THREADSAFE_ISUPPORTS1(InternetSearchContext, nsIInternetSearchContext)
-
-
-
-nsresult
-NS_NewInternetSearchContext(PRUint32 contextType, nsIRDFResource *aParent, nsIRDFResource *aEngine,
-          nsIUnicodeDecoder *aUnicodeDecoder, const PRUnichar *hint, nsIInternetSearchContext **aResult)
-{
-   InternetSearchContext *result =
-     new InternetSearchContext(contextType, aParent, aEngine, aUnicodeDecoder, hint);
-
-   if (! result)
-     return NS_ERROR_OUT_OF_MEMORY;
-
-   nsresult rv = result->Init();
-   if (NS_FAILED(rv)) {
-     delete result;
-     return rv;
-   }
-
-   NS_ADDREF(result);
-   *aResult = result;
-   return NS_OK;
-}
-
-
-
-
-
-static const char   kEngineProtocol[] = "engine://";
-static const char   kSearchProtocol[] = "internetsearch:";
-
-#ifdef  DEBUG_SEARCH_UPDATES
-#define SEARCH_UPDATE_TIMEOUT 10000   // fire every 10 seconds
-#else
-#define SEARCH_UPDATE_TIMEOUT 60000   // fire every 60 seconds
-#endif
-
-
-InternetSearchDataSource::InternetSearchDataSource(void) :
-  mBrowserSearchMode(0),
-  mEngineListBuilt(PR_FALSE),
-  mRDFService(do_GetService(NS_RDF_CONTRACTID "/rdf-service;1")),
-  mRDFC(do_GetService(NS_RDF_CONTRACTID "/container-utils;1")),
-  busySchedule(PR_FALSE)
-{
-  NS_ASSERTION(mRDFService, "No RDF Service");
-  NS_ASSERTION(mRDFC, "No RDF Container Utils");
-  
-  mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_SearchEngineRoot),
-                           getter_AddRefs(mNC_SearchEngineRoot));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_LastSearchRoot),
-                           getter_AddRefs(mNC_LastSearchRoot));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_SearchResultsSitesRoot),
-                           getter_AddRefs(mNC_SearchResultsSitesRoot));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_FilterSearchURLsRoot),
-                           getter_AddRefs(mNC_FilterSearchURLsRoot));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_FilterSearchSitesRoot),
-                           getter_AddRefs(mNC_FilterSearchSitesRoot));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(kURINC_SearchCategoryRoot),
-                           getter_AddRefs(mNC_SearchCategoryRoot));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "SearchMode"),
-                           getter_AddRefs(mNC_LastSearchMode));
- 
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "searchtype"),
-                           getter_AddRefs(mNC_SearchType));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "SearchResult"),
-                           getter_AddRefs(mNC_SearchResult));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "ref"),
-                           getter_AddRefs(mNC_Ref));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
-                           getter_AddRefs(mNC_Child));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "title"),
-                           getter_AddRefs(mNC_Title));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "data"),
-                           getter_AddRefs(mNC_Data));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"),
-                           getter_AddRefs(mNC_Name));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Description"),
-                           getter_AddRefs(mNC_Description));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Version"),
-                           getter_AddRefs(mNC_Version));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "actionButton"),
-                           getter_AddRefs(mNC_actionButton));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "actionBar"),
-                           getter_AddRefs(mNC_actionBar));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "searchForm"),
-                           getter_AddRefs(mNC_searchForm));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "LastText"),
-                           getter_AddRefs(mNC_LastText));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"),
-                           getter_AddRefs(mNC_URL));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"),
-                           getter_AddRefs(mRDF_InstanceOf));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"),
-                           getter_AddRefs(mRDF_type));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "loading"),
-                           getter_AddRefs(mNC_loading));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "HTML"),
-                           getter_AddRefs(mNC_HTML));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Icon"),
-                           getter_AddRefs(mNC_Icon));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "StatusIcon"),
-                           getter_AddRefs(mNC_StatusIcon));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Banner"),
-                           getter_AddRefs(mNC_Banner));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Site"),
-                           getter_AddRefs(mNC_Site));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Relevance"),
-                           getter_AddRefs(mNC_Relevance));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Relevance?sort=true"),
-                           getter_AddRefs(mNC_RelevanceSort));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Date"),
-                           getter_AddRefs(mNC_Date));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "PageRank"),
-                           getter_AddRefs(mNC_PageRank));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Engine"),
-                           getter_AddRefs(mNC_Engine));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Price"),
-                           getter_AddRefs(mNC_Price));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Price?sort=true"),
-                           getter_AddRefs(mNC_PriceSort));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Availability"),
-                           getter_AddRefs(mNC_Availability));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "BookmarkSeparator"),
-                           getter_AddRefs(mNC_BookmarkSeparator));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Update"),
-                           getter_AddRefs(mNC_Update));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "UpdateIcon"),
-                           getter_AddRefs(mNC_UpdateIcon));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "UpdateCheckDays"),
-                           getter_AddRefs(mNC_UpdateCheckDays));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastPingDate"),
-                           getter_AddRefs(mWEB_LastPingDate));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastPingModDate"),
-                           getter_AddRefs(mWEB_LastPingModDate));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(WEB_NAMESPACE_URI "LastPingContentLen"),
-                           getter_AddRefs(mWEB_LastPingContentLen));
- 
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=addtobookmarks"),
-                           getter_AddRefs(mNC_SearchCommand_AddToBookmarks));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=addquerytobookmarks"),
-                           getter_AddRefs(mNC_SearchCommand_AddQueryToBookmarks));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=filterresult"),
-                           getter_AddRefs(mNC_SearchCommand_FilterResult));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=filtersite"),
-                           getter_AddRefs(mNC_SearchCommand_FilterSite));
-  mRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "command?cmd=clearfilters"),
-                           getter_AddRefs(mNC_SearchCommand_ClearFilters));
- 
-  mRDFService->GetLiteral(NS_LITERAL_STRING("true").get(),
-                          getter_AddRefs(mTrueLiteral));
-
-  nsCOMPtr<nsIPrefBranch2> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-  if (prefs) {
-    prefs->AddObserver("browser.search.mode", this, PR_FALSE);
-    prefs->GetIntPref("browser.search.mode", &mBrowserSearchMode);
-  }
-}
-
-
-
-InternetSearchDataSource::~InternetSearchDataSource (void)
-{
-  if (mTimer) {
-    // be sure to cancel the timer, as it holds a
-    // weak reference back to InternetSearchDataSource
-    mTimer->Cancel();
-  }
-
-  if (mRDFService)
-    mRDFService->UnregisterDataSource(this);
-}
-
-
-
-nsresult
-InternetSearchDataSource::GetSearchEngineToPing(nsIRDFResource **theEngine, nsCString &updateURL)
-{
-  nsresult  rv = NS_OK;
-
-  *theEngine = nsnull;
-  updateURL.Truncate();
-
-  if (!mUpdateArray)  return(NS_OK);
-
-  PRUint32  numEngines = 0;
-  if (NS_FAILED(rv = mUpdateArray->Count(&numEngines))) return(rv);
-  if (numEngines < 1) return(NS_OK);
-
-  nsCOMPtr<nsIRDFResource> aRes (do_QueryElementAt(mUpdateArray, 0));
-
-  // note: important to remove element from array
-  mUpdateArray->RemoveElementAt(0);
-
-  if (aRes)
-  {
-    if (isSearchCategoryEngineURI(aRes))
-    {
-      nsCOMPtr<nsIRDFResource>  trueEngine;
-      rv = resolveSearchCategoryEngineURI(aRes, getter_AddRefs(trueEngine));
-      if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
-      if (!trueEngine)  return(NS_RDF_NO_VALUE);
-
-      aRes = trueEngine;
-    }
-
-    if (!aRes)  return(NS_OK);
-
-    *theEngine = aRes.get();
-    NS_ADDREF(*theEngine);
-
-    // get update URL
-    nsCOMPtr<nsIRDFNode>  aNode;
-    if (NS_SUCCEEDED(rv = mInner->GetTarget(aRes, mNC_Update, PR_TRUE, getter_AddRefs(aNode)))
-      && (rv != NS_RDF_NO_VALUE))
-    {
-      nsCOMPtr<nsIRDFLiteral> aLiteral (do_QueryInterface(aNode));
-      if (aLiteral)
-      {
-        const PRUnichar *updateUni = nsnull;
-        aLiteral->GetValueConst(&updateUni);
-        if (updateUni)
-        {
-          CopyUTF16toUTF8(nsDependentString(updateUni), updateURL);
-        }
-      }
-    }
-  }
-  return(rv);
-}
-
-
-
-void
-InternetSearchDataSource::FireTimer(nsITimer* aTimer, void* aClosure)
-{
-  InternetSearchDataSource *search = static_cast<InternetSearchDataSource *>(aClosure);
-  if (!search)  return;
-
-  if (!search->busySchedule)
-  {
-    nsresult      rv;
-    nsCOMPtr<nsIRDFResource>  searchURI;
-    nsCAutoString     updateURL;
-    if (NS_FAILED(rv = search->GetSearchEngineToPing(getter_AddRefs(searchURI), updateURL)))
-      return;
-    if (!searchURI)     return;
-    if (updateURL.IsEmpty())  return;
-
-    search->busyResource = searchURI;
-
-    nsCOMPtr<nsIInternetSearchContext>  engineContext;
-    if (NS_FAILED(rv = NS_NewInternetSearchContext(nsIInternetSearchContext::ENGINE_UPDATE_HEAD_CONTEXT,
-      nsnull, searchURI, nsnull, nsnull, getter_AddRefs(engineContext))))
-      return;
-    if (!engineContext) return;
-
-    nsCOMPtr<nsIURI>  uri;
-    if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(uri), updateURL.get())))  return;
-
-    nsCOMPtr<nsIChannel>  channel;
-    if (NS_FAILED(rv = NS_NewChannel(getter_AddRefs(channel), uri, nsnull)))  return;
-
-    channel->SetLoadFlags(nsIRequest::VALIDATE_ALWAYS);
-
-    nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(channel));
-    if (!httpChannel) return;
-
-    // rjc says: just check "HEAD" info for whether a search file has changed
-        httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("HEAD"));
-    if (NS_SUCCEEDED(rv = channel->AsyncOpen(search, engineContext)))
-    {
-      search->busySchedule = PR_TRUE;
-
-#ifdef  DEBUG_SEARCH_UPDATES
-      printf("    InternetSearchDataSource::FireTimer - Pinging '%s'\n", (char *)updateURL.get());
-#endif
-    }
-  }
-#ifdef  DEBUG_SEARCH_UPDATES
-else
-  {
-  printf("    InternetSearchDataSource::FireTimer - busy pinging.\n");
-  }
-#endif
-}
-
-
-
-PRBool
-InternetSearchDataSource::isEngineURI(nsIRDFResource *r)
-{
-  PRBool    isEngineURIFlag = PR_FALSE;
-  const char  *uri = nsnull;
-  
-  r->GetValueConst(&uri);
-  if ((uri) && (!strncmp(uri, kEngineProtocol, sizeof(kEngineProtocol) - 1)))
-  {
-    isEngineURIFlag = PR_TRUE;
-  }
-  return(isEngineURIFlag);
-}
-
-
-
-PRBool
-InternetSearchDataSource::isSearchURI(nsIRDFResource *r)
-{
-  PRBool    isSearchURIFlag = PR_FALSE;
-  const char  *uri = nsnull;
-  
-  r->GetValueConst(&uri);
-  if ((uri) && (!strncmp(uri, kSearchProtocol, sizeof(kSearchProtocol) - 1)))
-  {
-    isSearchURIFlag = PR_TRUE;
-  }
-  return(isSearchURIFlag);
-}
-
-
-
-PRBool
-InternetSearchDataSource::isSearchCategoryURI(nsIRDFResource *r)
-{
-  PRBool    isSearchCategoryURIFlag = PR_FALSE;
-  const char  *uri = nsnull;
-  
-  r->GetValueConst(&uri);
-  if ((uri) && (!strncmp(uri, kURINC_SearchCategoryPrefix, sizeof(kURINC_SearchCategoryPrefix) - 1)))
-  {
-    isSearchCategoryURIFlag = PR_TRUE;
-  }
-  return(isSearchCategoryURIFlag);
-}
-
-
-
-PRBool
-InternetSearchDataSource::isSearchCategoryEngineURI(nsIRDFResource *r)
-{
-  PRBool    isSearchCategoryEngineURIFlag = PR_FALSE;
-  const char  *uri = nsnull;
-  
-  r->GetValueConst(&uri);
-  if ((uri) && (!strncmp(uri, kURINC_SearchCategoryEnginePrefix, sizeof(kURINC_SearchCategoryEnginePrefix) - 1)))
-  {
-    isSearchCategoryEngineURIFlag = PR_TRUE;
-  }
-  return(isSearchCategoryEngineURIFlag);
-}
-
-
-
-PRBool
-InternetSearchDataSource::isSearchCommand(nsIRDFResource *r)
-{
-  PRBool    isSearchCommandFlag = PR_FALSE;
-  const char  *uri = nsnull;
-  
-  if (NS_SUCCEEDED(r->GetValueConst( &uri )) && (uri))
-  {
-    if (!strncmp(uri, kSearchCommand, sizeof(kSearchCommand) - 1))
-    {
-      isSearchCommandFlag = PR_TRUE;
-    }
-  }
-  return(isSearchCommandFlag);
-}
-
-
-
-nsresult
-InternetSearchDataSource::resolveSearchCategoryEngineURI(nsIRDFResource *engine, nsIRDFResource **trueEngine)
-{
-  *trueEngine = nsnull;
-
-  if ((!categoryDataSource) || (!mInner)) return(NS_ERROR_UNEXPECTED);
-
-  nsresult  rv;
-  const char  *uriUni = nsnull;
-  if (NS_FAILED(rv = engine->GetValueConst(&uriUni))) return(rv);
-  if (!uriUni)  return(NS_ERROR_NULL_POINTER);
-
-  NS_ConvertUTF8toUTF16 uri(uriUni);
-  if (uri.Find(kURINC_SearchCategoryEngineBasenamePrefix) !=0)  return(NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsIRDFLiteral> basenameLiteral;
-  if (NS_FAILED(rv = mRDFService->GetLiteral(uri.get(),
-      getter_AddRefs(basenameLiteral))))  return(rv);
-
-  nsCOMPtr<nsIRDFResource>  catSrc;
-  rv = mInner->GetSource(mNC_URL, basenameLiteral, PR_TRUE, getter_AddRefs(catSrc));
-  if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
-  if (!catSrc)    return(NS_ERROR_UNEXPECTED);
-
-  *trueEngine = catSrc;
-  NS_IF_ADDREF(*trueEngine);
-  return(NS_OK);
-}
-
-
-
-////////////////////////////////////////////////////////////////////////
-
-NS_IMPL_CYCLE_COLLECTION_CLASS(InternetSearchDataSource)
-
-NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(InternetSearchDataSource)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRDFService)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mRDFC)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mInner)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLocalstore)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mTimer)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mBackgroundLoadGroup)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(mLoadGroup)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(categoryDataSource)
-  NS_IMPL_CYCLE_COLLECTION_UNLINK_NSCOMPTR(busyResource)
-NS_IMPL_CYCLE_COLLECTION_UNLINK_END
-
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(InternetSearchDataSource)
-  // Skip all the RDF resources?
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRDFService)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mRDFC)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mInner)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLocalstore)
-  // Skip mUpdateArray?  Or not?  Hard to tell...
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mTimer)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mBackgroundLoadGroup)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mLoadGroup)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(categoryDataSource)
-  NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(busyResource)
-NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
-
-NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(InternetSearchDataSource,
-                                          nsIInternetSearchService)
-NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(InternetSearchDataSource,
-                                           nsIInternetSearchService)
-
-NS_INTERFACE_MAP_BEGIN(InternetSearchDataSource)
-   NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIInternetSearchService)
-   NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
-   NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
-   NS_INTERFACE_MAP_ENTRY(nsIInternetSearchService)
-   NS_INTERFACE_MAP_ENTRY(nsIRDFDataSource)
-   NS_INTERFACE_MAP_ENTRY(nsIObserver)
-   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
-   NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(InternetSearchDataSource)
-NS_INTERFACE_MAP_END
-
-
-NS_METHOD
-InternetSearchDataSource::Init()
-{
-  nsresult rv;
-
-  mInner = do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "in-memory-datasource");
-  NS_ENSURE_TRUE(mRDFService && mInner, NS_ERROR_FAILURE);
-
-  // get localstore, as we'll be using it
-  rv = mRDFService->GetDataSource("rdf:local-store",
-                                  getter_AddRefs(mLocalstore));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  mUpdateArray = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // register this as a named data source with the service manager
-  rv = mRDFService->RegisterDataSource(this, PR_FALSE);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  rv = NS_NewLoadGroup(getter_AddRefs(mLoadGroup), nsnull);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  busySchedule = PR_FALSE;
-  mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  mTimer->InitWithFuncCallback(InternetSearchDataSource::FireTimer, this,
-                               SEARCH_UPDATE_TIMEOUT,
-                               nsITimer::TYPE_REPEATING_SLACK);
-  // Note: don't addref "this" as we'll cancel the timer in the
-  //       InternetSearchDataSource destructor
-
-  mEngineListBuilt = PR_FALSE;
-
-  // Register as a profile change observer
-  nsCOMPtr<nsIObserverService> observerService = 
-           do_GetService("@mozilla.org/observer-service;1", &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  observerService->AddObserver(this, "profile-before-change", PR_TRUE);
-  observerService->AddObserver(this, "profile-do-change", PR_TRUE);
-
-  return NS_OK;
-}
-
-void
-InternetSearchDataSource::DeferredInit()
-{
-  if (mEngineListBuilt)
-    return;
-
-  nsresult rv;
-
-  nsCOMPtr<nsIProperties> dirSvc
-    (do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID));
-  if (!dirSvc)
-    return;
-
-  mEngineListBuilt = PR_TRUE;
-
-  // get available search engines
-  nsCOMPtr<nsISimpleEnumerator> dirlist;
-  rv = dirSvc->Get(NS_APP_SEARCH_DIR_LIST,
-                   NS_GET_IID(nsISimpleEnumerator), getter_AddRefs(dirlist));
-  if (NS_SUCCEEDED(rv))
-  {
-    PRBool more;
-    while (NS_SUCCEEDED(dirlist->HasMoreElements(&more)) && more) {
-      nsCOMPtr<nsISupports> suppfile;
-      nsCOMPtr<nsIFile> dir;
-      dirlist->GetNext(getter_AddRefs(suppfile));
-      dir = do_QueryInterface(suppfile);
-      if (dir)
-      {
-        GetSearchEngineList(dir, PR_FALSE);
-      }
-    }
-  }
-
-  // read in category list
-  GetCategoryList();
-}
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetURI(char **uri)
-{
-  NS_PRECONDITION(uri != nsnull, "null ptr");
-  if (! uri)
-    return NS_ERROR_NULL_POINTER;
-
-  if ((*uri = ToNewCString(NS_LITERAL_CSTRING("rdf:internetsearch"))) == nsnull)
-    return NS_ERROR_OUT_OF_MEMORY;
-
-  return NS_OK;
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetSource(nsIRDFResource* property,
-                                nsIRDFNode* target,
-                                PRBool tv,
-                                nsIRDFResource** source /* out */)
-{
-  NS_PRECONDITION(property != nsnull, "null ptr");
-  if (! property)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(target != nsnull, "null ptr");
-  if (! target)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(source != nsnull, "null ptr");
-  if (! source)
-    return NS_ERROR_NULL_POINTER;
-
-  *source = nsnull;
-  return NS_RDF_NO_VALUE;
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetSources(nsIRDFResource *property,
-                                 nsIRDFNode *target,
-                                 PRBool tv,
-                                 nsISimpleEnumerator **sources /* out */)
-{
-  nsresult  rv = NS_RDF_NO_VALUE;
-
-  if (mInner)
-  {
-    rv = mInner->GetSources(property, target, tv, sources);
-  }
-  else
-  {
-    rv = NS_NewEmptyEnumerator(sources);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetTarget(nsIRDFResource *source,
-                                nsIRDFResource *property,
-                                PRBool tv,
-                                nsIRDFNode **target /* out */)
-{
-  NS_PRECONDITION(source != nsnull, "null ptr");
-  if (! source)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(property != nsnull, "null ptr");
-  if (! property)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(target != nsnull, "null ptr");
-  if (! target)
-    return NS_ERROR_NULL_POINTER;
-
-  *target = nsnull;
-
-  nsresult    rv = NS_RDF_NO_VALUE;
-
-  // we only have positive assertions in the internet search data source.
-  if (! tv)
-    return(rv);
-
-  if ((isSearchCategoryURI(source)) && (categoryDataSource))
-  {
-    rv = categoryDataSource->GetTarget(source, property, tv, target);
-    return(rv);
-  }
-
-  if (isSearchCategoryEngineURI(source))
-  {
-    nsCOMPtr<nsIRDFResource>  trueEngine;
-    rv = resolveSearchCategoryEngineURI(source, getter_AddRefs(trueEngine));
-    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
-    if (!trueEngine)  return(NS_RDF_NO_VALUE);
-
-    source = trueEngine;
-  }
-
-  if (isSearchURI(source) && (property == mNC_Child))
-  {
-    // fake out the generic builder (i.e. return anything in this case)
-    // so that search containers never appear to be empty
-    *target = source;
-    NS_ADDREF(source);
-    return(NS_OK);
-  }
-
-  if (isSearchCommand(source) && (property == mNC_Name))
-  {
-    nsresult rv;
-    nsCOMPtr<nsIStringBundleService>
-    stringService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
-
-    if (NS_SUCCEEDED(rv) && stringService) {
-
-      nsCOMPtr<nsIStringBundle> bundle;
-      rv = stringService->CreateBundle(SEARCH_PROPERTIES, getter_AddRefs(bundle));
-      if (NS_SUCCEEDED(rv) && bundle) {
-
-        nsString valUni;
-        nsAutoString name;
-
-        if (source == mNC_SearchCommand_AddToBookmarks)
-          name.AssignLiteral("addtobookmarks");
-        else if (source == mNC_SearchCommand_AddQueryToBookmarks)
-          name.AssignLiteral("addquerytobookmarks");
-        else if (source == mNC_SearchCommand_FilterResult)
-          name.AssignLiteral("excludeurl");
-        else if (source == mNC_SearchCommand_FilterSite)
-          name.AssignLiteral("excludedomain");
-        else if (source == mNC_SearchCommand_ClearFilters)
-          name.AssignLiteral("clearfilters");
-
-        rv = bundle->GetStringFromName(name.get(), getter_Copies(valUni));
-        if (NS_SUCCEEDED(rv) && !valUni.IsEmpty()) {
-          *target = nsnull;
-          nsCOMPtr<nsIRDFLiteral> literal;
-          if (NS_FAILED(rv = mRDFService->GetLiteral(valUni.get(), getter_AddRefs(literal))))
-            return rv;
-          *target = literal;
-          NS_IF_ADDREF(*target);
-          return rv;
-        }
-      }
-    }
-  }
-
-  if (isEngineURI(source))
-  {
-    // if we're asking for info on a search engine, (deferred) load it if needed
-    nsCOMPtr<nsIRDFLiteral> dataLit;
-    FindData(source, getter_AddRefs(dataLit));
-  }
-
-  if (mInner)
-  {
-    rv = mInner->GetTarget(source, property, tv, target);
-  }
-
-  return(rv);
-}
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetTargets(nsIRDFResource *source,
-                           nsIRDFResource *property,
-                           PRBool tv,
-                           nsISimpleEnumerator **targets /* out */)
-{
-  NS_PRECONDITION(source != nsnull, "null ptr");
-  if (! source)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(property != nsnull, "null ptr");
-  if (! property)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(targets != nsnull, "null ptr");
-  if (! targets)
-    return NS_ERROR_NULL_POINTER;
-
-  nsresult rv = NS_RDF_NO_VALUE;
-
-  // we only have positive assertions in the internet search data source.
-  if (! tv)
-    return(rv);
-
-  if ((isSearchCategoryURI(source)) && (categoryDataSource))
-  {
-    rv = categoryDataSource->GetTargets(source, property, tv, targets);
-    return(rv);
-  }
-
-  if (isSearchCategoryEngineURI(source))
-  {
-    nsCOMPtr<nsIRDFResource>  trueEngine;
-    rv = resolveSearchCategoryEngineURI(source, getter_AddRefs(trueEngine));
-    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
-    if (!trueEngine)  return(NS_RDF_NO_VALUE);
-
-    source = trueEngine;
-  }
-
-  if (mInner)
-  { 
-    // defer search engine discovery until needed; small startup time improvement
-    if ((source == mNC_SearchEngineRoot || isSearchURI(source)) &&
-        property == mNC_Child && !mEngineListBuilt)
-    {
-      DeferredInit();
-    }
-
-    rv = mInner->GetTargets(source, property, tv, targets);
-  }
-  if (isSearchURI(source))
-  {
-    if (property == mNC_Child)
-    {
-      PRBool    doNetworkRequest = PR_TRUE;
-      if (NS_SUCCEEDED(rv) && (targets))
-      {
-        // check and see if we already have data for the search in question;
-        // if we do, BeginSearchRequest() won't bother doing the search again,
-        // otherwise it will kickstart it
-        PRBool    hasResults = PR_FALSE;
-        if (NS_SUCCEEDED((*targets)->HasMoreElements(&hasResults)) &&
-            hasResults)
-        {
-          doNetworkRequest = PR_FALSE;
-        }
-      }
-      BeginSearchRequest(source, doNetworkRequest);
-    }
-  }
-  return(rv);
-}
-
-
-
-nsresult
-InternetSearchDataSource::GetCategoryList()
-{
-  nsresult rv;
-
-  categoryDataSource =
-    do_CreateInstance(NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource");
-  NS_ENSURE_TRUE(categoryDataSource, NS_ERROR_FAILURE);
-
-  nsCOMPtr<nsIRDFRemoteDataSource> remoteCategoryDataSource (do_QueryInterface(categoryDataSource));
-  if (!remoteCategoryDataSource)  return(NS_ERROR_UNEXPECTED);
-
-  // get search.rdf
-    
-  nsCOMPtr<nsIFile> searchFile;
-  nsCAutoString searchFileURLSpec;
-
-  rv = NS_GetSpecialDirectory(NS_APP_SEARCH_50_FILE, getter_AddRefs(searchFile));
-  if (NS_FAILED(rv)) return rv;
-  NS_GetURLSpecFromFile(searchFile, searchFileURLSpec);
-  if (NS_FAILED(rv)) return rv;
-  rv = remoteCategoryDataSource->Init(searchFileURLSpec.get());
-  if (NS_FAILED(rv)) return rv;
-    
-  // synchronous read
-  rv = remoteCategoryDataSource->Refresh(PR_TRUE);
-  if (NS_FAILED(rv))  return(rv);
-
-  // ensure that all search engine references actually exist; if not, forget about them
-
-  PRBool        isDirtyFlag = PR_FALSE;
-  nsCOMPtr<nsIRDFContainer>   categoryRoot;
-  rv = mRDFC->MakeSeq(categoryDataSource, mNC_SearchCategoryRoot, getter_AddRefs(categoryRoot));
-  if (NS_FAILED(rv))  return(rv);
-  if (!categoryRoot)  return(NS_ERROR_UNEXPECTED);
-
-  rv = categoryRoot->Init(categoryDataSource, mNC_SearchCategoryRoot);
-  if (NS_FAILED(rv))  return(rv);
-
-  PRInt32   numCategories = 0;
-  rv = categoryRoot->GetCount(&numCategories);
-  if (NS_FAILED(rv))  return(rv);
-
-  // Note: one-based
-  for (PRInt32 catLoop=1; catLoop <= numCategories; catLoop++)
-  {
-    nsCOMPtr<nsIRDFResource>  aCategoryOrdinal;
-    rv = mRDFC->IndexToOrdinalResource(catLoop,
-      getter_AddRefs(aCategoryOrdinal));
-    if (NS_FAILED(rv))  break;
-    if (!aCategoryOrdinal)  break;
-
-    nsCOMPtr<nsIRDFNode>    aCategoryNode;
-    rv = categoryDataSource->GetTarget(mNC_SearchCategoryRoot, aCategoryOrdinal,
-      PR_TRUE, getter_AddRefs(aCategoryNode));
-    if (NS_FAILED(rv))  break;
-    nsCOMPtr<nsIRDFResource> aCategoryRes (do_QueryInterface(aCategoryNode));
-    if (!aCategoryRes)  break;
-    const char      *catResURI = nsnull;
-    aCategoryRes->GetValueConst(&catResURI);
-    if (!catResURI)   break;
-    nsCAutoString    categoryStr;
-    categoryStr.AssignLiteral(kURINC_SearchCategoryPrefix);
-    categoryStr.Append(catResURI);
-
-    nsCOMPtr<nsIRDFResource>  searchCategoryRes;
-    rv = mRDFService->GetResource(categoryStr, getter_AddRefs(searchCategoryRes));
-    if (NS_FAILED(rv))
-      break; 
-
-    nsCOMPtr<nsIRDFContainer> categoryContainer;
-    rv = mRDFC->MakeSeq(categoryDataSource, searchCategoryRes,
-      getter_AddRefs(categoryContainer));
-    if (NS_FAILED(rv))  continue;
-
-    rv = categoryContainer->Init(categoryDataSource, searchCategoryRes);
-    if (NS_FAILED(rv))  return(rv);
-
-    PRInt32   numEngines = 0;
-    rv = categoryContainer->GetCount(&numEngines);
-    if (NS_FAILED(rv))  break;
-
-    // Note: one-based, and loop backwards as we might be removing entries
-    for (PRInt32 engineLoop=numEngines; engineLoop >= 1; engineLoop--)
-    {
-      nsCOMPtr<nsIRDFResource>  aEngineOrdinal;
-      rv = mRDFC->IndexToOrdinalResource(engineLoop,
-        getter_AddRefs(aEngineOrdinal));
-      if (NS_FAILED(rv))  break;
-      if (!aEngineOrdinal)  break;
-
-      nsCOMPtr<nsIRDFNode>    aEngineNode;
-      rv = categoryDataSource->GetTarget(searchCategoryRes, aEngineOrdinal,
-        PR_TRUE, getter_AddRefs(aEngineNode));
-      if (NS_FAILED(rv))  break;
-      nsCOMPtr<nsIRDFResource> aEngineRes (do_QueryInterface(aEngineNode));
-      if (!aEngineRes)  break;
-
-      if (isSearchCategoryEngineURI(aEngineRes))
-      {
-        nsCOMPtr<nsIRDFResource>  trueEngine;
-        rv = resolveSearchCategoryEngineURI(aEngineRes,
-          getter_AddRefs(trueEngine));
-        if (NS_FAILED(rv) || (!trueEngine))
-        {
-          // unable to resolve, so forget about this engine reference
-#ifdef  DEBUG
-          const char    *catEngineURI = nsnull;
-          aEngineRes->GetValueConst(&catEngineURI);
-          if (catEngineURI)
-          {
-            printf("**** Stale search engine reference to '%s'\n",
-              catEngineURI);
-          }
-#endif
-          nsCOMPtr<nsIRDFNode>  staleCatEngine;
-          rv = categoryContainer->RemoveElementAt(engineLoop, PR_TRUE,
-            getter_AddRefs(staleCatEngine));
-          isDirtyFlag = PR_TRUE;
-        }
-      }
-    }
-  }
-
-  if (isDirtyFlag)
-  {
-    if (remoteCategoryDataSource)
-    {
-      remoteCategoryDataSource->Flush();
-    }
-  }
-
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::Assert(nsIRDFResource *source,
-                       nsIRDFResource *property,
-                       nsIRDFNode *target,
-                       PRBool tv)
-{
-  nsresult  rv = NS_RDF_ASSERTION_REJECTED;
-
-  // we only have positive assertions in the internet search data source.
-  if (! tv)
-    return(rv);
-
-  if (mInner)
-  {
-    rv = mInner->Assert(source, property, target, tv);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::Unassert(nsIRDFResource *source,
-                         nsIRDFResource *property,
-                         nsIRDFNode *target)
-{
-  nsresult  rv = NS_RDF_ASSERTION_REJECTED;
-
-  if (mInner)
-  {
-    rv = mInner->Unassert(source, property, target);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::Change(nsIRDFResource *source,
-      nsIRDFResource *property,
-      nsIRDFNode *oldTarget,
-      nsIRDFNode *newTarget)
-{
-  nsresult  rv = NS_RDF_ASSERTION_REJECTED;
-
-  if (mInner)
-  {
-    rv = mInner->Change(source, property, oldTarget, newTarget);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::Move(nsIRDFResource *oldSource,
-             nsIRDFResource *newSource,
-             nsIRDFResource *property,
-             nsIRDFNode *target)
-{
-  nsresult  rv = NS_RDF_ASSERTION_REJECTED;
-
-  if (mInner)
-  {
-    rv = mInner->Move(oldSource, newSource, property, target);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::HasAssertion(nsIRDFResource *source,
-                             nsIRDFResource *property,
-                             nsIRDFNode *target,
-                             PRBool tv,
-                             PRBool *hasAssertion /* out */)
-{
-  NS_PRECONDITION(source != nsnull, "null ptr");
-  if (! source)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(property != nsnull, "null ptr");
-  if (! property)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(target != nsnull, "null ptr");
-  if (! target)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(hasAssertion != nsnull, "null ptr");
-  if (! hasAssertion)
-    return NS_ERROR_NULL_POINTER;
-
-  *hasAssertion = PR_FALSE;
-
-  // we only have positive assertions in the internet search data source.
-  if (! tv)
-  {
-    return NS_OK;
-        }
-        nsresult  rv = NS_RDF_NO_VALUE;
-        
-        if (mInner)
-        {
-    rv = mInner->HasAssertion(source, property, target, tv, hasAssertion);
-  }
-        return(rv);
-}
-
-NS_IMETHODIMP 
-InternetSearchDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *result)
-{
-    if (mInner) {
-  return mInner->HasArcIn(aNode, aArc, result);
-    }
-    else {
-  *result = PR_FALSE;
-    }
-    return NS_OK;
-}
-
-NS_IMETHODIMP 
-InternetSearchDataSource::HasArcOut(nsIRDFResource *source, nsIRDFResource *aArc, PRBool *result)
-{
-    NS_PRECONDITION(source != nsnull, "null ptr");
-    if (! source)
-  return NS_ERROR_NULL_POINTER;
-
-    nsresult rv;
-
-    if ((source == mNC_SearchEngineRoot) || (source == mNC_LastSearchRoot) || isSearchURI(source))
-    {
-  *result = (aArc == mNC_Child);
-  return NS_OK;
-    }
-
-    if ((isSearchCategoryURI(source)) && (categoryDataSource))
-    {
-  const char  *uri = nsnull;
-  source->GetValueConst(&uri);
-  if (!uri) return(NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsIRDFResource>  category;
-  if (NS_FAILED(rv = mRDFService->GetResource(nsDependentCString(uri),
-                getter_AddRefs(category))))
-      return(rv);
-
-  return categoryDataSource->HasArcOut(source, aArc, result);
-    }
-
-    if (isSearchCategoryEngineURI(source))
-    {
-  nsCOMPtr<nsIRDFResource>  trueEngine;
-  rv = resolveSearchCategoryEngineURI(source, getter_AddRefs(trueEngine));
-  if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
-  if (!trueEngine) {
-      *result = PR_FALSE;
-      return NS_OK;
-  }
-  source = trueEngine;
-    }
-
-    if (isEngineURI(source))
-    {
-  // if we're asking for info on a search engine, (deferred) load it if needed
-  nsCOMPtr<nsIRDFLiteral> dataLit;
-  FindData(source, getter_AddRefs(dataLit));
-    }
-
-    if (mInner)
-    {
-  return mInner->HasArcOut(source, aArc, result);
-    }
-
-    *result = PR_FALSE;
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-InternetSearchDataSource::ArcLabelsIn(nsIRDFNode *node,
-                            nsISimpleEnumerator ** labels /* out */)
-{
-  nsresult  rv;
-
-  if (mInner)
-  {
-    rv = mInner->ArcLabelsIn(node, labels);
-    return(rv);
-  }
-  else
-  {
-    rv = NS_NewEmptyEnumerator(labels);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::ArcLabelsOut(nsIRDFResource *source,
-                             nsISimpleEnumerator **labels /* out */)
-{
-  NS_PRECONDITION(source != nsnull, "null ptr");
-  if (! source)
-    return NS_ERROR_NULL_POINTER;
-
-  NS_PRECONDITION(labels != nsnull, "null ptr");
-  if (! labels)
-    return NS_ERROR_NULL_POINTER;
-
-  nsresult rv;
-
-  if ((source == mNC_SearchEngineRoot) || (source == mNC_LastSearchRoot) || isSearchURI(source))
-  {
-            nsCOMPtr<nsISupportsArray> array(do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv));
-            if (NS_FAILED(rv)) return rv;
-
-            array->AppendElement(mNC_Child);
-
-            return NS_NewArrayEnumerator(labels, array);
-  }
-
-  if ((isSearchCategoryURI(source)) && (categoryDataSource))
-  {
-    const char  *uri = nsnull;
-    source->GetValueConst(&uri);
-    if (!uri) return(NS_ERROR_UNEXPECTED);
-
-    nsCOMPtr<nsIRDFResource>  category;
-    if (NS_FAILED(rv = mRDFService->GetResource(nsDependentCString(uri),
-      getter_AddRefs(category))))
-      return(rv);
-
-    rv = categoryDataSource->ArcLabelsOut(category, labels);
-    return(rv);
-  }
-
-  if (isSearchCategoryEngineURI(source))
-  {
-    nsCOMPtr<nsIRDFResource>  trueEngine;
-    rv = resolveSearchCategoryEngineURI(source, getter_AddRefs(trueEngine));
-    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
-    if (!trueEngine)  return(NS_RDF_NO_VALUE);
-
-    source = trueEngine;
-  }
-
-  if (isEngineURI(source))
-  {
-    // if we're asking for info on a search engine, (deferred) load it if needed
-    nsCOMPtr<nsIRDFLiteral> dataLit;
-    FindData(source, getter_AddRefs(dataLit));
-  }
-
-  if (mInner)
-  {
-    rv = mInner->ArcLabelsOut(source, labels);
-    return(rv);
-  }
-
-  return NS_NewEmptyEnumerator(labels);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
-{
-  nsresult  rv = NS_RDF_NO_VALUE;
-
-  if (mInner)
-  {
-    rv = mInner->GetAllResources(aCursor);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::AddObserver(nsIRDFObserver *aObserver)
-{
-  nsresult  rv = NS_OK;
-
-  if (mInner)
-  {
-    rv = mInner->AddObserver(aObserver);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::RemoveObserver(nsIRDFObserver *aObserver)
-{
-  nsresult  rv = NS_OK;
-
-  if (mInner)
-  {
-    rv = mInner->RemoveObserver(aObserver);
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetAllCmds(nsIRDFResource* source,
-                                     nsISimpleEnumerator/*<nsIRDFResource>*/** commands)
-{
-  nsresult      rv;
-  nsCOMPtr<nsISupportsArray> cmdArray(do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv));
-  if (NS_FAILED(rv))  return(rv);
-
-  // check if we have any filters, enable command to clear them
-  PRBool        haveFilters = PR_FALSE;
-
-  if (mLocalstore)
-  {
-    nsCOMPtr<nsISimpleEnumerator> cursor;
-    PRBool        hasMore = PR_FALSE;
-
-    // check mNC_FilterSearchURLsRoot
-    if (NS_SUCCEEDED(rv = mLocalstore->GetTargets(mNC_FilterSearchURLsRoot, mNC_Child,
-      PR_TRUE, getter_AddRefs(cursor))))
-    {
-      if (NS_SUCCEEDED(cursor->HasMoreElements(&hasMore)) && hasMore)
-      {
-        haveFilters = PR_TRUE;
-      }
-    }
-    if (!haveFilters)
-    {
-      // check mNC_FilterSearchSitesRoot
-      if (NS_SUCCEEDED(rv = mLocalstore->GetTargets(mNC_FilterSearchSitesRoot, mNC_Child,
-        PR_TRUE, getter_AddRefs(cursor))))
-      {
-        if (NS_SUCCEEDED(cursor->HasMoreElements(&hasMore)) && hasMore)
-        {
-          haveFilters = PR_TRUE;
-        }
-      }
-    }
-  }
-
-  PRBool        isSearchResult = PR_FALSE;
-  rv = mInner->HasAssertion(source, mRDF_type, mNC_SearchResult, PR_TRUE,
-          &isSearchResult);
-  if (NS_SUCCEEDED(rv) && isSearchResult)
-  {
-    cmdArray->AppendElement(mNC_SearchCommand_AddQueryToBookmarks);
-    cmdArray->AppendElement(mNC_BookmarkSeparator);
-
-    // if this is a search result, and it isn't filtered, enable command to be able to filter it
-    PRBool        isURLFiltered = PR_FALSE;
-    rv = mInner->HasAssertion(mNC_FilterSearchURLsRoot, mNC_Child, source,
-                              PR_TRUE, &isURLFiltered);
-    if (NS_SUCCEEDED(rv) && !isURLFiltered)
-    {
-      cmdArray->AppendElement(mNC_SearchCommand_FilterResult);
-    }
-
-    // XXX (should check site) if this is a search result site, and the site isn't filtered,
-    //     enable command to filter it
-    cmdArray->AppendElement(mNC_SearchCommand_FilterSite);
-
-    if (haveFilters)
-    {
-      cmdArray->AppendElement(mNC_BookmarkSeparator);
-      cmdArray->AppendElement(mNC_SearchCommand_ClearFilters);
-    }
-  }
-  else if (isSearchURI(source) || (source == mNC_LastSearchRoot))
-  {
-    if (haveFilters)
-    {
-      cmdArray->AppendElement(mNC_SearchCommand_ClearFilters);
-    }
-  }
-
-  // always append a separator last (due to aggregation of commands from multiple datasources)
-  cmdArray->AppendElement(mNC_BookmarkSeparator);
-
-  return NS_NewArrayEnumerator(commands, cmdArray);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
-                                       nsIRDFResource*   aCommand,
-                                       nsISupportsArray/*<nsIRDFResource>*/* aArguments,
-                                       PRBool* aResult)
-{
-  return(NS_ERROR_NOT_IMPLEMENTED);
-}
-
-
-
-PRBool
-InternetSearchDataSource::getSearchURI(nsIRDFResource *src, nsAString &_retval)
-{
-
-  if (src)
-  {
-    nsresult    rv;
-    nsCOMPtr<nsIRDFNode>  srcNode;
-    if (NS_SUCCEEDED(rv = mInner->GetTarget(src, mNC_URL, PR_TRUE, getter_AddRefs(srcNode))))
-    {
-      nsCOMPtr<nsIRDFLiteral> urlLiteral (do_QueryInterface(srcNode));
-      if (urlLiteral)
-      {
-        const PRUnichar *uriUni = nsnull;
-        urlLiteral->GetValueConst(&uriUni);
-        if (uriUni)
-        {
-          _retval.Assign(uriUni);
-          return PR_TRUE;
-        }
-      }
-    }
-  }
-  return PR_FALSE;
-}
-
-
-
-nsresult
-InternetSearchDataSource::addToBookmarks(nsIRDFResource *src)
-{
-  if (!src) return(NS_ERROR_UNEXPECTED);
-  if (!mInner)  return(NS_ERROR_UNEXPECTED);
-
-  nsresult    rv;
-  nsCOMPtr<nsIRDFNode>  nameNode;
-  // Note: nameLiteral needs to stay in scope for the life of "name"
-  nsCOMPtr<nsIRDFLiteral> nameLiteral;
-  const PRUnichar   *name = nsnull;
-  if (NS_SUCCEEDED(rv = mInner->GetTarget(src, mNC_Name, PR_TRUE, getter_AddRefs(nameNode))))
-  {
-    nameLiteral = do_QueryInterface(nameNode);
-    if (nameLiteral)
-    {
-      nameLiteral->GetValueConst(&name);
-    }
-  }
-
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::addQueryToBookmarks(nsIRDFResource *src)
-{
-  if (!src) return(NS_ERROR_UNEXPECTED);
-  if (!mInner)  return(NS_ERROR_UNEXPECTED);
-
-  nsresult rv;
-  nsCOMPtr<nsIRDFNode>  refNode;
-  if (NS_FAILED(rv = mInner->GetTarget(mNC_LastSearchRoot, mNC_Ref, PR_TRUE,
-    getter_AddRefs(refNode))))
-    return(rv);
-  nsCOMPtr<nsIRDFLiteral> urlLiteral (do_QueryInterface(refNode));
-  if (!urlLiteral)
-    return(NS_ERROR_UNEXPECTED);
-  const PRUnichar *uriUni = nsnull;
-  urlLiteral->GetValueConst(&uriUni);
-
-  nsCOMPtr<nsIRDFNode>  textNode;
-  if (NS_FAILED(rv = mInner->GetTarget(mNC_LastSearchRoot, mNC_LastText, PR_TRUE,
-    getter_AddRefs(textNode))))
-    return(rv);
-  nsCOMPtr<nsIRDFLiteral> textLiteral = do_QueryInterface(textNode);
-  nsString value;
-  if (textLiteral)
-  {
-    const PRUnichar *textUni = nsnull;
-    textLiteral->GetValueConst(&textUni);
-    nsAutoString name;
-    name.Assign(textUni);
-    // replace pluses with spaces
-    PRInt32 offset = name.FindChar(PRUnichar('+'));
-    while (offset != -1) {
-      name.Replace(offset, 1, PRUnichar(' '));
-      offset = name.FindChar(PRUnichar('+'), offset + 1);
-    }
-
-    nsCOMPtr<nsIStringBundleService>
-    stringService(do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv));
-    if (NS_SUCCEEDED(rv) && stringService)
-    {
-      nsCOMPtr<nsIStringBundle> bundle;
-      rv = stringService->CreateBundle(SEARCH_PROPERTIES, getter_AddRefs(bundle));
-      if (bundle)
-      {
-        const PRUnichar *strings[] = { name.get() };
-        rv = bundle->FormatStringFromName(NS_LITERAL_STRING("searchTitle").get(), strings, 1, 
-          getter_Copies(value));
-      }
-    }
-  }
-
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::filterResult(nsIRDFResource *aResource)
-{
-  if (!aResource) return(NS_ERROR_UNEXPECTED);
-  if (!mInner)  return(NS_ERROR_UNEXPECTED);
-
-  // remove all anonymous resources which have this as a #URL
-  nsAutoString url;
-  if (!getSearchURI(aResource, url))
-  {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  nsresult      rv;
-  nsCOMPtr<nsIRDFLiteral> urlLiteral;
-  if (NS_FAILED(rv = mRDFService->GetLiteral(url.get(), getter_AddRefs(urlLiteral)))
-    || (urlLiteral == nsnull))  return(NS_ERROR_UNEXPECTED);
-
-  // add aResource into a list of nodes to filter out
-  PRBool  alreadyFiltered = PR_FALSE;
-  rv = mLocalstore->HasAssertion(mNC_FilterSearchURLsRoot, mNC_Child,
-         urlLiteral, PR_TRUE, &alreadyFiltered);
-  if (NS_SUCCEEDED(rv) && alreadyFiltered)
-  {
-    // already filtered, nothing to do
-    return(rv);
-  }
-
-  // filter this URL out
-  mLocalstore->Assert(mNC_FilterSearchURLsRoot, mNC_Child, urlLiteral, PR_TRUE);
-
-  // flush localstore
-  nsCOMPtr<nsIRDFRemoteDataSource> remoteLocalStore (do_QueryInterface(mLocalstore));
-  if (remoteLocalStore)
-  {
-    remoteLocalStore->Flush();
-  }
-
-  nsCOMPtr<nsISimpleEnumerator> anonArcs;
-  if (NS_SUCCEEDED(rv = mInner->GetSources(mNC_URL, urlLiteral, PR_TRUE,
-    getter_AddRefs(anonArcs))))
-  {
-    PRBool      hasMoreAnonArcs = PR_TRUE;
-    while (hasMoreAnonArcs)
-    {
-      if (NS_FAILED(anonArcs->HasMoreElements(&hasMoreAnonArcs)) ||
-          !hasMoreAnonArcs)
-        break;
-      nsCOMPtr<nsISupports> anonArc;
-      if (NS_FAILED(anonArcs->GetNext(getter_AddRefs(anonArc))))
-        break;
-      nsCOMPtr<nsIRDFResource> anonChild (do_QueryInterface(anonArc));
-      if (!anonChild) continue;
-
-      PRBool  isSearchResult = PR_FALSE;
-      rv = mInner->HasAssertion(anonChild, mRDF_type, mNC_SearchResult,
-                                PR_TRUE, &isSearchResult);
-      if (NS_FAILED(rv) || !isSearchResult)
-        continue;
-
-      nsCOMPtr<nsIRDFResource>  anonParent;
-      if (NS_FAILED(rv = mInner->GetSource(mNC_Child, anonChild, PR_TRUE,
-        getter_AddRefs(anonParent)))) continue;
-      if (!anonParent)  continue;
-
-      mInner->Unassert(anonParent, mNC_Child, anonChild);
-    }
-  }
-
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::filterSite(nsIRDFResource *aResource)
-{
-  if (!aResource) return(NS_ERROR_UNEXPECTED);
-  if (!mInner)  return(NS_ERROR_UNEXPECTED);
-
-  nsAutoString host;
-  if (!getSearchURI(aResource, host))
-  {
-    return NS_ERROR_UNEXPECTED;
-  }
-
-  // determine site (host name)
-  PRInt32   slashOffset1 = host.Find("://");
-  if (slashOffset1 < 1)     return(NS_ERROR_UNEXPECTED);
-  PRInt32   slashOffset2 = host.FindChar(PRUnichar('/'), slashOffset1 + 3);
-  if (slashOffset2 <= slashOffset1) return(NS_ERROR_UNEXPECTED);
-  host.SetLength(slashOffset2 + 1);
-
-  nsresult      rv;
-  nsCOMPtr<nsIRDFLiteral> urlLiteral;
-  if (NS_FAILED(rv = mRDFService->GetLiteral(host.get(), getter_AddRefs(urlLiteral)))
-    || (urlLiteral == nsnull))  return(NS_ERROR_UNEXPECTED);
-
-  // add aResource into a list of nodes to filter out
-  PRBool  alreadyFiltered = PR_FALSE;
-  rv = mLocalstore->HasAssertion(mNC_FilterSearchSitesRoot, mNC_Child,
-         urlLiteral, PR_TRUE, &alreadyFiltered);
-  if (NS_SUCCEEDED(rv) && alreadyFiltered)
-  {
-    // already filtered, nothing to do
-    return(rv);
-  }
-
-  // filter this site out
-  mLocalstore->Assert(mNC_FilterSearchSitesRoot, mNC_Child, urlLiteral, PR_TRUE);
-
-  // flush localstore
-  nsCOMPtr<nsIRDFRemoteDataSource> remoteLocalStore (do_QueryInterface(mLocalstore));
-  if (remoteLocalStore)
-  {
-    remoteLocalStore->Flush();
-  }
-
-  // remove all anonymous resources which have this as a site
-
-  nsCOMPtr<nsIRDFResource>  aRes;
-  nsCOMPtr<nsISimpleEnumerator> cursor;
-  PRBool        hasMore;
-
-  nsCOMPtr<nsISupportsArray> array(do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv));
-  if (NS_FAILED(rv)) return rv;
-
-  if (NS_FAILED(rv = GetAllResources(getter_AddRefs(cursor))))  return(rv);
-  if (!cursor)  return(NS_ERROR_UNEXPECTED);
-
-  hasMore = PR_TRUE;
-  while (hasMore)
-  {
-    if (NS_FAILED(rv = cursor->HasMoreElements(&hasMore)))  return(rv);
-    if (!hasMore)
-      break;
-    
-    nsCOMPtr<nsISupports> isupports;
-    if (NS_FAILED(rv = cursor->GetNext(getter_AddRefs(isupports))))
-        return(rv);
-    if (!isupports) return(NS_ERROR_UNEXPECTED);
-    aRes = do_QueryInterface(isupports);
-    if (!aRes)  return(NS_ERROR_UNEXPECTED);
-
-    if ((aRes.get() == mNC_LastSearchRoot) || (isSearchURI(aRes)))
-    {
-      array->AppendElement(aRes);
-    }
-  }
-
-  PRUint32  count;
-  if (NS_FAILED(rv = array->Count(&count))) return(rv);
-  for (PRUint32 loop=0; loop<count; loop++)
-  {
-    nsCOMPtr<nsIRDFResource> aSearchRoot (do_QueryElementAt(array, loop));
-    if (!aSearchRoot) break;
-
-    if (NS_SUCCEEDED(rv = mInner->GetTargets(aSearchRoot, mNC_Child,
-      PR_TRUE, getter_AddRefs(cursor))))
-    {
-      hasMore = PR_TRUE;
-      while (hasMore)
-      {
-        if (NS_FAILED(cursor->HasMoreElements(&hasMore)) || !hasMore)
-          break;
-
-        nsCOMPtr<nsISupports>   arc;
-        if (NS_FAILED(cursor->GetNext(getter_AddRefs(arc))))
-          break;
-        aRes = do_QueryInterface(arc);
-        if (!aRes)  break;
-
-        nsAutoString site;
-        if (!getSearchURI(aRes, site))
-        {
-          return NS_ERROR_UNEXPECTED;
-        }
-
-        // determine site (host name)
-        slashOffset1 = site.Find("://");
-        if (slashOffset1 < 1)     return(NS_ERROR_UNEXPECTED);
-        slashOffset2 = site.FindChar(PRUnichar('/'), slashOffset1 + 3);
-        if (slashOffset2 <= slashOffset1) return(NS_ERROR_UNEXPECTED);
-        site.SetLength(slashOffset2 + 1);
-
-        if (site.Equals(host, CaseInsensitiveCompare))
-        {
-          mInner->Unassert(aSearchRoot, mNC_Child, aRes);
-        }
-      }
-    }
-  }
-
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::clearFilters(void)
-{
-  if (!mInner)  return(NS_ERROR_UNEXPECTED);
-
-  nsresult      rv;
-  nsCOMPtr<nsISimpleEnumerator> arcs;
-  PRBool        hasMore = PR_TRUE;
-  nsCOMPtr<nsISupports>   arc;
-
-  // remove all filtered URLs
-  if (NS_SUCCEEDED(rv = mLocalstore->GetTargets(mNC_FilterSearchURLsRoot, mNC_Child,
-    PR_TRUE, getter_AddRefs(arcs))))
-  {
-    hasMore = PR_TRUE;
-    while (hasMore)
-    {
-      if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || !hasMore)
-        break;
-      if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))
-        break;
-
-      nsCOMPtr<nsIRDFLiteral> filterURL (do_QueryInterface(arc));
-      if (!filterURL) continue;
-      
-      mLocalstore->Unassert(mNC_FilterSearchURLsRoot, mNC_Child, filterURL);
-    }
-  }
-
-  // remove all filtered sites
-  if (NS_SUCCEEDED(rv = mLocalstore->GetTargets(mNC_FilterSearchSitesRoot, mNC_Child,
-    PR_TRUE, getter_AddRefs(arcs))))
-  {
-    hasMore = PR_TRUE;
-    while (hasMore)
-    {
-      if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || !hasMore)
-        break;
-      if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))
-        break;
-
-      nsCOMPtr<nsIRDFLiteral> filterSiteLiteral (do_QueryInterface(arc));
-      if (!filterSiteLiteral) continue;
-      
-      mLocalstore->Unassert(mNC_FilterSearchSitesRoot, mNC_Child, filterSiteLiteral);
-    }
-  }
-
-  // flush localstore
-  nsCOMPtr<nsIRDFRemoteDataSource> remoteLocalStore (do_QueryInterface(mLocalstore));
-  if (remoteLocalStore)
-  {
-    remoteLocalStore->Flush();
-  }
-
-  return(NS_OK);
-}
-
-
-
-PRBool
-InternetSearchDataSource::isSearchResultFiltered(const nsString &hrefStr)
-{
-  PRBool    filterStatus = PR_FALSE;
-  nsresult  rv;
-
-  const PRUnichar *hrefUni = hrefStr.get();
-  if (!hrefUni) return(filterStatus);
-
-  // check if this specific URL is to be filtered out
-  nsCOMPtr<nsIRDFLiteral> hrefLiteral;
-  if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(hrefUni, getter_AddRefs(hrefLiteral))))
-  {
-    if (NS_SUCCEEDED(rv = mLocalstore->HasAssertion(mNC_FilterSearchURLsRoot,
-      mNC_Child, hrefLiteral, PR_TRUE, &filterStatus)))
-    {
-      if (filterStatus)
-      {
-        return(filterStatus);
-      }
-    }
-  }
-
-  // check if this specific Site is to be filtered out
-
-  // determine site (host name)
-  nsAutoString  host(hrefStr);
-  PRInt32   slashOffset1 = host.Find("://");
-  if (slashOffset1 < 1)     return(NS_ERROR_UNEXPECTED);
-  PRInt32   slashOffset2 = host.FindChar(PRUnichar('/'), slashOffset1 + 3);
-  if (slashOffset2 <= slashOffset1) return(NS_ERROR_UNEXPECTED);
-  host.SetLength(slashOffset2 + 1);
-
-  nsCOMPtr<nsIRDFLiteral> urlLiteral;
-  if (NS_FAILED(rv = mRDFService->GetLiteral(host.get(), getter_AddRefs(urlLiteral)))
-    || (urlLiteral == nsnull))  return(NS_ERROR_UNEXPECTED);
-
-  rv = mLocalstore->HasAssertion(mNC_FilterSearchSitesRoot, mNC_Child, urlLiteral,
-    PR_TRUE, &filterStatus);
-
-  return(filterStatus);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
-                                nsIRDFResource*   aCommand,
-                                nsISupportsArray/*<nsIRDFResource>*/* aArguments)
-{
-  nsresult    rv = NS_OK;
-  PRInt32     loop;
-  PRUint32    numSources;
-  if (NS_FAILED(rv = aSources->Count(&numSources))) return(rv);
-  if (numSources < 1)
-  {
-    return(NS_ERROR_ILLEGAL_VALUE);
-  }
-
-  for (loop=((PRInt32)numSources)-1; loop>=0; loop--)
-  {
-    nsCOMPtr<nsIRDFResource> src (do_QueryElementAt(aSources, loop));
-    if (!src) return(NS_ERROR_NO_INTERFACE);
-
-    if (aCommand == mNC_SearchCommand_AddToBookmarks)
-    {
-      if (NS_FAILED(rv = addToBookmarks(src)))
-        return(rv);
-    }
-    else if (aCommand == mNC_SearchCommand_AddQueryToBookmarks)
-    {
-      if (NS_FAILED(rv = addQueryToBookmarks(src)))
-        return(rv);
-    }
-    else if (aCommand == mNC_SearchCommand_FilterResult)
-    {
-      if (NS_FAILED(rv = filterResult(src)))
-        return(rv);
-    }
-    else if (aCommand == mNC_SearchCommand_FilterSite)
-    {
-      if (NS_FAILED(rv = filterSite(src)))
-        return(rv);
-    }
-    else if (aCommand == mNC_SearchCommand_ClearFilters)
-    {
-      if (NS_FAILED(rv = clearFilters()))
-        return(rv);
-    }
-  }
-  return(NS_OK);
-}
-
-NS_IMETHODIMP
-InternetSearchDataSource::BeginUpdateBatch()
-{
-        return mInner->BeginUpdateBatch();
-}
-
-NS_IMETHODIMP
-InternetSearchDataSource::EndUpdateBatch()
-{
-        return mInner->EndUpdateBatch();
-}
-
-NS_IMETHODIMP
-InternetSearchDataSource::AddSearchEngine(const char *engineURL, const char *iconURL,
-            const PRUnichar *suggestedTitle, const PRUnichar *suggestedCategory)
-{
-        return AddSearchEngineInternal(engineURL, iconURL, suggestedTitle,
-                                       suggestedCategory, nsnull);
-}
-
-nsresult
-InternetSearchDataSource::AddSearchEngineInternal(const char *engineURL, const char *iconURL,
-                                                  const PRUnichar *suggestedTitle,
-                                                  const PRUnichar *suggestedCategory,
-                                                  nsIRDFResource *aOldEngineResource)
-{
-  NS_PRECONDITION(engineURL != nsnull, "null ptr");
-  if (!engineURL) return(NS_ERROR_NULL_POINTER);
-  // Note: iconURL, suggestedTitle & suggestedCategory
-  // can be null or empty strings, which is OK
-
-#ifdef  DEBUG_SEARCH_OUTPUT
-  printf("AddSearchEngine: engine='%s'\n", engineURL);
-#endif
-
-  nsresult  rv = NS_OK;
-
-  // mBackgroundLoadGroup is a dynamically created singleton
-  if (!mBackgroundLoadGroup)
-  {
-    if (NS_FAILED(rv = NS_NewLoadGroup(getter_AddRefs(mBackgroundLoadGroup), nsnull)))
-      return(rv);
-    if (!mBackgroundLoadGroup)
-      return(NS_ERROR_UNEXPECTED);
-  }
-
-  // download engine
-  nsCOMPtr<nsIInternetSearchContext>  engineContext;
-  rv = NS_NewInternetSearchContext
-         (aOldEngineResource? nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT:
-                              nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT,
-          nsnull, aOldEngineResource, nsnull, suggestedCategory,
-          getter_AddRefs(engineContext));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!engineContext) return(NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsIURI>  engineURI;
-  if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(engineURI), engineURL)))
-    return(rv);
-
-  nsCOMPtr<nsIChannel>  engineChannel;
-  if (NS_FAILED(rv = NS_NewChannel(getter_AddRefs(engineChannel), engineURI, nsnull, mBackgroundLoadGroup)))
-    return(rv);
-    
-  if (NS_FAILED(rv = engineChannel->AsyncOpen(this, engineContext)))
-    return(rv);
-
-  // download icon
-  nsCOMPtr<nsIInternetSearchContext>  iconContext;
-  rv = NS_NewInternetSearchContext
-         (aOldEngineResource? nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT:
-                              nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT,
-          nsnull, aOldEngineResource, nsnull, suggestedCategory,
-          getter_AddRefs(iconContext));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!iconContext) return(NS_ERROR_UNEXPECTED);
-
-  if (iconURL && (*iconURL))
-  {
-    nsCOMPtr<nsIURI>  iconURI;
-    if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(iconURI), iconURL)))
-      return(rv);
-
-    nsCOMPtr<nsIChannel>  iconChannel;
-    if (NS_FAILED(rv = NS_NewChannel(getter_AddRefs(iconChannel), iconURI, nsnull, mBackgroundLoadGroup)))
-      return(rv);
-    if (NS_FAILED(rv = iconChannel->AsyncOpen(this, iconContext)))
-      return(rv);
-  }
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::saveContents(nsIChannel* channel, nsIInternetSearchContext *context, PRUint32 contextType)
-{
-    NS_ASSERTION(contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT ||
-                 contextType == nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT ||
-                 contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT ||
-                 contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT,
-                 "unexpected context");
-  nsresult  rv = NS_OK;
-
-  if (!channel) return(NS_ERROR_UNEXPECTED);
-  if (!context) return(NS_ERROR_UNEXPECTED);
-
-  // get real URI
-  nsCOMPtr<nsIURI>  channelURI;
-  if (NS_FAILED(rv = channel->GetURI(getter_AddRefs(channelURI))))
-    return(rv);
-  if (!channelURI)
-    return(NS_ERROR_NULL_POINTER);
-
-  nsCAutoString baseName;
-  if (NS_FAILED(rv = channelURI->GetSpec(baseName)))
-    return(rv);
-
-  PRInt32     slashOffset = baseName.RFindChar(PRUnichar('/'));
-  if (slashOffset < 0)    return(NS_ERROR_UNEXPECTED);
-  baseName.Cut(0, slashOffset+1);
-  if (baseName.IsEmpty()) return(NS_ERROR_UNEXPECTED);
-
-  // make sure that search engines are .src files
-  if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT ||
-    contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT)
-  {
-    if (!StringEndsWith(baseName, NS_LITERAL_CSTRING(".src"), CaseInsensitiveCompare))
-    {
-      return(NS_ERROR_UNEXPECTED);
-    }
-  }
-
-    nsCOMPtr<nsIFile> outFile;
-  // If the mode is "UPDATE", the output dir is same as the original file
-  // location. Otherwise ("NEW" mode), located in NS_APP_USER_SEARCH_DIR.
-  nsCOMPtr<nsIRDFResource> oldResource;
-  rv = context->GetEngine(getter_AddRefs(oldResource));
-
-  if (oldResource) {
-    nsCOMPtr<nsILocalFile> oldEngineFile;
-    rv = EngineFileFromResource(oldResource, getter_AddRefs(oldEngineFile));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    rv = oldEngineFile->GetParent(getter_AddRefs(outFile));
-    NS_ENSURE_SUCCESS(rv, rv);
-  }
-  else {
-    rv = NS_GetSpecialDirectory(NS_APP_USER_SEARCH_DIR, getter_AddRefs(outFile));
-    if (NS_FAILED(rv))
-        return rv;
-  }
-
-    PRBool exists;
-    rv = outFile->Exists(&exists);
-    if (NS_FAILED(rv)) return(rv);
-    if (!exists)
-    {
-        rv = outFile->Create(nsIFile::DIRECTORY_TYPE, 0755);
-        if (NS_FAILED(rv)) return(rv);
-    }
-
-  const PRUnichar *dataBuf = nsnull;
-  if (NS_FAILED(rv = context->GetBufferConst(&dataBuf)))  return(rv);
-
-  // if no data, then nothing to do
-  // Note: do this before opening file, as it would be truncated
-  PRInt32   bufferLength = 0;
-  if (NS_FAILED(context->GetBufferLength(&bufferLength))) return(rv);
-  if (bufferLength < 1) return(NS_OK);
-  
-  rv = outFile->Append(NS_ConvertUTF8toUTF16(baseName));
-  if (NS_FAILED(rv)) return rv;
-  
-  // save data to file
-  // Note: write out one character at a time, as we might be dealing
-  //       with binary data (such as 0x00) [especially for images]
-    //
-    // XXX - It appears that this is done in order to discard the upper
-    // byte of each PRUnichar.  I hope that's OK!!
-    //
-    if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT ||
-        contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT) {
-        // This is an update operation that we triggered.  Remove the old one.
-        outFile->Remove(PR_FALSE);
-    } else {
-        PRBool exists;
-        rv = outFile->Exists(&exists);
-        if (NS_FAILED(rv) || exists) {
-            // We already have a search plugin with this filename; don't
-            // replace it (bug 290038).
-            return NS_ERROR_UNEXPECTED;
-        }
-    }
-
-    nsCOMPtr<nsIOutputStream> outputStream, fileOutputStream;
-    rv = NS_NewLocalFileOutputStream(getter_AddRefs(fileOutputStream), outFile);
-    if (NS_FAILED(rv)) return rv;
-    rv = NS_NewBufferedOutputStream(getter_AddRefs(outputStream), fileOutputStream, 4096);
-    if (NS_FAILED(rv)) return rv;
-
-    PRUint32 bytesWritten;
-    for (PRInt32 loop=0; loop < bufferLength; loop++)
-    {
-        const char b = (const char) dataBuf[loop];
-        outputStream->Write(&b, 1, &bytesWritten);
-    }
-    outputStream->Flush();    
-    outputStream->Close();
-
-    if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT ||
-        contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT)
-    {
-        // check suggested category hint
-        const PRUnichar *hintUni = nsnull;
-        rv = context->GetHintConst(&hintUni);
-
-        // update graph with various required info
-        SaveEngineInfoIntoGraph(outFile, nsnull, hintUni, dataBuf, PR_FALSE);
-    }
-    else if (contextType == nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT ||
-             contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT)
-    {
-        // update graph with icon info
-        SaveEngineInfoIntoGraph(nsnull, outFile, nsnull, nsnull, PR_FALSE);
-    }
-
-  // after we're all done with the data buffer, get rid of it
-  context->Truncate();
-
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetInternetSearchURL(const char *searchEngineURI,
-  const PRUnichar *searchStr, PRInt16 direction, PRUint16 pageNumber, 
-  PRUint16 *whichButtons, PRUnichar **resultURL)
-{
-  if (!resultURL) return(NS_ERROR_NULL_POINTER);
-  *resultURL = nsnull;
-
-  // if we haven't already, load in the engines
-  if (!mEngineListBuilt)
-    DeferredInit();
-
-  nsresult      rv;
-  nsCOMPtr<nsIRDFResource>  engine;
-  rv = mRDFService->GetResource(nsDependentCString(searchEngineURI),
-                                getter_AddRefs(engine));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  validateEngine(engine);
-  
-  // if it's an engine from a search category, then get its "#Name",
-  // and try to map from that back to the real engine reference
-  if (isSearchCategoryEngineURI(engine))
-  {
-    nsCOMPtr<nsIRDFResource>  trueEngine;
-    rv = resolveSearchCategoryEngineURI(engine, getter_AddRefs(trueEngine));
-    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
-    if (!trueEngine)  return(NS_RDF_NO_VALUE);
-
-    engine = trueEngine;
-  }
-
-  nsCOMPtr<nsIRDFLiteral> dataLit;
-  rv = FindData(engine, getter_AddRefs(dataLit));
-  if (NS_FAILED(rv) ||
-      (rv == NS_RDF_NO_VALUE))  return(rv);
-  if (!dataLit) return(NS_ERROR_UNEXPECTED);
-
-  const PRUnichar *dataUni = nsnull;
-  dataLit->GetValueConst(&dataUni);
-  if (!dataUni) return(NS_RDF_NO_VALUE);
-
-  nsAutoString   text(searchStr), encodingStr, queryEncodingStr;
-
-  // first look for "search/queryCharset"... if that isn't specified,
-  // then fall back to looking for "search/queryEncoding" (a decimal)
-  GetData(dataUni, "search", 0, "queryCharset", queryEncodingStr);
-       if (queryEncodingStr.IsEmpty())
-  {
-    GetData(dataUni, "search", 0, "queryEncoding", encodingStr);    // decimal string values
-    MapEncoding(encodingStr, queryEncodingStr);
-  }
-
-  if (!queryEncodingStr.IsEmpty())
-  {
-    // remember query charset string
-    mQueryEncodingStr = queryEncodingStr;
-    // convert from escaped-UTF_8, to unicode, and then to
-    // the escaped version of the charset indicated by the dataset in question
-
-    char  *utf8data = ToNewUTF8String(text);
-    if (utf8data)
-    {
-      nsCOMPtr<nsITextToSubURI> textToSubURI = 
-               do_GetService(kTextToSubURICID, &rv);
-      if (NS_SUCCEEDED(rv) && (textToSubURI))
-      {
-        PRUnichar *uni = nsnull;
-        if (NS_SUCCEEDED(rv = textToSubURI->UnEscapeAndConvert("UTF-8", utf8data, &uni)) && (uni))
-        {
-          char    *charsetData = nsnull;
-          rv = textToSubURI->ConvertAndEscape(NS_LossyConvertUTF16toASCII(queryEncodingStr).get(),
-                                              uni,
-                                              &charsetData);
-          if (NS_SUCCEEDED(rv) && charsetData)
-          {
-            CopyASCIItoUTF16(nsDependentCString(charsetData), text);
-            NS_Free(charsetData);
-          }
-          NS_Free(uni);
-        }
-      }
-      NS_Free(utf8data);
-    }
-  }
-  
-  nsAutoString  action, input, method, userVar, name;
-  if (NS_FAILED(rv = GetData(dataUni, "search", 0, "action", action)))
-      return(rv);
-
-    // Search only supports the http protocol
-    if (!StringBeginsWith(action, NS_LITERAL_STRING("http:")) &&
-        !StringBeginsWith(action, NS_LITERAL_STRING("https:")))
-        return NS_ERROR_UNEXPECTED;
-
-  if (NS_FAILED(rv = GetData(dataUni, "search", 0, "method", method)))
-      return(rv);
-  if (NS_FAILED(rv = GetData(dataUni, "search", 0, "name", name)))
-      return(rv);
-  if (NS_FAILED(rv = GetInputs(dataUni, name, userVar, text, input, direction, pageNumber, whichButtons)))
-      return(rv);
-  // if the search string is null add a placeholder for the search string
-  if (!searchStr)
-  {
-    input.Append(input.IsEmpty() ? '?' : '&');
-    input.Append(userVar);
-    input.Append('=');
-  }
-  if (input.IsEmpty())        return(NS_ERROR_UNEXPECTED);
-
-  // we can only handle HTTP GET
-  if (!method.LowerCaseEqualsLiteral("get"))  return(NS_ERROR_UNEXPECTED);
-  // HTTP Get method support
-  action += input;
-
-  // return a copy of the resulting search URL
-  *resultURL = ToNewUnicode(action);
-  if (!resultURL)
-      return NS_ERROR_OUT_OF_MEMORY;
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::RememberLastSearchText(const PRUnichar *escapedSearchStr)
-{
-  nsresult    rv;
-
-  nsCOMPtr<nsIRDFNode>  textNode;
-  if (NS_SUCCEEDED(rv = mInner->GetTarget(mNC_LastSearchRoot, mNC_LastText, PR_TRUE,
-    getter_AddRefs(textNode))))
-  {
-    if (escapedSearchStr != nsnull)
-    {
-      nsresult    temprv;
-      nsCOMPtr<nsIRDFLiteral> textLiteral;
-      if (NS_SUCCEEDED(temprv = mRDFService->GetLiteral(escapedSearchStr, getter_AddRefs(textLiteral))))
-      {
-        if (rv != NS_RDF_NO_VALUE)
-        {
-          mInner->Change(mNC_LastSearchRoot, mNC_LastText, textNode, textLiteral);
-        }
-        else
-        {
-          mInner->Assert(mNC_LastSearchRoot, mNC_LastText, textLiteral, PR_TRUE);
-        }
-      }
-    }
-    else if (rv != NS_RDF_NO_VALUE)
-    {
-      rv = mInner->Unassert(mNC_LastSearchRoot, mNC_LastText, textNode);
-    }
-  }
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::FindInternetSearchResults(const char *url, PRBool *searchInProgress)
-{
-  *searchInProgress = PR_FALSE;
-
-  if (!mInner)  return(NS_OK);
-
-  // if the url doesn't look like a HTTP GET query, just return,
-  // otherwise strip off the query data
-  nsAutoString    shortURL;
-  CopyASCIItoUTF16(nsDependentCString(url), shortURL);
-  PRInt32     optionsOffset;
-  if ((optionsOffset = shortURL.FindChar(PRUnichar('?'))) < 0)  return(NS_OK);
-  shortURL.SetLength(optionsOffset);
-
-  // if we haven't already, load in the engines
-  if (!mEngineListBuilt)
-    DeferredInit();
-
-  // look in available engines to see if any of them appear
-  // to match this url (minus the GET options)
-  PRBool        foundEngine = PR_FALSE;
-  nsresult      rv;
-  nsCOMPtr<nsIRDFResource>  engine;
-  nsCOMPtr<nsISimpleEnumerator> arcs;
-  nsAutoString      engineURI;
-  nsCOMPtr<nsIRDFLiteral>   dataLit;
-  const PRUnichar     *dataUni = nsnull;
-
-  if (NS_SUCCEEDED(rv = mInner->GetTargets(mNC_SearchEngineRoot, mNC_Child,
-    PR_TRUE, getter_AddRefs(arcs))))
-  {
-    PRBool      hasMore = PR_TRUE;
-    while (hasMore)
-    {
-      if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || !hasMore)
-        break;
-      nsCOMPtr<nsISupports> arc;
-      if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))
-        break;
-
-      engine = do_QueryInterface(arc);
-      if (!engine)  continue;
-
-      const char  *uri = nsnull;
-      engine->GetValueConst(&uri);
-      if (uri)
-      {
-        CopyUTF8toUTF16(nsDependentCString(uri), engineURI);
-      }
-
-      if (NS_FAILED(rv = FindData(engine, getter_AddRefs(dataLit))) ||
-        (rv == NS_RDF_NO_VALUE))  continue;
-      if (!dataLit) continue;
-
-      dataLit->GetValueConst(&dataUni);
-      if (!dataUni) continue;
-
-      nsAutoString    action;
-      if (NS_FAILED(rv = GetData(dataUni, "search", 0, "action", action)))  continue;
-      if (shortURL.Equals(action, CaseInsensitiveCompare))
-      {
-        foundEngine = PR_TRUE;
-        break;
-      }
-
-      // extension for engines which can have multiple "actions"
-      if (NS_FAILED(rv = GetData(dataUni, "browser", 0, "alsomatch", action)))  continue;
-      if (action.Find(shortURL, CaseInsensitiveCompare) >= 0)
-      {
-        foundEngine = PR_TRUE;
-        break;
-      }
-    }
-  }
-  if (foundEngine)
-  {
-    nsAutoString  searchURL;
-    CopyASCIItoUTF16(nsDependentCString(url), searchURL);
-
-    // look for query option which is the string the user is searching for
-    nsAutoString  userVar, inputUnused, engineNameStr;
-    GetData(dataUni, "search", 0, "name", engineNameStr);
-
-    if (NS_FAILED(rv = GetInputs(dataUni, engineNameStr, userVar, EmptyString(), inputUnused, 0, 0, 0)))  return(rv);
-    if (userVar.IsEmpty())  return(NS_RDF_NO_VALUE);
-
-    nsAutoString  queryStr;
-    queryStr.Assign(PRUnichar('?'));
-    queryStr.Append(userVar);
-    queryStr.Append(PRUnichar('='));
-
-    PRInt32   queryOffset = searchURL.Find(queryStr, CaseInsensitiveCompare);
-    if (queryOffset < 0)
-    {
-      queryStr.Replace(0, 1, PRUnichar('&'));
-      queryOffset = searchURL.Find(queryStr, CaseInsensitiveCompare);
-    }
-
-    nsAutoString  searchText;
-    if (queryOffset >= 0)
-    {
-      PRInt32   andOffset;
-      searchText = Substring(searchURL, queryOffset + queryStr.Length());
-
-      if ((andOffset = searchText.FindChar(PRUnichar('&'))) >= 0)
-      {
-        searchText.SetLength(andOffset);
-      }
-    }
-    if (!searchText.IsEmpty())
-    {
-      // apply charset conversion to the search text
-      if (!mQueryEncodingStr.IsEmpty())
-      {
-        nsCOMPtr<nsITextToSubURI> textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
-        if (NS_SUCCEEDED(rv))
-        {
-          nsCAutoString escapedSearchText;
-          LossyCopyUTF16toASCII(searchText, escapedSearchText);
-
-          // encoding +'s so as to preserve distinction between + and %2B
-          PRInt32 offset = escapedSearchText.FindChar('%');
-          while (offset != -1) {
-            escapedSearchText.Replace(offset, 1, "%25");
-            offset = escapedSearchText.FindChar('%', offset + 3);
-          }
-          offset = escapedSearchText.FindChar('+');
-          while (offset != -1) {
-            escapedSearchText.Replace(offset, 1, "%2B");
-            offset = escapedSearchText.FindChar('+', offset + 3);
-          }
-
-          PRUnichar *uni = nsnull;
-          rv = textToSubURI->UnEscapeAndConvert(NS_LossyConvertUTF16toASCII(mQueryEncodingStr).get(),
-                                                escapedSearchText.get(), &uni);
-          if (NS_SUCCEEDED(rv) && uni)
-          {
-            char  *convertedSearchText = nsnull;
-            if (NS_SUCCEEDED(rv = textToSubURI->ConvertAndEscape("UTF-8", uni, &convertedSearchText)))
-            {
-
-              // decoding +'s thereby preserving distinction between + and %2B
-              nsCAutoString unescapedSearchText(convertedSearchText);
-              offset = unescapedSearchText.Find(NS_LITERAL_CSTRING("%2B"));
-              while (offset != -1) {
-                unescapedSearchText.Replace(offset, 3, '+');
-                offset = unescapedSearchText.Find(NS_LITERAL_CSTRING("%2B"), offset + 1);
-              }
-              offset = unescapedSearchText.Find(NS_LITERAL_CSTRING("%25"));
-              while (offset != -1) {
-                unescapedSearchText.Replace(offset, 3, '%');
-                offset = unescapedSearchText.Find(NS_LITERAL_CSTRING("%25"), offset + 1);
-              }
-
-              CopyUTF8toUTF16(unescapedSearchText, searchText);
-
-              NS_Free(convertedSearchText);
-            }
-            NS_Free(uni);
-          }
-        }
-      }
-      // remember the text of the last search
-      RememberLastSearchText(searchText.get());
-
-      // construct the search query uri
-      engineURI.Insert(NS_LITERAL_STRING("internetsearch:engine="), 0);
-      engineURI.Append(NS_LITERAL_STRING("&text="));
-      engineURI.Append(searchText);
-
-#ifdef  DEBUG_SEARCH_OUTPUT
-      printf("FindInternetSearchResults: search for: '%s'\n\n",
-        NS_ConvertUTF16toUTF8(searchText).get());
-#endif
-    }
-    else
-    {
-      // not able to determine engine URI, so just use the search URL
-      engineURI = searchURL;
-
-      // clear the text of the last search
-      RememberLastSearchText(nsnull);
-    }
-
-    // update "#Ref" on LastSearchRoot
-    nsCOMPtr<nsIRDFNode>  oldNode;
-    if (NS_SUCCEEDED(rv = mInner->GetTarget(mNC_LastSearchRoot, mNC_Ref, PR_TRUE,
-      getter_AddRefs(oldNode))))
-    {
-      if (!engineURI.IsEmpty())
-      {
-        const PRUnichar *uriUni = engineURI.get();
-        nsCOMPtr<nsIRDFLiteral> uriLiteral;
-        nsresult    temprv;
-        if ((uriUni) && (NS_SUCCEEDED(temprv = mRDFService->GetLiteral(uriUni,
-          getter_AddRefs(uriLiteral)))))
-        {
-          if (rv != NS_RDF_NO_VALUE)
-          {
-            rv = mInner->Change(mNC_LastSearchRoot, mNC_Ref, oldNode, uriLiteral);
-          }
-          else
-          {
-            rv = mInner->Assert(mNC_LastSearchRoot, mNC_Ref, uriLiteral, PR_TRUE);
-          }
-        }
-      }
-      else
-      {
-        rv = mInner->Unassert(mNC_LastSearchRoot, mNC_Ref, oldNode);
-      }
-    }
-
-    // forget about any previous search results
-    ClearResults(PR_FALSE);
-
-    // do the search
-    DoSearch(nsnull, engine, searchURL, EmptyString());
-
-    *searchInProgress = PR_TRUE;
-  }
-
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::ClearResults(PRBool flushLastSearchRef)
-{
-  if (!mInner)  return(NS_ERROR_UNEXPECTED);
-
-  // forget any nodes under the last search root
-  nsresult      rv;
-  nsCOMPtr<nsISimpleEnumerator> arcs;
-  if (NS_SUCCEEDED(rv = mInner->GetTargets(mNC_LastSearchRoot, mNC_Child, PR_TRUE, getter_AddRefs(arcs))))
-  {
-    PRBool      hasMore = PR_TRUE;
-    while (hasMore)
-    {
-      if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || !hasMore)
-        break;
-      nsCOMPtr<nsISupports> arc;
-      if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))
-        break;
-      nsCOMPtr<nsIRDFResource> child (do_QueryInterface(arc));
-      if (child)
-      {
-        mInner->Unassert(mNC_LastSearchRoot, mNC_Child, child);
-      }
-
-      // *after* (so that we won't thrash the XUL template builder) unasserting
-      // child node, determine if there are any other references to the child
-      // node in the graph
-
-      PRBool hasInArcs = PR_FALSE;
-      nsCOMPtr<nsISimpleEnumerator> inArcs;
-      if (NS_FAILED(mInner->ArcLabelsIn(child, getter_AddRefs(inArcs))) ||
-        (!inArcs))
-        continue;
-      if (NS_FAILED(inArcs->HasMoreElements(&hasInArcs)) || hasInArcs)
-        continue;
-
-      // no other references, so also unassert any outgoing arcs
-
-      nsCOMPtr<nsISimpleEnumerator> outArcs;
-      if (NS_FAILED(mInner->ArcLabelsOut(child, getter_AddRefs(outArcs))) ||
-        (!outArcs))
-        continue;
-      PRBool  hasMoreOutArcs = PR_TRUE;
-      while (hasMoreOutArcs)
-      {
-        if (NS_FAILED(outArcs->HasMoreElements(&hasMoreOutArcs)) ||
-            !hasMoreOutArcs)
-          break;
-        nsCOMPtr<nsISupports> outArc;
-        if (NS_FAILED(outArcs->GetNext(getter_AddRefs(outArc))))
-          break;
-        nsCOMPtr<nsIRDFResource> property (do_QueryInterface(outArc));
-        if (!property)
-          continue;
-        nsCOMPtr<nsIRDFNode> target;
-        if (NS_FAILED(mInner->GetTarget(child, property, PR_TRUE,
-          getter_AddRefs(target))) || (!target))
-          continue;
-        mInner->Unassert(child, property, target);
-      }
-    }
-  }
-
-  if (flushLastSearchRef)
-  {
-    // forget the last search query
-    nsCOMPtr<nsIRDFNode>  lastTarget;
-    if (NS_SUCCEEDED(rv = mInner->GetTarget(mNC_LastSearchRoot, mNC_Ref,
-      PR_TRUE, getter_AddRefs(lastTarget))) && (rv != NS_RDF_NO_VALUE))
-    {
-      nsCOMPtr<nsIRDFLiteral> lastLiteral (do_QueryInterface(lastTarget));
-      if (lastLiteral)
-      {
-        rv = mInner->Unassert(mNC_LastSearchRoot, mNC_Ref, lastLiteral);
-      }
-    }
-  }
-
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::ClearResultSearchSites(void)
-{
-  // forget about any previous search sites
-
-  if (mInner)
-  {
-    nsresult      rv;
-    nsCOMPtr<nsISimpleEnumerator> arcs;
-    if (NS_SUCCEEDED(rv = mInner->GetTargets(mNC_SearchResultsSitesRoot, mNC_Child, PR_TRUE, getter_AddRefs(arcs))))
-    {
-      PRBool      hasMore = PR_TRUE;
-      while (hasMore)
-      {
-        if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || !hasMore)
-          break;
-        nsCOMPtr<nsISupports> arc;
-        if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))
-          break;
-        nsCOMPtr<nsIRDFResource> child (do_QueryInterface(arc));
-        if (child)
-        {
-          mInner->Unassert(mNC_SearchResultsSitesRoot, mNC_Child, child);
-        }
-      }
-    }
-  }
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::GetCategoryDataSource(nsIRDFDataSource **ds)
-{
-  nsresult  rv;
-
-  if (!categoryDataSource)
-  {
-    if (NS_FAILED(rv = GetCategoryList()))
-    {
-      *ds = nsnull;
-      return(rv);
-    }
-  }
-  if (categoryDataSource)
-  {
-    *ds = categoryDataSource.get();
-    NS_IF_ADDREF(*ds);
-    return(NS_OK);
-  }
-  *ds = nsnull;
-  return(NS_ERROR_FAILURE);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::Stop()
-{
-  nsresult    rv;
-
-  // cancel any outstanding connections
-  if (mLoadGroup)
-  {
-    nsCOMPtr<nsISimpleEnumerator> requests;
-    if (NS_SUCCEEDED(rv = mLoadGroup->GetRequests(getter_AddRefs(requests))))
-    {
-      PRBool      more;
-      while (NS_SUCCEEDED(rv = requests->HasMoreElements(&more)) && more)
-      {
-        nsCOMPtr<nsISupports> isupports;
-        if (NS_FAILED(rv = requests->GetNext(getter_AddRefs(isupports))))
-          break;
-        nsCOMPtr<nsIRequest> request (do_QueryInterface(isupports));
-        if (!request) continue;
-        request->Cancel(NS_BINDING_ABORTED);
-      }
-    }
-    mLoadGroup->Cancel(NS_BINDING_ABORTED);
-  }
-
-  // remove any loading icons
-  nsCOMPtr<nsISimpleEnumerator> arcs;
-  if (NS_SUCCEEDED(rv = mInner->GetSources(mNC_loading, mTrueLiteral, PR_TRUE,
-    getter_AddRefs(arcs))))
-  {
-    PRBool      hasMore = PR_TRUE;
-    while (hasMore)
-    {
-      if (NS_FAILED(arcs->HasMoreElements(&hasMore)) || !hasMore)
-        break;
-      nsCOMPtr<nsISupports> arc;
-      if (NS_FAILED(arcs->GetNext(getter_AddRefs(arc))))
-        break;
-      nsCOMPtr<nsIRDFResource> src (do_QueryInterface(arc));
-      if (src)
-      {
-        mInner->Unassert(src, mNC_loading, mTrueLiteral);
-      }
-    }
-  }
-
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::BeginSearchRequest(nsIRDFResource *source, PRBool doNetworkRequest)
-{
-        nsresult    rv = NS_OK;
-  const char    *sourceURI = nsnull;
-
-  if (NS_FAILED(rv = source->GetValueConst(&sourceURI)))
-    return(rv);
-  nsAutoString    uri;
-  CopyUTF8toUTF16(nsDependentCString(sourceURI), uri);
-
-  if (uri.Find("internetsearch:") != 0)
-    return(NS_ERROR_FAILURE);
-
-  // forget about any previous search results
-  ClearResults(PR_TRUE);
-
-  // forget about any previous search sites
-  ClearResultSearchSites();
-
-  // remember the last search query
-  const PRUnichar *uriUni = uri.get();
-  nsCOMPtr<nsIRDFLiteral> uriLiteral;
-  if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(uriUni, getter_AddRefs(uriLiteral))))
-  {
-    rv = mInner->Assert(mNC_LastSearchRoot, mNC_Ref, uriLiteral, PR_TRUE);
-  }
-
-  uri.Cut(0, strlen("internetsearch:"));
-
-  nsVoidArray *engineArray = new nsVoidArray;
-  if (!engineArray)
-    return(NS_ERROR_FAILURE);
-
-  nsAutoString  text;
-
-  // parse up attributes
-
-  while(!uri.IsEmpty())
-  {
-    nsAutoString  item;
-
-    PRInt32 andOffset = uri.Find("&");
-    if (andOffset >= 0)
-    {
-      item = StringHead(uri, andOffset);
-      uri.Cut(0, andOffset + 1);
-    }
-    else
-    {
-      item = uri;
-      uri.Truncate();
-    }
-
-    PRInt32 equalOffset = item.Find("=");
-    if (equalOffset < 0)  break;
-    
-    nsAutoString  attrib(StringHead(item, equalOffset)), value(item);
-    value.Cut(0, equalOffset + 1);
-    
-    if (!attrib.IsEmpty() && !value.IsEmpty())
-    {
-      if (attrib.LowerCaseEqualsLiteral("engine"))
-      {
-        if ((value.Find(kEngineProtocol) == 0) ||
-          (value.Find(kURINC_SearchCategoryEnginePrefix) == 0))
-        {
-          char  *val = ToNewCString(NS_LossyConvertUTF16toASCII(value));
-          if (val)
-          {
-            engineArray->AppendElement(val);
-          }
-        }
-      }
-      else if (attrib.LowerCaseEqualsLiteral("text"))
-      {
-        text = value;
-      }
-    }
-  }
-
-  mInner->Assert(source, mNC_loading, mTrueLiteral, PR_TRUE);
-
-  PRBool  requestInitiated = PR_FALSE;
-
-  // loop over specified search engines
-  while (engineArray->Count() > 0)
-  {
-    char *baseFilename = (char *)(engineArray->ElementAt(0));
-    engineArray->RemoveElementAt(0);
-    if (!baseFilename)  continue;
-
-#ifdef  DEBUG_SEARCH_OUTPUT
-    printf("Search engine to query: '%s'\n", baseFilename);
-#endif
-
-    nsCOMPtr<nsIRDFResource>  engine;
-    mRDFService->GetResource(nsDependentCString(baseFilename), getter_AddRefs(engine));
-    NS_Free(baseFilename);
-    baseFilename = nsnull;
-    if (!engine)  continue;
-
-    // if it's an engine from a search category, then get its "#Name",
-    // and map from that back to the real engine reference; if an
-    // error occurs, finish processing the rest of the engines,
-    // don't just break/return out
-    if (isSearchCategoryEngineURI(engine))
-    {
-      nsCOMPtr<nsIRDFResource>  trueEngine;
-      rv = resolveSearchCategoryEngineURI(engine, getter_AddRefs(trueEngine));
-      if (NS_FAILED(rv) || !trueEngine)
-        continue;
-      engine = trueEngine;
-    }
-
-    // mark this as a search site
-    if (mInner)
-    {
-      mInner->Assert(mNC_SearchResultsSitesRoot, mNC_Child, engine, PR_TRUE);
-    }
-
-    if (doNetworkRequest)
-    {
-      DoSearch(source, engine, EmptyString(), text);
-      requestInitiated = PR_TRUE;
-    }
-  }
-  
-  delete engineArray;
-  engineArray = nsnull;
-
-  if (!requestInitiated)
-  {
-    Stop();
-  }
-
-  return(rv);
-}
-
-
-
-nsresult
-InternetSearchDataSource::FindData(nsIRDFResource *engine, nsIRDFLiteral **dataLit)
-{
-  if (!engine)  return(NS_ERROR_NULL_POINTER);
-  if (!dataLit) return(NS_ERROR_NULL_POINTER);
-
-  *dataLit = nsnull;
-
-  if (!mInner)  return(NS_RDF_NO_VALUE);
-
-  nsresult    rv;
-
-  nsCOMPtr<nsIRDFNode>  dataTarget = nsnull;
-  if (NS_SUCCEEDED((rv = mInner->GetTarget(engine, mNC_Data, PR_TRUE,
-    getter_AddRefs(dataTarget)))) && (dataTarget))
-  {
-    nsCOMPtr<nsIRDFLiteral> aLiteral (do_QueryInterface(dataTarget));
-    if (!aLiteral)
-      return(NS_ERROR_UNEXPECTED);
-    *dataLit = aLiteral;
-    NS_IF_ADDREF(*dataLit);
-    return(NS_OK);
-  }
-
-        nsCOMPtr<nsILocalFile> engineFile;
-        rv = EngineFileFromResource(engine, getter_AddRefs(engineFile));
-        if (NS_FAILED(rv)) return rv;
-
-        nsString  data;
-        rv = ReadFileContents(engineFile, data);
-
-  if (NS_FAILED(rv))
-  {
-    return(rv);
-  }
-
-  // save file contents
-  if (data.IsEmpty()) return(NS_ERROR_UNEXPECTED);
-
-  rv = updateDataHintsInGraph(engine, data.get());
-
-  nsCOMPtr<nsIRDFLiteral> aLiteral;
-  if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(data.get(), getter_AddRefs(aLiteral))))
-  {
-    *dataLit = aLiteral;
-    NS_IF_ADDREF(*dataLit);
-  }
-  
-  return(rv);
-}
-
-nsresult
-InternetSearchDataSource::EngineFileFromResource(nsIRDFResource *aResource,
-                                                 nsILocalFile **aResult)
-{
-  nsresult rv = NS_OK;
-
-  // get resource uri
-  const char *engineURI = nsnull;
-  rv = aResource->GetValueConst(&engineURI);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // remove protocol from uri and get escaped file path
-  nsCAutoString nativePath;
-  nativePath.Assign(engineURI);
-
-  NS_ENSURE_TRUE(StringBeginsWith(nativePath,
-                                  NS_LITERAL_CSTRING(kEngineProtocol)),
-                 NS_ERROR_FAILURE);
-  nativePath.Cut(0, sizeof(kEngineProtocol) - 1);
-
-  // unescape it
-  nsCOMPtr<nsINetUtil> netUtil = do_GetService(NS_NETUTIL_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCString nativePathSrc = nativePath;
-  rv = netUtil->UnescapeString(nativePathSrc, 0, nativePath);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-#ifdef DEBUG_SEARCH_OUTPUT
-  printf("InternetSearchDataSource::EngineFileFromResource\n"
-         "File Path: %s\n",
-         nativePath.get());
-#endif
-
-  rv = NS_NewNativeLocalFile(nativePath, PR_TRUE, aResult);
-
-  return rv;
-}
-
-nsresult
-InternetSearchDataSource::DecodeData(const char *aCharset, const PRUnichar *aInString, PRUnichar **aOutString)
-{
-  nsresult rv;
-    
-  nsCOMPtr <nsICharsetConverterManager> charsetConv = 
-          do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
-  rv = charsetConv->GetUnicodeDecoder(aCharset, getter_AddRefs(unicodeDecoder));
-
-  // Use the sherlock default charset in case of failure
-  if (NS_FAILED(rv))
-    rv = charsetConv->GetUnicodeDecoderRaw("x-mac-roman", getter_AddRefs(unicodeDecoder));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // This fixes the corruption occured in InternetSearchDataSource::ReadFileContents()
-  // (eg. aValue contains "0x0082 0x00a1" for "0x82 0xa1" shift_jis double-byte char)
-  NS_LossyConvertUTF16toASCII value(aInString);
-
-  PRInt32 srcLength = value.Length();
-  PRInt32 outUnicodeLen;
-  rv = unicodeDecoder->GetMaxLength(value.get(), srcLength, &outUnicodeLen);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  *aOutString = reinterpret_cast<PRUnichar*>(nsMemory::Alloc((outUnicodeLen + 1) * sizeof(PRUnichar)));
-  NS_ENSURE_TRUE(*aOutString, NS_ERROR_OUT_OF_MEMORY);
-
-  rv = unicodeDecoder->Convert(value.get(), &srcLength, *aOutString, &outUnicodeLen);
-  NS_ENSURE_SUCCESS(rv, rv);
-  (*aOutString)[outUnicodeLen] = (PRUnichar)'\0';
-
-  return rv;
-}
-
-nsresult
-InternetSearchDataSource::updateDataHintsInGraph(nsIRDFResource *engine, const PRUnichar *dataUni)
-{
-  nsresult  rv = NS_OK;
-
-  // save/update search engine data
-  nsCOMPtr<nsIRDFLiteral> dataLiteral;
-  if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(dataUni, getter_AddRefs(dataLiteral))))
-  {
-    updateAtom(mInner, engine, mNC_Data, dataLiteral, nsnull);
-  }
-
-  // save/update name of search engine (as specified in file)
-  nsAutoString scriptCodeValue;
-  const char * charsetName = MapScriptCodeToCharsetName(0);
-  nsString decodedValue;
-
-  if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "sourceTextEncoding", scriptCodeValue)) && 
-    !scriptCodeValue.IsEmpty())
-  {
-    PRInt32 scriptCode = scriptCodeValue.ToInteger(&rv);
-    if (NS_SUCCEEDED(rv))
-      charsetName = MapScriptCodeToCharsetName(scriptCode);
-  }
-
-  nsAutoString  nameValue;
-  if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "name", nameValue)))
-  {
-    rv = DecodeData(charsetName, nameValue.get(), getter_Copies(decodedValue));
-    nsCOMPtr<nsIRDFLiteral> nameLiteral;
-    if (NS_SUCCEEDED(rv) &&
-        NS_SUCCEEDED(rv = mRDFService->GetLiteral(decodedValue.get(),
-                                                  getter_AddRefs(nameLiteral))))
-    {
-      rv = updateAtom(mInner, engine, mNC_Name, nameLiteral, nsnull);
-    }
-  }
-
-  // save/update description of search engine (if specified)
-  nsAutoString  descValue;
-  if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "description", descValue)))
-  {
-    rv = DecodeData(charsetName, descValue.get(), getter_Copies(decodedValue));
-    nsCOMPtr<nsIRDFLiteral> descLiteral;
-    if (NS_SUCCEEDED(rv) &&
-        NS_SUCCEEDED(rv = mRDFService->GetLiteral(decodedValue.get(),
-                                                  getter_AddRefs(descLiteral))))
-    {
-      rv = updateAtom(mInner, engine, mNC_Description, descLiteral, nsnull);
-    }
-  }
-
-  // save/update version of search engine (if specified)
-  nsAutoString  versionValue;
-  if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "version", versionValue)))
-  {
-    nsCOMPtr<nsIRDFLiteral> versionLiteral;
-    if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(versionValue.get(),
-        getter_AddRefs(versionLiteral))))
-    {
-      rv = updateAtom(mInner, engine, mNC_Version, versionLiteral, nsnull);
-    }
-  }
-
-  nsAutoString  buttonValue;
-  if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "actionButton", buttonValue)))
-  {
-    nsCOMPtr<nsIRDFLiteral> buttonLiteral;
-    if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(buttonValue.get(),
-        getter_AddRefs(buttonLiteral))))
-    {
-      rv = updateAtom(mInner, engine, mNC_actionButton, buttonLiteral, nsnull);
-    }
-  }
-
-  nsAutoString  barValue;
-  if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "actionBar", barValue)))
-  {
-    nsCOMPtr<nsIRDFLiteral> barLiteral;
-    if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(barValue.get(),
-        getter_AddRefs(barLiteral))))
-    {
-      rv = updateAtom(mInner, engine, mNC_actionBar, barLiteral, nsnull);
-    }
-  }
-
-  nsAutoString  searchFormValue;
-  if (NS_SUCCEEDED(rv = GetData(dataUni, "search", 0, "searchForm", searchFormValue)))
-  {
-    nsCOMPtr<nsIRDFLiteral> searchFormLiteral;
-    if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(searchFormValue.get(),
-        getter_AddRefs(searchFormLiteral))))
-    {
-      rv = updateAtom(mInner, engine, mNC_searchForm, searchFormLiteral, nsnull);
-    }
-  }
-
-
-  PRBool  updatePrivateFiles = PR_FALSE;
-
-  rv = mInner->HasAssertion(engine, mNC_SearchType, mNC_Engine, PR_TRUE,
-                            &updatePrivateFiles);
-  if (NS_SUCCEEDED(rv) && updatePrivateFiles)
-  {
-    // rjc says: so here is our strategy. The spec says that the "search"|"update"
-    // attribute MUST refer to a binhex-ed file (i.e. ends with ".src.hqx"). We don't
-    // support binhex (due to being cross-platform minded folks) and, even if we did,
-    // its not enough info to figure out what the appropriate icon should be.
-    // The answer: we're add additional attributes in our private <BROWSER> section
-    // to re-define these values. If they aren't there, we'll fallback to the <SEARCH>
-    // section values and try and make logical choices:  for example, if we have an
-    // "update" URL which ends with ".src.hqx", we'll strip off the ".hqx" part and
-    // check to see if it exists... which at least makes it possible for a web site
-    // to put up both a binhexed version and a straight text version of the search file.
-
-    // get update URL and # of days to check for updates
-    // Note: only check for updates on our private search files
-    nsAutoString  updateStr, updateIconStr, updateCheckDaysStr;
-
-    GetData(dataUni, "browser", 0, "update", updateStr);
-    if (updateStr.IsEmpty())
-    {
-      // fallback to trying "search"|"updateCheckDays"
-      GetData(dataUni, "search", 0, "update", updateStr);
-
-      // if we have a ".hqx" extension, strip it off
-      if (StringEndsWith(updateStr, NS_LITERAL_STRING(".hqx"), CaseInsensitiveCompare))
-      {
-        updateStr.SetLength(updateStr.Length() - 4);
-      }
-
-      // now, either way, ensure that we have a ".src" file
-      if (!StringEndsWith(updateStr, NS_LITERAL_STRING(".src"), CaseInsensitiveCompare))
-      {
-        // and if we don't, toss it
-        updateStr.Truncate();
-      }
-    }
-    else
-    {
-      // note: its OK if the "updateIcon" isn't specified
-      GetData(dataUni, "browser", 0, "updateIcon", updateIconStr);
-    }
-    if (!updateStr.IsEmpty())
-    {
-      GetData(dataUni, "browser", 0, "updateCheckDays", updateCheckDaysStr);
-      if (updateCheckDaysStr.IsEmpty())
-      {
-        // fallback to trying "search"|"updateCheckDays"
-        GetData(dataUni, "search", 0, "updateCheckDays", updateCheckDaysStr);
-      }
-    }
-
-    if (!updateStr.IsEmpty() && !updateCheckDaysStr.IsEmpty())
-    {
-      nsCOMPtr<nsIRDFLiteral> updateLiteral;
-      if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(updateStr.get(),
-          getter_AddRefs(updateLiteral))))
-      {
-        rv = updateAtom(mInner, engine, mNC_Update, updateLiteral, nsnull);
-      }
-
-      PRInt32 updateDays = updateCheckDaysStr.ToInteger(&rv);
-      if (NS_FAILED(rv) || (updateDays < 1))
-      {
-        // default to something sane
-        updateDays = 3;
-      }
-
-      nsCOMPtr<nsIRDFInt> updateCheckDaysLiteral;
-      if (NS_SUCCEEDED(rv = mRDFService->GetIntLiteral(updateDays,
-          getter_AddRefs(updateCheckDaysLiteral))))
-      {
-        rv = updateAtom(mInner, engine, mNC_UpdateCheckDays, updateCheckDaysLiteral, nsnull);
-      }
-
-      if (!updateIconStr.IsEmpty())
-      {
-        nsCOMPtr<nsIRDFLiteral> updateIconLiteral;
-        if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(updateIconStr.get(),
-            getter_AddRefs(updateIconLiteral))))
-        {
-          rv = updateAtom(mInner, engine, mNC_UpdateIcon, updateIconLiteral, nsnull);
-        }
-      }
-    }
-  }
-
-  return(rv);
-}
-
-
-
-nsresult
-InternetSearchDataSource::updateAtom(nsIRDFDataSource *db, nsIRDFResource *src,
-      nsIRDFResource *prop, nsIRDFNode *newValue, PRBool *dirtyFlag)
-{
-  nsresult    rv;
-  nsCOMPtr<nsIRDFNode>  oldValue;
-
-  if (dirtyFlag != nsnull)
-  {
-    *dirtyFlag = PR_FALSE;
-  }
-
-  if (NS_SUCCEEDED(rv = db->GetTarget(src, prop, PR_TRUE, getter_AddRefs(oldValue))) &&
-    (rv != NS_RDF_NO_VALUE))
-  {
-    rv = db->Change(src, prop, oldValue, newValue);
-
-    if ((oldValue.get() != newValue) && (dirtyFlag != nsnull))
-    {
-      *dirtyFlag = PR_TRUE;
-    }
-  }
-  else
-  {
-    rv = db->Assert(src, prop, newValue, PR_TRUE);
-    if (dirtyFlag != nsnull)
-    {
-        *dirtyFlag = PR_TRUE;
-    }
-  }
-  return(rv);
-}
-
-
-
-struct  encodings
-{
-  const char  *numericEncoding;
-  const char  *stringEncoding;
-};
-
-
-
-nsresult
-InternetSearchDataSource::MapEncoding(const nsString &numericEncoding, 
-                                      nsString &stringEncoding)
-{
-  // XXX we need to have a full table of numeric --> string conversions
-
-  struct  encodings encodingList[] =
-  {
-    { "0", "x-mac-roman"  },
-    { "6", "x-mac-greek"  },
-    { "35", "x-mac-turkish" },
-    { "513", "ISO-8859-1" },
-    { "514", "ISO-8859-2" },
-    { "517", "ISO-8859-5" },
-    { "518", "ISO-8859-6" },
-    { "519", "ISO-8859-7" },
-    { "520", "ISO-8859-8" },
-    { "521", "ISO-8859-9" },
-    { "1049", "IBM864"  },
-    { "1280", "windows-1252"  },
-    { "1281", "windows-1250"  },
-    { "1282", "windows-1251"  },
-    { "1283", "windows-1253"  },
-    { "1284", "windows-1254"  },
-    { "1285", "windows-1255"  },
-    { "1286", "windows-1256"  },
-    { "1536", "us-ascii"  },
-    { "1584", "GB2312"  },
-    { "1585", "x-gbk"   },
-    { "1600", "EUC-KR"  },
-    { "2080", "ISO-2022-JP" },
-    { "2096", "ISO-2022-CN" },
-    { "2112", "ISO-2022-KR" },
-    { "2336", "EUC-JP"  },
-    { "2352", "GB2312"  },
-    { "2353", "x-euc-tw"  },
-    { "2368", "EUC-KR"  },
-    { "2561", "Shift_JIS" },
-    { "2562", "KOI8-R"  },
-    { "2563", "Big5"    },
-    { "2565", "HZ-GB-2312"  },
-
-    { nsnull, nsnull    }
-  };
-
-  if (!numericEncoding.IsEmpty()) {
-    NS_LossyConvertUTF16toASCII numericEncodingASCII(numericEncoding);
-    for (PRUint32 i = 0; encodingList[i].numericEncoding != nsnull; i++)
-    {
-      if (numericEncodingASCII.Equals(encodingList[i].numericEncoding))
-      {
-        stringEncoding.Assign(NS_ConvertASCIItoUTF16(encodingList[i].stringEncoding));
-        return NS_OK;
-      }
-    }
-  }
-
-  // Still no encoding, fall back to default charset if possible
-  nsString defCharset;
-  nsCOMPtr<nsIPrefBranch> prefs(do_GetService(NS_PREFSERVICE_CONTRACTID));
-  if (prefs) {
-    nsCOMPtr<nsIPrefLocalizedString> localizedStr;
-    nsresult rv = prefs->GetComplexValue("intl.charset.default",
-                                         NS_GET_IID(nsIPrefLocalizedString),
-                                         getter_AddRefs(localizedStr));
-    if (NS_SUCCEEDED(rv))
-      localizedStr->GetData(getter_Copies(defCharset));
-  }
-
-  if (!defCharset.IsEmpty())
-    stringEncoding = defCharset;
-  else
-    // make "ISO-8859-1" as the default (not "UTF-8")
-    stringEncoding.AssignLiteral("ISO-8859-1");
-
-  return(NS_OK);
-}
-
-
-
-const char * const
-InternetSearchDataSource::MapScriptCodeToCharsetName(PRUint32 aScriptCode)
-{
-  // Script codes listed here are taken from Inside Macintosh Text.
-  // Used TECGetTextEncodingInternetName to map script code to charset name.
-  // Some are edited to match with standard name (e.g. "x-mac-japanese" -> "Shift_JIS").
-  // In case no converter can be found for a charset name, 
-  // the default sherlock charset "x-mac-roman" should be used.
-  // 
-        static const char* const scriptList[] =
-  {
-    "x-mac-roman",           // 0
-    "Shift_JIS",             // 1
-    "Big5",                  // 2
-    "EUC-KR",                // 3
-    "X-MAC-ARABIC",          // 4
-    "X-MAC-HEBREW",          // 5
-    "X-MAC-GREEK",           // 6
-    "X-MAC-CYRILLIC",        // 7
-    "X-MAC-DEVANAGARI" ,     // 9
-    "X-MAC-GURMUKHI",        // 10
-    "X-MAC-GUJARATI",        // 11
-    "X-MAC-ORIYA",           // 12
-    "X-MAC-BENGALI",         // 13
-    "X-MAC-TAMIL",           // 14
-    "X-MAC-TELUGU",          // 15
-    "X-MAC-KANNADA",         // 16
-    "X-MAC-MALAYALAM",       // 17
-    "X-MAC-SINHALESE",       // 18
-    "X-MAC-BURMESE",         // 19
-    "X-MAC-KHMER",           // 20
-    "X-MAC-THAI",            // 21
-    "X-MAC-LAOTIAN",         // 22
-    "X-MAC-GEORGIAN",        // 23
-    "X-MAC-ARMENIAN",        // 24
-    "GB2312",                // 25
-    "X-MAC-TIBETAN",         // 26
-    "X-MAC-MONGOLIAN",       // 27
-    "X-MAC-ETHIOPIC",        // 28
-    "X-MAC-CENTRALEURROMAN", // 29
-    "X-MAC-VIETNAMESE",      // 30
-    "X-MAC-EXTARABIC",       // 31
-  };
-
-        if (aScriptCode >= NS_ARRAY_LENGTH(scriptList))
-          aScriptCode = 0;
-
-  return scriptList[aScriptCode];
-}
-
-
-nsresult
-InternetSearchDataSource::validateEngine(nsIRDFResource *engine)
-{
-  nsresult  rv;
-
-  // confirm whether the user wants to update plugins.
-  nsCOMPtr<nsIPrefBranch>
-    prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRBool userAllowed = PR_TRUE;
-  rv = prefBranch->GetBoolPref("browser.search.update", &userAllowed);
-  // if the pref value is not set or wrong type, don't stop here.
-  if (NS_SUCCEEDED(rv) && !userAllowed)
-    return NS_OK;
-
-#ifdef  DEBUG_SEARCH_UPDATES
-  const char  *engineURI = nsnull;
-  engine->GetValueConst(&engineURI);
-#endif
-
-  // get the engines "updateCheckDays" value
-  nsCOMPtr<nsIRDFNode>  updateCheckDaysNode;
-  rv = mInner->GetTarget(engine, mNC_UpdateCheckDays, PR_TRUE, getter_AddRefs(updateCheckDaysNode));
-  if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE)) return(rv);
-  nsCOMPtr<nsIRDFInt> updateCheckDaysLiteral (do_QueryInterface(updateCheckDaysNode));
-  PRInt32   updateCheckDays;
-  updateCheckDaysLiteral->GetValue(&updateCheckDays);
-  // convert updateCheckDays from days to seconds;
-
-#ifndef DEBUG_SEARCH_UPDATES
-  PRInt32   updateCheckSecs = updateCheckDays * (60 * 60 * 24);
-#else
-  // rjc note: for debugging, use as minutes instead days
-  PRInt32   updateCheckSecs = updateCheckDays * 60;
-#endif
-
-  nsCOMPtr<nsIRDFNode>  aNode;
-  rv = mLocalstore->GetTarget(engine, mWEB_LastPingDate, PR_TRUE, getter_AddRefs(aNode));
-  if (NS_FAILED(rv))  return(rv);
-
-  // if aNode is a valid entry, we should check the durationSecs.
-  if (rv != NS_RDF_NO_VALUE) {
-    // get last validate date/time
-    nsCOMPtr<nsIRDFLiteral> lastCheckLiteral(do_QueryInterface(aNode));
-    if (!lastCheckLiteral)
-      return NS_ERROR_UNEXPECTED;
-
-    const PRUnichar *lastCheckUni = nsnull;
-    lastCheckLiteral->GetValueConst(&lastCheckUni);
-    if (!lastCheckUni)
-      return NS_ERROR_UNEXPECTED;
-
-    PRInt32 lastCheckInt = 0;
-    lastCheckInt = nsDependentString(lastCheckUni).ToInteger(&rv);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // get the current date/time [from microseconds (PRTime) to seconds]
-    PRTime now64 = PR_Now(), temp64, million;
-    LL_I2L(million, PR_USEC_PER_SEC);
-    LL_DIV(temp64, now64, million);
-    PRInt32 now32;
-    LL_L2I(now32, temp64);
-
-    // calculate duration since last validation
-    // just return if it's too early to check again
-    PRInt32 durationSecs = now32 - lastCheckInt;
-
-    if (durationSecs < updateCheckSecs) {
-#ifdef  DEBUG_SEARCH_UPDATES
-      printf("    Search engine '%s' is valid for %d more seconds.\n",
-             engineURI, (updateCheckSecs-durationSecs));
-#endif
-      return NS_OK;
-    }
-  }
-
-  // search engine needs to be checked again, so add it into the to-be-validated array
-  PRInt32   elementIndex = mUpdateArray->IndexOf(engine);
-  if (elementIndex < 0)
-  {
-    mUpdateArray->AppendElement(engine);
-
-#ifdef  DEBUG_SEARCH_UPDATES
-    printf("    Search engine '%s' is now queued to be validated"
-           " via HTTP HEAD method.\n",
-           engineURI);
-#endif
-  }
-  else
-  {
-#ifdef  DEBUG_SEARCH_UPDATES
-    printf("    Search engine '%s' is already in queue to be validated.\n",
-      engineURI);
-#endif
-  }
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::DoSearch(nsIRDFResource *source, nsIRDFResource *engine,
-        const nsString &fullURL, const nsString &text)
-{
-  nsresult  rv;
-  nsAutoString  textTemp(text);
-
-  if (!mInner)  return(NS_RDF_NO_VALUE);
-//  Note: source can be null
-//  if (!source)  return(NS_ERROR_NULL_POINTER);
-  if (!engine)  return(NS_ERROR_NULL_POINTER);
-
-  validateEngine(engine);
-
-  nsCOMPtr<nsIUnicodeDecoder> unicodeDecoder;
-  nsAutoString      action, methodStr, input, userVar;
-
-  nsCOMPtr<nsIRDFLiteral>   dataLit;
-  if (NS_FAILED(rv = FindData(engine, getter_AddRefs(dataLit))) ||
-    (rv == NS_RDF_NO_VALUE))  return(rv);
-
-  const PRUnichar     *dataUni = nsnull;
-  dataLit->GetValueConst(&dataUni);
-  if (!dataUni)     return(NS_RDF_NO_VALUE);
-
-  if (!fullURL.IsEmpty())
-  {
-    action.Assign(fullURL);
-    methodStr.AssignLiteral("get");
-  }
-  else
-  {
-    if (NS_FAILED(rv = GetData(dataUni, "search", 0, "action", action)))  return(rv);
-    if (NS_FAILED(rv = GetData(dataUni, "search", 0, "method", methodStr))) return(rv);
-  }
-
-  nsAutoString  encodingStr, resultEncodingStr;
-
-  // first look for "interpret/charset"... if that isn't specified,
-  // then fall back to looking for "interpret/resultEncoding" (a decimal)
-  GetData(dataUni, "interpret", 0, "charset", resultEncodingStr);
-  if (resultEncodingStr.IsEmpty())
-  {
-    GetData(dataUni, "interpret", 0, "resultEncoding", encodingStr);  // decimal string values
-    MapEncoding(encodingStr, resultEncodingStr);
-  }
-  // rjc note: ignore "interpret/resultTranslationEncoding" as well as
-  // "interpret/resultTranslationFont" since we always convert results to Unicode
-  if (!resultEncodingStr.IsEmpty())
-  {
-    nsCOMPtr <nsICharsetConverterManager> charsetConv = do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
-    if (NS_SUCCEEDED(rv))
-    {
-                  NS_LossyConvertUTF16toASCII charset(resultEncodingStr);
-                  rv = charsetConv->GetUnicodeDecoder(charset.get(),
-                                                      getter_AddRefs(unicodeDecoder));
-    }
-  }
-
-  // first look for "search/queryCharset"... if that isn't specified,
-  // then fall back to looking for "search/queryEncoding" (a decimal)
-  nsAutoString    queryEncodingStr;
-  GetData(dataUni, "search", 0, "queryCharset", queryEncodingStr);
-  if (queryEncodingStr.IsEmpty())
-  {
-    GetData(dataUni, "search", 0, "queryEncoding", encodingStr);    // decimal string values
-    MapEncoding(encodingStr, queryEncodingStr);
-  }
-  if (!queryEncodingStr.IsEmpty())
-  {
-    // convert from escaped-UTF_8, to unicode, and then to
-    // the charset indicated by the dataset in question
-
-    char  *utf8data = ToNewUTF8String(textTemp);
-    if (utf8data)
-    {
-      nsCOMPtr<nsITextToSubURI> textToSubURI = 
-               do_GetService(kTextToSubURICID, &rv);
-      if (NS_SUCCEEDED(rv) && (textToSubURI))
-      {
-        PRUnichar *uni = nsnull;
-        if (NS_SUCCEEDED(rv = textToSubURI->UnEscapeAndConvert("UTF-8", utf8data, &uni)) && (uni))
-        {
-          char    *charsetData = nsnull;
-          rv = textToSubURI->ConvertAndEscape(NS_LossyConvertUTF16toASCII(queryEncodingStr).get(),
-                                              uni, &charsetData);
-          if (NS_SUCCEEDED(rv) && charsetData)
-          {
-            CopyASCIItoUTF16(nsDependentCString(charsetData), textTemp);
-            NS_Free(charsetData);
-          }
-          NS_Free(uni);
-        }
-      }
-      NS_Free(utf8data);
-    }
-  }
-
-  if (fullURL.IsEmpty() && methodStr.LowerCaseEqualsLiteral("get"))
-  {
-    nsAutoString engineNameStr;
-    GetData(dataUni, "search", 0, "name", engineNameStr);
-
-    if (NS_FAILED(rv = GetInputs(dataUni, engineNameStr, userVar, textTemp, input, 0, 0, 0)))  return(rv);
-    if (input.IsEmpty())        return(NS_ERROR_UNEXPECTED);
-
-    // HTTP Get method support
-    action += input;
-  }
-
-  nsCOMPtr<nsIInternetSearchContext>  context;
-  if (NS_FAILED(rv = NS_NewInternetSearchContext(nsIInternetSearchContext::WEB_SEARCH_CONTEXT,
-    source, engine, unicodeDecoder, nsnull, getter_AddRefs(context))))
-    return(rv);
-  if (!context) return(NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsIURI>  url;
-  if (NS_SUCCEEDED(rv = NS_NewURI(getter_AddRefs(url), action)))
-  {
-    nsCOMPtr<nsIChannel>  channel;
-    if (NS_SUCCEEDED(rv = NS_NewChannel(getter_AddRefs(channel), url, nsnull, mLoadGroup)))
-    {
-
-      // send a "MultiSearch" header
-      nsCOMPtr<nsIHttpChannel> httpMultiChannel (do_QueryInterface(channel));
-      if (httpMultiChannel)
-      {
-                httpMultiChannel->SetRequestHeader(NS_LITERAL_CSTRING("MultiSearch"),
-                                                   NS_LITERAL_CSTRING("true"),
-                                                   PR_FALSE);
-      }
-
-      // get it just from the cache if we can (do not validate)
-      channel->SetLoadFlags(nsIRequest::LOAD_FROM_CACHE);
-
-      if (methodStr.LowerCaseEqualsLiteral("post"))
-      {
-        nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(channel));
-        if (httpChannel)
-        {
-            httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST"));
-            
-            // construct post data to send
-            nsCAutoString  postStr;
-            postStr.AssignLiteral(POSTHEADER_PREFIX);
-            postStr.AppendInt(input.Length(), 10);
-            postStr.AppendLiteral(POSTHEADER_SUFFIX);
-            postStr.Append(NS_LossyConvertUTF16toASCII(input));
-            
-            nsCOMPtr<nsIInputStream>  postDataStream;
-            if (NS_SUCCEEDED(rv = NS_NewPostDataStream(getter_AddRefs(postDataStream),
-                         PR_FALSE, postStr, 0)))
-            {
-          nsCOMPtr<nsIUploadChannel> uploadChannel(do_QueryInterface(httpChannel));
-          NS_ASSERTION(uploadChannel, "http must support nsIUploadChannel");
-          uploadChannel->SetUploadStream(postDataStream, EmptyCString(), -1);
-            }
-        }
-      }
-      
-      nsCOMPtr<nsIRequest> request;
-      rv = channel->AsyncOpen(this, context);
-    }
-  }
-
-  // dispose of any last HTML results page
-  if (mInner)
-  {
-    nsCOMPtr<nsIRDFNode>  htmlNode;
-    if (NS_SUCCEEDED(rv = mInner->GetTarget(engine, mNC_HTML, PR_TRUE, getter_AddRefs(htmlNode)))
-      && (rv != NS_RDF_NO_VALUE))
-    {
-      rv = mInner->Unassert(engine, mNC_HTML, htmlNode);
-    }
-  }
-
-  // start "loading" animation for this search engine
-  if (NS_SUCCEEDED(rv) && (mInner))
-  {
-    // remove status icon so that loading icon style can be used
-    nsCOMPtr<nsIRDFNode>    engineIconNode = nsnull;
-    mInner->GetTarget(engine, mNC_StatusIcon, PR_TRUE, getter_AddRefs(engineIconNode));
-    if (engineIconNode)
-    {
-      rv = mInner->Unassert(engine, mNC_StatusIcon, engineIconNode);
-    }
-
-    mInner->Assert(engine, mNC_loading, mTrueLiteral, PR_TRUE);
-  }
-
-  return(rv);
-}
-
-nsresult
-InternetSearchDataSource::SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon,
-                                                  const PRUnichar *categoryHint,
-                                                  const PRUnichar *dataUni,
-                                                  PRBool isSystemSearchFile)
-{
-  nsresult      rv = NS_OK;
-
-  if (!file && !icon) return(NS_ERROR_UNEXPECTED);
-
-  nsCOMPtr<nsIRDFResource>  searchRes;
-  nsCOMPtr<nsIRDFResource>  categoryRes;
-  nsCOMPtr<nsIFile>   native;
-
-  if (icon != nsnull)
-  {
-    native = icon;
-  }
-
-  if (file != nsnull)
-  {
-    native = file;
-  }
-
-  PRBool exists;
-  rv = native->Exists(&exists);
-  if (NS_FAILED(rv)) return(rv);
-  if (!exists) return(NS_ERROR_UNEXPECTED);
-
-  nsAutoString basename;
-  rv = native->GetLeafName(basename);
-  if (NS_FAILED(rv)) return rv;
-
-  // ensure that the basename points to the search engine file
-  PRInt32   extensionOffset;
-  if ((extensionOffset = basename.RFindChar(PRUnichar('.'))) > 0)
-  {
-    basename.SetLength(extensionOffset);
-    basename.AppendLiteral(".src");
-  }
-
-  nsCAutoString filePath;
-  rv = native->GetNativePath(filePath);
-  if (NS_FAILED(rv)) return rv;
-  
-  nsAutoString  searchURL;
-  searchURL.AssignLiteral(kEngineProtocol);
-
-  nsCOMPtr<nsINetUtil> netUtil = do_GetService(NS_NETUTIL_CONTRACTID, &rv);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCString uriCescaped;
-  rv = netUtil->EscapeString(filePath,
-                             nsINetUtil::ESCAPE_URL_PATH,
-                             uriCescaped);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  searchURL.Append(NS_ConvertASCIItoUTF16(uriCescaped));
-
-  if ((extensionOffset = searchURL.RFindChar(PRUnichar('.'))) > 0)
-  {
-    searchURL.SetLength(extensionOffset);
-    searchURL.AppendLiteral(".src");
-  }
-
-  rv = mRDFService->GetUnicodeResource(searchURL,
-                                       getter_AddRefs(searchRes));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  // save the basename reference
-  if (!basename.IsEmpty())
-  {
-    basename.Insert(NS_ConvertASCIItoUTF16(kURINC_SearchCategoryEngineBasenamePrefix), 0);
-
-    rv = mRDFService->GetUnicodeResource(basename,
-                                         getter_AddRefs(categoryRes));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    nsCOMPtr<nsIRDFLiteral> searchLiteral;
-    rv = mRDFService->GetLiteral(basename.get(),
-                                 getter_AddRefs(searchLiteral));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    if (file)
-      updateAtom(mInner, searchRes, mNC_URL, searchLiteral, nsnull);
-  }
-
-  if (!searchRes)   return(NS_ERROR_UNEXPECTED);
-  if (!categoryRes) return(NS_ERROR_UNEXPECTED);
-
-  nsAutoString  iconURL;
-  if (icon)
-  {
-    nsCAutoString iconFileURL;
-    if (NS_FAILED(rv = NS_GetURLSpecFromFile(icon, iconFileURL)))
-      return(rv);
-    CopyUTF8toUTF16(iconFileURL, iconURL);
-  }
-
-  // save icon url (if we have one)
-  if (iconURL.Length() > 0)
-  {
-    nsCOMPtr<nsIRDFLiteral> iconLiteral;
-    if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(iconURL.get(),
-        getter_AddRefs(iconLiteral))))
-    {
-      updateAtom(mInner, searchRes, mNC_Icon, iconLiteral, nsnull);
-    }
-  }
-
-  if (!isSystemSearchFile)
-  {
-    // mark our private search files, so that we can distinguish
-    // between ours and any that are included with the OS
-    updateAtom(mInner, searchRes, mNC_SearchType, mNC_Engine, nsnull);
-  }
-
-  if (dataUni != nsnull)
-  {
-    updateDataHintsInGraph(searchRes, dataUni);
-
-    // finally, if we have a category hint, add this new engine into the category (if it exists)
-    if (categoryHint && categoryDataSource)
-    {
-      nsCOMPtr<nsIRDFLiteral> catLiteral;
-      rv = mRDFService->GetLiteral(categoryHint, getter_AddRefs(catLiteral));
-
-      nsCOMPtr<nsIRDFResource>  catSrc;
-      if (catLiteral)
-      {
-        rv = categoryDataSource->GetSource(mNC_Title, catLiteral,
-          PR_TRUE, getter_AddRefs(catSrc));
-      }
-
-      const char    *catURI = nsnull;
-      if (catSrc)         
-      {
-        rv = catSrc->GetValueConst(&catURI);
-      }
-
-      nsCOMPtr<nsIRDFResource>  catRes;
-      if (catURI)
-      {
-        nsCAutoString  catList;
-        catList.AssignLiteral(kURINC_SearchCategoryPrefix);
-        catList.Append(catURI);
-        mRDFService->GetResource(catList, getter_AddRefs(catRes));
-      }
-
-      nsCOMPtr<nsIRDFContainer> container;
-      if (catRes)
-        container = do_CreateInstance(NS_RDF_CONTRACTID "/container;1");
-
-      if (container)
-      {
-        rv = container->Init(categoryDataSource, catRes);
-        if (NS_SUCCEEDED(rv))
-          rv = mRDFC->MakeSeq(categoryDataSource, catRes, nsnull);
-
-        if (NS_SUCCEEDED(rv))
-        {
-          PRInt32   searchIndex = -1;
-          if (NS_SUCCEEDED(rv = container->IndexOf(categoryRes, &searchIndex))
-            && (searchIndex < 0))
-          {
-            rv = container->AppendElement(categoryRes);
-          }
-        }
-        if (NS_SUCCEEDED(rv))
-        {
-          // flush categoryDataSource
-          nsCOMPtr<nsIRDFRemoteDataSource>  remoteCategoryStore;
-          remoteCategoryStore = do_QueryInterface(categoryDataSource);
-          if (remoteCategoryStore)
-          {
-            remoteCategoryStore->Flush();
-          }
-        }
-      }
-    }
-  }
-
-  // Note: add the child relationship last
-  PRBool  hasChildFlag = PR_FALSE;
-  rv = mInner->HasAssertion(mNC_SearchEngineRoot, mNC_Child, searchRes,
-                            PR_TRUE, &hasChildFlag);
-  if (NS_SUCCEEDED(rv) && !hasChildFlag)
-  {
-    mInner->Assert(mNC_SearchEngineRoot, mNC_Child, searchRes, PR_TRUE);
-  }
-
-  return(NS_OK);
-}
-
-nsresult
-InternetSearchDataSource::GetSearchEngineList(nsIFile *searchDir,
-              PRBool isSystemSearchFile)
-{
-        nsresult      rv = NS_OK;
-
-    if (!mInner)
-    {
-      return(NS_RDF_NO_VALUE);
-    }
-
-    PRBool hasMore = PR_FALSE;
-    nsCOMPtr<nsISimpleEnumerator> dirIterator;
-    rv = searchDir->GetDirectoryEntries(getter_AddRefs(dirIterator));
-    if (NS_FAILED(rv)) return rv;
-
-    nsCOMPtr<nsIFile> dirEntry;
-  while ((rv = dirIterator->HasMoreElements(&hasMore)) == NS_OK && hasMore)
-  {
-    rv = dirIterator->GetNext((nsISupports**)getter_AddRefs(dirEntry));
-        if (NS_FAILED(rv))
-          continue;
-
-        // Ignore hidden files/directories
-        PRBool isHidden;
-        rv = dirEntry->IsHidden(&isHidden);
-        if (NS_FAILED(rv) || isHidden)
-          continue;
-
-        PRBool isDirectory;
-        rv = dirEntry->IsDirectory(&isDirectory);
-        if (NS_FAILED(rv))
-          continue;
-        if (isDirectory)
-        {
-          GetSearchEngineList(dirEntry, isSystemSearchFile);
-          continue;
-        }
-
-        // Skip over empty files
-        // Note: use GetFileSize even on Mac [instead of GetFileSizeWithResFork()]
-        // as we want the size of ONLY the data fork
-        PRInt64 fileSize;
-        rv = dirEntry->GetFileSize(&fileSize);
-        if (NS_FAILED(rv) || (fileSize == 0))
-            continue;
-    
-        nsAutoString uri;
-        rv = dirEntry->GetPath(uri);
-        if (NS_FAILED(rv))
-        continue;
-
-    PRInt32   len = uri.Length();
-    if (len < 5)
-    {
-      continue;
-    }
-
-    // check the extension (must be ".src")
-    if (!StringEndsWith(uri, NS_LITERAL_STRING(".src"), CaseInsensitiveCompare))
-    {
-      continue;
-    }
-
-    // check for various icons
-    PRBool    foundIconFlag = PR_FALSE;
-    nsAutoString  temp;
-    
-    nsCOMPtr<nsILocalFile> iconFile, loopFile;
-
-                static const char *extensions[] = {
-                        ".gif",
-                        ".jpg",
-                        ".jpeg",
-                        ".png",
-                        nsnull,
-                };
-
-                for (int ext_count = 0; extensions[ext_count] != nsnull; ext_count++) {
-                        temp = Substring(uri, 0, uri.Length()-4);
-                        temp.Append(NS_ConvertASCIItoUTF16(extensions[ext_count]));
-                        rv = NS_NewLocalFile(temp, PR_TRUE, getter_AddRefs(loopFile));
-                        if (NS_FAILED(rv)) return rv;
-                        rv = loopFile->Exists(&foundIconFlag);
-                        if (NS_FAILED(rv)) return rv;
-                        if (!foundIconFlag) continue;
-                        rv = loopFile->IsFile(&foundIconFlag);
-                        if (NS_FAILED(rv)) return rv;
-                        if (foundIconFlag) 
-                        {
-                                iconFile = loopFile;
-                                break;
-                        } 
-                }
-    
-    SaveEngineInfoIntoGraph(dirEntry, iconFile, nsnull, nsnull, isSystemSearchFile);
-  }
-
-  return(rv);
-}
-
-nsresult
-InternetSearchDataSource::ReadFileContents(nsILocalFile *localFile, nsString& sourceContents)
-{
-  nsresult      rv = NS_ERROR_FAILURE;
-  PRInt64       contentsLen, total = 0;
-  char        *contents;
-
-        NS_ENSURE_ARG_POINTER(localFile);
-
-        sourceContents.Truncate();
-
-        rv = localFile->GetFileSize(&contentsLen);
-        if (NS_FAILED(rv)) return rv;
-        if (contentsLen > 0)
-        {
-                contents = new char [contentsLen + 1];
-                if (contents)
-                {
-                        nsCOMPtr<nsIInputStream> inputStream;
-                        rv = NS_NewLocalFileInputStream(getter_AddRefs(inputStream), localFile);
-                        if (NS_FAILED(rv)) {
-                          delete [] contents;
-                          return rv;
-                        }
-                        PRUint32 howMany;
-                        while (total < contentsLen) {
-                                rv = inputStream->Read(contents+total, 
-                                                       PRUint32(contentsLen),
-                                                       &howMany);
-                                if (NS_FAILED(rv)) {
-                                        delete [] contents;
-                                        return rv;
-                                }
-                                total += howMany;
-                        }
-                        if (total == contentsLen)
-            {
-        contents[contentsLen] = '\0';
-        CopyASCIItoUTF16(Substring(contents, contents + contentsLen), sourceContents);
-        rv = NS_OK;
-            }
-            delete [] contents;
-            contents = nsnull;
-    }
-  }
-  return(rv);
-}
-
-
-
-nsresult
-InternetSearchDataSource::GetNumInterpretSections(const PRUnichar *dataUni, PRUint32 &numInterpretSections)
-{
-  numInterpretSections = 0;
-
-  nsString  buffer(dataUni);
-
-  NS_NAMED_LITERAL_STRING(section, "<interpret");
-  PRBool    inSection = PR_FALSE;
-
-  while(!buffer.IsEmpty())
-  {
-    PRInt32 eol = nsString_FindCharInSet(buffer, "\r\n", 0);
-    if (eol < 0)  break;
-    nsAutoString  line(StringHead(buffer, eol));
-    buffer.Cut(0, eol+1);
-    if (line.IsEmpty()) continue;   // skip empty lines
-    if (line[0] == PRUnichar('#'))  continue; // skip comments
-    line.Trim(" \t");
-    if (!inSection)
-    {
-      PRInt32 sectionOffset = line.Find(section, CaseInsensitiveCompare);
-      if (sectionOffset < 0)  continue;
-      line.Cut(0, sectionOffset + section.Length() + 1);
-      inSection = PR_TRUE;
-      ++numInterpretSections;     // increment # of sections
-    }
-    line.Trim(" \t");
-    PRInt32 len = line.Length();
-    if (len > 0)
-    {
-      if (line[len-1] == PRUnichar('>'))
-      {
-        inSection = PR_FALSE;
-        line.SetLength(len-1);
-      }
-    }
-  }
-  return(NS_OK);
-}
-
-
-nsresult
-InternetSearchDataSource::GetData(const PRUnichar *dataUni, const char *sectionToFind, PRUint32 sectionNum,
-          const char *attribToFind, nsString &value)
-{
-  nsString  buffer(dataUni);
-
-  nsresult  rv = NS_RDF_NO_VALUE;
-  PRBool    inSection = PR_FALSE;
-
-  nsAutoString  section;
-  section.Assign(PRUnichar('<'));
-  section.Append(NS_ConvertASCIItoUTF16(sectionToFind));
-
-  while(!buffer.IsEmpty())
-  {
-    PRInt32 eol = nsString_FindCharInSet(buffer, "\r\n", 0);
-    if (eol < 0)  break;
-    nsAutoString  line(StringHead(buffer, eol));
-    buffer.Cut(0, eol+1);
-    if (line.IsEmpty()) continue;   // skip empty lines
-    if (line[0] == PRUnichar('#'))  continue; // skip comments
-    line.Trim(" \t");
-    if (!inSection)
-    {
-      PRInt32 sectionOffset = line.Find(section, CaseInsensitiveCompare);
-      if (sectionOffset < 0)  continue;
-      if (sectionNum > 0)
-      {
-        --sectionNum;
-        continue;
-      }
-      line.Cut(0, sectionOffset + section.Length() + 1);
-      inSection = PR_TRUE;
-    }
-    line.Trim(" \t");
-    PRInt32 len = line.Length();
-    if (len > 0)
-    {
-      if (line[len-1] == PRUnichar('>'))
-      {
-        inSection = PR_FALSE;
-        line.SetLength(len-1);
-      }
-    }
-    PRInt32 equal = line.FindChar(PRUnichar('='));
-    if (equal < 0)  continue;     // skip lines with no equality
-    
-    nsAutoString  attrib(StringHead(line, equal /* - 1 */));
-    attrib.Trim(" \t");
-    if (attrib.Equals(NS_ConvertASCIItoUTF16(attribToFind), CaseInsensitiveCompare))
-    {
-      line.Cut(0, equal+1);
-      line.Trim(" \t");
-      value = line;
-
-      // strip of any enclosing quotes and trailing comments
-      if ((value[0] == PRUnichar('\"')) || (value[0] == PRUnichar('\'')))
-      {
-        PRUnichar quoteChar = value[0];
-        value.Cut(0,1);
-        if (!value.IsEmpty())
-        {
-          PRInt32 quoteEnd = value.FindChar(quoteChar);
-          if (quoteEnd >= 0)
-          {
-            value.SetLength(quoteEnd);
-          }
-        }
-      }
-      else
-      {
-        PRInt32 commentOffset = nsString_FindCharInSet(value, "# \t", 0);
-        if (commentOffset >= 0)
-        {
-          value.SetLength(commentOffset);
-        }
-        value.Trim(" \t");
-      }
-      rv = NS_OK;
-      break;
-    }
-  }
-  return(rv);
-}
-
-
-
-nsresult
-InternetSearchDataSource::GetInputs(const PRUnichar *dataUni, nsString &engineName, nsString &userVar,
-  const nsString &text, nsString &input, PRInt16 direction, PRUint16 pageNumber,  PRUint16 *whichButtons)
-{
-  nsString  buffer(dataUni);
-
-  nsresult  rv = NS_OK;
-  PRBool    inSection = PR_FALSE;
-  PRBool    inDirInput; // directional input: "inputnext" or "inputprev"
-  PRBool    foundInput = PR_FALSE;
-
-  while(!buffer.IsEmpty())
-  {
-    PRInt32 eol = nsString_FindCharInSet(buffer, "\r\n", 0);
-    if (eol < 0)  break;
-    nsAutoString  line(StringHead(buffer, eol));
-    buffer.Cut(0, eol+1);
-    if (line.IsEmpty()) continue;   // skip empty lines
-    if (line[0] == PRUnichar('#'))  continue; // skip comments
-    line.Trim(" \t");
-    if (!inSection)
-    {
-      if (line[0] != PRUnichar('<'))  continue;
-      line.Cut(0, 1);
-      inSection = PR_TRUE;
-    }
-    PRInt32 len = line.Length();
-    if (len > 0)
-    {
-      if (line[len-1] == PRUnichar('>'))
-      {
-        inSection = PR_FALSE;
-        line.SetLength(len-1);
-      }
-    }
-    if (inSection)
-      continue;
-
-    // look for inputs
-    if (line.Find("input", PR_TRUE) == 0)
-    {
-      line.Cut(0, 5);
-
-      // look for "inputnext" or "inputprev"
-      inDirInput = PR_FALSE;
-
-      if (line.Find("next", PR_TRUE) == 0)
-      {
-        inDirInput = PR_TRUE;
-        if (whichButtons)
-          *whichButtons |= kHaveNext;
-      }
-
-      if (line.Find("prev", PR_TRUE) == 0)
-      {
-        inDirInput = PR_TRUE;
-        if (whichButtons)
-          *whichButtons |= kHavePrev;
-      }
-
-      if (inDirInput)
-        line.Cut(0, 4);
-      
-      line.Trim(" \t");
-      
-      // first look for name attribute
-      nsAutoString  nameAttrib;
-
-      PRInt32 nameOffset = line.Find("name", PR_TRUE);
-      if (nameOffset >= 0)
-      {
-        PRInt32 equal = line.FindChar(PRUnichar('='), nameOffset);
-        if (equal >= 0)
-        {
-          PRInt32 startQuote = line.FindChar(PRUnichar('\"'), equal + 1);
-          if (startQuote >= 0)
-          {
-            PRInt32 endQuote = line.FindChar(PRUnichar('\"'), startQuote + 1);
-            if (endQuote > 0)
-            {
-              nameAttrib = Substring(line,
-                                     startQuote + 1,
-                                     endQuote - startQuote - 1);
-              line.Cut(0, endQuote + 1);
-            }
-          }
-          else
-          {
-            nameAttrib = line;
-            nameAttrib.Cut(0, equal+1);
-            nameAttrib.Trim(" \t");
-            PRInt32 space = nsString_FindCharInSet(nameAttrib, " \t", 0);
-            if (space > 0)
-            {
-              nameAttrib.SetLength(space);
-              line.Cut(0, equal+1+space);
-            }
-            else
-            {
-              line.Truncate();
-            }
-          }
-        }
-      }
-      if (foundInput && nameAttrib.IsEmpty()) 
-        continue;
-
-      // first look for value attribute
-      nsAutoString  valueAttrib;
-
-      PRInt32  valueOffset;
-      if (!inDirInput)
-        valueOffset = line.Find("value", PR_TRUE);
-      else
-        valueOffset = line.Find("factor", PR_TRUE);
-      if (valueOffset >= 0)
-      {
-        PRInt32 equal = line.FindChar(PRUnichar('='), valueOffset);
-        if (equal >= 0)
-        {
-          PRInt32 startQuote = line.FindChar(PRUnichar('\"'), equal + 1);
-          if (startQuote >= 0)
-          {
-            PRInt32 endQuote = line.FindChar(PRUnichar('\"'), startQuote + 1);
-            if (endQuote >= 0)
-            {
-              valueAttrib = Substring(line,
-                                      startQuote + 1,
-                                      endQuote - startQuote - 1);
-            }
-          }
-          else
-          {
-            // if value attribute's "value" isn't quoted, get the first word... ?
-            valueAttrib = line;
-            valueAttrib.Cut(0, equal+1);
-            valueAttrib.Trim(" \t");
-            PRInt32 space = nsString_FindCharInSet(valueAttrib, " \t>", 0);
-            if (space > 0)
-            {
-              valueAttrib.SetLength(space);
-            }
-          }
-        }
-      }
-      else if (line.Find("user", PR_TRUE) >= 0)
-      {
-        userVar = nameAttrib;
-        valueAttrib.Assign(text);
-      }
-      
-      // XXX should ignore if  mode=browser  is specified
-      // XXX need to do this better
-      if (line.Find("mode=browser", PR_TRUE) >= 0)
-        continue;
-
-      if (!valueAttrib.IsEmpty())
-      {
-        // Here's how we construct the input string:
-        // <input> is first: Name Attr: Prefix      Data           Example:
-        // YES               EMPTY      None        <value>        ACTION<value>
-        // YES               NON-EMPTY  ?           <name>=<value> ACTION?<name>=<value>
-        // NO                EMPTY      ----------- <ignored> -------------
-        // NO                NON-EMPTY  &           <name>=<value> ACTION?<n1>=<v1>&<n2>=<v2>
-        if (!input.IsEmpty())
-          input.AppendLiteral("&");
-        else if (!nameAttrib.IsEmpty()) 
-          input.AppendLiteral("?");
-
-        if (!nameAttrib.IsEmpty()) 
-        {
-          input += nameAttrib;
-          input.AppendLiteral("=");
-        }
-
-        // Indicate that we've already found an input, so we cannot have any 
-        // inputs after this that do not have names. I could be more sophisticated
-        // than this but I don't care right now since I'm only doing this for one
-        // plugin. --ben
-        foundInput = PR_TRUE;
-
-        if (!inDirInput)
-          input += valueAttrib;
-        else
-          input.AppendInt( computeIndex(valueAttrib, pageNumber, direction) );
-      }
-    }
-  }
-
-  // Now add the default vs. non-default parameters, which come from 
-  // preferences and are part of the pre-configuration.
-  nsCOMPtr<nsIPrefService> pserv(do_GetService(NS_PREFSERVICE_CONTRACTID));
-  if (pserv) 
-  {
-    // If the pref "browser.search.defaultenginename" has a user value, that
-    // means the user has changed the engine in the list. This implies that
-    // the selected engine was _not_ configured as the default by the 
-    // distributor, because if the value of the pref matched, prefHasUserValue
-    // would return false. 
-    PRBool engineIsNotDefault = PR_FALSE;
-    nsCOMPtr<nsIPrefBranch> rootBranch(do_QueryInterface(pserv));
-    nsCOMPtr<nsIPrefBranch> defaultBranch;
-    pserv->GetDefaultBranch("", getter_AddRefs(defaultBranch));
-
-    if (defaultBranch) 
-    {
-      nsString defaultEngineNameStr;
-      nsCOMPtr<nsIPrefLocalizedString> defaultEngineName;
-      rv = defaultBranch->GetComplexValue("browser.search.defaultenginename", 
-                                          NS_GET_IID(nsIPrefLocalizedString),
-                                          getter_AddRefs(defaultEngineName));
-      if (NS_SUCCEEDED(rv)) {
-        defaultEngineName->GetData(getter_Copies(defaultEngineNameStr));
-
-        nsString selectedEngineNameStr;
-        nsCOMPtr<nsIPrefLocalizedString> selectedEngineName;
-        rv = rootBranch->GetComplexValue("browser.search.selectedEngine", 
-                                         NS_GET_IID(nsIPrefLocalizedString),
-                                         getter_AddRefs(selectedEngineName));
-        if (NS_SUCCEEDED(rv) && selectedEngineName) {
-          selectedEngineName->GetData(getter_Copies(selectedEngineNameStr));
-          engineIsNotDefault = !defaultEngineNameStr.Equals(selectedEngineNameStr);
-        }
-        else {
-          engineIsNotDefault = PR_FALSE; // The selected engine *is* the default
-                                         // since the user has not changed the
-                                         // selected item in the list causing
-                                         // the selectedEngine pref to be set.
-        }
-      }
-    }
-
-    PRInt32 i = 0;
-    char prefNameBuf[1096];
-    do
-    {
-      ++i;
-      sprintf(prefNameBuf, "browser.search.param.%s.%d.", 
-              NS_ConvertUTF16toUTF8(engineName).get(), i);
-
-      nsCOMPtr<nsIPrefBranch> pb;
-      rv = pserv->GetBranch(prefNameBuf, getter_AddRefs(pb));
-      if (NS_FAILED(rv)) 
-        break;
-
-      nsCOMPtr<nsIPrefLocalizedString> parameter;
-      nsString parameterStr;
-      rv = pb->GetComplexValue(engineIsNotDefault ? "custom" : "default", 
-                               NS_GET_IID(nsIPrefLocalizedString), 
-                               getter_AddRefs(parameter));
-      if (NS_FAILED(rv))
-        break;
-
-      parameter->GetData(getter_Copies(parameterStr));
-      
-      if (!parameterStr.IsEmpty()) 
-      {
-        if (!input.IsEmpty())
-          input.Append(NS_LITERAL_STRING("&"));
-        input += parameterStr;
-      }
-    }
-    while (1);
-
-    // Now add the release identifier
-    nsCOMPtr<nsIStringBundleService> stringService(do_GetService(NS_STRINGBUNDLE_CONTRACTID));
-    nsCOMPtr<nsIStringBundle> bundle;
-    rv = stringService->CreateBundle(SEARCHCONFIG_PROPERTIES, getter_AddRefs(bundle));
-    nsCOMPtr<nsIStringBundle> intlBundle;
-    rv = stringService->CreateBundle(INTL_PROPERTIES, getter_AddRefs(intlBundle));
-
-    nsString langName;
-    intlBundle->GetStringFromName(NS_LITERAL_STRING("general.useragent.locale").get(), 
-                                  getter_Copies(langName));
-
-    nsAutoString keyTemplate(NS_LITERAL_STRING("browser.search.param."));
-    keyTemplate += engineName;
-    keyTemplate.Append(NS_LITERAL_STRING(".release"));
-
-    nsString releaseValue;
-    NS_NAMED_LITERAL_STRING(distributionID, MOZ_DISTRIBUTION_ID);
-    const PRUnichar* strings[] = { distributionID.get(), langName.get() };
-    bundle->FormatStringFromName(keyTemplate.get(), strings, 2, getter_Copies(releaseValue));
-
-    if (!releaseValue.IsEmpty()) 
-    {
-      if (!input.IsEmpty())
-        input.Append(NS_LITERAL_STRING("&"));
-      input += releaseValue;
-    }
-
-    // Now add order parameters.
-    nsCOMPtr<nsIPrefBranch> pb;
-    rv = pserv->GetBranch("", getter_AddRefs(pb));
-    if (NS_FAILED(rv)) return rv;
-
-    i = 0;
-    do {
-      ++i;
-      sprintf(prefNameBuf, "browser.search.order.%d", i);
-
-      nsCOMPtr<nsIPrefLocalizedString> orderEngineName;
-      rv = pb->GetComplexValue(prefNameBuf, 
-                               NS_GET_IID(nsIPrefLocalizedString),
-                               getter_AddRefs(orderEngineName));
-      if (NS_FAILED(rv)) 
-        break;
-
-      nsString orderEngineNameStr;
-      orderEngineName->GetData(getter_Copies(orderEngineNameStr));
-      if (orderEngineNameStr.Equals(engineName))
-        break;
-    }
-    while (PR_TRUE);
-
-    if (NS_SUCCEEDED(rv))
-    {
-      sprintf(prefNameBuf, "browser.search.order.%s.%d",
-              NS_ConvertUTF16toUTF8(engineName).get(), i);
-      
-      nsCOMPtr<nsIPrefLocalizedString> orderParam;
-      rv = rootBranch->GetComplexValue(prefNameBuf, 
-                                       NS_GET_IID(nsIPrefLocalizedString),
-                                       getter_AddRefs(orderParam));
-      if (NS_FAILED(rv))
-      {
-        sprintf(prefNameBuf, "browser.search.order.%s",
-                NS_ConvertUTF16toUTF8(engineName).get());
-        rv = rootBranch->GetComplexValue(prefNameBuf, 
-                                         NS_GET_IID(nsIPrefLocalizedString),
-                                         getter_AddRefs(orderParam));
-      }
-    
-      if (NS_SUCCEEDED(rv)) 
-      {
-        nsString orderParamStr;
-        orderParam->GetData(getter_Copies(orderParamStr));
-
-        if (!orderParamStr.IsEmpty())
-        {
-          if (!input.IsEmpty())
-            input.Append(NS_LITERAL_STRING("&"));
-          input += orderParamStr;
-        }
-      }
-    }
-
-    rv = NS_OK;
-  }
-
-  return(rv);
-}
-
-PRInt32
-InternetSearchDataSource::computeIndex(nsAutoString &factor, 
-                                       PRUint16 page, PRInt16 direction)
-{
-  // XXX get page
-  nsresult rv;
-  PRInt32 index = 0;
-  PRInt32 factorInt = factor.ToInteger(&rv);
-  
-  if (NS_SUCCEEDED(rv))
-  {
-    // if factor is garbled assume 10
-    if (factorInt <= 0)
-      factorInt = 10;
-
-    if (direction < 0)
-    {
-      // don't pass back a negative index!
-      if (0 <= (page - 1))
-        --page;
-    }
-    index = factorInt * page;
-  }
-
-  return index;
-}
-
-
-
-nsresult
-InternetSearchDataSource::GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult)
-{
-  const char *uri = nsnull;
-  nsresult rv = source->GetValueConst( &uri );
-  NS_ENSURE_SUCCESS(rv, rv);
-  return mRDFService->GetLiteral(NS_ConvertUTF8toUTF16(uri).get(), aResult);
-}
-
-
-
-// stream observer methods
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
-{
-#ifdef  DEBUG_SEARCH_OUTPUT
-  printf("InternetSearchDataSourceCallback::OnStartRequest entered.\n");
-#endif
-  return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::OnDataAvailable(nsIRequest *request, nsISupports *ctxt,
-        nsIInputStream *aIStream, PRUint32 sourceOffset, PRUint32 aLength)
-{
-  if (!ctxt)  return(NS_ERROR_NO_INTERFACE);
-  nsCOMPtr<nsIInternetSearchContext> context (do_QueryInterface(ctxt));
-  if (!context) return(NS_ERROR_NO_INTERFACE);
-
-  nsresult  rv = NS_OK;
-
-  if (aLength < 1)  return(rv);
-
-  PRUint32  count;
-  char    *buffer = new char[ aLength ];
-  if (!buffer)  return(NS_ERROR_OUT_OF_MEMORY);
-
-  if (NS_FAILED(rv = aIStream->Read(buffer, aLength, &count)) || count == 0)
-  {
-#ifdef  DEBUG
-    printf("Search datasource read failure.\n");
-#endif
-    delete []buffer;
-    return(rv);
-  }
-  if (count != aLength)
-  {
-#ifdef  DEBUG
-    printf("Search datasource read # of bytes failure.\n");
-#endif
-    delete []buffer;
-    return(NS_ERROR_UNEXPECTED);
-  }
-
-  nsCOMPtr<nsIUnicodeDecoder> decoder;
-  context->GetUnicodeDecoder(getter_AddRefs(decoder));
-  if (decoder)
-  {
-    char      *aBuffer = buffer;
-    PRInt32     unicharBufLen = 0;
-    decoder->GetMaxLength(aBuffer, aLength, &unicharBufLen);
-    PRUnichar   *unichars = new PRUnichar [ unicharBufLen+1 ];
-    do
-    {
-      PRInt32   srcLength = aLength;
-      PRInt32   unicharLength = unicharBufLen;
-      rv = decoder->Convert(aBuffer, &srcLength, unichars, &unicharLength);
-      unichars[unicharLength]=0;  //add this since the unicode converters can't be trusted to do so.
-
-      // Move the nsParser.cpp 00 -> space hack to here so it won't break UCS2 file
-
-      // Hack Start
-      for(PRInt32 i=0;i < unicharLength; i++)
-      {
-        if(0x0000 == unichars[i])
-        {
-          unichars[i] = PRUnichar(' ');
-        }
-      }
-      // Hack End
-
-      context->AppendUnicodeBytes(unichars, unicharLength);
-      // if we failed, we consume one byte by replace it with U+FFFD
-      // and try conversion again.
-      if(NS_FAILED(rv))
-      {
-        decoder->Reset();
-        unsigned char smallBuf[2];
-        smallBuf[0] = 0xFF;
-        smallBuf[1] = 0xFD;
-        context->AppendBytes( (const char *)&smallBuf, 2L);
-        if(((PRUint32) (srcLength + 1)) > aLength)
-          srcLength = aLength;
-        else 
-          srcLength++;
-        aBuffer += srcLength;
-        aLength -= srcLength;
-      }
-    } while (NS_FAILED(rv) && (aLength > 0));
-    delete [] unichars;
-    unichars = nsnull;
-  }
-  else
-  {
-    context->AppendBytes(buffer, aLength);
-  }
-
-  delete [] buffer;
-  buffer = nsnull;
-  return(rv);
-}
-
-
-
-NS_IMETHODIMP
-InternetSearchDataSource::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
-                                        nsresult status)
-{
-  if (!mInner)  return(NS_OK);
-
-  nsCOMPtr<nsIChannel> channel (do_QueryInterface(request));
-  nsCOMPtr<nsIInternetSearchContext> context (do_QueryInterface(ctxt));
-  if (!ctxt)  return(NS_ERROR_NO_INTERFACE);
-
-  nsresult  rv;
-  PRUint32  contextType = 0;
-  if (NS_FAILED(rv = context->GetContextType(&contextType)))    return(rv);
-
-  if (contextType == nsIInternetSearchContext::WEB_SEARCH_CONTEXT)
-  {
-    // continue to process nsIInternetSearchContext::WEB_SEARCH_CONTEXT
-    rv = webSearchFinalize(channel, context);
-  }
-  else if (contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_NEW_CONTEXT ||
-           contextType == nsIInternetSearchContext::ICON_DOWNLOAD_NEW_CONTEXT ||
-           contextType == nsIInternetSearchContext::ENGINE_DOWNLOAD_UPDATE_CONTEXT ||
-           contextType == nsIInternetSearchContext::ICON_DOWNLOAD_UPDATE_CONTEXT)
-  {
-    nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(channel));
-    if (!httpChannel) return(NS_ERROR_UNEXPECTED);
-
-    // check HTTP status to ensure success
-    PRUint32  httpStatus = 0;
-    if (NS_SUCCEEDED(rv = httpChannel->GetResponseStatus(&httpStatus)) &&
-      (httpStatus == 200))
-    {
-      rv = saveContents(channel, context, contextType);
-    }
-  }
-  else if (contextType == nsIInternetSearchContext::ENGINE_UPDATE_HEAD_CONTEXT)
-  {
-    nsCOMPtr<nsIRDFResource>  theEngine;
-    if (NS_FAILED(rv = context->GetEngine(getter_AddRefs(theEngine))))  return(rv);
-    if (!theEngine) return(NS_ERROR_NO_INTERFACE);
-
-#ifdef  DEBUG_SEARCH_UPDATES
-    const char  *engineURI = nsnull;
-    theEngine->GetValueConst(&engineURI);
-#endif
-
-    // free up "busy" info now & mark as non-busy
-    busySchedule = PR_FALSE;
-    busyResource = nsnull;
-
-    // mark now as the last time we stat'ted the search engine
-    // regardless of HTTP status
-    rv = validateEngineNow(theEngine);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // we only have HTTP "HEAD" information when doing updates
-    nsCOMPtr<nsIHttpChannel> httpChannel (do_QueryInterface(channel));
-    if (!httpChannel) return(NS_ERROR_UNEXPECTED);
-
-    // check HTTP status to ensure success
-    PRUint32  httpStatus = 0;
-    if (NS_FAILED(rv = httpChannel->GetResponseStatus(&httpStatus)))
-      return(rv);
-    if (httpStatus != 200)  return(NS_ERROR_UNEXPECTED);
-
-    // get last-modified & content-length info
-    nsCAutoString     lastModValue, contentLengthValue;
-
-        if (NS_FAILED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Last-Modified"), lastModValue)))
-            lastModValue.Truncate();
-        if (NS_FAILED(httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthValue)))
-            contentLengthValue.Truncate();
-
-    // should we fetch the entire file?
-    PRBool    updateSearchEngineFile = PR_FALSE;
-
-    // save out new search engine state data into localstore
-    PRBool      tempDirty = PR_FALSE;
-    nsCOMPtr<nsIRDFLiteral> newValue;
-    if (!lastModValue.IsEmpty())
-    {
-      mRDFService->GetLiteral(NS_ConvertASCIItoUTF16(lastModValue).get(),
-        getter_AddRefs(newValue));
-      if (newValue)
-      {
-        updateAtom(mLocalstore, theEngine, mWEB_LastPingModDate, newValue,
-          &tempDirty);
-        if (tempDirty)
-          updateSearchEngineFile = PR_TRUE;
-      }
-    }
-    if (!contentLengthValue.IsEmpty())
-    {
-      mRDFService->GetLiteral(NS_ConvertASCIItoUTF16(contentLengthValue).get(),
-        getter_AddRefs(newValue));
-      if (newValue)
-      {
-        updateAtom(mLocalstore, theEngine, mWEB_LastPingContentLen, newValue,
-          &tempDirty);
-        if (tempDirty)
-        {
-          updateSearchEngineFile = PR_TRUE;
-        }
-        else
-        {
-          // worst case: compare local data size vs. remote content size
-          nsCOMPtr<nsIRDFLiteral> dataLit;
-          if (NS_SUCCEEDED(rv = FindData(theEngine, getter_AddRefs(dataLit))) &&
-            (rv != NS_RDF_NO_VALUE))
-          {
-            const PRUnichar *dataUni = nsnull;
-            dataLit->GetValueConst(&dataUni);
-            nsAutoString  dataStr(dataUni);
-            PRInt32   dataLen=dataStr.Length();
-#ifdef  DEBUG_SEARCH_UPDATES
-            printf("    Search engine='%s' data length='%d'\n", engineURI, dataLen);
-#endif
-            PRInt32 contentLen = contentLengthValue.ToInteger(&rv);
-            if (NS_SUCCEEDED(rv) && (dataLen != contentLen))
-            {
-#ifdef  DEBUG_SEARCH_UPDATES
-              printf("    Search engine '%s' data length != remote content length, so update\n",
-                engineURI, dataLen);
-#endif
-              updateSearchEngineFile = PR_TRUE;
-            }
-          }
-        }
-      }
-    }
-
-    if (updateSearchEngineFile)
-    {
-#ifdef  DEBUG_SEARCH_UPDATES
-      printf("    Search engine='%s' needs updating, so fetching it\n", engineURI);
-#endif
-      // get update URL
-      nsCString   updateURL;
-      nsCOMPtr<nsIRDFNode>  aNode;
-      if (NS_SUCCEEDED(rv = mInner->GetTarget(theEngine, mNC_Update, PR_TRUE, getter_AddRefs(aNode)))
-        && (rv != NS_RDF_NO_VALUE))
-      {
-        nsCOMPtr<nsIRDFLiteral> aLiteral (do_QueryInterface(aNode));
-        if (aLiteral)
-        {
-          const PRUnichar *updateUni = nsnull;
-          aLiteral->GetValueConst(&updateUni);
-          if (updateUni)
-          {
-            CopyUTF16toUTF8(nsDependentString(updateUni), updateURL);
-          }
-        }
-      }
-
-      // get update icon
-      nsCString   updateIconURL;
-      if (NS_SUCCEEDED(rv = mInner->GetTarget(theEngine, mNC_UpdateIcon, PR_TRUE, getter_AddRefs(aNode)))
-        && (rv != NS_RDF_NO_VALUE))
-      {
-        nsCOMPtr<nsIRDFLiteral> aIconLiteral (do_QueryInterface(aNode));
-        if (aIconLiteral)
-        {
-          const PRUnichar *updateIconUni = nsnull;
-          aIconLiteral->GetValueConst(&updateIconUni);
-          if (updateIconUni)
-          {
-            CopyUTF16toUTF8(nsDependentString(updateIconUni), updateIconURL);
-          }
-        }
-      }
-
-      // download it!
-      AddSearchEngineInternal(updateURL.get(), updateIconURL.get(),
-                              nsnull, nsnull, theEngine);
-    }
-    else
-    {
-#ifdef  DEBUG_SEARCH_UPDATES
-      printf("    Search engine='%s' is current and requires no updating\n", engineURI);
-#endif
-    }
-  }
-  else
-  {
-    rv = NS_ERROR_UNEXPECTED;
-  }
-  return(rv);
-}
-
-
-
-nsresult
-InternetSearchDataSource::validateEngineNow(nsIRDFResource *engine)
-{
-  // get the current date/time [from microseconds (PRTime) to seconds]
-  // also, need to convert from 64 bites to 32 bites as we don't have an easy
-  // way to convert from 64 bit number to a string like we do for 32 bit numbers
-  PRTime    now64 = PR_Now(), temp64, million;
-  LL_I2L(million, PR_USEC_PER_SEC);
-  LL_DIV(temp64, now64, million);
-  PRInt32   now32;
-  LL_L2I(now32, temp64);
-
-  // validate this engine as of now (save as string
-  // literal as that's all RDF can currently serialize)
-  nsAutoString  nowStr;
-  nowStr.AppendInt(now32);
-
-  nsresult    rv;
-  nsCOMPtr<nsIRDFLiteral> nowLiteral;
-  if (NS_FAILED(rv = mRDFService->GetLiteral(nowStr.get(),
-      getter_AddRefs(nowLiteral)))) return(rv);
-  updateAtom(mLocalstore, engine, mWEB_LastPingDate, nowLiteral, nsnull);
-
-  // flush localstore
-  nsCOMPtr<nsIRDFRemoteDataSource> remoteLocalStore (do_QueryInterface(mLocalstore));
-  if (remoteLocalStore)
-  {
-    remoteLocalStore->Flush();
-  }
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::webSearchFinalize(nsIChannel* channel, nsIInternetSearchContext *context)
-{
-  nsresult      rv;
-  nsCOMPtr<nsIRDFResource>  mParent;
-  if (NS_FAILED(rv = context->GetParent(getter_AddRefs(mParent))))  return(rv);
-//  Note: mParent can be null
-//  if (!mParent) return(NS_ERROR_NO_INTERFACE);
-
-  nsCOMPtr<nsIRDFResource>  mEngine;
-  if (NS_FAILED(rv = context->GetEngine(getter_AddRefs(mEngine))))  return(rv);
-  if (!mEngine) return(NS_ERROR_NO_INTERFACE);
-
-  nsCOMPtr<nsIURI> aURL;
-  rv = channel->GetURI(getter_AddRefs(aURL));
-  if (NS_FAILED(rv)) return rv;
-
-  // copy the engine's icon reference (if it has one) onto the result node
-  nsCOMPtr<nsIRDFNode>    engineIconStatusNode = nsnull;
-  mInner->GetTarget(mEngine, mNC_Icon, PR_TRUE, getter_AddRefs(engineIconStatusNode));
-  if (engineIconStatusNode)
-  {
-    rv = mInner->Assert(mEngine, mNC_StatusIcon, engineIconStatusNode, PR_TRUE);
-  }
-
-  const PRUnichar *uniBuf = nsnull;
-  if (NS_SUCCEEDED(rv = context->GetBufferConst(&uniBuf)) && (uniBuf))
-  {
-    if (mParent && (mBrowserSearchMode>0))
-    {
-      // save HTML result page for this engine
-      nsCOMPtr<nsIRDFLiteral> htmlLiteral;
-      if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(uniBuf, getter_AddRefs(htmlLiteral))))
-      {
-        rv = mInner->Assert(mEngine, mNC_HTML, htmlLiteral, PR_TRUE);
-      }
-    }
-
-    // parse up HTML results
-    PRInt32 uniBufLen = 0L;
-    if (NS_SUCCEEDED(rv = context->GetBufferLength(&uniBufLen)))
-    {
-      rv = ParseHTML(aURL, mParent, mEngine, uniBuf, uniBufLen);
-    }
-  }
-  else
-  {
-#ifdef  DEBUG_SEARCH_OUTPUT
-    printf(" *** InternetSearchDataSourceCallback::OnStopRequest:  no data.\n\n");
-#endif
-  }
-
-  // after we're all done with the html buffer, get rid of it
-  context->Truncate();
-
-  // (do this last) potentially remove the loading attribute
-  mInner->Unassert(mEngine, mNC_loading, mTrueLiteral);
-
-  if (mLoadGroup)
-  {
-    PRUint32  count = 0;
-    if (NS_SUCCEEDED(rv = mLoadGroup->GetActiveCount(&count)))
-    {
-      // is this the last connection in the loadgroup?
-      if (count <= 1)
-      {
-        Stop();
-      }
-    }
-  }
-
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::ParseHTML(nsIURI *aURL, nsIRDFResource *mParent,
-        nsIRDFResource *mEngine, const PRUnichar *htmlPage, PRInt32 htmlPageSize)
-{
-  // get data out of graph
-  nsresult  rv;
-  nsCOMPtr<nsIRDFNode>  dataNode;
-  if (NS_FAILED(rv = mInner->GetTarget(mEngine, mNC_Data, PR_TRUE, getter_AddRefs(dataNode))))
-  {
-    return(rv);
-  }
-  nsCOMPtr<nsIRDFLiteral> dataLiteral (do_QueryInterface(dataNode));
-  if (!dataLiteral) return(NS_ERROR_NULL_POINTER);
-
-  const PRUnichar *dataUni = nsnull;
-  if (NS_FAILED(rv = dataLiteral->GetValueConst(&dataUni)))
-    return(rv);
-  if (!dataUni) return(NS_ERROR_NULL_POINTER);
-
-  // get name of this engine once
-  nsAutoString  engineStr;
-  GetData(dataUni, "search", 0, "name", engineStr);
-
-  // pre-compute host (we might discard URLs that match this)
-  nsCAutoString hostName;
-  aURL->GetAsciiHost(hostName);
-
-  // pre-compute server path (we might discard URLs that match this)
-  nsAutoString  serverPathStr;
-  nsCAutoString serverPath;
-  aURL->GetPath(serverPath);
-  if (!serverPath.IsEmpty())
-  {
-    CopyUTF8toUTF16(serverPath, serverPathStr);
-    serverPath.Truncate();
-
-    PRInt32 serverOptionsOffset = serverPathStr.FindChar(PRUnichar('?'));
-    if (serverOptionsOffset >= 0) serverPathStr.SetLength(serverOptionsOffset);
-  }
-
-  PRBool    hasPriceFlag = PR_FALSE, hasAvailabilityFlag = PR_FALSE, hasRelevanceFlag = PR_FALSE;
-  PRBool    hasDateFlag = PR_FALSE;
-  PRBool    skipLocalFlag = PR_FALSE, useAllHREFsFlag = PR_FALSE;
-  PRInt32   pageRank = 1;
-  PRUint32  numInterpretSections, numResults = 0;
-
-  GetNumInterpretSections(dataUni, numInterpretSections);
-  if (numInterpretSections < 1)
-  {
-    // if no <interpret> sections, use all the HREFS on the page
-    numInterpretSections = 1;
-    useAllHREFsFlag = PR_TRUE;
-    skipLocalFlag = PR_TRUE;
-  }
-
-#ifdef  DEBUG
-  PRTime    now;
-  now = PR_Now();
-  printf("\nStart processing search results:   %u bytes \n", htmlPageSize); 
-#endif
-
-  // need to handle multiple <interpret> sections, per spec
-  for (PRUint32 interpretSectionNum=0; interpretSectionNum < numInterpretSections; interpretSectionNum++)
-  {
-    nsAutoString  resultListStartStr, resultListEndStr;
-    nsAutoString  resultItemStartStr, resultItemEndStr;
-    nsAutoString  relevanceStartStr, relevanceEndStr;
-    nsAutoString  bannerStartStr, bannerEndStr, skiplocalStr;
-    nsAutoString  priceStartStr, priceEndStr, availStartStr, availEndStr;
-    nsAutoString  dateStartStr, dateEndStr;
-    nsAutoString  nameStartStr, nameEndStr;
-    nsAutoString  emailStartStr, emailEndStr;
-    nsAutoString  browserResultTypeStr;
-    browserResultTypeStr.AssignLiteral("result");   // default to "result"
-
-    // use a nsDependentString so that "htmlPage" data isn't copied
-    nsDependentString  htmlResults(htmlPage, htmlPageSize);
-    PRUint32           startIndex = 0L, stopIndex = htmlPageSize;
-
-    if (!useAllHREFsFlag)
-    {
-      GetData(dataUni, "interpret", interpretSectionNum, "resultListStart", resultListStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "resultListEnd", resultListEndStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "resultItemStart", resultItemStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "resultItemEnd", resultItemEndStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "relevanceStart", relevanceStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "relevanceEnd", relevanceEndStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "bannerStart", bannerStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "bannerEnd", bannerEndStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "skiplocal", skiplocalStr);
-      skipLocalFlag = (skiplocalStr.LowerCaseEqualsLiteral("true")) ? PR_TRUE : PR_FALSE;
-
-      // shopping channel support
-      GetData(dataUni, "interpret", interpretSectionNum, "priceStart", priceStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "priceEnd", priceEndStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "availStart", availStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "availEnd", availEndStr);
-
-      // news channel support
-      GetData(dataUni, "interpret", interpretSectionNum, "dateStart", dateStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "dateEnd", dateEndStr);
-
-      // people channel support
-      GetData(dataUni, "interpret", interpretSectionNum, "nameStart", nameStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "nameEnd", nameEndStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "emailStart", emailStartStr);
-      GetData(dataUni, "interpret", interpretSectionNum, "emailEnd", emailEndStr);
-
-      // special browser support
-      GetData(dataUni, "interpret", interpretSectionNum, "browserResultType", browserResultTypeStr);
-      if (browserResultTypeStr.IsEmpty())
-      {
-        browserResultTypeStr.AssignLiteral("result"); // default to "result"
-      }
-    }
-
-    // look for banner
-    nsCOMPtr<nsIRDFLiteral> bannerLiteral;
-    if ((!bannerStartStr.IsEmpty()) && (!bannerEndStr.IsEmpty()))
-    {
-      PRInt32 bannerStart = htmlResults.Find(bannerStartStr, CaseInsensitiveCompare);
-      if (bannerStart >= 0)
-      {
-        startIndex = bannerStart;
-
-        PRInt32 bannerEnd = htmlResults.Find(bannerEndStr, bannerStart + bannerStartStr.Length(), CaseInsensitiveCompare);
-        if (bannerEnd > bannerStart)
-        {
-          stopIndex = bannerEnd - 1;
-
-          nsAutoString  htmlBanner;
-          htmlBanner = Substring(htmlResults, bannerStart, bannerEnd - bannerStart - 1);
-          if (!htmlBanner.IsEmpty())
-          {
-            const PRUnichar *bannerUni = htmlBanner.get();
-            if (bannerUni)
-            {
-              mRDFService->GetLiteral(bannerUni, getter_AddRefs(bannerLiteral));
-            }
-          }
-        }
-      }
-    }
-
-    if (!resultListStartStr.IsEmpty())
-    {
-      PRInt32 resultListStart = htmlResults.Find(resultListStartStr, CaseInsensitiveCompare);
-      if (resultListStart >= 0)
-      {
-        startIndex = resultListStart + resultListStartStr.Length();
-      }
-      else if (!useAllHREFsFlag)
-      {
-        // if we have multiple <INTERPRET> sections but can't find the startIndex
-        // of a result list block, just continue on with the the next block
-        continue;
-      }
-    }
-    if (!resultListEndStr.IsEmpty())
-    {
-      // rjc note: use RFind to find the LAST
-      // occurrence of resultListEndStr
-
-      const PRUnichar *originalStart, *start, *end;
-      htmlResults.BeginReading(&start, &end);
-      originalStart = start;
-      
-      if (RFindInReadable(resultListEndStr, &start, &end))
-        stopIndex = start - originalStart;
-    }
-
-    PRBool  trimItemStart = PR_TRUE;
-    PRBool  trimItemEnd = PR_FALSE;   // rjc note: testing shows we should NEVER trim end???
-
-    // if resultItemStartStr is not specified, try making it just be "HREF="
-    if (resultItemStartStr.IsEmpty())
-    {
-      resultItemStartStr.AssignLiteral("HREF=");
-      trimItemStart = PR_FALSE;
-    }
-
-    // if resultItemEndStr is not specified, try making it the same as resultItemStartStr
-    if (resultItemEndStr.IsEmpty())
-    {
-      resultItemEndStr = resultItemStartStr;
-      trimItemEnd = PR_TRUE;
-    }
-
-    while(startIndex < stopIndex)
-    {
-      PRInt32 resultItemStart;
-      resultItemStart = htmlResults.Find(resultItemStartStr, startIndex, CaseInsensitiveCompare);
-      if (resultItemStart < 0)  break;
-
-      PRInt32 resultItemEnd;
-      if (trimItemStart)
-      {
-        resultItemStart += resultItemStartStr.Length();
-        resultItemEnd = htmlResults.Find(resultItemEndStr, resultItemStart, CaseInsensitiveCompare);
-      }
-      else
-      {
-        resultItemEnd = htmlResults.Find(resultItemEndStr, resultItemStart + resultItemStartStr.Length(), CaseInsensitiveCompare);
-      }
-
-      if (resultItemEnd < 0)
-      {
-        resultItemEnd = stopIndex;
-      }
-      else if (!trimItemEnd && resultItemEnd >= 0)
-      {
-        resultItemEnd += resultItemEndStr.Length();
-      }
-
-      // forced to use an nsAutoString (which copies)
-      // as CBufDescriptor doesn't guarantee null terminator
-      if (resultItemEnd - resultItemStart - 1 <= 0)    break;
-      nsAutoString resultItem(&htmlPage[resultItemStart],
-        resultItemEnd - resultItemStart - 1);
-
-      if (resultItem.IsEmpty()) break;
-
-      // advance startIndex here so that, from this point onward, "continue" can be used
-      startIndex = resultItemEnd;
-
-#ifdef  DEBUG_SEARCH_OUTPUT
-      printf("\n----- Search result: '%s'\n\n", NS_ConvertUTF16toUTF8(resultItem).get());
-#endif
-
-      // look for href
-      PRInt32 hrefOffset = resultItem.Find("HREF=", PR_TRUE);
-      if (hrefOffset < 0)
-      {
-#ifdef  DEBUG_SEARCH_OUTPUT
-        printf("\n***** Unable to find HREF!\n\n");
-#endif
-        continue;
-      }
-
-      nsAutoString  hrefStr;
-      PRInt32   quoteStartOffset = nsString_FindCharInSet(resultItem, "\"\'>", hrefOffset);
-      PRInt32   quoteEndOffset;
-      if (quoteStartOffset < hrefOffset)
-      {
-        // handle case where HREF isn't quoted
-        quoteStartOffset = hrefOffset + strlen("HREF=");
-        quoteEndOffset = resultItem.FindChar('>', quoteStartOffset);
-        if (quoteEndOffset < quoteStartOffset)  continue;
-      }
-      else
-      {
-        if (resultItem[quoteStartOffset] == PRUnichar('>'))
-        {
-          // handle case where HREF isn't quoted
-          quoteEndOffset = quoteStartOffset;
-          quoteStartOffset = hrefOffset + strlen("HREF=") -1;
-        }
-        else
-        {
-          quoteEndOffset = nsString_FindCharInSet(resultItem, "\"\'", quoteStartOffset + 1);
-          if (quoteEndOffset < hrefOffset)  continue;
-        }
-      }
-      hrefStr = Substring(resultItem, quoteStartOffset + 1, quoteEndOffset - quoteStartOffset - 1);
-
-      ConvertEntities(hrefStr, PR_FALSE, PR_TRUE, PR_FALSE);
-
-      if (hrefStr.IsEmpty())  continue;
-
-      nsAutoString absURIStr;
-
-      if (NS_SUCCEEDED(rv = NS_MakeAbsoluteURI(absURIStr, hrefStr, aURL)))
-      {
-        hrefStr.Assign(absURIStr);
-
-        nsCOMPtr<nsIURI>  absURI;
-        rv = NS_NewURI(getter_AddRefs(absURI), absURIStr);
-
-        if (absURI && skipLocalFlag)
-        {
-          nsCAutoString absPath;
-          absURI->GetPath(absPath);
-          if (!absPath.IsEmpty())
-          {
-                        NS_ConvertUTF8toUTF16 absPathStr(absPath);
-            PRInt32 pathOptionsOffset = absPathStr.FindChar(PRUnichar('?'));
-            if (pathOptionsOffset >= 0)
-              absPathStr.SetLength(pathOptionsOffset);
-            PRBool  pathsMatchFlag = serverPathStr.Equals(absPathStr, CaseInsensitiveCompare);
-            if (pathsMatchFlag)
-              continue;
-          }
-
-          if (!hostName.IsEmpty())
-          {
-            nsCAutoString absHost;
-            absURI->GetAsciiHost(absHost);
-            if (!absHost.IsEmpty())
-            {
-              PRBool  hostsMatchFlag = hostName.Equals(absHost, CaseInsensitiveCompare);
-              if (hostsMatchFlag)
-                continue;
-            }
-          }
-        }
-      }
-
-      // if this result is to be filtered out, notice it now
-      if (isSearchResultFiltered(hrefStr))
-        continue;
-
-      nsAutoString  site(hrefStr);
-
-#ifdef  DEBUG_SEARCH_OUTPUT
-      printf("HREF: '%s'\n", NS_ConvertUTF16toUTF8(hrefStr).get());
-#endif
-
-      nsCOMPtr<nsIRDFResource>  res;
-
-      // save HREF attribute as URL
-      if (NS_SUCCEEDED(rv = mRDFService->GetAnonymousResource(getter_AddRefs(res))))
-      {
-        const PRUnichar *hrefUni = hrefStr.get();
-        if (hrefUni)
-        {
-          nsCOMPtr<nsIRDFLiteral> hrefLiteral;
-          if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(hrefUni, getter_AddRefs(hrefLiteral))))
-          {
-            mInner->Assert(res, mNC_URL, hrefLiteral, PR_TRUE);
-          }
-        }
-      }
-
-      if (NS_FAILED(rv))  continue;
-      
-      // set HTML response chunk
-      const PRUnichar *htmlResponseUni = resultItem.get();
-      if (htmlResponseUni && (mBrowserSearchMode > 0))
-      {
-        nsCOMPtr<nsIRDFLiteral> htmlResponseLiteral;
-        if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(htmlResponseUni, getter_AddRefs(htmlResponseLiteral))))
-        {
-          if (htmlResponseLiteral)
-          {
-            mInner->Assert(res, mNC_HTML, htmlResponseLiteral, PR_TRUE);
-          }
-        }
-      }
-      
-      // set banner (if we have one)
-      if (bannerLiteral)
-      {
-        mInner->Assert(res, mNC_Banner, bannerLiteral, PR_TRUE);
-      }
-
-      // look for Site (if it isn't already set)
-      nsCOMPtr<nsIRDFNode>    oldSiteRes = nsnull;
-      mInner->GetTarget(res, mNC_Site, PR_TRUE, getter_AddRefs(oldSiteRes));
-      if (!oldSiteRes)
-      {
-        PRInt32 protocolOffset = site.FindChar(':', 0);
-        if (protocolOffset >= 0)
-        {
-          site.Cut(0, protocolOffset+1);
-          while (site[0] == PRUnichar('/'))
-          {
-            site.Cut(0, 1);
-          }
-          PRInt32 slashOffset = site.FindChar('/', 0);
-          if (slashOffset >= 0)
-          {
-            site.SetLength(slashOffset);
-          }
-          if (!site.IsEmpty())
-          {
-            const PRUnichar *siteUni = site.get();
-            if (siteUni)
-            {
-              nsCOMPtr<nsIRDFLiteral> siteLiteral;
-              if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(siteUni, getter_AddRefs(siteLiteral))))
-              {
-                if (siteLiteral)
-                {
-                  mInner->Assert(res, mNC_Site, siteLiteral, PR_TRUE);
-                }
-              }
-            }
-          }
-        }
-      }
-
-      // look for name
-      nsAutoString  nameStr;
-
-      if ((!nameStartStr.IsEmpty()) && (!nameEndStr.IsEmpty()))
-      {
-        PRInt32   nameStart;
-        if ((nameStart = resultItem.Find(nameStartStr, CaseInsensitiveCompare)) >= 0)
-        {
-          nameStart += nameStartStr.Length();
-          PRInt32 nameEnd = resultItem.Find(nameEndStr, nameStart, CaseInsensitiveCompare);
-          if (nameEnd > nameStart)
-          {
-            nameStr = Substring(resultItem, nameStart, nameEnd - nameStart);
-          }
-        }
-      }
-
-      if (nameStr.IsEmpty())
-      {
-        PRInt32 anchorEnd = resultItem.FindChar('>', quoteEndOffset);
-        if (anchorEnd < quoteEndOffset)
-        {
-#ifdef  DEBUG_SEARCH_OUTPUT
-          printf("\n\nSearch: Unable to find ending > when computing name.\n\n");
-#endif
-          continue;
-        }
-        PRInt32 anchorStop = resultItem.Find("</A>", PR_TRUE, quoteEndOffset);
-        if (anchorStop < anchorEnd)
-        {
-#ifdef  DEBUG_SEARCH_OUTPUT
-          printf("\n\nSearch: Unable to find </A> tag to compute name.\n\n");
-#endif
-          continue;
-        }
-        nameStr = Substring(resultItem, anchorEnd + 1, anchorStop - anchorEnd - 1);
-      }
-
-      ConvertEntities(nameStr);
-
-      // look for Name (if it isn't already set)
-      nsCOMPtr<nsIRDFNode>    oldNameRes = nsnull;
-      if (!oldNameRes)
-      {
-        if (!nameStr.IsEmpty())
-        {
-          const PRUnichar *nameUni = nameStr.get();
-          if (nameUni)
-          {
-            nsCOMPtr<nsIRDFLiteral> nameLiteral;
-            if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(nameUni, getter_AddRefs(nameLiteral))))
-            {
-              if (nameLiteral)
-              {
-                mInner->Assert(res, mNC_Name, nameLiteral, PR_TRUE);
-              }
-            }
-          }
-        }
-      }
-
-      // look for date
-      if (!dateStartStr.IsEmpty())
-      {
-        nsAutoString  dateItem;
-        PRInt32   dateStart = resultItem.Find(dateStartStr, CaseInsensitiveCompare);
-        if (dateStart >= 0)
-        {
-          dateStart += dateStartStr.Length();
-          PRInt32 dateEnd = resultItem.Find(dateEndStr, dateStart, CaseInsensitiveCompare);
-          if (dateEnd > dateStart)
-          {
-            dateItem = Substring(resultItem, dateStart, dateEnd - dateStart);
-          }
-        }
-        
-        // strip out any html tags
-        PRInt32   ltOffset, gtOffset;
-        while ((ltOffset = dateItem.FindChar(PRUnichar('<'))) >= 0)
-        {
-          if ((gtOffset = dateItem.FindChar(PRUnichar('>'), ltOffset)) <= ltOffset)
-            break;
-          dateItem.Cut(ltOffset, gtOffset - ltOffset + 1);
-        }
-
-        // strip out whitespace and any CR/LFs
-        dateItem.Trim("\n\r\t ");
-
-        if (!dateItem.IsEmpty())
-        {
-          const PRUnichar   *dateUni = dateItem.get();
-          nsCOMPtr<nsIRDFLiteral> dateLiteral;
-          if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(dateUni, getter_AddRefs(dateLiteral))))
-          {
-            if (dateLiteral)
-            {
-              mInner->Assert(res, mNC_Date, dateLiteral, PR_TRUE);
-              hasDateFlag = PR_TRUE;
-            }
-          }
-        }
-      }
-
-      // look for price
-      if (!priceStartStr.IsEmpty())
-      {
-        nsAutoString  priceItem;
-        PRInt32   priceStart = resultItem.Find(priceStartStr, CaseInsensitiveCompare);
-        if (priceStart >= 0)
-        {
-          priceStart += priceStartStr.Length();
-          PRInt32 priceEnd = resultItem.Find(priceEndStr, priceStart, CaseInsensitiveCompare);
-          if (priceEnd > priceStart)
-          {
-            priceItem = Substring(resultItem, priceStart, priceEnd - priceStart);
-            ConvertEntities(priceItem);
-          }
-        }
-        if (!priceItem.IsEmpty())
-        {
-          const PRUnichar   *priceUni = priceItem.get();
-          nsCOMPtr<nsIRDFLiteral> priceLiteral;
-          if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(priceUni, getter_AddRefs(priceLiteral))))
-          {
-            if (priceLiteral)
-            {
-              mInner->Assert(res, mNC_Price, priceLiteral, PR_TRUE);
-              hasPriceFlag = PR_TRUE;
-            }
-          }
-
-          PRInt32 priceCharStartOffset = nsString_FindCharInSet(priceItem, "1234567890");
-          if (priceCharStartOffset >= 0)
-          {
-            priceItem.Cut(0, priceCharStartOffset);
-            nsCString priceItemC = NS_LossyConvertUTF16toASCII(priceItem);
-            float val = (float)PR_strtod(priceItemC.BeginReading(), nsnull);
-            if (priceItem.FindChar(PRUnichar('.')) >= 0)  val *= 100;
-
-            nsCOMPtr<nsIRDFInt> priceSortLiteral;
-            if (NS_SUCCEEDED(rv = mRDFService->GetIntLiteral((PRInt32)val, getter_AddRefs(priceSortLiteral))))
-            {
-              if (priceSortLiteral)
-              {
-                mInner->Assert(res, mNC_PriceSort, priceSortLiteral, PR_TRUE);
-              }
-            }
-          }
-        }
-        // look for availability (if we looked for price)
-        if (!availStartStr.IsEmpty())
-        {
-          nsAutoString  availItem;
-          PRInt32   availStart = resultItem.Find(availStartStr, CaseInsensitiveCompare);
-          if (availStart >= 0)
-          {
-            availStart += availStartStr.Length();
-            PRInt32 availEnd = resultItem.Find(availEndStr, availStart, CaseInsensitiveCompare);
-            if (availEnd > availStart)
-            {
-              availItem = Substring(resultItem, availStart, availEnd - availStart);
-              ConvertEntities(availItem);
-            }
-          }
-          if (!availItem.IsEmpty())
-          {
-            const PRUnichar   *availUni = availItem.get();
-            nsCOMPtr<nsIRDFLiteral> availLiteral;
-            if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(availUni, getter_AddRefs(availLiteral))))
-            {
-              if (availLiteral)
-              {
-                mInner->Assert(res, mNC_Availability, availLiteral, PR_TRUE);
-                hasAvailabilityFlag = PR_TRUE;
-              }
-            }
-          }
-        }
-      }
-
-      // look for relevance
-      nsAutoString  relItem;
-      PRInt32   relStart = resultItem.Find(relevanceStartStr, CaseInsensitiveCompare);
-      if (relStart >= 0)
-      {
-        relStart += relevanceStartStr.Length();
-        PRInt32 relEnd = resultItem.Find(relevanceEndStr, CaseInsensitiveCompare);
-        if (relEnd > relStart)
-        {
-          relItem = Substring(resultItem, relStart, relEnd - relStart);
-        }
-      }
-
-      // look for Relevance (if it isn't already set)
-      nsCOMPtr<nsIRDFNode>    oldRelRes = nsnull;
-      if (!oldRelRes)
-      {
-        if (!relItem.IsEmpty())
-        {
-          // save real relevance
-          const PRUnichar *relUni = relItem.get();
-          if (relUni)
-          {
-            nsAutoString  relStr(relUni);
-            // take out any characters that aren't numeric or "%"
-            PRInt32 len = relStr.Length();
-            for (PRInt32 x=len-1; x>=0; x--)
-            {
-              PRUnichar ch;
-              ch = relStr.CharAt(x);
-              if ((ch != PRUnichar('%')) &&
-                ((ch < PRUnichar('0')) || (ch > PRUnichar('9'))))
-              {
-                relStr.Cut(x, 1);
-              }
-            }
-            // make sure it ends with a "%"
-            len = relStr.Length();
-            if (len > 0)
-            {
-              PRUnichar ch;
-              ch = relStr.CharAt(len - 1);
-              if (ch != PRUnichar('%'))
-              {
-                relStr += PRUnichar('%');
-              }
-              relItem = relStr;
-              hasRelevanceFlag = PR_TRUE;
-            }
-            else
-            {
-              relItem.Truncate();
-            }
-          }
-        }
-        if (relItem.IsEmpty())
-        {
-          relItem.AssignLiteral("-");
-        }
-
-        const PRUnichar *relItemUni = relItem.get();
-        nsCOMPtr<nsIRDFLiteral> relLiteral;
-        if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(relItemUni, getter_AddRefs(relLiteral))))
-        {
-          if (relLiteral)
-          {
-            mInner->Assert(res, mNC_Relevance, relLiteral, PR_TRUE);
-          }
-        }
-
-        if ((!relItem.IsEmpty()) && (!relItem.EqualsLiteral("-")))
-        {
-          // If its a percentage, remove "%"
-          if (relItem[relItem.Length()-1] == PRUnichar('%'))
-          {
-            relItem.Cut(relItem.Length()-1, 1);
-          }
-
-          // left-pad with "0"s and set special sorting value
-          nsAutoString  zero;
-          zero.AssignLiteral("000");
-          if (relItem.Length() < 3)
-          {
-            relItem.Insert(zero.get(), 0, zero.Length() - relItem.Length()); 
-          }
-        }
-        else
-        {
-          relItem.AssignLiteral("000");
-        }
-
-        const PRUnichar *relSortUni = relItem.get();
-        if (relSortUni)
-        {
-          nsCOMPtr<nsIRDFLiteral> relSortLiteral;
-          if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(relSortUni, getter_AddRefs(relSortLiteral))))
-          {
-            if (relSortLiteral)
-            {
-              mInner->Assert(res, mNC_RelevanceSort, relSortLiteral, PR_TRUE);
-            }
-          }
-        }
-      }
-
-      // set reference to engine this came from (if it isn't already set)
-      nsCOMPtr<nsIRDFNode>    oldEngineRes = nsnull;
-      if (!oldEngineRes)
-      {
-        if (!engineStr.IsEmpty())
-        {
-          const PRUnichar   *engineUni = engineStr.get();
-          nsCOMPtr<nsIRDFLiteral> engineLiteral;
-          if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(engineUni, getter_AddRefs(engineLiteral))))
-          {
-            if (engineLiteral)
-            {
-              mInner->Assert(res, mNC_Engine, engineLiteral, PR_TRUE);
-            }
-          }
-        }
-      }
-
-      // copy the engine's icon reference (if it has one) onto the result node
-      nsCOMPtr<nsIRDFNode>    engineIconNode = nsnull;
-      mInner->GetTarget(mEngine, mNC_Icon, PR_TRUE, getter_AddRefs(engineIconNode));
-
-      // if no branding icon, use some default icons
-      nsAutoString  iconChromeDefault;
-
-      if (browserResultTypeStr.LowerCaseEqualsLiteral("category"))
-        iconChromeDefault.AssignLiteral("chrome://communicator/skin/search/category.gif");
-      else if ((browserResultTypeStr.LowerCaseEqualsLiteral("result")) && (!engineIconNode))
-        iconChromeDefault.AssignLiteral("chrome://communicator/skin/search/result.gif");
-
-      if (!iconChromeDefault.IsEmpty())
-      {
-        const PRUnichar   *iconUni = iconChromeDefault.get();
-        nsCOMPtr<nsIRDFLiteral> iconLiteral;
-        if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(iconUni, getter_AddRefs(iconLiteral))))
-        {
-          if (iconLiteral)
-          {
-            mInner->Assert(res, mNC_Icon, iconLiteral, PR_TRUE);
-          }
-        }
-      }
-      else if (engineIconNode)
-      {
-        rv = mInner->Assert(res, mNC_Icon, engineIconNode, PR_TRUE);
-      }
-
-      // set result page rank
-      nsCOMPtr<nsIRDFInt> pageRankLiteral;
-      if (NS_SUCCEEDED(rv = mRDFService->GetIntLiteral(pageRank++, getter_AddRefs(pageRankLiteral))))
-      {
-        rv = mInner->Assert(res, mNC_PageRank, pageRankLiteral, PR_TRUE);
-      }
-
-      // set the result type
-      if (!browserResultTypeStr.IsEmpty())
-      {
-        const PRUnichar   *resultTypeUni = browserResultTypeStr.get();
-        nsCOMPtr<nsIRDFLiteral> resultTypeLiteral;
-        if (NS_SUCCEEDED(rv = mRDFService->GetLiteral(resultTypeUni, getter_AddRefs(resultTypeLiteral))))
-        {
-          if (resultTypeLiteral)
-          {
-            mInner->Assert(res, mNC_SearchType, resultTypeLiteral, PR_TRUE);
-          }
-        }
-      }
-
-      // set the node type
-      rv = mInner->Assert(res, mRDF_type, mNC_SearchResult, PR_TRUE);
-
-      // Note: always add in parent-child relationship last!  (if it isn't already set)
-#ifdef  OLDWAY
-      PRBool    parentHasChildFlag = PR_FALSE;
-      if (mParent)
-      {
-        mInner->HasAssertion(mParent, mNC_Child, res, PR_TRUE, &parentHasChildFlag);
-      }
-      if (!parentHasChildFlag)
-#endif
-      {
-        if (mParent)
-        {
-          rv = mInner->Assert(mParent, mNC_Child, res, PR_TRUE);
-        }
-      }
-
-      // Persist this under mNC_LastSearchRoot
-      if (mInner)
-      {
-        rv = mInner->Assert(mNC_LastSearchRoot, mNC_Child, res, PR_TRUE);
-      }
-
-      ++numResults;
-
-      // place a cap on the # of results we can process
-      if (numResults >= MAX_SEARCH_RESULTS_ALLOWED)
-        break;
-
-    }
-  }
-
-  // set hints so that the appropriate columns can be displayed
-  if (mParent)
-  {
-    if (hasPriceFlag)
-      SetHint(mParent, mNC_Price);
-    if (hasAvailabilityFlag)
-      SetHint(mParent, mNC_Availability);
-    if (hasRelevanceFlag)
-      SetHint(mParent, mNC_Relevance);
-    if (hasDateFlag)
-      SetHint(mParent, mNC_Date);
-  }
-
-#ifdef  DEBUG
-  PRTime    now2;
-  now2 = PR_Now();
-  PRUint64  loadTime64;
-  LL_SUB(loadTime64, now2, now);
-  PRUint32  loadTime32;
-  LL_L2UI(loadTime32, loadTime64);
-  printf("Finished processing search results  (%u microseconds)\n", loadTime32);
-#endif
-
-  return(NS_OK);
-}
-
-
-
-nsresult
-InternetSearchDataSource::SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes)
-{
-  if (!mInner)  return(NS_OK);
-
-  nsresult  rv;
-  PRBool    hasAssertionFlag = PR_FALSE;
-  rv = mInner->HasAssertion(mParent, hintRes, mTrueLiteral, PR_TRUE,
-                            &hasAssertionFlag);
-  if (NS_SUCCEEDED(rv) && !hasAssertionFlag)
-  {
-    rv = mInner->Assert(mParent, hintRes, mTrueLiteral, PR_TRUE);
-  }
-  return(rv);
-}
-
-
-
-nsresult
-InternetSearchDataSource::ConvertEntities(nsString &nameStr, PRBool removeHTMLFlag,
-          PRBool removeCRLFsFlag, PRBool trimWhiteSpaceFlag)
-{
-  PRInt32 startOffset = 0, ampOffset, semiOffset, offset;
-
-  // do this before converting entities
-  if (removeHTMLFlag)
-  {
-    // munge out anything inside of HTML "<" / ">" tags
-    while ((offset = nameStr.FindChar(PRUnichar('<'), 0)) >= 0)
-    {
-      PRInt32 offsetEnd = nameStr.FindChar(PRUnichar('>'), offset+1);
-      if (offsetEnd <= offset)  break;
-      nameStr.Cut(offset, offsetEnd - offset + 1);
-    }
-  }
-  while ((ampOffset = nameStr.FindChar(PRUnichar('&'), startOffset)) >= 0)
-  {
-    if ((semiOffset = nameStr.FindChar(PRUnichar(';'), ampOffset+1)) <= ampOffset)
-      break;
-
-    nsAutoString  entityStr(Substring(nameStr, ampOffset, semiOffset - ampOffset + 1));
-    nameStr.Cut(ampOffset, semiOffset-ampOffset+1);
-
-    PRUnichar entityChar = 0;
-    if (entityStr.LowerCaseEqualsLiteral("&quot;")) entityChar = PRUnichar('\"');
-    else if (entityStr.LowerCaseEqualsLiteral("&amp;")) entityChar = PRUnichar('&');
-    else if (entityStr.LowerCaseEqualsLiteral("&nbsp;"))  entityChar = PRUnichar(' ');
-    else if (entityStr.LowerCaseEqualsLiteral("&lt;"))    entityChar = PRUnichar('<');
-    else if (entityStr.LowerCaseEqualsLiteral("&gt;"))    entityChar = PRUnichar('>');
-    else if (entityStr.LowerCaseEqualsLiteral("&iexcl;")) entityChar = PRUnichar(161);
-    else if (entityStr.LowerCaseEqualsLiteral("&cent;"))  entityChar = PRUnichar(162);
-    else if (entityStr.LowerCaseEqualsLiteral("&pound;")) entityChar = PRUnichar(163);
-    else if (entityStr.LowerCaseEqualsLiteral("&curren;"))  entityChar = PRUnichar(164);
-    else if (entityStr.LowerCaseEqualsLiteral("&yen;")) entityChar = PRUnichar(165);
-    else if (entityStr.LowerCaseEqualsLiteral("&brvbar;"))  entityChar = PRUnichar(166);
-    else if (entityStr.LowerCaseEqualsLiteral("&sect;"))  entityChar = PRUnichar(167);
-    else if (entityStr.LowerCaseEqualsLiteral("&uml;")) entityChar = PRUnichar(168);
-    else if (entityStr.LowerCaseEqualsLiteral("&copy;"))  entityChar = PRUnichar(169);
-    else if (entityStr.LowerCaseEqualsLiteral("&ordf;"))  entityChar = PRUnichar(170);
-    else if (entityStr.LowerCaseEqualsLiteral("&laquo;")) entityChar = PRUnichar(171);
-    else if (entityStr.LowerCaseEqualsLiteral("&not;")) entityChar = PRUnichar(172);
-    else if (entityStr.LowerCaseEqualsLiteral("&shy;")) entityChar = PRUnichar(173);
-    else if (entityStr.LowerCaseEqualsLiteral("&reg;")) entityChar = PRUnichar(174);
-    else if (entityStr.LowerCaseEqualsLiteral("&macr;"))  entityChar = PRUnichar(175);
-    else if (entityStr.LowerCaseEqualsLiteral("&deg;")) entityChar = PRUnichar(176);
-    else if (entityStr.LowerCaseEqualsLiteral("&plusmn;"))  entityChar = PRUnichar(177);
-    else if (entityStr.LowerCaseEqualsLiteral("&sup2;"))  entityChar = PRUnichar(178);
-    else if (entityStr.LowerCaseEqualsLiteral("&sup3;"))  entityChar = PRUnichar(179);
-    else if (entityStr.LowerCaseEqualsLiteral("&acute;")) entityChar = PRUnichar(180);
-    else if (entityStr.LowerCaseEqualsLiteral("&micro;")) entityChar = PRUnichar(181);
-    else if (entityStr.LowerCaseEqualsLiteral("&para;"))  entityChar = PRUnichar(182);
-    else if (entityStr.LowerCaseEqualsLiteral("&middot;"))  entityChar = PRUnichar(183);
-    else if (entityStr.LowerCaseEqualsLiteral("&cedil;")) entityChar = PRUnichar(184);
-    else if (entityStr.LowerCaseEqualsLiteral("&sup1;"))  entityChar = PRUnichar(185);
-    else if (entityStr.LowerCaseEqualsLiteral("&ordm;"))  entityChar = PRUnichar(186);
-    else if (entityStr.LowerCaseEqualsLiteral("&raquo;")) entityChar = PRUnichar(187);
-    else if (entityStr.LowerCaseEqualsLiteral("&frac14;"))  entityChar = PRUnichar(188);
-    else if (entityStr.LowerCaseEqualsLiteral("&frac12;"))  entityChar = PRUnichar(189);
-    else if (entityStr.LowerCaseEqualsLiteral("&frac34;"))  entityChar = PRUnichar(190);
-    else if (entityStr.LowerCaseEqualsLiteral("&iquest;"))  entityChar = PRUnichar(191);
-    else if (entityStr.LowerCaseEqualsLiteral("&agrave;"))  entityChar = PRUnichar(192);
-    else if (entityStr.LowerCaseEqualsLiteral("&aacute;"))  entityChar = PRUnichar(193);
-    else if (entityStr.LowerCaseEqualsLiteral("&acirc;")) entityChar = PRUnichar(194);
-    else if (entityStr.LowerCaseEqualsLiteral("&atilde;"))  entityChar = PRUnichar(195);
-    else if (entityStr.LowerCaseEqualsLiteral("&auml;"))  entityChar = PRUnichar(196);
-    else if (entityStr.LowerCaseEqualsLiteral("&aring;")) entityChar = PRUnichar(197);
-    else if (entityStr.LowerCaseEqualsLiteral("&aelig;")) entityChar = PRUnichar(198);
-    else if (entityStr.LowerCaseEqualsLiteral("&ccedil;"))  entityChar = PRUnichar(199);
-    else if (entityStr.LowerCaseEqualsLiteral("&egrave;"))  entityChar = PRUnichar(200);
-    else if (entityStr.LowerCaseEqualsLiteral("&eacute;"))  entityChar = PRUnichar(201);
-    else if (entityStr.LowerCaseEqualsLiteral("&ecirc;")) entityChar = PRUnichar(202);
-    else if (entityStr.LowerCaseEqualsLiteral("&euml;"))  entityChar = PRUnichar(203);
-    else if (entityStr.LowerCaseEqualsLiteral("&igrave;"))  entityChar = PRUnichar(204);
-    else if (entityStr.LowerCaseEqualsLiteral("&iacute;"))  entityChar = PRUnichar(205);
-    else if (entityStr.LowerCaseEqualsLiteral("&icirc;")) entityChar = PRUnichar(206);
-    else if (entityStr.LowerCaseEqualsLiteral("&iuml;"))  entityChar = PRUnichar(207);
-    else if (entityStr.LowerCaseEqualsLiteral("&eth;")) entityChar = PRUnichar(208);
-    else if (entityStr.LowerCaseEqualsLiteral("&ntilde;"))  entityChar = PRUnichar(209);
-    else if (entityStr.LowerCaseEqualsLiteral("&ograve;"))  entityChar = PRUnichar(210);
-    else if (entityStr.LowerCaseEqualsLiteral("&oacute;"))  entityChar = PRUnichar(211);
-    else if (entityStr.LowerCaseEqualsLiteral("&ocirc;")) entityChar = PRUnichar(212);
-    else if (entityStr.LowerCaseEqualsLiteral("&otilde;"))  entityChar = PRUnichar(213);
-    else if (entityStr.LowerCaseEqualsLiteral("&ouml;"))  entityChar = PRUnichar(214);
-    else if (entityStr.LowerCaseEqualsLiteral("&times;")) entityChar = PRUnichar(215);
-    else if (entityStr.LowerCaseEqualsLiteral("&oslash;"))  entityChar = PRUnichar(216);
-    else if (entityStr.LowerCaseEqualsLiteral("&ugrave;"))  entityChar = PRUnichar(217);
-    else if (entityStr.LowerCaseEqualsLiteral("&uacute;"))  entityChar = PRUnichar(218);
-    else if (entityStr.LowerCaseEqualsLiteral("&ucirc;")) entityChar = PRUnichar(219);
-    else if (entityStr.LowerCaseEqualsLiteral("&uuml;"))  entityChar = PRUnichar(220);
-    else if (entityStr.LowerCaseEqualsLiteral("&yacute;"))  entityChar = PRUnichar(221);
-    else if (entityStr.LowerCaseEqualsLiteral("&thorn;")) entityChar = PRUnichar(222);
-    else if (entityStr.LowerCaseEqualsLiteral("&szlig;")) entityChar = PRUnichar(223);
-    else if (entityStr.LowerCaseEqualsLiteral("&agrave;"))  entityChar = PRUnichar(224);
-    else if (entityStr.LowerCaseEqualsLiteral("&aacute;"))  entityChar = PRUnichar(225);
-    else if (entityStr.LowerCaseEqualsLiteral("&acirc;")) entityChar = PRUnichar(226);
-    else if (entityStr.LowerCaseEqualsLiteral("&atilde;"))  entityChar = PRUnichar(227);
-    else if (entityStr.LowerCaseEqualsLiteral("&auml;"))  entityChar = PRUnichar(228);
-    else if (entityStr.LowerCaseEqualsLiteral("&aring;")) entityChar = PRUnichar(229);
-    else if (entityStr.LowerCaseEqualsLiteral("&aelig;")) entityChar = PRUnichar(230);
-    else if (entityStr.LowerCaseEqualsLiteral("&ccedil;"))  entityChar = PRUnichar(231);
-    else if (entityStr.LowerCaseEqualsLiteral("&egrave;"))  entityChar = PRUnichar(232);
-    else if (entityStr.LowerCaseEqualsLiteral("&eacute;"))  entityChar = PRUnichar(233);
-    else if (entityStr.LowerCaseEqualsLiteral("&ecirc;")) entityChar = PRUnichar(234);
-    else if (entityStr.LowerCaseEqualsLiteral("&euml;"))  entityChar = PRUnichar(235);
-    else if (entityStr.LowerCaseEqualsLiteral("&igrave;"))  entityChar = PRUnichar(236);
-    else if (entityStr.LowerCaseEqualsLiteral("&iacute;"))  entityChar = PRUnichar(237);
-    else if (entityStr.LowerCaseEqualsLiteral("&icirc;")) entityChar = PRUnichar(238);
-    else if (entityStr.LowerCaseEqualsLiteral("&iuml;"))  entityChar = PRUnichar(239);
-    else if (entityStr.LowerCaseEqualsLiteral("&eth;")) entityChar = PRUnichar(240);
-    else if (entityStr.LowerCaseEqualsLiteral("&ntilde;"))  entityChar = PRUnichar(241);
-    else if (entityStr.LowerCaseEqualsLiteral("&ograve;"))  entityChar = PRUnichar(242);
-    else if (entityStr.LowerCaseEqualsLiteral("&oacute;"))  entityChar = PRUnichar(243);
-    else if (entityStr.LowerCaseEqualsLiteral("&ocirc;")) entityChar = PRUnichar(244);
-    else if (entityStr.LowerCaseEqualsLiteral("&otilde;"))  entityChar = PRUnichar(245);
-    else if (entityStr.LowerCaseEqualsLiteral("&ouml;"))  entityChar = PRUnichar(246);
-    else if (entityStr.LowerCaseEqualsLiteral("&divide;"))  entityChar = PRUnichar(247);
-    else if (entityStr.LowerCaseEqualsLiteral("&oslash;"))  entityChar = PRUnichar(248);
-    else if (entityStr.LowerCaseEqualsLiteral("&ugrave;"))  entityChar = PRUnichar(249);
-    else if (entityStr.LowerCaseEqualsLiteral("&uacute;"))  entityChar = PRUnichar(250);
-    else if (entityStr.LowerCaseEqualsLiteral("&ucirc;")) entityChar = PRUnichar(251);
-    else if (entityStr.LowerCaseEqualsLiteral("&uuml;"))  entityChar = PRUnichar(252);
-    else if (entityStr.LowerCaseEqualsLiteral("&yacute;"))  entityChar = PRUnichar(253);
-    else if (entityStr.LowerCaseEqualsLiteral("&thorn;")) entityChar = PRUnichar(254);
-    else if (entityStr.LowerCaseEqualsLiteral("&yuml;"))  entityChar = PRUnichar(255);
-
-    startOffset = ampOffset;
-    if (entityChar != 0)
-    {
-      nameStr.Insert(entityChar, ampOffset);
-      ++startOffset;
-    }
-  }
-
-  if (removeCRLFsFlag)
-  {
-    nameStr.StripChars("\n\r");
-  }
-
-  if (trimWhiteSpaceFlag)
-  {
-    // trim name
-    nameStr.Trim(" \t");
-  }
-
-  return(NS_OK);
-}
-
-NS_IMETHODIMP
-InternetSearchDataSource::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *someData)
-{
-    nsresult rv = NS_OK;
-
-    if (!strcmp(aTopic, "profile-before-change"))
-    {
-        // The profile is about to change.
-        categoryDataSource = nsnull;
-
-        if (someData && NS_LITERAL_STRING("shutdown-cleanse").Equals(someData))
-        {
-            // Delete search.rdf
-            nsCOMPtr<nsIFile> searchFile;
-            rv = NS_GetSpecialDirectory(NS_APP_SEARCH_50_FILE, getter_AddRefs(searchFile));
-            if (NS_SUCCEEDED(rv))
-                rv = searchFile->Remove(PR_FALSE);
-        }
-    }
-    else if (!strcmp(aTopic, "profile-do-change"))
-    {
-        // The profile has aleady changed.
-        if (!categoryDataSource)
-          GetCategoryList();
-    }
-    else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID))
-    {
-        nsCOMPtr<nsIPrefBranch> prefs = do_QueryInterface(aSubject);
-        if (prefs)
-        {
-            prefs->GetIntPref("browser.search.mode", &mBrowserSearchMode);
-            Assert(mNC_LastSearchRoot, mNC_LastSearchMode, mTrueLiteral, PR_TRUE);
-        }
-    }
-
-    return rv;
-}
-
deleted file mode 100644
--- a/suite/browser/src/nsInternetSearchService.h
+++ /dev/null
@@ -1,203 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
- 
-#ifndef nsinternetsearchdatasource__h____
-#define nsinternetsearchdatasource__h____
-
-#include "nsCOMPtr.h"
-#include "nsStringAPI.h"
-#include "nsISearchService.h"
-#include "nsIRDFDataSource.h"
-#include "nsIStreamListener.h"
-#include "nsIObserver.h"
-#include "nsWeakReference.h"
-#include "nsIRDFService.h"
-#include "nsIRDFContainerUtils.h"
-#include "nsITimer.h"
-#include "nsIChannel.h"
-#include "nsILoadGroup.h"
-#include "nsCycleCollectionParticipant.h"
-
-class InternetSearchDataSource : public nsIInternetSearchService,
-                                 public nsIRDFDataSource,
-                                 public nsIStreamListener,
-                                 public nsIObserver,
-                                 public nsSupportsWeakReference
-{
-private:
-  PRInt32 mBrowserSearchMode;
-  PRBool  mEngineListBuilt;
-
-  // pseudo-constants
-  nsCOMPtr<nsIRDFResource> mNC_SearchResult;
-  nsCOMPtr<nsIRDFResource> mNC_SearchEngineRoot;
-  nsCOMPtr<nsIRDFResource> mNC_LastSearchRoot;
-  nsCOMPtr<nsIRDFResource> mNC_LastSearchMode;
-  nsCOMPtr<nsIRDFResource> mNC_SearchCategoryRoot;
-  nsCOMPtr<nsIRDFResource> mNC_SearchResultsSitesRoot;
-  nsCOMPtr<nsIRDFResource> mNC_FilterSearchURLsRoot;
-  nsCOMPtr<nsIRDFResource> mNC_FilterSearchSitesRoot;
-  nsCOMPtr<nsIRDFResource> mNC_SearchType;
-  nsCOMPtr<nsIRDFResource> mNC_Ref;
-  nsCOMPtr<nsIRDFResource> mNC_Child;
-  nsCOMPtr<nsIRDFResource> mNC_Title;
-  nsCOMPtr<nsIRDFResource> mNC_Data;
-  nsCOMPtr<nsIRDFResource> mNC_Name;
-  nsCOMPtr<nsIRDFResource> mNC_Description;
-  nsCOMPtr<nsIRDFResource> mNC_Version;
-  nsCOMPtr<nsIRDFResource> mNC_actionButton;
-  nsCOMPtr<nsIRDFResource> mNC_actionBar;
-  nsCOMPtr<nsIRDFResource> mNC_searchForm;
-  nsCOMPtr<nsIRDFResource> mNC_LastText;
-  nsCOMPtr<nsIRDFResource> mNC_URL;
-  nsCOMPtr<nsIRDFResource> mRDF_InstanceOf;
-  nsCOMPtr<nsIRDFResource> mRDF_type;
-  nsCOMPtr<nsIRDFResource> mNC_loading;
-  nsCOMPtr<nsIRDFResource> mNC_HTML;
-  nsCOMPtr<nsIRDFResource> mNC_Icon;
-  nsCOMPtr<nsIRDFResource> mNC_StatusIcon;
-  nsCOMPtr<nsIRDFResource> mNC_Banner;
-  nsCOMPtr<nsIRDFResource> mNC_Site;
-  nsCOMPtr<nsIRDFResource> mNC_Relevance;
-  nsCOMPtr<nsIRDFResource> mNC_Date;
-  nsCOMPtr<nsIRDFResource> mNC_RelevanceSort;
-  nsCOMPtr<nsIRDFResource> mNC_PageRank;
-  nsCOMPtr<nsIRDFResource> mNC_Engine;
-  nsCOMPtr<nsIRDFResource> mNC_Price;
-  nsCOMPtr<nsIRDFResource> mNC_PriceSort;
-  nsCOMPtr<nsIRDFResource> mNC_Availability;
-  nsCOMPtr<nsIRDFResource> mNC_BookmarkSeparator;
-  nsCOMPtr<nsIRDFResource> mNC_Update;
-  nsCOMPtr<nsIRDFResource> mNC_UpdateIcon;
-  nsCOMPtr<nsIRDFResource> mNC_UpdateCheckDays;
-  nsCOMPtr<nsIRDFResource> mWEB_LastPingDate;
-  nsCOMPtr<nsIRDFResource> mWEB_LastPingModDate;
-  nsCOMPtr<nsIRDFResource> mWEB_LastPingContentLen;
-
-  nsCOMPtr<nsIRDFResource> mNC_SearchCommand_AddToBookmarks;
-  nsCOMPtr<nsIRDFResource> mNC_SearchCommand_AddQueryToBookmarks;
-  nsCOMPtr<nsIRDFResource> mNC_SearchCommand_FilterResult;
-  nsCOMPtr<nsIRDFResource> mNC_SearchCommand_FilterSite;
-  nsCOMPtr<nsIRDFResource> mNC_SearchCommand_ClearFilters;
-
-  nsCOMPtr<nsIRDFLiteral>  mTrueLiteral;
-
-protected:
-  nsCOMPtr<nsIRDFService>     mRDFService;
-  nsCOMPtr<nsIRDFContainerUtils> mRDFC;
-  nsCOMPtr<nsIRDFDataSource>  mInner;
-  nsCOMPtr<nsIRDFDataSource>  mLocalstore;
-  nsCOMPtr<nsISupportsArray>  mUpdateArray;
-  nsCOMPtr<nsITimer>          mTimer;
-  nsCOMPtr<nsILoadGroup>      mBackgroundLoadGroup;
-  nsCOMPtr<nsILoadGroup>      mLoadGroup;
-  nsCOMPtr<nsIRDFDataSource>  categoryDataSource;
-  PRBool                      busySchedule;
-  nsCOMPtr<nsIRDFResource>    busyResource;
-  nsString                    mQueryEncodingStr;
-
-  // helper methods
-  nsresult  GetSearchEngineToPing(nsIRDFResource **theResource, nsCString &updateURL);
-  PRBool    isEngineURI(nsIRDFResource* aResource);
-  PRBool    isSearchURI(nsIRDFResource* aResource);
-  PRBool    isSearchCategoryURI(nsIRDFResource* aResource);
-  PRBool    isSearchCategoryEngineURI(nsIRDFResource* aResource);
-  PRBool    isSearchCommand(nsIRDFResource* aResource);
-  nsresult  resolveSearchCategoryEngineURI(nsIRDFResource *source, nsIRDFResource **trueEngine);
-  nsresult  BeginSearchRequest(nsIRDFResource *source, PRBool doNetworkRequest);
-  nsresult  FindData(nsIRDFResource *engine, nsIRDFLiteral **data);
-  nsresult  EngineFileFromResource(nsIRDFResource *aEngineResource,
-                                   nsILocalFile **aResult);
-  nsresult  updateDataHintsInGraph(nsIRDFResource *engine, const PRUnichar *data);
-  nsresult  updateAtom(nsIRDFDataSource *db, nsIRDFResource *src, nsIRDFResource *prop, nsIRDFNode *newValue, PRBool *dirtyFlag);
-  nsresult  validateEngine(nsIRDFResource *engine);
-  nsresult  DoSearch(nsIRDFResource *source, nsIRDFResource *engine, const nsString &fullURL, const nsString &text);
-  nsresult  MapEncoding(const nsString &numericEncoding, 
-                        nsString &stringEncoding);
-  const char * const MapScriptCodeToCharsetName(PRUint32 aScriptCode);
-  nsresult  SaveEngineInfoIntoGraph(nsIFile *file, nsIFile *icon, const PRUnichar *hint, const PRUnichar *data, PRBool isSystemSearchFile);
-  nsresult  GetSearchEngineList(nsIFile *spec, PRBool isSystemSearchFile);
-  nsresult  GetCategoryList();
-  nsresult  ReadFileContents(nsILocalFile *baseFilename, nsString & sourceContents);
-  nsresult  DecodeData(const char *aCharset, const PRUnichar *aInString, PRUnichar **aOutString);
-  nsresult  GetData(const PRUnichar *data, const char *sectionToFind, PRUint32 sectionNum, const char *attribToFind, nsString &value);
-  nsresult  GetNumInterpretSections(const PRUnichar *data, PRUint32 &numInterpretSections);
-  nsresult  GetInputs(const PRUnichar *data, nsString &engineName, nsString &userVar, const nsString &text, nsString &input, PRInt16 direction, PRUint16 pageNumber, PRUint16 *whichButtons);
-  PRInt32   computeIndex(nsAutoString &factor, PRUint16 page, PRInt16 direction);
-  nsresult  GetURL(nsIRDFResource *source, nsIRDFLiteral** aResult);
-  nsresult  validateEngineNow(nsIRDFResource *engine);
-  nsresult  webSearchFinalize(nsIChannel *channel, nsIInternetSearchContext *context);
-  nsresult  ParseHTML(nsIURI *aURL, nsIRDFResource *mParent, nsIRDFResource *engine, const PRUnichar *htmlPage, PRInt32 htmlPageSize);
-  nsresult  SetHint(nsIRDFResource *mParent, nsIRDFResource *hintRes);
-  nsresult  ConvertEntities(nsString &str, PRBool removeHTMLFlag = PR_TRUE, PRBool removeCRLFsFlag = PR_TRUE, PRBool trimWhiteSpaceFlag = PR_TRUE);
-  nsresult  saveContents(nsIChannel* channel, nsIInternetSearchContext *context, PRUint32 contextType);
-  PRBool    getSearchURI(nsIRDFResource *src, nsAString &_retval);  // returns true on success
-  nsresult  addToBookmarks(nsIRDFResource *src);
-  nsresult  addQueryToBookmarks(nsIRDFResource *src);
-  nsresult  filterResult(nsIRDFResource *src);
-  nsresult  filterSite(nsIRDFResource *src);
-  nsresult  clearFilters(void);
-  PRBool    isSearchResultFiltered(const nsString &href);
-
-static  void    FireTimer(nsITimer* aTimer, void* aClosure);
-
-  // Just like AddSearchEngine, but with an extra parameter to include the
-  // nsIRDFResource of an existing engines.  If this is a new search engine
-  // aOldEngineResource should be null.
-  nsresult AddSearchEngineInternal(const char *engineURL,
-                                   const char *iconURL,
-                                   const PRUnichar *suggestedTitle,
-                                   const PRUnichar *suggestedCategory,
-                                   nsIRDFResource *aOldEngineResource);
-
-public:
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(InternetSearchDataSource,
-                                           nsIInternetSearchService)
-  NS_DECL_NSIINTERNETSEARCHSERVICE
-  NS_DECL_NSIREQUESTOBSERVER
-  NS_DECL_NSISTREAMLISTENER
-  NS_DECL_NSIRDFDATASOURCE
-  NS_DECL_NSIOBSERVER
-
-  InternetSearchDataSource(void);
-  virtual    ~InternetSearchDataSource(void);
-  NS_METHOD  Init();
-  void DeferredInit();
-};
-
-#endif // nsinternetsearchdatasource__h____
deleted file mode 100755
--- a/suite/browser/src/nsLocalSearchService.cpp
+++ /dev/null
@@ -1,950 +0,0 @@
-/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8; c-file-style: "stroustrup" -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *   Robert John Churchill      <rjc@netscape.com>
- *   Pierre Phaneuf             <pp@ludusdesign.com>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-/*
-  Implementation for a find RDF data store.
- */
-
-#include "nsLocalSearchService.h"
-#include "nscore.h"
-#include "nsIServiceManager.h"
-#include "nsServiceManagerUtils.h"
-#include "nsComponentManagerUtils.h"
-#include "nsEnumeratorUtils.h"
-#include "nsArrayEnumerator.h"
-#include "nsUnicharUtils.h"
-#include "plhash.h"
-#include "plstr.h"
-#include "prmem.h"
-#include "prprf.h"
-#include "prio.h"
-#include "prlog.h"
-#include "nsITextToSubURI.h"
-#include "nsIRDFObserver.h"
-#include "nsRDFCID.h"
-#include "rdf.h"
-#include "nsCRTGlue.h"
-
-static NS_DEFINE_CID(kRDFServiceCID,               NS_RDFSERVICE_CID);
-static NS_DEFINE_CID(kTextToSubURICID,             NS_TEXTTOSUBURI_CID);
-
-static	nsIRDFService		*gRDFService = nsnull;
-static	LocalSearchDataSource		*gLocalSearchDataSource = nsnull;
-static const char	kFindProtocol[] = "find:";
-
-static PRBool
-isFindURI(nsIRDFResource *r)
-{
-	PRBool		isFindURIFlag = PR_FALSE;
-	const char	*uri = nsnull;
-	
-	r->GetValueConst(&uri);
-	if ((uri) && (!strncmp(uri, kFindProtocol, sizeof(kFindProtocol) - 1)))
-	{
-		isFindURIFlag = PR_TRUE;
-	}
-	return(isFindURIFlag);
-}
-
-
-PRInt32              LocalSearchDataSource::gRefCnt;
-nsIRDFResource		*LocalSearchDataSource::kNC_Child;
-nsIRDFResource		*LocalSearchDataSource::kNC_Name;
-nsIRDFResource		*LocalSearchDataSource::kNC_URL;
-nsIRDFResource		*LocalSearchDataSource::kNC_FindObject;
-nsIRDFResource		*LocalSearchDataSource::kNC_pulse;
-nsIRDFResource		*LocalSearchDataSource::kRDF_InstanceOf;
-nsIRDFResource		*LocalSearchDataSource::kRDF_type;
-
-LocalSearchDataSource::LocalSearchDataSource(void)
-{
-	if (gRefCnt++ == 0)
-	{
-		nsresult rv = CallGetService(kRDFServiceCID, &gRDFService);
-
-		PR_ASSERT(NS_SUCCEEDED(rv));
-
-		gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "child"),
-                             &kNC_Child);
-		gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "Name"),
-                             &kNC_Name);
-		gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "URL"),
-                             &kNC_URL);
-		gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "FindObject"),
-                             &kNC_FindObject);
-		gRDFService->GetResource(NS_LITERAL_CSTRING(NC_NAMESPACE_URI "pulse"),
-                             &kNC_pulse);
-
-		gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "instanceOf"),
-                             &kRDF_InstanceOf);
-		gRDFService->GetResource(NS_LITERAL_CSTRING(RDF_NAMESPACE_URI "type"),
-                             &kRDF_type);
-
-		gLocalSearchDataSource = this;
-	}
-}
-
-
-
-LocalSearchDataSource::~LocalSearchDataSource (void)
-{
-	if (--gRefCnt == 0)
-	{
-		NS_RELEASE(kNC_Child);
-		NS_RELEASE(kNC_Name);
-		NS_RELEASE(kNC_URL);
-		NS_RELEASE(kNC_FindObject);
-		NS_RELEASE(kNC_pulse);
-		NS_RELEASE(kRDF_InstanceOf);
-		NS_RELEASE(kRDF_type);
-
-		gLocalSearchDataSource = nsnull;
-		NS_RELEASE(gRDFService);
-	}
-}
-
-
-
-nsresult
-LocalSearchDataSource::Init()
-{
-	nsresult	rv = NS_ERROR_OUT_OF_MEMORY;
-
-	// register this as a named data source with the service manager
-	if (NS_FAILED(rv = gRDFService->RegisterDataSource(this, PR_FALSE)))
-		return(rv);
-
-	return(rv);
-}
-
-
-
-NS_IMPL_ISUPPORTS1(LocalSearchDataSource, nsIRDFDataSource)
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::GetURI(char **uri)
-{
-	NS_PRECONDITION(uri != nsnull, "null ptr");
-	if (! uri)
-		return NS_ERROR_NULL_POINTER;
-
-	*uri = ToNewCString(NS_LITERAL_CSTRING("rdf:localsearch"));
-	if (! *uri)
-		return NS_ERROR_OUT_OF_MEMORY;
-
-	return NS_OK;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::GetSource(nsIRDFResource* property,
-                          nsIRDFNode* target,
-                          PRBool tv,
-                          nsIRDFResource** source /* out */)
-{
-	NS_PRECONDITION(property != nsnull, "null ptr");
-	if (! property)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(target != nsnull, "null ptr");
-	if (! target)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(source != nsnull, "null ptr");
-	if (! source)
-		return NS_ERROR_NULL_POINTER;
-
-	*source = nsnull;
-	return NS_RDF_NO_VALUE;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::GetSources(nsIRDFResource *property,
-                           nsIRDFNode *target,
-			   PRBool tv,
-                           nsISimpleEnumerator **sources /* out */)
-{
-	NS_NOTYETIMPLEMENTED("write me");
-	return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::GetTarget(nsIRDFResource *source,
-                          nsIRDFResource *property,
-                          PRBool tv,
-                          nsIRDFNode **target /* out */)
-{
-	NS_PRECONDITION(source != nsnull, "null ptr");
-	if (! source)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(property != nsnull, "null ptr");
-	if (! property)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(target != nsnull, "null ptr");
-	if (! target)
-		return NS_ERROR_NULL_POINTER;
-
-	nsresult		rv = NS_RDF_NO_VALUE;
-
-	// we only have positive assertions in the find data source.
-	if (! tv)
-		return rv;
-
-	if (isFindURI(source))
-	{
-		if (property == kNC_Name)
-		{
-//			rv = GetName(source, &array);
-		}
-		else if (property == kNC_URL)
-		{
-			// note: lie and say there is no URL
-//			rv = GetURL(source, &array);
-			nsAutoString	url;
-			nsIRDFLiteral	*literal;
-			rv = gRDFService->GetLiteral(url.get(), &literal);
-			*target = literal;
-			return rv;
-		}
-		else if (property == kRDF_type)
-		{
-			const char	*uri = nsnull;
-			rv = kNC_FindObject->GetValueConst(&uri);
-			if (NS_FAILED(rv)) return rv;
-
-			NS_ConvertUTF8toUTF16 url(uri);
-			nsIRDFLiteral	*literal;
-			rv = gRDFService->GetLiteral(url.get(), &literal);
-
-			*target = literal;
-			return rv;
-		}
-		else if (property == kNC_pulse)
-		{
-			nsAutoString	pulse(NS_LITERAL_STRING("15"));
-			nsIRDFLiteral	*pulseLiteral;
-			rv = gRDFService->GetLiteral(pulse.get(), &pulseLiteral);
-			if (NS_FAILED(rv)) return rv;
-
-			*target = pulseLiteral;
-			return NS_OK;
-		}
-		else if (property == kNC_Child)
-		{
-			// fake out the generic builder (i.e. return anything in this case)
-			// so that search containers never appear to be empty
-			*target = source;
-			NS_ADDREF(*target);
-			return(NS_OK);
-		}
-	}
-	return NS_RDF_NO_VALUE;
-}
-
-
-
-NS_METHOD
-LocalSearchDataSource::parseResourceIntoFindTokens(nsIRDFResource *u, findTokenPtr tokens)
-{
-	const char		*uri = nsnull;
-	char			*id, *token, *value, *newstr;
-	int			loop;
-	nsresult		rv;
-
-	if (NS_FAILED(rv = u->GetValueConst(&uri)))	return(rv);
-
-#ifdef	DEBUG
-	printf("Find: %s\n", (const char*) uri);
-#endif
-
-	if (!(id = PL_strdup(uri + sizeof(kFindProtocol) - 1)))
-		return(NS_ERROR_OUT_OF_MEMORY);
-
-	/* parse ID, build up token list */
-	newstr = id;
-	if ((token = NS_strtok("&", &newstr)) != NULL)
-	{
-		while (token != NULL)
-		{
-			if ((value = strstr(token, "=")) != NULL)
-			{
-				*value++ = '\0';
-			}
-			for (loop=0; tokens[loop].token != NULL; loop++)
-			{
-				if (!strcmp(token, tokens[loop].token))
-				{
-				    if (!strcmp(token, "text"))
-				    {
-            			nsCOMPtr<nsITextToSubURI> textToSubURI = 
-            			         do_GetService(kTextToSubURICID, &rv);
-            			if (NS_SUCCEEDED(rv) && (textToSubURI))
-            			{
-            				PRUnichar	*uni = nsnull;
-            				if (NS_SUCCEEDED(rv = textToSubURI->UnEscapeAndConvert("UTF-8", value, &uni)) && (uni))
-            				{
-    					        tokens[loop].value.Adopt(uni);
-    					    }
-    					}
-				    }
-				    else
-				    {
-				        CopyASCIItoUTF16(nsDependentCString(value), tokens[loop].value);
-    			    }
-					break;
-				}
-			}
-			token = NS_strtok("&", &newstr);
-		}
-	}
-	PL_strfree(id);
-	return(NS_OK);
-}
-
-
-
-PRBool
-LocalSearchDataSource::doMatch(nsIRDFLiteral *literal,
-                               const nsAString &matchMethod,
-                               const nsString &matchText)
-{
-	PRBool		found = PR_FALSE;
-
-	if ((nsnull == literal) ||
-            matchMethod.IsEmpty() ||
-            matchText.IsEmpty())
-		return(found);
-
-	const	PRUnichar	*str = nsnull;
-	literal->GetValueConst( &str );
-	if (! str)	return(found);
-	nsAutoString	value(str);
-
-        if (matchMethod.EqualsLiteral("contains"))
-	{
-            if (-1 != value.Find(matchText, CaseInsensitiveCompare))
-                found = PR_TRUE;
-	}
-        else if (matchMethod.EqualsLiteral("startswith"))
-	{
-            if (StringBeginsWith(value, matchText, CaseInsensitiveCompare))
-                found = PR_TRUE;
-	}
-        else if (matchMethod.EqualsLiteral("endswith"))
-	{
-            if (StringEndsWith(value, matchText, CaseInsensitiveCompare))
-                found = PR_TRUE;
-	}
-        else if (matchMethod.EqualsLiteral("is"))
-	{
-            if (value.Equals(matchText, CaseInsensitiveCompare))
-                found = PR_TRUE;
-	}
-        else if (matchMethod.EqualsLiteral("isnot"))
-	{
-            if (!value.Equals(matchText, CaseInsensitiveCompare))
-                found = PR_TRUE;
-	}
-        else if (matchMethod.EqualsLiteral("doesntcontain"))
-	{
-            if (-1 == value.Find(matchText, CaseInsensitiveCompare))
-                found = PR_TRUE;
-	}
-        return(found);
-}
-
-PRBool
-LocalSearchDataSource::doDateMatch(nsIRDFDate *aDate,
-                                   const nsAString& matchMethod,
-                                   const nsAString& matchText)
-{
-    PRBool found = PR_FALSE;
-    
-    if (matchMethod.EqualsLiteral("isbefore") ||
-        matchMethod.EqualsLiteral("isafter"))
-    {
-        PRInt64 matchDate;
-        nsresult rv = parseDate(matchText, &matchDate);
-        if (NS_SUCCEEDED(rv))
-            found = dateMatches(aDate, matchMethod, matchDate);
-    }
-
-    return found;
-}
-
-PRBool
-LocalSearchDataSource::doIntMatch(nsIRDFInt *aInt,
-                                  const nsAString& matchMethod,
-                                  const nsString& matchText)
-{
-    nsresult rv;
-    PRBool found = PR_FALSE;
-    
-    PRInt32 val;
-    rv = aInt->GetValue(&val);
-    if (NS_FAILED(rv)) return PR_FALSE;
-    
-    PRInt32 matchVal = matchText.ToInteger(&rv);
-    if (NS_FAILED(rv)) return PR_FALSE;
-    
-    if (matchMethod.EqualsLiteral("is"))
-        found = (val == matchVal);
-    else if (matchMethod.EqualsLiteral("isgreater"))
-        found = (val > matchVal);
-    else if (matchMethod.EqualsLiteral("isless"))
-        found = (val < matchVal);
-
-    return found;
-}
-
-NS_METHOD
-LocalSearchDataSource::parseDate(const nsAString& aDate,
-                                 PRInt64 *aResult)
-{
-    // date is in the form of msec since epoch, but use NSPR to
-    // parse the time
-    PRTime *outTime = static_cast<PRTime*>(aResult);
-    PRStatus err;
-    err = PR_ParseTimeString(NS_ConvertUTF16toUTF8(aDate).get(),
-                             PR_FALSE, // PR_FALSE == use current timezone
-                             outTime);
-    NS_ENSURE_TRUE(err == 0, NS_ERROR_FAILURE);
-    
-    return NS_OK;
-}
-
-
-PRBool
-LocalSearchDataSource::dateMatches(nsIRDFDate *aDate,
-                                   const nsAString& method,
-                                   const PRInt64& matchDate)
-{
-    PRInt64 date;
-    aDate->GetValue(&date);
-    PRBool matches = PR_FALSE;
-    
-    if (method.EqualsLiteral("isbefore"))
-        matches = LL_CMP(date, <, matchDate);
-    
-    else if (method.EqualsLiteral("isafter"))
-        matches = LL_CMP(date, >, matchDate);
-
-    else if (method.EqualsLiteral("is"))
-        matches = LL_EQ(date, matchDate);
-
-    return matches;
-}
-
-
-NS_METHOD
-LocalSearchDataSource::parseFindURL(nsIRDFResource *u, nsIMutableArray *array)
-{
-  findTokenStruct		tokens[5];
-  nsresult rv;
-
-  // build up a token list
-  tokens[0].token = "datasource";
-  tokens[1].token = "match";
-  tokens[2].token = "method";
-  tokens[3].token = "text";
-  tokens[4].token = NULL;
-
-  // parse find URI, get parameters, search in appropriate
-  // datasource(s), return results
-  rv = parseResourceIntoFindTokens(u, tokens);
-  if (NS_FAILED(rv)) 
-    return rv;
-
-  nsCAutoString dsName;
-  dsName.Assign(NS_LossyConvertUTF16toASCII(tokens[0].value));
-
-  nsCOMPtr<nsIRDFDataSource> datasource;
-  rv = gRDFService->GetDataSource(dsName.get(), getter_AddRefs(datasource));
-  if (NS_FAILED(rv)) 
-    return rv;
-
-  nsCOMPtr<nsISimpleEnumerator> cursor;
-  rv = datasource->GetAllResources(getter_AddRefs(cursor));
-  if (NS_FAILED(rv)) 
-    return rv;
-        
-  while (PR_TRUE) {
-    PRBool hasMore;
-    rv = cursor->HasMoreElements(&hasMore);
-    if (NS_FAILED(rv)) 
-      break;
-
-    if (!hasMore) 
-      break;
-
-    nsCOMPtr<nsISupports> isupports;
-    rv = cursor->GetNext(getter_AddRefs(isupports));
-    if (NS_FAILED(rv)) 
-      continue;
-
-    nsCOMPtr<nsIRDFResource> source(do_QueryInterface(isupports));
-    if (!source) 
-      continue;
-
-    const char	*uri = nsnull;
-    source->GetValueConst(&uri);
-
-    if (!uri) 
-      continue;
-            
-    // never match against a "find:" URI
-    if (PL_strncmp(uri, kFindProtocol, sizeof(kFindProtocol)-1) == 0)
-      continue;
-
-    // never match against a container. Searching for folders just isn't
-    // much of a utility, and this fixes an infinite recursion crash. (65063)
-    PRBool isContainer = PR_FALSE;
-
-    // Check to see if this source is an RDF container
-    nsCOMPtr<nsIRDFContainerUtils> cUtils(do_GetService("@mozilla.org/rdf/container-utils;1"));
-    if (cUtils)
-      cUtils->IsContainer(datasource, source, &isContainer);
-    // Check to see if this source is a pseudo-container
-    if (!isContainer)
-      datasource->HasArcOut(source, kNC_Child, &isContainer);
-
-    if (isContainer) 
-      continue;
-
-    // Check to see if this source has a parent
-    if (!nodeHasParent(datasource, source, cUtils))
-      continue;
-
-    nsCOMPtr<nsIRDFResource> property;
-    rv = gRDFService->GetUnicodeResource(tokens[1].value,
-    getter_AddRefs(property));
-
-    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE) || !property)
-      continue;
-
-    nsCOMPtr<nsIRDFNode>    value;
-    rv = datasource->GetTarget(source, property,
-    PR_TRUE, getter_AddRefs(value));
-    if (NS_FAILED(rv) || (rv == NS_RDF_NO_VALUE) || !value)
-      continue;
-
-    PRBool found = PR_FALSE;
-    found = matchNode(value, tokens[2].value, tokens[3].value);
-
-    if (found)
-      array->AppendElement(source, PR_FALSE);
-   }
-
-  if (rv == NS_RDF_CURSOR_EMPTY)
-    rv = NS_OK;
-
-  return rv;
-}
-
-PRBool
-LocalSearchDataSource::nodeHasParent(nsIRDFDataSource *aDataSource,
-                                     nsIRDFNode *aNode,
-                                     nsIRDFContainerUtils *aUtils)
-{
-  nsCOMPtr<nsISimpleEnumerator> cursor;
-  if (NS_FAILED(aDataSource->ArcLabelsIn(aNode, getter_AddRefs(cursor))))
-    return PR_FALSE;
-
-  PRBool hasMore;
-  while (NS_SUCCEEDED(cursor->HasMoreElements(&hasMore)) && hasMore) {
-    nsCOMPtr<nsISupports> isupports;
-    if (NS_FAILED(cursor->GetNext(getter_AddRefs(isupports))))
-      break;
-
-    nsCOMPtr<nsIRDFResource> arc(do_QueryInterface(isupports));
-    if (!arc)
-      continue;
-
-    PRBool result;
-    if (NS_SUCCEEDED(aUtils->IsOrdinalProperty(arc, &result)) && result)
-      return PR_TRUE;
-  }
-  return PR_FALSE;
-}
-
-// could speed up date/integer matching signifigantly by caching the
-// last successful match data type (i.e. string, date, int) and trying
-// to QI against that first
-PRBool
-LocalSearchDataSource::matchNode(nsIRDFNode *aValue,
-                                 const nsAString& matchMethod,
-                                 const nsString& matchText)
-{
-    nsCOMPtr<nsIRDFLiteral> literal(do_QueryInterface(aValue));
-    if (literal)
-        return doMatch(literal, matchMethod, matchText);
-
-    nsCOMPtr<nsIRDFDate> dateLiteral(do_QueryInterface(aValue));
-    if (dateLiteral)
-        return doDateMatch(dateLiteral, matchMethod, matchText);
-    
-    nsCOMPtr<nsIRDFInt> intLiteral(do_QueryInterface(aValue));
-    if (intLiteral)
-        return doIntMatch(intLiteral, matchMethod, matchText);
-
-    return PR_FALSE;
-}
-
-NS_METHOD
-LocalSearchDataSource::getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult)
-{
-	nsresult			rv;
-	nsCOMPtr<nsIMutableArray>	nameArray;
-	nameArray = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
-	if (NS_FAILED(rv)) return rv;
-
-	rv = parseFindURL(source, nameArray);
-	if (NS_FAILED(rv)) return rv;
-
-        return NS_NewArrayEnumerator(aResult, nameArray);
-}
-
-
-
-NS_METHOD
-LocalSearchDataSource::getFindName(nsIRDFResource *source, nsIRDFLiteral** aResult)
-{
-	// XXX construct find URI human-readable name
-	*aResult = nsnull;
-	return(NS_OK);
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::GetTargets(nsIRDFResource *source,
-                           nsIRDFResource *property,
-                           PRBool tv,
-                           nsISimpleEnumerator **targets /* out */)
-{
-	NS_PRECONDITION(source != nsnull, "null ptr");
-	if (! source)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(property != nsnull, "null ptr");
-	if (! property)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(targets != nsnull, "null ptr");
-	if (! targets)
-		return NS_ERROR_NULL_POINTER;
-
-	nsresult		rv = NS_ERROR_FAILURE;
-
-	// we only have positive assertions in the find data source.
-	if (! tv)
-		return rv;
-
-	if (isFindURI(source))
-	{
-		if (property == kNC_Child)
-		{
-			return getFindResults(source, targets);
-		}
-		else if (property == kNC_Name)
-		{
-			nsCOMPtr<nsIRDFLiteral>	name;
-			rv = getFindName(source, getter_AddRefs(name));
-			if (NS_FAILED(rv)) return rv;
-
-                        return NS_NewSingletonEnumerator(targets, name);
-		}
-		else if (property == kRDF_type)
-		{
-			const	char	*uri = nsnull;
-			rv = kNC_FindObject->GetValueConst( &uri );
-			if (NS_FAILED(rv)) return rv;
-
-			nsCOMPtr<nsIRDFLiteral> literal;
-			rv = gRDFService->GetLiteral(NS_ConvertUTF8toUTF16(uri).get(),
-                                                     getter_AddRefs(literal));
-			if (NS_FAILED(rv)) return rv;
-
-                        return NS_NewSingletonEnumerator(targets, literal);
-		}
-		else if (property == kNC_pulse)
-		{
-			nsAutoString	pulse(NS_LITERAL_STRING("15"));
-
-			nsCOMPtr<nsIRDFLiteral> pulseLiteral;
-			rv = gRDFService->GetLiteral(pulse.get(),
-                                                     getter_AddRefs(pulseLiteral));
-			if (NS_FAILED(rv)) return rv;
-
-                        return NS_NewSingletonEnumerator(targets, pulseLiteral);
-		}
-	}
-
-	return NS_NewEmptyEnumerator(targets);
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::Assert(nsIRDFResource *source,
-                       nsIRDFResource *property,
-                       nsIRDFNode *target,
-                       PRBool tv)
-{
-	return NS_RDF_ASSERTION_REJECTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::Unassert(nsIRDFResource *source,
-                         nsIRDFResource *property,
-                         nsIRDFNode *target)
-{
-	return NS_RDF_ASSERTION_REJECTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::Change(nsIRDFResource* aSource,
-                       nsIRDFResource* aProperty,
-                       nsIRDFNode* aOldTarget,
-                       nsIRDFNode* aNewTarget)
-{
-	return NS_RDF_ASSERTION_REJECTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::Move(nsIRDFResource* aOldSource,
-                     nsIRDFResource* aNewSource,
-                     nsIRDFResource* aProperty,
-                     nsIRDFNode* aTarget)
-{
-	return NS_RDF_ASSERTION_REJECTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::HasAssertion(nsIRDFResource *source,
-                             nsIRDFResource *property,
-                             nsIRDFNode *target,
-                             PRBool tv,
-                             PRBool *hasAssertion /* out */)
-{
-	NS_PRECONDITION(source != nsnull, "null ptr");
-	if (! source)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(property != nsnull, "null ptr");
-	if (! property)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(target != nsnull, "null ptr");
-	if (! target)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(hasAssertion != nsnull, "null ptr");
-	if (! hasAssertion)
-		return NS_ERROR_NULL_POINTER;
-
-	nsresult		rv = NS_OK;
-
-	*hasAssertion = PR_FALSE;
-
-	// we only have positive assertions in the find data source.
-	if (! tv)
-		return rv;
-
-	if (isFindURI(source))
-	{
-		if (property == kRDF_type)
-		{
-			if ((nsIRDFResource *)target == kRDF_type)
-			{
-				*hasAssertion = PR_TRUE;
-			}
-		}
-	}
-	return (rv);
-}
-
-NS_IMETHODIMP 
-LocalSearchDataSource::HasArcIn(nsIRDFNode *aNode, nsIRDFResource *aArc, PRBool *result)
-{
-    *result = PR_FALSE;
-    return NS_OK;
-}
-
-NS_IMETHODIMP 
-LocalSearchDataSource::HasArcOut(nsIRDFResource *source, nsIRDFResource *aArc, PRBool *result)
-{
-    NS_PRECONDITION(source != nsnull, "null ptr");
-    if (! source)
-        return NS_ERROR_NULL_POINTER;
-
-    if ((aArc == kNC_Child ||
-         aArc == kNC_pulse)) {
-        *result = isFindURI(source);
-    }
-    else {
-        *result = PR_FALSE;
-    }
-    return NS_OK;
-}
-
-NS_IMETHODIMP
-LocalSearchDataSource::ArcLabelsIn(nsIRDFNode *node,
-                            nsISimpleEnumerator ** labels /* out */)
-{
-	NS_NOTYETIMPLEMENTED("write me");
-	return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::ArcLabelsOut(nsIRDFResource *source,
-                             nsISimpleEnumerator **labels /* out */)
-{
-	NS_PRECONDITION(source != nsnull, "null ptr");
-	if (! source)
-		return NS_ERROR_NULL_POINTER;
-
-	NS_PRECONDITION(labels != nsnull, "null ptr");
-	if (! labels)
-		return NS_ERROR_NULL_POINTER;
-
-	nsresult		rv;
-
-	if (isFindURI(source))
-	{
-		nsCOMPtr<nsIMutableArray> array;
-		array = do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
-		if (NS_FAILED(rv)) return rv;
-
-		array->AppendElement(kNC_Child, PR_FALSE);
-		array->AppendElement(kNC_pulse, PR_FALSE);
-
-                return NS_NewArrayEnumerator(labels, array);
-	}
-	return(NS_NewEmptyEnumerator(labels));
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::GetAllResources(nsISimpleEnumerator** aCursor)
-{
-	NS_NOTYETIMPLEMENTED("sorry!");
-	return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::AddObserver(nsIRDFObserver *n)
-{
-	return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::RemoveObserver(nsIRDFObserver *n)
-{
-	return NS_ERROR_NOT_IMPLEMENTED;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::GetAllCmds(nsIRDFResource* source, nsISimpleEnumerator/*<nsIRDFResource>*/** commands)
-{
-	return(NS_NewEmptyEnumerator(commands));
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::IsCommandEnabled(nsISupportsArray/*<nsIRDFResource>*/* aSources,
-				nsIRDFResource*   aCommand,
-				nsISupportsArray/*<nsIRDFResource>*/* aArguments,
-                                PRBool* aResult)
-{
-	return(NS_ERROR_NOT_IMPLEMENTED);
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::DoCommand(nsISupportsArray/*<nsIRDFResource>*/* aSources,
-				nsIRDFResource*   aCommand,
-				nsISupportsArray/*<nsIRDFResource>*/* aArguments)
-{
-	return(NS_ERROR_NOT_IMPLEMENTED);
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::BeginUpdateBatch()
-{
-	return NS_OK;
-}
-
-
-
-NS_IMETHODIMP
-LocalSearchDataSource::EndUpdateBatch()
-{
-	return NS_OK;
-}
deleted file mode 100644
--- a/suite/browser/src/nsLocalSearchService.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is
- * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s):
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either of the GNU General Public License Version 2 or later (the "GPL"),
- * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-#ifndef localsearchdb___h_____
-#define localsearchdb___h_____
-
-#include "nsIMutableArray.h"
-#include "nsCOMPtr.h"
-#include "nsIRDFDataSource.h"
-#include "nsStringAPI.h"
-#include "nsIRDFNode.h"
-#include "nsIRDFService.h"
-#include "nsIRDFContainerUtils.h"
-#include "nsISearchService.h"
-
-typedef	struct	_findTokenStruct
-{
-	const char		*token;
-	nsString	    value;
-} findTokenStruct, *findTokenPtr;
-
-
-class LocalSearchDataSource : public nsIRDFDataSource
-{
-private:
-	static PRInt32		gRefCnt;
-
-    // pseudo-constants
-	static nsIRDFResource	*kNC_Child;
-	static nsIRDFResource	*kNC_Name;
-	static nsIRDFResource	*kNC_URL;
-	static nsIRDFResource	*kNC_FindObject;
-	static nsIRDFResource	*kNC_pulse;
-	static nsIRDFResource	*kRDF_InstanceOf;
-	static nsIRDFResource	*kRDF_type;
-
-protected:
-
-	NS_METHOD	getFindResults(nsIRDFResource *source, nsISimpleEnumerator** aResult);
-	NS_METHOD	getFindName(nsIRDFResource *source, nsIRDFLiteral** aResult);
-	NS_METHOD	parseResourceIntoFindTokens(nsIRDFResource *u, findTokenPtr tokens);
-
-    PRBool nodeHasParent(nsIRDFDataSource *aDataSource,
-                         nsIRDFNode *aNode,
-                         nsIRDFContainerUtils *aUtils);
-    // matching functions, based on type
-	PRBool doMatch(nsIRDFLiteral  *literal,
-                   const nsAString& matchMethod,
-                   const nsString& matchText);
-    PRBool matchNode(nsIRDFNode *aNode,
-                     const nsAString& matchMethod,
-                     const nsString& matchText);
-    
-	PRBool doDateMatch(nsIRDFDate *literal,
-                       const nsAString& matchMethod,
-                       const nsAString& matchText);
-	PRBool doIntMatch (nsIRDFInt  *literal,
-                       const nsAString& matchMethod,
-                       const nsString& matchText);
-
-    PRBool dateMatches(nsIRDFDate *literal,
-                       const nsAString& method,
-                       const PRInt64& matchDate);
-    
-    NS_METHOD   parseDate(const nsAString& aDate, PRInt64* aResult);
-    
-	NS_METHOD	parseFindURL(nsIRDFResource *u, nsIMutableArray *array);
-
-public:
-	LocalSearchDataSource(void);
-	virtual		~LocalSearchDataSource(void);
-	nsresult	Init();
-
-	NS_DECL_ISUPPORTS
-	NS_DECL_NSILOCALSEARCHSERVICE
-    NS_DECL_NSIRDFDATASOURCE
-};
-
-#endif // localsearchdb___h_____
--- a/suite/browser/urlbarBindings.xml
+++ b/suite/browser/urlbarBindings.xml
@@ -178,139 +178,66 @@
       <field name="mInputTimeout"><![CDATA[
         (function(me) {
           me.resultsPopup.mSearchBox.searchValue = me.value;
           me.mSearchInputTO = 0;
         });
       ]]></field>
 
       <field name="mEnginesReady">false</field>
-      
+
       <property name="overrideValue" readonly="true">
         <getter><![CDATA[
           if (this.mSearchBox.selectedIndex != -1) {
-            // save the value.  RevealSearchPanel can close the popup
-            var returnValue = this.mSearchBox.overrideValue;
-            try {
-              if (pref.getBoolPref("browser.search.opensidebarsearchpanel"))
-                RevealSearchPanel();
-            } catch (ex) {
-            }
-            return returnValue;
+            return this.mSearchBox.overrideValue;
           }
           return null;
         ]]></getter>
       </property>
 
       <method name="updatePref">
         <parameter name="aPref"/>
         <body><![CDATA[
           if (aPref == "browser.urlbar.showSearch")
             this.showSearch = this.mPrefs.getBoolPref("browser.urlbar.showSearch");
         ]]></body>
       </method>
-      
+
       <method name="addEngine">
-        <parameter name="aEngineId"/>
         <parameter name="aName"/>
         <parameter name="aIcon"/>
         <parameter name="aSearchBarUrl"/>
         <body><![CDATA[
           var box = document.createElement("box");
           box.setAttribute("class", "autocomplete-search-engine");
-          box.setAttribute("searchEngine", aEngineId);
           box.setAttribute("name", aName);
           box.setAttribute("icon", aIcon);
           box.setAttribute("searchBarUrl", aSearchBarUrl);
           box.setAttribute("engineIndex", this.childNodes.length);
           this.mSearchBox.appendChild(box);
         ]]></body>
       </method>
 
       <method name="clearEngines">
         <body><![CDATA[
           while (this.mSearchBox.hasChildNodes())
             this.mSearchBox.removeChild(this.mSearchBox.lastChild);
         ]]></body>
       </method>
-   
+
       <method name="updateEngines">
         <body><![CDATA[
-          var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"]
-                      .getService(Components.interfaces.nsIRDFService);
-          try {
-            var ds = rdf.GetDataSource("rdf:internetsearch");
-          } catch (ex) {
-            // sometimes bad profiles cause this error, which horks the hold urlbar
-            return;
-          }
-                              
-          const kNC_Name = rdf.GetResource("http://home.netscape.com/NC-rdf#Name");
-          const kNC_Icon = rdf.GetResource("http://home.netscape.com/NC-rdf#Icon");
-          const kNC_searchBarUrl = rdf.GetResource("http://home.netscape.com/NC-rdf#actionBar");
-        
-          var defaultEngine = null;
-          try {
-            defaultEngine = this.mPrefs.getComplexValue("browser.search.defaultengine",
-                                                        Components.interfaces.nsISupportsString).data;
-          } catch(ex) {
-            // this will re-invoke updateEngines via the pref observer if the pref changes
-            this.ensureDefaultEnginePrefs(rdf, ds);
-            return;
-          }
-          
+          var defaultEngine = Services.search.defaultEngine;
           if (defaultEngine) {
             this.clearEngines();
-            
-            if (ds) {
-              var res = rdf.GetResource(defaultEngine);
-              try {
-                var searchBarUrl = this.readRDFString(ds, res, kNC_searchBarUrl);
-              } catch(ex) {
-                searchBarUrl = null;
-              }
-              if (searchBarUrl == null) {
-                // this will re-invoke updateEngines via the pref observer if the pref changes
-                this.ensureDefaultEnginePrefs(rdf, ds);
-                return;
-              }
-              this.addEngine(res.Value, 
-                            this.readRDFString(ds, res, kNC_Name),
-                            this.readRDFString(ds, res, kNC_Icon),
-                            searchBarUrl);
-            }
+            this.addEngine(defaultEngine.name, defaultEngine.iconURI,
+                           defaultEngine.searchForm);
           }
-          
-          this.mEnginesReady = true;
-        ]]></body>
-      </method>
 
-      <method name="ensureDefaultEnginePrefs">
-        <parameter name="aRDF"/>
-        <parameter name="aDS"/>
-        <body><![CDATA[
-          var defaultName = this.mPrefs.getComplexValue("browser.search.defaultenginename",
-                                                        Components.interfaces.nsIPrefLocalizedString).data;
-          const kNC_Root = aRDF.GetResource("NC:SearchEngineRoot");
-          const kNC_child = aRDF.GetResource("http://home.netscape.com/NC-rdf#child");
-          const kNC_Name = aRDF.GetResource("http://home.netscape.com/NC-rdf#Name");
-          
-          var arcs = aDS.GetTargets(kNC_Root, kNC_child, true);
-          while (arcs.hasMoreElements()) {
-            var engineRes = arcs.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
-            var name = this.readRDFString(aDS, engineRes, kNC_Name);
-            if (name == defaultName) {
-              var str = Components.classes["@mozilla.org/supports-string;1"]
-                                  .createInstance(Components.interfaces.nsISupportsString);
-              str.data = engineRes.Value;
-              this.mPrefs.setComplexValue("browser.search.defaultengine",
-                                          Components.interfaces.nsISupportsString,
-                                          str);
-            }
-          }
+          this.mEnginesReady = true;
         ]]></body>
       </method>
 
       <method name="readRDFString">
         <parameter name="aDS"/>
         <parameter name="aRes"/>
         <parameter name="aProp"/>
         <body><![CDATA[
@@ -440,28 +367,34 @@
           return this.selectedIndex = this.parentNode.getNextIndex(aReverse, aPage, this.selectedIndex, this.childNodes.length - 1);
         ]]></body>
       </method>
 
       <property name="overrideValue" readonly="true">
         <getter><![CDATA[
           var item = this.activeChild;
           if (item) {
-            const ISEARCH_CONTRACTID = "@mozilla.org/rdf/datasource;1?name=internetsearch";
-            const nsIInternetSearchService = Components.interfaces.nsIInternetSearchService;           
-            var searchService = Components.classes[ISEARCH_CONTRACTID].getService(nsIInternetSearchService);
-            var searchEng = item.getAttribute("searchEngine");
-            var searchEngUrl = item.getAttribute("searchBarUrl");
-            var escapedSearch = encodeURIComponent(this.mSearchValue)
-            if (searchEngUrl) {
-                searchEngUrl += escapedSearch;
-                return searchEngUrl;
-            } else {
-              return searchService.GetInternetSearchURL(item.getAttribute("searchEngine"),escapedSearch, 0, 0, {value:0});
-            }
+            // XXXsearch: using default engine for now, this ignores the following values:
+            //            item.getAttribute("searchEngine") and item.getAttribute("searchBarUrl")
+            var engine = Services.search.defaultEngine;
+
+            var submission = engine.getSubmission(this.mSearchValue); // HTML response
+
+            // getSubmission can return null if the engine doesn't have a URL
+            // with a text/html response type.  This is unlikely (since
+            // SearchService._addEngineToStore() should fail for such an engine),
+            // but let's be on the safe side.
+            if (!submission)
+              return null;
+
+            // XXXsearch: the submission object may have postData but .overrideValue can't deal with that
+            //            see http://mxr.mozilla.org/comm-central/source/mozilla/netwerk/base/public/nsIBrowserSearchService.idl#47
+            //            we need to figure out what to do with that case here
+
+            return submission.uri.spec;
           }
           return null;
         ]]></getter>
       </property>
 
     </implementation>
 
     <handlers>
--- a/suite/build/nsSuiteModule.cpp
+++ b/suite/build/nsSuiteModule.cpp
@@ -36,18 +36,16 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "mozilla/ModuleUtils.h"
 #include "nsSuiteDirectoryProvider.h"
 #include "nsProfileMigrator.h"
 #include "nsSeamonkeyProfileMigrator.h"
 #include "nsThunderbirdProfileMigrator.h"
-#include "nsInternetSearchService.h"
-#include "nsLocalSearchService.h"
 #include "nsNetCID.h"
 #include "nsRDFCID.h"
 #include "nsFeedSniffer.h"
 
 #if defined(XP_WIN)
 #include "nsUrlWidget.h"
 #if !defined(BUILD_STATIC_SHELL)
 #include "nsWindowsShellService.h"
@@ -69,36 +67,32 @@ NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsWi
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsMacShellService)
 #elif defined(MOZ_WIDGET_GTK2) && !defined(BUILD_STATIC_SHELL)
 NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsGNOMEShellService, Init)
 #endif
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSuiteDirectoryProvider)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsProfileMigrator)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsSeamonkeyProfileMigrator)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsThunderbirdProfileMigrator)
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(LocalSearchDataSource, Init)
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(InternetSearchDataSource, Init)
 NS_GENERIC_FACTORY_CONSTRUCTOR(nsFeedSniffer)
 
 #if defined(XP_WIN)
 NS_DEFINE_NAMED_CID(NS_IURLWIDGET_CID);
 #endif
 #if defined(NS_SUITEWININTEGRATION_CID)
 NS_DEFINE_NAMED_CID(NS_SUITEWININTEGRATION_CID);
 #elif defined(NS_SUITEMACINTEGRATION_CID)
 NS_DEFINE_NAMED_CID(NS_SUITEMACINTEGRATION_CID);
 #elif defined(NS_SUITEGNOMEINTEGRATION_CID)
 NS_DEFINE_NAMED_CID(NS_SUITEGNOMEINTEGRATION_CID);
 #endif
 NS_DEFINE_NAMED_CID(NS_SUITEDIRECTORYPROVIDER_CID);
 NS_DEFINE_NAMED_CID(NS_SUITEPROFILEMIGRATOR_CID);
 NS_DEFINE_NAMED_CID(NS_SEAMONKEYPROFILEMIGRATOR_CID);
 NS_DEFINE_NAMED_CID(NS_THUNDERBIRDPROFILEMIGRATOR_CID);
-NS_DEFINE_NAMED_CID(NS_RDFFINDDATASOURCE_CID);
-NS_DEFINE_NAMED_CID(NS_RDFSEARCHDATASOURCE_CID);
 NS_DEFINE_NAMED_CID(NS_FEEDSNIFFER_CID);
 
 /////////////////////////////////////////////////////////////////////////////
 
 static const mozilla::Module::CIDEntry kSuiteCIDs[] = {
 #if defined(XP_WIN)
   { &kNS_IURLWIDGET_CID, false, NULL, nsUrlWidgetConstructor },
 #endif
@@ -108,18 +102,16 @@ static const mozilla::Module::CIDEntry k
   { &kNS_SUITEMACINTEGRATION_CID, false, NULL, nsMacShellServiceConstructor },
 #elif defined(NS_SUITEGNOMEINTEGRATION_CID)
   { &kNS_SUITEGNOMEINTEGRATION_CID, false, NULL, nsGNOMEShellServiceConstructor },
 #endif
   { &kNS_SUITEDIRECTORYPROVIDER_CID, false, NULL, nsSuiteDirectoryProviderConstructor },
   { &kNS_SUITEPROFILEMIGRATOR_CID, false, NULL, nsProfileMigratorConstructor },
   { &kNS_SEAMONKEYPROFILEMIGRATOR_CID, false, NULL, nsSeamonkeyProfileMigratorConstructor },
   { &kNS_THUNDERBIRDPROFILEMIGRATOR_CID, false, NULL, nsThunderbirdProfileMigratorConstructor },
-  { &kNS_RDFFINDDATASOURCE_CID, false, NULL, LocalSearchDataSourceConstructor },
-  { &kNS_RDFSEARCHDATASOURCE_CID, false, NULL, InternetSearchDataSourceConstructor },
   { &kNS_FEEDSNIFFER_CID, false, NULL, nsFeedSnifferConstructor },
   { NULL }
 };
 
 static const mozilla::Module::ContractIDEntry kSuiteContracts[] = {
 #if defined(XP_WIN)
   { NS_IURLWIDGET_CONTRACTID, &kNS_IURLWIDGET_CID },
 #endif
@@ -130,20 +122,16 @@ static const mozilla::Module::ContractID
   { NS_SUITEFEEDSERVICE_CONTRACTID, &kNS_SUITEMACINTEGRATION_CID },
 #elif defined(NS_SUITEGNOMEINTEGRATION_CID)
   { NS_SUITEFEEDSERVICE_CONTRACTID, &kNS_SUITEGNOMEINTEGRATION_CID },
 #endif
   { NS_SUITEDIRECTORYPROVIDER_CONTRACTID, &kNS_SUITEDIRECTORYPROVIDER_CID },
   { NS_PROFILEMIGRATOR_CONTRACTID, &kNS_SUITEPROFILEMIGRATOR_CID },
   { NS_SUITEPROFILEMIGRATOR_CONTRACTID_PREFIX "seamonkey", &kNS_SEAMONKEYPROFILEMIGRATOR_CID },
   { NS_SUITEPROFILEMIGRATOR_CONTRACTID_PREFIX "thunderbird", &kNS_THUNDERBIRDPROFILEMIGRATOR_CID },
-  { NS_LOCALSEARCH_SERVICE_CONTRACTID, &kNS_RDFFINDDATASOURCE_CID },
-  { NS_LOCALSEARCH_DATASOURCE_CONTRACTID, &kNS_RDFFINDDATASOURCE_CID },
-  { NS_INTERNETSEARCH_SERVICE_CONTRACTID, &kNS_RDFSEARCHDATASOURCE_CID },
-  { NS_INTERNETSEARCH_DATASOURCE_CONTRACTID, &kNS_RDFSEARCHDATASOURCE_CID },
   { NS_FEEDSNIFFER_CONTRACTID, &kNS_FEEDSNIFFER_CID },
   { NULL }
 };
 
 static const mozilla::Module::CategoryEntry kSuiteCategories[] = {
   { XPCOM_DIRECTORY_PROVIDER_CATEGORY, "suite-directory-provider", NS_SUITEDIRECTORYPROVIDER_CONTRACTID },
   { NS_CONTENT_SNIFFER_CATEGORY, "Feed Sniffer", NS_FEEDSNIFFER_CONTRACTID },
   { NULL }
--- a/suite/common/contentAreaContextOverlay.xul
+++ b/suite/common/contentAreaContextOverlay.xul
@@ -254,17 +254,17 @@
                 command="cmd_delete"/>
       <menuseparator id="context-sep-paste"/>
       <menuitem id="context-selectall"
                 label="&selectAllCmd.label;"
                 accesskey="&selectAllCmd.accesskey;"
                 command="cmd_selectAll"/>
       <menuseparator id="context-sep-selectall"/>
       <menuitem id="context-searchselect"
-                oncommand="OpenSearch('internet', gContextMenu.searchSelected(), true, event.shiftKey);"/>
+                oncommand="BrowserSearch.loadSearch(gContextMenu.searchSelected(), true);"/>
       <menuseparator id="frame-sep"/>
       <menu id="frame" label="&thisFrameMenu.label;" accesskey="&thisFrameMenu.accesskey;">
         <menupopup id="frame_popup">
           <menuitem id="context-showonlythisframe"
                     label="&showOnlyThisFrameCmd.label;"
                     accesskey="&showOnlyThisFrameCmd.accesskey;"
                     oncommand="gContextMenu.showOnlyThisFrame();"/>
           <menuitem id="context-openframe"
--- a/suite/common/jar.mn
+++ b/suite/common/jar.mn
@@ -227,23 +227,18 @@ comm.jar:
    content/communicator/pref/pref-search.xul                        (pref/pref-search.xul)
    content/communicator/pref/pref-security.js                       (pref/pref-security.js)
    content/communicator/pref/pref-security.xul                      (pref/pref-security.xul)
    content/communicator/pref/pref-smartupdate.js                    (pref/pref-smartupdate.js)
    content/communicator/pref/pref-smartupdate.xul                   (pref/pref-smartupdate.xul)
    content/communicator/pref/pref-tabs.xul                          (pref/pref-tabs.xul)
    content/communicator/profile/profileSelection.js                 (profile/profileSelection.js)
    content/communicator/profile/profileSelection.xul                (profile/profileSelection.xul)
-   content/communicator/search/internetresults.js                   (search/internetresults.js)
-   content/communicator/search/internetresults.xul                  (search/internetresults.xul)
-   content/communicator/search/search-editor.js                     (search/search-editor.js)
-   content/communicator/search/search-editor.xul                    (search/search-editor.xul)
    content/communicator/search/search-panel.js                      (search/search-panel.js)
    content/communicator/search/search-panel.xul                     (search/search-panel.xul)
-   content/communicator/search/shared.js                            (search/shared.js)
    content/communicator/sidebar/customize-panel.js                  (sidebar/customize-panel.js)
    content/communicator/sidebar/customize-panel.xul                 (sidebar/customize-panel.xul)
    content/communicator/sidebar/customize.js                        (sidebar/customize.js)
    content/communicator/sidebar/customize.xul                       (sidebar/customize.xul)
    content/communicator/sidebar/local-panels.rdf                    (sidebar/local-panels.rdf)
    content/communicator/sidebar/PageNotFound.xul                    (sidebar/PageNotFound.xul)
    content/communicator/sidebar/preview.js                          (sidebar/preview.js)
    content/communicator/sidebar/preview.xul                         (sidebar/preview.xul)
--- a/suite/common/nsContextMenu.js
+++ b/suite/common/nsContextMenu.js
@@ -607,17 +607,17 @@ nsContextMenu.prototype = {
               (elem instanceof HTMLModElement && (elem.cite || elem.dateTime)) ||
               (elem instanceof HTMLElement && (elem.title || elem.lang)) ||
               elem.getAttributeNS(XMLNS, "lang")) {
             dump("On metadata item.\n");
             this.onMetaDataItem = true;
           }
         }
 
-        // Background image?  Don't bother if we've already found a 
+        // Background image?  Don't bother if we've already found a
         // background image further down the hierarchy.  Otherwise,
         // we look for the computed background-image style.
         if (!this.hasBGImage) {
           var bgImgUrl = this.getComputedURL(elem, "background-image");
           if (bgImgUrl) {
             this.hasBGImage = true;
             this.bgImageURL = this.makeURLAbsolute(elem.baseURI, bgImgUrl);
           }
@@ -1200,23 +1200,31 @@ nsContextMenu.prototype = {
   isTextSelection: function() {
     var searchSelectText = this.searchSelected(16);
     if (!searchSelectText)
       return false;
 
     if (searchSelectText.length > 15)
       searchSelectText = searchSelectText.substr(0, 15) + this.ellipsis;
 
-    // Format "Search for <selection>" string to show in menu.
+    // Use the current engine if it's a browser window and the search bar is
+    // visible, the default engine otherwise.
+    var engineName = "";
+    if (window.BrowserSearch && BrowserSearch.searchBar && isElementVisible(BrowserSearch.searchBar))
+      engineName = Services.search.currentEngine.name;
+    else
+      engineName = Services.search.defaultEngine.name;
+
+    // format "Search <engine> for <selection>" string to show in menu
     const bundle = document.getElementById("contentAreaCommandsBundle");
-    searchSelectText = bundle.getFormattedString("searchText",
-                                                 [searchSelectText]);
-    this.setItemAttr("context-searchselect", "label", searchSelectText);
+    var menuLabel = bundle.getFormattedString("contextMenuSearchText",
+                                              [engineName, searchSelectText]);
+    this.setItemAttr("context-searchselect", "label", menuLabel);
     this.setItemAttr("context-searchselect", "accesskey",
-                     bundle.getString("searchText.accesskey"));
+                     bundle.getString("contextMenuSearchText.accesskey"));
 
     return true;
   },
 
   searchSelected: function(aCharlen) {
     var focusedWindow = document.commandDispatcher.focusedWindow;
     var searchStr = focusedWindow.getSelection();
     searchStr = searchStr.toString();
--- a/suite/common/pref/pref-search.js
+++ b/suite/common/pref/pref-search.js
@@ -11,63 +11,46 @@
  * for the specific language governing rights and limitations under the
  * License.
  *
  * The Original Code is Mozilla Communicator client code, released
  * March 31, 1998.
  *
  * The Initial Developer of the Original Code is
  * Netscape Communications Corporation.
- * Portions created by the Initial Developer are Copyright (C) 1998-1999
+ * Portions created by the Initial Developer are Copyright (C) 1998-2010
  * the Initial Developer. All Rights Reserved.
  *
  * Contributor(s):
  *   Robert John Churchill <rjc@netscape.com>
  *   Mark Olson <maolson@earthlink.net>
+ *   Robert Kaiser <kairo@kairo.at>
  *
  * Alternatively, the contents of this file may be used under the terms of
  * either of the GNU General Public License Version 2 or later (the "GPL"),
  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  * in which case the provisions of the GPL or the LGPL are applicable instead
  * of those above. If you wish to allow use of your version of this file only
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
-function Startup()
-{
-  var engineList = document.getElementById("engineList");
-  // Need to set ref attribute once overlay has loaded
-  engineList.setAttribute("ref", "NC:SearchEngineRoot");
-  // Due to a bug in the internet search service, the first time
-  // ref is set only one menuitem is built, so force a rebuild
-  engineList.builder.rebuild();
-
-  // Since the menulist starts off empty it has no selected item
-  // so try and set it to the preference value.
-  var pref = document.getElementById(engineList.getAttribute("preference"));
-  engineList.value = pref.value;
+Components.utils.import("resource://gre/modules/Services.jsm");
 
-  // nothing is selected
-  if (!engineList.selectedItem)
-  {
-    var name = document.getElementById("browser.search.defaultenginename").value;
-    var selectedItem = engineList.getElementsByAttribute("label", name).item(0);
- 
-    if (selectedItem)
-    {
-      // select a locale-dependent predefined search engine
-      // in absence of a user default
-      engineList.selectedItem = selectedItem;
-    }
-    else
-    {
-      // select the first listed search engine
-      engineList.selectedIndex = 0;
-    }
-    pref.value = engineList.value;
+function Startup() {
+  var menulist = document.getElementById("engineList");
+  var engines = Services.search.getVisibleEngines();
+  for (let i = 0; i < engines.length; i++) {
+    let name = engines[i].name;
+    let menuitem = menulist.appendItem(name, name);
+    menuitem.setAttribute("class", "menuitem-iconic");
+    if (engines[i].iconURI)
+      menuitem.setAttribute("image", engines[i].iconURI.spec);
+    menulist.menupopup.appendChild(menuitem);
+    menuitem.engine = engines[i];
   }
+  menulist.value = Services.search.defaultEngine.name;
 }
--- a/suite/common/pref/pref-search.xul
+++ b/suite/common/pref/pref-search.xul
@@ -1,116 +1,85 @@
 <?xml version="1.0"?>
 <!-- ***** BEGIN LICENSE BLOCK *****
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
-
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
-
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
-
- The Original Code is Mozilla Communicator client code, released
- March 31, 1998.
+   - Version: MPL 1.1/GPL 2.0/LGPL 2.1
+   -
+   - The contents of this file are subject to the Mozilla Public License Version
+   - 1.1 (the "License"); you may not use this file except in compliance with
+   - the License. You may obtain a copy of the License at
+   - http://www.mozilla.org/MPL/
+   -
+   - Software distributed under the License is distributed on an "AS IS" basis,
+   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+   - for the specific language governing rights and limitations under the
+   - License.
+   -
+   - The Original Code is Mozilla Communicator client code, released
+   - March 31, 1998.
+   -
+   - The Initial Developer of the Original Code is
+   - Netscape Communications Corporation.
+   - Portions created by the Initial Developer are Copyright (C) 1998-2010
+   - the Initial Developer. All Rights Reserved.
+   -
+   - Contributor(s):
+   -   Robert John Churchill <rjc@netscape.com>
+   -   Robert Kaiser <kairo@kairo.at>
+   -
+   - Alternatively, the contents of this file may be used under the terms of
+   - either the GNU General Public License Version 2 or later (the "GPL"), or
+   - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+   - in which case the provisions of the GPL or the LGPL are applicable instead
+   - of those above. If you wish to allow use of your version of this file only
+   - under the terms of either the GPL or the LGPL, and not to allow others to
+   - use your version of this file under the terms of the MPL, indicate your
+   - decision by deleting the provisions above and replace them with the notice
+   - and other provisions required by the GPL or the LGPL. If you do not delete
+   - the provisions above, a recipient may use your version of this file under
+   - the terms of any one of the MPL, the GPL or the LGPL.
+   -
+   - ***** END LICENSE BLOCK ***** -->
 
- The Initial Developer of the Original Code is
- Netscape Communications Corporation.
- Portions created by the Initial Developer are Copyright (C) 1998-1999
- the Initial Developer. All Rights Reserved.
-
- Contributor(s):
-   Robert John Churchill (rjc@netscape.com)
-
- Alternatively, the contents of this file may be used under the terms of
- either of the GNU General Public License Version 2 or later (the "GPL"),
- or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- in which case the provisions of the GPL or the LGPL are applicable instead
- of those above. If you wish to allow use of your version of this file only
- under the terms of either the GPL or the LGPL, and not to allow others to
- use your version of this file under the terms of the MPL, indicate your
- decision by deleting the provisions above and replace them with the notice
- and other provisions required by the GPL or the LGPL. If you do not delete
- the provisions above, a recipient may use your version of this file under
- the terms of any one of the MPL, the GPL or the LGPL.
-
- ***** END LICENSE BLOCK ***** -->
 <?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
 
 <!DOCTYPE overlay SYSTEM "chrome://communicator/locale/pref/pref-search.dtd">
 <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <prefpane id="search_pane"
             label="&pref.search.title;"
             script="chrome://communicator/content/pref/pref-search.js">
 
     <preferences id="search_preferences">
       <preference id="browser.search.defaultenginename"
                   name="browser.search.defaultenginename"
-                  type="wstring"/>
-      <preference id="browser.search.defaultengine"
-                  name="browser.search.defaultengine"
                   type="string"/>
+      <preference id="browser.search.openintab"
+                  name="browser.search.openintab"
+                  type="bool"/>
       <preference id="browser.search.opensidebarsearchpanel"
                   name="browser.search.opensidebarsearchpanel"
                   type="bool"/>
-      <preference id="browser.search.opentabforcontextsearch"
-                  name="browser.search.opentabforcontextsearch"
-                  type="bool"/>
-      <preference id="browser.search.mode"
-                  name="browser.search.mode"
-                  type="int"/>
     </preferences>
 
     <groupbox>
       <caption label="&legendHeader;"/>
 
       <hbox align="center">
         <label value="&defaultSearchEngine.label;"
                accesskey="&defaultSearchEngine.accesskey;"
                control="engineList"/>
         <menulist id="engineList"
-                  ref=""
-                  datasources="rdf:internetsearch"
-                  sortResource="http://home.netscape.com/NC-rdf#Name"
-                  sortDirection="ascending"
-                  preference="browser.search.defaultengine">
-          <template>
-            <menupopup>
-              <menuitem class="menuitem-iconic"
-                        value="..."
-                        uri="..."
-                        image="rdf:http://home.netscape.com/NC-rdf#Icon"
-                        label="rdf:http://home.netscape.com/NC-rdf#Name"/>
-            </menupopup>
-          </template>
-        </menulist>
+                  preference="browser.search.defaultenginename"/>
       </hbox>
     </groupbox>
 
     <groupbox>
       <caption label="&searchResults.label;"/>
+      <checkbox id="openSearchTab"
+                label="&openInTab.label;"
+                accesskey="&openInTab.accesskey;"
+                preference="browser.search.openintab"/>
       <checkbox id="openSidebarPanel"
                 label="&openSidebarSearchPanel.label;"
                 accesskey="&openSidebarSearchPanel.accesskey;"
                 preference="browser.search.opensidebarsearchpanel"/>
-      <checkbox id="openContextSearchTab"
-                label="&openContextSearchTab.label;"
-                accesskey="&openContextSearchTab.accesskey;"
-                preference="browser.search.opentabforcontextsearch"/>
-    </groupbox>
-
-    <groupbox>
-      <caption label="&sidebarSearchTabPref.label;"/>
-      <radiogroup id="sidebarSearchMode"
-                  preference="browser.search.mode">
-        <radio value="0"
-               label="&searchModeBasic.label;"
-               accesskey="&searchModeBasic.accesskey;"/>
-        <radio value="1"
-               label="&searchModeAdvanced.label;"
-               accesskey="&searchModeAdvanced.accesskey;"/>
-      </radiogroup>
     </groupbox>
   </prefpane>
 </overlay>
deleted file mode 100644
--- a/suite/common/search/internetresults.js
+++ /dev/null
@@ -1,266 +0,0 @@
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * The Original Code is mozilla.org code.
- *
- * The Initial Developer of the Original Code is Robert John Churchill.
- * Portions created by the Initial Developer are Copyright (C) 1999
- * the Initial Developer. All Rights Reserved.
- *
- * Contributor(s): 
- *    Robert John Churchill   <rjc@netscape.com> (Original Author)
- *    Ben Goodger             <ben@netscape.com>
- *    Daniel Matejka          <danm@netscape.com>
- *    Eric Pollmann           <pollmann@netscape.com>
- *    Ray Whitmer             <rayw@netscape.com>
- *    Peter Annema            <disttsc@bart.nl>
- *    Blake Ross              <blakeross@telocity.com>
- *    Joe Hewitt              <hewitt@netscape.com>
- *    Jan Varga               <varga@utcruk.sk>
- *    Karsten Duesterloh      <kd-moz@tprac.de>
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 2 or later (the "GPL"), or
- * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- * in which case the provisions of the GPL or the LGPL are applicable instead
- * of those above. If you wish to allow use of your version of this file only
- * under the terms of either the GPL or the LGPL, and not to allow others to
- * use your version of this file under the terms of the MPL, indicate your
- * decision by deleting the provisions above and replace them with the notice
- * and other provisions required by the GPL or the LGPL. If you do not delete
- * the provisions above, a recipient may use your version of this file under
- * the terms of any one of the MPL, the GPL or the LGPL.
- *
- * ***** END LICENSE BLOCK ***** */
-
-function searchResultsOpenURL(event)
-{
-  var tree = document.getElementById("resultsList");
-  var node = tree.contentView.getItemAtIndex(tree.currentIndex);
-  
-  var url = node.id;
-  var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
-  if (rdf)   rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
-  if (rdf)
-  {
-    var ds = rdf.GetDataSource("rdf:internetsearch");
-    if (ds)
-    {
-      var src = rdf.GetResource(url, true);
-      var prop = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
-      var target = ds.GetTarget(src, prop, true);
-      if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
-      if (target) target = target.Value;
-      if (target) url = target;
-    }
-  }
-
-  // Ignore "NC:" urls.
-  if (url.substring(0, 3) == "NC:")
-    return false;
-
-  if ("loadURI" in top)
-    top.loadURI(url);
-  else
-    top.content.location.href = url;
-
-  return true;
-}
-
-
-// Workaround for bug 196057 (double onload event): accept only the first onload event
-// ( This workaround will fix bug 147068 (duplicate search results).
-//   Without this fix, xpfe\components\search\src\nsInternetSearchService.cpp will
-//   crash when removing the same tree node twice. )
-// If bug 196057 should be fixed eventually, this workaround does no harm -
-// nevertheless it should be removed then
-var gbProcessOnloadEvent = true;
-
-function onLoadInternetResults()
-{
-  if (gbProcessOnloadEvent)
-  { // forbid other onload events
-    gbProcessOnloadEvent = false;
-
-    // clear any previous results on load
-    var iSearch = Components.classes["@mozilla.org/rdf/datasource;1?name=internetsearch"]
-                            .getService(Components.interfaces.nsIInternetSearchService);
-    iSearch.ClearResultSearchSites();
-
-    // the search URI is passed in as a parameter, so get it and then root the results list
-    var searchURI = top.content.location.href;
-    if (searchURI) {
-      const lastSearchURIPref = "browser.search.lastMultipleSearchURI";
-      var offset = searchURI.indexOf("?");
-      if (offset > 0) {
-        nsPreferences.setUnicharPref(lastSearchURIPref, searchURI); // evil
-        searchURI = searchURI.substr(offset+1);
-        loadResultsList(searchURI);
-      }
-      else {
-        searchURI = nsPreferences.copyUnicharPref(lastSearchURIPref, "");
-        offset = searchURI.indexOf("?");
-        if (offset > 0) {
-          nsPreferences.setUnicharPref(lastSearchURIPref, searchURI); // evil
-          searchURI = searchURI.substr(offset+1);
-          loadResultsList(searchURI);
-        }
-      }
-    }
-  }
-  return true;
-}
-
-function loadResultsList( aSearchURL )
-{
-  var resultsTree = document.getElementById( "resultsList" );
-  if (!resultsTree) return false;
-  resultsTree.setAttribute("ref", decodeURI(aSearchURL));
-  return true;
-}
-
-
-
-function doEngineClick( event, aNode )
-{
-  event.target.checked = true;
-
-  var html = null;
-
-  var resultsTree = document.getElementById("resultsList");
-  var contentArea = document.getElementById("resultsContent");
-  var splitter = document.getElementById("results-splitter");
-  var engineURI = aNode.id;
-  if (engineURI == "allEngines") {
-    resultsTree.removeAttribute("hidden");
-    splitter.removeAttribute("hidden");
-  }
-  else
-  {
-    resultsTree.setAttribute("hidden", "true");
-    splitter.setAttribute("hidden", "true");
-    try
-    {
-      var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
-      if (rdf)   rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
-      if (rdf)
-      {
-        var internetSearchStore = rdf.GetDataSource("rdf:internetsearch");
-        if (internetSearchStore)
-        {
-          var src = rdf.GetResource(engineURI, true);
-          var htmlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#HTML", true);
-          html = internetSearchStore.GetTarget(src, htmlProperty, true);
-          if ( html ) html = html.QueryInterface(Components.interfaces.nsIRDFLiteral);
-          if ( html ) html = html.Value;
-        }
-      }
-    }
-    catch(ex)
-    {
-    }
-  }
-
-  if ( html )
-  {
-    var doc = frames[0].document;
-    if (doc)
-    {
-        doc.open("text/html", "replace");
-        doc.writeln( html );
-        doc.close();
-    }
-  }
-  else
-    frames[0].document.location.href = 
-      "chrome://communicator/locale/search/default.htm";
-}
-
-
-
-function doResultClick(node)
-{
-  var theID = node.id;
-  if (!theID) return(false);
-
-  try
-  {
-    var rdf = Components.classes["@mozilla.org/rdf/rdf-service;1"].getService();
-    if (rdf)   rdf = rdf.QueryInterface(Components.interfaces.nsIRDFService);
-    if (rdf)
-    {
-      var internetSearchStore = rdf.GetDataSource("rdf:internetsearch");
-      if (internetSearchStore)
-      {
-        var src = rdf.GetResource(theID, true);
-        var urlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#URL", true);
-        var bannerProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#Banner", true);
-        var htmlProperty = rdf.GetResource("http://home.netscape.com/NC-rdf#HTML", true);
-
-        var url = internetSearchStore.GetTarget(src, urlProperty, true);
-        if (url)  url = url.QueryInterface(Components.interfaces.nsIRDFLiteral);
-        if (url)  url = url.Value;
-        if (url)
-        {
-          var statusNode = document.getElementById("status-button");
-          if (statusNode)
-          {
-            statusNode.label = url;
-          }
-        }
-
-        var banner = internetSearchStore.GetTarget(src, bannerProperty, true);
-        if (banner) banner = banner.QueryInterface(Components.interfaces.nsIRDFLiteral);
-        if (banner) banner = banner.Value;
-
-        var target = internetSearchStore.GetTarget(src, htmlProperty, true);
-        if (target) target = target.QueryInterface(Components.interfaces.nsIRDFLiteral);
-        if (target) target = target.Value;
-        if (target)
-        {
-          var text = "<HTML><HEAD><TITLE>Search</TITLE><BASE TARGET='_top'></HEAD><BODY><FONT POINT-SIZE='9'>";
-
-          if (banner)
-            text += banner + "</A><BR>"; // add a </A> and a <BR> just in case
-          text += target;
-          text += "</FONT></BODY></HTML>"
-
-          var doc = frames[0].document;
-          doc.open("text/html", "replace");
-          doc.writeln(text);
-          doc.close();
-        }
-      }
-    }
-  }
-  catch(ex)
-  {
-  }
-  return(true);
-}
-
-function listSelect(event)
-{
-  var tree = document.getElementById("resultsList");
-  if (tree.view.selection.count != 1)
-    return false;
-  var selection = tree.contentView.getItemAtIndex(tree.currentIndex);
-  return doResultClick(selection);
-}
-
-function listClick(event)
-{ // left double click opens URL
-  if (event.detail == 2 && event.button == 0)
-    searchResultsOpenURL(event);
-  return true; // always allow further click processing
-}
deleted file mode 100644
--- a/suite/common/search/internetresults.xul
+++ /dev/null
@@ -1,124 +0,0 @@
-<?xml version="1.0"?>
-<?xml-stylesheet href="chrome://communicator/skin/" type="text/css"?>
-<?xml-stylesheet href="chrome://communicator/skin/search/search.css" type="text/css"?>
-<?xml-stylesheet href="chrome://communicator/skin/search/internetresults.css" type="text/css"?>
-
-<!DOCTYPE page SYSTEM "chrome://communicator/locale/search/internetresults.dtd">
-
-<page onload="onLoadInternetResults();"
-      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-      xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
-      title="&internetresults.title;"
-      context="disallowcontext">
-
-  <popupset>
-    <menupopup id="disallowcontext" onpopupshowing="return false;"/>
-  </popupset>
-
-  <script type="application/javascript" src="chrome://global/content/nsUserSettings.js"/>
-  <script type="application/javascript" src="chrome://communicator/content/search/internetresults.js"/>
-  <script type="application/javascript" src="chrome://communicator/content/search/shared.js"/>
-
-  <hbox id="multi-results-header"> 
-    <label value="&results.header.label;"/>
-  </hbox>
-
-  <hbox align="center" style="min-width: 1px;">
-    <label value="&viewbyprovider.label;"/>
-    <menulist id="engineTabs" ref="NC:SearchResultsSitesRoot"
-              datasources="rdf:internetsearch" oncommand="switchTab(1);">
-      <template>
-        <menupopup>
-          <menuitem id="chooseCat" uri="..." oncommand="doEngineClick(event, this);"
-                    src="rdf:http://home.netscape.com/NC-rdf#Icon"
-                    value="rdf:http://home.netscape.com/NC-rdf#category"
-                    label="rdf:http://home.netscape.com/NC-rdf#Name"/>
-        </menupopup>
-      </template>
-      <menupopup id="categoryPopup">
-        <menuitem id="allEngines" value="NC:SearchEngineRoot" label="&allresults.title.label;"
-                  oncommand="doEngineClick(event, this);"/>
-        <menuseparator/>
-      </menupopup>
-    </menulist>
-  </hbox>
-
-  <menupopup id="contextual" onpopupshowing="return fillContextMenu('contextual', 'resultsList');"/>
-  
-  <tree id="resultsList" flex="1" class="plain"
-           datasources="rdf:internetsearch" context="contextual"
-           onselect="return listSelect(event);"
-           onclick ="return listClick (event);">
-
-    <treecols onclick="doSort(event.target.id, 'http://home.netscape.com/NC-rdf#PageRank');">
-      <treecol id="NameColumn" primary="true" label="&name.column.label;"
-               resource="http://home.netscape.com/NC-rdf#Name" flex="1"/>
-      <splitter class="tree-splitter"/>
-      <treecol id="PageRankColumn" label="&pagerank.column.label;"
-               resource="http://home.netscape.com/NC-rdf#PageRank"
-               resource2="http://home.netscape.com/NC-rdf#Name" flex="1"/>
-      <splitter class="tree-splitter"/>
-      <treecol id="RelevanceColumn" label="&relevance.column.label;"
-               resource="http://home.netscape.com/NC-rdf#Relevance"
-               resource2="http://home.netscape.com/NC-rdf#Name"
-               hidden="true" flex="1"/>
-      <splitter class="tree-splitter"/>
-      <treecol id="PriceColumn" label="&price.column.label;"
-               resource="http://home.netscape.com/NC-rdf#Price"
-               resource2="http://home.netscape.com/NC-rdf#Availability"
-               hidden="true" flex="1"/>
-      <splitter class="tree-splitter"/>
-      <treecol id="AvailabilityColumn" label="&availability.column.label;"
-               resource="http://home.netscape.com/NC-rdf#Availability"
-               resource2="http://home.netscape.com/NC-rdf#Price"
-               hidden="true" flex="1"/>
-      <splitter class="tree-splitter"/>
-      <treecol id="DateColumn" label="&date.column.label;"
-               resource="http://home.netscape.com/NC-rdf#Date"
-               resource2="http://home.netscape.com/NC-rdf#Name"
-               hidden="true" flex="1"/>
-      <splitter class="tree-splitter"/>
-      <treecol id="SiteColumn" label="&site.column.label;"
-               resource="http://home.netscape.com/NC-rdf#Site"
-               resource2="http://home.netscape.com/NC-rdf#Name" flex="1"/>
-      <splitter class="tree-splitter"/>
-      <treecol id="EngineColumn" label="&engine.column.label;"
-               resource="http://home.netscape.com/NC-rdf#Engine"
-               resource2="http://home.netscape.com/NC-rdf#Name" flex="1"/>
-    </treecols>
-
-    <template>
-      <rule rdf:type="http://home.netscape.com/NC-rdf#BookmarkSeparator">
-        <treeseparator uri="..."/>
-      </rule>
-      
-      <rule>
-        <treechildren>
-          <treeitem uri="...">
-            <treerow>
-              <treecell src="rdf:http://home.netscape.com/NC-rdf#Icon" 
-                        label="rdf:http://home.netscape.com/NC-rdf#Name" />
-              <treecell label="rdf:http://home.netscape.com/NC-rdf#PageRank"/>
-              <treecell label="rdf:http://home.netscape.com/NC-rdf#Relevance"/>
-              <treecell label="rdf:http://home.netscape.com/NC-rdf#Price"/>
-              <treecell label="rdf:http://home.netscape.com/NC-rdf#Availability"/>
-              <treecell label="rdf:http://home.netscape.com/NC-rdf#Date"/>
-              <treecell label="rdf:http://home.netscape.com/NC-rdf#Site"/>
-              <treecell label="rdf:http://home.netscape.com/NC-rdf#Engine"/>
-            </treerow>
-          </treeitem>
-        </treechildren>
-      </rule>
-    </template>
-
-  </tree>
-
-  <splitter id="results-splitter" persist="state" collapse="after">
-    <grippy/>
-  </splitter>
-  
-  <hbox flex="1">
-    <iframe id="resultsContent" flex="1" src="chrome://communicator/locale/search/default.htm"/>
-  </hbox>
-  
-</page>
deleted file mode 100644
--- a/suite/common/search/search-editor.js
+++ /dev/null
@@ -1,634 +0,0 @@
-/* -*- Mode: Java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
- * Version: MPL 1.1/GPL 2.0/LGPL 2.1
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- * http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
<