michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: ft=cpp tw=78 sw=4 et ts=8 michael@0: * michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsWebBrowserContentPolicy.h" michael@0: #include "nsIDocShell.h" michael@0: #include "nsCOMPtr.h" michael@0: #include "nsContentPolicyUtils.h" michael@0: #include "nsIContentViewer.h" michael@0: michael@0: nsWebBrowserContentPolicy::nsWebBrowserContentPolicy() michael@0: { michael@0: MOZ_COUNT_CTOR(nsWebBrowserContentPolicy); michael@0: } michael@0: michael@0: nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy() michael@0: { michael@0: MOZ_COUNT_DTOR(nsWebBrowserContentPolicy); michael@0: } michael@0: michael@0: NS_IMPL_ISUPPORTS(nsWebBrowserContentPolicy, nsIContentPolicy) michael@0: michael@0: NS_IMETHODIMP michael@0: nsWebBrowserContentPolicy::ShouldLoad(uint32_t contentType, michael@0: nsIURI *contentLocation, michael@0: nsIURI *requestingLocation, michael@0: nsISupports *requestingContext, michael@0: const nsACString &mimeGuess, michael@0: nsISupports *extra, michael@0: nsIPrincipal *requestPrincipal, michael@0: int16_t *shouldLoad) michael@0: { michael@0: NS_PRECONDITION(shouldLoad, "Null out param"); michael@0: michael@0: *shouldLoad = nsIContentPolicy::ACCEPT; michael@0: michael@0: nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext); michael@0: /* We're going to dereference shell, so make sure it isn't null */ michael@0: if (!shell) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsresult rv; michael@0: bool allowed = true; michael@0: michael@0: switch (contentType) { michael@0: case nsIContentPolicy::TYPE_SCRIPT: michael@0: rv = shell->GetAllowJavascript(&allowed); michael@0: break; michael@0: case nsIContentPolicy::TYPE_SUBDOCUMENT: michael@0: rv = shell->GetAllowSubframes(&allowed); michael@0: break; michael@0: #if 0 michael@0: /* XXXtw: commented out in old code; add during conpol phase 2 */ michael@0: case nsIContentPolicy::TYPE_REFRESH: michael@0: rv = shell->GetAllowMetaRedirects(&allowed); /* meta _refresh_ */ michael@0: break; michael@0: #endif michael@0: case nsIContentPolicy::TYPE_IMAGE: michael@0: rv = shell->GetAllowImages(&allowed); michael@0: break; michael@0: default: michael@0: return NS_OK; michael@0: } michael@0: michael@0: if (NS_SUCCEEDED(rv) && !allowed) { michael@0: *shouldLoad = nsIContentPolicy::REJECT_TYPE; michael@0: } michael@0: return rv; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: nsWebBrowserContentPolicy::ShouldProcess(uint32_t contentType, michael@0: nsIURI *contentLocation, michael@0: nsIURI *requestingLocation, michael@0: nsISupports *requestingContext, michael@0: const nsACString &mimeGuess, michael@0: nsISupports *extra, michael@0: nsIPrincipal *requestPrincipal, michael@0: int16_t *shouldProcess) michael@0: { michael@0: NS_PRECONDITION(shouldProcess, "Null out param"); michael@0: michael@0: *shouldProcess = nsIContentPolicy::ACCEPT; michael@0: michael@0: // Object tags will always open channels with TYPE_OBJECT, but may end up michael@0: // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block michael@0: // actual-plugins at the process stage michael@0: if (contentType != nsIContentPolicy::TYPE_OBJECT) { michael@0: return NS_OK; michael@0: } michael@0: michael@0: nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext); michael@0: if (shell && (!shell->PluginsAllowedInCurrentDoc())) { michael@0: *shouldProcess = nsIContentPolicy::REJECT_TYPE; michael@0: } michael@0: michael@0: return NS_OK; michael@0: }