Bug 1182543 - Use channel->ascynOpen2 in dom/plugins/base/nsPluginHost.cpp - simplifications in instanceowner (r=sicking)

This commit is contained in:
Christoph Kerschbaumer 2015-08-04 20:06:03 -07:00
parent 5e14023d90
commit e790a1627f
6 changed files with 39 additions and 79 deletions

View File

@ -26,7 +26,7 @@ enum nsPluginTagType {
// Do not make this interface scriptable, because the virtual functions in C++
// blocks will make script call the wrong functions.
[uuid(8ff5f46e-96fa-4905-a75c-35aac30bdcee)]
[uuid(518e7465-e1bc-4490-a30e-0ba9d791aaa8)]
interface nsIPluginInstanceOwner : nsISupports
{
/**
@ -66,7 +66,8 @@ interface nsIPluginInstanceOwner : nsISupports
NS_IMETHOD
GetURL(const char *aURL, const char *aTarget,
nsIInputStream *aPostStream,
void *aHeadersData, uint32_t aHeadersDataLen) = 0;
void *aHeadersData, uint32_t aHeadersDataLen,
bool aDoCheckLoadURIChecks) = 0;
%}
/**

View File

@ -90,8 +90,7 @@ nsPluginStreamToFile::Write(const char* aBuf, uint32_t aCount,
{
mOutputStream->Write(aBuf, aCount, aWriteCount);
mOutputStream->Flush();
mOwner->GetURL(mFileURL.get(), mTarget, nullptr, nullptr, 0);
mOwner->GetURL(mFileURL.get(), mTarget, nullptr, nullptr, 0, false);
return NS_OK;
}
@ -122,7 +121,7 @@ NS_IMETHODIMP
nsPluginStreamToFile::Close(void)
{
mOutputStream->Close();
mOwner->GetURL(mFileURL.get(), mTarget, nullptr, nullptr, 0);
mOwner->GetURL(mFileURL.get(), mTarget, nullptr, nullptr, 0, false);
return NS_OK;
}

View File

@ -88,7 +88,6 @@
#include "nsIWeakReferenceUtils.h"
#include "nsIPresShell.h"
#include "nsPluginNativeWindow.h"
#include "nsIScriptSecurityManager.h"
#include "nsIContentPolicy.h"
#include "nsContentPolicyUtils.h"
#include "mozilla/TimeStamp.h"
@ -516,32 +515,24 @@ nsresult nsPluginHost::GetURLWithHeaders(nsNPAPIPluginInstance* pluginInst,
{
// we can only send a stream back to the plugin (as specified by a
// null target) if we also have a nsNPAPIPluginStreamListener to talk to
if (!target && !streamListener)
if (!target && !streamListener) {
return NS_ERROR_ILLEGAL_VALUE;
}
nsresult rv = NS_OK;
if (target) {
rv = DoURLLoadSecurityCheck(pluginInst, url);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsPluginInstanceOwner> owner = pluginInst->GetOwner();
if (owner) {
if ((0 == PL_strcmp(target, "newwindow")) ||
(0 == PL_strcmp(target, "_new")))
target = "_blank";
else if (0 == PL_strcmp(target, "_current"))
target = "_self";
rv = owner->GetURL(url, target, nullptr, nullptr, 0);
rv = owner->GetURL(url, target, nullptr, nullptr, 0, true);
}
}
if (streamListener)
if (streamListener) {
rv = NewPluginURLStream(NS_ConvertUTF8toUTF16(url), pluginInst,
streamListener, nullptr,
getHeaders, getHeadersLength);
}
return rv;
}
@ -609,28 +600,19 @@ nsresult nsPluginHost::PostURL(nsISupports* pluginInst,
}
if (target) {
rv = DoURLLoadSecurityCheck(instance, url);
NS_ENSURE_SUCCESS(rv, rv);
nsRefPtr<nsPluginInstanceOwner> owner = instance->GetOwner();
if (owner) {
if ((0 == PL_strcmp(target, "newwindow")) ||
(0 == PL_strcmp(target, "_new"))) {
target = "_blank";
} else if (0 == PL_strcmp(target, "_current")) {
target = "_self";
}
rv = owner->GetURL(url, target, postStream,
(void*)postHeaders, postHeadersLength);
(void*)postHeaders, postHeadersLength, true);
}
}
// if we don't have a target, just create a stream.
if (streamListener)
if (streamListener) {
rv = NewPluginURLStream(NS_ConvertUTF8toUTF16(url), instance,
streamListener,
postStream, postHeaders, postHeadersLength);
}
return rv;
}
@ -3531,45 +3513,6 @@ nsresult nsPluginHost::NewPluginURLStream(const nsString& aURL,
return rv;
}
// Called by GetURL and PostURL
nsresult
nsPluginHost::DoURLLoadSecurityCheck(nsNPAPIPluginInstance *aInstance,
const char* aURL)
{
if (!aURL || *aURL == '\0')
return NS_OK;
// get the base URI for the plugin element
nsRefPtr<nsPluginInstanceOwner> owner = aInstance->GetOwner();
if (!owner)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> baseURI = owner->GetBaseURI();
if (!baseURI)
return NS_ERROR_FAILURE;
// Create an absolute URL for the target in case the target is relative
nsCOMPtr<nsIURI> targetURL;
NS_NewURI(getter_AddRefs(targetURL), aURL, baseURI);
if (!targetURL)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocument> doc;
owner->GetDocument(getter_AddRefs(doc));
if (!doc)
return NS_ERROR_FAILURE;
nsresult rv;
nsCOMPtr<nsIScriptSecurityManager> secMan(
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
if (NS_FAILED(rv))
return rv;
return secMan->CheckLoadURIWithPrincipal(doc->NodePrincipal(), targetURL,
nsIScriptSecurityManager::STANDARD);
}
nsresult
nsPluginHost::AddHeadersToChannel(const char *aHeadersData,
uint32_t aHeadersDataLen,

View File

@ -180,10 +180,6 @@ public:
uint32_t getHeadersLength = 0,
const char* getHeaders = nullptr);
nsresult
DoURLLoadSecurityCheck(nsNPAPIPluginInstance *aInstance,
const char* aURL);
nsresult
AddHeadersToChannel(const char *aHeadersData, uint32_t aHeadersDataLen,
nsIChannel *aGenericChannel);

View File

@ -44,6 +44,7 @@ using mozilla::DefaultXDisplay;
#include "nsIFocusManager.h"
#include "nsFocusManager.h"
#include "nsIDOMDragEvent.h"
#include "nsIScriptSecurityManager.h"
#include "nsIScrollableFrame.h"
#include "nsIDocShell.h"
#include "ImageContainer.h"
@ -480,7 +481,8 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL,
const char *aTarget,
nsIInputStream *aPostStream,
void *aHeadersData,
uint32_t aHeadersDataLen)
uint32_t aHeadersDataLen,
bool aDoCheckLoadURIChecks)
{
nsCOMPtr<nsIContent> content = do_QueryReferent(mContent);
if (!content) {
@ -512,17 +514,35 @@ NS_IMETHODIMP nsPluginInstanceOwner::GetURL(const char *aURL,
nsCOMPtr<nsILinkHandler> lh = do_QueryInterface(container);
NS_ENSURE_TRUE(lh, NS_ERROR_FAILURE);
nsAutoString unitarget;
unitarget.AssignASCII(aTarget); // XXX could this be nonascii?
nsAutoString unitarget;
if ((0 == PL_strcmp(aTarget, "newwindow")) ||
(0 == PL_strcmp(aTarget, "_new"))) {
unitarget.AssignASCII("_blank");
}
else if (0 == PL_strcmp(aTarget, "_current")) {
unitarget.AssignASCII("_self");
}
else {
unitarget.AssignASCII(aTarget); // XXX could this be nonascii?
}
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
// Create an absolute URL
nsCOMPtr<nsIURI> uri;
nsresult rv = NS_NewURI(getter_AddRefs(uri), aURL, baseURI);
NS_ENSURE_SUCCESS(rv, NS_ERROR_FAILURE);
if (aDoCheckLoadURIChecks) {
nsCOMPtr<nsIScriptSecurityManager> secMan(
do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv));
NS_ENSURE_TRUE(secMan, NS_ERROR_FAILURE);
rv = secMan->CheckLoadURIWithPrincipal(content->NodePrincipal(), uri,
nsIScriptSecurityManager::STANDARD);
NS_ENSURE_SUCCESS(rv, rv);
}
nsCOMPtr<nsIInputStream> headersDataStream;
if (aPostStream && aHeadersData) {
if (!aHeadersDataLen)

View File

@ -61,7 +61,8 @@ public:
NS_IMETHOD GetURL(const char *aURL, const char *aTarget,
nsIInputStream *aPostStream,
void *aHeadersData, uint32_t aHeadersDataLen) override;
void *aHeadersData, uint32_t aHeadersDataLen,
bool aDoCheckLoadURIChecks) override;
NPBool ConvertPoint(double sourceX, double sourceY, NPCoordinateSpace sourceSpace,
double *destX, double *destY, NPCoordinateSpace destSpace) override;