embedding/browser/webBrowser/nsWebBrowserContentPolicy.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

     1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     2  * vim: ft=cpp tw=78 sw=4 et ts=8
     3  *
     4  * This Source Code Form is subject to the terms of the Mozilla Public
     5  * License, v. 2.0. If a copy of the MPL was not distributed with this
     6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     8 #include "nsWebBrowserContentPolicy.h"
     9 #include "nsIDocShell.h"
    10 #include "nsCOMPtr.h"
    11 #include "nsContentPolicyUtils.h"
    12 #include "nsIContentViewer.h"
    14 nsWebBrowserContentPolicy::nsWebBrowserContentPolicy()
    15 {
    16     MOZ_COUNT_CTOR(nsWebBrowserContentPolicy);
    17 }
    19 nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy()
    20 {
    21     MOZ_COUNT_DTOR(nsWebBrowserContentPolicy);
    22 }
    24 NS_IMPL_ISUPPORTS(nsWebBrowserContentPolicy, nsIContentPolicy)
    26 NS_IMETHODIMP
    27 nsWebBrowserContentPolicy::ShouldLoad(uint32_t          contentType,
    28                                       nsIURI           *contentLocation,
    29                                       nsIURI           *requestingLocation,
    30                                       nsISupports      *requestingContext,
    31                                       const nsACString &mimeGuess,
    32                                       nsISupports      *extra,
    33                                       nsIPrincipal     *requestPrincipal,
    34                                       int16_t          *shouldLoad)
    35 {
    36     NS_PRECONDITION(shouldLoad, "Null out param");
    38     *shouldLoad = nsIContentPolicy::ACCEPT;
    40     nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext);
    41     /* We're going to dereference shell, so make sure it isn't null */
    42     if (!shell) {
    43         return NS_OK;
    44     }
    46     nsresult rv;
    47     bool allowed = true;
    49     switch (contentType) {
    50       case nsIContentPolicy::TYPE_SCRIPT:
    51         rv = shell->GetAllowJavascript(&allowed);
    52         break;
    53       case nsIContentPolicy::TYPE_SUBDOCUMENT:
    54         rv = shell->GetAllowSubframes(&allowed);
    55         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         rv = shell->GetAllowImages(&allowed);
    64         break;
    65       default:
    66         return NS_OK;
    67     }
    69     if (NS_SUCCEEDED(rv) && !allowed) {
    70         *shouldLoad = nsIContentPolicy::REJECT_TYPE;
    71     }
    72     return rv;
    73 }
    75 NS_IMETHODIMP
    76 nsWebBrowserContentPolicy::ShouldProcess(uint32_t          contentType,
    77                                          nsIURI           *contentLocation,
    78                                          nsIURI           *requestingLocation,
    79                                          nsISupports      *requestingContext,
    80                                          const nsACString &mimeGuess,
    81                                          nsISupports      *extra,
    82                                          nsIPrincipal     *requestPrincipal,
    83                                          int16_t          *shouldProcess)
    84 {
    85     NS_PRECONDITION(shouldProcess, "Null out param");
    87     *shouldProcess = nsIContentPolicy::ACCEPT;
    89     // Object tags will always open channels with TYPE_OBJECT, but may end up
    90     // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block
    91     // actual-plugins at the process stage
    92     if (contentType != nsIContentPolicy::TYPE_OBJECT) {
    93         return NS_OK;
    94     }
    96     nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext);
    97     if (shell && (!shell->PluginsAllowedInCurrentDoc())) {
    98         *shouldProcess = nsIContentPolicy::REJECT_TYPE;
    99     }
   101     return NS_OK;
   102 }

mercurial