Skip to content

Commit

Permalink
Bug 1110469 - Remove NS_OpenURI (r=sworkman)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christoph Kerschbaumer committed Jan 12, 2015
1 parent 1969a22 commit 54b8e4e
Show file tree
Hide file tree
Showing 12 changed files with 122 additions and 292 deletions.
3 changes: 1 addition & 2 deletions dom/plugins/base/nsPluginHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 3 additions & 5 deletions dom/xul/XULDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2711,19 +2711,17 @@ 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;
}

// 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
Expand Down
13 changes: 8 additions & 5 deletions editor/libeditor/nsHTMLDataTransfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 11 additions & 6 deletions intl/hyphenation/hnjstdio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion intl/strres/nsStringBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 11 additions & 8 deletions intl/strres/nsStringBundleTextOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nsIInputStream> in;
rv = NS_OpenURI(getter_AddRefs(in),
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 rv;
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIInputStream> in;
rv = channel->Open(getter_AddRefs(in));
NS_ENSURE_SUCCESS(rv, rv);

static NS_DEFINE_CID(kPersistentPropertiesCID, NS_IPERSISTENTPROPERTIES_CID);
mValues = do_CreateInstance(kPersistentPropertiesCID, &rv);
Expand Down
4 changes: 2 additions & 2 deletions js/xpconnect/loader/mozJSSubScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
52 changes: 22 additions & 30 deletions layout/style/Loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1464,58 +1464,50 @@ 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
// we should always have a requestingNode, or we are loading something
// 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"));
SheetComplete(aLoadData, rv);
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,
Expand Down
42 changes: 25 additions & 17 deletions modules/libjar/nsJARChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,33 +862,41 @@ 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...
rv = NS_NewDownloader(getter_AddRefs(mDownloader), this);
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.
Expand Down
Loading

0 comments on commit 54b8e4e

Please sign in to comment.