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  *
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 <strings.h>
00039 #include <nsXPIDLString.h>
00040 
00041 #include "nsIURI.h"
00042 
00043 #include "EmbedContentListener.h"
00044 #include "EmbedPrivate.h"
00045 
00046 #include "nsServiceManagerUtils.h"
00047 #include "nsIWebNavigationInfo.h"
00048 #include "nsDocShellCID.h"
00049 
00050 EmbedContentListener::EmbedContentListener(void)
00051 {
00052   mOwner = nsnull;
00053 }
00054 
00055 EmbedContentListener::~EmbedContentListener()
00056 {
00057 }
00058 
00059 NS_IMPL_ISUPPORTS2(EmbedContentListener,
00060                    nsIURIContentListener,
00061                    nsISupportsWeakReference)
00062 
00063 nsresult
00064 EmbedContentListener::Init(EmbedPrivate *aOwner)
00065 {
00066   mOwner = aOwner;
00067   return NS_OK;
00068 }
00069 
00070 NS_IMETHODIMP
00071 EmbedContentListener::OnStartURIOpen(nsIURI     *aURI,
00072                                  PRBool     *aAbortOpen)
00073 {
00074   nsresult rv;
00075 
00076   nsCAutoString specString;
00077   rv = aURI->GetSpec(specString);
00078 
00079   if (NS_FAILED(rv))
00080     return rv;
00081 
00082   gint return_val = FALSE;
00083   gtk_signal_emit(GTK_OBJECT(mOwner->mOwningWidget),
00084                 moz_embed_signals[OPEN_URI],
00085                 specString.get(), &return_val);
00086 
00087   *aAbortOpen = return_val;
00088 
00089   return NS_OK;
00090 }
00091 
00092 NS_IMETHODIMP
00093 EmbedContentListener::DoContent(const char         *aContentType,
00094                             PRBool             aIsContentPreferred,
00095                             nsIRequest         *aRequest,
00096                             nsIStreamListener **aContentHandler,
00097                             PRBool             *aAbortProcess)
00098 {
00099   return NS_ERROR_NOT_IMPLEMENTED;
00100 }
00101 
00102 NS_IMETHODIMP
00103 EmbedContentListener::IsPreferred(const char        *aContentType,
00104                               char             **aDesiredContentType,
00105                               PRBool            *aCanHandleContent)
00106 {
00107   return CanHandleContent(aContentType, PR_TRUE, aDesiredContentType,
00108                        aCanHandleContent);
00109 }
00110 
00111 NS_IMETHODIMP
00112 EmbedContentListener::CanHandleContent(const char        *aContentType,
00113                                    PRBool           aIsContentPreferred,
00114                                    char             **aDesiredContentType,
00115                                    PRBool            *_retval)
00116 {
00117   *_retval = PR_FALSE;
00118   *aDesiredContentType = nsnull;
00119   
00120   if (aContentType) {
00121     nsCOMPtr<nsIWebNavigationInfo> webNavInfo(
00122            do_GetService(NS_WEBNAVIGATION_INFO_CONTRACTID));
00123     if (webNavInfo) {
00124       PRUint32 canHandle;
00125       nsresult rv =
00126        webNavInfo->IsTypeSupported(nsDependentCString(aContentType),
00127                                 mOwner ? mOwner->mNavigation.get() : nsnull,
00128                                 &canHandle);
00129       NS_ENSURE_SUCCESS(rv, rv);
00130       *_retval = (canHandle != nsIWebNavigationInfo::UNSUPPORTED);
00131     }
00132   }
00133   return NS_OK;
00134 }
00135 
00136 NS_IMETHODIMP
00137 EmbedContentListener::GetLoadCookie(nsISupports **aLoadCookie)
00138 {
00139   return NS_ERROR_NOT_IMPLEMENTED;
00140 }
00141 
00142 NS_IMETHODIMP
00143 EmbedContentListener::SetLoadCookie(nsISupports *aLoadCookie)
00144 {
00145   return NS_ERROR_NOT_IMPLEMENTED;
00146 }
00147 
00148 NS_IMETHODIMP
00149 EmbedContentListener::GetParentContentListener(nsIURIContentListener **aParent)
00150 {
00151   return NS_ERROR_NOT_IMPLEMENTED;
00152 }
00153 
00154 NS_IMETHODIMP
00155 EmbedContentListener::SetParentContentListener(nsIURIContentListener *aParent)
00156 {
00157   return NS_ERROR_NOT_IMPLEMENTED;
00158 }
00159