home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 January / 01_02.iso / software / netscape62win / browser.xpi / bin / chrome / comm.jar / content / navigator / viewsource.js < prev    next >
Encoding:
JavaScript  |  2001-06-12  |  2.5 KB  |  87 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  * The contents of this file are subject to the Mozilla Public
  3.  * License Version 1.1 (the "License"); you may not use this file
  4.  * except in compliance with the License. You may obtain a copy of
  5.  * the License at http://www.mozilla.org/MPL/
  6.  * 
  7.  * Software distributed under the License is distributed on an "AS
  8.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  9.  * implied. See the License for the specific language governing
  10.  * rights and limitations under the License.
  11.  * 
  12.  * The Original Code is mozilla.org code.
  13.  * 
  14.  * The Initial Developer of the Original Code is Netscape
  15.  * Communications Corporation.  Portions created by Netscape are
  16.  * Copyright (C) Netscape Communications Corporation.  All
  17.  * Rights Reserved.
  18.  * 
  19.  * Contributor(s): 
  20.  *    Doron Rosenberg (doronr@naboonline.com) 
  21.  */
  22.  
  23. var gBrowser = null;
  24. var appCore = null;
  25.  
  26. function onLoadViewSource() 
  27. {
  28.   viewSource(window.arguments[0]);
  29.   window._content.focus();
  30. }
  31.  
  32. function getBrowser()
  33. {
  34.   if (!gBrowser)
  35.     gBrowser = document.getElementById("content");
  36.   return gBrowser;
  37. }
  38.  
  39. function viewSource(url)
  40. {
  41.   if (!url)
  42.     return false; // throw Components.results.NS_ERROR_FAILURE;
  43.  
  44.   try {
  45.     appCore = Components.classes["@mozilla.org/appshell/component/browser/instance;1"]
  46.                         .createInstance(Components.interfaces.nsIBrowserInstance);
  47.  
  48.     // Initialize browser instance..
  49.     appCore.setWebShellWindow(window);
  50.   } catch(ex) {
  51.     // Give up.
  52.     window.close();
  53.     return false;
  54.   }
  55.  
  56.   try {
  57.     if ("arguments" in window && window.arguments.length >= 2) {
  58.       if (window.arguments[1].indexOf('charset=') != -1) {
  59.         var arrayArgComponents = window.arguments[1].split('=');
  60.         if (arrayArgComponents) {
  61.           appCore.setDefaultCharacterSet(arrayArgComponents[1]); //XXXjag see bug 67442
  62.         } 
  63.       }
  64.     }
  65.   } catch(ex) {
  66.   }
  67.  
  68.   var loadFlags = Components.interfaces.nsIWebNavigation.LOAD_FLAGS_NONE;
  69.   var viewSrcUrl = "view-source:" + url;
  70.   getBrowser().webNavigation.loadURI(viewSrcUrl, loadFlags);
  71.   window._content.focus();
  72.   return true;
  73. }
  74.  
  75. function getMarkupDocumentViewer()
  76. {
  77.   return getBrowser().markupDocumentViewer;
  78. }
  79.  
  80. // Strips the |view-source:| for editPage()
  81. function ViewSourceEditPage()
  82. {
  83.   var url = window._content.location.href;
  84.   url = url.substring(12,url.length);
  85.   editPage(url,window, false);
  86. }
  87.