Bumping manifests a=b2g-bump
[gecko.git] / embedding / browser / nsWebBrowserContentPolicy.cpp
blob6d2f741b36d3e0f6492b7dfd1873954db7714ae1
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
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()
16 MOZ_COUNT_CTOR(nsWebBrowserContentPolicy);
19 nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy()
21 MOZ_COUNT_DTOR(nsWebBrowserContentPolicy);
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)
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;
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 case nsIContentPolicy::TYPE_IMAGESET:
64 rv = shell->GetAllowImages(&allowed);
65 break;
66 default:
67 return NS_OK;
70 if (NS_SUCCEEDED(rv) && !allowed) {
71 *shouldLoad = nsIContentPolicy::REJECT_TYPE;
73 return rv;
76 NS_IMETHODIMP
77 nsWebBrowserContentPolicy::ShouldProcess(uint32_t contentType,
78 nsIURI *contentLocation,
79 nsIURI *requestingLocation,
80 nsISupports *requestingContext,
81 const nsACString &mimeGuess,
82 nsISupports *extra,
83 nsIPrincipal *requestPrincipal,
84 int16_t *shouldProcess)
86 NS_PRECONDITION(shouldProcess, "Null out param");
88 *shouldProcess = nsIContentPolicy::ACCEPT;
90 // Object tags will always open channels with TYPE_OBJECT, but may end up
91 // loading with TYPE_IMAGE or TYPE_DOCUMENT as their final type, so we block
92 // actual-plugins at the process stage
93 if (contentType != nsIContentPolicy::TYPE_OBJECT) {
94 return NS_OK;
97 nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext);
98 if (shell && (!shell->PluginsAllowedInCurrentDoc())) {
99 *shouldProcess = nsIContentPolicy::REJECT_TYPE;
102 return NS_OK;