Open main menu

CDOT Wiki β

Changes

Localized Search in Firefox Search Box

13,929 bytes added, 23:04, 13 February 2008
Release v.03 added
== '''Release Target for v.03''' ==
* When 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.  === 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 page with site.  ==== Patch File - localsearchpatch_v031.txt ==== <pre>? localsearchpatch_v031.txt? nohup.out? objdir-ff-debugIndex: browser/base/content/browser.js===================================================================RCS file: /cvsroot/mozilla/browser/base/content/browser.js,vretrieving revision 1.962diff -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 00:34: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 an 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,27 @@ 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 (searchService.getEngineByName(gAddedEngine.name))+ searchService.removeEngine(gAddedEngine);+ } 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,vretrieving revision 1.20diff -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 00:34: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,vretrieving revision 1.108diff -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 00:34:18 -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>  === 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 remove "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-debugIndex: browser/base/content/browser.js===================================================================RCS file: /cvsroot/mozilla/browser/base/content/browser.js,vretrieving revision 1.962diff -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 00:14:06 -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 an 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,27 @@ 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 (searchService.getEngineByName(gAddedEngine.name))+ searchService.removeEngine(gAddedEngine);+ } 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,vretrieving revision 1.20diff -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 00:14:07 -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,vretrieving revision 1.108diff -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 00:14:09 -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,vretrieving revision 1.120diff -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 00:14:09 -0000@@ -326,16 +326,23 @@ </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.+ try {+ if (this.searchService.getEngineByName(gAddedEngine.name))+ this.searchService.removeEngine(gAddedEngine);+ } 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>
1
edit