Back to index

lightning-sunbird  0.9+nobinonly
nsDataHandler.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; 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 "nspr.h"
00039 #include "nsDataChannel.h"
00040 #include "nsDataHandler.h"
00041 #include "nsIURL.h"
00042 #include "nsCRT.h"
00043 #include "nsIComponentManager.h"
00044 #include "nsIServiceManager.h"
00045 #include "nsIInterfaceRequestor.h"
00046 #include "nsIInterfaceRequestorUtils.h"
00047 #include "nsIProgressEventSink.h"
00048 #include "nsNetCID.h"
00049 
00050 static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
00051 
00053 
00054 nsDataHandler::nsDataHandler() {
00055 }
00056 
00057 nsDataHandler::~nsDataHandler() {
00058 }
00059 
00060 NS_IMPL_ISUPPORTS1(nsDataHandler, nsIProtocolHandler)
00061 
00062 NS_METHOD
00063 nsDataHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) {
00064 
00065     nsDataHandler* ph = new nsDataHandler();
00066     if (ph == nsnull)
00067         return NS_ERROR_OUT_OF_MEMORY;
00068     NS_ADDREF(ph);
00069     nsresult rv = ph->QueryInterface(aIID, aResult);
00070     NS_RELEASE(ph);
00071     return rv;
00072 }
00073     
00075 // nsIProtocolHandler methods:
00076 
00077 NS_IMETHODIMP
00078 nsDataHandler::GetScheme(nsACString &result) {
00079     result.AssignLiteral("data");
00080     return NS_OK;
00081 }
00082 
00083 NS_IMETHODIMP
00084 nsDataHandler::GetDefaultPort(PRInt32 *result) {
00085     // no ports for data protocol
00086     *result = -1;
00087     return NS_OK;
00088 }
00089 
00090 NS_IMETHODIMP
00091 nsDataHandler::GetProtocolFlags(PRUint32 *result) {
00092     *result = URI_NORELATIVE | URI_NOAUTH;
00093     return NS_OK;
00094 }
00095 
00096 NS_IMETHODIMP
00097 nsDataHandler::NewURI(const nsACString &aSpec,
00098                       const char *aCharset, // ignore charset info
00099                       nsIURI *aBaseURI,
00100                       nsIURI **result) {
00101     nsresult rv;
00102 
00103     nsIURI* url;
00104     rv = CallCreateInstance(kSimpleURICID, &url);
00105     if (NS_FAILED(rv)) return rv;
00106 
00107     rv = url->SetSpec(aSpec);
00108     if (NS_FAILED(rv)) {
00109         NS_RELEASE(url);
00110         return rv;
00111     }
00112 
00113     *result = url;
00114     return rv;
00115 }
00116 
00117 NS_IMETHODIMP
00118 nsDataHandler::NewChannel(nsIURI* url, nsIChannel* *result)
00119 {
00120     NS_ENSURE_ARG_POINTER(url);
00121     nsresult rv;
00122     
00123     nsDataChannel* channel;
00124     rv = nsDataChannel::Create(nsnull, NS_GET_IID(nsIDataChannel), (void**)&channel);
00125     if (NS_FAILED(rv)) return rv;
00126 
00127     rv = channel->Init(url);
00128     if (NS_FAILED(rv)) {
00129         NS_RELEASE(channel);
00130         return rv;
00131     }
00132 
00133     *result = channel;
00134     return NS_OK;
00135 }
00136 
00137 NS_IMETHODIMP 
00138 nsDataHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval)
00139 {
00140     // don't override anything.  
00141     *_retval = PR_FALSE;
00142     return NS_OK;
00143 }