Back to index

lightning-sunbird  0.9+nobinonly
nsIPluginHost.idl
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "nspluginroot.idl"
00039 #include "nsIFactory.idl"
00040 #include "nsIPluginInstanceOwner.idl"
00041 #include "nsIStreamListener.idl"
00042 #include "nsIStringStream.idl"
00043 
00044 %{C++
00045 #include "nsplugindefs.h"
00046 #ifdef MOZILLA_INTERNAL_API
00047 #include "nsString.h"
00048 #include "nsNetUtil.h"
00049 #endif
00050 #include "prlink.h"  // for PRLibrary
00051 %}
00052 
00053 interface nsIPlugin;
00054 interface nsIURI;
00055 interface nsIDOMPlugin;
00056 
00057 [ptr] native PRLibraryPtr(PRLibrary);
00058 [ref] native nsIStreamListenerRef(nsIStreamListener *);
00059 
00060 [uuid(e740d8c4-fd94-456a-9506-9e044c5da27a)]
00061 interface nsIPluginHost : nsIFactory
00062 {
00063   void init();
00064 
00065   void destroy();
00066 
00067   void loadPlugins();
00068   
00069   void getPluginFactory(in string aMimeType, out nsIPlugin aPlugin);
00070 
00071   void instantiateEmbeddedPlugin(in string aMimeType, in nsIURI aURL, in nsIPluginInstanceOwner aOwner);
00072 
00073   void instantiateFullPagePlugin(in string aMimeType, in nsIURI aURI, in nsIStreamListenerRef aStreamListener, in nsIPluginInstanceOwner aOwner);
00074 
00075   void setUpPluginInstance(in string aMimeType, in nsIURI aURL, in nsIPluginInstanceOwner aOwner);
00076 
00077   void isPluginEnabledForType(in string aMimeType);
00078 
00079   void isPluginEnabledForExtension(in string aExtension, in constCharStarRef aMimeType);
00080 
00081   readonly attribute unsigned long pluginCount;
00082   
00083   [noscript] void getPlugins(in unsigned long aPluginCount, out /*array*/ nsIDOMPlugin aPluginArray);
00084 
00085   void stopPluginInstance(in nsIPluginInstance aInstance);
00086 
00087   void handleBadPlugin(in PRLibraryPtr aLibrary, in nsIPluginInstance instance);
00088 };
00089 
00090 %{C++
00091 #ifdef MOZILLA_INTERNAL_API
00092 
00102 inline nsresult
00103 NS_NewPluginPostDataStream(nsIInputStream **result,
00104                            const char *data,
00105                            PRUint32 contentLength,
00106                            PRBool isFile = PR_FALSE,
00107                            PRBool headers = PR_FALSE)
00108 {
00109   nsresult rv = NS_ERROR_UNEXPECTED;
00110   if (!data)
00111     return rv;
00112 
00113   if (!isFile) { // do raw data case first
00114     if (contentLength < 1)
00115       return rv;
00116     
00117     char *buf = (char*) data;
00118     if (headers) {
00119       // in assumption we got correctly formated headers just passed in
00120       if (!(buf = (char*)nsMemory::Alloc(contentLength)))
00121         return NS_ERROR_OUT_OF_MEMORY;
00122       memcpy(buf, data, contentLength);
00123     }
00124     nsCOMPtr<nsIStringInputStream> sis = do_CreateInstance("@mozilla.org/io/string-input-stream;1",&rv);
00125     if (NS_SUCCEEDED(rv)) {
00126       sis->AdoptData(buf, contentLength);  // let the string stream manage our data
00127       rv = CallQueryInterface(sis, result);
00128     }
00129     else if (headers)
00130       nsMemory::Free(buf); // Cleanup the memory if the data was copied.
00131   } else {
00132     nsCOMPtr<nsILocalFile> file; // tmp file will be deleted on release of stream
00133     nsCOMPtr<nsIInputStream> fileStream;
00134     if (NS_SUCCEEDED(rv = NS_NewNativeLocalFile(nsDependentCString(data), PR_FALSE, getter_AddRefs(file))) &&
00135         NS_SUCCEEDED(rv = NS_NewLocalFileInputStream(getter_AddRefs(fileStream),
00136                                      file,
00137                                      PR_RDONLY,
00138                                      0600,
00139                                      nsIFileInputStream::DELETE_ON_CLOSE |
00140                                      nsIFileInputStream::CLOSE_ON_EOF))
00141                                      ) 
00142     {
00143       // wrap the file stream with a buffered input stream
00144       return NS_NewBufferedInputStream(result, fileStream, 8192);
00145     }
00146   }
00147   return rv;
00148 }
00149 #endif
00150 %}