18 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_URL_ENCODER_H_
19 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_URL_ENCODER_H_
21 #include "net/instaweb/rewriter/cached_result.pb.h"
22 #include "pagespeed/kernel/base/basictypes.h"
23 #include "pagespeed/kernel/base/gtest_prod.h"
24 #include "pagespeed/kernel/base/string.h"
25 #include "pagespeed/kernel/base/string_util.h"
26 #include "pagespeed/kernel/util/url_segment_encoder.h"
28 namespace net_instaweb {
31 class RequestProperties;
72 virtual void Encode(
const StringVector& urls,
73 const ResourceContext* dim,
74 GoogleString* rewritten_url)
const;
76 virtual bool Decode(
const StringPiece& url_segment,
79 MessageHandler* handler)
const;
87 ResourceContext* resource_context);
95 ResourceContext* context);
103 ResourceContext* context);
111 const ResourceContext& resource_context);
113 static bool HasDimensions(
const ResourceContext& data) {
114 return (data.has_desired_image_dims() &&
115 HasValidDimensions(data.desired_image_dims()));
118 static bool HasValidDimensions(
const ImageDim& dims) {
119 return (dims.has_width() && dims.has_height());
122 static bool HasDimension(
const ResourceContext& data) {
123 return (data.has_desired_image_dims() &&
124 HasValidDimension(data.desired_image_dims()));
127 static bool HasValidDimension(
const ImageDim& dims) {
128 return (dims.has_width() || dims.has_height());
132 FRIEND_TEST(ImageRewriteTest, SquashImagesForMobileScreen);
133 FRIEND_TEST(ImageUrlEncoderTest, UserAgentScreenResolution);
138 static bool GetNormalizedScreenResolution(
139 int screen_width,
int screen_height,
int* normalized_width,
140 int* normalized_height);
142 DISALLOW_COPY_AND_ASSIGN(ImageUrlEncoder);
static GoogleString CacheKeyFromResourceContext(const ResourceContext &resource_context)
Helper function to generate Metadata cache key from ResourceContext.
static void SetSmallScreen(const RewriteDriver &driver, ResourceContext *context)
static void SetWebpAndMobileUserAgent(const RewriteDriver &driver, ResourceContext *context)
static void SetLibWebpLevel(const RewriteOptions &options, const RequestProperties &request_properties, ResourceContext *resource_context)
static void SetUserAgentScreenResolution(RewriteDriver *driver, ResourceContext *context)
Set context for screen resolution.
Definition: rewrite_driver.h:98
static bool IsWebpRewrittenUrl(const GoogleUrl &gurl)
Determines whether the given URL is a pagespeed-rewritten webp URL.
Definition: rewrite_options.h:83
static const int kSmallScreenSizeThresholdArea
Definition: image_url_encoder.h:67
Definition: request_properties.h:39
Definition: image_url_encoder.h:62