Commit 0d8afc1a authored by Nate Chapin's avatar Nate Chapin Committed by Commit Bot

Move the special case for image loads in unload handlers to ImageLoader

Change-Id: I3465c7c43e9f699e13eb1b4dddfa924ff4cb54a4
Reviewed-on: https://chromium-review.googlesource.com/881957Reviewed-by: default avatarMike West <mkwst@chromium.org>
Commit-Queue: Nate Chapin <japhet@chromium.org>
Cr-Commit-Position: refs/heads/master@{#532943}
parent f071bebc
...@@ -807,11 +807,6 @@ bool FrameFetchContext::IsLoadComplete() const { ...@@ -807,11 +807,6 @@ bool FrameFetchContext::IsLoadComplete() const {
return document_ && document_->LoadEventFinished(); return document_ && document_->LoadEventFinished();
} }
bool FrameFetchContext::PageDismissalEventBeingDispatched() const {
return document_ && document_->PageDismissalEventBeingDispatched() !=
Document::kNoDismissal;
}
bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation( bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation(
ResourceTimingInfo* info) { ResourceTimingInfo* info) {
if (IsDetached()) if (IsDetached())
...@@ -832,12 +827,6 @@ bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation( ...@@ -832,12 +827,6 @@ bool FrameFetchContext::UpdateTimingInfoForIFrameNavigation(
return true; return true;
} }
void FrameFetchContext::SendImagePing(const KURL& url) {
if (IsDetached())
return;
PingLoader::LoadImage(GetFrame(), url);
}
const SecurityOrigin* FrameFetchContext::GetSecurityOrigin() const { const SecurityOrigin* FrameFetchContext::GetSecurityOrigin() const {
if (IsDetached()) if (IsDetached())
return frozen_state_->security_origin.get(); return frozen_state_->security_origin.get();
......
...@@ -134,9 +134,7 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext { ...@@ -134,9 +134,7 @@ class CORE_EXPORT FrameFetchContext final : public BaseFetchContext {
bool IsMainFrame() const override; bool IsMainFrame() const override;
bool DefersLoading() const override; bool DefersLoading() const override;
bool IsLoadComplete() const override; bool IsLoadComplete() const override;
bool PageDismissalEventBeingDispatched() const override;
bool UpdateTimingInfoForIFrameNavigation(ResourceTimingInfo*) override; bool UpdateTimingInfoForIFrameNavigation(ResourceTimingInfo*) override;
void SendImagePing(const KURL&) override;
const SecurityOrigin* GetSecurityOrigin() const override; const SecurityOrigin* GetSecurityOrigin() const override;
......
...@@ -1383,12 +1383,6 @@ TEST_F(FrameFetchContextTest, IsLoadCompleteWhenDetached_2) { ...@@ -1383,12 +1383,6 @@ TEST_F(FrameFetchContextTest, IsLoadCompleteWhenDetached_2) {
EXPECT_TRUE(fetch_context->IsLoadComplete()); EXPECT_TRUE(fetch_context->IsLoadComplete());
} }
TEST_F(FrameFetchContextTest, PageDismissalEventBeingDispatchedWhenDetached) {
dummy_page_holder = nullptr;
EXPECT_FALSE(fetch_context->PageDismissalEventBeingDispatched());
}
TEST_F(FrameFetchContextTest, UpdateTimingInfoForIFrameNavigationWhenDetached) { TEST_F(FrameFetchContextTest, UpdateTimingInfoForIFrameNavigationWhenDetached) {
scoped_refptr<ResourceTimingInfo> info = scoped_refptr<ResourceTimingInfo> info =
ResourceTimingInfo::Create("type", 0.3, false); ResourceTimingInfo::Create("type", 0.3, false);
...@@ -1399,15 +1393,6 @@ TEST_F(FrameFetchContextTest, UpdateTimingInfoForIFrameNavigationWhenDetached) { ...@@ -1399,15 +1393,6 @@ TEST_F(FrameFetchContextTest, UpdateTimingInfoForIFrameNavigationWhenDetached) {
// Should not crash. // Should not crash.
} }
TEST_F(FrameFetchContextTest, SendImagePingWhenDetached) {
const KURL url("https://www.example.com/");
dummy_page_holder = nullptr;
fetch_context->SendImagePing(url);
// Should not crash. Nothing should be sent.
}
TEST_F(FrameFetchContextTest, AddConsoleMessageWhenDetached) { TEST_F(FrameFetchContextTest, AddConsoleMessageWhenDetached) {
dummy_page_holder = nullptr; dummy_page_holder = nullptr;
......
...@@ -395,6 +395,16 @@ void ImageLoader::DoUpdateFromElement(BypassMainWorldBehavior bypass_behavior, ...@@ -395,6 +395,16 @@ void ImageLoader::DoUpdateFromElement(BypassMainWorldBehavior bypass_behavior,
!GetElement()->FastGetAttribute(HTMLNames::srcsetAttr).IsNull()) !GetElement()->FastGetAttribute(HTMLNames::srcsetAttr).IsNull())
resource_request.SetRequestContext( resource_request.SetRequestContext(
WebURLRequest::kRequestContextImageSet); WebURLRequest::kRequestContextImageSet);
bool page_is_being_dismissed =
document.PageDismissalEventBeingDispatched() != Document::kNoDismissal;
if (page_is_being_dismissed) {
resource_request.SetHTTPHeaderField(HTTPNames::Cache_Control,
"max-age=0");
resource_request.SetKeepalive(true);
resource_request.SetRequestContext(WebURLRequest::kRequestContextPing);
}
FetchParameters params(resource_request, resource_loader_options); FetchParameters params(resource_request, resource_loader_options);
ConfigureRequest(params, bypass_behavior, *element_, ConfigureRequest(params, bypass_behavior, *element_,
document.GetClientHintsPreferences()); document.GetClientHintsPreferences());
...@@ -403,6 +413,12 @@ void ImageLoader::DoUpdateFromElement(BypassMainWorldBehavior bypass_behavior, ...@@ -403,6 +413,12 @@ void ImageLoader::DoUpdateFromElement(BypassMainWorldBehavior bypass_behavior,
document.GetFrame()->MaybeAllowImagePlaceholder(params); document.GetFrame()->MaybeAllowImagePlaceholder(params);
new_image_content = ImageResourceContent::Fetch(params, document.Fetcher()); new_image_content = ImageResourceContent::Fetch(params, document.Fetcher());
// If this load is starting while navigating away, treat it as an auditing
// keepalive request, and don't report its results back to the element.
if (page_is_being_dismissed)
new_image_content = nullptr;
ClearFailedLoadURL(); ClearFailedLoadURL();
} else { } else {
if (!image_source_url.IsNull()) { if (!image_source_url.IsNull()) {
......
...@@ -208,20 +208,6 @@ bool SendBeaconCommon(LocalFrame* frame, ...@@ -208,20 +208,6 @@ bool SendBeaconCommon(LocalFrame* frame,
} // namespace } // namespace
void PingLoader::LoadImage(LocalFrame* frame, const KURL& url) {
ResourceRequest request(url);
request.SetHTTPHeaderField(HTTPNames::Cache_Control, "max-age=0");
request.SetKeepalive(true);
request.SetRequestContext(WebURLRequest::kRequestContextPing);
FetchParameters params(request);
params.MutableOptions().initiator_info.name = FetchInitiatorTypeNames::ping;
// TODO(mkwst): Reevaluate this.
params.SetContentSecurityCheck(kDoNotCheckContentSecurityPolicy);
frame->Client()->DidDispatchPingLoader(request.Url());
RawResource::Fetch(params, frame->GetDocument()->Fetcher(), nullptr);
}
// http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#hyperlink-auditing // http://www.whatwg.org/specs/web-apps/current-work/multipage/links.html#hyperlink-auditing
void PingLoader::SendLinkAuditPing(LocalFrame* frame, void PingLoader::SendLinkAuditPing(LocalFrame* frame,
const KURL& ping_url, const KURL& ping_url,
......
...@@ -65,7 +65,6 @@ class CORE_EXPORT PingLoader { ...@@ -65,7 +65,6 @@ class CORE_EXPORT PingLoader {
kXSSAuditorViolationReport kXSSAuditorViolationReport
}; };
static void LoadImage(LocalFrame*, const KURL&);
static void SendLinkAuditPing(LocalFrame*, static void SendLinkAuditPing(LocalFrame*,
const KURL& ping_url, const KURL& ping_url,
const KURL& destination_url); const KURL& destination_url);
......
...@@ -103,20 +103,6 @@ TEST_F(PingLoaderTest, NonHTTPPingTarget) { ...@@ -103,20 +103,6 @@ TEST_F(PingLoaderTest, NonHTTPPingTarget) {
ASSERT_TRUE(ping_request.IsNull()); ASSERT_TRUE(ping_request.IsNull());
} }
TEST_F(PingLoaderTest, LoadImagePriority) {
SetDocumentURL(KURL("http://localhost/foo.html"));
KURL ping_url("https://localhost/bar.html");
URLTestHelpers::RegisterMockedURLLoad(
ping_url, testing::CoreTestDataPath("bar.html"), "text/html");
PingLoader::LoadImage(&page_holder_->GetFrame(), ping_url);
Platform::Current()->GetURLLoaderMockFactory()->ServeAsynchronousRequests();
const ResourceRequest& request = client_->PingRequest();
ASSERT_FALSE(request.IsNull());
ASSERT_EQ(request.Url(), ping_url);
EXPECT_EQ(ResourceLoadPriority::kVeryLow, request.Priority());
}
TEST_F(PingLoaderTest, LinkAuditPingPriority) { TEST_F(PingLoaderTest, LinkAuditPingPriority) {
KURL destination_url("http://navigation.destination"); KURL destination_url("http://navigation.destination");
SetDocumentURL(KURL("http://localhost/foo.html")); SetDocumentURL(KURL("http://localhost/foo.html"));
......
...@@ -169,23 +169,6 @@ ImageResource* ImageResource::Fetch(FetchParameters& params, ...@@ -169,23 +169,6 @@ ImageResource* ImageResource::Fetch(FetchParameters& params,
WebURLRequest::kRequestContextUnspecified) { WebURLRequest::kRequestContextUnspecified) {
params.SetRequestContext(WebURLRequest::kRequestContextImage); params.SetRequestContext(WebURLRequest::kRequestContextImage);
} }
if (fetcher->Context().PageDismissalEventBeingDispatched()) {
KURL request_url = params.GetResourceRequest().Url();
if (request_url.IsValid()) {
ResourceRequestBlockedReason block_reason = fetcher->Context().CanRequest(
Resource::kImage, params.GetResourceRequest(), request_url,
params.Options(),
/* Don't send security violation reports for speculative preloads */
params.IsSpeculativePreload()
? SecurityViolationReportingPolicy::kSuppressReporting
: SecurityViolationReportingPolicy::kReport,
params.GetOriginRestriction(),
params.GetResourceRequest().GetRedirectStatus());
if (block_reason == ResourceRequestBlockedReason::kNone)
fetcher->Context().SendImagePing(request_url);
}
return nullptr;
}
ImageResource* resource = ToImageResource( ImageResource* resource = ToImageResource(
fetcher->RequestResource(params, ImageResourceFactory(params), nullptr)); fetcher->RequestResource(params, ImageResourceFactory(params), nullptr));
......
...@@ -109,8 +109,6 @@ void FetchContext::DidLoadResource(Resource*) {} ...@@ -109,8 +109,6 @@ void FetchContext::DidLoadResource(Resource*) {}
void FetchContext::AddResourceTiming(const ResourceTimingInfo&) {} void FetchContext::AddResourceTiming(const ResourceTimingInfo&) {}
void FetchContext::SendImagePing(const KURL&) {}
void FetchContext::AddWarningConsoleMessage(const String&, LogSource) const {} void FetchContext::AddWarningConsoleMessage(const String&, LogSource) const {}
void FetchContext::AddErrorConsoleMessage(const String&, LogSource) const {} void FetchContext::AddErrorConsoleMessage(const String&, LogSource) const {}
......
...@@ -203,11 +203,9 @@ class PLATFORM_EXPORT FetchContext ...@@ -203,11 +203,9 @@ class PLATFORM_EXPORT FetchContext
virtual bool IsMainFrame() const { return true; } virtual bool IsMainFrame() const { return true; }
virtual bool DefersLoading() const { return false; } virtual bool DefersLoading() const { return false; }
virtual bool IsLoadComplete() const { return false; } virtual bool IsLoadComplete() const { return false; }
virtual bool PageDismissalEventBeingDispatched() const { return false; }
virtual bool UpdateTimingInfoForIFrameNavigation(ResourceTimingInfo*) { virtual bool UpdateTimingInfoForIFrameNavigation(ResourceTimingInfo*) {
return false; return false;
} }
virtual void SendImagePing(const KURL&);
virtual void AddWarningConsoleMessage(const String&, LogSource) const; virtual void AddWarningConsoleMessage(const String&, LogSource) const;
virtual void AddErrorConsoleMessage(const String&, LogSource) const; virtual void AddErrorConsoleMessage(const String&, LogSource) const;
......
...@@ -469,6 +469,19 @@ TEST_F(ResourceFetcherTest, SynchronousRequest) { ...@@ -469,6 +469,19 @@ TEST_F(ResourceFetcherTest, SynchronousRequest) {
resource->GetResourceRequest().Priority()); resource->GetResourceRequest().Priority());
} }
TEST_F(ResourceFetcherTest, PingPriority) {
KURL url("http://127.0.0.1:8000/foo.png");
RegisterMockedURLLoad(url);
ResourceFetcher* fetcher = ResourceFetcher::Create(Context());
ResourceRequest resource_request(url);
resource_request.SetRequestContext(WebURLRequest::kRequestContextPing);
FetchParameters fetch_params(resource_request);
Resource* resource = RawResource::Fetch(fetch_params, fetcher, nullptr);
EXPECT_EQ(ResourceLoadPriority::kVeryLow,
resource->GetResourceRequest().Priority());
}
TEST_F(ResourceFetcherTest, PreloadResourceTwice) { TEST_F(ResourceFetcherTest, PreloadResourceTwice) {
ResourceFetcher* fetcher = ResourceFetcher::Create(Context()); ResourceFetcher* fetcher = ResourceFetcher::Create(Context());
......
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