Allow passing a cached nsIContentPolicy service pointer to

NS_CheckContent*Policy if the caller has one.  Bug 304845, r=biesi, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2005-08-19 15:00:01 +00:00
Родитель 9df2704ed9
Коммит f4c380c572
9 изменённых файлов: 55 добавлений и 12 удалений

Просмотреть файл

@ -141,17 +141,28 @@ NS_CP_ContentTypeName(PRUint32 contentType)
/* Passes on parameters from its "caller"'s context. */
#define CHECK_CONTENT_POLICY(action) \
PR_BEGIN_MACRO \
nsCOMPtr<nsIContentPolicy> policy = \
do_GetService(NS_CONTENTPOLICY_CONTRACTID); \
if (!policy) \
return NS_ERROR_FAILURE; \
\
return policy-> action (contentType, contentLocation, requestOrigin, \
context, mimeType, extra, decision);
context, mimeType, extra, decision); \
PR_END_MACRO
/* Passes on parameters from its "caller"'s context. */
#define CHECK_CONTENT_POLICY_WITH_SERVICE(action, _policy) \
PR_BEGIN_MACRO \
return _policy-> action (contentType, contentLocation, requestOrigin, \
context, mimeType, extra, decision); \
PR_END_MACRO
/**
* Alias for calling ShouldLoad on the content policy service.
* Parameters are the same as nsIContentPolicy::shouldLoad.
* Parameters are the same as nsIContentPolicy::shouldLoad, except for
* the last parameter, which can be used to pass in a pointer to the
* service if the caller already has one.
*/
inline nsresult
NS_CheckContentLoadPolicy(PRUint32 contentType,
@ -160,8 +171,12 @@ NS_CheckContentLoadPolicy(PRUint32 contentType,
nsISupports *context,
const nsACString &mimeType,
nsISupports *extra,
PRInt16 *decision)
PRInt16 *decision,
nsIContentPolicy *policyService = nsnull)
{
if (policyService) {
CHECK_CONTENT_POLICY_WITH_SERVICE(ShouldLoad, policyService);
}
CHECK_CONTENT_POLICY(ShouldLoad);
}
@ -176,12 +191,17 @@ NS_CheckContentProcessPolicy(PRUint32 contentType,
nsISupports *context,
const nsACString &mimeType,
nsISupports *extra,
PRInt16 *decision)
PRInt16 *decision,
nsIContentPolicy *policyService = nsnull)
{
if (policyService) {
CHECK_CONTENT_POLICY_WITH_SERVICE(ShouldProcess, policyService);
}
CHECK_CONTENT_POLICY(ShouldProcess);
}
#undef CHECK_CONTENT_POLICY
#undef CHECK_CONTENT_POLICY_WITH_SERVICE
/**
* Helper function to get an nsIDocShell given a context.

Просмотреть файл

@ -77,6 +77,7 @@ class nsIDOMDocument;
class nsIConsoleService;
class nsIStringBundleService;
class nsIStringBundle;
class nsIContentPolicy;
#ifdef MOZ_XTF
class nsIXTFService;
#endif
@ -554,7 +555,15 @@ public:
return sPtrsToPtrsToRelease->AppendElement(aSupportsPtr) ? NS_OK :
NS_ERROR_OUT_OF_MEMORY;
}
/**
* Return the content policy service
*/
static nsIContentPolicy *GetContentPolicy()
{
return sContentPolicyService;
}
private:
static nsresult doReparentContentWrapper(nsIContent *aChild,
nsIDocument *aNewDocument,
@ -594,6 +603,8 @@ private:
static nsIStringBundleService* sStringBundleService;
static nsIStringBundle* sStringBundles[PropertiesFile_COUNT];
static nsIContentPolicy* sContentPolicyService;
// Holds pointers to nsISupports* that should be released at shutdown
static nsVoidArray* sPtrsToPtrsToRelease;

Просмотреть файл

@ -134,6 +134,7 @@ imgILoader *nsContentUtils::sImgLoader = nsnull;
nsIConsoleService *nsContentUtils::sConsoleService;
nsIStringBundleService *nsContentUtils::sStringBundleService;
nsIStringBundle *nsContentUtils::sStringBundles[PropertiesFile_COUNT];
nsIContentPolicy *nsContentUtils::sContentPolicyService;
nsVoidArray *nsContentUtils::sPtrsToPtrsToRelease;
@ -159,6 +160,9 @@ nsContentUtils::Init()
// It's ok to not have prefs too.
CallGetService(NS_PREF_CONTRACTID, &sPref);
// It's also OK to not have a content policy service
CallGetService(NS_CONTENTPOLICY_CONTRACTID, &sContentPolicyService);
rv = NS_GetNameSpaceManager(&sNameSpaceManager);
NS_ENSURE_SUCCESS(rv, rv);
@ -410,6 +414,7 @@ nsContentUtils::Shutdown()
{
sInitialized = PR_FALSE;
NS_IF_RELEASE(sContentPolicyService);
PRInt32 i;
for (i = 0; i < PRInt32(PropertiesFile_COUNT); ++i)
NS_IF_RELEASE(sStringBundles[i]);
@ -1851,7 +1856,8 @@ nsContentUtils::CanLoadImage(nsIURI* aURI, nsISupports* aContext,
aContext,
EmptyCString(), //mime guess
nsnull, //extra
&decision);
&decision,
sContentPolicyService);
if (aImageBlockingStatus) {
*aImageBlockingStatus =

Просмотреть файл

@ -530,7 +530,8 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement,
aElement,
NS_LossyConvertUCS2toASCII(type),
nsnull, //extra
&shouldLoad);
&shouldLoad,
nsContentUtils::GetContentPolicy());
if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
if (NS_FAILED(rv) || shouldLoad != nsIContentPolicy::REJECT_TYPE) {
return FireErrorNotification(NS_ERROR_CONTENT_BLOCKED, aElement,

Просмотреть файл

@ -190,7 +190,8 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
domWindow->GetFrameElementInternal(),
mimeType,
nsnull,
&decision);
&decision,
nsContentUtils::GetContentPolicy());
if (NS_FAILED(rv) || NS_CP_REJECTED(decision)) {
request->Cancel(NS_ERROR_CONTENT_BLOCKED);

Просмотреть файл

@ -576,7 +576,8 @@ nsXBLService::LoadBindings(nsIContent* aContent, nsIURI* aURL, PRBool aAugmentFl
document, // context
EmptyCString(), // mime guess
nsnull, // extra
&decision);
&decision,
nsContentUtils::GetContentPolicy());
if (NS_SUCCEEDED(rv) && !NS_CP_ACCEPTED(decision))
rv = NS_ERROR_NOT_AVAILABLE;

Просмотреть файл

@ -643,7 +643,8 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement,
aElement,
type,
nsnull,
&decision);
&decision,
nsContentUtils::GetContentPolicy());
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -1363,7 +1363,8 @@ nsObjectFrame::InstantiatePlugin(nsPresContext* aPresContext,
mContent,
nsDependentCString(aMimeType ? aMimeType : ""),
nsnull, //extra
&shouldLoad);
&shouldLoad,
nsContentUtils::GetContentPolicy());
if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT;
}

Просмотреть файл

@ -860,7 +860,8 @@ CSSLoaderImpl::CheckLoadAllowed(nsIURI* aSourceURI,
aContext,
NS_LITERAL_CSTRING("text/css"),
nsnull, //extra param
&shouldLoad);
&shouldLoad,
nsContentUtils::GetContentPolicy());
if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) {
LOG((" Load blocked by content policy"));