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"
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
)
27 nsWebBrowserContentPolicy::ShouldLoad(uint32_t contentType
,
28 nsIURI
*contentLocation
,
29 nsIURI
*requestingLocation
,
30 nsISupports
*requestingContext
,
31 const nsACString
&mimeGuess
,
33 nsIPrincipal
*requestPrincipal
,
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 */
49 switch (contentType
) {
50 case nsIContentPolicy::TYPE_SCRIPT
:
51 rv
= shell
->GetAllowJavascript(&allowed
);
53 case nsIContentPolicy::TYPE_SUBDOCUMENT
:
54 rv
= shell
->GetAllowSubframes(&allowed
);
57 /* XXXtw: commented out in old code; add during conpol phase 2 */
58 case nsIContentPolicy::TYPE_REFRESH
:
59 rv
= shell
->GetAllowMetaRedirects(&allowed
); /* meta _refresh_ */
62 case nsIContentPolicy::TYPE_IMAGE
:
63 rv
= shell
->GetAllowImages(&allowed
);
69 if (NS_SUCCEEDED(rv
) && !allowed
) {
70 *shouldLoad
= nsIContentPolicy::REJECT_TYPE
;
76 nsWebBrowserContentPolicy::ShouldProcess(uint32_t contentType
,
77 nsIURI
*contentLocation
,
78 nsIURI
*requestingLocation
,
79 nsISupports
*requestingContext
,
80 const nsACString
&mimeGuess
,
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
) {
96 nsIDocShell
*shell
= NS_CP_GetDocShellFromContext(requestingContext
);
97 if (shell
&& (!shell
->PluginsAllowedInCurrentDoc())) {
98 *shouldProcess
= nsIContentPolicy::REJECT_TYPE
;