Commit 0f14f303 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Chromium LUCI CQ

NoStatePrefetch: Remove mojom::PrerenderMode param from IsValidHttpMethod()

The param is always mojom::PrerenderMode::kPrefetchOnly, so it's not
necessary to pass it.

Bug: 755921
Change-Id: Id595b125d66569be5ed53e81356a845c52f1ca85
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2591843Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837079}
parent cb8344e8
......@@ -1598,18 +1598,12 @@ TEST_F(PrerenderTest, LinkManagerExpireRevealingLaunch) {
}
TEST_F(PrerenderTest, PrerenderContentsIsValidHttpMethod) {
EXPECT_TRUE(
IsValidHttpMethod(prerender::mojom::PrerenderMode::kPrefetchOnly, "GET"));
EXPECT_TRUE(IsValidHttpMethod(prerender::mojom::PrerenderMode::kPrefetchOnly,
"HEAD"));
EXPECT_FALSE(IsValidHttpMethod(prerender::mojom::PrerenderMode::kPrefetchOnly,
"OPTIONS"));
EXPECT_FALSE(IsValidHttpMethod(prerender::mojom::PrerenderMode::kPrefetchOnly,
"POST"));
EXPECT_FALSE(IsValidHttpMethod(prerender::mojom::PrerenderMode::kPrefetchOnly,
"TRACE"));
EXPECT_FALSE(IsValidHttpMethod(prerender::mojom::PrerenderMode::kPrefetchOnly,
"WHATEVER"));
EXPECT_TRUE(IsValidHttpMethod("GET"));
EXPECT_TRUE(IsValidHttpMethod("HEAD"));
EXPECT_FALSE(IsValidHttpMethod("OPTIONS"));
EXPECT_FALSE(IsValidHttpMethod("POST"));
EXPECT_FALSE(IsValidHttpMethod("TRACE"));
EXPECT_FALSE(IsValidHttpMethod("WHATEVER"));
}
TEST_F(PrerenderTest, PrerenderContentsIncrementsByteCount) {
......
......@@ -78,7 +78,7 @@ void PrerenderURLLoaderThrottle::WillStartRequest(
static_cast<blink::mojom::ResourceType>(request->resource_type);
// Abort any prerenders that spawn requests that use unsupported HTTP
// methods or schemes.
if (!IsValidHttpMethod(mode_, request->method)) {
if (!IsValidHttpMethod(request->method)) {
// If this is a full prerender, cancel the prerender in response to
// invalid requests. For prefetches, cancel invalid requests but keep the
// prefetch going.
......
......@@ -17,19 +17,12 @@ namespace prerender {
namespace {
// Valid HTTP methods for both prefetch and prerendering.
// Valid HTTP methods for NoStatePrefetch.
const char* const kValidHttpMethods[] = {
"GET",
"HEAD",
};
// Additional valid HTTP methods for prerendering.
const char* const kValidHttpMethodsForPrerendering[] = {
"OPTIONS",
"POST",
"TRACE",
};
// This enum is used to define the buckets for the
// "Prerender.NoStatePrefetchResourceCount" histogram family.
// Hence, existing enumerated constants should never be deleted or reordered,
......@@ -60,9 +53,7 @@ bool DoesSubresourceURLHaveValidScheme(const GURL& url) {
return DoesURLHaveValidScheme(url) || url == url::kAboutBlankURL;
}
bool IsValidHttpMethod(prerender::mojom::PrerenderMode prerender_mode,
const std::string& method) {
DCHECK_NE(prerender_mode, prerender::mojom::PrerenderMode::kNoPrerender);
bool IsValidHttpMethod(const std::string& method) {
// |method| has been canonicalized to upper case at this point so we can just
// compare them.
DCHECK_EQ(method, base::ToUpperASCII(method));
......@@ -70,15 +61,6 @@ bool IsValidHttpMethod(prerender::mojom::PrerenderMode prerender_mode,
if (method == valid_method)
return true;
}
if (prerender_mode == prerender::mojom::PrerenderMode::kPrefetchOnly)
return false;
for (auto* valid_method : kValidHttpMethodsForPrerendering) {
if (method == valid_method)
return true;
}
return false;
}
......
......@@ -21,9 +21,8 @@ bool DoesURLHaveValidScheme(const GURL& url);
// prerendering.
bool DoesSubresourceURLHaveValidScheme(const GURL& url);
// Returns true iff the method given is valid for prerendering.
bool IsValidHttpMethod(prerender::mojom::PrerenderMode prerender_mode,
const std::string& method);
// Returns true iff the method given is valid for NoStatePrefetch.
bool IsValidHttpMethod(const std::string& method);
std::string ComposeHistogramName(const std::string& prefix_type,
const std::string& name);
......
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