LCOV - app.info - content/base/src/nsNoDataProtocolContentPolicy.cpp

LCOV - code coverage report
| Current view: | directory - content/base/src - nsNoDataProtocolContentPolicy.cpp (source / functions) |  | Found | Hit | Coverage |
| Test: | app.info | Lines: | 18 | 14 | 77.8 %
| Date: | 2012-07-07 | Functions: | 5 | 4 | 80.0 %

           1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
           2                 : /* ***** BEGIN LICENSE BLOCK *****
           3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
           4                 :  *
           5                 :  * The contents of this file are subject to the Mozilla Public License Version
           6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
           7                 :  * the License. You may obtain a copy of the License at
           8                 :  * http://www.mozilla.org/MPL/
           9                 :  *
          10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
          11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
          12                 :  * for the specific language governing rights and limitations under the
          13                 :  * License.
          14                 :  *
          15                 :  * The Original Code is mozilla.org code.
          16                 :  *
          17                 :  * The Initial Developer of the Original Code is Mozilla Foundation.
          18                 :  * Portions created by the Initial Developer are Copyright (C) 2006
          19                 :  * the Initial Developer. All Rights Reserved.
          20                 :  *
          21                 :  * Contributor(s):
          22                 :  *         Jonas Sicking <jonas@sicking.cc> (Original Author)
          23                 :  *
          24                 :  * Alternatively, the contents of this file may be used under the terms of
          25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
          26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
          27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
          28                 :  * of those above. If you wish to allow use of your version of this file only
          29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
          30                 :  * use your version of this file under the terms of the MPL, indicate your
          31                 :  * decision by deleting the provisions above and replace them with the notice
          32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
          33                 :  * the provisions above, a recipient may use your version of this file under
          34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
          35                 :  *
          36                 :  * ***** END LICENSE BLOCK ***** */
          37                 :
          38                 : /*
          39                 :  * Content policy implementation that prevents all loads of images,
          40                 :  * subframes, etc from protocols that don't return data but rather open
          41                 :  * applications (such as mailto).
          42                 :  */
          43                 :
          44                 : #include "nsNoDataProtocolContentPolicy.h"
          45                 : #include "nsIDocument.h"
          46                 : #include "nsINode.h"
          47                 : #include "nsIDOMWindow.h"
          48                 : #include "nsIDOMDocument.h"
          49                 : #include "nsString.h"
          50                 : #include "nsContentUtils.h"
          51                 : #include "nsIProtocolHandler.h"
          52                 : #include "nsIIOService.h"
          53                 : #include "nsIExternalProtocolHandler.h"
          54                 : #include "nsNetUtil.h"
          55                 :
          56              36 : NS_IMPL_ISUPPORTS1(nsNoDataProtocolContentPolicy, nsIContentPolicy)
          57                 :
          58                 : NS_IMETHODIMP
          59              10 : nsNoDataProtocolContentPolicy::ShouldLoad(PRUint32 aContentType,
          60                 :                                           nsIURI *aContentLocation,
          61                 :                                           nsIURI *aRequestingLocation,
          62                 :                                           nsISupports *aRequestingContext,
          63                 :                                           const nsACString &aMimeGuess,
          64                 :                                           nsISupports *aExtra,
          65                 :                                           PRInt16 *aDecision)
          66                 : {
          67              10 :   *aDecision = nsIContentPolicy::ACCEPT;
          68                 :
          69                 :   // Don't block for TYPE_OBJECT since such URIs are sometimes loaded by the
          70                 :   // plugin, so they don't necessarily open external apps
          71                 :   // TYPE_WEBSOCKET loads can only go to ws:// or wss://, so we don't need to
          72                 :   // concern ourselves with them.
          73              10 :   if (aContentType != TYPE_DOCUMENT &&
          74                 :       aContentType != TYPE_SUBDOCUMENT &&
          75                 :       aContentType != TYPE_OBJECT &&
          76                 :       aContentType != TYPE_WEBSOCKET) {
          77                 :
          78                 :     // The following are just quick-escapes for the most common cases
          79                 :     // where we would allow the content to be loaded anyway.
          80              20 :     nsCAutoString scheme;
          81              10 :     aContentLocation->GetScheme(scheme);
          82              50 :     if (scheme.EqualsLiteral("http") ||
          83              10 :         scheme.EqualsLiteral("https") ||
          84              10 :         scheme.EqualsLiteral("ftp") ||
          85              10 :         scheme.EqualsLiteral("file") ||
          86              10 :         scheme.EqualsLiteral("chrome")) {
          87               0 :       return NS_OK;
          88                 :     }
          89                 :
          90                 :     bool shouldBlock;
          91                 :     nsresult rv = NS_URIChainHasFlags(aContentLocation,
          92                 :                                       nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA,
          93              10 :                                       &shouldBlock);
          94              10 :     if (NS_SUCCEEDED(rv) && shouldBlock) {
          95               0 :       *aDecision = nsIContentPolicy::REJECT_REQUEST;
          96                 :     }
          97                 :   }
          98                 :
          99              10 :   return NS_OK;
         100                 : }
         101                 :
         102                 : NS_IMETHODIMP
         103               0 : nsNoDataProtocolContentPolicy::ShouldProcess(PRUint32 aContentType,
         104                 :                                              nsIURI *aContentLocation,
         105                 :                                              nsIURI *aRequestingLocation,
         106                 :                                              nsISupports *aRequestingContext,
         107                 :                                              const nsACString &aMimeGuess,
         108                 :                                              nsISupports *aExtra,
         109                 :                                              PRInt16 *aDecision)
         110                 : {
         111                 :   return ShouldLoad(aContentType, aContentLocation, aRequestingLocation,
         112               0 :                     aRequestingContext, aMimeGuess, aExtra, aDecision);
         113                 : }

Generated by: LCOV version 1.7