Page Speed Optimization Libraries
1.13.35.1
|
Context used by CssFilter under async flow that flattens . More...
#include "css_flatten_imports_context.h"
Public Member Functions | |
CssFlattenImportsContext (RewriteContext *parent, CssFilter *filter, CssFilter::Context *rewriter, CssHierarchy *hierarchy) | |
virtual GoogleString | CacheKeySuffix () const |
virtual void | RewriteSingle (const ResourcePtr &input_resource, const OutputResourcePtr &output_resource) |
Subclasses of SingleRewriteContext must override this: More... | |
void | Harvest () |
bool | PolicyPermitsRendering () const |
virtual void | Render () |
virtual const char * | id () const |
Returns the filter ID. | |
virtual OutputResourceKind | kind () const |
Public Member Functions inherited from net_instaweb::SingleRewriteContext | |
SingleRewriteContext (RewriteDriver *driver, RewriteContext *parent, ResourceContext *resource_context) | |
Public Member Functions inherited from net_instaweb::RewriteContext | |
RewriteContext (RewriteDriver *driver, RewriteContext *parent, ResourceContext *resource_context) | |
int | num_slots () const |
ResourceSlotPtr | slot (int index) const |
int | num_outputs () const |
OutputResourcePtr | output (int i) const |
int | num_output_partitions () const |
const CachedResult * | output_partition (int i) const |
CachedResult * | mutable_output_partition (int i) |
bool | chained () const |
void | AddSlot (const ResourceSlotPtr &slot) |
void | RemoveLastSlot () |
void | AddNestedContext (RewriteContext *context) |
void | CallFetchInputs () |
void | CallLockFailed () |
void | CallStartFetchImpl () |
void | Initiate () |
bool | Fetch (const OutputResourcePtr &output_resource, AsyncFetch *fetch, MessageHandler *message_handler) |
bool | slow () const |
bool | is_metadata_cache_miss () const |
This particular rewrite was a metadata cache miss. | |
bool | has_parent () const |
Returns true if this is a nested rewriter. | |
bool | IsNestedIn (StringPiece id) const |
void | CheckNotFrozen () |
RewriteContext * | parent () |
Allows a nested rewriter to walk up its parent hierarchy. | |
const RewriteContext * | parent () const |
int | num_nested () const |
Accessors for the nested rewrites. | |
RewriteContext * | nested (int i) const |
RewriteDriver * | Driver () const |
void | set_force_rewrite (bool x) |
If called with true, forces a rewrite and re-generates the output. | |
bool | rewrite_uncacheable () const |
void | set_rewrite_uncacheable (bool rewrite_uncacheable) |
const ResourceContext * | resource_context () const |
GoogleString | ToString () const |
Returns debug information about this RewriteContext. | |
GoogleString | ToStringWithPrefix (StringPiece prefix) const |
Additional Inherited Members | |
Public Types inherited from net_instaweb::RewriteContext | |
typedef std::vector< InputInfo * > | InputInfoStarVector |
Static Public Member Functions inherited from net_instaweb::RewriteContext | |
static void | InitStats (Statistics *stats) |
Initializes statistics. | |
Static Public Attributes inherited from net_instaweb::RewriteContext | |
static const char | kNumRewritesAbandonedForLockContention [] |
static const char | kNumDeadlineAlarmInvocations [] |
static const char | kHashMismatchMessage [] |
Protected Types inherited from net_instaweb::RewriteContext | |
typedef std::vector< GoogleUrl * > | GoogleUrlStarVector |
Protected Member Functions inherited from net_instaweb::SingleRewriteContext | |
virtual bool | Partition (OutputPartitions *partitions, OutputResourceVector *outputs) |
SingleRewriteContext takes care of these methods from RewriteContext: | |
virtual void | Rewrite (int partition_index, CachedResult *partition, const OutputResourcePtr &output) |
void | AddLinkRelCanonical (const ResourcePtr &input, ResponseHeaders *output) |
Adds a link: rel=canonical header pointing to the input URL as canonical. | |
void | AddLinkRelCanonicalForFallbackHeaders (ResponseHeaders *output) |
Helper for using above in FixFetchFallbackHeaders() | |
Protected Member Functions inherited from net_instaweb::RewriteContext | |
ServerContext * | FindServerContext () const |
const RewriteOptions * | Options () const |
OutputPartitions * | partitions () |
void | AddRecheckDependency () |
virtual bool | OptimizationOnly () const |
virtual void | PartitionAsync (OutputPartitions *partitions, OutputResourceVector *outputs) |
void | PartitionDone (RewriteResult result) |
void | CrossThreadPartitionDone (RewriteResult result) |
void | RewriteDone (RewriteResult result, int partition_index) |
virtual bool | SendFallbackResponse (StringPiece output_url_base, StringPiece contents, AsyncFetch *async_fetch, MessageHandler *handler) |
void | StartNestedTasks () |
bool | AreOutputsAllowedByCsp (CspDirective role) const |
Helper that checks that all output resources are OK with CSP as given role. | |
virtual void | WillNotRender () |
virtual void | Cancel () |
virtual const UrlSegmentEncoder * | encoder () const |
virtual GoogleString | UserAgentCacheKey (const ResourceContext *context) const |
virtual void | EncodeUserAgentIntoResourceContext (ResourceContext *context) |
void | AttachDependentRequestTrace (const StringPiece &label) |
RequestTrace * | dependent_request_trace () |
void | TracePrintf (const char *fmt,...) |
virtual void | StartFetchReconstruction () |
void | DetachFetch () |
virtual bool | DecodeFetchUrls (const OutputResourcePtr &output_resource, MessageHandler *message_handler, GoogleUrlStarVector *url_vector) |
virtual void | FixFetchFallbackHeaders (const CachedResult &cached_result, ResponseHeaders *headers) |
virtual void | FetchCallbackDone (bool success) |
virtual void | FetchTryFallback (const GoogleString &url, const StringPiece &hash) |
void | Freshen () |
Freshens resources proactively to avoid expiration in the near future. | |
bool | notify_driver_on_fetch_done () const |
void | set_notify_driver_on_fetch_done (bool value) |
AsyncFetch * | async_fetch () |
Note that the following must only be called in the fetch flow. | |
bool | FetchContextDetached () |
Is fetch_ detached? Only call this in the fetch flow. | |
MessageHandler * | fetch_message_handler () |
The message handler for the fetch. | |
bool | stale_rewrite () const |
Indicates whether we are serving a stale rewrite. | |
virtual int64 | GetRewriteDeadlineAlarmMs () const |
virtual bool | CreationLockBeforeStartFetch () const |
Should the context call LockForCreation before checking the cache? | |
virtual bool | FailOnHashMismatch () const |
virtual bool | ScheduleViaCentralController () |
virtual bool | ScheduleNestedContextViaCentalController () const |
void | ObtainLockForCreation (ServerContext *server_context, Function *callback) |
void | ReleaseCreationLock (bool succeeded) |
Static Protected Member Functions inherited from net_instaweb::RewriteContext | |
static bool | LookupMetadataForOutputResourceImpl (OutputResourcePtr output_resource, const GoogleUrl &gurl, RewriteContext *rewrite_context, RewriteDriver *driver, GoogleString *error_out, CacheLookupResultCallback *callback) |
Context used by CssFilter under async flow that flattens .
|
inline |
no resource_context
|
inlinevirtual |
Allows subclasses to add additional text to be appended to the metadata cache key. The default implementation returns "".
We have to include the media that applies to this context in its key so that, if someone 's the same file but with a different set of media on the rule, we don't fetch the cached file, since it has been minified based on the original set of applicable media.
Reimplemented from net_instaweb::RewriteContext.
|
inlinevirtual |
Once any nested rewrites have completed, the results of these can be incorporated into the rewritten data. For contexts that do not require any nested RewriteContexts, it is OK to skip overriding this method – the empty default implementation is fine.
Propagate any info on images from child rewrites.
Roll up the rewritten CSS(s) regardless of success or failure. Failure means we can't flatten it for some reason, such as incompatible charsets or invalid CSS, but we still need to cache the unflattened version so we don't try to flatten it again and again, so even in that case we don't return kRewriteFailed.
Our result is the combination of all our imports and our own rules.
Reimplemented from net_instaweb::RewriteContext.
|
inlinevirtual |
Rewrites come in three flavors, as described in output_resource_kind.h, so this method must be defined by subclasses to indicate which it is.
For example, we will avoid caching output_resource content in the HTTP cache for rewrites that are so quick to complete that it's fine to do the rewrite on every request. extend_cache is obviously in this category, and it's arguable we could treat js minification that way too (though we don't at the moment).
Implements net_instaweb::RewriteContext.
|
inlinevirtual |
This method gives the context a chance to verify that rendering the result is consistent with the current document's (Content Security) Policy, which may be different than that of the page for which the result was first computed + cached. Most subclasses can just call AreOutputsAllowedByCsp(), with appropriate role.
We apply CSP policy for flattening at top-level, not here.
Implements net_instaweb::RewriteContext.
|
inlinevirtual |
Performs rendering activities that span multiple HTML slots. For example, in a filter that combines N slots to 1, N-1 of the HTML elements might need to be removed. That can be performed in Render(). This method is optional; the base-class implementation is empty.
Note that unlike Harvest(), this method runs in the HTML thread (for top-level rewrites), and only runs if the rewrite completes prior to the rewrite-deadline. If the rewrite does make it by the deadline, RewriteContext::Render() will be invoked regardless of whether any slots were actually optimized successfully.
If we have flattened the imported file ...
If Harvest() was called, directly or from RewriteSingle(), then the minified contents are already set as are the stylesheet and input contents - in that case we don't actually have to do anything. If they haven't been called then the minified contents are empty and the result was found in the cache, in which case we have to set the input and minified contents to this result; the minified because we know that cached values are minified (we only cache minified contents), the input because we will need that to generate the stylesheet from when RollUpStylesheets is eventually called.
Parse() will compute flattening_succeeded_, which needs to be restored. See https://github.com/pagespeed/mod_pagespeed/issues/1092
Something has gone wrong earlier. It could be that the resource is not valid and cacheable (see SingleRewriteContext::Partition) or it could be that we're handling a cached failure, but it's hard to tell. So, mark flattening as failed but don't record a failure statistic nor a failure reason.
Reimplemented from net_instaweb::RewriteContext.
|
inlinevirtual |
Subclasses of SingleRewriteContext must override this:
We have to fix relative URLs in the CSS as they break if used in a CSS file that itself was loaded via a relative path from the base (for example, if styles/screen.css references ../images/icon.png, then the correct path for the image is /images/icon.png). We also need to absolutify or left-trim URLs in flattened CSS if no other rewriter is going to do it (cache extend, css image rewriter, etc), but it's hard to tell if that will happen so we transform URLs here regardless and note that for CssHierarchy::css_resolution_base().
If we rewrite the input resource's contents we need somewhere to store it; that's what the hierarchy's backing store is for.
See RewriteDriver::ResolveCssUrls about why we disable trimming in proxy mode. We also disable it if trimming is not enabled.
If we cannot parse the CSS then we cannot flatten it.
< Initiates rewriting of 'd files.
< Harvest centralizes all the output generation.
Implements net_instaweb::SingleRewriteContext.