mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 557047 - Replace mailnews specific ifdef (MOZ_MAIL_NEWS) in cookie code with tests for a protocol flag. r=sdwilsh,sr=bzbarsky
This commit is contained in:
parent
ab6e074472
commit
34bd0c10c3
@ -129,7 +129,6 @@ MOZ_LIBSTDCXX_TARGET_VERSION=@MOZ_LIBSTDCXX_TARGET_VERSION@
|
||||
MOZ_LIBSTDCXX_HOST_VERSION=@MOZ_LIBSTDCXX_HOST_VERSION@
|
||||
INCREMENTAL_LINKER = @INCREMENTAL_LINKER@
|
||||
MACOSX_DEPLOYMENT_TARGET = @MACOSX_DEPLOYMENT_TARGET@
|
||||
MOZ_MAIL_NEWS = @MOZ_MAIL_NEWS@
|
||||
ENABLE_TESTS = @ENABLE_TESTS@
|
||||
IBMBIDI = @IBMBIDI@
|
||||
MOZ_UNIVERSALCHARDET = @MOZ_UNIVERSALCHARDET@
|
||||
|
@ -65,10 +65,6 @@ XPIDLSRCS = \
|
||||
nsICookiePromptService.idl \
|
||||
$(NULL)
|
||||
|
||||
ifdef MOZ_MAIL_NEWS
|
||||
DEFINES += -DMOZ_MAIL_NEWS
|
||||
endif
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
TOOL_DIRS += test
|
||||
endif
|
||||
|
@ -90,23 +90,6 @@ static const char kCookiesAskPermission[] = "network.cookie.warnAboutCookies";
|
||||
|
||||
static const char kPermissionType[] = "cookie";
|
||||
|
||||
#ifdef MOZ_MAIL_NEWS
|
||||
// returns true if URI appears to be the URI of a mailnews protocol
|
||||
// XXXbz this should be a protocol flag, not a scheme list, dammit!
|
||||
static bool
|
||||
IsFromMailNews(nsIURI *aURI)
|
||||
{
|
||||
static const char *kMailNewsProtocols[] =
|
||||
{ "imap", "news", "snews", "mailbox", nsnull };
|
||||
bool result;
|
||||
for (const char **p = kMailNewsProtocols; *p; ++p) {
|
||||
if (NS_SUCCEEDED(aURI->SchemeIs(*p, &result)) && result)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsCookiePermission,
|
||||
nsICookiePermission,
|
||||
nsIObserver)
|
||||
@ -206,21 +189,22 @@ nsCookiePermission::CanAccess(nsIURI *aURI,
|
||||
nsIChannel *aChannel,
|
||||
nsCookieAccess *aResult)
|
||||
{
|
||||
#ifdef MOZ_MAIL_NEWS
|
||||
// If this URI is a mailnews one (e.g. imap etc), don't allow cookies for
|
||||
// it.
|
||||
if (IsFromMailNews(aURI)) {
|
||||
// Check this protocol doesn't allow cookies
|
||||
bool hasFlags;
|
||||
nsresult rv =
|
||||
NS_URIChainHasFlags(aURI, nsIProtocolHandler::URI_FORBIDS_COOKIE_ACCESS,
|
||||
&hasFlags);
|
||||
if (NS_FAILED(rv) || hasFlags) {
|
||||
*aResult = ACCESS_DENY;
|
||||
return NS_OK;
|
||||
}
|
||||
#endif // MOZ_MAIL_NEWS
|
||||
|
||||
// Lazily initialize ourselves
|
||||
if (!EnsureInitialized())
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
// finally, check with permission manager...
|
||||
nsresult rv = mPermMgr->TestPermission(aURI, kPermissionType, (PRUint32 *) aResult);
|
||||
rv = mPermMgr->TestPermission(aURI, kPermissionType, (PRUint32 *) aResult);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
switch (*aResult) {
|
||||
// if we have one of the publicly-available values, just return it
|
||||
|
@ -261,6 +261,12 @@ interface nsIProtocolHandler : nsISupports
|
||||
* ignored if ALLOWS_PROXY is not set.
|
||||
*/
|
||||
const unsigned long ALLOWS_PROXY_HTTP = (1<<3);
|
||||
|
||||
/**
|
||||
* This protocol handler forbids accessing cookies e.g. for mail related
|
||||
* protocols.
|
||||
*/
|
||||
const unsigned long URI_FORBIDS_COOKIE_ACCESS = (1<<15);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
@ -576,29 +576,6 @@ main(PRInt32 argc, char *argv[])
|
||||
allTestsPassed = PrintResult(rv, 10) && allTestsPassed;
|
||||
|
||||
|
||||
// *** mailnews tests
|
||||
sBuffer = PR_sprintf_append(sBuffer, "*** Beginning mailnews tests...\n");
|
||||
|
||||
// test some mailnews cookies to ensure blockage.
|
||||
// we use null firstURI's deliberately, since we have hacks to deal with
|
||||
// this situation...
|
||||
SetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[0] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[1] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
SetACookie(cookieService, "http://mail.co.uk/", nsnull, "test=mailnews", nsnull);
|
||||
GetACookie(cookieService, "mailbox://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[2] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[3] = CheckResult(cookie.get(), MUST_EQUAL, "test=mailnews");
|
||||
SetACookie(cookieService, "http://mail.co.uk/", nsnull, "test=mailnews; max-age=0", nsnull);
|
||||
GetACookie(cookieService, "http://mail.co.uk/", nsnull, getter_Copies(cookie));
|
||||
rv[4] = CheckResult(cookie.get(), MUST_BE_NULL);
|
||||
|
||||
allTestsPassed = PrintResult(rv, 5) && allTestsPassed;
|
||||
|
||||
|
||||
// *** path ordering tests
|
||||
sBuffer = PR_sprintf_append(sBuffer, "*** Beginning path ordering tests...\n");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user