Backed out changeset dc42de66de8c (bug 1243791) landing with wrong bug number

--HG--
extra : rebase_source : b016defba5a12065b401d0d59b3f03e8b1d7cbe1
This commit is contained in:
Carsten "Tomcat" Book 2016-05-10 12:50:15 +02:00
Родитель 391584fd9d
Коммит a993b36b4a
17 изменённых файлов: 155 добавлений и 383 удалений

2
dom/cache/CacheTypes.ipdlh поставляемый
Просмотреть файл

@ -79,7 +79,7 @@ union CacheRequestOrVoid
struct CacheResponse
{
ResponseType type;
nsCString[] urlList;
nsCString url;
uint32_t status;
nsCString statusText;
HeadersEntry[] headers;

245
dom/cache/DBSchema.cpp поставляемый
Просмотреть файл

@ -37,7 +37,7 @@ const int32_t kFirstShippedSchemaVersion = 15;
namespace {
// Update this whenever the DB schema is changed.
const int32_t kLatestSchemaVersion = 21;
const int32_t kLatestSchemaVersion = 20;
// ---------
// The following constants define the SQL schema. These are defined in the
@ -95,6 +95,7 @@ const char* const kTableEntries =
"request_cache INTEGER NOT NULL, "
"request_body_id TEXT NULL, "
"response_type INTEGER NOT NULL, "
"response_url TEXT NOT NULL, "
"response_status INTEGER NOT NULL, "
"response_status_text TEXT NOT NULL, "
"response_headers_guard INTEGER NOT NULL, "
@ -142,12 +143,6 @@ const char* const kIndexResponseHeadersName =
"CREATE INDEX response_headers_name_index "
"ON response_headers (name)";
const char* const kTableResponseUrlList =
"CREATE TABLE response_url_list ("
"url TEXT NOT NULL, "
"entry_id INTEGER NOT NULL REFERENCES entries(id) ON DELETE CASCADE"
")";
// NOTE: key allows NULL below since that is how "" is represented
// in a BLOB column. We use BLOB to avoid encoding issues
// with storing DOMStrings.
@ -463,9 +458,6 @@ CreateOrMigrateSchema(mozIStorageConnection* aConn)
rv = aConn->ExecuteSimpleSQL(nsDependentCString(kIndexResponseHeadersName));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = aConn->ExecuteSimpleSQL(nsDependentCString(kTableResponseUrlList));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = aConn->ExecuteSimpleSQL(nsDependentCString(kTableStorage));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
@ -1661,6 +1653,7 @@ InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
"request_redirect, "
"request_body_id, "
"response_type, "
"response_url, "
"response_status, "
"response_status_text, "
"response_headers_guard, "
@ -1684,6 +1677,7 @@ InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
":request_redirect, "
":request_body_id, "
":response_type, "
":response_url, "
":response_status, "
":response_status_text, "
":response_headers_guard, "
@ -1761,6 +1755,10 @@ InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
static_cast<int32_t>(aResponse.type()));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
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"),
aResponse.status());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
@ -1875,27 +1873,6 @@ InsertEntry(mozIStorageConnection* aConn, CacheId aCacheId,
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
}
rv = aConn->CreateStatement(NS_LITERAL_CSTRING(
"INSERT INTO response_url_list ("
"url, "
"entry_id "
") VALUES (:url, :entry_id)"
), getter_AddRefs(state));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
const nsTArray<nsCString>& responseUrlList = aResponse.urlList();
for (uint32_t i = 0; i < responseUrlList.Length(); ++i) {
rv = state->BindUTF8StringByName(NS_LITERAL_CSTRING("url"),
responseUrlList[i]);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->BindInt64ByName(NS_LITERAL_CSTRING("entry_id"), entryId);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->Execute();
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
}
return rv;
}
@ -1911,6 +1888,7 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
nsresult rv = aConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT "
"entries.response_type, "
"entries.response_url, "
"entries.response_status, "
"entries.response_status_text, "
"entries.response_headers_guard, "
@ -1936,32 +1914,35 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aSavedResponseOut->mValue.type() = static_cast<ResponseType>(type);
rv = state->GetUTF8String(1, aSavedResponseOut->mValue.url());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
int32_t status;
rv = state->GetInt32(1, &status);
rv = state->GetInt32(2, &status);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aSavedResponseOut->mValue.status() = status;
rv = state->GetUTF8String(2, aSavedResponseOut->mValue.statusText());
rv = state->GetUTF8String(3, aSavedResponseOut->mValue.statusText());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
int32_t guard;
rv = state->GetInt32(3, &guard);
rv = state->GetInt32(4, &guard);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aSavedResponseOut->mValue.headersGuard() =
static_cast<HeadersGuardEnum>(guard);
bool nullBody = false;
rv = state->GetIsNull(4, &nullBody);
rv = state->GetIsNull(5, &nullBody);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aSavedResponseOut->mHasBodyId = !nullBody;
if (aSavedResponseOut->mHasBodyId) {
rv = ExtractId(state, 4, &aSavedResponseOut->mBodyId);
rv = ExtractId(state, 5, &aSavedResponseOut->mBodyId);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
}
nsAutoCString serializedInfo;
rv = state->GetUTF8String(5, serializedInfo);
rv = state->GetUTF8String(6, serializedInfo);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aSavedResponseOut->mValue.principalInfo() = void_t();
@ -1977,7 +1958,7 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
mozilla::ipc::ContentPrincipalInfo(attrs, originNoSuffix);
}
rv = state->GetBlobAsUTF8String(6, aSavedResponseOut->mValue.channelInfo().securityInfo());
rv = state->GetBlobAsUTF8String(7, aSavedResponseOut->mValue.channelInfo().securityInfo());
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = aConn->CreateStatement(NS_LITERAL_CSTRING(
@ -2004,26 +1985,6 @@ ReadResponse(mozIStorageConnection* aConn, EntryId aEntryId,
aSavedResponseOut->mValue.headers().AppendElement(header);
}
rv = aConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT "
"url "
"FROM response_url_list "
"WHERE entry_id=:entry_id;"
), getter_AddRefs(state));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
rv = state->BindInt32ByName(NS_LITERAL_CSTRING("entry_id"), aEntryId);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
while (NS_SUCCEEDED(state->ExecuteStep(&hasMoreData)) && hasMoreData) {
nsCString url;
rv = state->GetUTF8String(0, url);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aSavedResponseOut->mValue.urlList().AppendElement(url);
}
return rv;
}
@ -2396,7 +2357,6 @@ Validate(mozIStorageConnection* aConn)
Expect("request_headers", "table", kTableRequestHeaders),
Expect("response_headers", "table", kTableResponseHeaders),
Expect("response_headers_name_index", "index", kIndexResponseHeadersName),
Expect("response_url_list", "table", kTableResponseUrlList),
Expect("storage", "table", kTableStorage),
Expect("sqlite_autoindex_storage_1", "index"), // auto-gen by sqlite
};
@ -2476,7 +2436,6 @@ nsresult MigrateFrom16To17(mozIStorageConnection* aConn, bool& aRewriteSchema);
nsresult MigrateFrom17To18(mozIStorageConnection* aConn, bool& aRewriteSchema);
nsresult MigrateFrom18To19(mozIStorageConnection* aConn, bool& aRewriteSchema);
nsresult MigrateFrom19To20(mozIStorageConnection* aConn, bool& aRewriteSchema);
nsresult MigrateFrom20To21(mozIStorageConnection* aConn, bool& aRewriteSchema);
// Configure migration functions to run for the given starting version.
Migration sMigrationList[] = {
@ -2485,7 +2444,6 @@ Migration sMigrationList[] = {
Migration(17, MigrateFrom17To18),
Migration(18, MigrateFrom18To19),
Migration(19, MigrateFrom19To20),
Migration(20, MigrateFrom20To21),
};
uint32_t sMigrationListLength = sizeof(sMigrationList) / sizeof(Migration);
@ -2572,6 +2530,9 @@ nsresult MigrateFrom15To16(mozIStorageConnection* aConn, bool& aRewriteSchema)
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
mozStorageTransaction trans(aConn, true,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
// Add the request_redirect column with a default value of "follow". Note,
// we only use a default value here because its required by ALTER TABLE and
// we need to apply the default "follow" to existing records in the table.
@ -2729,6 +2690,9 @@ MigrateFrom17To18(mozIStorageConnection* aConn, bool& aRewriteSchema)
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
mozStorageTransaction trans(aConn, true,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
// This migration is needed in order to remove "only-if-cached" RequestCache
// values from the database. This enum value was removed from the spec in
// https://github.com/whatwg/fetch/issues/39 but we unfortunately happily
@ -2756,6 +2720,9 @@ MigrateFrom18To19(mozIStorageConnection* aConn, bool& aRewriteSchema)
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
mozStorageTransaction trans(aConn, true,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
// This migration is needed in order to update the RequestMode values for
// Request objects corresponding to a navigation content policy type to
// "navigate".
@ -2784,6 +2751,9 @@ nsresult MigrateFrom19To20(mozIStorageConnection* aConn, bool& aRewriteSchema)
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
mozStorageTransaction trans(aConn, true,
mozIStorageConnection::TRANSACTION_IMMEDIATE);
// Add the request_referrer_policy column with a default value of
// "no-referrer-when-downgrade". Note, we only use a default value here
// because its required by ALTER TABLE and we need to apply the default
@ -2803,159 +2773,6 @@ nsresult MigrateFrom19To20(mozIStorageConnection* aConn, bool& aRewriteSchema)
return rv;
}
nsresult MigrateFrom20To21(mozIStorageConnection* aConn, bool& aRewriteSchema)
{
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aConn);
// This migration creates response_url_list table to store response_url and
// removes the response_url column from the entries table.
// sqlite doesn't support removing a column from a table using ALTER TABLE,
// so we need to create a new table without those columns, fill it up with the
// existing data, and then drop the original table and rename the new one to
// the old one.
// Create a new_entries table with the new fields as of version 21.
nsresult rv = aConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"CREATE TABLE new_entries ("
"id INTEGER NOT NULL PRIMARY KEY, "
"request_method TEXT NOT NULL, "
"request_url_no_query TEXT NOT NULL, "
"request_url_no_query_hash BLOB NOT NULL, "
"request_url_query TEXT NOT NULL, "
"request_url_query_hash BLOB NOT NULL, "
"request_referrer TEXT NOT NULL, "
"request_headers_guard INTEGER NOT NULL, "
"request_mode INTEGER NOT NULL, "
"request_credentials INTEGER NOT NULL, "
"request_contentpolicytype INTEGER NOT NULL, "
"request_cache INTEGER NOT NULL, "
"request_body_id TEXT NULL, "
"response_type INTEGER NOT NULL, "
"response_status INTEGER NOT NULL, "
"response_status_text TEXT NOT NULL, "
"response_headers_guard INTEGER NOT NULL, "
"response_body_id TEXT NULL, "
"response_security_info_id INTEGER NULL REFERENCES security_info(id), "
"response_principal_info TEXT NOT NULL, "
"cache_id INTEGER NOT NULL REFERENCES caches(id) ON DELETE CASCADE, "
"request_redirect INTEGER NOT NULL, "
"request_referrer_policy INTEGER NOT NULL"
")"
));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
// Create a response_url_list table with the new fields as of version 21.
rv = aConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"CREATE TABLE response_url_list ("
"url TEXT NOT NULL, "
"entry_id INTEGER NOT NULL REFERENCES entries(id) ON DELETE CASCADE"
")"
));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
// Copy all of the data to the newly created entries table.
rv = aConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"INSERT INTO new_entries ("
"id, "
"request_method, "
"request_url_no_query, "
"request_url_no_query_hash, "
"request_url_query, "
"request_url_query_hash, "
"request_referrer, "
"request_headers_guard, "
"request_mode, "
"request_credentials, "
"request_contentpolicytype, "
"request_cache, "
"request_redirect, "
"request_referrer_policy, "
"request_body_id, "
"response_type, "
"response_status, "
"response_status_text, "
"response_headers_guard, "
"response_body_id, "
"response_security_info_id, "
"response_principal_info, "
"cache_id "
") SELECT "
"id, "
"request_method, "
"request_url_no_query, "
"request_url_no_query_hash, "
"request_url_query, "
"request_url_query_hash, "
"request_referrer, "
"request_headers_guard, "
"request_mode, "
"request_credentials, "
"request_contentpolicytype, "
"request_cache, "
"request_redirect, "
"request_referrer_policy, "
"request_body_id, "
"response_type, "
"response_status, "
"response_status_text, "
"response_headers_guard, "
"response_body_id, "
"response_security_info_id, "
"response_principal_info, "
"cache_id "
"FROM entries;"
));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
// Copy reponse_url to the newly created response_url_list table.
rv = aConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"INSERT INTO response_url_list ("
"url, "
"entry_id "
") SELECT "
"response_url, "
"id "
"FROM entries;"
));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
// Remove the old table.
rv = aConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"DROP TABLE entries;"
));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
// Rename new_entries to entries.
rv = aConn->ExecuteSimpleSQL(NS_LITERAL_CSTRING(
"ALTER TABLE new_entries RENAME to entries;"
));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
// Now, recreate our indices.
rv = aConn->ExecuteSimpleSQL(nsDependentCString(kIndexEntriesRequest));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
// Revalidate the foreign key constraints, and ensure that there are no
// violations.
nsCOMPtr<mozIStorageStatement> state;
rv = aConn->CreateStatement(NS_LITERAL_CSTRING(
"PRAGMA foreign_key_check;"
), getter_AddRefs(state));
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
bool hasMoreData = false;
rv = state->ExecuteStep(&hasMoreData);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
if (NS_WARN_IF(hasMoreData)) { return NS_ERROR_FAILURE; }
rv = aConn->SetSchemaVersion(21);
if (NS_WARN_IF(NS_FAILED(rv))) { return rv; }
aRewriteSchema = true;
return rv;
}
} // anonymous namespace

23
dom/cache/TypeUtils.cpp поставляемый
Просмотреть файл

@ -203,15 +203,15 @@ TypeUtils::ToCacheResponseWithoutBody(CacheResponse& aOut,
{
aOut.type() = aIn.Type();
aIn.GetUnfilteredURLList(aOut.urlList());
AutoTArray<nsCString, 4> urlList;
aIn.GetURLList(urlList);
aIn.GetUnfilteredUrl(aOut.url());
for (uint32_t i = 0; i < aOut.urlList().Length(); i++) {
MOZ_ASSERT(!aOut.urlList()[i].IsEmpty());
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.urlList()[i], nullptr, nullptr, nullptr, aRv);
ProcessURL(aOut.url(), nullptr, nullptr, nullptr, aRv);
if (aRv.Failed()) {
return;
}
}
aOut.status() = aIn.GetUnfilteredStatus();
@ -285,7 +285,7 @@ TypeUtils::ToResponse(const CacheResponse& aIn)
RefPtr<InternalResponse> ir = new InternalResponse(aIn.status(),
aIn.statusText());
ir->SetURLList(aIn.urlList());
ir->SetUrl(aIn.url());
RefPtr<InternalHeaders> internalHeaders =
ToInternalHeaders(aIn.headers(), aIn.headersGuard());
@ -332,13 +332,14 @@ TypeUtils::ToResponse(const CacheResponse& aIn)
already_AddRefed<InternalRequest>
TypeUtils::ToInternalRequest(const CacheRequest& aIn)
{
nsAutoCString url(aIn.urlWithoutQuery());
url.Append(aIn.urlQuery());
RefPtr<InternalRequest> internalRequest = new InternalRequest(url);
RefPtr<InternalRequest> internalRequest = new InternalRequest();
internalRequest->SetMethod(aIn.method());
nsAutoCString url(aIn.urlWithoutQuery());
url.Append(aIn.urlQuery());
internalRequest->SetURL(url);
internalRequest->SetReferrer(aIn.referrer());
internalRequest->SetReferrerPolicy(aIn.referrerPolicy());
internalRequest->SetMode(aIn.mode());

6
dom/cache/test/xpcshell/test_migration.js поставляемый
Просмотреть файл

@ -31,12 +31,6 @@ function run_test() {
ok(responseList.length > 0, 'should have at least one response in cache');
responseList.forEach(function(response) {
ok(response, 'each response in list should be non-null');
// reponse.url is a empty string in current test file. It should test for
// not being a empty string once thet test file is updated.
ok(typeof response.url === 'string', 'each response.url in list should be a string');
// reponse.redirected may be changed once test file is updated. It should
// be false since current reponse.url is a empty string.
ok(response.redirected === false, 'each response.redirected in list should be false');
do_check_eq(response.headers.get('Content-Type'), 'text/plain;charset=UTF-8',
'the response should have the correct header');
});

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

@ -373,15 +373,18 @@ FetchDriver::HttpFetch()
already_AddRefed<InternalResponse>
FetchDriver::BeginAndGetFilteredResponse(InternalResponse* aResponse,
nsIURI* aFinalURI,
bool aFoundOpaqueRedirect)
{
MOZ_ASSERT(aResponse);
AutoTArray<nsCString, 4> reqURLList;
mRequest->GetURLList(reqURLList);
MOZ_ASSERT(!reqURLList.IsEmpty());
aResponse->SetURLList(reqURLList);
nsAutoCString reqURL;
if (aFinalURI) {
aFinalURI->GetSpec(reqURL);
} else {
mRequest->GetURL(reqURL);
}
DebugOnly<nsresult> rv = aResponse->StripFragmentAndSetUrl(reqURL);
MOZ_ASSERT(NS_SUCCEEDED(rv));
RefPtr<InternalResponse> filteredResponse;
if (aFoundOpaqueRedirect) {
@ -486,6 +489,20 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest,
// On a successful redirect we perform the following substeps of HTTP Fetch,
// step 5, "redirect status", step 11.
// Step 11.5 "Append locationURL to request's url list." so that when we set the
// Response's URL from the Request's URL in Main Fetch, step 15, we get the
// final value. Note, we still use a single URL value instead of a list.
// Because of that we only need to do this after the request finishes.
nsCOMPtr<nsIURI> newURI;
rv = NS_GetFinalChannelURI(channel, getter_AddRefs(newURI));
if (NS_FAILED(rv)) {
FailWithNetworkError();
return rv;
}
nsAutoCString newUrl;
newURI->GetSpec(newUrl);
mRequest->SetURL(newUrl);
bool foundOpaqueRedirect = false;
if (httpChannel) {
@ -590,7 +607,8 @@ FetchDriver::OnStartRequest(nsIRequest* aRequest,
// Resolves fetch() promise which may trigger code running in a worker. Make
// sure the Response is fully initialized before calling this.
mResponse = BeginAndGetFilteredResponse(response, foundOpaqueRedirect);
mResponse = BeginAndGetFilteredResponse(response, channelURI,
foundOpaqueRedirect);
nsCOMPtr<nsIEventTarget> sts = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
@ -669,24 +687,6 @@ FetchDriver::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
SetRequestHeaders(httpChannel);
}
// "HTTP-redirect fetch": step 14 "Append locationURL to request's URL list."
nsCOMPtr<nsIURI> uri;
MOZ_ALWAYS_SUCCEEDS(aNewChannel->GetURI(getter_AddRefs(uri)));
nsCOMPtr<nsIURI> uriClone;
nsresult rv = uri->CloneIgnoringRef(getter_AddRefs(uriClone));
if(NS_WARN_IF(NS_FAILED(rv))){
return rv;
}
nsCString spec;
rv = uriClone->GetSpec(spec);
if(NS_WARN_IF(NS_FAILED(rv))){
return rv;
}
mRequest->AddURL(spec);
aCallback->OnRedirectVerifyCallback(NS_OK);
return NS_OK;
}

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

@ -96,8 +96,9 @@ private:
nsresult ContinueFetch();
nsresult HttpFetch();
// Returns the filtered response sent to the observer.
// Callers who don't have access to a channel can pass null for aFinalURI.
already_AddRefed<InternalResponse>
BeginAndGetFilteredResponse(InternalResponse* aResponse,
BeginAndGetFilteredResponse(InternalResponse* aResponse, nsIURI* aFinalURI,
bool aFoundOpaqueRedirect);
// Utility since not all cases need to do any post processing of the filtered
// response.

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

@ -23,9 +23,8 @@ namespace dom {
already_AddRefed<InternalRequest>
InternalRequest::GetRequestConstructorCopy(nsIGlobalObject* aGlobal, ErrorResult& aRv) const
{
MOZ_RELEASE_ASSERT(!mURLList.IsEmpty(), "Internal Request's urlList should not be empty when copied from constructor.");
RefPtr<InternalRequest> copy = new InternalRequest(mURLList.LastElement());
RefPtr<InternalRequest> copy = new InternalRequest();
copy->mURL.Assign(mURL);
copy->SetMethod(mMethod);
copy->mHeaders = new InternalHeaders(*mHeaders);
copy->SetUnsafeRequest();
@ -78,7 +77,7 @@ InternalRequest::Clone()
InternalRequest::InternalRequest(const InternalRequest& aOther)
: mMethod(aOther.mMethod)
, mURLList(aOther.mURLList)
, mURL(aOther.mURL)
, mHeaders(new InternalHeaders(*aOther.mHeaders))
, mContentPolicyType(aOther.mContentPolicyType)
, mReferrer(aOther.mReferrer)

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

@ -88,7 +88,7 @@ class InternalRequest final
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(InternalRequest)
explicit InternalRequest(const nsACString& aURL)
InternalRequest()
: mMethod("GET")
, mHeaders(new InternalHeaders(HeadersGuardEnum::None))
, mContentPolicyType(nsIContentPolicy::TYPE_FETCH)
@ -112,8 +112,6 @@ public:
, mUnsafeRequest(false)
, mUseURLCredentials(false)
{
MOZ_ASSERT(!aURL.IsEmpty());
AddURL(aURL);
}
InternalRequest(const nsACString& aURL,
@ -127,6 +125,7 @@ public:
ReferrerPolicy aReferrerPolicy,
nsContentPolicyType aContentPolicyType)
: mMethod(aMethod)
, mURL(aURL)
, mHeaders(aHeaders)
, mContentPolicyType(aContentPolicyType)
, mReferrer(aReferrer)
@ -146,8 +145,12 @@ public:
, mUnsafeRequest(false)
, mUseURLCredentials(false)
{
MOZ_ASSERT(!aURL.IsEmpty());
AddURL(aURL);
// Normally we strip the fragment from the URL in Request::Constructor.
// If internal code is directly constructing this object they must
// strip the fragment first. Since these should be well formed URLs we
// can use a simple check for a fragment here. The full parser is
// difficult to use off the main thread.
MOZ_ASSERT(mURL.Find(NS_LITERAL_CSTRING("#")) == kNotFound);
}
already_AddRefed<InternalRequest> Clone();
@ -172,34 +175,16 @@ public:
mMethod.LowerCaseEqualsASCII("head");
}
// GetURL should get the request's current url. A request has an associated
// current url. It is a pointer to the last fetch URL in request's url list.
void
GetURL(nsACString& aURL) const
GetURL(nsCString& aURL) const
{
MOZ_RELEASE_ASSERT(!mURLList.IsEmpty(), "Internal Request's urlList should not be empty.");
aURL.Assign(mURLList.LastElement());
}
// AddURL should append the url into url list.
// Normally we strip the fragment from the URL in Request::Constructor.
// If internal code is directly constructing this object they must
// strip the fragment first. Since these should be well formed URLs we
// can use a simple check for a fragment here. The full parser is
// difficult to use off the main thread.
void
AddURL(const nsACString& aURL)
{
MOZ_ASSERT(!aURL.IsEmpty());
mURLList.AppendElement(aURL);
MOZ_ASSERT(mURLList.LastElement().Find(NS_LITERAL_CSTRING("#")) == kNotFound);
aURL.Assign(mURL);
}
void
GetURLList(nsTArray<nsCString>& aURLList)
SetURL(const nsACString& aURL)
{
aURLList.Assign(mURLList);
mURL.Assign(aURL);
}
void
@ -474,8 +459,8 @@ private:
IsWorkerContentPolicy(nsContentPolicyType aContentPolicyType);
nsCString mMethod;
// mURLList: a list of one or more fetch URLs
nsTArray<nsCString> mURLList;
// mURL always stores the url with the ref stripped
nsCString mURL;
RefPtr<InternalHeaders> mHeaders;
nsCOMPtr<nsIInputStream> mBodyStream;

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

@ -87,6 +87,37 @@ InternalResponse::SetPrincipalInfo(UniquePtr<mozilla::ipc::PrincipalInfo> aPrinc
mPrincipalInfo = Move(aPrincipalInfo);
}
nsresult
InternalResponse::StripFragmentAndSetUrl(const nsACString& aUrl)
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIURI> iuri;
nsresult rv;
rv = NS_NewURI(getter_AddRefs(iuri), aUrl);
if(NS_WARN_IF(NS_FAILED(rv))){
return rv;
}
nsCOMPtr<nsIURI> iuriClone;
// We use CloneIgnoringRef to strip away the fragment even if the original URI
// is immutable.
rv = iuri->CloneIgnoringRef(getter_AddRefs(iuriClone));
if(NS_WARN_IF(NS_FAILED(rv))){
return rv;
}
nsCString spec;
rv = iuriClone->GetSpec(spec);
if(NS_WARN_IF(NS_FAILED(rv))){
return rv;
}
SetUrl(spec);
return NS_OK;
}
LoadTainting
InternalResponse::GetTainting() const
{
@ -129,10 +160,9 @@ already_AddRefed<InternalResponse>
InternalResponse::OpaqueRedirectResponse()
{
MOZ_ASSERT(!mWrappedResponse, "Can't OpaqueRedirectResponse a already wrapped response");
MOZ_ASSERT(!mURLList.IsEmpty(), "URLList should not be emtpy for internalResponse");
RefPtr<InternalResponse> response = OpaqueResponse();
response->mType = ResponseType::Opaqueredirect;
response->mURLList = mURLList;
response->mURL = mURL;
return response.forget();
}
@ -142,7 +172,7 @@ InternalResponse::CreateIncompleteCopy()
RefPtr<InternalResponse> copy = new InternalResponse(mStatus, mStatusText);
copy->mType = mType;
copy->mTerminationReason = mTerminationReason;
copy->mURLList = mURLList;
copy->mURL = mURL;
copy->mChannelInfo = mChannelInfo;
if (mPrincipalInfo) {
copy->mPrincipalInfo = MakeUnique<mozilla::ipc::PrincipalInfo>(*mPrincipalInfo);

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

@ -75,56 +75,28 @@ public:
return Type() == ResponseType::Error;
}
// GetUrl should return last fetch URL in response's url list and null if
// response's url list is the empty list.
// FIXME(nsm): Return with exclude fragment.
void
GetURL(nsCString& aURL) const
GetUrl(nsCString& aURL) const
{
// Empty urlList when response is a synthetic response.
if (mURLList.IsEmpty()) {
aURL.Truncate();
return;
}
aURL.Assign(mURLList.LastElement());
aURL.Assign(mURL);
}
void
GetURLList(nsTArray<nsCString>& aURLList) const
{
aURLList.Assign(mURLList);
}
void
GetUnfilteredURL(nsCString& aURL) const
GetUnfilteredUrl(nsCString& aURL) const
{
if (mWrappedResponse) {
return mWrappedResponse->GetURL(aURL);
return mWrappedResponse->GetUrl(aURL);
}
return GetURL(aURL);
return GetUrl(aURL);
}
// SetUrl should only be called when the fragment has alredy been stripped
void
GetUnfilteredURLList(nsTArray<nsCString>& aURLList) const
SetUrl(const nsACString& aURL)
{
if (mWrappedResponse) {
return mWrappedResponse->GetURLList(aURLList);
}
return GetURLList(aURLList);
}
void
SetURLList(const nsTArray<nsCString>& aURLList)
{
mURLList.Assign(aURLList);
#ifdef DEBUG
for(uint32_t i = 0; i < mURLList.Length(); ++i) {
MOZ_ASSERT(mURLList[i].Find(NS_LITERAL_CSTRING("#")) == kNotFound);
}
#endif
mURL.Assign(aURL);
}
uint16_t
@ -239,16 +211,13 @@ public:
return mPrincipalInfo;
}
bool
IsRedirected() const
{
return mURLList.Length() > 1;
}
// Takes ownership of the principal info.
void
SetPrincipalInfo(UniquePtr<mozilla::ipc::PrincipalInfo> aPrincipalInfo);
nsresult
StripFragmentAndSetUrl(const nsACString& aUrl);
LoadTainting
GetTainting() const;
@ -268,10 +237,7 @@ private:
ResponseType mType;
nsCString mTerminationReason;
// A response has an associated url list (a list of zero or more fetch URLs).
// Unless stated otherwise, it is the empty list. The current url is the last
// element in mURLlist
nsTArray<nsCString> mURLList;
nsCString mURL;
const uint16_t mStatus;
const nsCString mStatusText;
RefPtr<InternalHeaders> mHeaders;

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

@ -285,8 +285,18 @@ Request::Constructor(const GlobalObject& aGlobal,
request = inputReq->GetInternalRequest();
} else {
// aInput is USVString.
// We need to get url before we create a InternalRequest.
request = new InternalRequest();
}
request = request->GetRequestConstructorCopy(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RequestMode fallbackMode = RequestMode::EndGuard_;
RequestCredentials fallbackCredentials = RequestCredentials::EndGuard_;
RequestCache fallbackCache = RequestCache::EndGuard_;
if (aInput.IsUSVString()) {
nsAutoString input;
input.Assign(aInput.GetAsUSVString());
@ -307,18 +317,7 @@ Request::Constructor(const GlobalObject& aGlobal,
return nullptr;
}
request = new InternalRequest(NS_ConvertUTF16toUTF8(requestURL));
}
request = request->GetRequestConstructorCopy(global, aRv);
if (NS_WARN_IF(aRv.Failed())) {
return nullptr;
}
RequestMode fallbackMode = RequestMode::EndGuard_;
RequestCredentials fallbackCredentials = RequestCredentials::EndGuard_;
RequestCache fallbackCache = RequestCache::EndGuard_;
if (aInput.IsUSVString()) {
request->SetURL(NS_ConvertUTF16toUTF8(requestURL));
fallbackMode = RequestMode::Cors;
fallbackCredentials = RequestCredentials::Omit;
fallbackCache = RequestCache::Default;

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

@ -46,9 +46,7 @@ public:
void
GetUrl(nsAString& aUrl) const
{
nsAutoCString url;
mRequest->GetURL(url);
CopyUTF8toUTF16(url, aUrl);
CopyUTF8toUTF16(mRequest->mURL, aUrl);
}
void

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

@ -53,16 +53,10 @@ public:
GetUrl(nsAString& aUrl) const
{
nsCString url;
mInternalResponse->GetURL(url);
mInternalResponse->GetUrl(url);
CopyUTF8toUTF16(url, aUrl);
}
bool
Redirected() const
{
return mInternalResponse->IsRedirected();
}
uint16_t
Status() const
{

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

@ -194,8 +194,6 @@ InterceptedErrorResponseWithURL=Failed to load %S. A ServiceWorker passed
InterceptedUsedResponseWithURL=Failed to load %S. A ServiceWorker passed a used Response to FetchEvent.respondWith(). The body of a Response may only be read once. Use Response.clone() to access the body multiple times.
# LOCALIZATION NOTE: Do not translate "ServiceWorker", "opaqueredirect", "Response", "FetchEvent.respondWith()", or "FetchEvent". %s is a URL.
BadOpaqueRedirectInterceptionWithURL=Failed to load %S. A ServiceWorker passed an opaqueredirect Response to FetchEvent.respondWith() while handling a non-navigation FetchEvent.
# LOCALIZATION NOTE: Do not translate "ServiceWorker", "Response", "FetchEvent.respondWith()", "RedirectMode" or "follow". %S is a URL.
BadRedirectModeInterceptionWithURL=Failed to load %S. A ServiceWorker passed a redirected Response to FetchEvent.respondWith() while RedirectMode is not follow.
# LOCALIZATION NOTE: Do not translate "ServiceWorker" or "FetchEvent.preventDefault()". %S is a URL.
InterceptionCanceledWithURL=Failed to load %S. A ServiceWorker canceled the load by calling FetchEvent.preventDefault().
# LOCALIZATION NOTE: Do not translate "ServiceWorker", "promise", or "FetchEvent.respondWith()". %1$S is a URL. %2$S is an error string.

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

@ -17,7 +17,6 @@ interface Response {
readonly attribute ResponseType type;
readonly attribute USVString url;
readonly attribute boolean redirected;
readonly attribute unsigned short status;
readonly attribute boolean ok;
readonly attribute ByteString statusText;

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

@ -250,7 +250,7 @@ public:
nsresult rv;
nsCOMPtr<nsIURI> uri;
nsAutoCString url;
mInternalResponse->GetUnfilteredURL(url);
mInternalResponse->GetUnfilteredUrl(url);
if (url.IsEmpty()) {
// Synthetic response. The buck stops at the worker script.
url = mScriptSpec;
@ -587,8 +587,6 @@ RespondWithHandler::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValu
// * request's mode is not "no-cors" and response's type is "opaque".
// * request's redirect mode is not "manual" and response's type is
// "opaqueredirect".
// * request's redirect mode is not "follow" and response's url list
// has more than one item.
if (response->Type() == ResponseType::Error) {
autoCancel.SetCancelMessage(
@ -617,12 +615,6 @@ RespondWithHandler::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValu
return;
}
if (mRequestRedirectMode != RequestRedirect::Follow && response->Redirected()) {
autoCancel.SetCancelMessage(
NS_LITERAL_CSTRING("BadRedirectModeInterceptionWithURL"), mRequestURL);
return;
}
if (NS_WARN_IF(response->BodyUsed())) {
autoCancel.SetCancelMessage(
NS_LITERAL_CSTRING("InterceptedUsedResponseWithURL"), mRequestURL);
@ -639,7 +631,7 @@ RespondWithHandler::ResolvedCallback(JSContext* aCx, JS::Handle<JS::Value> aValu
// cross-origin responses, which are treated as same-origin by consumers.
nsCString responseURL;
if (response->Type() == ResponseType::Opaque) {
ir->GetUnfilteredURL(responseURL);
ir->GetUnfilteredUrl(responseURL);
if (NS_WARN_IF(responseURL.IsEmpty())) {
return;
}

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

@ -146,13 +146,12 @@ promise_test(function(t) {
assert_resolves(
iframe_test(REDIRECT_TO_HTML_URL),
'Normal redirected iframe loading should succeed.'),
assert_rejects(
assert_resolves(
iframe_test(SCOPE + '?url=' +
encodeURIComponent(REDIRECT_TO_HTML_URL) +
'&redirect-mode=follow',
true /* timeout_enabled */),
'&redirect-mode=follow'),
'Redirected iframe loading with Request.redirect=follow should'+
' fail.'),
' succeed.'),
assert_rejects(
iframe_test(SCOPE + '?url=' +
encodeURIComponent(REDIRECT_TO_HTML_URL) +