Merge for backout of bug 441359

This commit is contained in:
Dave Camp 2009-01-05 01:28:52 -08:00
commit 0f9f0c44a0
14 changed files with 13 additions and 287 deletions

View File

@ -147,8 +147,3 @@ https://sectest1.example.org:443 privileged
https://sub.sectest2.example.org:443 privileged https://sub.sectest2.example.org:443 privileged
https://sectest2.example.org:443 https://sectest2.example.org:443
https://sub.sectest1.example.org:443 https://sub.sectest1.example.org:443
#
# Used while testing the url-classifier
#
http://malware.com:80 privileged

View File

@ -1758,7 +1758,7 @@ nsObjectLoadingContent::CheckClassifier(nsIChannel *aChannel)
do_CreateInstance(NS_CHANNELCLASSIFIER_CONTRACTID, &rv); do_CreateInstance(NS_CHANNELCLASSIFIER_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = classifier->Start(aChannel, PR_FALSE); rv = classifier->Start(aChannel);
if (rv == NS_ERROR_FACTORY_NOT_REGISTERED) { if (rv == NS_ERROR_FACTORY_NOT_REGISTERED) {
// no URI classifier, ignore this // no URI classifier, ignore this
return NS_OK; return NS_OK;

View File

@ -68,8 +68,6 @@
#include "nsContentErrors.h" #include "nsContentErrors.h"
#include "nsIParser.h" #include "nsIParser.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsIChannelClassifier.h"
#include "nsDocShellCID.h"
////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////
// Per-request data structure // Per-request data structure
@ -266,21 +264,7 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType)
rv = NS_NewStreamLoader(getter_AddRefs(loader), this); rv = NS_NewStreamLoader(getter_AddRefs(loader), this);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
rv = channel->AsyncOpen(loader, aRequest); return channel->AsyncOpen(loader, aRequest);
NS_ENSURE_SUCCESS(rv, rv);
// Check the load against the URI classifier
nsCOMPtr<nsIChannelClassifier> classifier =
do_CreateInstance(NS_CHANNELCLASSIFIER_CONTRACTID);
if (classifier) {
rv = classifier->Start(channel, PR_TRUE);
if (NS_FAILED(rv)) {
channel->Cancel(rv);
return rv;
}
}
return NS_OK;
} }
PRBool PRBool

View File

@ -7774,7 +7774,7 @@ nsDocShell::CheckClassifier(nsIChannel *aChannel)
nsRefPtr<nsClassifierCallback> classifier = new nsClassifierCallback(); nsRefPtr<nsClassifierCallback> classifier = new nsClassifierCallback();
if (!classifier) return NS_ERROR_OUT_OF_MEMORY; if (!classifier) return NS_ERROR_OUT_OF_MEMORY;
nsresult rv = classifier->Start(aChannel, PR_FALSE); nsresult rv = classifier->Start(aChannel);
if (rv == NS_ERROR_FACTORY_NOT_REGISTERED || if (rv == NS_ERROR_FACTORY_NOT_REGISTERED ||
rv == NS_ERROR_NOT_AVAILABLE) { rv == NS_ERROR_NOT_AVAILABLE) {
// no URI classifier => ignored cases // no URI classifier => ignored cases
@ -9660,12 +9660,10 @@ nsDocShell::IsOKToLoadURI(nsIURI* aURI)
// nsClassifierCallback // nsClassifierCallback
//***************************************************************************** //*****************************************************************************
NS_IMPL_ISUPPORTS5(nsClassifierCallback, NS_IMPL_ISUPPORTS3(nsClassifierCallback,
nsIChannelClassifier, nsIChannelClassifier,
nsIURIClassifierCallback, nsIURIClassifierCallback,
nsIRunnable, nsIRunnable)
nsIChannelEventSink,
nsIInterfaceRequestor)
NS_IMETHODIMP NS_IMETHODIMP
nsClassifierCallback::Run() nsClassifierCallback::Run()
@ -9690,7 +9688,7 @@ nsClassifierCallback::Run()
// Don't bother to run the classifier on a cached load that was // Don't bother to run the classifier on a cached load that was
// previously classified. // previously classified.
if (HasBeenClassified(channel)) { if (HasBeenClassified()) {
return NS_OK; return NS_OK;
} }
@ -9782,10 +9780,10 @@ nsClassifierCallback::MarkEntryClassified(nsresult status)
} }
PRBool PRBool
nsClassifierCallback::HasBeenClassified(nsIChannel *aChannel) nsClassifierCallback::HasBeenClassified()
{ {
nsCOMPtr<nsICachingChannel> cachingChannel = nsCOMPtr<nsICachingChannel> cachingChannel =
do_QueryInterface(aChannel); do_QueryInterface(mSuspendedChannel);
if (!cachingChannel) { if (!cachingChannel) {
return PR_FALSE; return PR_FALSE;
} }
@ -9841,20 +9839,9 @@ nsClassifierCallback::OnClassifyComplete(nsresult aErrorCode)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsClassifierCallback::Start(nsIChannel *aChannel, PRBool aInstallListener) nsClassifierCallback::Start(nsIChannel *aChannel)
{ {
mChannel = aChannel; mChannel = aChannel;
if (aInstallListener) {
nsresult rv = aChannel->GetNotificationCallbacks
(getter_AddRefs(mNotificationCallbacks));
NS_ENSURE_SUCCESS(rv, rv);
rv = aChannel->SetNotificationCallbacks
(static_cast<nsIInterfaceRequestor*>(this));
NS_ENSURE_SUCCESS(rv, rv);
}
return Run(); return Run();
} }
@ -9890,36 +9877,3 @@ nsClassifierCallback::Cancel()
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
nsClassifierCallback::OnChannelRedirect(nsIChannel *aOldChannel,
nsIChannel *aNewChannel,
PRUint32 aFlags)
{
nsresult rv = OnRedirect(aOldChannel, aNewChannel);
NS_ENSURE_SUCCESS(rv, rv);
if (mNotificationCallbacks) {
nsCOMPtr<nsIChannelEventSink> sink =
do_GetInterface(mNotificationCallbacks);
if (sink) {
return sink->OnChannelRedirect(aOldChannel, aNewChannel, aFlags);
}
}
return NS_OK;
}
NS_IMETHODIMP
nsClassifierCallback::GetInterface(const nsIID &aIID, void **aResult)
{
if (aIID.Equals(NS_GET_IID(nsIChannelEventSink))) {
NS_ADDREF_THIS();
*aResult = static_cast<nsIChannelEventSink *>(this);
return NS_OK;
} else if (mNotificationCallbacks) {
return mNotificationCallbacks->GetInterface(aIID, aResult);
} else {
return NS_ERROR_NO_INTERFACE;
}
}

View File

@ -148,8 +148,6 @@ protected:
class nsClassifierCallback : public nsIChannelClassifier class nsClassifierCallback : public nsIChannelClassifier
, public nsIURIClassifierCallback , public nsIURIClassifierCallback
, public nsIRunnable , public nsIRunnable
, public nsIChannelEventSink
, public nsIInterfaceRequestor
{ {
public: public:
nsClassifierCallback() {} nsClassifierCallback() {}
@ -159,16 +157,13 @@ public:
NS_DECL_NSICHANNELCLASSIFIER NS_DECL_NSICHANNELCLASSIFIER
NS_DECL_NSIURICLASSIFIERCALLBACK NS_DECL_NSIURICLASSIFIERCALLBACK
NS_DECL_NSIRUNNABLE NS_DECL_NSIRUNNABLE
NS_DECL_NSICHANNELEVENTSINK
NS_DECL_NSIINTERFACEREQUESTOR
private: private:
nsCOMPtr<nsIChannel> mChannel; nsCOMPtr<nsIChannel> mChannel;
nsCOMPtr<nsIChannel> mSuspendedChannel; nsCOMPtr<nsIChannel> mSuspendedChannel;
nsCOMPtr<nsIInterfaceRequestor> mNotificationCallbacks;
void MarkEntryClassified(nsresult status); void MarkEntryClassified(nsresult status);
PRBool HasBeenClassified(nsIChannel *aChannel); PRBool HasBeenClassified();
}; };
//***************************************************************************** //*****************************************************************************

View File

@ -46,7 +46,7 @@ interface nsIChannel;
* URI classifier service, and cancels the channel before OnStartRequest * URI classifier service, and cancels the channel before OnStartRequest
* if it is found on a blacklist. * if it is found on a blacklist.
*/ */
[scriptable, uuid(1481c5b5-9f6e-4995-8fe3-2aad5c06440d)] [scriptable, uuid(d17f8f74-d403-4dea-b124-3ace5dbe44dc)]
interface nsIChannelClassifier : nsISupports interface nsIChannelClassifier : nsISupports
{ {
/** /**
@ -59,18 +59,10 @@ interface nsIChannelClassifier : nsISupports
* If there is no URI classifier service, NS_ERROR_FACTORY_NOT_REGISTERED * If there is no URI classifier service, NS_ERROR_FACTORY_NOT_REGISTERED
* will be returned. * will be returned.
* *
* This method must be called immediately after AsyncOpen() has been called
* on the channel.
*
* @param aChannel * @param aChannel
* The channel to suspend. * The channel to suspend.
* @param aInstallListener
* If true, the classifier will install notification
* callbacks to listen for redirects. The classifier will
* pass all notifications on to the channel's existing
* notification callbacks.
*/ */
void start(in nsIChannel aChannel, in boolean aInstallListener); void start(in nsIChannel aChannel);
/** /**
* Notify the classifier that the channel was redirected. The new channel * Notify the classifier that the channel was redirected. The new channel

View File

@ -79,8 +79,6 @@
#include "nsICSSImportRule.h" #include "nsICSSImportRule.h"
#include "nsThreadUtils.h" #include "nsThreadUtils.h"
#include "nsGkAtoms.h" #include "nsGkAtoms.h"
#include "nsDocShellCID.h"
#include "nsIChannelClassifier.h"
#ifdef MOZ_XUL #ifdef MOZ_XUL
#include "nsXULPrototypeCache.h" #include "nsXULPrototypeCache.h"
@ -1457,19 +1455,6 @@ CSSLoaderImpl::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
mSyncCallback = PR_FALSE; mSyncCallback = PR_FALSE;
#endif #endif
// Check the load against the URI classifier
nsCOMPtr<nsIChannelClassifier> classifier =
do_CreateInstance(NS_CHANNELCLASSIFIER_CONTRACTID);
if (classifier) {
rv = classifier->Start(channel, PR_TRUE);
if (NS_FAILED(rv)) {
LOG_ERROR((" Failed to classify URI"));
SheetComplete(aLoadData, rv);
channel->Cancel(rv);
return rv;
}
}
if (NS_FAILED(rv)) { if (NS_FAILED(rv)) {
LOG_ERROR((" Failed to create stream loader")); LOG_ERROR((" Failed to create stream loader"));
SheetComplete(aLoadData, rv); SheetComplete(aLoadData, rv);

View File

@ -55,10 +55,6 @@ REQUIRES = \
necko \ necko \
$(NULL) $(NULL)
# mochitest tests
DIRS += mochitest \
$(NULL)
# xpcshell tests # xpcshell tests
XPCSHELL_TESTS=unit XPCSHELL_TESTS=unit

View File

@ -1,57 +0,0 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
# # The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2008
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
DEPTH = ../../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = toolkit/components/url-classifier/tests/mochitest
MODULE = test_url-classifier
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_classifier.html \
classifierFrame.html \
evil.js \
evil.css \
import.css \
$(NULL)
libs:: $(_TEST_FILES)
$(INSTALL) $(foreach f,$^,"$f") $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)

View File

@ -1,34 +0,0 @@
<html> <head>
<title></title>
</head>
<script type="text/javascript">
var scriptItem = "untouched";
function checkLoads() {
// Make sure the javascript did not load.
window.parent.is(scriptItem, "untouched", "Should not load bad javascript");
// Make sure the css did not load.
var elt = document.getElementById("styleCheck");
var style = document.defaultView.getComputedStyle(elt, "");
window.parent.isnot(style.visibility, "hidden", "Should not load bad css");
window.parent.SimpleTest.finish();
}
</script>
<!-- Try loading from a malware javascript URI -->
<script type="text/javascript" src="http://malware.com/tests/toolkit/components/url-classifier/test/mochitest/evil.js"></script>
<!-- Try loading from a malware css URI
<link rel="stylesheet" type="text/css" href="http://malware.com/tests/toolkit/components/url-classifier/test/mochitest/evil.css"></link>
<!-- Try loading a marked-as-malware css through an @import from a clean URI -->
<link rel="stylesheet" type="text/css" href="import.css"></link>
<body onload="checkLoads()">
The following should not be hidden:
<div id="styleCheck">STYLE TEST</div>
</body> </html>

View File

@ -1 +0,0 @@
#styleCheck { visibility: hidden; }

View File

@ -1 +0,0 @@
scriptItem = "loaded malware javascript!";

View File

@ -1 +0,0 @@
@import url("http://malware.com/tests/docshell/test/classifierBad.css");

View File

@ -1,81 +0,0 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test the URI Classifier</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var Cc = Components.classes;
var Ci = Components.interfaces;
// Add some URLs to the malware database.
var testData = "malware.com/"
var testUpdate =
"n:1000\ni:test-malware-simple\nad:1\n" +
"a:524:32:" + testData.length + "\n" +
testData;
var dbService = Cc["@mozilla.org/url-classifier/dbservice;1"]
.getService(Ci.nsIUrlClassifierDBService);
var numTries = 10;
function doUpdate(update) {
var listener = {
QueryInterface: function(iid)
{
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIUrlClassifierUpdateObserver))
return this;
throw Cr.NS_ERROR_NO_INTERFACE;
},
updateUrlRequested: function(url) { },
streamFinished: function(status) { },
updateError: function(errorCode) {
ok(false, "Couldn't update classifier.");
SimpleTest.finish();
},
updateSuccess: function(requestedTimeout) {
document.getElementById("testFrame").src = "classifierFrame.html";
}
};
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
try {
dbService.beginUpdate(listener,
"test-malware-simple", "");
dbService.beginStream("", "");
dbService.updateStream(update);
dbService.finishStream();
dbService.finishUpdate();
} catch(ex) {
// The DB service might already be updating. Try again after a 5 seconds...
if (--numTries != 0) {
setTimeout(function() { doUpdate(update) }, 5000);
return;
}
throw ex;
}
}
doUpdate(testUpdate);
SimpleTest.waitForExplicitFinish();
</script>
</pre>
<iframe id="testFrame" onload=""></iframe>
</body>
</html>