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