browserUtilities.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 
27 /************************************************************************************
28  * Firefox Browser Compatibility Functions.
29  * See http://lxr.mozilla.org/seamonkey/source/browser/base/content/utilityOverlay.js
30  ***********************************************************************************/
31 
32 /*
33  * Songbird Dependencies:
34  * gBrowser
35  * About() in playerOpen.js
36  */
37 
38 if (typeof(Ci) == "undefined")
39  var Ci = Components.interfaces;
40 if (typeof(Cc) == "undefined")
41  var Cc = Components.classes;
42 if (typeof(Cr) == "undefined")
43  var Cr = Components.results;
44 
45 var gBidiUI = false;
46 
47 function getBrowserURL()
48 {
49  throw("browserUtilities.js: : getBrowserURL() is not implemented in Songbird!");
50 }
51 
52 function goToggleToolbar( id, elementID )
53 {
54  var toolbar = document.getElementById(id);
55  var element = document.getElementById(elementID);
56  if (toolbar)
57  {
58  var isHidden = toolbar.hidden;
59  toolbar.hidden = !isHidden;
60  document.persist(id, 'hidden');
61  if (element) {
62  element.setAttribute("checked", isHidden ? "true" : "false");
63  document.persist(elementID, 'checked');
64  }
65  }
66 }
67 
68 function getTopWin()
69 {
70  var windowManager = Components.classes['@mozilla.org/appshell/window-mediator;1']
71  .getService(Components.interfaces.nsIWindowMediator);
72  return windowManager.getMostRecentWindow("Songbird:Main");
73 }
74 
75 function openTopWin( url )
76 {
77  openUILink(url, {})
78 }
79 
80 function getBoolPref ( prefname, def )
81 {
82  try {
83  var pref = Components.classes["@mozilla.org/preferences-service;1"]
84  .getService(Components.interfaces.nsIPrefBranch);
85  return pref.getBoolPref(prefname);
86  }
87  catch(er) {
88  return def;
89  }
90 }
91 
92 // Change focus for this browser window to |aElement|, without focusing the
93 // window itself.
94 function focusElement(aElement) {
95  // This is a redo of the fix for jag bug 91884
96  var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
97  .getService(Components.interfaces.nsIWindowWatcher);
98  if (window == ww.activeWindow)
99  aElement.focus();
100  else {
101  // set the element in command dispatcher so focus will restore properly
102  // when the window does become active
103  var cmdDispatcher = document.commandDispatcher;
104  if (aElement instanceof Window) {
105  cmdDispatcher.focusedWindow = aElement;
106  cmdDispatcher.focusedElement = null;
107  }
108  else if (aElement instanceof Element) {
109  cmdDispatcher.focusedWindow = aElement.ownerDocument.defaultView;
110  cmdDispatcher.focusedElement = aElement;
111  }
112  }
113 }
114 
115 // openUILink handles clicks on UI elements that cause URLs to load.
116 function openUILink( url, e, ignoreButton, ignoreAlt, allowKeywordFixup, postData, referrerUrl )
117 {
118  var where = whereToOpenLink(e, ignoreButton, ignoreAlt);
119  openUILinkIn(url, where, allowKeywordFixup, postData, referrerUrl);
120 }
121 
122 
123 /* whereToOpenLink() looks at an event to decide where to open a link.
124  *
125  * The event may be a mouse event (click, double-click, middle-click) or keypress event (enter).
126  *
127  * On Windows, the modifiers are:
128  * Ctrl new tab, selected
129  * Shift new window
130  * Ctrl+Shift new tab, in background
131  * Alt save
132  *
133  * You can swap Ctrl and Ctrl+shift by toggling the hidden pref
134  * browser.tabs.loadBookmarksInBackground (not browser.tabs.loadInBackground, which
135  * is for content area links).
136  *
137  * Middle-clicking is the same as Ctrl+clicking (it opens a new tab) and it is
138  * subject to the shift modifier and pref in the same way.
139  *
140  * Exceptions:
141  * - Alt is ignored for menu items selected using the keyboard so you don't accidentally save stuff.
142  * (Currently, the Alt isn't sent here at all for menu items, but that will change in bug 126189.)
143  * - Alt is hard to use in context menus, because pressing Alt closes the menu.
144  * - Alt can't be used on the bookmarks toolbar because Alt is used for "treat this as something draggable".
145  * - The button is ignored for the middle-click-paste-URL feature, since it's always a middle-click.
146  */
147 function whereToOpenLink( e, ignoreButton, ignoreAlt )
148 {
149  if (!e)
150  e = { shiftKey:false, ctrlKey:false, metaKey:false, altKey:false, button:0 };
151 
152  var shift = e.shiftKey;
153  var ctrl = e.ctrlKey;
154  var meta = e.metaKey;
155  var alt = e.altKey && !ignoreAlt;
156 
157  // ignoreButton allows "middle-click paste" to use function without always opening in a new window.
158  var middle = !ignoreButton && e.button == 1;
159  var middleUsesTabs = getBoolPref("browser.tabs.opentabfor.middleclick", true);
160 
161  // Don't do anything special with right-mouse clicks. They're probably clicks on context menu items.
162  var sysInfo =
163  Components.classes["@mozilla.org/system-info;1"]
164  .getService(Components.interfaces.nsIPropertyBag2);
165  var os = sysInfo.getProperty("name");
166 
167  var modifier = (os == "Darwin") ? meta : ctrl;
168  if (modifier || (middle && middleUsesTabs)) {
169  if (shift)
170  return "tabshifted";
171  else
172  return "tab";
173  }
174  else if (alt) {
175  return "save";
176  }
177  else if (shift || (middle && !middleUsesTabs)) {
178  return "window";
179  }
180  else {
181  return "current";
182  }
183 }
184 
185 /* openUILinkIn opens a URL in a place specified by the parameter |where|.
186  *
187  * |where| can be:
188  * "current" current tab (if there aren't any browser windows, then in a new window instead)
189  * "tab" new tab (if there aren't any browser windows, then in a new window instead)
190  * "tabshifted" same as "tab" but in background if default is to select new tabs, and vice versa
191  * "window" new window
192  * "save" save to disk (with no filename hint!)
193  *
194  * allowThirdPartyFixup controls whether third party services such as Google's
195  * I Feel Lucky are allowed to interpret this URL. This parameter may be
196  * undefined, which is treated as false.
197  */
198 function openUILinkIn( url, where, allowThirdPartyFixup, postData, referrerUrl )
199 {
200  if (!where || !url)
201  return;
202 
203  if (where == "save") {
204  saveURL(url, null, null, true, null, referrerUrl);
205  return;
206  }
207 
208 
209  var w = getTopWin();
210  //if (!w || where == "window") {
211  // openDialog(getBrowserURL(), "_blank", "chrome,all,dialog=no", url,
212  // null, referrerUrl, postData, allowThirdPartyFixup);
213  // return;
214  //}
215  if (where == "window") {
216  dump("browserUtilities.js.openUILinkIn() Warning: Songbird does not support where=window.\n");
217  }
218 
219 
220  var loadInBackground = getBoolPref("browser.tabs.loadBookmarksInBackground", false);
221 
222  var browser = w.gBrowser;
223 
224  // Make sure we have a browser to talk to
225  // TODO: Look for other windows?
226  if (typeof(browser) == "undefined") {
227  dump("\n\n\nbrowserUtilities.openUILinkIn() Error: no browser available!\n\n\n");
228  return;
229  }
230 
231  // Songbird defaults to tab
232  switch (where) {
233  case "current":
234  browser.loadURI(url, referrerUrl, postData, allowThirdPartyFixup);
235  break;
236  case "tabshifted":
237  loadInBackground = !loadInBackground;
238  // fall through
239  case "tab":
240  default:
241  browser.loadOneTab(url, referrerUrl, null, postData, loadInBackground,
242  allowThirdPartyFixup || false);
243  break;
244  }
245 
246  // Call focusElement(w.content) instead of w.content.focus() to make sure
247  // that we don't raise the old window, since the URI we just loaded may have
248  // resulted in a new frontmost window (e.g. "javascript:window.open('');").
249  focusElement(w.content);
250 }
251 
252 // Used as an onclick handler for UI elements with link-like behavior.
253 // e.g. onclick="checkForMiddleClick(this, event);"
255 {
256  // We should be using the disabled property here instead of the attribute,
257  // but some elements that this function is used with don't support it (e.g.
258  // menuitem).
259  if (node.getAttribute("disabled") == "true")
260  return; // Do nothing
261 
262  if (event.button == 1) {
263  /* Execute the node's oncommand.
264  *
265  * XXX: we should use node.oncommand(event) once bug 246720 is fixed.
266  */
267  var fn = new Function("event", node.getAttribute("oncommand"));
268  fn.call(node, event);
269 
270  // If the middle-click was on part of a menu, close the menu.
271  // (Menus close automatically with left-click but not with middle-click.)
272  closeMenus(event.target);
273  }
274 }
275 
276 // Closes all popups that are ancestors of the node.
277 function closeMenus(node)
278 {
279  if ("tagName" in node) {
280  if (node.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
281  && (node.tagName == "menupopup" || node.tagName == "popup"))
282  node.hidePopup();
283 
284  closeMenus(node.parentNode);
285  }
286 }
287 
288 // Gather all descendent text under given document node.
289 function gatherTextUnder ( root )
290 {
291  var text = "";
292  var node = root.firstChild;
293  var depth = 1;
294  while ( node && depth > 0 ) {
295  // See if this node is text.
296  if ( node.nodeType == Node.TEXT_NODE ) {
297  // Add this text to our collection.
298  text += " " + node.data;
299  } else if ( node instanceof HTMLImageElement) {
300  // If it has an alt= attribute, use that.
301  var altText = node.getAttribute( "alt" );
302  if ( altText && altText != "" ) {
303  text = altText;
304  break;
305  }
306  }
307  // Find next node to test.
308  // First, see if this node has children.
309  if ( node.hasChildNodes() ) {
310  // Go to first child.
311  node = node.firstChild;
312  depth++;
313  } else {
314  // No children, try next sibling.
315  if ( node.nextSibling ) {
316  node = node.nextSibling;
317  } else {
318  // Last resort is our next oldest uncle/aunt.
319  node = node.parentNode.nextSibling;
320  depth--;
321  }
322  }
323  }
324  // Strip leading whitespace.
325  text = text.replace( /^\s+/, "" );
326  // Strip trailing whitespace.
327  text = text.replace( /\s+$/, "" );
328  // Compress remaining whitespace.
329  text = text.replace( /\s+/g, " " );
330  return text;
331 }
332 
333 function getShellService()
334 {
335  var shell = null;
336  try {
337  shell = Components.classes["@mozilla.org/browser/shell-service;1"]
338  .getService(Components.interfaces.nsIShellService);
339  } catch (e) {dump("*** e = " + e + "\n");}
340  return shell;
341 }
342 
343 function isBidiEnabled() {
344  var rv = false;
345 
346  try {
347  var localeService = Components.classes["@mozilla.org/intl/nslocaleservice;1"]
348  .getService(Components.interfaces.nsILocaleService);
349  var systemLocale = localeService.getSystemLocale().getCategory("NSILOCALE_CTYPE").substr(0,3);
350 
351  switch (systemLocale) {
352  case "ar-":
353  case "he-":
354  case "fa-":
355  case "ur-":
356  case "syr":
357  rv = true;
358  }
359  } catch (e) {}
360 
361  // check the overriding pref
362  if (!rv)
363  rv = getBoolPref("bidi.browser.ui");
364 
365  return rv;
366 }
367 
368 
369 function openAboutDialog()
370 {
371  // *sigh*
372  About();
373 }
374 
375 function openPreferences(paneID)
376 {
377  SBOpenPreferences(paneID);
378 }
379 
388 {
389  throw("browserUtilities.js: openReleaseNotes() is not implemented in Songbird!");
390 }
391 
395 function checkForUpdates()
396 {
397  var um =
398  Components.classes["@mozilla.org/updates/update-manager;1"].
399  getService(Components.interfaces.nsIUpdateManager);
400  var prompter =
401  Components.classes["@mozilla.org/updates/update-prompt;1"].
402  createInstance(Components.interfaces.nsIUpdatePrompt);
403 
404  // If there's an update ready to be applied, show the "Update Downloaded"
405  // UI instead and let the user know they have to restart the browser for
406  // the changes to be applied.
407  if (um.activeUpdate && um.activeUpdate.state == "pending")
408  prompter.showUpdateDownloaded(um.activeUpdate);
409  else
410  prompter.checkForUpdates();
411 }
412 
413 function isElementVisible(aElement)
414 {
415  // * When an element is hidden, the width and height of its boxObject
416  // are set to 0
417  // * css-visibility (unlike css-display) is inherited.
418  var bo = aElement.boxObject;
419  return (bo.height != 0 && bo.width != 0 &&
420  document.defaultView
421  .getComputedStyle(aElement, null).visibility == "visible");
422 }
423 
424 function getBrowserFromContentWindow(aContentWindow)
425 {
426  var browsers = gBrowser.browsers;
427  for (var i = 0; i < browsers.length; i++) {
428  if (browsers[i].contentWindow == aContentWindow)
429  return browsers[i];
430  }
431  return null;
432 }
433 
434 
455 function openNewTabWith(aURL, aDocument, aPostData, aEvent,
456  aAllowThirdPartyFixup)
457 {
458  if (aDocument)
459  urlSecurityCheck(aURL, aDocument.nodePrincipal);
460 
461  var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
462  .getService(Components.interfaces.nsIPrefService);
463  prefSvc = prefSvc.getBranch(null);
464 
465  // should we open it in a new tab?
466  var loadInBackground = true;
467  try {
468  loadInBackground = prefSvc.getBoolPref("browser.tabs.loadInBackground");
469  }
470  catch(ex) {
471  }
472 
473  if (aEvent && aEvent.shiftKey)
474  loadInBackground = !loadInBackground;
475 
476  // TODO: Does Songbird need this?
477 
478  // As in openNewWindowWith(), we want to pass the charset of the
479  // current document over to a new tab.
480  //var wintype = document.documentElement.getAttribute("windowtype");
481  var originCharset;
482  //if (wintype == "navigator:browser")
483  // originCharset = window.content.document.characterSet;
484 
485  // open link in new tab
486  var referrerURI = aDocument ? aDocument.documentURIObject : null;
487  if (typeof(gBrowser) == "undefined") {
488  dump("\n\n\nbrowserUtilities.openNewTabWith() Error: no browser available!\n\n\n");
489  return;
490  }
491  gBrowser.loadOneTab(aURL, referrerURI, originCharset, aPostData,
492  loadInBackground, aAllowThirdPartyFixup || false);
493 }
494 
495 function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup)
496 {
497  dump("\n\n\nbrowserUtilities.openNewWindowWith() Warning: Songbird does not support new windows.\n\n\n");
498 }
499 
500 
501 // From browser.js
502 function getBrowser()
503 {
504  return window.gBrowser;
505 }
506 
507 // From browser.js
508 function loadURI(uri, referrer, postData, allowThirdPartyFixup)
509 {
510  try {
511  if (postData === undefined)
512  postData = null;
513  var flags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
514  if (allowThirdPartyFixup) {
515  flags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_ALLOW_THIRD_PARTY_FIXUP;
516  }
517  getWebNavigation().loadURI(uri, flags, referrer, postData, null);
518  } catch (e) {
519  }
520 }
521 
522 // From browser.js
524 {
525  try {
526  return gBrowser.selectedBrowser.webNavigation;
527  } catch (e) {
528  return null;
529  }
530 }
531 
532 // From browser.js
533 function toOpenWindowByType(inType, uri, features)
534 {
535  const WM_CID = "@mozilla.org/appshell/window-mediator;1";
536  const nsIWM = Components.interfaces.nsIWindowMediator;
537 
538  var windowManager = Components.classes[WM_CID].getService();
539  var windowManagerInterface = windowManager.QueryInterface(nsIWM);
540  var topWindow = windowManagerInterface.getMostRecentWindow(inType);
541  var winFeatures = features ? features : "chrome,extrachrome,menubar," +
542  "resizable,scrollbars,status," +
543  "toolbar";
544 
545  if (topWindow)
546  topWindow.focus();
547  else
548  window.open(uri, "_blank", winFeatures);
549 }
550 
551 // From browser.js
552 function BrowserForward(aEvent, aIgnoreAlt)
553 {
554  var where = whereToOpenLink(aEvent, false, aIgnoreAlt);
555 
556  if (where == "current") {
557  try {
558  getWebNavigation().goForward();
559  }
560  catch(ex) {
561  }
562  }
563  else {
564  var sessionHistory = getWebNavigation().sessionHistory;
565  var currentIndex = sessionHistory.index;
566  var entry = sessionHistory.getEntryAtIndex(currentIndex + 1, false);
567  var url = entry.URI.spec;
568  openUILinkIn(url, where);
569  }
570 }
571 
572 // From browser.js
573 function BrowserBack(aEvent, aIgnoreAlt)
574 {
575  var where = whereToOpenLink(aEvent, false, aIgnoreAlt);
576 
577  if (where == "current") {
578  try {
579  getWebNavigation().goBack();
580  }
581  catch(ex) {
582  }
583  }
584  else {
585  var sessionHistory = getWebNavigation().sessionHistory;
586  var currentIndex = sessionHistory.index;
587  var entry = sessionHistory.getEntryAtIndex(currentIndex - 1, false);
588  var url = entry.URI.spec;
589  openUILinkIn(url, where);
590  }
591 }
592 
593 // From browser.js
594 function BrowserHomeClick(aEvent)
595 {
596  if (aEvent.button == 2) // right-click: do nothing
597  return;
598 
599  var homePage = gBrowser.homePage;
600  var where = whereToOpenLink(aEvent, false, true);
601  var urls;
602 
603  // openUILinkIn in utilityOverlay.js doesn't handle loading multiple pages
604  switch (where) {
605  case "save":
606  urls = homePage.split("|");
607  saveURL(urls[0], null, null, true); // only save the first page
608  break;
609  case "current":
610  loadOneOrMoreURIs(homePage);
611  break;
612  case "tabshifted":
613  case "tab":
614  case "window": // because songbird does not support new browser windows
615  urls = homePage.split("|");
616  var loadInBackground = getBoolPref("browser.tabs.loadBookmarksInBackground", false);
617  gBrowser.loadTabs(urls, loadInBackground);
618  break;
619  /* case "window":
620  OpenBrowserWindow();
621  break; */
622  }
623 }
624 
625 // From browser.js
626 function loadOneOrMoreURIs(aURIString)
627 {
628  // This function throws for certain malformed URIs, so use exception handling
629  // so that we don't disrupt startup
630  try {
631  gBrowser.loadTabs(aURIString.split("|"), false, true);
632  }
633  catch (e) {
634  }
635 }
636 
637 
647 {
648  this.typeSniffer =
649  Components.classes["@songbirdnest.com/Songbird/Mediacore/TypeSniffer;1"]
650  .createInstance(Components.interfaces.sbIMediacoreTypeSniffer);
651  this.ios = Components.classes["@mozilla.org/network/io-service;1"]
652  .getService(Components.interfaces.nsIIOService);
653 }
654 
656 {
657  // Stored Status, Link and Loading values
658  status : "",
659  defaultStatus : "",
660  jsStatus : "",
661  jsDefaultStatus : "",
662  overLink : "",
663  statusText: "",
664  typeSniffer: null,
665  ios: null,
666 
667  QueryInterface : function(aIID)
668  {
669  if (aIID.equals(Ci.nsIWebProgressListener) ||
670  aIID.equals(Ci.nsIWebProgressListener2) ||
671  aIID.equals(Ci.nsISupportsWeakReference) ||
672  aIID.equals(Ci.nsIXULBrowserWindow) ||
673  aIID.equals(Ci.nsISupports))
674  return this;
675  throw Cr.NS_NOINTERFACE;
676  },
677 
678  setJSStatus : function(status)
679  {
680  this.jsStatus = status;
681  this.updateStatusField();
682  },
683 
684  setJSDefaultStatus : function(status)
685  {
686  this.jsDefaultStatus = status;
687  this.updateStatusField();
688  },
689 
690  setDefaultStatus : function(status)
691  {
692  this.defaultStatus = status;
693  this.updateStatusField();
694  },
695 
696  setOverLink : function(link, b)
697  {
698  // Encode bidirectional formatting characters.
699  // (RFC 3987 sections 3.2 and 4.1 paragraph 6)
700  this.overLink = link.replace(/[\u200e\u200f\u202a\u202b\u202c\u202d\u202e]/g,
702  this.updateStatusField();
703  },
704 
705  updateStatusField : function()
706  {
707  var text = this.overLink || this.status || this.jsStatus || this.jsDefaultStatus || this.defaultStatus;
708 
709  // check the current value so we don't trigger an attribute change
710  // and cause needless (slow!) UI updates
711  if (this.statusText != text) {
712  SBDataSetStringValue( "faceplate.status.text", text);
713 
714  if (this.overLink) {
715  var uri = null;
716  try {
717  uri = this.ios.newURI(this.overLink, null, null);
718  } catch (ex) {}
719 
720  if (uri && (this.typeSniffer.isValidMediaURL(uri) ||
721  this.typeSniffer.isValidPlaylistURL(uri))) {
722  SBDataSetStringValue( "faceplate.status.type", "playable");
723  } else {
724  SBDataSetStringValue( "faceplate.status.type", "normal");
725  }
726  }
727 
728  this.statusText = text;
729  }
730  }
731 }
732 
733 // initialize observers and listeners
734 // and give C++ access to gBrowser
735 window.XULBrowserWindow = new nsBrowserStatusHandler();
736 window.QueryInterface(Ci.nsIInterfaceRequestor)
737  .getInterface(Ci.nsIWebNavigation)
738  .QueryInterface(Ci.nsIDocShellTreeItem).treeOwner
739  .QueryInterface(Ci.nsIInterfaceRequestor)
740  .getInterface(Ci.nsIXULWindow)
741  .XULBrowserWindow = window.XULBrowserWindow;
742 
743 
744 function makeURLAbsolute(aBase, aUrl)
745 {
746  // Note: makeURI() will throw if aUri is not a valid URI
747  return makeURI(aUrl, null, makeURI(aBase)).spec;
748 }
749 
750 function getBrowserSelection(aCharLen) {
751  // selections of more than 150 characters aren't useful
752  const kMaxSelectionLen = 150;
753  const charLen = Math.min(aCharLen || kMaxSelectionLen, kMaxSelectionLen);
754 
755  var focusedWindow = document.commandDispatcher.focusedWindow;
756  var selection = focusedWindow.getSelection().toString();
757 
758  if (selection) {
759  if (selection.length > charLen) {
760  // only use the first charLen important chars. see bug 221361
761  var pattern = new RegExp("^(?:\\s*.){0," + charLen + "}");
762  pattern.test(selection);
763  selection = RegExp.lastMatch;
764  }
765 
766  selection = selection.replace(/^\s+/, "")
767  .replace(/\s+$/, "")
768  .replace(/\s+/g, " ");
769 
770  if (selection.length > charLen)
771  selection = selection.substr(0, charLen);
772  }
773  return selection;
774 }
775 
776 function mimeTypeIsTextBased(aMimeType)
777 {
778  return /^text\/|\+xml$/.test(aMimeType) ||
779  aMimeType == "application/x-javascript" ||
780  aMimeType == "application/javascript" ||
781  aMimeType == "application/xml" ||
782  aMimeType == "mozilla.application/cached-xul";
783 }
784 
785 function BrowserReload()
786 {
787  const reloadFlags = nsIWebNavigation.LOAD_FLAGS_NONE;
788  return BrowserReloadWithFlags(reloadFlags);
789 }
790 
792 {
793  // Bypass proxy and cache.
794  const reloadFlags = nsIWebNavigation.LOAD_FLAGS_BYPASS_PROXY | nsIWebNavigation.LOAD_FLAGS_BYPASS_CACHE;
795  return BrowserReloadWithFlags(reloadFlags);
796 }
797 
798 function BrowserReloadWithFlags(reloadFlags)
799 {
800  /* First, we'll try to use the session history object to reload so
801  * that framesets are handled properly. If we're in a special
802  * window (such as view-source) that has no session history, fall
803  * back on using the web navigation's reload method.
804  */
805 
806  var webNav = getWebNavigation();
807  try {
808  var sh = webNav.sessionHistory;
809  if (sh)
810  webNav = sh.QueryInterface(nsIWebNavigation);
811  } catch (e) {
812  }
813 
814  try {
815  webNav.reload(reloadFlags);
816  } catch (e) {
817  }
818 }
819 
820 function formatURL(aFormat, aIsPref) {
821  var formatter = Cc["@mozilla.org/toolkit/URLFormatterService;1"]
822  .getService(Ci.nsIURLFormatter);
823  return aIsPref ?
824  formatter.formatURLPref(aFormat) : formatter.formatURL(aFormat);
825 }
826 
828 {
829  evt.stopPropagation();
830  switch (evt.command) {
831  case "Back":
832  gBrowser.goBack();
833  break;
834  case "Forward":
835  gBrowser.goForward();
836  break;
837  case "Reload":
839  break;
840  case "Stop":
841  gBrowser.stop();
842  break;
843  case "Search":
844  BrowserSearch.webSearch();
845  break;
846  case "Home":
847  gBrowser.goHome();
848  break;
849  default:
850  break;
851  }
852 }
853 
869 function FillInHTMLTooltip(tipElement)
870 {
871  var retVal = false;
872  if (tipElement.namespaceURI == "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul")
873  return retVal;
874 
875  const XLinkNS = "http://www.w3.org/1999/xlink";
876 
877 
878  var titleText = null;
879  var XLinkTitleText = null;
880  var direction = tipElement.ownerDocument.dir;
881 
882  while (!titleText && !XLinkTitleText && tipElement) {
883  if (tipElement.nodeType == Node.ELEMENT_NODE) {
884  titleText = tipElement.getAttribute("title");
885  XLinkTitleText = tipElement.getAttributeNS(XLinkNS, "title");
886  var defView = tipElement.ownerDocument.defaultView;
887  // XXX Work around bug 350679:
888  // "Tooltips can be fired in documents with no view".
889  if (!defView)
890  return retVal;
891  direction = defView.getComputedStyle(tipElement, "")
892  .getPropertyValue("direction");
893  }
894  tipElement = tipElement.parentNode;
895  }
896 
897  var tipNode = document.getElementById("aHTMLTooltip");
898  tipNode.style.direction = direction;
899 
900  for each (var t in [titleText, XLinkTitleText]) {
901  if (t && /\S/.test(t)) {
902 
903  // Per HTML 4.01 6.2 (CDATA section), literal CRs and tabs should be
904  // replaced with spaces, and LFs should be removed entirely.
905  // XXX Bug 322270: We don't preserve the result of entities like &#13;,
906  // which should result in a line break in the tooltip, because we can't
907  // distinguish that from a literal character in the source by this point.
908  t = t.replace(/[\r\t]/g, ' ');
909  t = t.replace(/\n/g, '');
910 
911  tipNode.setAttribute("label", t);
912  retVal = true;
913  }
914  }
915 
916  return retVal;
917 }
918 
921 
923  window.removeEventListener("load", onInitBrowserUtilities, false);
924  window.addEventListener("unload", onShutdownBrowserUtilities, false);
925  gNavigatorBundle = document.getElementById("bundle_browser");
926  var gPrefService = Components.classes["@mozilla.org/preferences-service;1"]
927  .getService(Components.interfaces.nsIPrefBranch2);
928  gBidiUI = isBidiEnabled();
929 
930  window.addEventListener("AppCommand", HandleAppCommandEvent, true);
931 }
932 
934  window.removeEventListener("unload", onShutdownBrowserUtilities, false);
935  window.removeEventListener("AppCommand", HandleAppCommandEvent, true);
936 }
937 
938 window.addEventListener("load", onInitBrowserUtilities, false);
939 
940 // Function from Mozilla's browser.js. Accel + #1 through 8 will send it to
941 // that tab. Accel + 9 always sends it to the last tab.
943  if (index == 8) {
944  index = gBrowser.tabContainer.childNodes.length - 1;
945  } else if (index >= gBrowser.tabContainer.childNodes.length) {
946  return;
947  }
948 
949  var oldTab = gBrowser.selectedTab;
950  var newTab = gBrowser.tabContainer.childNodes[index];
951  if (newTab != oldTab) {
952  gBrowser.selectedTab = newTab;
953  }
954 
955  event.preventDefault();
956  event.stopPropagation();
957 }
958 
960 {
961  switch (Application.prefs.getValue("browser.backspace_action", 2)) {
962  case 0:
963  gBrowser.goBack();
964  break;
965  case 1:
966  goDoCommand("cmd_scrollPageUp");
967  break;
968  }
969 }
970 
972 {
973  switch (Application.prefs.getValue("browser.backspace_action", 2)) {
974  case 0:
975  gBrowser.goForward();
976  break;
977  case 1:
978  goDoCommand("cmd_scrollPageDown");
979  break;
980  }
981 }
982 
function BrowserHomeClick(aEvent)
classDescription entry
Definition: FeedWriter.js:1427
let prefSvc
function closeMenus(node)
const Cc
function checkForUpdates()
function getBrowserSelection(aCharLen)
var gPrefService
function FillInHTMLTooltip(tipElement)
nsString encodeURIComponent(const nsString &c)
function BrowserReload()
var Application
Definition: sbAboutDRM.js:37
var pref
Definition: openLocation.js:44
window QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIWebNavigation).QueryInterface(Ci.nsIDocShellTreeItem).treeOwner.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIXULWindow).XULBrowserWindow
function BrowserReloadSkipCache()
function getBoolPref(prefname, def)
function gatherTextUnder(root)
function getWebNavigation()
sbDeviceFirmwareAutoCheckForUpdate prototype flags
function mimeTypeIsTextBased(aMimeType)
function BrowserBack(aEvent, aIgnoreAlt)
function isBidiEnabled()
function BrowserHandleShiftBackspace()
var event
function HandleAppCommandEvent(evt)
function getBrowser()
function makeURLAbsolute(aBase, aUrl)
function openAboutDialog()
var Element
sidebarFactory createInstance
Definition: nsSidebar.js:351
function loadURI(uri, referrer, postData, allowThirdPartyFixup)
getService(Ci.sbIFaceplateManager)
let window
function BrowserNumberTabSelection(event, index)
var t
function loadOneOrMoreURIs(aURIString)
_collectFormDataForFrame aDocument
var gBidiUI
const nsIWebNavigation
Definition: browser.js:71
function makeURI(aURLSpec, aCharset)
Definition: FeedWriter.js:71
function openUILink(url, e, ignoreButton, ignoreAlt, allowKeywordFixup, postData, referrerUrl)
return e ctrlKey(chr<' '||!chars||chars.indexOf(chr)>-1)
function formatURL(aFormat, aIsPref)
function onInitBrowserUtilities()
function BrowserForward(aEvent, aIgnoreAlt)
function getBrowserURL()
function openPreferences(paneID)
function BrowserReloadWithFlags(reloadFlags)
function checkForMiddleClick(node, event)
var Window
return null
Definition: FeedWriter.js:1143
function onShutdownBrowserUtilities()
function openReleaseNotes(event)
let node
var os
function BrowserHandleBackspace()
var uri
Definition: FeedWriter.js:1135
function url(spec)
const XLinkNS
Definition: pageInfo.js:219
function openNewWindowWith(aURL, aDocument, aPostData, aAllowThirdPartyFixup)
const Cr
function openTopWin(url)
function goToggleToolbar(id, elementID)
const Ci
var gNavigatorBundle
function openNewTabWith(aURL, aDocument, aPostData, aEvent, aAllowThirdPartyFixup)
function getBrowserFromContentWindow(aContentWindow)
var ios
Definition: head_feeds.js:5
function getTopWin()
function nsBrowserStatusHandler()
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.
function openUILinkIn(url, where, allowThirdPartyFixup, postData, referrerUrl)
var browser
Definition: openLocation.js:42
function getShellService()
function isElementVisible(aElement)
jQuery fn
_getSelectedPageStyle s i
function whereToOpenLink(e, ignoreButton, ignoreAlt)
function focusElement(aElement)
function toOpenWindowByType(inType, uri, features)