Page Speed Optimization Libraries
1.8.31.3
|
#include "inline_rewrite_context.h"
Public Member Functions | |
InlineRewriteContext (CommonFilter *filter, HtmlElement *element, HtmlElement::Attribute *src) | |
Note that you should also call StartInlining() to do the work. | |
bool | StartInlining () |
Protected Member Functions | |
virtual bool | ShouldInline (const ResourcePtr &resource) const =0 |
Subclasses of InlineRewriteContext must override these: | |
virtual void | RenderInline (const ResourcePtr &resource, const StringPiece &text, HtmlElement *element)=0 |
virtual ResourcePtr | CreateResource (const char *url) |
virtual bool | Partition (OutputPartitions *partitions, OutputResourceVector *outputs) |
InlineRewriteContext takes care of these methods from RewriteContext;. | |
virtual void | Rewrite (int partition_index, CachedResult *partition, const OutputResourcePtr &output) |
virtual void | Render () |
virtual OutputResourceKind | kind () const |
HtmlElement * | get_element () const |
Class that unifies tasks common to building rewriters for filters that inline resources.
virtual ResourcePtr net_instaweb::InlineRewriteContext::CreateResource | ( | const char * | url | ) | [protected, virtual] |
Subclasses of InlineRewriteContext may override this to customize resource creation. Default version just uses CommonFilter::CreateInputResource(). url is permitted to be NULL.
virtual OutputResourceKind net_instaweb::InlineRewriteContext::kind | ( | ) | const [protected, virtual] |
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.
virtual void net_instaweb::InlineRewriteContext::Render | ( | ) | [protected, virtual] |
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.
Reimplemented from net_instaweb::RewriteContext.
virtual void net_instaweb::InlineRewriteContext::Rewrite | ( | int | partition_index, |
CachedResult * | partition, | ||
const OutputResourcePtr & | output | ||
) | [protected, virtual] |
Takes a completed rewrite partition and rewrites it. When complete, implementations should call RewriteDone(kRewriteOk) if they successfully created an output resource using RewriteDriver::Write, and RewriteDone(kRewriteFailed) if they didn't. They may also call RewriteDone(kTooBusy) in case system load/resource usage makes it dangerous for the filter to do optimization at this time.
Any information about the inputs or output that may be needed to update the containing document should be stored inside the CachedResult.
If implementors wish to rewrite resources referred to from within the inputs (e.g. images in CSS), they may create nested rewrite contexts and call AddNestedContext() on each, and then StartNestedTasks() when all have been added.
Implements net_instaweb::RewriteContext.
Starts the actual inlining process, and takes over memory management of this object. Returns true if the process is started, false if it cannot be started because the input resource cannot be created, in which case 'this' is deleted and accordingly no rewriting callbacks are invoked.