home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / mozil06.zip / bin / components / remoteControl.js < prev    next >
Text File  |  2001-02-14  |  6KB  |  153 lines

  1. /* -*- Mode: C++; tab-width: 2; 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 Communicator client code, released March
  14.  * 31, 1998.
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications
  17.  * Corporation. Portions created by Netscape are
  18.  * Copyright (C) 1998 Netscape Communications Corporation. All
  19.  * Rights Reserved.
  20.  *
  21.  * Contributor(s): 
  22.  * Seth Spitzer <sspitzer@netscape.com>
  23.  * Shane Culpepper <pepper@netscape.com>
  24.  */
  25.  
  26. var remoteControlContractID    = "@mozilla.org/browser/remote-browser-control;1";
  27.  
  28. var nsIRemoteBrowserControl = Components.interfaces.nsIRemoteBrowserControl;
  29.  
  30. function BrowserRemoteControl() {
  31.   return browserRemoteControl;
  32. }
  33.  
  34. // We need to implement nsIRemoteBrowserControl
  35.     
  36. var browserRemoteControl = {
  37.     openURL: function(aURL, newWindow)
  38.     {
  39.         dump("openURL(" + aURL + "," + newWindow + ")\n");
  40.         return;
  41.     },
  42.     
  43.     openFile: function(aURL)
  44.     {
  45.         dump("openFile(" + aURL + ")\n");
  46.         return;
  47.     },
  48.  
  49.     saveAs: function(aURL)
  50.     {
  51.         dump("saveAs(" + aURL + ")\n");
  52.         var saveAsDialog = Components.classes["@mozilla.org/xfer;1"].getService();
  53.         saveAsDialog = saveAsDialog.QueryInterface(Components.interfaces.nsIMsgComposeService);
  54.         if ( !saveAsDialog ) return(false);
  55.        
  56.         saveAsDialog.SelectFileAndTransferLocation(aURL, null); 
  57.         return(true);
  58.     },
  59.  
  60.     mailTo: function(mailToList)
  61.     {
  62.         dump("mailto(" + mailToList + ")\n");
  63.         var msgComposeService = Components.classes["@mozilla.org/messengercompose;1"].getService();
  64.         msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService);
  65.         if ( !msgComposeService ) return(false);
  66.  
  67.         if ( mailToList )
  68.         {
  69.             msgComposeService.OpenComposeWindowWithValues(null,
  70.                                                           Components.interfaces.nsIMsgCompType.New,
  71.                                                           Components.interfaces.nsIMsgCompFormat.Default,
  72.                                                           mailToList,
  73.                                                           null,
  74.                                                           null,
  75.                                                           null,
  76.                                                           null,
  77.                                                           null,
  78.                                                           null,
  79.                                                           null);
  80.         }
  81.         else
  82.         {
  83.             msgComposeService.OpenComposeWindow(null,
  84.                                                 null,
  85.                                                 Components.interfaces.nsIMsgCompType.New,
  86.                                                 Components.interfaces.nsIMsgCompFormat.Default,
  87.                                                 null);
  88.         }
  89.         return(true);
  90.     },
  91.  
  92.     addBookmark: function(aURL, aTitle)
  93.     {
  94.         dump("addBookmark(" + aURL + "," + aTitle + ")\n");
  95.         var bookmarkService = Components.classes["@mozilla.org/browser/bookmarks-service;1"].getService();
  96.         bookmarkService = bookmarkService.QueryInterface(Components.interfaces.nsIBookmarksService);
  97.         if ( !bookmarkService ) return(false);
  98.  
  99.         if ( !aURL ) return(false);
  100.         if ( aTitle )
  101.         {
  102.             bookmarkService.AddBookmark(aURL, aTitle, bookmarkService.BOOKMARK_DEFAULT_TYPE, null );
  103.         }
  104.         else
  105.         {
  106.             bookmarkService.AddBookmark(aURL, null, bookmarkService.BOOKMARK_DEFAULT_TYPE);
  107.         }
  108.         return(true);
  109.     }
  110. };
  111.  
  112. var module = {
  113.     registerSelf: function (compMgr, fileSpec, location, type) {
  114.         dump("registerSelf for remoteControl\n");
  115.         compMgr.registerComponentWithType(this.myCID,
  116.                                           "Browser Remote Control",
  117.                                           remoteControlContractID,
  118.                                           fileSpec, location, true, true, 
  119.                                           type);
  120.     },
  121.  
  122.     getClassObject: function (compMgr, cid, iid) {
  123.         if (!cid.equals(this.myCID))
  124.             throw Components.results.NS_ERROR_NO_INTERFACE;
  125.         
  126.         if (!iid.equals(Components.interfaces.nsIFactory))
  127.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  128.  
  129.         return this.myFactory;
  130.     },
  131.  
  132.     canUnload: function () {
  133.     },
  134.  
  135.     myCID: Components.ID("{97c8d0de-1dd1-11b2-bc64-86a3aaf8f5c5}"),
  136.  
  137.     myFactory: {
  138.         createInstance: function (outer, iid) {
  139.             if (outer != null)
  140.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  141.             
  142.             if (!(iid.equals(nsIRemoteBrowserControl) ||
  143.                   iid.equals(Components.interfaces.nsISupports))) {
  144.                 throw Components.results.NS_ERROR_INVALID_ARG;
  145.             }
  146.  
  147.             return new BrowserRemoteControl();
  148.         }
  149.     }
  150. };
  151.  
  152. function NSGetModule(compMgr, fileSpec) { return module; }
  153.