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