Back to index

lightning-sunbird  0.9+nobinonly
nsWebBrowserContentPolicy.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  * vim: ft=cpp tw=78 sw=4 et ts=8
00003  *
00004  * ***** BEGIN LICENSE BLOCK *****
00005  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00006  *
00007  * The contents of this file are subject to the Mozilla Public License Version
00008  * 1.1 (the "License"); you may not use this file except in compliance with
00009  * the License. You may obtain a copy of the License at
00010  * http://www.mozilla.org/MPL/
00011  *
00012  * Software distributed under the License is distributed on an "AS IS" basis,
00013  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00014  * for the specific language governing rights and limitations under the
00015  * License.
00016  *
00017  * The Original Code is embedding content-control code.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Mike Shaver.
00021  * Portions created by the Initial Developer are Copyright (C) 2001
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsWebBrowserContentPolicy.h"
00041 #include "nsIScriptGlobalObject.h"
00042 #include "nsIDocShell.h"
00043 #include "nsCOMPtr.h"
00044 #include "nsContentPolicyUtils.h"
00045 
00046 nsWebBrowserContentPolicy::nsWebBrowserContentPolicy()
00047 {
00048     MOZ_COUNT_CTOR(nsWebBrowserContentPolicy);
00049 }
00050 
00051 nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy()
00052 {
00053     MOZ_COUNT_DTOR(nsWebBrowserContentPolicy);
00054 }
00055 
00056 NS_IMPL_ISUPPORTS1(nsWebBrowserContentPolicy, nsIContentPolicy)
00057 
00058 static nsresult
00059 PerformPolicyCheck(PRUint32     contentType,
00060                    nsISupports *requestingContext,
00061                    PRInt16     *decision)
00062 {
00063     NS_PRECONDITION(decision, "Null out param");
00064 
00065     *decision = nsIContentPolicy::ACCEPT;
00066 
00067     nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext);
00068     /* We're going to dereference shell, so make sure it isn't null */
00069     if (!shell)
00070         return NS_OK;
00071 
00072     nsresult rv;
00073     PRBool allowed = PR_TRUE;
00074 
00075     switch (contentType) {
00076       case nsIContentPolicy::TYPE_OBJECT:
00077         rv = shell->GetAllowPlugins(&allowed);
00078         break;
00079       case nsIContentPolicy::TYPE_SCRIPT:
00080         rv = shell->GetAllowJavascript(&allowed);
00081         break;
00082       case nsIContentPolicy::TYPE_SUBDOCUMENT:
00083         rv = shell->GetAllowSubframes(&allowed);
00084         break;
00085 #if 0
00086       /* XXXtw: commented out in old code; add during conpol phase 2 */
00087       case nsIContentPolicy::TYPE_REFRESH:
00088         rv = shell->GetAllowMetaRedirects(&allowed); /* meta _refresh_ */
00089         break;
00090 #endif
00091       case nsIContentPolicy::TYPE_IMAGE:
00092         rv = shell->GetAllowImages(&allowed);
00093         break;
00094       default:
00095         return NS_OK;
00096     }
00097 
00098     if (NS_SUCCEEDED(rv) && !allowed) {
00099         *decision = nsIContentPolicy::REJECT_TYPE;
00100     }
00101     return rv;
00102 }
00103 
00104 NS_IMETHODIMP
00105 nsWebBrowserContentPolicy::ShouldLoad(PRUint32          contentType,
00106                                       nsIURI           *contentLocation,
00107                                       nsIURI           *requestingLocation,
00108                                       nsISupports      *requestingContext,
00109                                       const nsACString &mimeGuess,
00110                                       nsISupports      *extra,
00111                                       PRInt16          *shouldLoad)
00112 {
00113     return PerformPolicyCheck(contentType, requestingContext, shouldLoad);
00114 }
00115 
00116 NS_IMETHODIMP
00117 nsWebBrowserContentPolicy::ShouldProcess(PRUint32          contentType,
00118                                          nsIURI           *contentLocation,
00119                                          nsIURI           *requestingLocation,
00120                                          nsISupports      *requestingContext,
00121                                          const nsACString &mimeGuess,
00122                                          nsISupports      *extra,
00123                                          PRInt16          *shouldProcess)
00124 {
00125     *shouldProcess = nsIContentPolicy::ACCEPT;
00126     return NS_OK;
00127     //LATER:
00128     //  return PerformPolicyCheck(contentType, requestingContext, shouldProcess);
00129 }