Bug 1363482: Part 3 - Preload string bundles off-thread during startup. r=erahm

MozReview-Commit-ID: 3Fig5BS9xMz

--HG--
extra : rebase_source : 0eab403521cdb37c86a66f61c0cbcf291b699041
This commit is contained in:
Kris Maglione 2017-08-31 17:23:08 -07:00
Родитель c4a2fd3bfb
Коммит 5395a3712b
1 изменённых файлов: 23 добавлений и 14 удалений

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

@ -25,6 +25,9 @@
#include "nsIErrorService.h"
#include "nsICategoryManager.h"
#include "nsContentUtils.h"
#include "nsStringStream.h"
#include "mozilla/ResultExtensions.h"
#include "mozilla/URLPreloader.h"
// for async loading
#ifdef ASYNC_LOADING
@ -93,21 +96,27 @@ nsStringBundle::LoadProperties()
return NS_ERROR_ABORT;
}
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
uri,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER);
if (NS_FAILED(rv)) return rv;
// It's a string bundle. We expect a text/plain type, so set that as hint
channel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
nsCOMPtr<nsIInputStream> in;
rv = channel->Open2(getter_AddRefs(in));
if (NS_FAILED(rv)) return rv;
auto result = URLPreloader::ReadURI(uri);
if (result.isOk()) {
MOZ_TRY(NS_NewCStringInputStream(getter_AddRefs(in), result.unwrap()));
} else {
nsCOMPtr<nsIChannel> channel;
rv = NS_NewChannel(getter_AddRefs(channel),
uri,
nsContentUtils::GetSystemPrincipal(),
nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL,
nsIContentPolicy::TYPE_OTHER);
if (NS_FAILED(rv)) return rv;
// It's a string bundle. We expect a text/plain type, so set that as hint
channel->SetContentType(NS_LITERAL_CSTRING("text/plain"));
rv = channel->Open2(getter_AddRefs(in));
if (NS_FAILED(rv)) return rv;
}
NS_ASSERTION(NS_SUCCEEDED(rv) && in, "Error in OpenBlockingStream");
NS_ENSURE_TRUE(NS_SUCCEEDED(rv) && in, NS_ERROR_FAILURE);