Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
device_properties.h
1 // Copyright 2012 Google Inc. All Rights Reserved.
14 
15 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DEVICE_PROPERTIES_H_
16 #define NET_INSTAWEB_REWRITER_PUBLIC_DEVICE_PROPERTIES_H_
17 
18 #include <vector>
19 
24 #include "pagespeed/kernel/http/user_agent_matcher.h"
25 
26 namespace net_instaweb {
27 
28 class RequestHeaders;
29 
33  public:
34  explicit DeviceProperties(UserAgentMatcher* matcher);
35  virtual ~DeviceProperties();
36 
37  void SetUserAgent(const StringPiece& user_agent_string);
40  void ParseRequestHeaders(const RequestHeaders& request_headers);
41  bool SupportsImageInlining() const;
42  bool SupportsLazyloadImages() const;
43  bool SupportsCriticalCss() const;
44  bool SupportsCriticalImagesBeacon() const;
45  bool SupportsJsDefer(bool enable_mobile) const;
49  bool SupportsWebpInPlace() const;
56  bool SupportsWebpRewrittenUrls() const;
57  bool SupportsWebpLosslessAlpha() const;
58  bool SupportsWebpAnimated() const;
59  bool IsBot() const;
60  bool AcceptsGzip() const;
61  UserAgentMatcher::DeviceType GetDeviceType() const;
62  bool IsMobile() const {
63  return GetDeviceType() == UserAgentMatcher::kMobile;
64  }
65  bool IsTablet() const {
66  return GetDeviceType() == UserAgentMatcher::kTablet;
67  }
68 
78  };
79  static const int kMediumScreenWidthThreshold = 720;
80  static const int kLargeScreenWidthThreshold = 1500;
81  bool ForbidWebpInlining() const;
82 
83  bool RequestsSaveData() const;
84  bool HasViaHeader() const;
85 
86  private:
87  friend class ImageRewriteTest;
88  friend class RequestProperties;
89 
90  GoogleString user_agent_;
91  GoogleString accept_header_;
92  UserAgentMatcher* ua_matcher_;
93 
94  mutable LazyBool supports_critical_css_;
95  mutable LazyBool supports_image_inlining_;
96  mutable LazyBool supports_js_defer_;
97  mutable LazyBool supports_lazyload_images_;
98  mutable LazyBool requests_save_data_;
99  mutable LazyBool accepts_webp_;
100  mutable LazyBool accepts_gzip_;
101  mutable LazyBool supports_webp_rewritten_urls_;
102  mutable LazyBool supports_webp_lossless_alpha_;
103  mutable LazyBool supports_webp_animated_;
104  mutable LazyBool is_bot_;
105  mutable LazyBool is_mobile_user_agent_;
106  mutable LazyBool supports_split_html_;
107  mutable LazyBool supports_flush_early_;
108  const std::vector<int>* preferred_webp_qualities_;
109  const std::vector<int>* preferred_jpeg_qualities_;
111  mutable LazyBool device_type_set_;
112  mutable UserAgentMatcher::DeviceType device_type_;
113  mutable LazyBool has_via_header_;
114 
115 
116 };
117 
118 }
119 
120 #endif
ImageQualityPreference
Definition: device_properties.h:69
Read/write API for HTTP request (RequestHeaders is a misnomer).
Definition: request_headers.h:32
Definition: user_agent_matcher.h:43
The request asks for high image quality.
Definition: device_properties.h:77
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
The request asks for low image quality.
Definition: device_properties.h:73
Definition: device_properties.h:32
Server uses its own default image quality.
Definition: device_properties.h:71
LazyBool
Lazily-initialized boolean value.
Definition: basictypes.h:68
The request asks for medium image quality.
Definition: device_properties.h:75
bool SupportsWebpRewrittenUrls() const
DeviceType
Definition: user_agent_matcher.h:49
void ParseRequestHeaders(const RequestHeaders &request_headers)
Definition: request_properties.h:37