Bug 1487100 - Allow calling nsICacheInfoChannel.preferAlternativeDataType(altDataType, contentType) multiple times r=michal,luke

This patch changes the way we set and handle the preferred alternate data type.
It is no longer just one choice, but a set of preferences, each conditional
on the contentType of the resource.

For example:
  var cc = chan.QueryInterface(Ci.nsICacheInfoChannel);
  cc.preferAlternativeDataType("js-bytecode", "text/javascript");
  cc.preferAlternativeDataType("ammended-text", "text/plain");
  cc.preferAlternativeDataType("something-else", "");

When loaded from the cache, the available alt-data type will be checked against
"js-bytecode" if the contentType is "text/javascript", "ammended-text" if the contentType is "text/plain" or "something-else" for all contentTypes.
Note that the alt-data type could be "something-else" even if the contentType is "text/javascript".

The preferences are saved as an nsTArray<mozilla::Tuple<nsCString, nsCString>>.

Differential Revision: https://phabricator.services.mozilla.com/D8071
This commit is contained in:
Valentin Gosu
2018-10-17 13:58:30 +00:00
parent 3ae0be7f6f
commit c5da4687a9
29 changed files with 193 additions and 85 deletions

View File

@@ -1109,7 +1109,7 @@ ScriptLoader::StartLoad(ScriptLoadRequest* aRequest)
// Inform the HTTP cache that we prefer to have information coming from the
// bytecode cache instead of the sources, if such entry is already registered.
LOG(("ScriptLoadRequest (%p): Maybe request bytecode", aRequest));
cic->PreferAlternativeDataType(nsContentUtils::JSBytecodeMimeType());
cic->PreferAlternativeDataType(nsContentUtils::JSBytecodeMimeType(), EmptyCString());
} else {
// If we are explicitly loading from the sources, such as after a
// restarted request, we might still want to save the bytecode after.
@@ -1118,7 +1118,7 @@ ScriptLoader::StartLoad(ScriptLoadRequest* aRequest)
// does not exist, such that we can later save the bytecode with a
// different alternative data type.
LOG(("ScriptLoadRequest (%p): Request saving bytecode later", aRequest));
cic->PreferAlternativeDataType(kNullMimeType);
cic->PreferAlternativeDataType(kNullMimeType, EmptyCString());
}
}