Page Speed Optimization Libraries
1.4.26.1
|
#include "css_summarizer_base.h"
Classes | |
struct | SummaryInfo |
Public Member Functions | |
CssSummarizerBase (RewriteDriver *driver) | |
Protected Types | |
enum | SummaryState { kSummaryOk, kSummaryStillPending, kSummaryCssParseError, kSummaryResourceCreationFailed, kSummaryInputUnavailable } |
Protected Member Functions | |
virtual GoogleString | CacheKeySuffix () const |
virtual void | Summarize (Css::Stylesheet *stylesheet, GoogleString *out) const =0 |
virtual void | SummariesDone ()=0 |
void | InjectSummaryData (HtmlNode *data) |
int | NumStyles () const |
const SummaryInfo & | GetSummaryForStyle (int pos) const |
virtual void | NotifyInlineCss (HtmlElement *style_element, HtmlCharactersNode *content) |
virtual void | NotifyExternalCss (HtmlElement *link) |
virtual void | StartDocumentImpl () |
virtual void | EndDocument () |
Note: EndDocument will be called imediately before the last Flush call. | |
virtual void | StartElementImpl (HtmlElement *element) |
virtual void | Characters (HtmlCharactersNode *characters) |
Called for raw characters between tags. | |
virtual void | EndElementImpl (HtmlElement *element) |
virtual RewriteContext * | MakeRewriteContext () |
This class helps implement filters that try to compute some properties of all the screen-affecting CSS in the page. They are expected to override Summarize() to perform the per-CSS computation; then at SummariesDone() they can lookup summaries via NumStyles/GetSummaryForStyle.
enum net_instaweb::CssSummarizerBase::SummaryState [protected] |
virtual GoogleString net_instaweb::CssSummarizerBase::CacheKeySuffix | ( | ) | const [protected, virtual] |
This method should be overridden in case the subclass's summary computation depends on things other than the input CSS.
Reimplemented in net_instaweb::CriticalSelectorFilter.
const SummaryInfo& net_instaweb::CssSummarizerBase::GetSummaryForStyle | ( | int | pos | ) | const [inline, protected] |
Returns summary computed for the pos'th style in the document.
pos must be in [0, NumStyles())
Should be called from a thread context that has HTML parser state access.
void net_instaweb::CssSummarizerBase::InjectSummaryData | ( | HtmlNode * | data | ) | [protected] |
Inject summary data at the end of the document. Intended to be called from SummariesDone(). Tries to inject just before </body> if nothing else intervenes; otherwise tries to inject before </html> or, failing that, at the end of all content. This latter case still works in browsers, but is incredibly ugly. It can be necessitated by other post-</html> content, or by flushes in the body.
virtual RewriteContext* net_instaweb::CssSummarizerBase::MakeRewriteContext | ( | ) | [protected, virtual] |
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.
virtual void net_instaweb::CssSummarizerBase::NotifyInlineCss | ( | HtmlElement * | style_element, |
HtmlCharactersNode * | content | ||
) | [protected, virtual] |
These notify the subclass of external or inline CSS the summarizer has noticed. Overriding these is optional, and base implementations do nothing.
Reimplemented in net_instaweb::CriticalSelectorFilter.
int net_instaweb::CssSummarizerBase::NumStyles | ( | ) | const [inline, protected] |
Returns total number of <link> and <style> elements we encountered. This includes those for which we had problem computing summary information.
Should be called from a thread context that has HTML parser state access.
virtual void net_instaweb::CssSummarizerBase::StartDocumentImpl | ( | ) | [protected, virtual] |
Overrides of the filter APIs. You should call through to this class's implementations if you override them.
Implements net_instaweb::CommonFilter.
Reimplemented in net_instaweb::CriticalSelectorFilter.
virtual void net_instaweb::CssSummarizerBase::SummariesDone | ( | ) | [protected, pure virtual] |
This is called at the end of the document when all outstanding summary computations have completed, regardless of whether successful or not. It will not be called at all if they are still ongoing, however.
It's called from a context which allows HTML parser state access. You can insert things at end of document by constructing an HtmlNode* using the factories in HtmlParse and calling InjectSummaryData(element).
Implemented in net_instaweb::CriticalSelectorFilter, and net_instaweb::CriticalCssBeaconFilter.
virtual void net_instaweb::CssSummarizerBase::Summarize | ( | Css::Stylesheet * | stylesheet, |
GoogleString * | out | ||
) | const [protected, pure virtual] |
This should be overridden to compute a per-resource summary. The method should not modify the object state, and only put the result into *out as it may not be invoked in case of a cache hit. The subclass may mutate *stylesheet if it so wishes.
Note: this is called on a rewrite thread, so it should not access HTML parser state.
Implemented in net_instaweb::CriticalSelectorFilter, and net_instaweb::CriticalCssBeaconFilter.