Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | List of all members
net_instaweb::CssSummarizerBase Class Referenceabstract

#include "css_summarizer_base.h"

Inheritance diagram for net_instaweb::CssSummarizerBase:
net_instaweb::RewriteFilter net_instaweb::CommonFilter net_instaweb::EmptyHtmlFilter net_instaweb::HtmlFilter net_instaweb::CriticalCssBeaconFilter net_instaweb::CriticalSelectorFilter

Classes

struct  SummaryInfo
 

Public Member Functions

 CssSummarizerBase (RewriteDriver *driver)
 
- Public Member Functions inherited from net_instaweb::RewriteFilter
 RewriteFilter (RewriteDriver *driver)
 
virtual const char * id () const =0
 
virtual void DetermineEnabled (GoogleString *disabled_reason)
 
virtual bool CanModifyUrls ()
 
virtual const UrlSegmentEncoderencoder () const
 
virtual bool ComputeOnTheFly () const
 
virtual RewriteContextMakeNestedRewriteContext (RewriteContext *parent, const ResourceSlotPtr &slot)
 
virtual void EncodeUserAgentIntoResourceContext (ResourceContext *context) const
 
virtual const
RewriteOptions::Filter
RelatedFilters (int *num_filters) const
 
virtual const StringPieceVector * RelatedOptions () const
 
- Public Member Functions inherited from net_instaweb::CommonFilter
 CommonFilter (RewriteDriver *driver)
 
const GoogleUrlbase_url () const
 Getters. More...
 
const GoogleUrldecoded_base_url () const
 
RewriteDriverdriver () const
 
HtmlElementnoscript_element () const
 
void InsertNodeAtBodyEnd (HtmlNode *data)
 
virtual void StartDocument ()
 Note: Don't overload these methods, overload the implementers instead!
 
virtual void StartElement (HtmlElement *element)
 
virtual void EndElement (HtmlElement *element)
 
ResourcePtr CreateInputResource (StringPiece input_url, RewriteDriver::InputRole role, bool *is_authorized)
 
ResourcePtr CreateInputResourceOrInsertDebugComment (StringPiece input_url, RewriteDriver::InputRole role, HtmlElement *element)
 
void ResolveUrl (StringPiece input_url, GoogleUrl *out_url)
 
bool IsRelativeUrlLoadPermittedByCsp (StringPiece url, CspDirective role)
 
bool BaseUrlIsValid () const
 
bool DebugMode () const
 
bool CanAddPagespeedOnloadToImage (const HtmlElement &)
 
virtual void LogFilterModifiedContent ()
 
virtual
RewriteDriver::InlineAuthorizationPolicy 
AllowUnauthorizedDomain () const
 
virtual bool IntendedForInlining () const
 
void AddJsToElement (StringPiece js, HtmlElement *script)
 
- Public Member Functions inherited from net_instaweb::EmptyHtmlFilter
virtual void Cdata (HtmlCdataNode *cdata)
 Called for CDATA blocks (e.g. <![CDATA[foobar]]>)
 
virtual void Comment (HtmlCommentNode *comment)
 Called for HTML comments that aren't IE directives (e.g. ).
 
virtual void IEDirective (HtmlIEDirectiveNode *directive)
 
virtual void Directive (HtmlDirectiveNode *directive)
 Called for HTML directives (e.g. <!doctype foobar>).
 
virtual void Flush ()
 
ScriptUsage GetScriptUsage () const override
 
- Public Member Functions inherited from net_instaweb::HtmlFilter
bool is_enabled () const
 
void set_is_enabled (bool is_enabled)
 
virtual const char * Name () const =0
 The name of this filter – used for logging and debugging.
 

Static Public Member Functions

static void InitStats (Statistics *statistics)
 
- Static Public Member Functions inherited from net_instaweb::RewriteFilter
static StringPiece GetCharsetForScript (const Resource *script, const StringPiece attribute_charset, const StringPiece enclosing_charset)
 
static GoogleString GetCharsetForStylesheet (const Resource *stylesheet, const StringPiece attribute_charset, const StringPiece enclosing_charset)
 
- Static Public Member Functions inherited from net_instaweb::CommonFilter
static bool ExtractMetaTagDetails (const HtmlElement &element, const ResponseHeaders *headers, GoogleString *content, GoogleString *mime_type, GoogleString *charset)
 

Static Public Attributes

static const char kNumCssUsedForCriticalCssComputation []
 
static const char kNumCssNotUsedForCriticalCssComputation []
 
- Static Public Attributes inherited from net_instaweb::CommonFilter
static const char kCreateResourceFailedDebugMsg []
 Debug message to be inserted when resource creation fails.
 

Protected Types

enum  SummaryState {
  kSummaryOk, kSummaryStillPending, kSummaryCssParseError, kSummaryResourceCreationFailed,
  kSummaryInputUnavailable, kSummarySlotRemoved
}
 

Protected Member Functions

virtual GoogleString CacheKeySuffix () const
 
virtual bool MustSummarize (HtmlElement *element) const
 
virtual void Summarize (Css::Stylesheet *stylesheet, GoogleString *out) const =0
 
virtual void RenderSummary (int pos, HtmlElement *element, HtmlCharactersNode *char_node, bool *is_element_deleted)
 
virtual void WillNotRenderSummary (int pos, HtmlElement *element, HtmlCharactersNode *char_node)
 
virtual void SummariesDone ()
 
int NumStyles () const
 
const SummaryInfoGetSummaryForStyle (int pos) const
 
virtual void StartDocumentImpl ()
 
virtual void EndDocument ()
 
virtual void StartElementImpl (HtmlElement *element)
 
virtual void Characters (HtmlCharactersNode *characters)
 
virtual void EndElementImpl (HtmlElement *element)
 
virtual void RenderDone ()
 
virtual RewriteContextMakeRewriteContext ()
 
- Protected Member Functions inherited from net_instaweb::RewriteFilter
virtual const char * LoggingId ()
 This class logs using id().
 
- Protected Member Functions inherited from net_instaweb::CommonFilter
ServerContextserver_context () const
 
const RewriteOptionsrewrite_options ()
 

Additional Inherited Members

- Public Types inherited from net_instaweb::HtmlFilter
enum  ScriptUsage { kWillInjectScripts, kMayInjectScripts, kNeverInjectsScripts }
 Describes a filter's relationship with scripts. More...
 

Detailed Description

This class helps implement filters that try to compute some properties of all the screen-affecting CSS in the page except for scoped <style> blocks (which are left untouched). They are expected to override Summarize() to perform the per-CSS computation; then at SummariesDone() they can lookup summaries via NumStyles/GetSummaryForStyle.

Member Enumeration Documentation

Enumerator
kSummaryOk 

All OK!

kSummaryStillPending 

Computation/Fetches ongoing, we don't have a result yet.

kSummaryCssParseError 

CSS parse error we can't recover from.

kSummaryResourceCreationFailed 

Could not create the resource object, so its URL is malformed or we do not have permission to rewrite it.

kSummaryInputUnavailable 

Fetch result unusable, either error or not cacheable.

kSummarySlotRemoved 

Slot got removed by an another optimization.

Member Function Documentation

virtual GoogleString net_instaweb::CssSummarizerBase::CacheKeySuffix ( ) const
protectedvirtual

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.

virtual void net_instaweb::CssSummarizerBase::Characters ( HtmlCharactersNode characters)
protectedvirtual

If a subclass overloads this function and wishes to use InsertNodeAtBodyEnd(), it needs to make an upcall to this implementation for InsertNodeAtBodyEnd() to work correctly.

Reimplemented from net_instaweb::CommonFilter.

virtual void net_instaweb::CssSummarizerBase::EndDocument ( )
protectedvirtual

Note: EndDocument will be called immediately before the last Flush call. (which also means that in the RewriteDriver use it is called before rendering for the last flush window).

Reimplemented from net_instaweb::EmptyHtmlFilter.

Reimplemented in net_instaweb::CriticalSelectorFilter.

const SummaryInfo& net_instaweb::CssSummarizerBase::GetSummaryForStyle ( int  pos) const
inlineprotected

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.

virtual RewriteContext* net_instaweb::CssSummarizerBase::MakeRewriteContext ( )
protectedvirtual

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 bool net_instaweb::CssSummarizerBase::MustSummarize ( HtmlElement element) const
inlineprotectedvirtual

This method should be overridden if some CSS should not go through the summarization process (eg because it uses an inapplicable media type and we'll just throw it away when we're done anyway). By default all CSS must be summarized.

Reimplemented in net_instaweb::CriticalCssBeaconFilter.

int net_instaweb::CssSummarizerBase::NumStyles ( ) const
inlineprotected

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::RenderDone ( )
protectedvirtual

Notifies a filter that an asynchronous rewrite & render computation phase has finished. This is not used by HtmlParse itself, but only by RewriteDriver for pre-render filters. Happens after the corresponding flush, for every flush window. Default implementation does nothing.

Todo:
TODO(morlovich): Push this down into CommonFilter and convert all the pre-render filters to inherit off it.

Reimplemented from net_instaweb::HtmlFilter.

Reimplemented in net_instaweb::CriticalSelectorFilter.

virtual void net_instaweb::CssSummarizerBase::RenderSummary ( int  pos,
HtmlElement element,
HtmlCharactersNode char_node,
bool *  is_element_deleted 
)
protectedvirtual

This can be optionally overridden to modify a CSS element based on a successfully computed summary. It might not be invoked if cached information is not readily available, and will not be invoked if CSS parsing failed or some other error occurred. Invocation occurs from a thread with HTML parser context state, so both DOM modification and GetSummaryForStyle() are safe to use. If invoked, the method will be called before SummariesDone().

pos is the position of the element in the summary table.

element points to the <link> or <style> element that was summarized. If the element was a <style>, char_node will also point to its contents node; otherwise it will be NULL. Overrides need to set is_element_deleted to true if they delete the element.

The default implementation does nothing.

Reimplemented in net_instaweb::CriticalSelectorFilter.

virtual void net_instaweb::CssSummarizerBase::StartDocumentImpl ( )
protectedvirtual

Overrides of the filter APIs. You MUST 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 ( )
protectedvirtual

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 CommonFilter::InsertNodeAtBodyEnd(node).

Note that the timing of this can vary widely — it can occur during initial parse, during the render phase, or even at RenderDone, so implementors should not make assumptions about what other filters may have done to the DOM.

Base version does nothing.

Reimplemented in net_instaweb::CriticalCssBeaconFilter.

virtual void net_instaweb::CssSummarizerBase::Summarize ( Css::Stylesheet *  stylesheet,
GoogleString out 
) const
protectedpure 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::CriticalCssBeaconFilter, and net_instaweb::CriticalSelectorFilter.

virtual void net_instaweb::CssSummarizerBase::WillNotRenderSummary ( int  pos,
HtmlElement element,
HtmlCharactersNode char_node 
)
protectedvirtual

Like RenderSummary, but called in cases where we're unable to render a summary for some reason (including not being able to compute one). Note: not called when we're canceled due to disable_further_processing.

Like with RenderSummary, this corresponds to entry [pos] in the summary table, and elements points to the <link> or <style> containing CSS, with char_node being non-null in case it was a <style>.

Reimplemented in net_instaweb::CriticalSelectorFilter.


The documentation for this class was generated from the following file: