content/base/src/nsNoDataProtocolContentPolicy.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 /*
michael@0 7 * Content policy implementation that prevents all loads of images,
michael@0 8 * subframes, etc from protocols that don't return data but rather open
michael@0 9 * applications (such as mailto).
michael@0 10 */
michael@0 11
michael@0 12 #include "nsNoDataProtocolContentPolicy.h"
michael@0 13 #include "nsIDOMWindow.h"
michael@0 14 #include "nsString.h"
michael@0 15 #include "nsIProtocolHandler.h"
michael@0 16 #include "nsIIOService.h"
michael@0 17 #include "nsIExternalProtocolHandler.h"
michael@0 18 #include "nsNetUtil.h"
michael@0 19
michael@0 20 NS_IMPL_ISUPPORTS(nsNoDataProtocolContentPolicy, nsIContentPolicy)
michael@0 21
michael@0 22 NS_IMETHODIMP
michael@0 23 nsNoDataProtocolContentPolicy::ShouldLoad(uint32_t aContentType,
michael@0 24 nsIURI *aContentLocation,
michael@0 25 nsIURI *aRequestingLocation,
michael@0 26 nsISupports *aRequestingContext,
michael@0 27 const nsACString &aMimeGuess,
michael@0 28 nsISupports *aExtra,
michael@0 29 nsIPrincipal *aRequestPrincipal,
michael@0 30 int16_t *aDecision)
michael@0 31 {
michael@0 32 *aDecision = nsIContentPolicy::ACCEPT;
michael@0 33
michael@0 34 // Don't block for TYPE_OBJECT since such URIs are sometimes loaded by the
michael@0 35 // plugin, so they don't necessarily open external apps
michael@0 36 // TYPE_WEBSOCKET loads can only go to ws:// or wss://, so we don't need to
michael@0 37 // concern ourselves with them.
michael@0 38 if (aContentType != TYPE_DOCUMENT &&
michael@0 39 aContentType != TYPE_SUBDOCUMENT &&
michael@0 40 aContentType != TYPE_OBJECT &&
michael@0 41 aContentType != TYPE_WEBSOCKET) {
michael@0 42
michael@0 43 // The following are just quick-escapes for the most common cases
michael@0 44 // where we would allow the content to be loaded anyway.
michael@0 45 nsAutoCString scheme;
michael@0 46 aContentLocation->GetScheme(scheme);
michael@0 47 if (scheme.EqualsLiteral("http") ||
michael@0 48 scheme.EqualsLiteral("https") ||
michael@0 49 scheme.EqualsLiteral("ftp") ||
michael@0 50 scheme.EqualsLiteral("file") ||
michael@0 51 scheme.EqualsLiteral("chrome")) {
michael@0 52 return NS_OK;
michael@0 53 }
michael@0 54
michael@0 55 bool shouldBlock;
michael@0 56 nsresult rv = NS_URIChainHasFlags(aContentLocation,
michael@0 57 nsIProtocolHandler::URI_DOES_NOT_RETURN_DATA,
michael@0 58 &shouldBlock);
michael@0 59 if (NS_SUCCEEDED(rv) && shouldBlock) {
michael@0 60 *aDecision = nsIContentPolicy::REJECT_REQUEST;
michael@0 61 }
michael@0 62 }
michael@0 63
michael@0 64 return NS_OK;
michael@0 65 }
michael@0 66
michael@0 67 NS_IMETHODIMP
michael@0 68 nsNoDataProtocolContentPolicy::ShouldProcess(uint32_t aContentType,
michael@0 69 nsIURI *aContentLocation,
michael@0 70 nsIURI *aRequestingLocation,
michael@0 71 nsISupports *aRequestingContext,
michael@0 72 const nsACString &aMimeGuess,
michael@0 73 nsISupports *aExtra,
michael@0 74 nsIPrincipal *aRequestPrincipal,
michael@0 75 int16_t *aDecision)
michael@0 76 {
michael@0 77 return ShouldLoad(aContentType, aContentLocation, aRequestingLocation,
michael@0 78 aRequestingContext, aMimeGuess, aExtra, aRequestPrincipal,
michael@0 79 aDecision);
michael@0 80 }

mercurial