From e2736d6096d5ef3aba48edea729e2986c92031f2 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Mon, 21 May 2001 22:40:10 +0000 Subject: [PATCH] sr=vidur/shaver@mozilla.org on the content policy callsite and implementation mods (81260). Update of the nsIContentPolicy interface to provide more generic context, a nsIURI instead of a URI wstring, and a nsIDOMWindow for window level context. Existing Callsites have been updated to reflect the new changes, and nsIDOMWindows are now passed into the new API. git-svn-id: svn://10.0.0.236/trunk@95620 18797224-902f-48f8-a5cc-f745e15eee43 --- .../base/public/nsContentPolicyUtils.h | 22 +++++----- .../content/base/public/nsIContentPolicy.idl | 29 ++++++------ mozilla/content/base/src/nsContentPolicy.cpp | 44 +++++++++---------- mozilla/content/base/src/nsContentPolicy.h | 5 +-- mozilla/content/base/src/nsScriptLoader.cpp | 24 +++++----- .../html/content/src/nsHTMLImageElement.cpp | 28 ++++++++++-- mozilla/layout/base/nsPresContext.cpp | 25 +++++++++-- mozilla/layout/base/src/nsPresContext.cpp | 25 +++++++++-- mozilla/layout/generic/nsImageFrame.cpp | 32 +++++++++----- mozilla/layout/generic/nsObjectFrame.cpp | 32 +++++++++----- mozilla/layout/html/base/src/nsImageFrame.cpp | 32 +++++++++----- .../layout/html/base/src/nsObjectFrame.cpp | 32 +++++++++----- 12 files changed, 211 insertions(+), 119 deletions(-) diff --git a/mozilla/content/base/public/nsContentPolicyUtils.h b/mozilla/content/base/public/nsContentPolicyUtils.h index 7876683ad0d..818455bc7ba 100644 --- a/mozilla/content/base/public/nsContentPolicyUtils.h +++ b/mozilla/content/base/public/nsContentPolicyUtils.h @@ -39,25 +39,27 @@ class nsIDOMElement; {0x0e3afd3d, 0xeb60, 0x4c2b, \ { 0x96, 0x3b, 0x56, 0xd7, 0xc4, 0x39, 0xf1, 0x24 }} -/* takes contentType, aURL, and element from its context */ +/* Takes contentType, aURI, context, and window from its "caller"'s context. */ #define CHECK_CONTENT_POLICY(action, result) \ - nsresult rv; \ - NS_WITH_SERVICE(nsIContentPolicy, policy, NS_CONTENTPOLICY_CONTRACTID, &rv); \ - if (NS_FAILED(rv)) \ - return rv; \ + nsCOMPtr policy = \ + do_GetService(NS_CONTENTPOLICY_CONTRACTID); \ + if (!policy) \ + return NS_ERROR_FAILURE; \ \ - return policy->##action(contentType, element, aURL.GetUnicode(), result) + return policy-> action (contentType, aURI, context, window, result); inline nsresult -NS_CheckContentLoadPolicy(PRInt32 contentType, const nsString &aURL, - nsIDOMElement *element, PRBool *shouldLoad) +NS_CheckContentLoadPolicy(PRInt32 contentType, nsIURI *aURI, + nsISupports *context, nsIDOMWindow *window, + PRBool *shouldLoad) { CHECK_CONTENT_POLICY(ShouldLoad, shouldLoad); } inline nsresult -NS_CheckContentProcessPolicy(PRInt32 contentType, nsString &aURL, - nsIDOMElement *element, PRBool *shouldProcess) +NS_CheckContentProcessPolicy(PRInt32 contentType, nsIURI *aURI, + nsISupports *context, nsIDOMWindow *window, + PRBool *shouldProcess) { CHECK_CONTENT_POLICY(ShouldProcess, shouldProcess); } diff --git a/mozilla/content/base/public/nsIContentPolicy.idl b/mozilla/content/base/public/nsIContentPolicy.idl index 834aff73e9c..440f2a66840 100644 --- a/mozilla/content/base/public/nsIContentPolicy.idl +++ b/mozilla/content/base/public/nsIContentPolicy.idl @@ -20,10 +20,9 @@ */ #include "nsISupports.idl" -#include "nsIURL.idl" - -interface nsIDOMElement; +interface nsIDOMWindow; +interface nsIURI; /** * Interface for content policy mechanism. Implementations of this @@ -34,25 +33,25 @@ interface nsIDOMElement; [scriptable,uuid(1cb4085d-5407-4169-bcfe-4c5ba013fa5b)] interface nsIContentPolicy : nsISupports { - const short CONTENT_OTHER = 0; - const short CONTENT_SCRIPT = 1; - const short CONTENT_IMAGE = 2; - const short CONTENT_STYLESHEET = 3; - const short CONTENT_OBJECT = 4; + const PRInt32 OTHER = 0; + const PRInt32 SCRIPT = 1; + const PRInt32 IMAGE = 2; + const PRInt32 STYLESHEET = 3; + const PRInt32 OBJECT = 4; + const PRInt32 SUBDOCUMENT = 5; + const PRInt32 CONTROL_TAG = 6; + const PRInt32 RAW_URL = 7; /** * Should the content at this location be loaded and processed? * - * XXX Permit URL-rewriting? - * XXX Use MIME types for contentType? - * XXX Use nsIURL for location? */ - boolean shouldLoad(in PRInt32 contentType, in nsIDOMElement element, - in wstring contentLocation); + boolean shouldLoad(in PRInt32 contentType, in nsIURI contentLocation, + in nsISupports ctxt, in nsIDOMWindow window); /** * Should the contents of the element in question be processed? */ - boolean shouldProcess(in PRInt32 contentType, in nsIDOMElement element, - in wstring documentLocation); + boolean shouldProcess(in PRInt32 contentType, in nsIURI documentLocation, + in nsISupports ctxt, in nsIDOMWindow window); }; diff --git a/mozilla/content/base/src/nsContentPolicy.cpp b/mozilla/content/base/src/nsContentPolicy.cpp index 0e129563294..69f54e48b5a 100644 --- a/mozilla/content/base/src/nsContentPolicy.cpp +++ b/mozilla/content/base/src/nsContentPolicy.cpp @@ -67,8 +67,8 @@ nsContentPolicy::nsContentPolicy() PRBool hasMore; if (NS_FAILED(catEnum->HasMoreElements(&hasMore)) || !hasMore || - NS_FAILED(NS_NewISupportsArray(getter_AddRefs(mPolicies)))) { - return; + NS_FAILED(NS_NewISupportsArray(getter_AddRefs(mPolicies)))) { + return; } /* @@ -105,14 +105,13 @@ nsContentPolicy::~nsContentPolicy() { } -#define POLICY_LOAD 0 -#define POLICY_PROCESS 1 +#define POLICY_LOAD (PRInt32)0 +#define POLICY_PROCESS (PRInt32)1 NS_IMETHODIMP nsContentPolicy::CheckPolicy(PRInt32 policyType, PRInt32 contentType, - nsIDOMElement *element, - const PRUnichar *contentLocation, - PRBool *shouldProceed) + nsIURI *contentLocation, nsISupports *context, + nsIDOMWindow *window, PRBool *shouldProceed) { *shouldProceed = PR_TRUE; if (!mPolicies) @@ -135,12 +134,13 @@ nsContentPolicy::CheckPolicy(PRInt32 policyType, PRInt32 contentType, continue; /* check the appropriate policy */ - if (policyType == POLICY_LOAD) - rv = policy->ShouldLoad(contentType, element, contentLocation, - shouldProceed); - else - rv = policy->ShouldProcess(contentType, element, contentLocation, - shouldProceed); + if (policyType == POLICY_LOAD) { + rv = policy->ShouldLoad(contentType, contentLocation, context, + window, shouldProceed); + } else { + rv = policy->ShouldProcess(contentType, contentLocation, context, + window, shouldProceed); + } if (NS_SUCCEEDED(rv) && !*shouldProceed) /* policy says no, no point continuing to check */ @@ -157,20 +157,20 @@ nsContentPolicy::CheckPolicy(PRInt32 policyType, PRInt32 contentType, } NS_IMETHODIMP -nsContentPolicy::ShouldLoad(PRInt32 contentType, nsIDOMElement *element, - const PRUnichar *contentLocation, +nsContentPolicy::ShouldLoad(PRInt32 contentType, nsIURI *contentLocation, + nsISupports *context, nsIDOMWindow *window, PRBool *shouldLoad) { - return CheckPolicy(POLICY_LOAD, contentType, element, contentLocation, - shouldLoad); + return CheckPolicy(POLICY_LOAD, contentType, contentLocation, context, + window, shouldLoad); } NS_IMETHODIMP -nsContentPolicy::ShouldProcess(PRInt32 contentType, nsIDOMElement *element, - const PRUnichar *contentLocation, - PRBool *shouldProcess) +nsContentPolicy::ShouldProcess(PRInt32 contentType, nsIURI *contentLocation, + nsISupports *context, nsIDOMWindow *window, + PRBool *shouldProcess) { - return CheckPolicy(POLICY_PROCESS, contentType, element, contentLocation, - shouldProcess); + return CheckPolicy(POLICY_PROCESS, contentType, contentLocation, context, + window, shouldProcess); } diff --git a/mozilla/content/base/src/nsContentPolicy.h b/mozilla/content/base/src/nsContentPolicy.h index 4d28c150a04..00a32d97e09 100644 --- a/mozilla/content/base/src/nsContentPolicy.h +++ b/mozilla/content/base/src/nsContentPolicy.h @@ -35,9 +35,8 @@ class nsContentPolicy : public nsIContentPolicy private: nsCOMPtr mPolicies; NS_IMETHOD CheckPolicy(PRInt32 policyType, PRInt32 contentType, - nsIDOMElement *element, - const PRUnichar *contentLocation, - PRBool *shouldProceed); + nsIURI *aURI, nsISupports *context, + nsIDOMWindow *window, PRBool *shouldProceed); }; nsresult diff --git a/mozilla/content/base/src/nsScriptLoader.cpp b/mozilla/content/base/src/nsScriptLoader.cpp index 6c74e9607fd..89fe9b2ce3f 100644 --- a/mozilla/content/base/src/nsScriptLoader.cpp +++ b/mozilla/content/base/src/nsScriptLoader.cpp @@ -37,6 +37,7 @@ #include "nsIScriptSecurityManager.h" #include "nsIPrincipal.h" #include "nsContentPolicyUtils.h" +#include "nsIDOMWindow.h" #include "nsIHttpChannel.h" #include "nsIScriptElement.h" #include "nsIDocShell.h" @@ -357,20 +358,15 @@ nsScriptLoader::ProcessScriptElement(nsIDOMHTMLScriptElement *aElement, } // After the security manager, the content-policy stuff gets a veto - // For pinkerton: a symphony for string conversion, in 3 parts. - nsXPIDLCString urlCString; - scriptURI->GetSpec(getter_Copies(urlCString)); - nsAutoString url; - url.AssignWithConversion(urlCString.get()); - - PRBool shouldLoad = PR_TRUE; - if (NS_SUCCEEDED(rv) && - (rv = NS_CheckContentLoadPolicy(nsIContentPolicy::CONTENT_SCRIPT, - url, aElement, &shouldLoad), - NS_SUCCEEDED(rv)) && - !shouldLoad) { - - return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement, aObserver); + if (globalObject) { + nsCOMPtr domWin(do_QueryInterface(globalObject)); + + PRBool shouldLoad = PR_TRUE; + rv = NS_CheckContentLoadPolicy(nsIContentPolicy::SCRIPT, + scriptURI, aElement, domWin, &shouldLoad); + if (NS_SUCCEEDED(rv) && !shouldLoad) { + return FireErrorNotification(NS_ERROR_NOT_AVAILABLE, aElement, aObserver); + } } request->mURI = scriptURI; diff --git a/mozilla/content/html/content/src/nsHTMLImageElement.cpp b/mozilla/content/html/content/src/nsHTMLImageElement.cpp index 8766769f54d..0c2a71aa342 100644 --- a/mozilla/content/html/content/src/nsHTMLImageElement.cpp +++ b/mozilla/content/html/content/src/nsHTMLImageElement.cpp @@ -50,6 +50,8 @@ #include "nsIImageFrame.h" #include "nsLayoutAtoms.h" #include "nsNodeInfoManager.h" +#include "nsContentPolicyUtils.h" +#include "nsIDOMWindow.h" #ifdef USE_IMG2 #include "imgIContainer.h" @@ -979,6 +981,29 @@ nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL, if ((size.width > 0) || (size.height > 0)) { specifiedSize = &size; } + + nsCOMPtr uri; + result = NS_NewURI(getter_AddRefs(uri), aSrc, aBaseURL); + if (NS_FAILED(result)) return result; + + nsCOMPtr document; + result = shell->GetDocument(getter_AddRefs(document)); + if (NS_FAILED(result)) return result; + + nsCOMPtr globalObject; + result = document->GetScriptGlobalObject(getter_AddRefs(globalObject)); + if (NS_FAILED(result)) return result; + + nsCOMPtr domWin(do_QueryInterface(globalObject)); + + PRBool shouldLoad = PR_TRUE; + result = NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE, + uri, + NS_STATIC_CAST(nsISupports *, + (nsIDOMHTMLImageElement*)this), + domWin, &shouldLoad); + if (NS_SUCCEEDED(result) && !shouldLoad) + return NS_OK; // If we have a loader we're in the middle of loading a image, // we'll cancel that load and start a new one. @@ -991,9 +1016,6 @@ nsHTMLImageElement::SetSrcInner(nsIURI* aBaseURL, if (!il) { return NS_ERROR_FAILURE; } - nsCOMPtr uri; - result = NS_NewURI(getter_AddRefs(uri), aSrc, aBaseURL); - if (NS_FAILED(result)) return result; nsCOMPtr sup(do_QueryInterface(context)); diff --git a/mozilla/layout/base/nsPresContext.cpp b/mozilla/layout/base/nsPresContext.cpp index 0434712ede8..7c644ed0bab 100644 --- a/mozilla/layout/base/nsPresContext.cpp +++ b/mozilla/layout/base/nsPresContext.cpp @@ -46,6 +46,9 @@ #include "nsIBox.h" #include "nsIDOMElement.h" #include "nsContentPolicyUtils.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMWindow.h" +#include "nsNetUtil.h" #include "nsXPIDLString.h" #include "prprf.h" #ifdef IBMBIDI @@ -1230,14 +1233,30 @@ nsPresContext::StartLoadImage(const nsString& aURL, element = do_QueryInterface(content); } - if (NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::CONTENT_IMAGE, - aURL, element, &shouldLoad)) + nsCOMPtr uri; + nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL); + if (NS_FAILED(rv)) { + NS_ASSERTION(0, "was expecting a URI"); + return NS_OK; + } + + nsCOMPtr document; + rv = mShell->GetDocument(getter_AddRefs(document)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr globalScript; + rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr domWin(do_QueryInterface(globalScript)); + + if (NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE, + uri, element, domWin, &shouldLoad)) && !shouldLoad) { return NS_OK; } // Create image group if needed - nsresult rv; if (!mImageGroup) { nsCOMPtr group; rv = GetImageGroup(getter_AddRefs(group)); // sets mImageGroup as side effect diff --git a/mozilla/layout/base/src/nsPresContext.cpp b/mozilla/layout/base/src/nsPresContext.cpp index 0434712ede8..7c644ed0bab 100644 --- a/mozilla/layout/base/src/nsPresContext.cpp +++ b/mozilla/layout/base/src/nsPresContext.cpp @@ -46,6 +46,9 @@ #include "nsIBox.h" #include "nsIDOMElement.h" #include "nsContentPolicyUtils.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMWindow.h" +#include "nsNetUtil.h" #include "nsXPIDLString.h" #include "prprf.h" #ifdef IBMBIDI @@ -1230,14 +1233,30 @@ nsPresContext::StartLoadImage(const nsString& aURL, element = do_QueryInterface(content); } - if (NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::CONTENT_IMAGE, - aURL, element, &shouldLoad)) + nsCOMPtr uri; + nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL); + if (NS_FAILED(rv)) { + NS_ASSERTION(0, "was expecting a URI"); + return NS_OK; + } + + nsCOMPtr document; + rv = mShell->GetDocument(getter_AddRefs(document)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr globalScript; + rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr domWin(do_QueryInterface(globalScript)); + + if (NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE, + uri, element, domWin, &shouldLoad)) && !shouldLoad) { return NS_OK; } // Create image group if needed - nsresult rv; if (!mImageGroup) { nsCOMPtr group; rv = GetImageGroup(getter_AddRefs(group)); // sets mImageGroup as side effect diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index 92b9487c92d..1dee4e55a4f 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -71,6 +71,8 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsContentPolicyUtils.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMWindow.h" #ifdef DEBUG @@ -1479,29 +1481,35 @@ nsImageFrame::CanLoadImage(nsIURI *aURI) return PR_FALSE; } #endif - // XXX leave this if 0'd until there is a good way to test it. -#if 0 // Check with the content-policy things to make sure this load is permitted. nsresult rv; nsCOMPtr element(do_QueryInterface(mContent)); if (!element) // this would seem bad(tm) - return PR_FALSE; + return shouldLoad; - nsXPIDLCString uric; - aURI->GetSpec(getter_Copies(uric)); + nsCOMPtr document; + if (mContent) { + rv = mContent->GetDocument(*getter_AddRefs(document)); + if (NS_FAILED(rv)) { + NS_ASSERTION(0, "expecting a document"); + return shouldLoad; + } - nsString uri = NS_ConvertUTF8toUCS2(uric); - - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::CONTENT_IMAGE, - uri, element, &shouldLoad); - if (NS_SUCCEEDED(rv) && !shouldLoad) - return PR_FALSE; + nsCOMPtr globalScript; + rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript)); + if (NS_FAILED(rv)) return shouldLoad; + nsCOMPtr domWin(do_QueryInterface(globalScript)); + rv = NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE, + aURI, element, domWin, &shouldLoad); + if (NS_SUCCEEDED(rv) && !shouldLoad) + return shouldLoad; + } + /* ... additional checks ? */ -#endif return shouldLoad; } diff --git a/mozilla/layout/generic/nsObjectFrame.cpp b/mozilla/layout/generic/nsObjectFrame.cpp index 9a087dbd34f..48a536ced0b 100644 --- a/mozilla/layout/generic/nsObjectFrame.cpp +++ b/mozilla/layout/generic/nsObjectFrame.cpp @@ -57,6 +57,7 @@ #include "nsIWebBrowserChrome.h" #include "nsIDOMElement.h" #include "nsContentPolicyUtils.h" +#include "nsIDOMWindow.h" #include "nsIDOMMouseListener.h" #include "nsIDOMFocusListener.h" #include "nsIDOMEventReceiver.h" @@ -966,7 +967,7 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsIPluginHost* aPluginHost, const char* aMimetype, - nsIURI* aURL) + nsIURI* aURI) { nsIView *parentWithView; nsPoint origin; @@ -975,7 +976,7 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext, aPresContext->GetTwipsToPixels(&t2p); - SetFullURL(aURL); + SetFullURL(aURI); // we need to recalculate this now that we have access to the nsPluginInstanceOwner // and its size info (as set in the tag) @@ -1013,27 +1014,36 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext, #endif // Check to see if content-policy wants to veto this - if(aURL != nsnull) + if(aURI != nsnull) { PRBool shouldLoad = PR_TRUE; // default permit nsresult rv; nsCOMPtr element = do_QueryInterface(mContent, &rv); + if (NS_FAILED(rv)) return rv; - // For pinkerton: a symphony for string conversion, in 3 parts. - nsXPIDLCString urlCString; - aURL->GetSpec(getter_Copies(urlCString)); - nsAutoString url; - url.AssignWithConversion((const char *)urlCString); + nsCOMPtr shell; + rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr document; + rv = shell->GetDocument(getter_AddRefs(document)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr globalScript; + rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr domWin(do_QueryInterface(globalScript)); if (NS_SUCCEEDED(rv) && - NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::CONTENT_OBJECT, - url, element, &shouldLoad)) && + NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::OBJECT, + aURI, element, domWin, &shouldLoad)) && !shouldLoad) { return NS_OK; } } - return aPluginHost->InstantiateEmbededPlugin(aMimetype, aURL, mInstanceOwner); + return aPluginHost->InstantiateEmbededPlugin(aMimetype, aURI, mInstanceOwner); } // This is called when the page containing plugin is resized, and plugin has its dimensions diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index 92b9487c92d..1dee4e55a4f 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -71,6 +71,8 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); #include "nsContentPolicyUtils.h" +#include "nsIScriptGlobalObject.h" +#include "nsIDOMWindow.h" #ifdef DEBUG @@ -1479,29 +1481,35 @@ nsImageFrame::CanLoadImage(nsIURI *aURI) return PR_FALSE; } #endif - // XXX leave this if 0'd until there is a good way to test it. -#if 0 // Check with the content-policy things to make sure this load is permitted. nsresult rv; nsCOMPtr element(do_QueryInterface(mContent)); if (!element) // this would seem bad(tm) - return PR_FALSE; + return shouldLoad; - nsXPIDLCString uric; - aURI->GetSpec(getter_Copies(uric)); + nsCOMPtr document; + if (mContent) { + rv = mContent->GetDocument(*getter_AddRefs(document)); + if (NS_FAILED(rv)) { + NS_ASSERTION(0, "expecting a document"); + return shouldLoad; + } - nsString uri = NS_ConvertUTF8toUCS2(uric); - - rv = NS_CheckContentLoadPolicy(nsIContentPolicy::CONTENT_IMAGE, - uri, element, &shouldLoad); - if (NS_SUCCEEDED(rv) && !shouldLoad) - return PR_FALSE; + nsCOMPtr globalScript; + rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript)); + if (NS_FAILED(rv)) return shouldLoad; + nsCOMPtr domWin(do_QueryInterface(globalScript)); + rv = NS_CheckContentLoadPolicy(nsIContentPolicy::IMAGE, + aURI, element, domWin, &shouldLoad); + if (NS_SUCCEEDED(rv) && !shouldLoad) + return shouldLoad; + } + /* ... additional checks ? */ -#endif return shouldLoad; } diff --git a/mozilla/layout/html/base/src/nsObjectFrame.cpp b/mozilla/layout/html/base/src/nsObjectFrame.cpp index 9a087dbd34f..48a536ced0b 100644 --- a/mozilla/layout/html/base/src/nsObjectFrame.cpp +++ b/mozilla/layout/html/base/src/nsObjectFrame.cpp @@ -57,6 +57,7 @@ #include "nsIWebBrowserChrome.h" #include "nsIDOMElement.h" #include "nsContentPolicyUtils.h" +#include "nsIDOMWindow.h" #include "nsIDOMMouseListener.h" #include "nsIDOMFocusListener.h" #include "nsIDOMEventReceiver.h" @@ -966,7 +967,7 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext, const nsHTMLReflowState& aReflowState, nsIPluginHost* aPluginHost, const char* aMimetype, - nsIURI* aURL) + nsIURI* aURI) { nsIView *parentWithView; nsPoint origin; @@ -975,7 +976,7 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext, aPresContext->GetTwipsToPixels(&t2p); - SetFullURL(aURL); + SetFullURL(aURI); // we need to recalculate this now that we have access to the nsPluginInstanceOwner // and its size info (as set in the tag) @@ -1013,27 +1014,36 @@ nsObjectFrame::InstantiatePlugin(nsIPresContext* aPresContext, #endif // Check to see if content-policy wants to veto this - if(aURL != nsnull) + if(aURI != nsnull) { PRBool shouldLoad = PR_TRUE; // default permit nsresult rv; nsCOMPtr element = do_QueryInterface(mContent, &rv); + if (NS_FAILED(rv)) return rv; - // For pinkerton: a symphony for string conversion, in 3 parts. - nsXPIDLCString urlCString; - aURL->GetSpec(getter_Copies(urlCString)); - nsAutoString url; - url.AssignWithConversion((const char *)urlCString); + nsCOMPtr shell; + rv = aPresContext->GetShell(getter_AddRefs(shell)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr document; + rv = shell->GetDocument(getter_AddRefs(document)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr globalScript; + rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr domWin(do_QueryInterface(globalScript)); if (NS_SUCCEEDED(rv) && - NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::CONTENT_OBJECT, - url, element, &shouldLoad)) && + NS_SUCCEEDED(NS_CheckContentLoadPolicy(nsIContentPolicy::OBJECT, + aURI, element, domWin, &shouldLoad)) && !shouldLoad) { return NS_OK; } } - return aPluginHost->InstantiateEmbededPlugin(aMimetype, aURL, mInstanceOwner); + return aPluginHost->InstantiateEmbededPlugin(aMimetype, aURI, mInstanceOwner); } // This is called when the page containing plugin is resized, and plugin has its dimensions