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