Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends 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 
20 #include "pagespeed/kernel/base/basictypes.h"
21 #include "pagespeed/kernel/base/gtest_prod.h"
22 #include "pagespeed/kernel/base/string.h"
23 #include "pagespeed/kernel/base/string_util.h"
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 CanPreloadResources() const;
61  bool AcceptsGzip() const;
62  UserAgentMatcher::DeviceType GetDeviceType() const;
63  bool IsMobile() const {
64  return GetDeviceType() == UserAgentMatcher::kMobile;
65  }
66  bool IsTablet() const {
67  return GetDeviceType() == UserAgentMatcher::kTablet;
68  }
69 
79  };
80  static const int kMediumScreenWidthThreshold = 720;
81  static const int kLargeScreenWidthThreshold = 1500;
82  bool ForbidWebpInlining() const;
83 
84  bool RequestsSaveData() const;
85  bool HasViaHeader() const;
86 
87  private:
88  friend class ImageRewriteTest;
89  friend class RequestProperties;
90 
91  GoogleString user_agent_;
92  GoogleString accept_header_;
93  UserAgentMatcher* ua_matcher_;
94 
95  mutable LazyBool supports_critical_css_;
96  mutable LazyBool supports_image_inlining_;
97  mutable LazyBool supports_js_defer_;
98  mutable LazyBool supports_lazyload_images_;
99  mutable LazyBool requests_save_data_;
100  mutable LazyBool accepts_webp_;
101  mutable LazyBool accepts_gzip_;
102  mutable LazyBool supports_webp_rewritten_urls_;
103  mutable LazyBool supports_webp_lossless_alpha_;
104  mutable LazyBool supports_webp_animated_;
105  mutable LazyBool is_bot_;
106  mutable LazyBool is_mobile_user_agent_;
107  mutable LazyBool supports_split_html_;
108  mutable LazyBool supports_flush_early_;
109  const std::vector<int>* preferred_webp_qualities_;
110  const std::vector<int>* preferred_jpeg_qualities_;
112  mutable LazyBool device_type_set_;
113  mutable UserAgentMatcher::DeviceType device_type_;
114  mutable LazyBool has_via_header_;
115 
116 
117 };
118 
119 }
120 
121 #endif
ImageQualityPreference
Definition: device_properties.h:70
The request asks for high image quality.
Definition: device_properties.h:78
The request asks for low image quality.
Definition: device_properties.h:74
Definition: device_properties.h:32
Server uses its own default image quality.
Definition: device_properties.h:72
The request asks for medium image quality.
Definition: device_properties.h:76
bool SupportsWebpRewrittenUrls() const
void ParseRequestHeaders(const RequestHeaders &request_headers)
Definition: request_properties.h:37