Page Speed Optimization Libraries  1.7.30.3
net/instaweb/rewriter/public/request_properties.h
00001 // Copyright 2013 Google Inc. All Rights Reserved.
00014 
00015 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_
00016 #define NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_
00017 
00018 #include <vector>
00019 
00020 #include "net/instaweb/http/public/user_agent_matcher.h"
00021 #include "net/instaweb/rewriter/public/device_properties.h"
00022 #include "net/instaweb/util/public/basictypes.h"
00023 #include "net/instaweb/util/public/gtest_prod.h"
00024 #include "net/instaweb/util/public/string_util.h"
00025 #include "pagespeed/kernel/base/scoped_ptr.h"            
00026 
00027 namespace net_instaweb {
00028 
00029 class DownstreamCachingDirectives;
00030 class AbstractLogRecord;
00031 class RequestHeaders;
00032 
00038 class RequestProperties {
00039  public:
00040   explicit RequestProperties(UserAgentMatcher* matcher);
00041   virtual ~RequestProperties();
00042 
00044   void set_user_agent(const StringPiece& user_agent_string);
00047   void ParseRequestHeaders(const RequestHeaders& request_headers);
00048 
00049   bool SupportsImageInlining() const;
00050   bool SupportsLazyloadImages() const;
00051   bool SupportsCriticalImagesBeacon() const;
00052   bool SupportsJsDefer(bool enable_mobile) const;
00053   bool SupportsWebp() const;
00054   bool SupportsWebpLosslessAlpha() const;
00055   bool IsBot() const;
00056   bool SupportsSplitHtml(bool enable_mobile) const;
00057   bool CanPreloadResources() const;
00058   bool GetScreenResolution(int* width, int* height) const;
00059   UserAgentMatcher::DeviceType GetDeviceType() const;
00060   bool IsMobile() const;
00061 
00064   void SetPreferredImageQualities(
00065       const std::vector<int>* webp,  const std::vector<int>* jpeg);
00067   bool GetPreferredImageQualities(
00068       DeviceProperties::ImageQualityPreference preference, int* webp, int* jpeg)
00069       const;
00070   static int GetPreferredImageQualityCount();
00071 
00072   void LogDeviceInfo(AbstractLogRecord* log_record,
00073                      bool enable_aggressive_rewriters_for_mobile);
00074 
00075  private:
00076   friend class ImageRewriteTest;
00077   FRIEND_TEST(ImageRewriteTest, SquashImagesForMobileScreen);
00078   FRIEND_TEST(RequestPropertiesTest, GetScreenGroupIndex);
00079 
00080   void SetScreenResolution(int width, int height) const;
00081 
00082   scoped_ptr<DeviceProperties> device_properties_;
00083   scoped_ptr<DownstreamCachingDirectives> downstream_caching_directives_;
00084 
00085   mutable LazyBool supports_image_inlining_;
00086   mutable LazyBool supports_js_defer_;
00087   mutable LazyBool supports_lazyload_images_;
00088   mutable LazyBool supports_webp_;
00089   mutable LazyBool supports_webp_lossless_alpha_;
00090 
00091   DISALLOW_COPY_AND_ASSIGN(RequestProperties);
00092 };
00093 
00094 }  
00095 
00096 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines