OnionSoup: Combine ApplicationCacheHost and ApplicationCacheHostHelper
This CL is a follow-up of crrev.com/c/1637023.
ApplicationCacheHostHelper is merged to ApplicationCacheHost and
ApplicationCacheHost::BindBackend() is added to bind
AppCacheBackend when the main resource is loaded.
ApplicationCacheHostFor{SharedWorker, Frame} are also changed to
inherit ApplicationCacheHost.
When DocumentLoader creates ApplicationCacheHost, it gets
AppCacheType from WebLocalFrameClient and creates
ApplicationCacheHost based on it. If it has kAppCacheForNone,
it just creates ApplicationCacheHost without binding
AppCacheBackend.
It removes application_cache_host_helper.cc/h and
application_cache_host_client.h.
Bug: 950159
Change-Id: I92a50572a776c18d062aa8f1f2057662a9b91f8f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1657951
Reviewed-by: Marijn Kruisselbrink <mek@chromium.org>
Reviewed-by: Kentaro Hara <haraken@chromium.org>
Commit-Queue: Julie Jeongeun Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#671266}
diff --git a/third_party/blink/renderer/core/dom/document_test.cc b/third_party/blink/renderer/core/dom/document_test.cc
index e5c17b3..9c022cef 100644
--- a/third_party/blink/renderer/core/dom/document_test.cc
+++ b/third_party/blink/renderer/core/dom/document_test.cc
@@ -55,7 +55,6 @@
#include "third_party/blink/renderer/core/html/html_head_element.h"
#include "third_party/blink/renderer/core/html/html_link_element.h"
#include "third_party/blink/renderer/core/loader/appcache/application_cache_host.h"
-#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/page/validation_message_client.h"
@@ -330,21 +329,16 @@
// ValidationMessageClient::trace(visitor); }
};
-class MockApplicationCacheHostHelper
- : public blink::ApplicationCacheHostHelper {
+class MockApplicationCacheHost : public blink::ApplicationCacheHost {
public:
- MockApplicationCacheHostHelper() {}
- ~MockApplicationCacheHostHelper() override = default;
+ MockApplicationCacheHost(DocumentLoader* loader)
+ : blink::ApplicationCacheHost(loader, nullptr, nullptr) {}
+ ~MockApplicationCacheHost() override = default;
void SelectCacheWithoutManifest() override {
without_manifest_was_called_ = true;
}
- bool SelectCacheWithManifest(const blink::KURL& manifestURL) override {
- with_manifest_was_called_ = true;
- return true;
- }
- bool with_manifest_was_called_ = false;
bool without_manifest_was_called_ = false;
};
@@ -883,16 +877,14 @@
TEST_F(DocumentTest, SandboxDisablesAppCache) {
NavigateTo(KURL("https://test.com/foobar/document"), "", "sandbox");
+ GetDocument().Loader()->SetApplicationCacheHostForTesting(
+ MakeGarbageCollected<MockApplicationCacheHost>(GetDocument().Loader()));
ApplicationCacheHost* appcache_host =
GetDocument().Loader()->GetApplicationCacheHost();
- appcache_host->helper_ =
- MakeGarbageCollected<MockApplicationCacheHostHelper>();
appcache_host->SelectCacheWithManifest(
KURL("https://test.com/foobar/manifest"));
- auto* mock_host_helper = static_cast<MockApplicationCacheHostHelper*>(
- appcache_host->helper_.Get());
- EXPECT_FALSE(mock_host_helper->with_manifest_was_called_);
- EXPECT_TRUE(mock_host_helper->without_manifest_was_called_);
+ auto* mock_host = static_cast<MockApplicationCacheHost*>(appcache_host);
+ EXPECT_TRUE(mock_host->without_manifest_was_called_);
}
// Verifies that calling EnsurePaintLocationDataValidForNode cleans compositor
diff --git a/third_party/blink/renderer/core/loader/BUILD.gn b/third_party/blink/renderer/core/loader/BUILD.gn
index 67be642..95aa8ade 100644
--- a/third_party/blink/renderer/core/loader/BUILD.gn
+++ b/third_party/blink/renderer/core/loader/BUILD.gn
@@ -12,13 +12,10 @@
"appcache/application_cache.h",
"appcache/application_cache_host.cc",
"appcache/application_cache_host.h",
- "appcache/application_cache_host_client.h",
"appcache/application_cache_host_for_frame.cc",
"appcache/application_cache_host_for_frame.h",
"appcache/application_cache_host_for_shared_worker.cc",
"appcache/application_cache_host_for_shared_worker.h",
- "appcache/application_cache_host_helper.cc",
- "appcache/application_cache_host_helper.h",
"base_fetch_context.cc",
"base_fetch_context.h",
"cookie_jar.cc",
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host.cc b/third_party/blink/renderer/core/loader/appcache/application_cache_host.cc
index 2c42658..66ef408 100644
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host.cc
+++ b/third_party/blink/renderer/core/loader/appcache/application_cache_host.cc
@@ -32,6 +32,8 @@
#include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h"
#include "third_party/blink/public/mojom/appcache/appcache_info.mojom-blink.h"
+#include "third_party/blink/public/platform/interface_provider.h"
+#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/core/events/application_cache_error_event.h"
#include "third_party/blink/renderer/core/events/progress_event.h"
#include "third_party/blink/renderer/core/frame/deprecation.h"
@@ -47,34 +49,70 @@
#include "third_party/blink/renderer/core/loader/frame_load_request.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h"
#include "third_party/blink/renderer/core/page/frame_tree.h"
-#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
-#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
namespace blink {
+namespace {
+
+// Note: the order of the elements in this array must match those
+// of the EventID enum in appcache_interfaces.h.
+const char* const kEventNames[] = {"Checking", "Error", "NoUpdate",
+ "Downloading", "Progress", "UpdateReady",
+ "Cached", "Obsolete"};
+
+mojom::blink::DocumentInterfaceBroker* GetDocumentInterfaceBroker(
+ LocalFrame* local_frame) {
+ return local_frame->Client()->GetDocumentInterfaceBroker();
+}
+
+} // namespace
+
+ApplicationCacheHost* ApplicationCacheHost::Create(
+ DocumentLoader* document_loader) {
+ DCHECK(document_loader);
+ DCHECK(document_loader->GetFrame());
+ LocalFrame* local_frame = document_loader->GetFrame();
+
+ DCHECK(local_frame->Client());
+ WebLocalFrameClient::AppCacheType type =
+ local_frame->Client()->GetAppCacheType();
+ switch (type) {
+ case WebLocalFrameClient::AppCacheType::kAppCacheForFrame:
+ return MakeGarbageCollected<ApplicationCacheHostForFrame>(
+ document_loader, GetDocumentInterfaceBroker(local_frame),
+ local_frame->GetTaskRunner(TaskType::kNetworking));
+ case WebLocalFrameClient::AppCacheType::kAppCacheForSharedWorker:
+ return MakeGarbageCollected<ApplicationCacheHostForSharedWorker>(
+ document_loader, Thread::Current()->GetTaskRunner());
+ default:
+ return MakeGarbageCollected<ApplicationCacheHost>(document_loader,
+ nullptr, nullptr);
+ }
+ return nullptr;
+}
+
// We provide a custom implementation of this class that calls out to the
// embedding application instead of using WebCore's built in appcache system.
// This file replaces webcore/appcache/ApplicationCacheHost.cpp in our build.
-ApplicationCacheHost::ApplicationCacheHost(DocumentLoader* document_loader)
- : dom_application_cache_(nullptr),
- document_loader_(document_loader),
- defers_events_(true) {
- DCHECK(document_loader_);
-}
+ApplicationCacheHost::ApplicationCacheHost(
+ DocumentLoader* document_loader,
+ mojom::blink::DocumentInterfaceBroker* interface_broker,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner)
+ : document_loader_(document_loader),
+ binding_(this),
+ task_runner_(std::move(task_runner)),
+ interface_broker_(interface_broker) {}
-ApplicationCacheHost::~ApplicationCacheHost() {
- // Verify that detachFromDocumentLoader() has been performed already.
- DCHECK(!helper_);
-}
+ApplicationCacheHost::~ApplicationCacheHost() = default;
void ApplicationCacheHost::WillStartLoading(ResourceRequest& request) {
- if (!IsApplicationCacheEnabled() || !helper_)
+ if (!IsApplicationCacheEnabled() || !backend_host_.is_bound())
return;
- const base::UnguessableToken& host_id = helper_->GetHostID();
+ const base::UnguessableToken& host_id = GetHostID();
if (!host_id.is_empty())
request.SetAppCacheHostID(host_id);
}
@@ -84,84 +122,11 @@
const String& method) {
if (!IsApplicationCacheEnabled())
return;
- // We defer creating the outer host object to avoid spurious
- // creation/destruction around creating empty documents. At this point, we're
- // initiating a main resource load for the document, so its for real.
- DCHECK(document_loader_->GetFrame());
- LocalFrame& frame = *document_loader_->GetFrame();
-
- helper_ = ApplicationCacheHostHelper::Create(&frame, this,
- loader->AppcacheHostId());
- if (!helper_)
- return;
-
- const ApplicationCacheHostHelper* spawning_host_helper = nullptr;
- Frame* spawning_frame = frame.Tree().Parent();
- if (!spawning_frame || !IsA<LocalFrame>(spawning_frame))
- spawning_frame = frame.Loader().Opener();
- if (!spawning_frame || !IsA<LocalFrame>(spawning_frame))
- spawning_frame = &frame;
- if (DocumentLoader* spawning_doc_loader =
- To<LocalFrame>(spawning_frame)->Loader().GetDocumentLoader()) {
- spawning_host_helper =
- spawning_doc_loader->GetApplicationCacheHost()
- ? spawning_doc_loader->GetApplicationCacheHost()->helper_.Get()
- : nullptr;
- }
-
- helper_->WillStartMainResourceRequest(url, method, spawning_host_helper);
-
- // NOTE: The semantics of this method, and others in this interface, are
- // subtly different than the method names would suggest. For example, in this
- // method never returns an appcached response in the SubstituteData out
- // argument, instead we return the appcached response thru the usual resource
- // loading pipeline.
-}
-
-void ApplicationCacheHost::SelectCacheWithoutManifest() {
- if (helper_)
- helper_->SelectCacheWithoutManifest();
-}
-
-void ApplicationCacheHost::SelectCacheWithManifest(const KURL& manifest_url) {
- DCHECK(document_loader_);
-
- LocalFrame* frame = document_loader_->GetFrame();
- Document* document = frame->GetDocument();
- if (document->IsSandboxed(WebSandboxFlags::kOrigin)) {
- // Prevent sandboxes from establishing application caches.
- SelectCacheWithoutManifest();
- return;
- }
- if (document->IsSecureContext()) {
- UseCounter::Count(document,
- WebFeature::kApplicationCacheManifestSelectSecureOrigin);
- } else {
- Deprecation::CountDeprecation(
- document, WebFeature::kApplicationCacheManifestSelectInsecureOrigin);
- Deprecation::CountDeprecationCrossOriginIframe(
- *document, WebFeature::kApplicationCacheManifestSelectInsecureOrigin);
- HostsUsingFeatures::CountAnyWorld(
- *document, HostsUsingFeatures::Feature::
- kApplicationCacheManifestSelectInsecureHost);
- }
- if (helper_ && !helper_->SelectCacheWithManifest(manifest_url)) {
- // It's a foreign entry, restart the current navigation from the top of the
- // navigation algorithm. The navigation will not result in the same resource
- // being loaded, because "foreign" entries are never picked during
- // navigation. see ApplicationCacheGroup::selectCache()
- FrameLoadRequest request(document, ResourceRequest(document->Url()));
- request.SetClientRedirectReason(ClientNavigationReason::kReload);
- frame->Navigate(request, WebFrameLoadType::kReplaceCurrentItem);
- }
-}
-
-void ApplicationCacheHost::DidReceiveResponseForMainResource(
- const ResourceResponse& response) {
- if (helper_) {
- helper_->DidReceiveResponseForMainResource(response);
- }
+ // We defer binding to backend to avoid unnecessary binding around creating
+ // empty documents. At this point, we're initiating a main resource load for
+ // the document, so its for real.
+ BindBackend();
}
void ApplicationCacheHost::SetApplicationCache(
@@ -171,13 +136,10 @@
}
void ApplicationCacheHost::DetachFromDocumentLoader() {
- // Detach from the owning DocumentLoader and let go of
- // ApplicationCacheHostHelper.
+ // Detach from the owning DocumentLoader and close mojo pipes.
SetApplicationCache(nullptr);
- if (helper_) {
- helper_->DetachFromDocumentLoader();
- helper_.Clear();
- }
+ binding_.Close();
+ backend_host_ = nullptr;
document_loader_ = nullptr;
}
@@ -205,36 +167,43 @@
}
ApplicationCacheHost::CacheInfo ApplicationCacheHost::ApplicationCacheInfo() {
- if (!helper_)
- return CacheInfo(NullURL(), 0, 0, 0, 0);
+ if (!backend_host_.is_bound())
+ return CacheInfo();
- ApplicationCacheHostHelper::CacheInfo cache_info;
- helper_->GetAssociatedCacheInfo(&cache_info);
- return CacheInfo(cache_info.manifest_url, cache_info.creation_time,
- cache_info.update_time, cache_info.response_sizes,
- cache_info.padding_sizes);
+ ApplicationCacheHost::CacheInfo cache_info;
+ GetAssociatedCacheInfo(&cache_info);
+ return cache_info;
}
const base::UnguessableToken& ApplicationCacheHost::GetHostID() const {
- if (!helper_)
+ if (!backend_host_.is_bound())
return base::UnguessableToken::Null();
- return helper_->GetHostID();
+ return host_id_;
}
void ApplicationCacheHost::SelectCacheForSharedWorker(
int64_t app_cache_id,
base::OnceClosure completion_callback) {
- helper_->SelectCacheForSharedWorker(app_cache_id,
- std::move(completion_callback));
+ if (!backend_host_.is_bound())
+ return;
+
+ select_cache_for_shared_worker_completion_callback_ =
+ std::move(completion_callback);
+ backend_host_->SelectCacheForSharedWorker(app_cache_id);
}
void ApplicationCacheHost::FillResourceList(
Vector<mojom::blink::AppCacheResourceInfo>* resources) {
DCHECK(resources);
- if (!helper_)
+ if (!backend_host_.is_bound())
return;
- helper_->GetResourceList(resources);
+ if (!cache_info_.is_complete)
+ return;
+ Vector<mojom::blink::AppCacheResourceInfoPtr> boxed_infos;
+ backend_host_->GetResourceList(&boxed_infos);
+ for (auto& b : boxed_infos)
+ resources->emplace_back(std::move(*b));
}
void ApplicationCacheHost::StopDeferringEvents() {
@@ -278,20 +247,40 @@
}
mojom::AppCacheStatus ApplicationCacheHost::GetStatus() const {
- return helper_ ? helper_->GetStatus()
- : mojom::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
+ if (!backend_host_.is_bound())
+ return mojom::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
+ return status_;
}
bool ApplicationCacheHost::Update() {
- return helper_ ? helper_->StartUpdate() : false;
+ if (!backend_host_.is_bound())
+ return false;
+
+ bool result = false;
+ backend_host_->StartUpdate(&result);
+ if (!result)
+ return false;
+ if (status_ == mojom::blink::AppCacheStatus::APPCACHE_STATUS_IDLE ||
+ status_ == mojom::blink::AppCacheStatus::APPCACHE_STATUS_UPDATE_READY) {
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
+ } else {
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
+ backend_host_->GetStatus(&status_);
+ }
+ return true;
}
bool ApplicationCacheHost::SwapCache() {
- bool success = helper_ ? helper_->SwapCache() : false;
- if (success) {
- probe::UpdateApplicationCacheStatus(document_loader_->GetFrame());
- }
- return success;
+ if (!backend_host_.is_bound())
+ return false;
+
+ bool success = false;
+ backend_host_->SwapCache(&success);
+ if (!success)
+ return false;
+ backend_host_->GetStatus(&status_);
+ probe::UpdateApplicationCacheStatus(document_loader_->GetFrame());
+ return true;
}
void ApplicationCacheHost::Abort() {
@@ -305,40 +294,187 @@
->GetOfflineWebApplicationCacheEnabled();
}
-void ApplicationCacheHost::DidChangeCacheAssociation() {
+void ApplicationCacheHost::CacheSelected(mojom::blink::AppCacheInfoPtr info) {
+ if (!backend_host_.is_bound())
+ return;
+
+ cache_info_ = *info;
// FIXME: Prod the inspector to update its notion of what cache the page is
// using.
+ if (select_cache_for_shared_worker_completion_callback_)
+ std::move(select_cache_for_shared_worker_completion_callback_).Run();
}
-void ApplicationCacheHost::NotifyEventListener(
- mojom::AppCacheEventID event_id) {
+void ApplicationCacheHost::EventRaised(mojom::blink::AppCacheEventID event_id) {
+ if (!backend_host_.is_bound())
+ return;
+
+ DCHECK_NE(event_id,
+ mojom::blink::AppCacheEventID::
+ APPCACHE_PROGRESS_EVENT); // See OnProgressEventRaised.
+ DCHECK_NE(event_id,
+ mojom::blink::AppCacheEventID::
+ APPCACHE_ERROR_EVENT); // See OnErrorEventRaised.
+
+ // Emit logging output prior to calling out to script as we can get
+ // deleted within the script event handler.
+ const char kFormatString[] = "Application Cache %s event";
+ String message =
+ String::Format(kFormatString, kEventNames[static_cast<int>(event_id)]);
+ LogMessage(mojom::blink::ConsoleMessageLevel::kInfo, message);
+
+ switch (event_id) {
+ case mojom::blink::AppCacheEventID::APPCACHE_CHECKING_EVENT:
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
+ break;
+ case mojom::blink::AppCacheEventID::APPCACHE_DOWNLOADING_EVENT:
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_DOWNLOADING;
+ break;
+ case mojom::blink::AppCacheEventID::APPCACHE_UPDATE_READY_EVENT:
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UPDATE_READY;
+ break;
+ case mojom::blink::AppCacheEventID::APPCACHE_CACHED_EVENT:
+ case mojom::blink::AppCacheEventID::APPCACHE_NO_UPDATE_EVENT:
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_IDLE;
+ break;
+ case mojom::blink::AppCacheEventID::APPCACHE_OBSOLETE_EVENT:
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_OBSOLETE;
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+
NotifyApplicationCache(event_id, 0, 0,
mojom::AppCacheErrorReason::APPCACHE_UNKNOWN_ERROR,
String(), 0, String());
}
-void ApplicationCacheHost::NotifyProgressEventListener(const KURL&,
- int progress_total,
- int progress_done) {
+void ApplicationCacheHost::ProgressEventRaised(const KURL& url,
+ int num_total,
+ int num_complete) {
+ if (!backend_host_.is_bound())
+ return;
+
+ // Emit logging output prior to calling out to script as we can get
+ // deleted within the script event handler.
+ const char kFormatString[] = "Application Cache Progress event (%d of %d) %s";
+ String message = String::Format(kFormatString, num_complete, num_total,
+ url.GetString().Utf8().c_str());
+ LogMessage(mojom::blink::ConsoleMessageLevel::kInfo, message);
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_DOWNLOADING;
NotifyApplicationCache(mojom::AppCacheEventID::APPCACHE_PROGRESS_EVENT,
- progress_total, progress_done,
+ num_total, num_complete,
mojom::AppCacheErrorReason::APPCACHE_UNKNOWN_ERROR,
String(), 0, String());
}
-void ApplicationCacheHost::NotifyErrorEventListener(
- mojom::AppCacheErrorReason reason,
- const KURL& url,
- int status,
- const String& message) {
- NotifyApplicationCache(mojom::AppCacheEventID::APPCACHE_ERROR_EVENT, 0, 0,
- reason, url.GetString(), status, message);
+void ApplicationCacheHost::ErrorEventRaised(
+ mojom::blink::AppCacheErrorDetailsPtr details) {
+ if (!backend_host_.is_bound())
+ return;
+
+ // Emit logging output prior to calling out to script as we can get
+ // deleted within the script event handler.
+ const char kFormatString[] = "Application Cache Error event: %s";
+ String full_message =
+ String::Format(kFormatString, details->message.Utf8().c_str());
+ LogMessage(mojom::blink::ConsoleMessageLevel::kError, full_message);
+
+ status_ = cache_info_.is_complete
+ ? mojom::blink::AppCacheStatus::APPCACHE_STATUS_IDLE
+ : mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
+ if (details->is_cross_origin) {
+ // Don't leak detailed information to script for cross-origin resources.
+ DCHECK_EQ(mojom::blink::AppCacheErrorReason::APPCACHE_RESOURCE_ERROR,
+ details->reason);
+ NotifyApplicationCache(mojom::AppCacheEventID::APPCACHE_ERROR_EVENT, 0, 0,
+ details->reason, details->url.GetString(), 0,
+ String());
+ } else {
+ NotifyApplicationCache(mojom::AppCacheEventID::APPCACHE_ERROR_EVENT, 0, 0,
+ details->reason, details->url.GetString(),
+ details->status, details->message);
+ }
+}
+
+void ApplicationCacheHost::SelectCacheWithManifest(const KURL& manifest_url) {
+ DCHECK(document_loader_);
+ LocalFrame* frame = document_loader_->GetFrame();
+ Document* document = frame->GetDocument();
+ if (document->IsSandboxed(WebSandboxFlags::kOrigin)) {
+ // Prevent sandboxes from establishing application caches.
+ SelectCacheWithoutManifest();
+ return;
+ }
+ if (document->IsSecureContext()) {
+ UseCounter::Count(document,
+ WebFeature::kApplicationCacheManifestSelectSecureOrigin);
+ } else {
+ Deprecation::CountDeprecation(
+ document, WebFeature::kApplicationCacheManifestSelectInsecureOrigin);
+ Deprecation::CountDeprecationCrossOriginIframe(
+ *document, WebFeature::kApplicationCacheManifestSelectInsecureOrigin);
+ HostsUsingFeatures::CountAnyWorld(
+ *document, HostsUsingFeatures::Feature::
+ kApplicationCacheManifestSelectInsecureHost);
+ }
+}
+
+void ApplicationCacheHost::GetAssociatedCacheInfo(
+ ApplicationCacheHost::CacheInfo* info) {
+ if (!backend_host_.is_bound())
+ return;
+
+ info->manifest_ = cache_info_.manifest_url;
+ if (!cache_info_.is_complete)
+ return;
+ info->creation_time_ = cache_info_.creation_time.ToDoubleT();
+ info->update_time_ = cache_info_.last_update_time.ToDoubleT();
+ info->response_sizes_ = cache_info_.response_sizes;
+ info->padding_sizes_ = cache_info_.padding_sizes;
+}
+
+bool ApplicationCacheHost::BindBackend() {
+ if (!task_runner_)
+ return false;
+
+ // PlzNavigate: The browser passes the ID to be used.
+ if (!document_loader_->AppcacheHostId().is_empty())
+ host_id_ = document_loader_->AppcacheHostId();
+ else
+ host_id_ = base::UnguessableToken::Create();
+
+ mojom::blink::AppCacheFrontendPtr frontend_ptr;
+ binding_.Bind(mojo::MakeRequest(&frontend_ptr, task_runner_), task_runner_);
+
+ if (interface_broker_) {
+ interface_broker_->RegisterAppCacheHost(
+ mojo::MakeRequest(&backend_host_, std::move(task_runner_)),
+ std::move(frontend_ptr), host_id_);
+ return true;
+ }
+
+ DEFINE_STATIC_LOCAL(
+ const mojom::blink::AppCacheBackendPtr, backend_ptr, ([] {
+ mojom::blink::AppCacheBackendPtr result;
+ Platform::Current()->GetInterfaceProvider()->GetInterface(
+ mojo::MakeRequest(&result));
+ return result;
+ }()));
+
+ // Once we have 'WebContextInterfaceBroker', we can call this function through
+ // it like render frame.
+ // Refer to the design document, 'https://bit.ly/2GT0rZv'.
+ backend_ptr.get()->RegisterHost(
+ mojo::MakeRequest(&backend_host_, std::move(task_runner_)),
+ std::move(frontend_ptr), host_id_);
+ return true;
}
void ApplicationCacheHost::Trace(blink::Visitor* visitor) {
visitor->Trace(dom_application_cache_);
visitor->Trace(document_loader_);
- visitor->Trace(helper_);
}
} // namespace blink
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host.h b/third_party/blink/renderer/core/loader/appcache/application_cache_host.h
index 98845bf..1bbdcd19 100644
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host.h
+++ b/third_party/blink/renderer/core/loader/appcache/application_cache_host.h
@@ -35,10 +35,14 @@
#include "base/gtest_prod_util.h"
#include "base/macros.h"
+#include "mojo/public/cpp/bindings/binding.h"
#include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h"
+#include "third_party/blink/public/mojom/appcache/appcache_info.mojom-blink.h"
+#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
+#include "third_party/blink/public/mojom/frame/document_interface_broker.mojom-blink.h"
#include "third_party/blink/renderer/core/core_export.h"
-#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_client.h"
#include "third_party/blink/renderer/platform/heap/handle.h"
+#include "third_party/blink/renderer/platform/loader/fetch/resource_response.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
@@ -47,14 +51,18 @@
class ApplicationCache;
class DocumentLoader;
class ResourceRequest;
-class ResourceResponse;
-class ApplicationCacheHostHelper;
-class CORE_EXPORT ApplicationCacheHost final
+class CORE_EXPORT ApplicationCacheHost
: public GarbageCollectedFinalized<ApplicationCacheHost>,
- public ApplicationCacheHostClient {
+ public mojom::blink::AppCacheFrontend {
public:
- explicit ApplicationCacheHost(DocumentLoader*);
+ static ApplicationCacheHost* Create(DocumentLoader* document_loader);
+ // |interface_broker| can be null for workers and |task_runner| is null for
+ // kAppCacheForNone.
+ explicit ApplicationCacheHost(
+ DocumentLoader* document_loader,
+ mojom::blink::DocumentInterfaceBroker* interface_broker,
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~ApplicationCacheHost() override;
void DetachFromDocumentLoader();
@@ -72,40 +80,23 @@
update_time_(update_time),
response_sizes_(response_sizes),
padding_sizes_(padding_sizes) {}
+ CacheInfo() = default;
KURL manifest_;
- double creation_time_;
- double update_time_;
- int64_t response_sizes_;
- int64_t padding_sizes_;
+ double creation_time_ = 0;
+ double update_time_ = 0;
+ int64_t response_sizes_ = 0;
+ int64_t padding_sizes_ = 0;
};
- void SelectCacheWithoutManifest();
- void SelectCacheWithManifest(const KURL& manifest_url);
-
- // Annotate request for ApplicationCache. This internally calls
- // willStartLoadingMainResource if it's for frame resource or
- // willStartLoadingResource for subresource requests.
+ // Annotate request for ApplicationCache.
void WillStartLoading(ResourceRequest&);
- void WillStartLoadingMainResource(DocumentLoader*,
- const KURL&,
- const String& method);
- void DidReceiveResponseForMainResource(const ResourceResponse&);
- void MainResourceDataReceived(const char* data, size_t length);
-
- mojom::AppCacheStatus GetStatus() const;
+ mojom::blink::AppCacheStatus GetStatus() const;
bool Update();
bool SwapCache();
void Abort();
void SetApplicationCache(ApplicationCache*);
- void NotifyApplicationCache(mojom::AppCacheEventID,
- int progress_total,
- int progress_done,
- mojom::AppCacheErrorReason,
- const String& error_url,
- int error_status,
- const String& error_message);
void
StopDeferringEvents(); // Also raises the events that have been queued up.
@@ -116,22 +107,51 @@
void SelectCacheForSharedWorker(int64_t app_cache_id,
base::OnceClosure completion_callback);
- void Trace(blink::Visitor*);
+ // mojom::blink::AppCacheFrontend
+ void CacheSelected(mojom::blink::AppCacheInfoPtr info) override;
+ void EventRaised(mojom::blink::AppCacheEventID event_id) override;
+ void ProgressEventRaised(const KURL& url,
+ int32_t num_total,
+ int32_t num_complete) override;
+ void ErrorEventRaised(mojom::blink::AppCacheErrorDetailsPtr details) override;
+ void LogMessage(mojom::blink::ConsoleMessageLevel log_level,
+ const String& message) override {}
+ void SetSubresourceFactory(
+ network::mojom::blink::URLLoaderFactoryPtr url_loader_factory) override {}
+
+ virtual void WillStartLoadingMainResource(DocumentLoader* loader,
+ const KURL& url,
+ const String& method);
+ virtual void SelectCacheWithoutManifest() {}
+ virtual void SelectCacheWithManifest(const KURL& manifest_url);
+ virtual void DidReceiveResponseForMainResource(const ResourceResponse&) {}
+ virtual void Trace(blink::Visitor*);
+
+ protected:
+ mojom::blink::AppCacheHostPtr backend_host_;
+ mojom::blink::AppCacheStatus status_ =
+ mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
private:
- // WebApplicationCacheHostClient implementation
- void DidChangeCacheAssociation() final;
- void NotifyEventListener(mojom::AppCacheEventID) final;
- void NotifyProgressEventListener(const KURL&,
- int progress_total,
- int progress_done) final;
- void NotifyErrorEventListener(mojom::AppCacheErrorReason,
- const KURL&,
- int status,
- const String& message) final;
+ void NotifyApplicationCache(mojom::AppCacheEventID,
+ int progress_total,
+ int progress_done,
+ mojom::AppCacheErrorReason,
+ const String& error_url,
+ int error_status,
+ const String& error_message);
+ void GetAssociatedCacheInfo(CacheInfo* info);
bool IsApplicationCacheEnabled();
DocumentLoader* GetDocumentLoader() const { return document_loader_; }
+ bool BindBackend();
+ void DispatchDOMEvent(mojom::AppCacheEventID,
+ int progress_total,
+ int progress_done,
+ mojom::AppCacheErrorReason,
+ const String& error_url,
+ int error_status,
+ const String& error_message);
struct DeferredEvent {
mojom::AppCacheEventID event_id;
@@ -157,20 +177,18 @@
error_message(error_message) {}
};
- WeakMember<ApplicationCache> dom_application_cache_;
+ WeakMember<ApplicationCache> dom_application_cache_ = nullptr;
Member<DocumentLoader> document_loader_;
- bool defers_events_; // Events are deferred until after document onload.
+ bool defers_events_ =
+ true; // Events are deferred until after document onload.
Vector<DeferredEvent> deferred_events_;
-
- void DispatchDOMEvent(mojom::AppCacheEventID,
- int progress_total,
- int progress_done,
- mojom::AppCacheErrorReason,
- const String& error_url,
- int error_status,
- const String& error_message);
-
- Member<ApplicationCacheHostHelper> helper_;
+ mojo::Binding<mojom::blink::AppCacheFrontend> binding_;
+ base::UnguessableToken host_id_;
+ mojom::blink::AppCacheInfo cache_info_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+ mojom::blink::DocumentInterfaceBroker* interface_broker_;
+ // Invoked when CacheSelected() is called.
+ base::OnceClosure select_cache_for_shared_worker_completion_callback_;
FRIEND_TEST_ALL_PREFIXES(DocumentTest, SandboxDisablesAppCache);
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host_client.h b/third_party/blink/renderer/core/loader/appcache/application_cache_host_client.h
deleted file mode 100644
index ff79962..0000000
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host_client.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2009 Google Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- * * Neither the name of Google Inc. nor the names of its
- * contributors may be used to endorse or promote products derived from
- * this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_CLIENT_H_
-#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_CLIENT_H_
-
-#include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h"
-
-namespace blink {
-
-// This interface is used by the embedder to call into webkit.
-// TODO(https://crbug.com/950159): Remove ApplicationCacheHostClient as the
-// communications happen in Blink.
-class ApplicationCacheHostClient {
- public:
- // Called when a different cache, including possibly no cache, is associated
- // with the host.
- virtual void DidChangeCacheAssociation() = 0;
-
- // Called to fire events in the scriptable interface.
- virtual void NotifyEventListener(mojom::AppCacheEventID) = 0;
- virtual void NotifyProgressEventListener(const KURL&,
- int num_total,
- int num_complete) = 0;
- virtual void NotifyErrorEventListener(mojom::AppCacheErrorReason,
- const KURL&,
- int status,
- const String& message) = 0;
-
- protected:
- // Should not be deleted by the embedder.
- virtual ~ApplicationCacheHostClient() = default;
-};
-
-} // namespace blink
-
-#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_CLIENT_H_
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.cc b/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.cc
index e94b000..ef8bd06 100644
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.cc
+++ b/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.cc
@@ -5,6 +5,7 @@
#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.h"
#include "third_party/blink/public/common/loader/url_loader_factory_bundle.h"
+#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
@@ -13,16 +14,35 @@
namespace blink {
+namespace {
+
+const char kHttpGETMethod[] = "GET";
+
+KURL ClearUrlRef(const KURL& input_url) {
+ KURL url(input_url);
+ if (!url.HasFragmentIdentifier())
+ return url;
+ url.RemoveFragmentIdentifier();
+ return url;
+}
+
+void RestartNavigation(LocalFrame* frame) {
+ Document* document = frame->GetDocument();
+ FrameLoadRequest request(document, ResourceRequest(document->Url()));
+ request.SetClientRedirectReason(ClientNavigationReason::kReload);
+ frame->Navigate(request, WebFrameLoadType::kReplaceCurrentItem);
+}
+
+} // namespace
+
ApplicationCacheHostForFrame::ApplicationCacheHostForFrame(
- LocalFrame* local_frame,
- ApplicationCacheHostClient* client,
- const base::UnguessableToken& appcache_host_id,
+ DocumentLoader* document_loader,
+ mojom::blink::DocumentInterfaceBroker* interface_broker,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : ApplicationCacheHostHelper(local_frame,
- client,
- appcache_host_id,
- std::move(task_runner)),
- local_frame_(local_frame) {}
+ : ApplicationCacheHost(document_loader,
+ interface_broker,
+ std::move(task_runner)),
+ local_frame_(document_loader->GetFrame()) {}
void ApplicationCacheHostForFrame::LogMessage(
mojom::blink::ConsoleMessageLevel log_level,
@@ -51,9 +71,131 @@
local_frame_->Client()->UpdateSubresourceFactory(std::move(info));
}
+void ApplicationCacheHostForFrame::WillStartLoadingMainResource(
+ DocumentLoader* loader,
+ const KURL& url,
+ const String& method) {
+ ApplicationCacheHost::WillStartLoadingMainResource(loader, url, method);
+ if (!backend_host_.is_bound())
+ return;
+
+ original_main_resource_url_ = ClearUrlRef(url);
+ is_get_method_ = (method == kHttpGETMethod);
+ DCHECK(method == method.UpperASCII());
+
+ const ApplicationCacheHost* spawning_host = nullptr;
+
+ DCHECK(loader->GetFrame());
+ LocalFrame* frame = loader->GetFrame();
+ Frame* spawning_frame = frame->Tree().Parent();
+ if (!spawning_frame || !IsA<LocalFrame>(spawning_frame))
+ spawning_frame = frame->Loader().Opener();
+ if (!spawning_frame || !IsA<LocalFrame>(spawning_frame))
+ spawning_frame = frame;
+ if (DocumentLoader* spawning_doc_loader =
+ To<LocalFrame>(spawning_frame)->Loader().GetDocumentLoader()) {
+ spawning_host = spawning_doc_loader->GetApplicationCacheHost();
+ }
+
+ if (spawning_host && (spawning_host != this) &&
+ (spawning_host->GetStatus() !=
+ mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED)) {
+ backend_host_->SetSpawningHostId(spawning_host->GetHostID());
+ }
+}
+
+void ApplicationCacheHostForFrame::SelectCacheWithoutManifest() {
+ if (!backend_host_.is_bound())
+ return;
+
+ if (was_select_cache_called_)
+ return;
+ was_select_cache_called_ = true;
+
+ status_ =
+ (document_response_.AppCacheID() == mojom::blink::kAppCacheNoCacheId)
+ ? mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED
+ : mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
+ is_new_master_entry_ = OLD_ENTRY;
+ backend_host_->SelectCache(document_url_, document_response_.AppCacheID(),
+ KURL());
+}
+
+void ApplicationCacheHostForFrame::SelectCacheWithManifest(
+ const KURL& manifest_url) {
+ ApplicationCacheHost::SelectCacheWithManifest(manifest_url);
+
+ if (!backend_host_.is_bound())
+ return;
+
+ if (was_select_cache_called_)
+ return;
+ was_select_cache_called_ = true;
+
+ KURL manifest_kurl(ClearUrlRef(manifest_url));
+
+ // 6.9.6 The application cache selection algorithm
+ // Check for new 'master' entries.
+ if (document_response_.AppCacheID() == mojom::blink::kAppCacheNoCacheId) {
+ if (is_scheme_supported_ && is_get_method_ &&
+ SecurityOrigin::AreSameSchemeHostPort(manifest_kurl, document_url_)) {
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
+ is_new_master_entry_ = NEW_ENTRY;
+ } else {
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
+ is_new_master_entry_ = OLD_ENTRY;
+ manifest_kurl = KURL();
+ }
+ backend_host_->SelectCache(document_url_, mojom::blink::kAppCacheNoCacheId,
+ manifest_kurl);
+ return;
+ }
+
+ DCHECK_EQ(OLD_ENTRY, is_new_master_entry_);
+
+ // 6.9.6 The application cache selection algorithm
+ // Check for 'foreign' entries.
+ KURL document_manifest_kurl(document_response_.AppCacheManifestURL());
+ if (document_manifest_kurl != manifest_kurl) {
+ backend_host_->MarkAsForeignEntry(document_url_,
+ document_response_.AppCacheID());
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
+ // It's a foreign entry, restart the current navigation from the top of the
+ // navigation algorithm. The navigation will not result in the same resource
+ // being loaded, because "foreign" entries are never picked during
+ // navigation. see ApplicationCacheGroup::selectCache()
+ RestartNavigation(local_frame_); // the navigation will be restarted
+ return;
+ }
+
+ status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
+
+ // It's a 'master' entry that's already in the cache.
+ backend_host_->SelectCache(document_url_, document_response_.AppCacheID(),
+ manifest_kurl);
+}
+
+void ApplicationCacheHostForFrame::DidReceiveResponseForMainResource(
+ const ResourceResponse& response) {
+ if (!backend_host_.is_bound())
+ return;
+
+ document_response_ = response;
+ document_url_ = ClearUrlRef(document_response_.CurrentRequestUrl());
+ if (document_url_ != original_main_resource_url_)
+ is_get_method_ = true; // A redirect was involved.
+ original_main_resource_url_ = KURL();
+
+ is_scheme_supported_ =
+ Platform::Current()->IsURLSupportedForAppCache(document_url_);
+ if ((document_response_.AppCacheID() != mojom::blink::kAppCacheNoCacheId) ||
+ !is_scheme_supported_ || !is_get_method_)
+ is_new_master_entry_ = OLD_ENTRY;
+}
+
void ApplicationCacheHostForFrame::Trace(blink::Visitor* visitor) {
visitor->Trace(local_frame_);
- ApplicationCacheHostHelper::Trace(visitor);
+ ApplicationCacheHost::Trace(visitor);
}
} // namespace blink
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.h b/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.h
index a75fc219..1b3d4c0 100644
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.h
+++ b/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.h
@@ -5,28 +5,46 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_FOR_FRAME_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_FOR_FRAME_H_
-#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.h"
+#include "third_party/blink/renderer/core/loader/appcache/application_cache_host.h"
namespace blink {
-class ApplicationCacheHostForFrame final : public ApplicationCacheHostHelper {
+
+class LocalFrame;
+
+class ApplicationCacheHostForFrame final : public ApplicationCacheHost {
public:
ApplicationCacheHostForFrame(
- LocalFrame* local_frame,
- ApplicationCacheHostClient* client,
- const base::UnguessableToken& appcache_host_id,
+ DocumentLoader* document_loader,
+ mojom::blink::DocumentInterfaceBroker* interface_broker,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
- // mojom::blink::AppCacheHostFrontend:
+ // ApplicationCacheHost:
void LogMessage(mojom::blink::ConsoleMessageLevel log_level,
const String& message) override;
void SetSubresourceFactory(
network::mojom::blink::URLLoaderFactoryPtr url_loader_factory) override;
+ void WillStartLoadingMainResource(DocumentLoader* loader,
+ const KURL& url,
+ const String& method) override;
+ void SelectCacheWithoutManifest() override;
+ void SelectCacheWithManifest(const KURL& manifest_url) override;
+ void DidReceiveResponseForMainResource(const ResourceResponse&) override;
+
void Trace(blink::Visitor*) override;
private:
+ enum IsNewMasterEntry { MAYBE_NEW_ENTRY, NEW_ENTRY, OLD_ENTRY };
+
Member<LocalFrame> local_frame_;
+ bool is_get_method_ = false;
+ bool was_select_cache_called_ = false;
+ IsNewMasterEntry is_new_master_entry_ = MAYBE_NEW_ENTRY;
+ bool is_scheme_supported_ = false;
+ ResourceResponse document_response_;
+ KURL document_url_;
+ KURL original_main_resource_url_; // Used to detect redirection.
};
} // namespace blink
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.cc b/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.cc
index a90586b..fb167e0 100644
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.cc
+++ b/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.cc
@@ -7,32 +7,15 @@
namespace blink {
ApplicationCacheHostForSharedWorker::ApplicationCacheHostForSharedWorker(
- ApplicationCacheHostClient* client,
- const base::UnguessableToken& appcache_host_id,
+ DocumentLoader* document_loader,
scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : ApplicationCacheHostHelper(nullptr /* LocalFrame* */,
- client,
- appcache_host_id,
- std::move(task_runner)) {}
+ : ApplicationCacheHost(document_loader,
+ nullptr, /* interface_broker */
+ std::move(task_runner)) {}
ApplicationCacheHostForSharedWorker::~ApplicationCacheHostForSharedWorker() =
default;
-void ApplicationCacheHostForSharedWorker::WillStartMainResourceRequest(
- const KURL& url,
- const String& method,
- const ApplicationCacheHostHelper* spawning_host) {}
-
-void ApplicationCacheHostForSharedWorker::DidReceiveResponseForMainResource(
- const ResourceResponse&) {}
-
-void ApplicationCacheHostForSharedWorker::SelectCacheWithoutManifest() {}
-
-bool ApplicationCacheHostForSharedWorker::SelectCacheWithManifest(
- const KURL& manifestURL) {
- return true;
-}
-
void ApplicationCacheHostForSharedWorker::LogMessage(
mojom::blink::ConsoleMessageLevel log_level,
const String& message) {}
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.h b/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.h
index aaf17fe8..73b0c90 100644
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.h
+++ b/third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.h
@@ -5,36 +5,18 @@
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_FOR_SHARED_WORKER_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_FOR_SHARED_WORKER_H_
-#include "base/unguessable_token.h"
-#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.h"
+#include "third_party/blink/renderer/core/loader/appcache/application_cache_host.h"
namespace blink {
-class ApplicationCacheHostForSharedWorker final
- : public ApplicationCacheHostHelper {
+class ApplicationCacheHostForSharedWorker final : public ApplicationCacheHost {
public:
ApplicationCacheHostForSharedWorker(
- ApplicationCacheHostClient* client,
- const base::UnguessableToken& appcache_host_id,
+ DocumentLoader* document_loader,
scoped_refptr<base::SingleThreadTaskRunner> task_runner);
~ApplicationCacheHostForSharedWorker() override;
- // Main resource loading is different for workers. The main resource is
- // loaded by the worker using WorkerClassicScriptLoader.
- // These overrides are stubbed out.
- void WillStartMainResourceRequest(
- const KURL& url,
- const String& method,
- const ApplicationCacheHostHelper* spawning_host) override;
- void DidReceiveResponseForMainResource(const ResourceResponse&) override;
-
- // Cache selection is also different for workers. We know at construction
- // time what cache to select and do so then.
- // These overrides are stubbed out.
- void SelectCacheWithoutManifest() override;
- bool SelectCacheWithManifest(const KURL& manifestURL) override;
-
- // mojom::blink::AppCacheFrontend:
+ // ApplicationCacheHost:
void LogMessage(mojom::blink::ConsoleMessageLevel log_level,
const String& message) override;
void SetSubresourceFactory(
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.cc b/third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.cc
deleted file mode 100644
index 0a097ea6..0000000
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.cc
+++ /dev/null
@@ -1,361 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.h"
-
-#include "third_party/blink/public/mojom/frame/document_interface_broker.mojom-blink.h"
-#include "third_party/blink/public/platform/interface_provider.h"
-#include "third_party/blink/public/platform/platform.h"
-#include "third_party/blink/renderer/core/frame/local_frame_client.h"
-#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_client.h"
-#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_for_frame.h"
-#include "third_party/blink/renderer/core/loader/appcache/application_cache_host_for_shared_worker.h"
-
-namespace blink {
-
-namespace {
-
-const char kHttpGETMethod[] = "GET";
-
-// Note: the order of the elements in this array must match those
-// of the EventID enum in appcache_interfaces.h.
-const char* const kEventNames[] = {"Checking", "Error", "NoUpdate",
- "Downloading", "Progress", "UpdateReady",
- "Cached", "Obsolete"};
-
-KURL ClearUrlRef(const KURL& input_url) {
- KURL url(input_url);
- if (!url.HasFragmentIdentifier())
- return url;
- url.RemoveFragmentIdentifier();
- return url;
-}
-
-mojom::blink::DocumentInterfaceBroker* GetDocumentInterfaceBroker(
- LocalFrame* local_frame) {
- if (!local_frame)
- return nullptr;
- return local_frame->Client()->GetDocumentInterfaceBroker();
-}
-
-} // namespace
-
-ApplicationCacheHostHelper* ApplicationCacheHostHelper::Create(
- LocalFrame* local_frame,
- ApplicationCacheHostClient* client,
- const base::UnguessableToken& appcache_host_id) {
- WebLocalFrameClient::AppCacheType type =
- local_frame->Client()->GetAppCacheType();
- switch (type) {
- case WebLocalFrameClient::AppCacheType::kAppCacheForFrame:
- return MakeGarbageCollected<ApplicationCacheHostForFrame>(
- local_frame, client, appcache_host_id,
- local_frame->GetTaskRunner(TaskType::kNetworking));
- case WebLocalFrameClient::AppCacheType::kAppCacheForSharedWorker:
- return MakeGarbageCollected<ApplicationCacheHostForSharedWorker>(
- client, appcache_host_id, Thread::Current()->GetTaskRunner());
- default:
- break;
- }
- return nullptr;
-}
-
-ApplicationCacheHostHelper::ApplicationCacheHostHelper() : binding_(this) {}
-
-ApplicationCacheHostHelper::ApplicationCacheHostHelper(
- LocalFrame* local_frame,
- ApplicationCacheHostClient* client,
- const base::UnguessableToken& appcache_host_id,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner)
- : binding_(this),
- client_(client),
- status_(mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED),
- is_scheme_supported_(false),
- is_get_method_(false),
- is_new_master_entry_(MAYBE_NEW_ENTRY),
- was_select_cache_called_(false) {
- DCHECK(client);
- // PlzNavigate: The browser passes the ID to be used.
- if (!appcache_host_id.is_empty())
- host_id_ = appcache_host_id;
- else
- host_id_ = base::UnguessableToken::Create();
-
- mojom::blink::AppCacheFrontendPtr frontend_ptr;
- binding_.Bind(mojo::MakeRequest(&frontend_ptr, task_runner), task_runner);
-
- mojom::blink::DocumentInterfaceBroker* interface_broker =
- GetDocumentInterfaceBroker(local_frame);
- if (interface_broker) {
- interface_broker->RegisterAppCacheHost(
- mojo::MakeRequest(&backend_host_, std::move(task_runner)),
- std::move(frontend_ptr), host_id_);
- return;
- }
-
- DEFINE_STATIC_LOCAL(
- const mojom::blink::AppCacheBackendPtr, backend_ptr, ([] {
- mojom::blink::AppCacheBackendPtr result;
- Platform::Current()->GetInterfaceProvider()->GetInterface(
- mojo::MakeRequest(&result));
- return result;
- }()));
-
- // Once we have 'WebContextInterfaceBroker', we can call this function through
- // it like render frame.
- // Refer to the design document, 'https://bit.ly/2GT0rZv'.
- backend_ptr.get()->RegisterHost(
- mojo::MakeRequest(&backend_host_, std::move(task_runner)),
- std::move(frontend_ptr), host_id_);
-}
-
-ApplicationCacheHostHelper::~ApplicationCacheHostHelper() = default;
-
-void ApplicationCacheHostHelper::CacheSelected(
- mojom::blink::AppCacheInfoPtr info) {
- cache_info_ = *info;
- client_->DidChangeCacheAssociation();
- if (select_cache_for_shared_worker_completion_callback_)
- std::move(select_cache_for_shared_worker_completion_callback_).Run();
-}
-
-void ApplicationCacheHostHelper::EventRaised(
- mojom::blink::AppCacheEventID event_id) {
- DCHECK_NE(event_id,
- mojom::blink::AppCacheEventID::
- APPCACHE_PROGRESS_EVENT); // See OnProgressEventRaised.
- DCHECK_NE(event_id,
- mojom::blink::AppCacheEventID::
- APPCACHE_ERROR_EVENT); // See OnErrorEventRaised.
-
- // Emit logging output prior to calling out to script as we can get
- // deleted within the script event handler.
- const char kFormatString[] = "Application Cache %s event";
- String message =
- String::Format(kFormatString, kEventNames[static_cast<int>(event_id)]);
- LogMessage(mojom::blink::ConsoleMessageLevel::kInfo, message);
-
- switch (event_id) {
- case mojom::blink::AppCacheEventID::APPCACHE_CHECKING_EVENT:
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
- break;
- case mojom::blink::AppCacheEventID::APPCACHE_DOWNLOADING_EVENT:
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_DOWNLOADING;
- break;
- case mojom::blink::AppCacheEventID::APPCACHE_UPDATE_READY_EVENT:
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UPDATE_READY;
- break;
- case mojom::blink::AppCacheEventID::APPCACHE_CACHED_EVENT:
- case mojom::blink::AppCacheEventID::APPCACHE_NO_UPDATE_EVENT:
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_IDLE;
- break;
- case mojom::blink::AppCacheEventID::APPCACHE_OBSOLETE_EVENT:
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_OBSOLETE;
- break;
- default:
- NOTREACHED();
- break;
- }
-
- client_->NotifyEventListener(event_id);
-}
-
-void ApplicationCacheHostHelper::ProgressEventRaised(const KURL& url,
- int num_total,
- int num_complete) {
- // Emit logging output prior to calling out to script as we can get
- // deleted within the script event handler.
- const char kFormatString[] = "Application Cache Progress event (%d of %d) %s";
- String message = String::Format(kFormatString, num_complete, num_total,
- url.GetString().Utf8().c_str());
- LogMessage(mojom::blink::ConsoleMessageLevel::kInfo, message);
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_DOWNLOADING;
- client_->NotifyProgressEventListener(url, num_total, num_complete);
-}
-
-void ApplicationCacheHostHelper::ErrorEventRaised(
- mojom::blink::AppCacheErrorDetailsPtr details) {
- // Emit logging output prior to calling out to script as we can get
- // deleted within the script event handler.
- const char kFormatString[] = "Application Cache Error event: %s";
- String full_message =
- String::Format(kFormatString, details->message.Utf8().c_str());
- LogMessage(mojom::blink::ConsoleMessageLevel::kError, full_message);
-
- status_ = cache_info_.is_complete
- ? mojom::blink::AppCacheStatus::APPCACHE_STATUS_IDLE
- : mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
- if (details->is_cross_origin) {
- // Don't leak detailed information to script for cross-origin resources.
- DCHECK_EQ(mojom::blink::AppCacheErrorReason::APPCACHE_RESOURCE_ERROR,
- details->reason);
- client_->NotifyErrorEventListener(details->reason, details->url, 0,
- String());
- } else {
- client_->NotifyErrorEventListener(details->reason, details->url,
- details->status, details->message);
- }
-}
-
-void ApplicationCacheHostHelper::WillStartMainResourceRequest(
- const KURL& url,
- const String& method,
- const ApplicationCacheHostHelper* spawning_host) {
- original_main_resource_url_ = ClearUrlRef(url);
-
- is_get_method_ = (method == kHttpGETMethod);
- DCHECK(method == method.UpperASCII());
-
- const ApplicationCacheHostHelper* spawning_host_impl =
- static_cast<const ApplicationCacheHostHelper*>(spawning_host);
- if (spawning_host_impl && (spawning_host_impl != this) &&
- (spawning_host_impl->status_ !=
- mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED)) {
- backend_host_->SetSpawningHostId(spawning_host_impl->host_id());
- }
-}
-
-void ApplicationCacheHostHelper::SelectCacheWithoutManifest() {
- if (was_select_cache_called_)
- return;
- was_select_cache_called_ = true;
-
- status_ =
- (document_response_.AppCacheID() == mojom::blink::kAppCacheNoCacheId)
- ? mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED
- : mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
- is_new_master_entry_ = OLD_ENTRY;
- backend_host_->SelectCache(document_url_, document_response_.AppCacheID(),
- KURL());
-}
-
-bool ApplicationCacheHostHelper::SelectCacheWithManifest(
- const KURL& manifest_url) {
- if (was_select_cache_called_)
- return true;
- was_select_cache_called_ = true;
-
- KURL manifest_kurl(ClearUrlRef(manifest_url));
-
- // 6.9.6 The application cache selection algorithm
- // Check for new 'master' entries.
- if (document_response_.AppCacheID() == mojom::blink::kAppCacheNoCacheId) {
- if (is_scheme_supported_ && is_get_method_ &&
- SecurityOrigin::AreSameSchemeHostPort(manifest_kurl, document_url_)) {
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
- is_new_master_entry_ = NEW_ENTRY;
- } else {
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
- is_new_master_entry_ = OLD_ENTRY;
- manifest_kurl = KURL();
- }
- backend_host_->SelectCache(document_url_, mojom::blink::kAppCacheNoCacheId,
- manifest_kurl);
- return true;
- }
-
- DCHECK_EQ(OLD_ENTRY, is_new_master_entry_);
-
- // 6.9.6 The application cache selection algorithm
- // Check for 'foreign' entries.
- KURL document_manifest_kurl(document_response_.AppCacheManifestURL());
- if (document_manifest_kurl != manifest_kurl) {
- backend_host_->MarkAsForeignEntry(document_url_,
- document_response_.AppCacheID());
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
- return false; // the navigation will be restarted
- }
-
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
-
- // It's a 'master' entry that's already in the cache.
- backend_host_->SelectCache(document_url_, document_response_.AppCacheID(),
- manifest_kurl);
- return true;
-}
-
-void ApplicationCacheHostHelper::DidReceiveResponseForMainResource(
- const ResourceResponse& response) {
- document_response_ = response;
- document_url_ = ClearUrlRef(document_response_.CurrentRequestUrl());
- if (document_url_ != original_main_resource_url_)
- is_get_method_ = true; // A redirect was involved.
- original_main_resource_url_ = KURL();
-
- is_scheme_supported_ =
- Platform::Current()->IsURLSupportedForAppCache(document_url_);
- if ((document_response_.AppCacheID() != mojom::blink::kAppCacheNoCacheId) ||
- !is_scheme_supported_ || !is_get_method_)
- is_new_master_entry_ = OLD_ENTRY;
-}
-
-mojom::blink::AppCacheStatus ApplicationCacheHostHelper::GetStatus() {
- return status_;
-}
-
-bool ApplicationCacheHostHelper::StartUpdate() {
- bool result = false;
- backend_host_->StartUpdate(&result);
- if (!result)
- return false;
- if (status_ == mojom::blink::AppCacheStatus::APPCACHE_STATUS_IDLE ||
- status_ == mojom::blink::AppCacheStatus::APPCACHE_STATUS_UPDATE_READY) {
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_CHECKING;
- } else {
- status_ = mojom::blink::AppCacheStatus::APPCACHE_STATUS_UNCACHED;
- backend_host_->GetStatus(&status_);
- }
- return true;
-}
-
-bool ApplicationCacheHostHelper::SwapCache() {
- bool result = false;
- backend_host_->SwapCache(&result);
- if (!result)
- return false;
- backend_host_->GetStatus(&status_);
- return true;
-}
-
-void ApplicationCacheHostHelper::GetAssociatedCacheInfo(
- ApplicationCacheHostHelper::CacheInfo* info) {
- info->manifest_url = cache_info_.manifest_url;
- if (!cache_info_.is_complete)
- return;
- info->creation_time = cache_info_.creation_time.ToDoubleT();
- info->update_time = cache_info_.last_update_time.ToDoubleT();
- info->response_sizes = cache_info_.response_sizes;
- info->padding_sizes = cache_info_.padding_sizes;
-}
-
-const base::UnguessableToken& ApplicationCacheHostHelper::GetHostID() const {
- return host_id_;
-}
-
-void ApplicationCacheHostHelper::GetResourceList(
- Vector<mojom::blink::AppCacheResourceInfo>* resources) {
- DCHECK(resources);
- if (!cache_info_.is_complete)
- return;
- Vector<mojom::blink::AppCacheResourceInfoPtr> boxed_infos;
- backend_host_->GetResourceList(&boxed_infos);
- for (auto& b : boxed_infos) {
- resources->emplace_back(std::move(*b));
- }
-}
-
-void ApplicationCacheHostHelper::SelectCacheForSharedWorker(
- int64_t app_cache_id,
- base::OnceClosure completion_callback) {
- select_cache_for_shared_worker_completion_callback_ =
- std::move(completion_callback);
- backend_host_->SelectCacheForSharedWorker(app_cache_id);
-}
-
-void ApplicationCacheHostHelper::DetachFromDocumentLoader() {
- binding_.Close();
- client_ = nullptr;
-}
-
-} // namespace blink
diff --git a/third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.h b/third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.h
deleted file mode 100644
index a79d2b0..0000000
--- a/third_party/blink/renderer/core/loader/appcache/application_cache_host_helper.h
+++ /dev/null
@@ -1,115 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_HELPER_H_
-#define THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_HELPER_H_
-
-#include "mojo/public/cpp/bindings/binding.h"
-#include "third_party/blink/public/mojom/appcache/appcache.mojom-blink.h"
-#include "third_party/blink/public/mojom/appcache/appcache_info.mojom-blink.h"
-#include "third_party/blink/public/mojom/devtools/console_message.mojom-blink.h"
-#include "third_party/blink/renderer/core/core_export.h"
-#include "third_party/blink/renderer/core/frame/local_frame.h"
-#include "third_party/blink/renderer/platform/loader/fetch/resource_response.h"
-#include "third_party/blink/renderer/platform/weborigin/kurl.h"
-
-namespace blink {
-
-class ApplicationCacheHostClient;
-
-// TODO(https://crbug.com/950159): Combine ApplicationCacheHostHelper and
-// ApplicationCacheHost and make ApplicationCacheHostForFrame and
-// ApplicationCacheHostForSharedWorker inherited from ApplicationCacheHost.
-class CORE_EXPORT ApplicationCacheHostHelper
- : public GarbageCollectedFinalized<ApplicationCacheHostHelper>,
- public mojom::blink::AppCacheFrontend {
- public:
- static ApplicationCacheHostHelper* Create(
- LocalFrame* local_frame,
- ApplicationCacheHostClient* client,
- const base::UnguessableToken& appcache_host_id);
-
- // This is only for testing in order to create it without any arguments.
- ApplicationCacheHostHelper();
-
- ApplicationCacheHostHelper(
- // |local_frame| is used for accessing to DocumentInterfaceBroker. As it's
- // not used for workers, |local_frame| is null for workers.
- LocalFrame* local_frame,
- ApplicationCacheHostClient* client,
- const base::UnguessableToken& appcache_host_id,
- scoped_refptr<base::SingleThreadTaskRunner> task_runner);
- ~ApplicationCacheHostHelper() override;
-
- const base::UnguessableToken& host_id() const { return host_id_; }
-
- // mojom::blink::AppCacheFrontend
- void CacheSelected(mojom::blink::AppCacheInfoPtr info) override;
- void EventRaised(mojom::blink::AppCacheEventID event_id) override;
- void ProgressEventRaised(const KURL& url,
- int32_t num_total,
- int32_t num_complete) override;
- void ErrorEventRaised(mojom::blink::AppCacheErrorDetailsPtr details) override;
- void LogMessage(mojom::blink::ConsoleMessageLevel log_level,
- const String& message) override {}
- void SetSubresourceFactory(
- network::mojom::blink::URLLoaderFactoryPtr url_loader_factory) override {}
-
- virtual void WillStartMainResourceRequest(
- const KURL& url,
- const String& method,
- const ApplicationCacheHostHelper* spawning_host);
- virtual void SelectCacheWithoutManifest();
- virtual bool SelectCacheWithManifest(const KURL& manifestURL);
- virtual void DidReceiveResponseForMainResource(const ResourceResponse&);
-
- mojom::blink::AppCacheStatus GetStatus();
- bool StartUpdate();
- bool SwapCache();
- void GetResourceList(Vector<mojom::blink::AppCacheResourceInfo>* resources);
- // Structures and methods to support inspecting Application Caches.
- struct CacheInfo {
- KURL manifest_url; // Empty if there is no associated cache.
- double creation_time;
- double update_time;
- // Sums up the sizes of all the responses in this cache.
- int64_t response_sizes;
- // Sums up the padding sizes for all opaque responses in the cache.
- int64_t padding_sizes;
- CacheInfo()
- : creation_time(0),
- update_time(0),
- response_sizes(0),
- padding_sizes(0) {}
- };
- void GetAssociatedCacheInfo(CacheInfo* info);
- const base::UnguessableToken& GetHostID() const;
- void SelectCacheForSharedWorker(int64_t app_cache_id,
- base::OnceClosure completion_callback);
- void DetachFromDocumentLoader();
- virtual void Trace(blink::Visitor*) {}
-
- private:
- enum IsNewMasterEntry { MAYBE_NEW_ENTRY, NEW_ENTRY, OLD_ENTRY };
-
- mojo::Binding<mojom::blink::AppCacheFrontend> binding_;
- ApplicationCacheHostClient* client_;
- mojom::blink::AppCacheHostPtr backend_host_;
- base::UnguessableToken host_id_;
- mojom::blink::AppCacheStatus status_;
- ResourceResponse document_response_;
- KURL document_url_;
- bool is_scheme_supported_;
- bool is_get_method_;
- IsNewMasterEntry is_new_master_entry_;
- mojom::blink::AppCacheInfo cache_info_;
- KURL original_main_resource_url_; // Used to detect redirection.
- bool was_select_cache_called_;
- // Invoked when CacheSelected() is called.
- base::OnceClosure select_cache_for_shared_worker_completion_callback_;
-};
-
-} // namespace blink
-
-#endif // THIRD_PARTY_BLINK_RENDERER_CORE_LOADER_APPCACHE_APPLICATION_CACHE_HOST_HELPER_H_
diff --git a/third_party/blink/renderer/core/loader/document_loader.cc b/third_party/blink/renderer/core/loader/document_loader.cc
index ee3c4eb..c4b55a5 100644
--- a/third_party/blink/renderer/core/loader/document_loader.cc
+++ b/third_party/blink/renderer/core/loader/document_loader.cc
@@ -1139,7 +1139,7 @@
DCHECK_EQ(state_, kNotStarted);
DCHECK(params_);
state_ = kProvisional;
- application_cache_host_ = MakeGarbageCollected<ApplicationCacheHost>(this);
+ application_cache_host_ = ApplicationCacheHost::Create(this);
if (url_.IsEmpty() &&
!GetFrameLoader().StateMachine()->CreatingInitialEmptyDocument()) {
diff --git a/third_party/blink/renderer/core/loader/document_loader.h b/third_party/blink/renderer/core/loader/document_loader.h
index 02f29915..be60065c 100644
--- a/third_party/blink/renderer/core/loader/document_loader.h
+++ b/third_party/blink/renderer/core/loader/document_loader.h
@@ -282,6 +282,9 @@
// The caller owns the |clock| which must outlive the DocumentLoader.
void SetTickClockForTesting(const base::TickClock* clock) { clock_ = clock; }
+ void SetApplicationCacheHostForTesting(ApplicationCacheHost* host) {
+ application_cache_host_ = host;
+ }
void SetLoadingJavaScriptUrl() { loading_url_as_javascript_ = true; }