19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_FLATTEN_IMPORTS_CONTEXT_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_FLATTEN_IMPORTS_CONTEXT_H_
22 #include "base/logging.h"
23 #include "net/instaweb/rewriter/cached_result.pb.h"
45 namespace net_instaweb {
57 hierarchy_(hierarchy) {
67 if (hierarchy_->media().empty()) {
70 suffix = hierarchy_->media()[0];
71 for (
int i = 1, n = hierarchy_->media().size(); i < n; ++i) {
72 StrAppend(&suffix,
"_", hierarchy_->media()[i]);
80 input_resource_ = input_resource;
81 output_resource_ = output_resource;
93 &hierarchy_->css_trim_url(),
94 driver->server_context(),
96 driver->message_handler());
99 StringWriter writer(hierarchy_->input_contents_backing_store());
102 if ( driver->server_context()->url_namer()->
ProxyMode()
105 !driver->
options()->Enabled(RewriteOptions::kLeftTrimUrls)) {
106 transformer.set_trim_urls(
false);
110 &transformer, driver->message_handler())) {
111 hierarchy_->set_input_contents_to_backing_store();
112 hierarchy_->set_input_contents_resolved(
true);
120 if (!hierarchy_->
Parse()) {
123 failure_reason = StrCat(
"Cannot parse the CSS in ",
124 hierarchy_->url_for_humans());
125 filter_->num_flatten_imports_minify_failed_->
Add(1);
126 }
else if (!hierarchy_->
CheckCharsetOk(input_resource, &failure_reason)) {
128 filter_->num_flatten_imports_charset_mismatch_->
Add(1);
134 hierarchy_->set_flattening_succeeded(
false);
158 mutable_output_partition(0)->set_inlined_data(
159 hierarchy_->minified_contents());
164 if (Driver()->Write(ResourceVector(1, input_resource_),
165 hierarchy_->minified_contents(),
168 output_resource_.get())) {
192 if (hierarchy_->minified_contents().empty()) {
193 hierarchy_->set_minified_contents(
194 output_partition(0)->inlined_data());
206 hierarchy_->set_flattening_succeeded(
false);
210 virtual const char*
id()
const {
211 return RewriteOptions::kCssImportFlattenerId;
RewriteContext * parent()
Allows a nested rewriter to walk up its parent hierarchy.
Definition: rewrite_context.h:280
Context used by CssFilter under async flow.
Definition: css_filter.h:251
void MergeNonCachingResponseHeaders(const ResourcePtr &input, const OutputResourcePtr &output)
Definition: server_context.h:494
virtual void Render()
Definition: css_flatten_imports_context.h:180
Definition: css_tag_scanner.h:147
virtual bool trim_urls_in_css() const
Return false in a subclass if you want to disallow all URL trimming in CSS.
Definition: rewrite_options.h:2278
virtual OutputResourceKind kind() const
Definition: css_flatten_imports_context.h:213
Definition: css_hierarchy.h:64
bool CheckCharsetOk(const ResourcePtr &resource, GoogleString *failure_reason)
int num_output_partitions() const
rewrite went fine
Definition: rewrite_result.h:29
bool PolicyPermitsRendering() const
Definition: css_flatten_imports_context.h:175
Context used by CssFilter under async flow that flattens .
Definition: css_flatten_imports_context.h:48
virtual void RewriteSingle(const ResourcePtr &input_resource, const OutputResourcePtr &output_resource)
Subclasses of SingleRewriteContext must override this:
Definition: css_flatten_imports_context.h:78
rewrite is impossible or undesirable
Definition: rewrite_result.h:28
void RewriteDone(RewriteResult result, int partition_index)
virtual GoogleString CacheKeySuffix() const
Definition: css_flatten_imports_context.h:61
void Harvest()
Definition: css_flatten_imports_context.h:144
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
ServerContext * FindServerContext() const
virtual const char * id() const
Returns the filter ID.
Definition: css_flatten_imports_context.h:210
void set_input_contents(const StringPiece input_contents)
Definition: css_hierarchy.h:113
int num_nested() const
Accessors for the nested rewrites.
Definition: rewrite_context.h:284
virtual ProxyExtent ProxyMode() const
Definition: url_namer.h:91
Definition: rewrite_driver.h:100
Definition: server_context.h:99
StringPiece ExtractUncompressedContents() const
Definition: rewrite_context.h:155
Derived from some input resource URL or URLs.
Definition: output_resource_kind.h:27
Definition: single_rewrite_context.h:36
StringPiece charset() const
Note: this is empty if the header is not specified.
Definition: resource.h:193
static void InheritChildImageInfo(RewriteContext *context)
Writer implementation for directing HTML output to a string.
Definition: string_writer.h:32
void RewriteCssFromNested(RewriteContext *parent, CssHierarchy *hierarchy)
Definition: css_filter.h:74
const RewriteOptions * options() const
Return the options used for this RewriteDriver.
Definition: rewrite_driver.h:496
CssFlattenImportsContext(RewriteContext *parent, CssFilter *filter, CssFilter::Context *rewriter, CssHierarchy *hierarchy)
Definition: css_flatten_imports_context.h:50
int64 Add(int64 non_negative_delta)
Adds 'delta' to the variable's value, returning the result.
Definition: statistics.h:53
OutputResourceKind
Definition: output_resource_kind.h:26
void AddFlatteningFailureReason(const GoogleString &reason)