embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,102 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: ft=cpp tw=78 sw=4 et ts=8
     1.6 + *
     1.7 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "nsWebBrowserContentPolicy.h"
    1.12 +#include "nsIDocShell.h"
    1.13 +#include "nsCOMPtr.h"
    1.14 +#include "nsContentPolicyUtils.h"
    1.15 +#include "nsIContentViewer.h"
    1.16 +
    1.17 +nsWebBrowserContentPolicy::nsWebBrowserContentPolicy()
    1.18 +{
    1.19 +    MOZ_COUNT_CTOR(nsWebBrowserContentPolicy);
    1.20 +}
    1.21 +
    1.22 +nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy()
    1.23 +{
    1.24 +    MOZ_COUNT_DTOR(nsWebBrowserContentPolicy);
    1.25 +}
    1.26 +
    1.27 +NS_IMPL_ISUPPORTS(nsWebBrowserContentPolicy, nsIContentPolicy)
    1.28 +
    1.29 +NS_IMETHODIMP
    1.30 +nsWebBrowserContentPolicy::ShouldLoad(uint32_t          contentType,
    1.31 +                                      nsIURI           *contentLocation,
    1.32 +                                      nsIURI           *requestingLocation,
    1.33 +                                      nsISupports      *requestingContext,
    1.34 +                                      const nsACString &mimeGuess,
    1.35 +                                      nsISupports      *extra,
    1.36 +                                      nsIPrincipal     *requestPrincipal,
    1.37 +                                      int16_t          *shouldLoad)
    1.38 +{
    1.39 +    NS_PRECONDITION(shouldLoad, "Null out param");
    1.40 +
    1.41 +    *shouldLoad = nsIContentPolicy::ACCEPT;
    1.42 +
    1.43 +    nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext);
    1.44 +    /* We're going to dereference shell, so make sure it isn't null */
    1.45 +    if (!shell) {
    1.46 +        return NS_OK;
    1.47 +    }
    1.48 +    
    1.49 +    nsresult rv;
    1.50 +    bool allowed = true;
    1.51 +
    1.52 +    switch (contentType) {
    1.53 +      case nsIContentPolicy::TYPE_SCRIPT:
    1.54 +        rv = shell->GetAllowJavascript(&allowed);
    1.55 +        break;
    1.56 +      case nsIContentPolicy::TYPE_SUBDOCUMENT:
    1.57 +        rv = shell->GetAllowSubframes(&allowed);
    1.58 +        break;
    1.59 +#if 0
    1.60 +      /* XXXtw: commented out in old code; add during conpol phase 2 */
    1.61 +      case nsIContentPolicy::TYPE_REFRESH:
    1.62 +        rv = shell->GetAllowMetaRedirects(&allowed); /* meta _refresh_ */
    1.63 +        break;
    1.64 +#endif
    1.65 +      case nsIContentPolicy::TYPE_IMAGE:
    1.66 +        rv = shell->GetAllowImages(&allowed);
    1.67 +        break;
    1.68 +      default:
    1.69 +        return NS_OK;
    1.70 +    }
    1.71 +
    1.72 +    if (NS_SUCCEEDED(rv) && !allowed) {
    1.73 +        *shouldLoad = nsIContentPolicy::REJECT_TYPE;
    1.74 +    }
    1.75 +    return rv;
    1.76 +}
    1.77 +
    1.78 +NS_IMETHODIMP
    1.79 +nsWebBrowserContentPolicy::ShouldProcess(uint32_t          contentType,
    1.80 +                                         nsIURI           *contentLocation,
    1.81 +                                         nsIURI           *requestingLocation,
    1.82 +                                         nsISupports      *requestingContext,
    1.83 +                                         const nsACString &mimeGuess,
    1.84 +                                         nsISupports      *extra,
    1.85 +                                         nsIPrincipal     *requestPrincipal,
    1.86 +                                         int16_t          *shouldProcess)
    1.87 +{
    1.88 +    NS_PRECONDITION(shouldProcess, "Null out param");
    1.89 +
    1.90 +    *shouldProcess = nsIContentPolicy::ACCEPT;
    1.91 +
    1.92 +    // Object tags will always open channels with TYPE_OBJECT, but may end up
    1.93 +    // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block
    1.94 +    // actual-plugins at the process stage
    1.95 +    if (contentType != nsIContentPolicy::TYPE_OBJECT) {
    1.96 +        return NS_OK;
    1.97 +    }
    1.98 +
    1.99 +    nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext);
   1.100 +    if (shell && (!shell->PluginsAllowedInCurrentDoc())) {
   1.101 +        *shouldProcess = nsIContentPolicy::REJECT_TYPE;
   1.102 +    }
   1.103 +
   1.104 +    return NS_OK;
   1.105 +}

mercurial