Page Speed Optimization Libraries  1.2.24.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | Friends
net_instaweb::ImageRewriteFilter Class Reference

#include "image_rewrite_filter.h"

Inheritance diagram for net_instaweb::ImageRewriteFilter:
net_instaweb::RewriteFilter net_instaweb::CommonFilter net_instaweb::EmptyHtmlFilter net_instaweb::HtmlFilter

List of all members.

Public Member Functions

 ImageRewriteFilter (RewriteDriver *driver)
virtual void StartDocumentImpl ()
virtual void StartElementImpl (HtmlElement *element)
virtual void EndElementImpl (HtmlElement *element)
virtual const char * Name () const
 The name of this filter -- used for logging and debugging.
virtual const char * id () const
bool TryInline (int64 image_inline_max_bytes, const CachedResult *cached_result, ResourceSlot *slot, GoogleString *data_url)
RewriteContextMakeNestedRewriteContextForCss (int64 css_image_inline_max_bytes, RewriteContext *parent, const ResourceSlotPtr &slot)
virtual RewriteContextMakeNestedRewriteContext (RewriteContext *parent, const ResourceSlotPtr &slot)

Static Public Member Functions

static void InitStats (Statistics *statistics)
static bool ParseDimensionAttribute (const char *position, int *value)
static bool UpdateDesiredImageDimsIfNecessary (const ImageDim &image_dim, RewriteDriver *driver, ImageDim *desired_dim)

Static Public Attributes

static const char kImageOngoingRewrites []
 name for statistic used to bound rewriting work.
static const char kImageNoRewritesHighResolution []
 # of images that we decided not to rewrite because of size constraint.
static const char kImageRewritesDroppedDueToLoad []
static const char kImageRewritesDroppedMIMETypeUnknown []
 # of images not rewritten because the image MIME type is unknown.
static const char kImageRewritesDroppedServerWriteFail []
static const char kImageRewritesDroppedNoSavingResize []
static const char kImageRewritesDroppedNoSavingNoResize []
static const char kInlinableImageUrlsPropertyName []

Protected Member Functions

virtual const UrlSegmentEncoderencoder () const
virtual RewriteContextMakeRewriteContext ()

Friends

class Context

Detailed Description

Identify img tags in html and optimize them.

Todo:
TODO(jmaessen): Big open question: how best to link pulled-in resources to rewritten urls, when in general those urls will be in a different domain.

Member Function Documentation

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.

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.

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

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.

static bool net_instaweb::ImageRewriteFilter::UpdateDesiredImageDimsIfNecessary ( const ImageDim &  image_dim,
RewriteDriver driver,
ImageDim *  desired_dim 
) [static]

Update desired image dimensions if necessary. Returns true if it is updated.


Member Data Documentation

TimedVariable denoting image rewrites we dropped due to load (too many concurrent rewrites)

# of images not rewritten because the rewriting does not reduce the data size by a certain threshold. The image is not resized in this case.

# of images not rewritten because the rewriting does not reduce the data size by a certain threshold. The image is resized in this case.

# of images not rewritten because the server fails to write the merged html files.

The property cache property name used to store URLs discovered when image_inlining_identify_and_cache_without_rewriting() is set in the RewriteOptions.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines