From e79cce1c425179bc732622ca49767725e3609ed9 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Fri, 19 Aug 2005 15:00:01 +0000 Subject: [PATCH] Allow passing a cached nsIContentPolicy service pointer to NS_CheckContent*Policy if the caller has one. Bug 304845, r=biesi, sr=jst git-svn-id: svn://10.0.0.236/trunk@178242 18797224-902f-48f8-a5cc-f745e15eee43 --- .../base/public/nsContentPolicyUtils.h | 28 ++++++++++++++++--- mozilla/content/base/public/nsContentUtils.h | 13 ++++++++- mozilla/content/base/src/nsContentUtils.cpp | 8 +++++- mozilla/content/base/src/nsScriptLoader.cpp | 3 +- .../html/document/src/nsImageDocument.cpp | 3 +- mozilla/content/xbl/src/nsXBLService.cpp | 3 +- .../xml/document/src/nsXMLContentSink.cpp | 3 +- mozilla/layout/generic/nsObjectFrame.cpp | 3 +- mozilla/layout/style/nsCSSLoader.cpp | 3 +- 9 files changed, 55 insertions(+), 12 deletions(-) diff --git a/mozilla/content/base/public/nsContentPolicyUtils.h b/mozilla/content/base/public/nsContentPolicyUtils.h index b351ed727b3..6227dafd5d4 100644 --- a/mozilla/content/base/public/nsContentPolicyUtils.h +++ b/mozilla/content/base/public/nsContentPolicyUtils.h @@ -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 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. diff --git a/mozilla/content/base/public/nsContentUtils.h b/mozilla/content/base/public/nsContentUtils.h index df7df623398..84c1339c7b1 100644 --- a/mozilla/content/base/public/nsContentUtils.h +++ b/mozilla/content/base/public/nsContentUtils.h @@ -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; diff --git a/mozilla/content/base/src/nsContentUtils.cpp b/mozilla/content/base/src/nsContentUtils.cpp index 9329a65dc7e..548ec3b2016 100644 --- a/mozilla/content/base/src/nsContentUtils.cpp +++ b/mozilla/content/base/src/nsContentUtils.cpp @@ -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 = diff --git a/mozilla/content/base/src/nsScriptLoader.cpp b/mozilla/content/base/src/nsScriptLoader.cpp index 563e2e40f5e..322ae8fd760 100644 --- a/mozilla/content/base/src/nsScriptLoader.cpp +++ b/mozilla/content/base/src/nsScriptLoader.cpp @@ -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, diff --git a/mozilla/content/html/document/src/nsImageDocument.cpp b/mozilla/content/html/document/src/nsImageDocument.cpp index a78e9c0eb51..0581b4d14bc 100644 --- a/mozilla/content/html/document/src/nsImageDocument.cpp +++ b/mozilla/content/html/document/src/nsImageDocument.cpp @@ -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); diff --git a/mozilla/content/xbl/src/nsXBLService.cpp b/mozilla/content/xbl/src/nsXBLService.cpp index a2a0171be3e..6590c84a2bc 100644 --- a/mozilla/content/xbl/src/nsXBLService.cpp +++ b/mozilla/content/xbl/src/nsXBLService.cpp @@ -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; diff --git a/mozilla/content/xml/document/src/nsXMLContentSink.cpp b/mozilla/content/xml/document/src/nsXMLContentSink.cpp index dbbe5056e0f..ed10e45ae98 100644 --- a/mozilla/content/xml/document/src/nsXMLContentSink.cpp +++ b/mozilla/content/xml/document/src/nsXMLContentSink.cpp @@ -643,7 +643,8 @@ nsXMLContentSink::ProcessStyleLink(nsIContent* aElement, aElement, type, nsnull, - &decision); + &decision, + nsContentUtils::GetContentPolicy()); NS_ENSURE_SUCCESS(rv, rv); diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index afb1d5cdb4d..32d91167bf5 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -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; } diff --git a/mozilla/layout/style/nsCSSLoader.cpp b/mozilla/layout/style/nsCSSLoader.cpp index 23921b13e06..7ed6f787b24 100644 --- a/mozilla/layout/style/nsCSSLoader.cpp +++ b/mozilla/layout/style/nsCSSLoader.cpp @@ -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"));