Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit 23947d0

Browse files
committed
Consider CriOS to be chrome-like, meaning that we need also
accept:image/webp to send webp. Fixes #1256
1 parent aa4ec14 commit 23947d0

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

net/instaweb/rewriter/device_properties_test.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ TEST_F(DevicePropertiesTest, NoWebpForChromeWithoutAcceptHeader) {
8585
EXPECT_FALSE(device_properties_.SupportsWebpRewrittenUrls());
8686
EXPECT_FALSE(device_properties_.SupportsWebpLosslessAlpha());
8787

88+
device_properties_.SetUserAgent(
89+
UserAgentMatcherTestBase::kCriOS48UserAgent);
90+
EXPECT_FALSE(device_properties_.SupportsWebpInPlace());
91+
EXPECT_FALSE(device_properties_.SupportsWebpRewrittenUrls());
92+
EXPECT_FALSE(device_properties_.SupportsWebpLosslessAlpha());
93+
8894
// However, Chrome 25 and 37 will get webp due to the accept header.
8995
RequestHeaders headers;
9096
headers.Add(HttpAttributes::kAccept, "image/webp");
@@ -100,6 +106,12 @@ TEST_F(DevicePropertiesTest, NoWebpForChromeWithoutAcceptHeader) {
100106
EXPECT_TRUE(device_properties_.SupportsWebpInPlace());
101107
EXPECT_TRUE(device_properties_.SupportsWebpRewrittenUrls());
102108
EXPECT_FALSE(device_properties_.SupportsWebpLosslessAlpha());
109+
110+
device_properties_.SetUserAgent(
111+
UserAgentMatcherTestBase::kCriOS48UserAgent);
112+
EXPECT_TRUE(device_properties_.SupportsWebpInPlace());
113+
EXPECT_TRUE(device_properties_.SupportsWebpRewrittenUrls());
114+
EXPECT_TRUE(device_properties_.SupportsWebpLosslessAlpha());
103115
}
104116

105117
TEST_F(DevicePropertiesTest, WebpUserAgentIdentificationAccept) {

pagespeed/kernel/http/user_agent_matcher.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,9 @@ bool UserAgentMatcher::IsiOSUserAgent(const StringPiece& user_agent) const {
616616
}
617617

618618
bool UserAgentMatcher::IsChromeLike(const StringPiece& user_agent) const {
619-
return user_agent.find("Chrome/") != StringPiece::npos;
619+
return
620+
(user_agent.find("Chrome/") != StringPiece::npos) ||
621+
(user_agent.find("CriOS/") != StringPiece::npos);
620622
}
621623

622624
bool UserAgentMatcher::GetChromeBuildNumber(const StringPiece& user_agent,

pagespeed/kernel/http/user_agent_matcher_test_base.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ const char UserAgentMatcherTestBase::kCriOS32UserAgent[] =
9999
"Mozilla/5.0 (iPhone; CPU iPhone OS 7_0_4 like Mac OS X) "
100100
"AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/32.0.1700.21 "
101101
"Mobile/11B554a Safari/9537.53 (A7BED55D-B09E-484F-B2FE-5E4952E9B87E)";
102+
const char UserAgentMatcherTestBase::kCriOS48UserAgent[] =
103+
"Mozilla/5.0 (iPhone; CPU iPhone OS 9_2 like Mac OS X) "
104+
"AppleWebKit/601.1 (KHTML, like Gecko) CriOS/48.0.2564.87 "
105+
"Mobile/13C75 Safari/601.1.46";
102106
const char UserAgentMatcherTestBase::kDoCoMoMobileUserAgent[] =
103107
"DoCoMo/1.0/D505iS/c20/TB/W20H10";
104108
const char UserAgentMatcherTestBase::kFirefox1UserAgent[] =

pagespeed/kernel/http/user_agent_matcher_test_base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class UserAgentMatcherTestBase : public testing::Test {
5555
static const char kCompalUserAgent[];
5656
static const char kCriOS31UserAgent[];
5757
static const char kCriOS32UserAgent[];
58+
static const char kCriOS48UserAgent[];
5859
static const char kDoCoMoMobileUserAgent[];
5960
static const char kFirefox1UserAgent[];
6061
static const char kFirefox3UserAgent[];

0 commit comments

Comments
 (0)