Open main menu

CDOT Wiki β

Changes

Localized Search in Firefox Search Box

1,578 bytes added, 12:21, 11 February 2008
'''Release v.02'''
-
- if (hidden)
+ // Use the nsIBrowserSearchService to Dynamically "Add" the search engine plugin ifit is NOT+ // it is NOT already on the search engine list and then add it to the + // searchbar's array of "hidden" engines.
+ if (!searchService.getEngineByName(engine.title)) {
+ searchService.addEngine(engine.href, Components.interfaces.nsISearchEngine.DATA_XML, iconURL, false);
</pre>
 
=== '''Code Modifications''' ===
My code modifications alter the original addEngine() function by using the nsIBrowserSearchService object to check if the new search plugin is NOT on the list. If it is not on the list, I "Add" the search plugin by calling the [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsSearchService.js#2726 addEngine() function] in the [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsSearchService.js nsSearchService.js] file. This function completes the important step of creating a '''new''' nsISearchEngine object. It is this type of object that is required by important methods in search.xml, such as [http://lxr.mozilla.org/seamonkey/source/browser/components/search/content/search.xml#208 observe()],[http://lxr.mozilla.org/seamonkey/source/browser/components/search/content/search.xml#262 offerNewEngine()] and [http://lxr.mozilla.org/seamonkey/source/browser/components/search/content/search.xml#290 hideNewEngine()]. I then push the anonymous JavaScript ''engine'' object onto the the list of "hidden" search engines, the ''browser.hiddenEngines'' array. It is not necessary for me to add any of the auto-detected search plugins to the ''browser.engines'' array at this point. My objective is to dynamically "Add" the auto-detected search engines, therefore they are all considered to be "hidden" engines for now and they are not displayed on the searchbar as "Add <Search Engine>" menu items.
 
=== How to Use the Patch ===
 
1. Copy and paste all of the text from the [http://zenit.senecac.on.ca/wiki/index.php/Localized_Search_in_Firefox_Search_Box#Patch_File patch file] into a text file and name the file localsearchpatch_v02.txt. Save the file to your root mozilla directory. Then, [http://zenit.senecac.on.ca/wiki/index.php/Localized_Search_in_Firefox_Search_Box#Downloading_and_applying_the_patch apply the patch and recompile] your mozilla source code as described in the release v.01 notes.
 
2. Navigate to a web site that offers a search engine plugin:
 
* [http://developer.mozilla.org/en/docs/Main_Page Mozilla Developer Center]
* [http://www.theglobeandmail.com/ The Globe and Mail]
* [http://www.yellowpages.ca/ Yellow Pages]
 
3. Notice that the search plugin has been dynamically loaded and added to the searchbar's list of "hidden" engines. The newly added search engine appears as the current engine and it can be used to search the web site.
 
4. Notice also that the "Add <Search Engine>" menu item is not displayed and the searchbar's drop-down list button did not turn blue because the search plugin was dynamically loaded.
 
5. Open the "Manage Search Engines" dialog box and "Remove" the dynamically loaded search engine. It will now appear on the the searchbar's list as an "Add <Search Engine>" menu item. It can then be added back as normal to the searchbar's list.
 
6. Clicking Firefox's reload button will reload the web page and trigger the code for the search plugin to be dynamically added to the list if it is not already on the searchbar's list of "hidden" engines.
== '''Release Target for v.03''' ==
1
edit