|
|
(14 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| = '''Project Name''' = | | = '''Project Name''' = |
| | | |
− | Localized Search in Firefox Search Box | + | '''Localized Search in Firefox Search Box''' |
| | | |
| | | |
Line 11: |
Line 11: |
| = '''Project Leader''' = | | = '''Project Leader''' = |
| | | |
− | [http://zenit.senecac.on.ca/wiki/index.php/User:Sinker Kerry M. Singh] | + | ==== [[User:Sinker | Kerry M. Singh]] ==== |
| | | |
| | | |
Line 38: |
Line 38: |
| | | |
| * [http://en.wikipedia.org/wiki/Main_Page Wikipedia] | | * [http://en.wikipedia.org/wiki/Main_Page Wikipedia] |
| + | |
| | | |
| = '''Project Details''' = | | = '''Project Details''' = |
Line 44: |
Line 45: |
| == '''Release v.01''' == | | == '''Release v.01''' == |
| | | |
− | This release demonstrates my understanding of how some searchbar features currently work in the Firefox browser. I've uploaded a [http://zenit.senecac.on.ca/wiki/index.php/Image:Localsearchpatch_v01.txt.zip patch file] that outputs a series of dump("DIAGNOSTIC MESSAGE: function name - what the source code is doing") statements to the terminal window while running a debug build of Firefox (i.e. Minefield). Specifically, what functions/methods are called and what is happening in the source code with respect to the searchbar menu when the following events occur: | + | This release demonstrates my understanding of how some searchbar features currently work in the Firefox browser. I've created a [http://zenit.senecac.on.ca/wiki/index.php/Image:Localsearchpatch_v01.txt.zip patch file] that outputs a series of dump("DIAGNOSTIC MESSAGE: function name - what the source code is doing") statements to the terminal window while running a debug build of Firefox (i.e. Minefield). Specifically, what functions/methods are called and what is happening in the source code with respect to the searchbar menu when the following events occur: |
| | | |
| * The browser auto-detects a site that has a search plugin available. | | * The browser auto-detects a site that has a search plugin available. |
Line 53: |
Line 54: |
| * The user removes an auto-detected search engine from the list of "installed" search engines. | | * The user removes an auto-detected search engine from the list of "installed" search engines. |
| | | |
| + | === '''Release Details''' === |
| | | |
− | === '''Downloading and applying the patch''' === | + | ==== [[Localized Search in Firefox Search Box: Release v.01]] ==== |
− | | |
− | 1. Download the [http://zenit.senecac.on.ca/wiki/index.php/Image:Localsearchpatch_v01.txt.zip patch file] to the root mozilla directory of your source tree and unzip the file there. I suggest renaming 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 [http://kb.mozillazine.org/About:config about:config] or in a [http://kb.mozillazine.org/User.js_file user.js file]. This preference is not listed in about:config by default, so you may need to create it. Enter <code>about:config</code> 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.
| |
− | <pre>
| |
− | $ cd mozilla
| |
− | $ patch -p0 < localsearchpatch_v01.txt
| |
− | </pre>
| |
− | * '''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.
| |
− | <pre>
| |
− | $ cd mozilla
| |
− | $ make -f client.mk build
| |
− | </pre>
| |
− | | |
− | | |
− | 4. Run the browser to test the patch.
| |
− | <pre>
| |
− | $ cd objdir/dist/bin
| |
− | $ ./firefox --ProfileManager --no-remote
| |
− | </pre>
| |
− | | |
− | | |
− | === '''How to Use the Patch''' === | |
− | | |
− | 1. Navigate to a web site that offers a search engine plugin:
| |
− | * [https://bugzilla.mozilla.org/ Bugzilla@Mozilla]
| |
− | * [http://developer.mozilla.org/en/docs/Main_Page Mozilla Developer Center]
| |
− | * [http://www.theglobeandmail.com/ The Globe and Mail]
| |
− | | |
− | '''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.
| |
− | | |
− | <pre>
| |
− | $ cd mozilla
| |
− | $ patch -R -p0 < localsearchpatch_v01.txt
| |
− | </pre>
| |
| | | |
| | | |
Line 132: |
Line 63: |
| The target for this release was to dynamically "Add" a search engine plugin when Firefox loads a web page with an available search plugin, and then propagate the search engine to the top of the searchbar's menu as the current engine. The propagation of a newly added search engine as the current engine in the searchbar's menu was already a behavioral feature of Firefox 3 so there were no changes required for this part of my release target. Determining how to dynamically "Add" an available search engine plugin was challenging to achieve, but in the end, it only required a few modifications to the code in the [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js browser.js file]. | | The target for this release was to dynamically "Add" a search engine plugin when Firefox loads a web page with an available search plugin, and then propagate the search engine to the top of the searchbar's menu as the current engine. The propagation of a newly added search engine as the current engine in the searchbar's menu was already a behavioral feature of Firefox 3 so there were no changes required for this part of my release target. Determining how to dynamically "Add" an available search engine plugin was challenging to achieve, but in the end, it only required a few modifications to the code in the [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js browser.js file]. |
| | | |
| + | === '''Release Details''' === |
| | | |
− | === '''Patch File''' === | + | ==== [[Localized Search in Firefox Search Box: Release v.02]] ==== |
− | | |
− | * The modifications to the code in browser.js are shown below in a copy of the patch file for this release:
| |
− | | |
− | <pre>
| |
− | ? localsearchpatch_v02.txt
| |
− | ? nohup.out
| |
− | ? objdir-ff-debug
| |
− | Index: browser/base/content/browser.js
| |
− | ===================================================================
| |
− | RCS file: /cvsroot/mozilla/browser/base/content/browser.js,v
| |
− | retrieving revision 1.961
| |
− | diff -u -8 -p -r1.961 browser.js
| |
− | --- browser/base/content/browser.js 10 Feb 2008 06:57:05 -0000 1.961
| |
− | +++ browser/base/content/browser.js 11 Feb 2008 19:57:26 -0000
| |
− | @@ -2780,16 +2780,19 @@ const BrowserSearch = {
| |
− | // If this engine (identified by title) is already in the list, add it
| |
− | // to the list of hidden engines rather than to the main list.
| |
− | // XXX This will need to be changed when engines are identified by URL;
| |
− | // see bug 335102.
| |
− | var searchService = Cc["@mozilla.org/browser/search-service;1"].
| |
− | getService(Ci.nsIBrowserSearchService);
| |
− | if (searchService.getEngineByName(engine.title))
| |
− | hidden = true;
| |
− | + else
| |
− | + // Dynamically "Add" the web site's search engine plugin.
| |
− | + searchService.addEngine(engine.href, Components.interfaces.nsISearchEngine.DATA_XML, iconURL, false);
| |
− |
| |
− | var engines = (hidden ? browser.hiddenEngines : browser.engines) || [];
| |
− |
| |
− | engines.push({ uri: engine.href,
| |
− | title: engine.title,
| |
− | icon: iconURL });
| |
− |
| |
− | if (hidden)
| |
− | | |
− | </pre>
| |
− | | |
− | | |
− | === '''Code Modifications''' ===
| |
− | | |
− | Prior to my code modifications, the [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#2770 addEngine() function] received a reference to an anonymous JavaScript [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#2758 engine object] which was passed as a parameter to the function by the [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#2669 onLinkAdded() function] that created it. Then, addEngine() used an nsIBrowserSearchService object to determine if the search engine was already on the list of engines. The addEngine() function used the ''title'' property of the ''engine'' object to "get" an nsISearchEngine object with a corresponding ''name'' property. If the search engine was on the list, then it was considered to be a "hidden" engine and it was ''pushed'' onto the ''browser.hiddenEngines'' array. This array is used by the [http://lxr.mozilla.org/seamonkey/source/browser/components/search/content/search.xml search.xml] file to determine how to populate and display the search engines on the searchbar menu. If the search engine was not on the list, it was ''pushed'' onto the "non-hidden", ''browser.engines'' array. The search engine would then be displayed as an "Add <Search Engine>" item on the searchbar menu and the searchbar button's background color would be changed to blue after a call to the [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#2809 updateSearchButton() function].
| |
− | | |
− | My code modifications alter the original addEngine() function by adding the new search plugin if is NOT on the list. The search plugin is dynamically "Added" by calling the [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsSearchService.js#2726 addEngine() function] defined 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()]. The remainder of the code follows the normal code paths.
| |
− | | |
− | | |
− | === 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. Start-up Firefox 3 (i.e. Minefield) and go 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 v.03''' == | | == '''Release v.03''' == |
| | | |
− | The target for this release was to build upon Release v.02 by dynamically "Removing" the dynamically "Added" search engine when the user navigates away from the web site offering the search plugin. I arrived at two solutions for this release and they are discussed in the next two sub-sections. | + | The target for this release was to build upon Release v.02 by dynamically "Removing" the dynamically "Added" search engine when the user navigates away from the web site offering the search plugin if they do not choose to add the plugin to the installed engines list. |
− | | |
− | | |
− | === Release v.03.1 ===
| |
− | | |
− | The first solution, version 0.3.1, dynamically removes the search engine when the user navigates away from the site. If the user chooses to manually remove the search plugin from the list of installed engines, the search engine is then placed on the list of available engines as an "Add <Search Engine>" searchbar menu item. The user may now manually "Add" the available search engine as usual and it will not be dynamically removed from the list of installed engines on the searchbar list when the user navigates to another web site.
| |
− | | |
− | | |
− | ==== Patch File - localsearchpatch_v031.txt ====
| |
− | | |
− | <pre>
| |
− | ? localsearchpatch_v031.txt
| |
− | ? nohup.out
| |
− | ? objdir-ff-debug
| |
− | Index: browser/base/content/browser.js
| |
− | ===================================================================
| |
− | RCS file: /cvsroot/mozilla/browser/base/content/browser.js,v
| |
− | retrieving revision 1.962
| |
− | diff -u -8 -p -r1.962 browser.js
| |
− | --- browser/base/content/browser.js 13 Feb 2008 10:40:03 -0000 1.962
| |
− | +++ browser/base/content/browser.js 14 Feb 2008 20:54:15 -0000
| |
− | @@ -97,16 +97,19 @@ var gContextMenu = null;
| |
− |
| |
− | var gChromeState = null; // chrome state before we went into print preview
| |
− |
| |
− | var gSanitizeListener = null;
| |
− |
| |
− | var gAutoHideTabbarPrefListener = null;
| |
− | var gBookmarkAllTabsHandler = null;
| |
− |
| |
− | +// Global variable that holds a 'dynamically added' nsISearchEngine object.
| |
− | +var gAddedEngine = null;
| |
− | +
| |
− | #ifdef XP_MACOSX
| |
− | var gClickAndHoldTimer = null;
| |
− | #endif
| |
− |
| |
− | #ifndef XP_MACOSX
| |
− | var gEditUIVisible = true;
| |
− | #endif
| |
− |
| |
− | @@ -2780,16 +2783,19 @@ const BrowserSearch = {
| |
− | // If this engine (identified by title) is already in the list, add it
| |
− | // to the list of hidden engines rather than to the main list.
| |
− | // XXX This will need to be changed when engines are identified by URL;
| |
− | // see bug 335102.
| |
− | var searchService = Cc["@mozilla.org/browser/search-service;1"].
| |
− | getService(Ci.nsIBrowserSearchService);
| |
− | if (searchService.getEngineByName(engine.title))
| |
− | hidden = true;
| |
− | + else
| |
− | + // Dynamically "Add" the web site's search engine plugin.
| |
− | + gAddedEngine = searchService.addEngine(engine.href, Components.interfaces.nsISearchEngine.DATA_XML, iconURL, false);
| |
− |
| |
− | var engines = (hidden ? browser.hiddenEngines : browser.engines) || [];
| |
− |
| |
− | engines.push({ uri: engine.href,
| |
− | title: engine.title,
| |
− | icon: iconURL });
| |
− |
| |
− | if (hidden)
| |
− | @@ -3849,18 +3855,28 @@ nsBrowserStatusHandler.prototype =
| |
− | this.onProgressChange(gBrowser.webProgress, 0, 0, aTotalProgress, 1);
| |
− | },
| |
− |
| |
− | startDocumentLoad : function(aRequest)
| |
− | {
| |
− | // clear out feed data
| |
− | gBrowser.mCurrentBrowser.feeds = null;
| |
− |
| |
− | + var searchService = Cc["@mozilla.org/browser/search-service;1"].
| |
− | + getService(Ci.nsIBrowserSearchService);
| |
− | + // Remove the dynamically added search engine if it is on the list.
| |
− | + try {
| |
− | + if (gAddedEngine)
| |
− | + searchService.removeEngine(searchService.getEngineByName(gAddedEngine.name));
| |
− | + gAddedEngine = null;
| |
− | + } catch (e) {
| |
− | + }
| |
− | +
| |
− | // clear out search-engine data
| |
− | - gBrowser.mCurrentBrowser.engines = null;
| |
− | + gBrowser.mCurrentBrowser.engines = null;
| |
− |
| |
− | const nsIChannel = Components.interfaces.nsIChannel;
| |
− | var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec;
| |
− | var observerService = Components.classes["@mozilla.org/observer-service;1"]
| |
− | .getService(Components.interfaces.nsIObserverService);
| |
− | try {
| |
− | observerService.notifyObservers(content, "StartDocumentLoad", urlStr);
| |
− | } catch (e) {
| |
− | Index: browser/components/search/nsIBrowserSearchService.idl
| |
− | ===================================================================
| |
− | RCS file: /cvsroot/mozilla/browser/components/search/nsIBrowserSearchService.idl,v
| |
− | retrieving revision 1.20
| |
− | diff -u -8 -p -r1.20 nsIBrowserSearchService.idl
| |
− | --- browser/components/search/nsIBrowserSearchService.idl 11 Sep 2007 16:07:11 -0000 1.20
| |
− | +++ browser/components/search/nsIBrowserSearchService.idl 14 Feb 2008 20:54:15 -0000
| |
− | @@ -187,19 +187,21 @@ interface nsIBrowserSearchService : nsIS
| |
− | * @param confirm
| |
− | * A boolean value indicating whether the user should be asked for
| |
− | * confirmation before this engine is added to the list. If this
| |
− | * value is false, the engine will be added to the list upon successful
| |
− | * load, but it will not be selected as the current engine.
| |
− | *
| |
− | * @throws NS_ERROR_FAILURE if the type is invalid, or if the description
| |
− | * file cannot be successfully loaded.
| |
− | + *
| |
− | + * @returns the created engine.
| |
− | */
| |
− | - void addEngine(in AString engineURL, in long dataType, in AString iconURL,
| |
− | - in boolean confirm);
| |
− | + nsISearchEngine addEngine(in AString engineURL, in long dataType, in AString iconURL,
| |
− | + in boolean confirm);
| |
− |
| |
− | /**
| |
− | * Adds a new search engine, without asking the user for confirmation and
| |
− | * without starting to use it right away.
| |
− | *
| |
− | * @param name
| |
− | * The search engine's name. Must be unique. Must not be null.
| |
− | *
| |
− | 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 14 Feb 2008 20:54:17 -0000
| |
− | @@ -2731,16 +2731,17 @@ SearchService.prototype = {
| |
− | var engine = new Engine(uri, aDataType, false);
| |
− | engine._initFromURI();
| |
− | } catch (ex) {
| |
− | LOG("addEngine: Error adding engine:\n" + ex);
| |
− | throw Cr.NS_ERROR_FAILURE;
| |
− | }
| |
− | engine._setIcon(aIconURL, false);
| |
− | engine._confirm = aConfirm;
| |
− | + return engine;
| |
− | },
| |
− |
| |
− | removeEngine: function SRCH_SVC_removeEngine(aEngine) {
| |
− | ENSURE_ARG(aEngine, "no engine passed to removeEngine!");
| |
− |
| |
− | var engineToRemove = null;
| |
− | for (var e in this._engines)
| |
− | if (aEngine.wrappedJSObject == this._engines[e])
| |
− | </pre>
| |
− | | |
− | | |
− | ==== Code Modifications ====
| |
− | | |
− | 1. [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js browser.js]
| |
− | | |
− | * Declare a global variable named ''gAddedEngine'' to hold a dynamically "Added" '''nsISearchEngine''' object and set its initial value to be '''null'''.
| |
− | * [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#2770 addEngine() function]: If the auto-detected search plugin is NOT on the search service's list of engines, then dynamically "Add" the search engine and assign it to the ''gAddedEngine'' global variable.
| |
− | * [http://lxr.mozilla.org/seamonkey/source/browser/base/content/browser.js#3852 startDocumentLoad() function]: When the user navigates to a different web site, get an instance of '''nsIBrowserSearchService''' and assign it to the variable ''searchService''. Use a try-catch block to first check that the global variable ''gAddedEngine'' has a non-null value. Then, use the search service's [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsSearchService.js#2697 getEngineByName() function] to "get" the engine if it is on the list and use the search service's [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsSearchService.js#2741 removeEngine() function] to remove it from the list. Set the global variable ''gAddedEngine'' to '''null'''.
| |
− | | |
− | | |
− | 2. [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsIBrowserSearchService.idl nsIBrowserSearchService.idl]
| |
− | | |
− | * [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsIBrowserSearchService.idl#196 addEngine() Interface]: Change the return type of the interface from '''void''' to an '''nsISearchEngine''' object.
| |
− | | |
− | | |
− | 3. [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsSearchService.js nsSearchService.js]
| |
− | | |
− | * [http://lxr.mozilla.org/seamonkey/source/browser/components/search/nsSearchService.js#2726 addEngine() function]: Return an '''nsISearchEngine''' object.
| |
− | | |
− | | |
− | ==== 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. Start-up Firefox 3 (i.e. Minefield) and go to a [http://zenit.senecac.on.ca/wiki/index.php?title=Localized_Search_in_Firefox_Search_Box#Web_Site_List web site that offers a search engine plugin].
| |
− | | |
− | | |
− | 3. Notice that the search plugin has been dynamically loaded and added to the searchbar's list of installed engines. The newly added search engine appears as the current engine and it can be used to search the web site.
| |
− | | |
− | | |
− | 4. Navigate to a different web site that offers a search engine plugin. Observe that the search engine that was dynamically "Added" at the previous web site is no longer on the list of installed engines but the search plugin for the current web site has been dynamically loaded and it appears as the current engine for searching the site.
| |
− | | |
− | | |
− | 5. Open the Search Engine Manager's dialog and "Remove" the dynamically "Added" search engine. Notice that it is no longer on the list of installed engines and it is now listed as an "Add <Search Engine>" menu item. If you choose to "Add" the engine back to the list of installed engines, it will remain as an installed engine when you navigate to a different web site.
| |
− | | |
− | | |
− | 6. Navigate to a web site that offers a search engine plugin and then to a different site that does NOT offer a search plugin. Observe that the dynamically "Added" search engine is no longer on the list of installed engines.
| |
− | | |
− | | |
− | === Release v.03.2 ===
| |
− | | |
− | Similarly to the first solution, the second solution (version 0.3.2) dynamically removes the auto-detected search engine when the user navigates to a different web site unless the user manually adds the "Add <Search Engine>" menu item from the searchbar's list of available engines. This version also dynamically removes the dynamically "Added" search engine from the list of installed engines on the searchbar list and places it on the list of available engines as an "Add <Search Engine>" menu item when the user clicks the searchbar's button to display the engine list. At this time, the user can choose to manually "Add" the auto-detected search plugin and it will remain on the list of installed engines when the user navigates to another web site.
| |
− | | |
− | | |
− | ==== Patch File - localsearchpatch_v032.txt ====
| |
− | | |
− | <pre>
| |
− | ? localsearchpatch_v032.txt
| |
− | ? nohup.out
| |
− | ? objdir-ff-debug
| |
− | Index: browser/base/content/browser.js
| |
− | ===================================================================
| |
− | RCS file: /cvsroot/mozilla/browser/base/content/browser.js,v
| |
− | retrieving revision 1.962
| |
− | diff -u -8 -p -r1.962 browser.js
| |
− | --- browser/base/content/browser.js 13 Feb 2008 10:40:03 -0000 1.962
| |
− | +++ browser/base/content/browser.js 14 Feb 2008 20:59:15 -0000
| |
− | @@ -97,16 +97,19 @@ var gContextMenu = null;
| |
− |
| |
− | var gChromeState = null; // chrome state before we went into print preview
| |
− |
| |
− | var gSanitizeListener = null;
| |
− |
| |
− | var gAutoHideTabbarPrefListener = null;
| |
− | var gBookmarkAllTabsHandler = null;
| |
− |
| |
− | +// Global variable that holds a 'dynamically added' nsISearchEngine object.
| |
− | +var gAddedEngine = null;
| |
− | +
| |
− | #ifdef XP_MACOSX
| |
− | var gClickAndHoldTimer = null;
| |
− | #endif
| |
− |
| |
− | #ifndef XP_MACOSX
| |
− | var gEditUIVisible = true;
| |
− | #endif
| |
− |
| |
− | @@ -2780,16 +2783,19 @@ const BrowserSearch = {
| |
− | // If this engine (identified by title) is already in the list, add it
| |
− | // to the list of hidden engines rather than to the main list.
| |
− | // XXX This will need to be changed when engines are identified by URL;
| |
− | // see bug 335102.
| |
− | var searchService = Cc["@mozilla.org/browser/search-service;1"].
| |
− | getService(Ci.nsIBrowserSearchService);
| |
− | if (searchService.getEngineByName(engine.title))
| |
− | hidden = true;
| |
− | + else
| |
− | + // Dynamically "Add" the web site's search engine plugin.
| |
− | + gAddedEngine = searchService.addEngine(engine.href, Components.interfaces.nsISearchEngine.DATA_XML, iconURL, false);
| |
− |
| |
− | var engines = (hidden ? browser.hiddenEngines : browser.engines) || [];
| |
− |
| |
− | engines.push({ uri: engine.href,
| |
− | title: engine.title,
| |
− | icon: iconURL });
| |
− |
| |
− | if (hidden)
| |
− | @@ -3849,18 +3855,28 @@ nsBrowserStatusHandler.prototype =
| |
− | this.onProgressChange(gBrowser.webProgress, 0, 0, aTotalProgress, 1);
| |
− | },
| |
− |
| |
− | startDocumentLoad : function(aRequest)
| |
− | {
| |
− | // clear out feed data
| |
− | gBrowser.mCurrentBrowser.feeds = null;
| |
− |
| |
− | + var searchService = Cc["@mozilla.org/browser/search-service;1"].
| |
− | + getService(Ci.nsIBrowserSearchService);
| |
− | + // Remove the dynamically added search engine if it is on the list.
| |
− | + try {
| |
− | + if (gAddedEngine)
| |
− | + searchService.removeEngine(searchService.getEngineByName(gAddedEngine.name));
| |
− | + gAddedEngine = null;
| |
− | + } catch (e) {
| |
− | + }
| |
− | +
| |
− | // clear out search-engine data
| |
− | - gBrowser.mCurrentBrowser.engines = null;
| |
− | + gBrowser.mCurrentBrowser.engines = null;
| |
− |
| |
− | const nsIChannel = Components.interfaces.nsIChannel;
| |
− | var urlStr = aRequest.QueryInterface(nsIChannel).URI.spec;
| |
− | var observerService = Components.classes["@mozilla.org/observer-service;1"]
| |
− | .getService(Components.interfaces.nsIObserverService);
| |
− | try {
| |
− | observerService.notifyObservers(content, "StartDocumentLoad", urlStr);
| |
− | } catch (e) {
| |
− | Index: browser/components/search/nsIBrowserSearchService.idl
| |
− | ===================================================================
| |
− | RCS file: /cvsroot/mozilla/browser/components/search/nsIBrowserSearchService.idl,v
| |
− | retrieving revision 1.20
| |
− | diff -u -8 -p -r1.20 nsIBrowserSearchService.idl
| |
− | --- browser/components/search/nsIBrowserSearchService.idl 11 Sep 2007 16:07:11 -0000 1.20
| |
− | +++ browser/components/search/nsIBrowserSearchService.idl 14 Feb 2008 20:59:16 -0000
| |
− | @@ -187,19 +187,21 @@ interface nsIBrowserSearchService : nsIS
| |
− | * @param confirm
| |
− | * A boolean value indicating whether the user should be asked for
| |
− | * confirmation before this engine is added to the list. If this
| |
− | * value is false, the engine will be added to the list upon successful
| |
− | * load, but it will not be selected as the current engine.
| |
− | *
| |
− | * @throws NS_ERROR_FAILURE if the type is invalid, or if the description
| |
− | * file cannot be successfully loaded.
| |
− | + *
| |
− | + * @returns the created engine.
| |
− | */
| |
− | - void addEngine(in AString engineURL, in long dataType, in AString iconURL,
| |
− | - in boolean confirm);
| |
− | + nsISearchEngine addEngine(in AString engineURL, in long dataType, in AString iconURL,
| |
− | + in boolean confirm);
| |
− |
| |
− | /**
| |
− | * Adds a new search engine, without asking the user for confirmation and
| |
− | * without starting to use it right away.
| |
− | *
| |
− | * @param name
| |
− | * The search engine's name. Must be unique. Must not be null.
| |
− | *
| |
− | 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 14 Feb 2008 20:59:17 -0000
| |
− | @@ -2731,16 +2731,17 @@ SearchService.prototype = {
| |
− | var engine = new Engine(uri, aDataType, false);
| |
− | engine._initFromURI();
| |
− | } catch (ex) {
| |
− | LOG("addEngine: Error adding engine:\n" + ex);
| |
− | throw Cr.NS_ERROR_FAILURE;
| |
− | }
| |
− | engine._setIcon(aIconURL, false);
| |
− | engine._confirm = aConfirm;
| |
− | + return engine;
| |
− | },
| |
− |
| |
− | removeEngine: function SRCH_SVC_removeEngine(aEngine) {
| |
− | ENSURE_ARG(aEngine, "no engine passed to removeEngine!");
| |
− |
| |
− | var engineToRemove = null;
| |
− | for (var e in this._engines)
| |
− | if (aEngine.wrappedJSObject == this._engines[e])
| |
− | Index: browser/components/search/content/search.xml
| |
− | ===================================================================
| |
− | RCS file: /cvsroot/mozilla/browser/components/search/content/search.xml,v
| |
− | retrieving revision 1.120
| |
− | diff -u -8 -p -r1.120 search.xml
| |
− | --- browser/components/search/content/search.xml 6 Feb 2008 19:00:09 -0000 1.120
| |
− | +++ browser/components/search/content/search.xml 14 Feb 2008 20:59:18 -0000
| |
− | @@ -326,16 +326,26 @@
| |
− | </method>
| |
− |
| |
− | <!-- Rebuilds the dynamic portion of the popup menu (i.e., the menu items
| |
− | for new search engines that can be added to the available list). This
| |
− | is called each time the popup is shown.
| |
− | -->
| |
− | <method name="rebuildPopupDynamic">
| |
− | <body><![CDATA[
| |
− | + // Remove the dynamically added search engine if it is on the list when
| |
− | + // the popup's menu items are first displayed. The user may then choose
| |
− | + // to add the "Add <Search Engine>" item to the list of installed engines.
| |
− | + try {
| |
− | + if (gAddedEngine)
| |
− | + this.searchService.removeEngine(this.searchService.getEngineByName(gAddedEngine.name));
| |
− | + gAddedEngine = null;
| |
− | + } catch (e) {
| |
− | + }
| |
− | +
| |
− | // We might not have added the main popup items yet, do that first
| |
− | // if needed.
| |
− | if (this._needToBuildPopup)
| |
− | this.rebuildPopup();
| |
− |
| |
− | var popup = this._popup;
| |
− | // Clear any addengine menuitems, including addengine-item entries and
| |
− | // the addengine-separator. Work backward to avoid invalidating the
| |
− | </pre>
| |
− | | |
| | | |
− | == '''Release Target for v.04''' == | + | === '''Release Details''' === |
| | | |
− | * TBA
| + | ==== [[Localized Search in Firefox Search Box: Release v.03]] ==== |
− | | |
− | | |
− | == '''Release Target for v.05''' == | |
− | | |
− | * TBA
| |
− | | |
− | | |
− | == '''Release Target for v.06''' ==
| |
− | | |
− | * TBA
| |
− | | |
− | | |
− | == '''Release Target for v.07''' ==
| |
− | | |
− | * TBA
| |
− | | |
− | | |
− | == '''Release Target for v.08''' == | |
− | | |
− | * TBA
| |
− | | |
− | | |
− | == '''Release Target for v.09''' == | |
− | | |
− | * TBA
| |
− | | |
− | | |
− | == '''Release Target for v1.0''' ==
| |
− | | |
− | * TBA
| |
| | | |
| | | |
Line 654: |
Line 121: |
| | | |
| For up-to-date information about my project, visit my blog: [http://kmsingh.blogspot.com/ Kerry's Open Source Blog] | | For up-to-date information about my project, visit my blog: [http://kmsingh.blogspot.com/ Kerry's Open Source Blog] |
| + | |
| + | |
| + | '''[[#Project Name | Return to top]]''' |
| + | |
| + | |
| + | [[Category : Localized Search in Firefox Search Box]] |