commandLine.js
Go to the documentation of this file.
1 /*
2 //
3 // BEGIN SONGBIRD GPL
4 //
5 // This file is part of the Songbird web player.
6 //
7 // Copyright(c) 2005-2008 POTI, Inc.
8 // http://songbirdnest.com
9 //
10 // This file may be licensed under the terms of of the
11 // GNU General Public License Version 2 (the "GPL").
12 //
13 // Software distributed under the License is distributed
14 // on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
15 // express or implied. See the GPL for the specific language
16 // governing rights and limitations.
17 //
18 // You should have received a copy of the GPL along with this
19 // program. If not, go to http://www.gnu.org/licenses/gpl.html
20 // or write to the Free Software Foundation, Inc.,
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 //
23 // END SONGBIRD GPL
24 //
25  */
26 
33 if (typeof(ExternalDropHandler) == "undefined")
34  Components.utils.import("resource://app/jsmodules/DropHelper.jsm");
35 
36 try
37 {
38 
39  // Module specific global for auto-init/deinit support
40  var commandline_module = {};
41  commandline_module.init_once = 0;
42  commandline_module.deinit_once = 0;
43 
44  commandline_module.onLoad = function()
45  {
46  if (commandline_module.init_once++) { dump("WARNING: commandline_module double init!!\n"); return; }
47  commandLineItemHandler.init();
48  }
49 
50  commandline_module.onUnload = function()
51  {
52  if (commandline_module.deinit_once++) { dump("WARNING: commandline_module double deinit!!\n"); return; }
53  commandLineItemHandler.shutdown();
54  window.removeEventListener("load", commandline_module.onLoad, false);
55  window.removeEventListener("unload", commandline_module.onUnload, false);
56  }
57 
58  var commandLineItemHandler = {
59  cmdline_mgr: null,
60 
61  init: function() {
62  var cmdline = Components.classes["@songbirdnest.com/commandlinehandler/general-startup;1?type=songbird"];
63  if (cmdline) {
64  var cmdline_service = cmdline.getService(Components.interfaces.nsICommandLineHandler);
65  if (cmdline_service) {
66  this.cmdline_mgr = cmdline_service.QueryInterface(Components.interfaces.sbICommandLineManager);
67  this.cmdline_mgr.addItemHandler(this);
68  }
69  }
70  },
71 
72  shutdown: function() {
73  if (this.cmdline_mgr) this.cmdline_mgr.removeItemHandler(this);
74  },
75 
76  handleItem: function(aUriSpec, aCount, aTotal) {
77  if (aUriSpec.toLowerCase().indexOf("http:") == 0 ||
78  aUriSpec.toLowerCase().indexOf("https:") == 0 ||
79  aUriSpec.toLowerCase().indexOf("ngale:") == 0)
80  {
81  if (gBrowser._sessionStore && !gBrowser._sessionStore.tabStateRestored) {
82  // process this after the session store is complete
83  // TODO: does the session store go away when it's done? be sure this doesn't break already-running behavior.
84  gBrowser.addEventListener("sessionstore-tabs-restored", function() {
85  var newTab = gBrowser.loadOneTab(aUriSpec, null, null, null, false, false);
86  gBrowser.selectedTab = newTab;
87  gBrowser.removeEventListener("sessionstore-tabs-restored", arguments.callee, false);
88  }, false);
89  }
90  else {
91  var newTab = gBrowser.loadOneTab(aUriSpec, null, null, null, false, false);
92  gBrowser.selectedTab = newTab;
93  }
94  } else {
95  var typeSniffer = Components.classes["@songbirdnest.com/Songbird/Mediacore/TypeSniffer;1"]
96  .createInstance(Components.interfaces.sbIMediacoreTypeSniffer);
97  var ioService = Components.classes["@mozilla.org/network/io-service;1"]
98  .getService(Components.interfaces.nsIIOService);
99  var aUri = ioService.newURI(aUriSpec, null, null);
100  if (typeSniffer.isValidPlaylistURL(aUri)) {
101  var list = SBOpenPlaylistURI(aUriSpec);
102  if (list) {
103  var view = LibraryUtils.createStandardMediaListView(list);
104  var mm = Components.classes["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
105  .getService(Components.interfaces.sbIMediacoreManager);
106  mm.sequencer.playView(view, 0);
107  }
108  } else {
109  var dropHandlerListener = {
110  onDropComplete: function(aTargetList,
111  aImportedInLibrary,
112  aDuplicates,
113  aInsertedInMediaList,
114  aOtherDropsHandled) {
115  // show the standard report on the status bar
116  return true;
117  },
118  onFirstMediaItem: function(aTargetList, aFirstMediaItem) {
119  var view = LibraryUtils.createStandardMediaListView(LibraryUtils.mainLibrary);
120 
121  var index = view.getIndexForItem(aFirstMediaItem);
122 
123  // If we have a browser, try to show the view
124  if (window.gBrowser) {
125  gBrowser.showIndexInView(view, index);
126  }
127 
128  // Play the item
129  var mm = Components.classes["@songbirdnest.com/Songbird/Mediacore/Manager;1"]
130  .getService(Components.interfaces.sbIMediacoreManager);
131  mm.sequencer.playView(view, index);
132  },
133  };
134  ExternalDropHandler.dropUrls(window, [aUriSpec], dropHandlerListener);
135  }
136  }
137  return true;
138  },
139 
140  QueryInterface : function(aIID) {
141  if (!aIID.equals(Components.interfaces.sbICommandLineItemHandler) &&
142  !aIID.equals(Components.interfaces.nsISupports))
143  {
144  throw Components.results.NS_ERROR_NO_INTERFACE;
145  }
146  return this;
147  }
148  };
149 
150  // Auto-init/deinit registration
151  window.addEventListener("load", commandline_module.onLoad, false);
152  window.addEventListener("unload", commandline_module.onUnload, false);
153 }
154 catch(e)
155 {
156  dump("commandLine.js - " + e + "\n");
157 }
158 
159 
sbOSDControlService prototype QueryInterface
var ioService
sbDownloadDeviceServicePaneModule prototype shutdown
let window
_window init
Definition: FeedWriter.js:1144
return null
Definition: FeedWriter.js:1143
return!aWindow arguments!aWindow arguments[0]
Javascript wrappers for common library tasks.
restoreHistoryPrecursor aCount