38 Components.utils.import(
"resource://gre/modules/XPCOMUtils.jsm");
39 Components.utils.import(
"resource://app/jsmodules/sbLibraryUtils.jsm");
41 const Cc = Components.classes;
42 const Ci = Components.interfaces;
45 const JSON =
Cc[
"@mozilla.org/dom/json;1"].createInstance(
Ci.nsIJSON);
83 return JSON.decode(state);
85 Components.utils.reportError(
"Error restoring tab state: invalid JSON\n" +
96 saveTabState:
function saveTabState(aTabBrowser)
98 var
tab = aTabBrowser.mTabs[0];
105 if (tab.mediaPage.mediaListView) {
106 var view = tab.mediaPage.mediaListView;
107 var mediaList = view.mediaList;
109 listGUID: mediaList.guid,
110 libraryGUID: mediaList.library.guid,
111 pageURL: tab.linkedBrowser.currentURI.spec,
112 isOnlyView: tab.mediaPage.isOnlyView
114 if (view instanceof
Ci.sbIFilterableMediaListView) {
119 var cloneView = view.clone();
120 cloneView.cascadeFilterSet.clearAll();
122 data.constraints = [];
123 for (var
group in ArrayConverter.JSEnum(cloneView.filterConstraint.groups)) {
124 if (!(
group instanceof
Ci.sbILibraryConstraintGroup)) {
129 for (let prop in ArrayConverter.JSEnum(
group.properties)) {
130 propArray.push([prop,
131 ArrayConverter.JSArray(
group.getValues(prop))]);
133 data.constraints.push(propArray);
135 if (!data.constraints.length) {
138 delete data.constraints;
150 let
url = tab.linkedBrowser.currentURI.spec;
151 let sps =
Cc[
"@songbirdnest.com/servicepane/service;1"]
152 .getService(
Ci.sbIServicePaneService);
154 sps.getNodeForURL(url,
Ci.sbIServicePaneService.URL_MATCH_PREFIX);
164 Components.utils.reportError(e);
166 tab = tab.nextSibling;
170 selectedTabIndex: aTabBrowser.tabContainer.selectedIndex,
175 restoreTabState:
function restoreTabState(aTabBrowser)
177 var tabObject = _tabState;
179 var selectedIndex = 0, selectedTab;
181 LOG(
"restoring tab state");
186 if (tabObject &&
"urlList" in tabObject) {
188 tabs = tabObject.urlList;
189 selectedIndex = tabObject.selectedTabIndex || 0;
195 var isFirstTab =
true;
196 if ( !tabs || !tabs.length ) {
198 LOG(
"no saved tabs, first run - using defaults");
204 var loadMLInBackground =
205 Application.prefs.getValue(
"songbird.firstrun.load_ml_in_background",
212 selectedTab = aTabBrowser.loadOneTab(firstrunURL,
null,
null,
null,
213 !loadMLInBackground);
220 LOG(
"saved tabs found: " + uneval(tabs));
224 LOG(
"first launch after an update");
228 LOG(
"opening update tab");
229 aTabBrowser.loadOneTab(updateURL,
null,
null,
null,
false);
236 var chromeReg =
Cc[
'@mozilla.org/chrome/chrome-registry;1']
237 .getService(
Ci.nsIChromeRegistry);
238 var
ios =
Cc[
"@mozilla.org/network/io-service;1"]
239 .getService(
Ci.nsIIOService);
240 function isInvalidChromeURL(
url) {
250 if (uri.scheme !=
'chrome') {
255 uri = chromeReg.convertChromeURL(uri);
262 if (uri.scheme ==
'chrome') {
271 for (var
i = 0;
i < tabs.length;
i++) {
275 var
url = (tab.pageURL ? tab.pageURL :
tab);
276 if (isInvalidChromeURL(url)) {
280 if (url ==
"about:blank") {
295 if (url.indexOf(
"&bypassXULCache") == -1) {
296 url +=
"&bypassXULCache="+ Math.random();
307 var list =
LibraryUtils.getMediaListByGUID(tab.libraryGUID,
310 catch (e
if e.result == Components.results.NS_ERROR_NOT_AVAILABLE) {
315 let view =
LibraryUtils.createStandardMediaListView(list);
316 if (
"constraints" in tab) {
317 view.filterConstraint =
LibraryUtils.createConstraint(tab.constraints);
319 newTab = aTabBrowser.loadMediaList(list,
328 LOG(
"loading plain url: " + url);
330 if (aTabBrowser.mediaTab) {
335 LOG(
"this is the placeholder tab or media url");
339 LOG(<>not a media-esque tab ({firstrunURL} vs {url}: {(firstrunURL ==
url)})</>);
343 newTab = this.loadDefault(aTabBrowser);
347 LOG(
"no media tab found, just use first tab");
351 LOG(
"not first tab, always _blank");
357 if (uri.scheme ==
'chrome' && (uri.path.indexOf(
"?device-id") >= 0)) {
358 var deviceId = uri.path.match(/\?device-
id=\{([0-9a-z\-]+)\}/);
360 deviceId = deviceId[1];
362 var deviceMgr =
Cc[
"@songbirdnest.com/Songbird/DeviceManager;2"]
363 .getService(
Ci.sbIDeviceManager2);
365 deviceMgr.getDevice(Components.ID(deviceId));
367 newTab = aTabBrowser.loadURI(url,
null,
null,
null, location);
370 newTab = this.loadDefault(aTabBrowser);
375 newTab = aTabBrowser.loadURI(url,
null,
null,
null, location);
383 if (
i == selectedIndex) {
387 selectedTab = newTab;
401 Application.prefs.getValue(
"songbird.firstrun.skip_load_default_page",
404 Application.prefs.setValue(
"songbird.firstrun.skip_load_default_page",
406 this.loadDefault(aTabBrowser);
414 if (!selectedTab && aTabBrowser.mediaTab) {
415 selectedTab = aTabBrowser.mediaTab;
417 aTabBrowser.delayedSelectTab(selectedTab);
419 this.tabStateRestored =
true;
422 var selectEvent = document.createEvent(
"Events");
423 selectEvent.initEvent(
"select",
true,
true);
424 aTabBrowser.tabStrip.dispatchEvent(selectEvent);
427 loadDefault:
function(aTabBrowser) {
429 var view =
LibraryUtils.createStandardMediaListView(mainLib);
430 var constraints = [[[
"http://songbirdnest.com/data/1.0#isList",[
"0"]]],
431 [[
"http://songbirdnest.com/data/1.0#hidden",[
"0"]]],
432 [[
"http://songbirdnest.com/data/1.0#contentType",[
"audio"]]]]
433 view.filterConstraint =
LibraryUtils.createConstraint(constraints);
434 return aTabBrowser.loadMediaList(mainLib,
null,
"_media", view,
null,
false);
437 tabStateRestored:
false
__defineGetter__("_tabState", function(){var state=Application.prefs.getValue(PREF_TAB_STATE, null);if(state===null) return null;try{return JSON.decode(state);}catch(e){Components.utils.reportError("Error restoring tab state: invalid JSON\n"+state);return null;}})
const PREF_UPDATE_VERSION
Javascript wrappers for common library tasks.
__defineSetter__("_tabState", function(aValue){Application.prefs.setValue(PREF_TAB_STATE, JSON.encode(aValue));})
_getSelectedPageStyle s i
const PREF_FIRSTRUN_SESSION