SBTabProgressListener.js
Go to the documentation of this file.
1 // vim: set sw=2 :miv
2 /*
3  *=BEGIN SONGBIRD GPL
4  *
5  * This file is part of the Songbird web player.
6  *
7  * Copyright(c) 2005-2010 POTI, Inc.
8  * http://www.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 
36 const EXPORTED_SYMBOLS = ["SBTabProgressListener"];
37 
38 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
39 
40 const Cc = Components.classes;
41 const Ci = Components.interfaces;
42 
43 function SBTabProgressListener(aTabBrowser ) {
44  this._tabBrowser = aTabBrowser;
45 }
46 
47 // create an object which implements as much of nsIWebProgressListener as we're using
48 SBTabProgressListener.prototype = {
49  _tabBrowser: null,
50 
51  onLocationChange: function SBTabProgressListener_onLocationChange(aWebProgress, aRequest, aLocation) {
52  try {
53  // for some reason we need to do this dance to get scrollbars to
54  // show up
55  const nsIScrollable = Ci.nsIScrollable;
56  var scrollable = this._tabBrowser
57  .selectedBrowser
58  .webNavigation
59  .QueryInterface(nsIScrollable);
60  scrollable.setDefaultScrollbarPreferences(nsIScrollable.ScrollOrientation_Y,
61  nsIScrollable.Scrollbar_Auto);
62  scrollable.setDefaultScrollbarPreferences(nsIScrollable.ScrollOrientation_X,
63  nsIScrollable.Scrollbar_Auto);
64 
65  if (this._tabBrowser.selectedBrowser.webNavigation.sessionHistory) {
66  SBDataSetBoolValue('browser.cangoback', this._tabBrowser.canGoBack);
67  SBDataSetBoolValue('browser.cangofwd', this._tabBrowser.canGoForward);
68  }
69 
70  // Nothing in the status text
71  SBDataSetStringValue( "faceplate.status.text", "");
72 
73  if (!aLocation) {
74  // If we do not have a location, make a new uri that points to
75  // about:blank. Do not assign a simple string, or subsequent usage
76  // of .scheme and .spec will fail
77  var ioService =
78  Components.classes["@mozilla.org/network/io-service;1"]
79  .getService(Components.interfaces.nsIIOService);
80 
81  aLocation = ioService.newURI("about:blank", null, null);
82  }
83 
84  SBDataSetBoolValue('browser.cansubscription',
85  this._tabBrowser.selectedTab.outerPlaylistShowing);
86 
87  var mediaTab = this._tabBrowser.mediaTab;
88  SBDataSetBoolValue("browser.in_media_page",
89  mediaTab && this._tabBrowser.selectedTab == mediaTab);
90 
91  // Let listeners know that the tab location has changed
92  this._tabBrowser.notifyTabContentChange();
93 
94  // If we're in the media tab, NOT a media list view, and the corresponding
95  // service pane node does not set searchtype property (means search bar
96  // should be available), then we're some sort of arbitrary XUL page,
97  // so hide the #nav-bar.
98  var node = null;
99  if (gServicePane) {
100  // Get the current active node.
101  node = gServicePane.activeNode;
102  }
103 
104  if (this._tabBrowser.selectedTab == mediaTab &&
105  !this._tabBrowser.currentMediaListView &&
106  (!node || node.searchtype.indexOf("internal") > -1) &&
107  (!node || node.searchtype.indexOf("external") == -1))
108  {
109  document.getElementById("nav-bar").setAttribute("collapsed", "true");
110  } else {
111  document.getElementById("nav-bar").removeAttribute("collapsed");
112  }
113 
114  // Set visibility for media page container
115  if (this._tabBrowser.selectedTab == mediaTab &&
116  this._tabBrowser.currentMediaListView)
117  {
118  document.getElementById("mediapages-container")
119  .removeAttribute("collapsed");
120  } else {
121  document.getElementById("mediapages-container")
122  .setAttribute("collapsed", "true");
123  }
124 
125  if (node) {
126  var className = node.className;
127 
128  // Set visibility for back forward buttons
129  var historyButtons = document.getElementById("back-forward-buttons");
130  if (className.indexOf("history") > -1) {
131  historyButtons.setAttribute("isCollapse", "false");
132  } else {
133  historyButtons.removeAttribute("isCollapse");
134  }
135 
136  // Set the visibility for the search box as needed.
137  var searchBox = document.getElementById("searchbar-container");
138  if (className.indexOf("nosearchbox") > -1) {
139  searchBox.setAttribute("isCollapse", "true");
140  } else {
141  searchBox.removeAttribute("isCollapse");
142  }
143 
144  // Set visibility for stop/reload button
145  var stopreloadButton = document.getElementById("stopreload-container");
146  if (className.indexOf("stopreload") > -1) {
147  stopreloadButton.setAttribute("isCollapse", "false");
148  } else {
149  stopreloadButton.removeAttribute("isCollapse");
150  }
151  }
152  }
153  catch ( err )
154  {
155  Components.utils.reportError( "SBTabProgressListener::onLocationChange\n\n" + err );
156  }
157  },
158 
159  onStateChange: function SBTabProgressListener_onStateChange(aWebProgress, aRequest, aState, aStatus) {
160  const nsIWebProgressListener =
161  Ci.nsIWebProgressListener;
162 
163  // if this state change isn't on the top-level window, ignore it
164  if (aWebProgress.DOMWindow != aWebProgress.DOMWindow.parent ||
165  !(aState & nsIWebProgressListener.STATE_IS_WINDOW)) {
166  return;
167  }
168 
169  if (aState & nsIWebProgressListener.STATE_START) {
170  // Start the spinner if necessary
171  this._tabBrowser.loading = true;
172  }
173  else if (aState & nsIWebProgressListener.STATE_STOP) {
174  // Stop the spinner if necessary
175  this._tabBrowser.loading = false;
176 
177  // Let listeners know that the tab has finished loading
178  // but only if aStatus == 0, an nsresult representing whether the request
179  // finished or was cancelled...
180  // or aStatus == NS_ERROR_PARSED_DATA_CACHED, an nsresult representing
181  // when the data from a channel has already been parsed and cached
182  const NS_ERROR_PARSED_DATA_CACHED = 0x805D0021;
183  if (Components.isSuccessCode(aStatus) ||
184  aStatus == NS_ERROR_PARSED_DATA_CACHED)
185  {
186  this._tabBrowser.notifyTabContentChange();
187  }
188 
189  // Save the tab state after every page load, just in case we crash
190  if ("_sessionStore" in this._tabBrowser) {
191  if (this._tabBrowser._sessionStore.tabStateRestored) {
192  this._tabBrowser._sessionStore.saveTabState(this._tabBrowser);
193  }
194  }
195  }
196  },
197 
198 
199  /* these are not called; refer to the sb-tabbrowser constructor where it's registered */
200  onProgressChange: function() { /* do nothing */ },
201  onStatusChange: function() { /* do nothing */ },
202  onSecurityChange: function() { /* do nothing */ },
203  QueryInterface : XPCOMUtils.generateQI([Ci.nsIWebProgressListener])
204 };
sbOSDControlService prototype className
const Cc
sbOSDControlService prototype QueryInterface
function SBTabProgressListener(aTabBrowser)
var ioService
function SBDataSetBoolValue(aKey, aBoolValue)
Set a boolean value. Changes the value of the data remote to the boolean passed in, regardless of its value before.
const EXPORTED_SYMBOLS
return null
Definition: FeedWriter.js:1143
let node
const Ci
ContinuingWebProgressListener prototype onStateChange
var gServicePane
Definition: mainWinInit.js:39
function SBDataSetStringValue(aKey, aStringValue)
Set a string value. Changes the value of the data remote to the boolean passed in, regardless of its value before.
restoreWindow aState