Back to index

lightning-sunbird  0.9+nobinonly
EmbedContentListener.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard.  All Rights Reserved.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Christopher Blizzard <blizzard@mozilla.org>
00023  *   Brian Edmond <briane@qnx.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include <strings.h>
00040 #include <nsXPIDLString.h>
00041 
00042 #include "nsIURI.h"
00043 
00044 #include "EmbedContentListener.h"
00045 #include "EmbedPrivate.h"
00046 
00047 #include "PtMozilla.h"
00048 
00049 #include "nsServiceManagerUtils.h"
00050 #include "nsIWebNavigationInfo.h"
00051 #include "nsDocShellCID.h"
00052 
00053 EmbedContentListener::EmbedContentListener(void)
00054 {
00055   mOwner = nsnull;
00056 }
00057 
00058 EmbedContentListener::~EmbedContentListener()
00059 {
00060 }
00061 
00062 NS_IMPL_ISUPPORTS1(EmbedContentListener,
00063                  nsIURIContentListener)
00064 
00065 nsresult
00066 EmbedContentListener::Init(EmbedPrivate *aOwner)
00067 {
00068   mOwner = aOwner;
00069   return NS_OK;
00070 }
00071 
00072 NS_IMETHODIMP
00073 EmbedContentListener::OnStartURIOpen(nsIURI     *aURI,
00074                                  PRBool     *aAbortOpen)
00075 {
00076        PtMozillaWidget_t   *moz = (PtMozillaWidget_t *) mOwner->mOwningWidget;
00077        PtCallbackList_t    *cb = NULL;
00078        PtCallbackInfo_t    cbinfo;
00079        PtMozillaUrlCb_t    url;
00080        nsCAutoString specString;
00081 
00082        if (!moz->open_cb)
00083               return NS_OK;
00084 
00085        memset(&cbinfo, 0, sizeof(cbinfo));
00086        cbinfo.cbdata = &url;
00087        cbinfo.reason = Pt_CB_MOZ_OPEN;
00088        cb = moz->open_cb;
00089 
00090        aURI->GetSpec(specString);
00091        url.url = (char *) specString.get();
00092 
00093        if (PtInvokeCallbackList(cb, (PtWidget_t *) moz, &cbinfo) == Pt_END)
00094        {
00095               *aAbortOpen = PR_TRUE;
00096               return NS_ERROR_ABORT;
00097        }
00098 
00099        *aAbortOpen = PR_FALSE;
00100 
00101        return NS_OK;
00102 }
00103 
00104 NS_IMETHODIMP
00105 EmbedContentListener::DoContent(const char         *aContentType,
00106                             PRBool             aIsContentPreferred,
00107                             nsIRequest         *aRequest,
00108                             nsIStreamListener **aContentHandler,
00109                             PRBool             *aAbortProcess)
00110 {
00111   return NS_ERROR_NOT_IMPLEMENTED;
00112 }
00113 
00114 NS_IMETHODIMP
00115 EmbedContentListener::IsPreferred(const char        *aContentType,
00116                               char             **aDesiredContentType,
00117                               PRBool            *aCanHandleContent)
00118 {
00119   return CanHandleContent(aContentType, PR_TRUE, aDesiredContentType,
00120                        aCanHandleContent);
00121 }
00122 
00123 NS_IMETHODIMP
00124 EmbedContentListener::CanHandleContent(const char        *aContentType,
00125                                    PRBool           aIsContentPreferred,
00126                                    char             **aDesiredContentType,
00127                                    PRBool            *_retval)
00128 {
00129   *_retval = PR_FALSE;
00130   *aDesiredContentType = nsnull;
00131   
00132   if (aContentType) {
00133     nsCOMPtr<nsIWebNavigationInfo> webNavInfo(
00134            do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID));
00135     if (webNavInfo) {
00136       PRUint32 canHandle;
00137       nsresult rv =
00138        webNavInfo->IsTypeSupported(nsDependentCString(aContentType),
00139                                 mOwner ? mOwner->mNavigation.get() : nsnull,
00140                                 &canHandle);
00141       NS_ENSURE_SUCCESS(rv, rv);
00142       *_retval = (canHandle != nsIWebNavigationInfo::UNSUPPORTED);
00143     }
00144   }
00145   return NS_OK;
00146 }
00147 
00148 NS_IMETHODIMP
00149 EmbedContentListener::GetLoadCookie(nsISupports **aLoadCookie)
00150 {
00151   return NS_ERROR_NOT_IMPLEMENTED;
00152 }
00153 
00154 NS_IMETHODIMP
00155 EmbedContentListener::SetLoadCookie(nsISupports *aLoadCookie)
00156 {
00157   return NS_ERROR_NOT_IMPLEMENTED;
00158 }
00159 
00160 NS_IMETHODIMP
00161 EmbedContentListener::GetParentContentListener(nsIURIContentListener **aParent)
00162 {
00163   return NS_ERROR_NOT_IMPLEMENTED;
00164 }
00165 
00166 NS_IMETHODIMP
00167 EmbedContentListener::SetParentContentListener(nsIURIContentListener *aParent)
00168 {
00169   return NS_ERROR_NOT_IMPLEMENTED;
00170 }
00171