LCOV - code coverage report
Current view: top level - toolkit/components/browser - nsWebBrowserContentPolicy.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 19 34 55.9 %
Date: 2017-07-14 16:53:18 Functions: 5 8 62.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #include "nsWebBrowserContentPolicy.h"
       8             : #include "nsIDocShell.h"
       9             : #include "nsCOMPtr.h"
      10             : #include "nsContentPolicyUtils.h"
      11             : #include "nsIContentViewer.h"
      12             : 
      13           2 : nsWebBrowserContentPolicy::nsWebBrowserContentPolicy()
      14             : {
      15           2 : }
      16             : 
      17           0 : nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy()
      18             : {
      19           0 : }
      20             : 
      21          24 : NS_IMPL_ISUPPORTS(nsWebBrowserContentPolicy, nsIContentPolicy)
      22             : 
      23             : NS_IMETHODIMP
      24          23 : nsWebBrowserContentPolicy::ShouldLoad(uint32_t aContentType,
      25             :                                       nsIURI* aContentLocation,
      26             :                                       nsIURI* aRequestingLocation,
      27             :                                       nsISupports* aRequestingContext,
      28             :                                       const nsACString& aMimeGuess,
      29             :                                       nsISupports* aExtra,
      30             :                                       nsIPrincipal* aRequestPrincipal,
      31             :                                       int16_t* aShouldLoad)
      32             : {
      33          23 :   NS_PRECONDITION(aShouldLoad, "Null out param");
      34             : 
      35          23 :   MOZ_ASSERT(aContentType == nsContentUtils::InternalContentPolicyTypeToExternal(aContentType),
      36             :              "We should only see external content policy types here.");
      37             : 
      38          23 :   *aShouldLoad = nsIContentPolicy::ACCEPT;
      39             : 
      40          23 :   nsIDocShell* shell = NS_CP_GetDocShellFromContext(aRequestingContext);
      41             :   /* We're going to dereference shell, so make sure it isn't null */
      42          23 :   if (!shell) {
      43           8 :     return NS_OK;
      44             :   }
      45             : 
      46             :   nsresult rv;
      47          15 :   bool allowed = true;
      48             : 
      49          15 :   switch (aContentType) {
      50             :     case nsIContentPolicy::TYPE_SCRIPT:
      51           8 :       rv = shell->GetAllowJavascript(&allowed);
      52           8 :       break;
      53             :     case nsIContentPolicy::TYPE_SUBDOCUMENT:
      54           0 :       rv = shell->GetAllowSubframes(&allowed);
      55           0 :       break;
      56             : #if 0
      57             :     /* XXXtw: commented out in old code; add during conpol phase 2 */
      58             :     case nsIContentPolicy::TYPE_REFRESH:
      59             :       rv = shell->GetAllowMetaRedirects(&allowed); /* meta _refresh_ */
      60             :       break;
      61             : #endif
      62             :     case nsIContentPolicy::TYPE_IMAGE:
      63             :     case nsIContentPolicy::TYPE_IMAGESET:
      64           1 :       rv = shell->GetAllowImages(&allowed);
      65           1 :       break;
      66             :     default:
      67           6 :       return NS_OK;
      68             :   }
      69             : 
      70           9 :   if (NS_SUCCEEDED(rv) && !allowed) {
      71           0 :     *aShouldLoad = nsIContentPolicy::REJECT_TYPE;
      72             :   }
      73           9 :   return rv;
      74             : }
      75             : 
      76             : NS_IMETHODIMP
      77           0 : nsWebBrowserContentPolicy::ShouldProcess(uint32_t aContentType,
      78             :                                          nsIURI* aContentLocation,
      79             :                                          nsIURI* aRequestingLocation,
      80             :                                          nsISupports* aRequestingContext,
      81             :                                          const nsACString& aMimeGuess,
      82             :                                          nsISupports* aExtra,
      83             :                                          nsIPrincipal* aRequestPrincipal,
      84             :                                          int16_t* aShouldProcess)
      85             : {
      86           0 :   NS_PRECONDITION(aShouldProcess, "Null out param");
      87             : 
      88           0 :   MOZ_ASSERT(aContentType == nsContentUtils::InternalContentPolicyTypeToExternal(aContentType),
      89             :              "We should only see external content policy types here.");
      90             : 
      91           0 :   *aShouldProcess = nsIContentPolicy::ACCEPT;
      92             : 
      93             :   // Object tags will always open channels with TYPE_OBJECT, but may end up
      94             :   // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block
      95             :   // actual-plugins at the process stage
      96           0 :   if (aContentType != nsIContentPolicy::TYPE_OBJECT) {
      97           0 :     return NS_OK;
      98             :   }
      99             : 
     100           0 :   nsIDocShell* shell = NS_CP_GetDocShellFromContext(aRequestingContext);
     101           0 :   if (shell && (!shell->PluginsAllowedInCurrentDoc())) {
     102           0 :     *aShouldProcess = nsIContentPolicy::REJECT_TYPE;
     103             :   }
     104             : 
     105           0 :   return NS_OK;
     106             : }

Generated by: LCOV version 1.13