1
// Copyright 2013 Google Inc. All Rights Reserved.
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
7
// http://www.apache.org/licenses/LICENSE-2.0
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.
15
#ifndef NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_
16
#define NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_
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
27
namespace net_instaweb {
29
class DownstreamCachingDirectives;
30
class AbstractLogRecord;
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
39
class RequestProperties {
41
explicit RequestProperties(UserAgentMatcher* matcher);
42
virtual ~RequestProperties();
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);
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;
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;
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)
78
static int GetPreferredImageQualityCount();
80
void LogDeviceInfo(AbstractLogRecord* log_record,
81
bool enable_aggressive_rewriters_for_mobile);
84
friend class ImageRewriteTest;
85
FRIEND_TEST(ImageRewriteTest, SquashImagesForMobileScreen);
86
FRIEND_TEST(RequestPropertiesTest, GetScreenGroupIndex);
88
void SetScreenResolution(int width, int height) const;
90
scoped_ptr<DeviceProperties> device_properties_;
91
scoped_ptr<DownstreamCachingDirectives> downstream_caching_directives_;
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_;
100
DISALLOW_COPY_AND_ASSIGN(RequestProperties);
103
} // namespace net_instaweb
105
#endif // NET_INSTAWEB_REWRITER_PUBLIC_REQUEST_PROPERTIES_H_