ngInternalSearchService.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN NIGHTINGALE GPL
4 //
5 // This file is part of the Nightingale web player.
6 //
7 // http://getnightingale.com
8 //
9 // This file may be licensed under the terms of of the
10 // GNU General Public License Version 2 (the "GPL").
11 //
12 // Software distributed under the License is distributed
13 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
14 // express or implied. See the GPL for the specific language
15 // governing rights and limitations.
16 //
17 // You should have received a copy of the GPL along with this
18 // program. If not, go to http://www.gnu.org/licenses/gpl.html
19 // or write to the Free Software Foundation, Inc.,
20 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 //
22 // END NIGHTINGALE GPL
23 //
24 */
25 
26 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
27 Components.utils.import("resource://app/jsmodules/DebugUtils.jsm");
28 
29 const LOG = DebugUtils.generateLogFunction("ngInternalSearchService", 2);
30 
40 {
41  XPCOMUtils.defineLazyServiceGetter(this, "searchService", "@mozilla.org/browser/search-service;1", "nsIBrowserSearchService");
42 }
43 
45  classDescription: "Nightingale Internal Search Engine Registering Serivce",
46  classID: Components.ID("{738e3a66-d7b3-4c7d-94ec-a158eb753203}"),
47  contractID: "@getnightingale.com/Nightingale/internal-search-service;1",
48  QueryInterface: XPCOMUtils.generateQI([Components.interfaces.ngIInternalSearchEnginesService]),
49 
61  registerInternalSearchEngine : function(searchEngineName, contractID, liveSearch) {
62  try {
63  Components.classes["@songbirdnest.com/Songbird/"+contractID+";1"].createInstance(Components.interfaces.sbISearchEngine);
64  }
65  catch(error) {
66  throw Components.results.NS_ERROR_ILLEGAL_VALUE;
67  }
68 
69  var engine = this.searchService.getEngineByName(searchEngineName);
70 
71  // Only continue if the engine isn't yet registered and exists
72  if(!this.internalEngines.hasOwnProperty(searchEngineName)&&engine) {
73  // default liveSearch to false
74  if(liveSearch === undefined)
75  liveSearch = false;
76 
77  this.internalEngines[searchEngineName] =
78  {'liveSearch':liveSearch,'contractID':contractID,
79  'wasHidden':engine.hidden};
80 
81  // If the engine is hidden, make it visible
82  if(engine.hidden)
83  engine.hidden = false;
84 
85  return true;
86  }
87  LOG("\n\nCouldn't register a search engine handler for \"" + searchEngineName +
88  "\".There either is already a handler for the search engine with this name or there is no engine with this name registered.\n");
89  return false;
90  },
91 
96  unregisterInternalSearchEngine :
97  function SearchHandler_unregisterInternalSearchEngine(searchEngineName) {
98  if(this.internalEngines.hasOwnProperty(searchEngineName)) {
99  // reset the hidden property to the default
100  if(this.internalEngines[searchEngineName].wasHidden)
101  this.searchService.getEngineByName(searchEngineName).hidden = false;
102 
103  delete this.internalEngines[searchEngineName];
104  }
105  LOG("\n\nThere is no internal search engine for the name \""
106  + searchEngineName + "\" registered.\n");
107  },
108 
109  getInternalSearchEngine: function(searchEngineName) {
110  if(this.internalEngines.hasOwnProperty(searchEngineName))
111  return this.internalEngines[searchEngineName];
112  return null;
113  },
114 
115  internalEngines: {}
116 };
117 
118 var NSGetModule = XPCOMUtils.generateNSGetModule([ngInternalSearchService]);
sbDeviceFirmwareAutoCheckForUpdate prototype contractID
sbOSDControlService prototype QueryInterface
sbDeviceFirmwareAutoCheckForUpdate prototype classDescription
Manager class for internal search engines.
return null
Definition: FeedWriter.js:1143
function ngInternalSearchService()
sbDeviceFirmwareAutoCheckForUpdate prototype classID