Bug 1173439 P1 Store URLs as UTF8 strings in Cache instead of UTF16. r=ehsan

This commit is contained in:
Ben Kelly 2015-06-16 17:39:05 -07:00
parent 1300f42c37
commit f892b6826b
6 changed files with 42 additions and 34 deletions

View File

@ -293,7 +293,7 @@ MatchInPutList(InternalRequest* aRequest,
aRequest->GetURL(url);
// If the URLs don't match, then just skip to the next entry.
if (NS_ConvertUTF8toUTF16(url) != cachedRequest.url()) {
if (url != cachedRequest.url()) {
continue;
}

4
dom/cache/Cache.cpp vendored
View File

@ -39,7 +39,7 @@ IsValidPutRequestURL(const nsAString& aUrl, ErrorResult& aRv)
bool validScheme = false;
// make a copy because ProcessURL strips the fragmet
nsAutoString url(aUrl);
NS_ConvertUTF16toUTF8 url(aUrl);
TypeUtils::ProcessURL(url, &validScheme, nullptr, aRv);
if (aRv.Failed()) {
@ -48,7 +48,7 @@ IsValidPutRequestURL(const nsAString& aUrl, ErrorResult& aRv)
if (!validScheme) {
NS_NAMED_LITERAL_STRING(label, "Request");
aRv.ThrowTypeError(MSG_INVALID_URL_SCHEME, &label, &url);
aRv.ThrowTypeError(MSG_INVALID_URL_SCHEME, &label, &aUrl);
return false;
}

View File

@ -53,8 +53,8 @@ struct HeadersEntry
struct CacheRequest
{
nsCString method;
nsString url;
nsString urlWithoutQuery;
nsCString url;
nsCString urlWithoutQuery;
HeadersEntry[] headers;
HeadersGuardEnum headersGuard;
nsString referrer;
@ -74,7 +74,7 @@ union CacheRequestOrVoid
struct CacheResponse
{
ResponseType type;
nsString url;
nsCString url;
uint32_t status;
nsCString statusText;
HeadersEntry[] headers;

View File

@ -29,11 +29,11 @@ namespace dom {
namespace cache {
namespace db {
const int32_t kMaxWipeSchemaVersion = 13;
const int32_t kMaxWipeSchemaVersion = 14;
namespace {
const int32_t kLatestSchemaVersion = 13;
const int32_t kLatestSchemaVersion = 14;
const int32_t kMaxEntriesPerStatement = 255;
const uint32_t kPageSize = 4 * 1024;
@ -939,7 +939,7 @@ QueryCache(mozIStorageConnection* aConn, CacheId aCacheId,
"AND entries."
);
nsAutoString urlToMatch;
nsAutoCString urlToMatch;
if (aParams.ignoreSearch()) {
urlToMatch = aRequest.urlWithoutQuery();
query.AppendLiteral("request_url_no_query");
@ -957,7 +957,7 @@ QueryCache(mozIStorageConnection* aConn, CacheId aCacheId,
rv = state->BindInt64ByName(NS_LITERAL_CSTRING("cache_id"), aCacheId);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->BindStringByName(NS_LITERAL_CSTRING("url"), urlToMatch);
rv = state->BindUTF8StringByName(NS_LITERAL_CSTRING("url"), urlToMatch);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
bool hasMoreData = false;
@ -1479,12 +1479,12 @@ InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
aRequest.method());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->BindStringByName(NS_LITERAL_CSTRING("request_url"),
aRequest.url());
rv = state->BindUTF8StringByName(NS_LITERAL_CSTRING("request_url"),
aRequest.url());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->BindStringByName(NS_LITERAL_CSTRING("request_url_no_query"),
aRequest.urlWithoutQuery());
rv = state->BindUTF8StringByName(NS_LITERAL_CSTRING("request_url_no_query"),
aRequest.urlWithoutQuery());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->BindStringByName(NS_LITERAL_CSTRING("request_referrer"),
@ -1518,8 +1518,8 @@ InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
static_cast<int32_t>(aResponse.type()));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->BindStringByName(NS_LITERAL_CSTRING("response_url"),
aResponse.url());
rv = state->BindUTF8StringByName(NS_LITERAL_CSTRING("response_url"),
aResponse.url());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->BindInt32ByName(NS_LITERAL_CSTRING("response_status"),
@ -1666,7 +1666,7 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aSavedResponseOut->mValue.type() = static_cast<ResponseType>(type);
rv = state->GetString(1, aSavedResponseOut->mValue.url());
rv = state->GetUTF8String(1, aSavedResponseOut->mValue.url());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
int32_t status;
@ -1767,10 +1767,10 @@ ReadRequest(mozIStorageConnection* aConn, EntryId aEntryId,
rv = state->GetUTF8String(0, aSavedRequestOut->mValue.method());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->GetString(1, aSavedRequestOut->mValue.url());
rv = state->GetUTF8String(1, aSavedRequestOut->mValue.url());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->GetString(2, aSavedRequestOut->mValue.urlWithoutQuery());
rv = state->GetUTF8String(2, aSavedRequestOut->mValue.urlWithoutQuery());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->GetString(3, aSavedRequestOut->mValue.referrer());

View File

@ -23,6 +23,7 @@
#include "nsIAsyncOutputStream.h"
#include "nsIIPCSerializableInputStream.h"
#include "nsQueryObject.h"
#include "nsPromiseFlatString.h"
#include "nsStreamUtils.h"
#include "nsString.h"
#include "nsURLParsers.h"
@ -150,9 +151,7 @@ TypeUtils::ToCacheRequest(CacheRequest& aOut, InternalRequest* aIn,
aIn->GetMethod(aOut.method());
nsAutoCString url;
aIn->GetURL(url);
CopyUTF8toUTF16(url, aOut.url());
aIn->GetURL(aOut.url());
bool schemeValid;
ProcessURL(aOut.url(), &schemeValid, &aOut.urlWithoutQuery(), aRv);
@ -163,7 +162,8 @@ TypeUtils::ToCacheRequest(CacheRequest& aOut, InternalRequest* aIn,
if (!schemeValid) {
if (aSchemeAction == TypeErrorOnInvalidScheme) {
NS_NAMED_LITERAL_STRING(label, "Request");
aRv.ThrowTypeError(MSG_INVALID_URL_SCHEME, &label, &aOut.url());
NS_ConvertUTF8toUTF16 url(aOut.url());
aRv.ThrowTypeError(MSG_INVALID_URL_SCHEME, &label, &url);
return;
}
}
@ -200,11 +200,9 @@ TypeUtils::ToCacheResponseWithoutBody(CacheResponse& aOut,
{
aOut.type() = aIn.Type();
nsAutoCString url;
aIn.GetUrl(url);
CopyUTF8toUTF16(url, aOut.url());
aIn.GetUrl(aOut.url());
if (aOut.url() != EmptyString()) {
if (aOut.url() != EmptyCString()) {
// Pass all Response URL schemes through... The spec only requires we take
// action on invalid schemes for Request objects.
ProcessURL(aOut.url(), nullptr, nullptr, aRv);
@ -279,7 +277,7 @@ TypeUtils::ToResponse(const CacheResponse& aIn)
nsRefPtr<InternalResponse> ir = new InternalResponse(aIn.status(),
aIn.statusText());
ir->SetUrl(NS_ConvertUTF16toUTF8(aIn.url()));
ir->SetUrl(aIn.url());
nsRefPtr<InternalHeaders> internalHeaders =
ToInternalHeaders(aIn.headers(), aIn.headersGuard());
@ -322,7 +320,7 @@ TypeUtils::ToInternalRequest(const CacheRequest& aIn)
nsRefPtr<InternalRequest> internalRequest = new InternalRequest();
internalRequest->SetMethod(aIn.method());
internalRequest->SetURL(NS_ConvertUTF16toUTF8(aIn.url()));
internalRequest->SetURL(aIn.url());
internalRequest->SetReferrer(aIn.referrer());
internalRequest->SetMode(aIn.mode());
internalRequest->SetCredentialsMode(aIn.credentials());
@ -374,10 +372,10 @@ TypeUtils::ToInternalHeaders(const nsTArray<HeadersEntry>& aHeadersEntryList,
// they require going to the main thread.
// static
void
TypeUtils::ProcessURL(nsAString& aUrl, bool* aSchemeValidOut,
nsAString* aUrlWithoutQueryOut, ErrorResult& aRv)
TypeUtils::ProcessURL(nsACString& aUrl, bool* aSchemeValidOut,
nsACString* aUrlWithoutQueryOut, ErrorResult& aRv)
{
NS_ConvertUTF16toUTF8 flatURL(aUrl);
const nsAFlatCString& flatURL = PromiseFlatCString(aUrl);
const char* url = flatURL.get();
// off the main thread URL parsing using nsStdURLParser.

14
dom/cache/TypeUtils.h vendored
View File

@ -100,9 +100,19 @@ public:
ToInternalHeaders(const nsTArray<HeadersEntry>& aHeadersEntryList,
HeadersGuardEnum aGuard = HeadersGuardEnum::None);
// Utility method for parsing a URL and doing associated operations. A mix
// of things are done in this one method to avoid duplicated parsing:
//
// 1) The aUrl argument is modified to strip the fragment
// 2) If aSchemaValidOut is set, then a boolean value is set indicating
// if the aUrl's scheme is valid or not for storing in the cache.
// 3) If aUrlWithoutQueryOut is set, then a url string is provided without
// the search section.
//
// Any errors are thrown on ErrorResult.
static void
ProcessURL(nsAString& aUrl, bool* aSchemeValidOut,
nsAString* aUrlWithoutQueryOut, ErrorResult& aRv);
ProcessURL(nsACString& aUrl, bool* aSchemeValidOut,
nsACString* aUrlWithoutQueryOut, ErrorResult& aRv);
private:
void