Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
user_agent_matcher.h
1 // Copyright 2010 Google Inc. All Rights Reserved.
14 
15 #ifndef PAGESPEED_KERNEL_HTTP_USER_AGENT_MATCHER_H_
16 #define PAGESPEED_KERNEL_HTTP_USER_AGENT_MATCHER_H_
17 
18 #include <map>
19 #include <utility>
20 
27 
28 using std::pair;
29 using std::make_pair;
30 using std::map;
31 
32 namespace net_instaweb {
33 
34 class RequestHeaders;
35 
44  public:
45  static const char kTestUserAgentWebP[];
46  static const char kTestUserAgentNoWebP[];
48 
49  enum DeviceType {
50  kDesktop,
51  kTablet,
52  kMobile,
56  };
57 
59  virtual ~UserAgentMatcher();
60 
66  bool IsIe(const StringPiece& user_agent) const;
67  bool IsIe9(const StringPiece& user_agent) const;
68 
69  virtual bool SupportsImageInlining(const StringPiece& user_agent) const;
70  bool SupportsLazyloadImages(StringPiece user_agent) const;
71 
73  virtual DeviceType GetDeviceTypeForUA(const StringPiece& user_agent) const;
74 
78  const StringPiece& user_agent,
79  const RequestHeaders* request_headers) const;
80 
83  static StringPiece DeviceTypeString(DeviceType device_type);
84 
86  static StringPiece DeviceTypeSuffix(DeviceType device_type);
87 
88  bool SupportsJsDefer(const StringPiece& user_agent, bool allow_mobile) const;
89 
93  bool LegacyWebp(const StringPiece& user_agent) const;
94 
98  bool SupportsWebpLosslessAlpha(const StringPiece& user_agent) const;
99 
103  bool SupportsWebpAnimated(const StringPiece& user_agent) const;
104 
109  bool SupportsDnsPrefetchUsingRelPrefetch(const StringPiece& user_agent) const;
110  bool SupportsDnsPrefetch(const StringPiece& user_agent) const;
111 
112  virtual bool IsAndroidUserAgent(const StringPiece& user_agent) const;
113  virtual bool IsiOSUserAgent(const StringPiece& user_agent) const;
114 
117  virtual bool GetChromeBuildNumber(const StringPiece& user_agent, int* major,
118  int* minor, int* build, int* patch) const;
119 
120  bool UserAgentExceedsChromeAndroidBuildAndPatch(
121  const StringPiece& user_agent, int required_build,
122  int required_patch) const;
123 
124  bool UserAgentExceedsChromeiOSBuildAndPatch(
125  const StringPiece& user_agent, int required_build,
126  int required_patch) const;
127 
128  bool UserAgentExceedsChromeBuildAndPatch(
129  const StringPiece& user_agent, int required_build,
130  int required_patch) const;
131 
132  bool SupportsMobilization(StringPiece user_agent) const;
133 
134  private:
135  FastWildcardGroup supports_image_inlining_;
136  FastWildcardGroup supports_lazyload_images_;
137  FastWildcardGroup defer_js_whitelist_;
138  FastWildcardGroup defer_js_mobile_whitelist_;
139  FastWildcardGroup legacy_webp_;
140  FastWildcardGroup supports_webp_lossless_alpha_;
141  FastWildcardGroup supports_webp_animated_;
142  FastWildcardGroup supports_dns_prefetch_;
143  FastWildcardGroup mobile_user_agents_;
144  FastWildcardGroup tablet_user_agents_;
145  FastWildcardGroup ie_user_agents_;
146  FastWildcardGroup mobilization_user_agents_;
147 
148  const RE2 chrome_version_pattern_;
149  scoped_ptr<RE2> known_devices_pattern_;
150  mutable map <GoogleString, pair<int, int> > screen_dimensions_map_;
151 
152 
153 };
154 
155 }
156 
157 #endif
static StringPiece DeviceTypeString(DeviceType device_type)
Definition: fast_wildcard_group.h:94
Read/write API for HTTP request (RequestHeaders is a misnomer).
Definition: request_headers.h:32
virtual DeviceType GetDeviceTypeForUAAndHeaders(const StringPiece &user_agent, const RequestHeaders *request_headers) const
virtual DeviceType GetDeviceTypeForUA(const StringPiece &user_agent) const
Returns the DeviceType for the given user agent string.
bool SupportsDnsPrefetchUsingRelPrefetch(const StringPiece &user_agent) const
Definition: user_agent_matcher.h:43
bool IsIe(const StringPiece &user_agent) const
bool SupportsWebpAnimated(const StringPiece &user_agent) const
bool SupportsWebpLosslessAlpha(const StringPiece &user_agent) const
virtual bool GetChromeBuildNumber(const StringPiece &user_agent, int *major, int *minor, int *build, int *patch) const
Definition: user_agent_matcher.h:55
static StringPiece DeviceTypeSuffix(DeviceType device_type)
Returns the suffix for the given device_type.
static const char kTestUserAgentWebP[]
Definition: user_agent_matcher.h:45
bool LegacyWebp(const StringPiece &user_agent) const
DeviceType
Definition: user_agent_matcher.h:49
static const char kTestUserAgentNoWebP[]
Note that this must not contain the substring "webp".
Definition: user_agent_matcher.h:47