Localized Search in Firefox Search Box: Release v.01

From CDOT Wiki
Jump to: navigation, search

Main Project Page

Localized Search in Firefox Search Box

Patch File

? localsearchpatch_v01.txt
? objdir-ff-debug
Index: browser/base/content/browser.js
===================================================================
RCS file: /cvsroot/mozilla/browser/base/content/browser.js,v
retrieving revision 1.953
diff -u -8 -p -r1.953 browser.js
--- browser/base/content/browser.js	30 Jan 2008 18:23:53 -0000	1.953
+++ browser/base/content/browser.js	1 Feb 2008 19:20:27 -0000
@@ -2794,16 +2794,17 @@ const BrowserSearch = {
 
     engines.push({ uri: engine.href,
                    title: engine.title,
                    icon: iconURL });
 
     if (hidden)
       browser.hiddenEngines = engines;
     else {
+      dump("DIAGNOSTIC MESSAGE: addEngine: function(engine, targetDoc) - Added a search engine plugin that was detected on web site.\n");
       browser.engines = engines;
       if (browser == gBrowser || browser == gBrowser.mCurrentBrowser)
         this.updateSearchButton();
     }
   },
 
   /**
    * Update the browser UI to show whether or not additional engines are 
Index: browser/components/search/nsSearchService.js
===================================================================
RCS file: /cvsroot/mozilla/browser/components/search/nsSearchService.js,v
retrieving revision 1.108
diff -u -8 -p -r1.108 nsSearchService.js
--- browser/components/search/nsSearchService.js	29 Jan 2008 19:39:20 -0000	1.108
+++ browser/components/search/nsSearchService.js	1 Feb 2008 19:20:30 -0000
@@ -2817,16 +2817,17 @@ SearchService.prototype = {
     if (currentIndex == aNewIndex)
       return; // nothing to do!
 
     // Move the engine
     var movedEngine = this._sortedEngines.splice(currentIndex, 1)[0];
     this._sortedEngines.splice(aNewIndex, 0, movedEngine);
 
     notifyAction(engine, SEARCH_ENGINE_CHANGED);
+    dump("DIAGNOSTIC MESSAGE: moveEngine: function SRCH_SVC_moveEngine(aEngine, aNewIndex) - MOVE search engine.\n");
 
     // Since we moved an engine, we need to update the preferences.
     this._needToSetOrderPrefs = true;
   },
 
   restoreDefaultEngines: function SRCH_SVC_resetDefaultEngines() {
     for each (var e in this._engines) {
       // Unhide all default engines
@@ -2837,16 +2838,17 @@ SearchService.prototype = {
 
   get defaultEngine() {
     const defPref = BROWSER_SEARCH_PREF + "defaultenginename";
     // Get the default engine - this pref should always exist, but the engine
     // might be hidden
     this._defaultEngine = this.getEngineByName(getLocalizedPref(defPref, ""));
     if (!this._defaultEngine || this._defaultEngine.hidden)
       this._defaultEngine = this._getSortedEngines(false)[0] || null;
+    dump("DIAGNOSTIC MESSAGE: get defaultEngine() - GET Default search engine.\n");
     return this._defaultEngine;
   },
 
   get currentEngine() {
     if (!this._currentEngine || this._currentEngine.hidden)
       this._currentEngine = this.defaultEngine;
     return this._currentEngine;
   },
@@ -2868,16 +2870,17 @@ SearchService.prototype = {
     if (this._currentEngine == this.defaultEngine) {
       if (prefB.prefHasUserValue(currentEnginePref))
         prefB.clearUserPref(currentEnginePref);
     }
     else {
       setLocalizedPref(currentEnginePref, this._currentEngine.name);
     }
 
+    dump("DIAGNOSTIC MESSAGE: set currentEngine(val) - SET Current search engine.\n");
     notifyAction(this._currentEngine, SEARCH_ENGINE_CURRENT);
   },
 
   // nsIObserver
   observe: function SRCH_SVC_observe(aEngine, aTopic, aVerb) {
     switch (aTopic) {
       case SEARCH_ENGINE_TOPIC:
         if (aVerb == SEARCH_ENGINE_LOADED) {
Index: browser/components/search/content/engineManager.js
===================================================================
RCS file: /cvsroot/mozilla/browser/components/search/content/engineManager.js,v
retrieving revision 1.18
diff -u -8 -p -r1.18 engineManager.js
--- browser/components/search/content/engineManager.js	26 Jul 2007 03:59:31 -0000	1.18
+++ browser/components/search/content/engineManager.js	1 Feb 2008 19:20:30 -0000
@@ -273,16 +273,18 @@ function EngineRemoveOp(aEngineClone) {
   this._engine = aEngineClone.originalEngine;
 }
 EngineRemoveOp.prototype = {
   _engine: null,
   commit: function ERO_commit() {
     var searchService = Cc["@mozilla.org/browser/search-service;1"].
                         getService(Ci.nsIBrowserSearchService);
     searchService.removeEngine(this._engine);
+
+    dump("DIAGNOSTIC MESSAGE: commit: function ERO_commit() - User clicked OK to commit to search engine removal.\n");
   }
 }
 
 function EngineUnhideOp(aEngineClone, aNewIndex) {
   if (!aEngineClone)
     throw new Error("bad args to new EngineUnhideOp!");
   this._engine = aEngineClone.originalEngine;
   this._newIndex = aNewIndex;
@@ -404,16 +406,18 @@ EngineStore.prototype = {
     var index = this._getIndexForEngine(aEngine);
     if (index == -1)
       throw new Error("invalid engine?");
  
     this._engines.splice(index, 1);
     this._ops.push(new EngineRemoveOp(aEngine));
     if (this._defaultEngines.some(this._isSameEngine, aEngine))
       gEngineManagerDialog.showRestoreDefaults(true);
+
+    dump("DIAGNOSTIC MESSAGE: removeEngine: function ES_removeEngine(aEngine) - User selected an engine to \'Remove\' from Engine Manager list.\n");
   },
 
   restoreDefaultEngines: function ES_restoreDefaultEngines() {
     var added = 0;
 
     for (var i = 0; i < this._defaultEngines.length; ++i) {
       var e = this._defaultEngines[i];
 
Index: browser/components/search/content/search.xml
===================================================================
RCS file: /cvsroot/mozilla/browser/components/search/content/search.xml,v
retrieving revision 1.119
diff -u -8 -p -r1.119 search.xml
--- browser/components/search/content/search.xml	29 Jan 2008 19:31:10 -0000	1.119
+++ browser/components/search/content/search.xml	1 Feb 2008 19:20:31 -0000
@@ -281,16 +281,18 @@
       335102.  -->
 
       <!-- If the engine that was just removed from the searchbox list was
       autodetected on this page, move it to each browser's active list so it
       will be offered to be added again. -->
       <method name="offerNewEngine">
         <parameter name="aEngine"/>
         <body><![CDATA[
+	  dump("DIAGNOSTIC MESSAGE: offerNewEngine(aEngine) - Move auto-detected search engines to each browser's \'active\' list ");
+	  dump("when they are removed from the search menu.\n");
           var allbrowsers = getBrowser().mPanelContainer.childNodes;
           for (var tab = 0; tab < allbrowsers.length; tab++) {
             var browser = getBrowser().getBrowserAtIndex(tab);
             if (browser.hiddenEngines) {
               // XXX This will need to be changed when engines are identified by
               // URL rather than title; see bug 335102.
               var removeTitle = aEngine.wrappedJSObject.name;
               for (var i = 0; i < browser.hiddenEngines.length; i++) {
@@ -308,17 +310,19 @@
         ]]></body>
       </method>
 
       <!-- If the engine that was just added to the searchbox list was
       autodetected on this page, move it to each browser's hidden list so it is
       no longer offered to be added. -->
       <method name="hideNewEngine">
         <parameter name="aEngine"/>
-        <body><![CDATA[
+        <body><![CDATA[ 
+	  dump("DIAGNOSTIC MESSAGE: hideNewEngine(aEngine) - Move auto-detected search engines to each browser's \'hidden\' list.\n");
+
           var allbrowsers = getBrowser().mPanelContainer.childNodes;
           for (var tab = 0; tab < allbrowsers.length; tab++) {
             var browser = getBrowser().getBrowserAtIndex(tab);
             if (browser.engines) {
               // XXX This will need to be changed when engines are identified by
               // URL rather than title; see bug 335102.
               var removeTitle = aEngine.wrappedJSObject.name;
               for (var i = 0; i < browser.engines.length; i++) {
@@ -404,16 +408,18 @@
               menuitem = document.createElementNS(kXULNS, "menuitem");
               menuitem.setAttribute("class", "menuitem-iconic addengine-item");
               menuitem.setAttribute("label", labelStr);
               menuitem.setAttribute("tooltiptext", engineInfo.uri);
               menuitem.setAttribute("uri", engineInfo.uri);
               if (engineInfo.icon)
                 menuitem.setAttribute("src", engineInfo.icon);
               menuitem.setAttribute("title", engineInfo.title);
+
+	      dump("DIAGNOSTIC MESSAGE: rebuildPopupDynamic() - Insert \'Add auto-detected engine\' to search engine menu.\n");
               popup.insertBefore(menuitem, insertLocation);
             }
           }
         ]]></body>
       </method>
 
       <!-- Rebuilds the list of visible search engines in the menu.  Does not remove
            or update any dynamic entries (i.e., "Add this engine" items) nor the


Applying the Patch

1. Copy and paste the text from the patch file into a text file and save it in the root mozilla directory of your source tree. I suggest naming the file localsearchpatch_v01.txt.

  • NOTE: This patch requires that you use a DEBUG build of firefox. To see the output messages from the dump() statements in the patch, you have to enable it by setting the preference browser.dom.window.dump.enabled to true. You can set this preference in about:config or in a user.js file. This preference is not listed in about:config by default, so you may need to create it. Enter about:config in the browser's address bar -> right-click the empty content area -> New -> Boolean.
  • You can preview the patch here: Localized Search in Firefox Search Box: Release v.01

2. Apply the patch.

 $ cd mozilla
 $ patch -p0 < localsearchpatch_v01.txt
  • NOTE: Use the -p0 option to strip 0 leading directories from each filename in the patch because it is being applied in the same directory where the patch was created.


3. Build your source tree.

 $ cd mozilla
 $ make -f client.mk build


4. Run the browser to test the patch.

 $ cd objdir/dist/bin
 $ ./firefox --ProfileManager --no-remote


How to Use the Patch

1. Navigate to a web site that offers a search engine plugin.

Note the DIAGNOSTIC MESSAGE in the terminal window.


2. Click the searchbar's dropdown menu button.

  • Note the DIAGNOSTIC MESSAGE in the terminal window and the "Add this engine" option on the searchbar menu.


3. Click the "Add this engine" option on the searchbar menu.

  • Note the DIAGNOSTIC MESSAGE in the terminal window and the position of the newly added search engine on the searchbar menu.


4. Select "Manage Search Engines..." from the searchbar menu and select the newly installed engine from the list. Click the "Remove" button and then click "OK".

  • Note the DIAGNOSTIC MESSAGES in the terminal window.


5. Select "Manage Search Engines..." from the searchbar menu and select one of the installed engines on the list. Next, click the "Move Up" and "Move Down" buttons and then click "OK".

  • Note the DIAGNOSTIC MESSAGES in the terminal window.


6. Click the searchbar's dropdown menu button and select a different search engine as the current engine.

  • Note the DIAGNOSTIC MESSAGES in the terminal window.


How to Remove the Patch

  • You can back-out a patch by using the patch command with the -R or --reverse option. This swaps the new file with the old one to reverse the patch.
 $ cd mozilla
 $ patch -R -p0 < localsearchpatch_v01.txt


Return to top