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