Page Speed Optimization Libraries  1.9.32.2
 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 
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 IsBot() const;
59  bool SupportsSplitHtml(bool enable_mobile) const;
60  bool CanPreloadResources() const;
61  bool GetScreenResolution(int* width, int* height) const;
62  UserAgentMatcher::DeviceType GetDeviceType() const;
63  bool IsMobile() const {
64  return GetDeviceType() == UserAgentMatcher::kMobile;
65  }
66 
76  };
77  static const int kMediumScreenWidthThreshold = 720;
78  static const int kLargeScreenWidthThreshold = 1500;
79 
83  const std::vector<int>* webp, const std::vector<int>* jpeg);
86  ImageQualityPreference preference, int* webp, int* jpeg) const;
87  static int GetPreferredImageQualityCount();
88  bool ForbidWebpInlining() const;
89 
90  private:
91  friend class ImageRewriteTest;
92  friend class RequestProperties;
93  FRIEND_TEST(ImageRewriteTest, SquashImagesForMobileScreen);
94  FRIEND_TEST(DevicePropertiesTest, GetScreenGroupIndex);
95 
98  static bool GetScreenGroupIndex(int screen_width, int* screen_index);
99  void SetScreenResolution(int width, int height) const;
101  bool HasPreferredImageQualities() const;
102  bool PossiblyMasqueradingAsChrome() const;
103 
104  GoogleString user_agent_;
105  GoogleString accept_header_;
106  UserAgentMatcher* ua_matcher_;
107 
108  mutable LazyBool supports_critical_css_;
109  mutable LazyBool supports_image_inlining_;
110  mutable LazyBool supports_js_defer_;
111  mutable LazyBool supports_lazyload_images_;
112  mutable LazyBool accepts_webp_;
113  mutable LazyBool supports_webp_rewritten_urls_;
114  mutable LazyBool supports_webp_lossless_alpha_;
115  mutable LazyBool is_bot_;
116  mutable LazyBool is_mobile_user_agent_;
117  mutable LazyBool supports_split_html_;
118  mutable LazyBool supports_flush_early_;
119  mutable LazyBool screen_dimensions_set_;
120  mutable int screen_width_;
121  mutable int screen_height_;
122  const std::vector<int>* preferred_webp_qualities_;
123  const std::vector<int>* preferred_jpeg_qualities_;
125  mutable LazyBool device_type_set_;
126  mutable UserAgentMatcher::DeviceType device_type_;
127 
128  DISALLOW_COPY_AND_ASSIGN(DeviceProperties);
129 };
130 
131 }
132 
133 #endif
ImageQualityPreference
Definition: device_properties.h:67
void SetPreferredImageQualities(const std::vector< int > *webp, const std::vector< int > *jpeg)
The request asks for high image quality.
Definition: device_properties.h:75
The request asks for low image quality.
Definition: device_properties.h:71
Definition: device_properties.h:32
Server uses its own default image quality.
Definition: device_properties.h:69
The request asks for medium image quality.
Definition: device_properties.h:73
bool SupportsWebpRewrittenUrls() const
void ParseRequestHeaders(const RequestHeaders &request_headers)
bool GetPreferredImageQualities(ImageQualityPreference preference, int *webp, int *jpeg) const
Returns true iff WebP and Jpeg image quality are set for the preference.
Definition: request_properties.h:39