19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_FILTER_H_
22 #include "net/instaweb/rewriter/cached_result.pb.h"
50 namespace net_instaweb {
52 class AssociationTransformer;
54 class CssImageRewriter;
56 class ImageCombineFilter;
57 class ImageRewriteFilter;
59 class RewriteDomainTransformer;
92 static void Terminate();
98 virtual void StartElementImpl(
HtmlElement* element);
102 virtual const char*
Name()
const {
return "CssFilter"; }
103 virtual const char* id()
const {
return RewriteOptions::kCssFilterId; }
105 ResourceContext* context)
const;
107 static const char kBlocksRewritten[];
108 static const char kParseFailures[];
109 static const char kFallbackRewrites[];
110 static const char kFallbackFailures[];
111 static const char kRewritesDropped[];
112 static const char kTotalBytesSaved[];
113 static const char kTotalOriginalBytes[];
114 static const char kUses[];
115 static const char kCharsetMismatch[];
116 static const char kInvalidUrl[];
117 static const char kLimitExceeded[];
118 static const char kMinifyFailed[];
119 static const char kRecursion[];
120 static const char kComplexQueries[];
122 RewriteContext* MakeNestedFlatteningContextInNewSlot(
123 const ResourcePtr& resource,
const GoogleString& location,
124 CssFilter::Context* rewriter, RewriteContext* parent,
128 *num_filters = merged_filters_size_;
129 return merged_filters_;
132 return related_options_;
142 friend class Context;
148 kAttributeWithoutUrls,
163 InlineCssKind inline_css_kind);
169 ResourcePtr MakeInlineResource(StringPiece content);
177 bool GetApplicableCharset(
const HtmlElement* element,
183 bool GetApplicableMedia(
const HtmlElement* element,
184 StringVector* media)
const;
186 bool in_style_element_;
226 Variable* num_flatten_imports_charset_mismatch_;
228 Variable* num_flatten_imports_invalid_url_;
230 Variable* num_flatten_imports_limit_exceeded_;
232 Variable* num_flatten_imports_minify_failed_;
234 Variable* num_flatten_imports_recursion_;
236 Variable* num_flatten_imports_complex_queries_;
242 static int merged_filters_size_;
245 static StringPieceVector* related_options_;
258 ResourceContext* context);
265 InlineCssKind inline_css_kind);
277 StringPiece input_contents,
283 CssHierarchy* mutable_hierarchy() {
return &hierarchy_; }
289 virtual bool Partition(OutputPartitions* partitions,
290 OutputResourceVector* outputs);
293 virtual const char*
id()
const {
return filter_->id(); }
300 const ResourceContext* resource_context)
const;
303 void GetCssBaseUrlToUse(
const ResourcePtr& input_resource,
306 void GetCssTrimUrlToUse(
const ResourcePtr& input_resource,
307 const StringPiece& output_url_base,
310 void GetCssTrimUrlToUse(
const ResourcePtr& input_resource,
314 bool RewriteCssText(
const GoogleUrl& css_base_gurl,
316 const StringPiece& in_text,
318 bool text_is_declarations,
322 void RewriteCssFromRoot(
const GoogleUrl& css_base_gurl,
324 const StringPiece& in_text, int64 in_text_size,
325 bool has_unparseables, Css::Stylesheet* stylesheet);
332 bool FallbackRewriteUrls(
const GoogleUrl& css_base_gurl,
334 const StringPiece& in_text);
338 bool SerializeCss(int64 in_text_size,
339 const Css::Stylesheet* stylesheet,
342 bool previously_optimized,
343 bool stylesheet_is_declarations,
351 bool IsInlineAttribute()
const {
352 return (rewrite_inline_attribute_ != NULL);
358 int64 ImageInlineMaxBytes()
const;
360 virtual bool ScheduleViaCentralController() {
return true; }
363 scoped_ptr<CssImageRewriter> css_image_rewriter_;
364 ImageRewriteFilter* image_rewrite_filter_;
365 CssResourceSlotFactory slot_factory_;
374 scoped_ptr<AssociationTransformer> fallback_transformer_;
377 scoped_ptr<RewriteDomainTransformer> absolutifier_;
381 HtmlElement* rewrite_element_;
386 HtmlElement* rewrite_inline_element_;
389 HtmlCharactersNode* rewrite_inline_char_node_;
394 HtmlElement::Attribute* rewrite_inline_attribute_;
399 InlineCssKind rewrite_inline_css_kind_;
403 GoogleUrl initial_css_base_gurl_;
404 GoogleUrl initial_css_trim_gurl_;
405 scoped_ptr<GoogleUrl> base_gurl_for_fallback_;
406 scoped_ptr<GoogleUrl> trim_gurl_for_fallback_;
407 ResourcePtr input_resource_;
408 OutputResourcePtr output_resource_;
RewriteContext * parent()
Allows a nested rewriter to walk up its parent hierarchy.
Definition: rewrite_context.h:280
class GoogleUrl
Definition: google_url.h:58
Context used by CssFilter under async flow.
Definition: css_filter.h:251
Definition: html_element.h:66
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: css_filter.h:102
Definition: statistics.h:43
static void AddRelatedOptions(StringPieceVector *target)
Add this filters related options to the given vector.
virtual GoogleString CacheKeySuffix() const
bool PolicyPermitsRendering() const override
Leaf node representing raw characters in HTML.
Definition: html_node.h:167
virtual GoogleString UserAgentCacheKey(const ResourceContext *resource_context) const
Implements UserAgentCacheKey method of RewriteContext.
Definition: css_resource_slot.h:83
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
virtual OutputResourceKind kind() const
Definition: css_filter.h:294
Definition: css_hierarchy.h:64
Definition: html_element.h:42
Definition: ref_counted_ptr.h:69
static void InitStats(Statistics *statistics)
Context used by CssFilter under async flow that flattens .
Definition: css_flatten_imports_context.h:48
virtual const StringPieceVector * RelatedOptions() const
Definition: css_filter.h:131
virtual const UrlSegmentEncoder * encoder() const
virtual void StartDocumentImpl()
virtual RewriteContext * MakeRewriteContext()
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual const RewriteOptions::Filter * RelatedFilters(int *num_filters) const
Definition: css_filter.h:127
virtual RewriteContext * MakeNestedRewriteContext(RewriteContext *parent, const ResourceSlotPtr &slot)
Definition: async_fetch.h:53
virtual bool Partition(OutputPartitions *partitions, OutputResourceVector *outputs)
SingleRewriteContext takes care of these methods from RewriteContext:
Definition: rewrite_filter.h:35
Filter
Definition: rewrite_options.h:106
Definition: rewrite_driver.h:100
Definition: rewrite_context.h:155
Definition: image_rewrite_filter.h:64
Derived from some input resource URL or URLs.
Definition: output_resource_kind.h:27
virtual const char * id() const
Returns the filter ID.
Definition: css_filter.h:293
CssFilter(RewriteDriver *driver, CacheExtender *cache_extender, ImageRewriteFilter *image_rewriter, ImageCombineFilter *image_combiner)
Definition: url_segment_encoder.h:33
Definition: single_rewrite_context.h:36
virtual const UrlSegmentEncoder * encoder() const
Definition: statistics.h:73
void SetupInlineRewrite(HtmlElement *style_element, HtmlCharactersNode *text)
Setup rewriting for inline, attribute, or external CSS.
static void Initialize()
Initialize & Terminate must be paired.
Definition: message_handler.h:39
Definition: image_combine_filter.h:58
Definition: css_url_encoder.h:49
void RewriteCssFromNested(RewriteContext *parent, CssHierarchy *hierarchy)
virtual void EncodeUserAgentIntoResourceContext(ResourceContext *context) const
Definition: cache_extender.h:49
Definition: css_filter.h:74
virtual void Characters(HtmlCharactersNode *characters)
virtual bool SendFallbackResponse(StringPiece output_url_base, StringPiece input_contents, AsyncFetch *async_fetch, MessageHandler *handler)
virtual void RewriteSingle(const ResourcePtr &input, const OutputResourcePtr &output)
Subclasses of SingleRewriteContext must override this:
friend class CssHierarchy
for statistics
Definition: css_filter.h:144
OutputResourceKind
Definition: output_resource_kind.h:26
AsyncFetch * async_fetch()
Note that the following must only be called in the fetch flow.