зеркало из https://github.com/mozilla/gecko-dev.git
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.
This commit is contained in:
Родитель
a962a940a4
Коммит
206a778ca4
|
@ -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<nsIContentPolicy> 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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,8 @@ class nsContentPolicy : public nsIContentPolicy
|
|||
private:
|
||||
nsCOMPtr<nsISupportsArray> mPolicies;
|
||||
NS_IMETHOD CheckPolicy(PRInt32 policyType, PRInt32 contentType,
|
||||
nsIDOMElement *element,
|
||||
const PRUnichar *contentLocation,
|
||||
PRBool *shouldProceed);
|
||||
nsIURI *aURI, nsISupports *context,
|
||||
nsIDOMWindow *window, PRBool *shouldProceed);
|
||||
};
|
||||
|
||||
nsresult
|
||||
|
|
|
@ -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<nsIDOMWindow> 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;
|
||||
|
|
|
@ -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<nsIURI> uri;
|
||||
result = NS_NewURI(getter_AddRefs(uri), aSrc, aBaseURL);
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
result = shell->GetDocument(getter_AddRefs(document));
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||
result = document->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> 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<nsIURI> uri;
|
||||
result = NS_NewURI(getter_AddRefs(uri), aSrc, aBaseURL);
|
||||
if (NS_FAILED(result)) return result;
|
||||
|
||||
nsCOMPtr<nsISupports> sup(do_QueryInterface(context));
|
||||
|
||||
|
|
|
@ -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<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ASSERTION(0, "was expecting a URI");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
rv = mShell->GetDocument(getter_AddRefs(document));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalScript;
|
||||
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> 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<nsIImageGroup> group;
|
||||
rv = GetImageGroup(getter_AddRefs(group)); // sets mImageGroup as side effect
|
||||
|
|
|
@ -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<nsIURI> uri;
|
||||
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_ASSERTION(0, "was expecting a URI");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
rv = mShell->GetDocument(getter_AddRefs(document));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalScript;
|
||||
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> 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<nsIImageGroup> group;
|
||||
rv = GetImageGroup(getter_AddRefs(group)); // sets mImageGroup as side effect
|
||||
|
|
|
@ -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<nsIDOMElement> element(do_QueryInterface(mContent));
|
||||
|
||||
if (!element) // this would seem bad(tm)
|
||||
return PR_FALSE;
|
||||
return shouldLoad;
|
||||
|
||||
nsXPIDLCString uric;
|
||||
aURI->GetSpec(getter_Copies(uric));
|
||||
nsCOMPtr<nsIDocument> 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<nsIScriptGlobalObject> globalScript;
|
||||
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
||||
if (NS_FAILED(rv)) return shouldLoad;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> 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;
|
||||
}
|
||||
|
|
|
@ -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<nsIDOMElement> 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<nsIPresShell> shell;
|
||||
rv = aPresContext->GetShell(getter_AddRefs(shell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
rv = shell->GetDocument(getter_AddRefs(document));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalScript;
|
||||
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> 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
|
||||
|
|
|
@ -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<nsIDOMElement> element(do_QueryInterface(mContent));
|
||||
|
||||
if (!element) // this would seem bad(tm)
|
||||
return PR_FALSE;
|
||||
return shouldLoad;
|
||||
|
||||
nsXPIDLCString uric;
|
||||
aURI->GetSpec(getter_Copies(uric));
|
||||
nsCOMPtr<nsIDocument> 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<nsIScriptGlobalObject> globalScript;
|
||||
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
||||
if (NS_FAILED(rv)) return shouldLoad;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> 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;
|
||||
}
|
||||
|
|
|
@ -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<nsIDOMElement> 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<nsIPresShell> shell;
|
||||
rv = aPresContext->GetShell(getter_AddRefs(shell));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
rv = shell->GetDocument(getter_AddRefs(document));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalScript;
|
||||
rv = document->GetScriptGlobalObject(getter_AddRefs(globalScript));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> 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
|
||||
|
|
Загрузка…
Ссылка в новой задаче