19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_REWRITE_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_IMAGE_REWRITE_FILTER_H_
24 #include "net/instaweb/rewriter/cached_result.pb.h"
42 #include "pagespeed/kernel/http/image_types.pb.h"
45 namespace net_instaweb {
50 INLINE_UNSUPPORTED_DEVICE,
54 INLINE_CACHE_SMALL_IMAGES_UNREWRITTEN,
58 INLINE_INTERNAL_ERROR,
67 typedef std::map<GoogleString, AssociatedImageInfo> AssociatedImageInfoMap;
71 static const char kImageOngoingRewrites[];
72 static const char kImageResizedUsingRenderedDimensions[];
73 static const char kImageRewriteLatencyFailedMs[];
74 static const char kImageRewriteLatencyOkMs[];
75 static const char kImageRewriteLatencyTotalMs[];
76 static const char kImageRewritesDroppedDecodeFailure[];
77 static const char kImageRewritesDroppedDueToLoad[];
78 static const char kImageRewritesDroppedMIMETypeUnknown[];
79 static const char kImageRewritesDroppedNoSavingNoResize[];
80 static const char kImageRewritesDroppedNoSavingResize[];
81 static const char kImageRewritesDroppedServerWriteFail[];
82 static const char kImageRewritesSquashingForMobileScreen[];
83 static const char kImageRewrites[];
84 static const char kImageWebpRewrites[];
85 static const char kImageWebpFromGifFailureMs[];
86 static const char kImageWebpFromGifSuccessMs[];
87 static const char kImageWebpFromGifTimeouts[];
88 static const char kImageWebpFromJpegFailureMs[];
89 static const char kImageWebpFromJpegSuccessMs[];
90 static const char kImageWebpFromJpegTimeouts[];
91 static const char kImageWebpFromPngFailureMs[];
92 static const char kImageWebpFromPngSuccessMs[];
93 static const char kImageWebpFromPngTimeouts[];
94 static const char kImageWebpOpaqueFailureMs[];
95 static const char kImageWebpOpaqueSuccessMs[];
96 static const char kImageWebpOpaqueTimeouts[];
97 static const char kImageWebpWithAlphaFailureMs[];
98 static const char kImageWebpWithAlphaSuccessMs[];
99 static const char kImageWebpWithAlphaTimeouts[];
100 static const char kImageWebpFromGifAnimatedFailureMs[];
101 static const char kImageWebpFromGifAnimatedSuccessMs[];
102 static const char kImageWebpFromGifAnimatedTimeouts[];
110 static const int kRelatedFiltersSize;
114 static void InitStats(
Statistics* statistics);
115 static void Initialize();
116 static void Terminate();
117 static void AddRelatedOptions(StringPieceVector* target);
121 virtual void StartElementImpl(
HtmlElement* element);
122 virtual void EndElementImpl(
HtmlElement* element) {}
123 virtual const char*
Name()
const {
return "ImageRewrite"; }
124 virtual const char* id()
const {
return RewriteOptions::kImageCompressionId; }
126 ResourceContext* context)
const;
139 RewriteContext* context,
140 AssociatedImageInfo* out);
145 int64 image_inline_max_bytes,
const CachedResult* cached_result,
173 int64 css_image_inline_max_bytes,
174 RewriteContext* parent,
175 const ResourceSlotPtr& slot);
180 const ResourceSlotPtr& slot);
185 const ImageDim& image_dim,
const ResourceContext& resource_context,
186 ImageDim* desired_dim);
194 ImageDim* desired_dimensions);
199 const Context* rewrite_context,
const GoogleString& url,
200 ResourceContext* context, Image* image, CachedResult* cached);
205 const ResourceContext& context,
const ResourcePtr& input_resource);
209 return related_options_;
224 friend class Context;
227 void InfoAndTrace(Context* context,
const char* format, ...)
241 bool FinishRewriteCssImageUrl(
242 int64 css_image_inline_max_bytes,
247 bool FinishRewriteImageUrl(
248 const CachedResult* cached, const ResourceContext* resource_context,
253 void SaveIfInlinable(const StringPiece& contents,
254 const ImageType image_type,
255 CachedResult* cached);
263 bool* is_resized_using_rendered_dimensions);
271 void ResizeLowQualityImage(
273 CachedResult* cached);
279 bool IsHtmlCriticalImage(StringPiece image_url) const;
284 bool StoreUrlInPropertyCache(const StringPiece& url);
286 void SaveDebugMessageToCache(const
GoogleString& message,
287 CachedResult* cached_result);
289 GoogleString UrlForDebugMessages(const Context* context) const;
296 Variable* image_resized_using_rendered_dimensions_;
298 Variable* image_norewrites_high_resolution_;
303 Variable* image_rewrites_dropped_intentionally_;
305 Variable* image_rewrites_dropped_decode_failure_;
307 Variable* image_rewrites_dropped_mime_type_unknown_;
310 Variable* image_rewrites_dropped_server_write_fail_;
313 Variable* image_rewrites_dropped_nosaving_resize_;
316 Variable* image_rewrites_dropped_nosaving_noresize_;
326 Variable* image_rewrite_total_bytes_saved_;
330 Variable* image_rewrite_total_original_bytes_;
342 Variable* image_rewrite_latency_total_ms_;
346 Histogram* image_rewrite_latency_failed_ms_;
357 StringSet inlinable_urls_;
360 Image::ConversionVariables webp_conversion_variables_;
363 static StringPieceVector* related_options_;
365 std::map<
GoogleString, AssociatedImageInfo> image_info_;
367 bool saw_end_document_;
InlineResult
See MessageForInlineResult for enum meanings.
Definition: image_rewrite_filter.h:48
void ReportDroppedRewrite()
Update stats for a rewrite dropped due to load.
virtual void EndDocument()
RewriteContext * MakeNestedRewriteContextForCss(int64 css_image_inline_max_bytes, RewriteContext *parent, const ResourceSlotPtr &slot)
bool ResizeImageIfNecessary(const Context *rewrite_context, const GoogleString &url, ResourceContext *context, Image *image, CachedResult *cached)
Definition: statistics.h:43
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: image_rewrite_filter.h:123
virtual RewriteContext * MakeRewriteContext()
virtual void EncodeUserAgentIntoResourceContext(ResourceContext *context) const
InlineResult TryInline(bool is_html, bool is_critical, int64 image_inline_max_bytes, const CachedResult *cached_result, ResourceSlot *slot, GoogleString *data_url)
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
virtual void StartDocumentImpl()
Definition: resource_slot.h:54
Definition: html_element.h:42
bool UpdateDesiredImageDimsIfNecessary(const ImageDim &image_dim, const ResourceContext &resource_context, ImageDim *desired_dim)
static bool ParseDimensionAttribute(const char *position, int *value)
DimensionState GetDimensions(Css::Declarations *decls, int *width, int *height)
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
Definition: resource_slot.h:259
Image::CompressionOptions * ImageOptionsForLoadedResource(const ResourceContext &context, const ResourcePtr &input_resource)
static void DisableRelatedFilters(RewriteOptions *options)
Disable all filters listed in kRelatedFilters in options.
virtual RewriteContext * MakeNestedRewriteContext(RewriteContext *parent, const ResourceSlotPtr &slot)
Definition: rewrite_filter.h:35
virtual const StringPieceVector * RelatedOptions() const
Definition: image_rewrite_filter.h:208
Filter
Definition: rewrite_options.h:106
Definition: rewrite_driver.h:100
virtual const UrlSegmentEncoder * encoder() const
Image should not be inlined because it is part of a responsive image.
Definition: image_rewrite_filter.h:56
Definition: content_type.h:31
RewriteResult
Definition: rewrite_result.h:27
void RegisterImageInfo(const AssociatedImageInfo &image_info)
virtual const RewriteOptions::Filter * RelatedFilters(int *num_filters) const
Definition: rewrite_context.h:155
static const char kInlinableImageUrlsPropertyName[]
Definition: image_rewrite_filter.h:107
Definition: image_rewrite_filter.h:64
Definition: statistics.h:138
Definition: url_segment_encoder.h:33
Definition: statistics.h:73
Definition: statistics.h:298
static bool ExtractAssociatedImageInfo(const CachedResult *in, RewriteContext *context, AssociatedImageInfo *out)
static const char kImageNoRewritesHighResolution[]
Statistic names:
Definition: image_rewrite_filter.h:70
Definition: rewrite_options.h:84
Definition: image_url_encoder.h:62
virtual void RenderDone()
bool ShouldResize(const ResourceContext &context, const GoogleString &url, Image *image, ImageDim *desired_dimensions)