Commit a8b46244 authored by Bill Budge's avatar Bill Budge Committed by Commit Bot

[wasm][code cache] Match response to cached raw resource

- Verifies that the retrieved resource has the same response time, and
  that the source matches (i.e. both are from service worker, or both
  are not).

Bug: chromium:1146673

Change-Id: I6243ec9017b2405687056aa6ea199c67b1c16063
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2526802Reviewed-by: default avatarYutaka Hirano <yhirano@chromium.org>
Reviewed-by: default avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Bill Budge <bbudge@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826277}
parent 51e4a2a1
......@@ -208,7 +208,8 @@ class ExceptionToAbortStreamingScope {
};
RawResource* GetRawResource(ScriptState* script_state,
const String& url_string) {
const String& url_string,
Response* response) {
ExecutionContext* execution_context = ExecutionContext::From(script_state);
if (!execution_context)
return nullptr;
......@@ -222,6 +223,18 @@ RawResource* GetRawResource(ScriptState* script_state,
if (!resource)
return nullptr;
// Make sure the resource matches the |response|. To check that, we make sure
// the response times match, and the response sources match.
const ResourceResponse& resource_response = resource->GetResponse();
const FetchResponseData* fetch_response_data =
response->GetResponse()->InternalResponse();
if (resource_response.ResponseTime() != fetch_response_data->ResponseTime())
return nullptr;
bool from_service_worker = fetch_response_data->ResponseSource() ==
network::mojom::FetchResponseSource::kUnspecified;
if (resource_response.WasFetchedViaServiceWorker() != from_service_worker)
return nullptr;
// Wasm modules should be fetched as raw resources.
DCHECK_EQ(ResourceType::kRaw, resource->GetType());
return ToRawResource(resource);
......@@ -349,13 +362,12 @@ void StreamFromResponseCallback(
String url = response->url();
const std::string& url_utf8 = url.Utf8();
streaming->SetUrl(url_utf8.c_str(), url_utf8.size());
RawResource* raw_resource = GetRawResource(script_state, url);
if (raw_resource) {
SingleCachedMetadataHandler* cache_handler =
raw_resource->ScriptCacheHandler();
RawResource* resource = GetRawResource(script_state, url, response);
if (resource) {
SingleCachedMetadataHandler* cache_handler = resource->ScriptCacheHandler();
if (cache_handler) {
auto client = std::make_shared<WasmStreamingClient>(
url, raw_resource->GetResponse().ResponseTime());
url, resource->GetResponse().ResponseTime());
streaming->SetClient(client);
scoped_refptr<CachedMetadata> cached_module =
cache_handler->GetCachedMetadata(kWasmModuleTag);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment