Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
image_url_encoder.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
17 
18 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_URL_ENCODER_H_
19 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_URL_ENCODER_H_
20 
21 #include "net/instaweb/rewriter/cached_result.pb.h"
27 
28 namespace net_instaweb {
29 
30 class GoogleUrl;
31 class RequestProperties;
32 class RewriteDriver;
33 class RewriteOptions;
34 class MessageHandler;
35 
63  public:
64  ImageUrlEncoder() {}
65  virtual ~ImageUrlEncoder();
66 
67  virtual void Encode(const StringVector& urls,
68  const ResourceContext* dim,
69  GoogleString* rewritten_url) const;
70 
71  virtual bool Decode(const StringPiece& url_segment,
72  StringVector* urls,
73  ResourceContext* dim,
74  MessageHandler* handler) const;
75 
80  static void SetLibWebpLevel(const RewriteOptions& options,
81  const RequestProperties& request_properties,
82  ResourceContext* resource_context);
83 
89  static void SetWebpAndMobileUserAgent(const RewriteDriver& driver,
90  ResourceContext* context);
91 
93  static bool IsWebpRewrittenUrl(const GoogleUrl& gurl);
94 
97  static void SetSmallScreen(const RewriteDriver& driver,
98  ResourceContext* context);
99 
102  const ResourceContext& resource_context);
103 
104  static bool HasDimensions(const ResourceContext& data) {
105  return (data.has_desired_image_dims() &&
106  HasValidDimensions(data.desired_image_dims()));
107  }
108 
109  static bool HasValidDimensions(const ImageDim& dims) {
110  return (dims.has_width() && dims.has_height());
111  }
112 
113  static bool HasDimension(const ResourceContext& data) {
114  return (data.has_desired_image_dims() &&
115  HasValidDimension(data.desired_image_dims()));
116  }
117 
118  static bool HasValidDimension(const ImageDim& dims) {
119  return (dims.has_width() || dims.has_height());
120  }
121 
122  static bool AllowVaryOnUserAgent(const RewriteOptions& options,
123  const RequestProperties& request_properties);
124 
125  static bool AllowVaryOnAccept(const RewriteOptions& options,
126  const RequestProperties& request_properties);
127 
128  private:
129 
130 };
131 
132 }
133 
134 #endif
class GoogleUrl
Definition: google_url.h:58
static GoogleString CacheKeyFromResourceContext(const ResourceContext &resource_context)
Helper function to generate Metadata cache key from ResourceContext.
virtual bool Decode(const StringPiece &url_segment, StringVector *urls, ResourceContext *dim, MessageHandler *handler) const
static void SetSmallScreen(const RewriteDriver &driver, ResourceContext *context)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static void SetWebpAndMobileUserAgent(const RewriteDriver &driver, ResourceContext *context)
static void SetLibWebpLevel(const RewriteOptions &options, const RequestProperties &request_properties, ResourceContext *resource_context)
Definition: rewrite_driver.h:100
static bool IsWebpRewrittenUrl(const GoogleUrl &gurl)
Determines whether the given URL is a pagespeed-rewritten webp URL.
Definition: url_segment_encoder.h:33
Definition: message_handler.h:39
Definition: rewrite_options.h:84
virtual void Encode(const StringVector &urls, const ResourceContext *dim, GoogleString *rewritten_url) const
Definition: request_properties.h:37
Definition: image_url_encoder.h:62