1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
*
* Copyright (C) 2003 Christian Persch
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/
#include "mozilla-config.h"
#include "config.h"
#include "EphyContentPolicy.h"
#include "ephy-embed-shell.h"
#include "ephy-embed-single.h"
#include "eel-gconf-extensions.h"
#include "ephy-debug.h"
#include <nsCOMPtr.h>
#include <nsIURI.h>
#define MOZILLA_STRICT_API
#include <nsEmbedString.h>
#undef MOZILLA_STRICT_API
#define CONF_LOCKDOWN_DISABLE_UNSAFE_PROTOCOLS "/apps/epiphany/lockdown/disable_unsafe_protocols"
#define CONF_LOCKDOWN_ADDITIONAL_SAFE_PROTOCOLS "/apps/epiphany/lockdown/additional_safe_protocols"
NS_IMPL_ISUPPORTS1(EphyContentPolicy, nsIContentPolicy)
EphyContentPolicy::EphyContentPolicy()
{
LOG ("EphyContentPolicy ctor (%p)", this)
mLocked = eel_gconf_get_boolean (CONF_LOCKDOWN_DISABLE_UNSAFE_PROTOCOLS);
mSafeProtocols = eel_gconf_get_string_list (CONF_LOCKDOWN_ADDITIONAL_SAFE_PROTOCOLS);
mSafeProtocols = g_slist_prepend (mSafeProtocols, g_strdup ("https"));
mSafeProtocols = g_slist_prepend (mSafeProtocols, g_strdup ("http"));
mEmbedSingle = ephy_embed_shell_get_embed_single (embed_shell);
g_return_if_fail (mEmbedSingle);
}
EphyContentPolicy::~EphyContentPolicy()
{
LOG ("EphyContentPolicy dtor (%p)", this)
g_slist_foreach (mSafeProtocols, (GFunc) g_free, NULL);
g_slist_free (mSafeProtocols);
}
#if MOZ_NSICONTENTPOLICY_VARIANT == 2
NS_IMETHODIMP
EphyContentPolicy::ShouldLoad(PRUint32 aContentType,
nsIURI *aContentLocation,
nsIURI *aRequestingLocation,
nsISupports *aContext,
const nsACString &aMimeTypeGuess,
nsISupports *aExtra,
PRInt16 *aDecision)
{
NS_ENSURE_ARG (aContentLocation);
nsEmbedCString contentScheme;
aContentLocation->GetScheme (contentScheme);
nsEmbedCString contentSpec;
aContentLocation->GetSpec (contentSpec);
/* first general lockdown check */
if (mLocked &&
!g_slist_find_custom (mSafeProtocols, contentScheme.get(), (GCompareFunc) strcmp) &&
strcmp (contentSpec.get(), "about:blank") != 0)
{
*aDecision = nsIContentPolicy::REJECT_REQUEST;
return NS_OK;
}
nsEmbedCString requestingSpec;
if (aRequestingLocation)
{
aRequestingLocation->GetSpec (requestingSpec);
}
gboolean result = FALSE;
g_signal_emit_by_name (mEmbedSingle, "check-content",
(EphyContentCheckType) aContentType,
contentSpec.get(),
requestingSpec.get(),
nsEmbedCString(aMimeTypeGuess).get(),
&result);
if (result)
{
*aDecision = nsIContentPolicy::REJECT_REQUEST;
}
else
{
*aDecision = nsIContentPolicy::ACCEPT;
}
return NS_OK;
}
NS_IMETHODIMP
EphyContentPolicy::ShouldProcess(PRUint32 aContentType,
nsIURI *aContentLocation,
nsIURI *aRequestingLocation,
nsISupports *aContext,
const nsACString &aMimeType,
nsISupports *aExtra,
PRInt16 *aDecision)
{
*aDecision = nsIContentPolicy::ACCEPT;
return NS_OK;
}
#else
/* boolean shouldLoad (in PRInt32 contentType, in nsIURI contentLocation, in nsISupports ctxt, in nsIDOMWindow window); */
NS_IMETHODIMP EphyContentPolicy::ShouldLoad(PRInt32 aContentType,
nsIURI *aContentLocation,
nsISupports *aContext,
nsIDOMWindow *aWindow,
PRBool *_retval)
{
NS_ENSURE_ARG (aContentLocation);
nsEmbedCString contentScheme;
aContentLocation->GetScheme (contentScheme);
nsEmbedCString contentSpec;
aContentLocation->GetSpec (contentSpec);
/* first general lockdown check */
if (mLocked &&
!g_slist_find_custom (mSafeProtocols, contentScheme.get(), (GCompareFunc) strcmp) &&
strcmp (contentSpec.get(), "about:blank") != 0)
{
*_retval = PR_FALSE;
return NS_OK;
}
/* translate to variant-2 types */
EphyContentCheckType type;
switch (aContentType)
{
case nsIContentPolicy::SCRIPT:
type = EPHY_CONTENT_CHECK_TYPE_SCRIPT;
break;
case nsIContentPolicy::IMAGE:
type = EPHY_CONTENT_CHECK_TYPE_IMAGE;
break;
case nsIContentPolicy::STYLESHEET:
type = EPHY_CONTENT_CHECK_TYPE_STYLESHEET;
break;
case nsIContentPolicy::OBJECT:
type = EPHY_CONTENT_CHECK_TYPE_OBJECT;
break;
case nsIContentPolicy::SUBDOCUMENT:
type = EPHY_CONTENT_CHECK_TYPE_SUBDOCUMENT;
break;
case nsIContentPolicy::CONTROL_TAG:
type = EPHY_CONTENT_CHECK_TYPE_REFRESH;
break;
case nsIContentPolicy::DOCUMENT:
type = EPHY_CONTENT_CHECK_TYPE_DOCUMENT;
break;
case nsIContentPolicy::OTHER:
case nsIContentPolicy::RAW_URL:
default:
type = EPHY_CONTENT_CHECK_TYPE_OTHER;
break;
}
gboolean result = FALSE;
g_signal_emit_by_name (mEmbedSingle, "check-content",
type,
contentSpec.get(),
"",
"",
&result);
*_retval = !result;
return NS_OK;
}
/* boolean shouldProcess (in PRInt32 contentType, in nsIURI documentLocation, in nsISupports ctxt, in nsIDOMWindow window); */
NS_IMETHODIMP EphyContentPolicy::ShouldProcess(PRInt32 contentType,
nsIURI *documentLocation,
nsISupports *ctxt,
nsIDOMWindow *window,
PRBool *_retval)
{
/* This is never called. */
LOG ("ShouldProcess: this is quite unexpected!")
*_retval = PR_TRUE;
return NS_OK;
}
#endif /* MOZ_NSICONTENTPOLICY_VARIANT == 2 */
|