|
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 |
|
3 * |
|
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/. */ |
|
7 |
|
8 #include "nsWebBrowserContentPolicy.h" |
|
9 #include "nsIDocShell.h" |
|
10 #include "nsCOMPtr.h" |
|
11 #include "nsContentPolicyUtils.h" |
|
12 #include "nsIContentViewer.h" |
|
13 |
|
14 nsWebBrowserContentPolicy::nsWebBrowserContentPolicy() |
|
15 { |
|
16 MOZ_COUNT_CTOR(nsWebBrowserContentPolicy); |
|
17 } |
|
18 |
|
19 nsWebBrowserContentPolicy::~nsWebBrowserContentPolicy() |
|
20 { |
|
21 MOZ_COUNT_DTOR(nsWebBrowserContentPolicy); |
|
22 } |
|
23 |
|
24 NS_IMPL_ISUPPORTS(nsWebBrowserContentPolicy, nsIContentPolicy) |
|
25 |
|
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) |
|
35 { |
|
36 NS_PRECONDITION(shouldLoad, "Null out param"); |
|
37 |
|
38 *shouldLoad = nsIContentPolicy::ACCEPT; |
|
39 |
|
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; |
|
44 } |
|
45 |
|
46 nsresult rv; |
|
47 bool allowed = true; |
|
48 |
|
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; |
|
67 } |
|
68 |
|
69 if (NS_SUCCEEDED(rv) && !allowed) { |
|
70 *shouldLoad = nsIContentPolicy::REJECT_TYPE; |
|
71 } |
|
72 return rv; |
|
73 } |
|
74 |
|
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) |
|
84 { |
|
85 NS_PRECONDITION(shouldProcess, "Null out param"); |
|
86 |
|
87 *shouldProcess = nsIContentPolicy::ACCEPT; |
|
88 |
|
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; |
|
94 } |
|
95 |
|
96 nsIDocShell *shell = NS_CP_GetDocShellFromContext(requestingContext); |
|
97 if (shell && (!shell->PluginsAllowedInCurrentDoc())) { |
|
98 *shouldProcess = nsIContentPolicy::REJECT_TYPE; |
|
99 } |
|
100 |
|
101 return NS_OK; |
|
102 } |