home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / chrome / toolkit.jar / content / global / unknownContent.js < prev    next >
Text File  |  2001-02-14  |  4KB  |  141 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is mozilla.org code.
  14.  *
  15.  * The Initial Developer of the Original Code is Netscape
  16.  * Communications Corporation.  Portions created by Netscape are
  17.  * Copyright (C) 1998 Netscape Communications Corporation. All
  18.  * Rights Reserved.
  19.  *
  20.  * Contributor(s): 
  21.  */
  22.  
  23. var data;
  24. var dialog;
  25. var bundle;
  26.  
  27. function initData() 
  28. {
  29.     // Create data object and initialize.
  30.     data = new Object;
  31.     data.channel     = window.arguments[0];
  32.     data.contentType = window.arguments[1];
  33.     data.contentDisp = window.arguments[2];
  34.  
  35.     // Get location from channel.
  36.     data.location = data.channel.URI.spec;
  37. }
  38.  
  39. function initDialog() {
  40.     // Create dialog object and initialize.
  41.     dialog = new Object;
  42.     dialog.contentType = document.getElementById("dialog.contentType");
  43.     dialog.more        = document.getElementById("dialog.more");
  44.     bundle = srGetStrBundle("chrome://global/locale/unknownContent.properties");
  45.  
  46.     var pickApp = document.getElementById("Button2");
  47.     pickApp.setAttribute( "style", "display: inherit" );
  48.     pickApp.setAttribute( "value", bundle.GetStringFromName("pick") );
  49.     var saveButton = document.getElementById("ok");
  50.     saveButton.setAttribute( "value", bundle.GetStringFromName("save") );
  51.     doSetOKCancel( save, null, pick, null );
  52. }
  53.  
  54. function loadDialog() 
  55. {
  56.   // Set initial dialog field contents.
  57.  
  58.   // Get raw content.
  59.   var text = dialog.contentType.childNodes[0].nodeValue;
  60.  
  61.   // Replace #1 with actual content type.
  62.   text = text.replace( /#1/, data.contentType );
  63.  
  64.   // Put it back into the dialog.
  65.   dialog.contentType.childNodes[0].nodeValue = text;
  66. }
  67.  
  68. function onUnload() 
  69. {
  70.   // do nothing
  71. }
  72.  
  73. function onLoad() 
  74. {
  75.     // Init data.
  76.     initData();
  77.  
  78.     // Init dialog.
  79.     initDialog();
  80.  
  81.     // Fill dialog.
  82.     loadDialog();
  83. }
  84.  
  85.  
  86. function more() 
  87. {
  88.     // Have parent browser window go to appropriate web page.
  89.     var moreInfo = "http://cgi.netscape.com/cgi-bin/plug-in_finder.cgi?";
  90.     moreInfo += data.contentType;
  91.     window.opener._content.location = moreInfo;
  92. }
  93.  
  94. function pick() 
  95. {
  96.     alert( "PickApp not implemented yet!" );
  97. }
  98.  
  99. // Parse out suggested file name from content disposition.
  100. function fileNameFromContentDisp( contentDisp ) {
  101.     // content-disposition: has format
  102.     //     disposition-type < ; filename=value >
  103.     var result = "";
  104.     try {
  105.         result = contentDisp.toString().match( /.*;\s*filename\s*=\s*(\S*)/ )[ 1 ];
  106.     } catch ( exception ) {
  107.         // ignored
  108.     }
  109.     return result;
  110.  
  111. }
  112.  
  113. function save() 
  114. {
  115.     // Use stream xfer component to prompt for destination and save.
  116.     var xfer = Components.classes[ "@mozilla.org/appshell/component/xfer;1" ].getService();
  117.     xfer = xfer.QueryInterface( Components.interfaces.nsIStreamTransfer );
  118.     var retry = false;
  119.     try {
  120.         var result = xfer.SelectFileAndTransferLocationSpec( data.location,
  121.                                                              window,
  122.                                                              data.contentType.toString(),
  123.                                                              fileNameFromContentDisp( data.contentDisp ),
  124.                                                              true,
  125.                                                              null );
  126.     } catch( exception ) {
  127.         // Failed (or cancelled), give them another chance.
  128.         retry = true;
  129.     }
  130.     // If save underway, close this dialog.
  131.     if ( !retry ) {
  132.         window.setTimeout( "window.close();", 10 );
  133.     }
  134. }
  135.  
  136. function cancel() 
  137. {
  138.     // Close this dialog.
  139.     window.close();
  140. }
  141.