Page Speed Optimization Libraries
1.6.29.3
|
#include "image_rewrite_filter.h"
Public Member Functions | |
ImageRewriteFilter (RewriteDriver *driver) | |
virtual void | StartDocumentImpl () |
virtual void | StartElementImpl (HtmlElement *element) |
virtual void | EndElementImpl (HtmlElement *element) |
virtual const char * | Name () const |
virtual const char * | id () const |
virtual void | EncodeUserAgentIntoResourceContext (ResourceContext *context) const |
bool | TryInline (int64 image_inline_max_bytes, const CachedResult *cached_result, ResourceSlot *slot, GoogleString *data_url) |
void | SetupRenderedImageDimensionsMap (const RenderedImages &rendered_images) |
Setup a map for RenderedImages and their dimensions. | |
RewriteContext * | MakeNestedRewriteContextForCss (int64 css_image_inline_max_bytes, RewriteContext *parent, const ResourceSlotPtr &slot) |
virtual RewriteContext * | MakeNestedRewriteContext (RewriteContext *parent, const ResourceSlotPtr &slot) |
bool | UpdateDesiredImageDimsIfNecessary (const ImageDim &image_dim, const ResourceContext &resource_context, ImageDim *desired_dim) |
bool | ShouldResize (const ResourceContext &context, const GoogleString &url, Image *image, ImageDim *desired_dimensions) |
bool | ResizeImageIfNecessary (const RewriteContext *rewrite_context, const GoogleString &url, ResourceContext *context, Image *image, CachedResult *cached) |
Image::CompressionOptions * | ImageOptionsForLoadedResource (const ResourceContext &context, const ResourcePtr &input_resource, bool is_css) |
virtual const RewriteOptions::Filter * | RelatedFilters (int *num_filters) const |
virtual const StringPieceVector * | RelatedOptions () const |
Static Public Member Functions | |
static void | InitStats (Statistics *statistics) |
static void | Initialize () |
static void | Terminate () |
static void | AddRelatedOptions (StringPieceVector *target) |
static bool | ParseDimensionAttribute (const char *position, int *value) |
static void | DisableRelatedFilters (RewriteOptions *options) |
Disable all filters listed in kRelatedFilters in options. | |
Static Public Attributes | |
static const char | kImageNoRewritesHighResolution [] |
Statistic names: | |
static const char | kImageOngoingRewrites [] |
static const char | kImageResizedUsingRenderedDimensions [] |
static const char | kImageRewriteLatencyFailedMs [] |
static const char | kImageRewriteLatencyOkMs [] |
static const char | kImageRewritesDroppedDecodeFailure [] |
static const char | kImageRewritesDroppedDueToLoad [] |
static const char | kImageRewritesDroppedMIMETypeUnknown [] |
static const char | kImageRewritesDroppedNoSavingNoResize [] |
static const char | kImageRewritesDroppedNoSavingResize [] |
static const char | kImageRewritesDroppedServerWriteFail [] |
static const char | kImageRewritesSquashingForMobileScreen [] |
static const char | kImageRewrites [] |
static const char | kImageWebpFromGifFailureMs [] |
static const char | kImageWebpFromGifSuccessMs [] |
static const char | kImageWebpFromGifTimeouts [] |
static const char | kImageWebpFromJpegFailureMs [] |
static const char | kImageWebpFromJpegSuccessMs [] |
static const char | kImageWebpFromJpegTimeouts [] |
static const char | kImageWebpFromPngFailureMs [] |
static const char | kImageWebpFromPngSuccessMs [] |
static const char | kImageWebpFromPngTimeouts [] |
static const char | kImageWebpOpaqueFailureMs [] |
static const char | kImageWebpOpaqueSuccessMs [] |
static const char | kImageWebpOpaqueTimeouts [] |
static const char | kImageWebpWithAlphaFailureMs [] |
static const char | kImageWebpWithAlphaSuccessMs [] |
static const char | kImageWebpWithAlphaTimeouts [] |
static const char | kInlinableImageUrlsPropertyName [] |
static const RewriteOptions::Filter | kRelatedFilters [] |
static const int | kRelatedFiltersSize |
Protected Member Functions | |
virtual const UrlSegmentEncoder * | encoder () const |
virtual RewriteContext * | MakeRewriteContext () |
Friends | |
class | Context |
Identify img tags in html and optimize them.
virtual const UrlSegmentEncoder* net_instaweb::ImageRewriteFilter::encoder | ( | ) | const [protected, virtual] |
All RewriteFilters define how they encode URLs and other associated information needed for a rewrite into a URL. The default implementation handles a single URL with no extra data. The filter owns the encoder.
Reimplemented from net_instaweb::RewriteFilter.
virtual void net_instaweb::ImageRewriteFilter::EncodeUserAgentIntoResourceContext | ( | ResourceContext * | context | ) | const [virtual] |
Encodes user agent information needed by the filter into ResourceContext. See additional header document for RewriteContext::EncodeUserAgentIntoResourceContext.
Reimplemented from net_instaweb::RewriteFilter.
Image::CompressionOptions* net_instaweb::ImageRewriteFilter::ImageOptionsForLoadedResource | ( | const ResourceContext & | context, |
const ResourcePtr & | input_resource, | ||
bool | is_css | ||
) |
Allocate and initialize CompressionOptions object based on RewriteOptions and ResourceContext.
virtual RewriteContext* net_instaweb::ImageRewriteFilter::MakeNestedRewriteContext | ( | RewriteContext * | parent, |
const ResourceSlotPtr & | slot | ||
) | [virtual] |
Creates a nested rewrite for the given parent and slot and returns it. The result is not registered with the parent.
Reimplemented from net_instaweb::RewriteFilter.
RewriteContext* net_instaweb::ImageRewriteFilter::MakeNestedRewriteContextForCss | ( | int64 | css_image_inline_max_bytes, |
RewriteContext * | parent, | ||
const ResourceSlotPtr & | slot | ||
) |
Creates a nested rewrite for an image inside a CSS file with the given parent and slot, and returns it. The result is not registered with the parent.
virtual RewriteContext* net_instaweb::ImageRewriteFilter::MakeRewriteContext | ( | ) | [protected, virtual] |
Generates a RewriteContext appropriate for this filter. Default implementation returns NULL. This must be overridden by filters. This is used to implement Fetch.
Reimplemented from net_instaweb::RewriteFilter.
static bool net_instaweb::ImageRewriteFilter::ParseDimensionAttribute | ( | const char * | position, |
int * | value | ||
) | [static] |
The valid contents of a dimension attribute on an image element have one of the following forms: "45%" "45%px" "+45.0%" [45% of browser width; we can't handle this] "45", "+45", "45px", "45arbitraryjunk" "45px%" [45 pixels regardless of junk] Technically 0 is an invalid dimension, so we'll reject those as well; note that 0 dimensions occur in the wild and Safari and Chrome at least don't display anything.
We actually reject the arbitraryjunk cases, as older browsers (eg FF9, which isn't *that* old) don't deal with them at all. So the only trailing stuff we allow is px possibly with some white space. Note that some older browsers (like FF9) accept other units such as "in" or "pt" as synonyms for px!
We round fractions, as fractional pixels appear to be rounded in practice (and our image resize algorithms require integer pixel sizes).
Far more detail in the spec at: http://www.whatwg.org/specs/web-apps/current-work/multipage/ common-microsyntaxes.html#percentages-and-dimensions
virtual const RewriteOptions::Filter* net_instaweb::ImageRewriteFilter::RelatedFilters | ( | int * | num_filters | ) | const [virtual] |
Determines which filters are related to this RewriteFilter. Note, for example, that the ImageRewriteFilter class implements lots of different RewriteOptions::Filters.
This is used for embedding the relevant enabled filter IDs. See the doc for RewriteOptions::add_options_to_urls_. We want to support that without bloating URLs excessively adding unrelated filter settings.
The vector is returned in numerically increasing order so binary_search is possible.
num_filters is set to the size of this array.
Ownership of the filter-vector is not transferred to the caller; it is expected to return a pointer to a static vector.
Reimplemented from net_instaweb::RewriteFilter.
virtual const StringPieceVector* net_instaweb::ImageRewriteFilter::RelatedOptions | ( | ) | const [inline, virtual] |
Return the names of options related to this RewriteFilter in case-insensitive alphabetical order. NULL means there are none. Ownership of the vector is not transferred to the caller.
Reimplemented from net_instaweb::RewriteFilter.
bool net_instaweb::ImageRewriteFilter::ResizeImageIfNecessary | ( | const RewriteContext * | rewrite_context, |
const GoogleString & | url, | ||
ResourceContext * | context, | ||
Image * | image, | ||
CachedResult * | cached | ||
) |
Resize image if necessary, returning true if this resizing succeeds and false if it's unnecessary or fails.
bool net_instaweb::ImageRewriteFilter::ShouldResize | ( | const ResourceContext & | context, |
const GoogleString & | url, | ||
Image * | image, | ||
ImageDim * | desired_dimensions | ||
) |
Determines whether an image should be resized based on the current options.
Returns the dimensions to resize to in *desired_dimensions.
virtual void net_instaweb::ImageRewriteFilter::StartDocumentImpl | ( | ) | [virtual] |
Overload these implementer methods: Intentionally left abstract so that implementers don't forget to change the name from Blah to BlahImpl.
Implements net_instaweb::CommonFilter.
bool net_instaweb::ImageRewriteFilter::TryInline | ( | int64 | image_inline_max_bytes, |
const CachedResult * | cached_result, | ||
ResourceSlot * | slot, | ||
GoogleString * | data_url | ||
) |
Can we inline resource? If so, encode its contents into the data_url, otherwise leave data_url alone.
bool net_instaweb::ImageRewriteFilter::UpdateDesiredImageDimsIfNecessary | ( | const ImageDim & | image_dim, |
const ResourceContext & | resource_context, | ||
ImageDim * | desired_dim | ||
) |
Update desired image dimensions if necessary. Returns true if it is updated.
const char net_instaweb::ImageRewriteFilter::kInlinableImageUrlsPropertyName[] [static] |
The property cache property name used to store URLs discovered when image_inlining_identify_and_cache_without_rewriting() is set in the RewriteOptions.