Bug 1110469 - Remove NS_OpenURI (r=sworkman)

This commit is contained in:
Christoph Kerschbaumer 2015-01-11 20:26:40 -08:00
Родитель 1969a22887
Коммит 54b8e4e5e4
12 изменённых файлов: 122 добавлений и 292 удалений

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

@ -580,8 +580,7 @@ nsresult nsPluginHost::PostURL(nsISupports* pluginInst,
}
}
// if we don't have a target, just create a stream. This does
// NS_OpenURI()!
// if we don't have a target, just create a stream.
if (streamListener)
rv = NewPluginURLStream(NS_ConvertUTF8toUTF16(url), instance,
streamListener,

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

@ -2711,11 +2711,9 @@ XULDocument::LoadOverlayInternal(nsIURI* aURI, bool aIsDynamic,
// OnStopRequest, so it needs a Terminate.
parser->Terminate();
// Just move on to the next overlay. NS_OpenURI could fail
// just because a channel could not be opened, which can happen
// if a file or chrome package does not exist.
// Just move on to the next overlay.
ReportMissingOverlay(aURI);
// XXX the error could indicate an internal error as well...
*aFailureFromContent = true;
return rv;
@ -2723,7 +2721,7 @@ XULDocument::LoadOverlayInternal(nsIURI* aURI, bool aIsDynamic,
// If it's a 'chrome:' prototype document, then put it into
// the prototype cache; other XUL documents will be reloaded
// each time. We must do this after NS_OpenURI and AsyncOpen,
// each time. We must do this after AsyncOpen,
// or chrome code will wrongly create a cached chrome channel
// instead of a real one. Prototypes are only cached when the
// document to be overlayed is chrome to avoid caching overlay

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

@ -1083,12 +1083,15 @@ nsresult nsHTMLEditor::InsertObject(const char* aType, nsISupports* aObject, boo
nsCOMPtr<nsIInputStream> imageStream;
if (insertAsImage) {
NS_ASSERTION(fileURI, "The file URI should be retrieved earlier");
rv = NS_OpenURI(getter_AddRefs(imageStream),
fileURI,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
fileURI,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
NS_ENSURE_SUCCESS(rv, rv);
rv = channel->Open(getter_AddRefs(imageStream));
NS_ENSURE_SUCCESS(rv, rv);
} else {
imageStream = do_QueryInterface(aObject);

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

@ -36,13 +36,18 @@ hnjFopen(const char* aURISpec, const char* aMode)
return nullptr;
}
nsCOMPtr<nsIInputStream> instream;
rv = NS_OpenURI(getter_AddRefs(instream),
uri,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
uri,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
if (NS_FAILED(rv)) {
return nullptr;
}
nsCOMPtr<nsIInputStream> instream;
rv = channel->Open(getter_AddRefs(instream));
if (NS_FAILED(rv)) {
return nullptr;
}

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

@ -69,7 +69,6 @@ nsStringBundle::LoadProperties()
rv = NS_NewURI(getter_AddRefs(uri), mPropertiesURL);
if (NS_FAILED(rv)) return rv;
// We don't use NS_OpenURI because we want to tweak the channel
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
uri,

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

@ -146,16 +146,19 @@ nsStringBundleTextOverride::Init()
nsCOMPtr<nsIURI> uri;
rv = NS_NewURI(getter_AddRefs(uri), customStringsURLSpec);
if (NS_FAILED(rv)) return rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
uri,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> in;
rv = NS_OpenURI(getter_AddRefs(in),
uri,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
if (NS_FAILED(rv)) return rv;
rv = channel->Open(getter_AddRefs(in));
NS_ENSURE_SUCCESS(rv, rv);
static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
mValues = do_CreateInstance(kPersistentPropertiesCID, &rv);

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

@ -136,8 +136,8 @@ mozJSSubScriptLoader::ReadScript(nsIURI *uri, JSContext *cx, JSObject *targetObj
script.set(nullptr);
function.set(nullptr);
// Instead of calling NS_OpenURI, we create the channel ourselves and call
// SetContentType, to avoid expensive MIME type lookups (bug 632490).
// We create a channel and call SetContentType, to avoid expensive MIME type
// lookups (bug 632490).
nsCOMPtr<nsIChannel> chan;
nsCOMPtr<nsIInputStream> instream;
nsresult rv;

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

@ -1464,24 +1464,19 @@ Loader::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
}
// Just load it
nsCOMPtr<nsIInputStream> stream;
nsCOMPtr<nsIChannel> channel;
// Note that we are calling NS_OpenURIInternal() with both a node and a
// principal. This is because of a case where the node is the document
// being styled and the principal is the stylesheet (perhaps from a
// different origin) that is applying the styles.
// Note that we are calling NS_NewChannelWithTriggeringPrincipal() with both
// a node and a principal.
// This is because of a case where the node is the document being styled and
// the principal is the stylesheet (perhaps from a different origin) that is
// applying the styles.
if (aLoadData->mRequestingNode) {
rv = NS_OpenURIWithTriggeringPrincipal(getter_AddRefs(stream),
aLoadData->mURI,
aLoadData->mRequestingNode,
triggeringPrincipal,
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
nullptr, // aLoadGroup
nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL,
nullptr, // aIoService
getter_AddRefs(channel));
rv = NS_NewChannelWithTriggeringPrincipal(getter_AddRefs(channel),
aLoadData->mURI,
aLoadData->mRequestingNode,
triggeringPrincipal,
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
}
else {
// either we are loading something inside a document, in which case
@ -1489,17 +1484,16 @@ Loader::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
// outside a document, in which case the triggeringPrincipal
// should always be the systemPrincipal.
MOZ_ASSERT(nsContentUtils::IsSystemPrincipal(triggeringPrincipal));
rv = NS_OpenURI(getter_AddRefs(stream),
aLoadData->mURI,
triggeringPrincipal,
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
nullptr, // aLoadGroup
nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL,
nullptr, // aIoService
getter_AddRefs(channel));
rv = NS_NewChannel(getter_AddRefs(channel),
aLoadData->mURI,
triggeringPrincipal,
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
}
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> stream;
rv = channel->Open(getter_AddRefs(stream));
if (NS_FAILED(rv)) {
LOG_ERROR((" Failed to open URI synchronously"));
@ -1507,15 +1501,13 @@ Loader::LoadSheet(SheetLoadData* aLoadData, StyleSheetState aSheetState)
return rv;
}
NS_ASSERTION(channel, "NS_OpenURI lied?");
// Force UA sheets to be UTF-8.
// XXX this is only necessary because the default in
// SheetLoadData::OnDetermineCharset is wrong (bug 521039).
channel->SetContentCharset(NS_LITERAL_CSTRING("UTF-8"));
// Manually feed the streamloader the contents of the stream we
// got from NS_OpenURI. This will call back into OnStreamComplete
// Manually feed the streamloader the contents of the stream.
// This will call back into OnStreamComplete
// and thence to ParseSheet. Regardless of whether this fails,
// SheetComplete has been called.
return nsSyncLoadService::PushSyncStreamToListener(stream,

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

@ -862,6 +862,8 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
mListenerContext = ctx;
mIsPending = true;
nsCOMPtr<nsIChannel> channel;
if (!mJarFile) {
// Not a local file...
// kick off an async download of the base URI...
@ -869,26 +871,32 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
if (NS_SUCCEEDED(rv)) {
// Since we might not have a loadinfo on all channels yet
// we have to provide default arguments in case mLoadInfo is null;
uint32_t loadFlags =
mLoadFlags & ~(LOAD_DOCUMENT_URI | LOAD_CALL_CONTENT_SNIFFERS);
if (mLoadInfo) {
rv = NS_OpenURIInternal(mDownloader,
nullptr, // aContext
mJarBaseURI,
mLoadInfo,
mLoadGroup,
mCallbacks,
mLoadFlags & ~(LOAD_DOCUMENT_URI | LOAD_CALL_CONTENT_SNIFFERS));
rv = NS_NewChannelInternal(getter_AddRefs(channel),
mJarBaseURI,
mLoadInfo,
mLoadGroup,
mCallbacks,
loadFlags);
} else {
rv = NS_NewChannel(getter_AddRefs(channel),
mJarBaseURI,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
mLoadGroup,
mCallbacks,
loadFlags);
}
else {
rv = NS_OpenURI(mDownloader,
nullptr, // aContext
mJarBaseURI,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
mLoadGroup,
mCallbacks,
mLoadFlags & ~(LOAD_DOCUMENT_URI | LOAD_CALL_CONTENT_SNIFFERS));
if (NS_FAILED(rv)) {
mIsPending = false;
mListenerContext = nullptr;
mListener = nullptr;
return rv;
}
channel->AsyncOpen(mDownloader, nullptr);
}
} else if (mOpeningRemote) {
// nothing to do: already asked parent to open file.

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

@ -189,7 +189,7 @@ NS_NewFileURI(nsIURI* *result,
/*
* How to create a new Channel, using NS_NewChannel,
* NS_NewChannelWithTriggeringPrincipal, NS_OpenURI,
* NS_NewChannelWithTriggeringPrincipal,
* NS_NewInputStreamChannel, NS_NewChannelInternal
* and it's variations:
*
@ -449,189 +449,6 @@ NS_NewChannel(nsIChannel** outChannel,
aIoService);
}
// Use this function with CAUTION. It creates a stream that blocks when you
// Read() from it and blocking the UI thread is a bad idea. If you don't want
// to implement a full blown asynchronous consumer (via nsIStreamListener) look
// at nsIStreamLoader instead.
inline nsresult
NS_OpenURIInternal(nsIInputStream** outStream,
nsIURI* aUri,
nsINode* aLoadingNode,
nsIPrincipal* aLoadingPrincipal,
nsIPrincipal* aTriggeringPrincipal,
nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType,
nsILoadGroup* aLoadGroup = nullptr,
nsIInterfaceRequestor* aCallbacks = nullptr,
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
nsIIOService* aIoService = nullptr, // pass in nsIIOService to optimize callers
nsIChannel** outChannel = nullptr)
{
NS_ASSERTION(aLoadingPrincipal, "Can not create channel without a loading Principal!");
nsCOMPtr<nsIChannel> channel;
nsresult rv = NS_NewChannelInternal(getter_AddRefs(channel),
aUri,
aLoadingNode,
aLoadingPrincipal,
aTriggeringPrincipal,
aSecurityFlags,
aContentPolicyType,
aLoadGroup,
aCallbacks,
aLoadFlags,
aIoService);
NS_ENSURE_SUCCESS(rv, rv);
nsIInputStream *stream;
rv = channel->Open(&stream);
NS_ENSURE_SUCCESS(rv, rv);
*outStream = stream;
if (outChannel) {
*outChannel = nullptr;
channel.swap(*outChannel);
}
return NS_OK;
}
inline nsresult /* NS_OpenURIprincipal */
NS_OpenURI(nsIInputStream** outStream,
nsIURI* aUri,
nsIPrincipal* aLoadingPrincipal,
nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType,
nsILoadGroup* aLoadGroup = nullptr,
nsIInterfaceRequestor* aCallbacks = nullptr,
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
nsIIOService* aIoService = nullptr,
nsIChannel** outChannel = nullptr)
{
return NS_OpenURIInternal(outStream,
aUri,
nullptr, // aLoadingNode
aLoadingPrincipal,
nullptr, // aTriggeringPrincipal
aSecurityFlags,
aContentPolicyType,
aLoadGroup,
aCallbacks,
aLoadFlags,
aIoService,
outChannel);
}
inline nsresult /* NS_OpenURIWithTriggeringPrincipalAndNode */
NS_OpenURIWithTriggeringPrincipal(nsIInputStream** outStream,
nsIURI* aUri,
nsINode* aLoadingNode,
nsIPrincipal* aTriggeringPrincipal,
nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType,
nsILoadGroup* aLoadGroup = nullptr,
nsIInterfaceRequestor* aCallbacks = nullptr,
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
nsIIOService* aIoService = nullptr,
nsIChannel** outChannel = nullptr)
{
MOZ_ASSERT(aLoadingNode);
NS_ASSERTION(aTriggeringPrincipal, "Can not open uri without a triggering Principal!");
return NS_OpenURIInternal(outStream,
aUri,
aLoadingNode,
aLoadingNode->NodePrincipal(),
aTriggeringPrincipal,
aSecurityFlags,
aContentPolicyType,
aLoadGroup,
aCallbacks,
aLoadFlags,
aIoService,
outChannel);
}
inline nsresult
NS_OpenURIInternal(nsIStreamListener* aListener,
nsISupports* aContext,
nsIURI* aUri,
nsILoadInfo* aLoadInfo,
nsILoadGroup* aLoadGroup = nullptr,
nsIInterfaceRequestor* aCallbacks = nullptr,
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
nsIIOService* aIoService = nullptr)
{
nsCOMPtr<nsIChannel> channel;
nsresult rv = NS_NewChannelInternal(getter_AddRefs(channel),
aUri,
aLoadInfo,
aLoadGroup,
aCallbacks,
aLoadFlags,
aIoService);
NS_ENSURE_SUCCESS(rv, rv);
return channel->AsyncOpen(aListener, aContext);
}
inline nsresult
NS_OpenURIInternal(nsIStreamListener* aListener,
nsISupports* aContext,
nsIURI* aUri,
nsINode* aLoadingNode,
nsIPrincipal* aLoadingPrincipal,
nsIPrincipal* aTriggeringPrincipal,
nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType,
nsILoadGroup* aLoadGroup = nullptr,
nsIInterfaceRequestor* aCallbacks = nullptr,
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
nsIIOService* aIoService = nullptr)
{
NS_ASSERTION(aLoadingPrincipal, "Can not create channel without a loading Principal!");
nsCOMPtr<nsILoadInfo> loadInfo =
new mozilla::LoadInfo(aLoadingPrincipal,
aTriggeringPrincipal,
aLoadingNode,
aSecurityFlags,
aContentPolicyType);
if (!loadInfo) {
return NS_ERROR_UNEXPECTED;
}
return NS_OpenURIInternal(aListener,
aContext,
aUri,
loadInfo,
aLoadGroup,
aCallbacks,
aLoadFlags,
aIoService);
}
inline nsresult
NS_OpenURI(nsIStreamListener* aListener,
nsISupports* aContext,
nsIURI* aUri,
nsIPrincipal* aLoadingPrincipal,
nsSecurityFlags aSecurityFlags,
nsContentPolicyType aContentPolicyType,
nsILoadGroup* aLoadGroup = nullptr,
nsIInterfaceRequestor* aCallbacks = nullptr,
nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL,
nsIIOService* aIoService = nullptr)
{
return NS_OpenURIInternal(aListener,
aContext,
aUri,
nullptr, // aLoadingNode
aLoadingPrincipal,
nullptr, // aTriggeringPrincipal
aSecurityFlags,
aContentPolicyType,
aLoadGroup,
aCallbacks,
aLoadFlags,
aIoService);
}
inline nsresult
NS_MakeAbsoluteURI(nsACString &result,
const nsACString &spec,
@ -1744,27 +1561,29 @@ NS_LoadPersistentPropertiesFromURI(nsIPersistentProperties** outResult,
nsContentPolicyType aContentPolicyType,
nsIIOService* aIoService = nullptr)
{
nsCOMPtr<nsIInputStream> in;
nsresult rv = NS_OpenURI(getter_AddRefs(in),
aUri,
aLoadingPrincipal,
nsILoadInfo::SEC_NORMAL,
aContentPolicyType,
nullptr, // aLoadGroup
nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL, //aLoadFlags
aIoService);
nsCOMPtr<nsIChannel> channel;
nsresult rv = NS_NewChannel(getter_AddRefs(channel),
aUri,
aLoadingPrincipal,
nsILoadInfo::SEC_NORMAL,
aContentPolicyType,
nullptr, // aLoadGroup
nullptr, // aCallbacks
nsIRequest::LOAD_NORMAL,
aIoService);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> in;
rv = channel->Open(getter_AddRefs(in));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIPersistentProperties> properties =
do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = properties->Load(in);
if (NS_SUCCEEDED(rv)) {
*outResult = nullptr;
properties.swap(*outResult);
}
return rv;
NS_ENSURE_SUCCESS(rv, rv);
properties.swap(*outResult);
return NS_OK;
}
inline nsresult

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

@ -59,13 +59,16 @@ main(int argc, char **argv)
rv = secman->GetSystemPrincipal(getter_AddRefs(systemPrincipal));
RETURN_IF_FAILED(rv, "Couldn't get system principal!");
rv = NS_OpenURI(getter_AddRefs(stream),
uri,
systemPrincipal,
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
uri,
systemPrincipal,
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER);
RETURN_IF_FAILED(rv, "NS_NewChannel");
RETURN_IF_FAILED(rv, "NS_OpenURI");
rv = channel->Open(getter_AddRefs(stream));
RETURN_IF_FAILED(rv, "channel->Open()");
FILE* outfile = fopen(argv[2], "wb");
if (!outfile) {

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

@ -955,16 +955,17 @@ RDFXMLDataSourceImpl::Refresh(bool aBlocking)
}
else {
// Null LoadGroup ?
rv = NS_OpenURI(this,
nullptr, // aContext
mURL,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
nullptr, // aLoadGroup
this); // aCallbacks
if (NS_FAILED(rv)) return rv;
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
mURL,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_NORMAL,
nsIContentPolicy::TYPE_OTHER,
nullptr, // aLoadGroup
this); // aCallbacks
NS_ENSURE_SUCCESS(rv, rv);
rv = channel->AsyncOpen(this, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
// So we don't try to issue two asynchronous loads at once.
mLoadState = eLoadState_Pending;