~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/request_properties.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright 2013 Google Inc. All Rights Reserved.
2
 
//
3
 
// Licensed under the Apache License, Version 2.0 (the "License");
4
 
// you may not use this file except in compliance with the License.
5
 
// You may obtain a copy of the License at
6
 
//
7
 
//      http://www.apache.org/licenses/LICENSE-2.0
8
 
//
9
 
// Unless required by applicable law or agreed to in writing, software
10
 
// distributed under the License is distributed on an "AS IS" BASIS,
11
 
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
 
// See the License for the specific language governing permissions and
13
 
// limitations under the License.
14
 
 
15
 
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_
16
 
#define NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_
17
 
 
18
 
#include <vector>
19
 
 
20
 
#include "net/instaweb/http/public/user_agent_matcher.h"
21
 
#include "net/instaweb/rewriter/public/device_properties.h"
22
 
#include "net/instaweb/util/public/basictypes.h"
23
 
#include "net/instaweb/util/public/gtest_prod.h"
24
 
#include "net/instaweb/util/public/string_util.h"
25
 
#include "pagespeed/kernel/base/scoped_ptr.h"            // for scoped_ptr
26
 
 
27
 
namespace net_instaweb {
28
 
 
29
 
class DownstreamCachingDirectives;
30
 
class AbstractLogRecord;
31
 
class RequestHeaders;
32
 
 
33
 
// This class keeps track of the request properties of the client, which are for
34
 
// the most part learned from the UserAgent string and specific request headers
35
 
// that indicate what optimizations are supported; most properties are described
36
 
// in device_properties.h.  It relies on DeviceProperties and
37
 
// DownstreamCachingDirectives objects for deciding on support for a given
38
 
// capability.
39
 
class RequestProperties {
40
 
 public:
41
 
  explicit RequestProperties(UserAgentMatcher* matcher);
42
 
  virtual ~RequestProperties();
43
 
 
44
 
  // Sets the user agent string on the underlying DeviceProperties object.
45
 
  void SetUserAgent(const StringPiece& user_agent_string);
46
 
  // Calls ParseCapabilityListFromRequestHeaders on the underlying
47
 
  // DownstreamCachingDirectives object.
48
 
  void ParseRequestHeaders(const RequestHeaders& request_headers);
49
 
 
50
 
  bool SupportsImageInlining() const;
51
 
  bool SupportsLazyloadImages() const;
52
 
  bool SupportsCriticalCss() const;
53
 
  bool SupportsCriticalCssBeacon() const;
54
 
  bool SupportsCriticalImagesBeacon() const;
55
 
  bool SupportsJsDefer(bool enable_mobile) const;
56
 
  // Note that it's assumed that if the proxy cache SupportsWebp it also
57
 
  // supports the Accept: image/webp header (since this represents a strict
58
 
  // subset of the user agents for which SupportsWebpRewrittenUrls holds).
59
 
  bool SupportsWebpInPlace() const;
60
 
  bool SupportsWebpRewrittenUrls() const;
61
 
  bool SupportsWebpLosslessAlpha() const;
62
 
  bool IsBot() const;
63
 
  bool SupportsSplitHtml(bool enable_mobile) const;
64
 
  bool CanPreloadResources() const;
65
 
  bool GetScreenResolution(int* width, int* height) const;
66
 
  UserAgentMatcher::DeviceType GetDeviceType() const;
67
 
  bool IsMobile() const;
68
 
  bool ForbidWebpInlining() const;
69
 
 
70
 
  // Does not own the vectors. Callers must ensure the lifetime of vectors
71
 
  // exceeds that of the RequestProperties.
72
 
  void SetPreferredImageQualities(
73
 
      const std::vector<int>* webp,  const std::vector<int>* jpeg);
74
 
  // Returns true iff WebP and Jpeg image quality are set for the preference.
75
 
  bool GetPreferredImageQualities(
76
 
      DeviceProperties::ImageQualityPreference preference, int* webp, int* jpeg)
77
 
      const;
78
 
  static int GetPreferredImageQualityCount();
79
 
 
80
 
  void LogDeviceInfo(AbstractLogRecord* log_record,
81
 
                     bool enable_aggressive_rewriters_for_mobile);
82
 
 
83
 
 private:
84
 
  friend class ImageRewriteTest;
85
 
  FRIEND_TEST(ImageRewriteTest, SquashImagesForMobileScreen);
86
 
  FRIEND_TEST(RequestPropertiesTest, GetScreenGroupIndex);
87
 
 
88
 
  void SetScreenResolution(int width, int height) const;
89
 
 
90
 
  scoped_ptr<DeviceProperties> device_properties_;
91
 
  scoped_ptr<DownstreamCachingDirectives> downstream_caching_directives_;
92
 
 
93
 
  mutable LazyBool supports_image_inlining_;
94
 
  mutable LazyBool supports_js_defer_;
95
 
  mutable LazyBool supports_lazyload_images_;
96
 
  mutable LazyBool supports_webp_in_place_;
97
 
  mutable LazyBool supports_webp_rewritten_urls_;
98
 
  mutable LazyBool supports_webp_lossless_alpha_;
99
 
 
100
 
  DISALLOW_COPY_AND_ASSIGN(RequestProperties);
101
 
};
102
 
 
103
 
}  // namespace net_instaweb
104
 
 
105
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_