Page Speed Optimization Libraries
1.13.35.1
|
#include "html_filter.h"
Public Types | |
enum | ScriptUsage { kWillInjectScripts, kMayInjectScripts, kNeverInjectsScripts } |
Describes a filter's relationship with scripts. More... | |
Public Member Functions | |
virtual void | StartDocument ()=0 |
virtual void | EndDocument ()=0 |
virtual void | StartElement (HtmlElement *element)=0 |
virtual void | EndElement (HtmlElement *element)=0 |
virtual void | Cdata (HtmlCdataNode *cdata)=0 |
Called for CDATA blocks (e.g. <![CDATA[foobar]]>) | |
virtual void | Comment (HtmlCommentNode *comment)=0 |
Called for HTML comments that aren't IE directives (e.g. ). | |
virtual void | IEDirective (HtmlIEDirectiveNode *directive)=0 |
virtual void | Characters (HtmlCharactersNode *characters)=0 |
Called for raw characters between tags. | |
virtual void | Directive (HtmlDirectiveNode *directive)=0 |
Called for HTML directives (e.g. <!doctype foobar>). | |
virtual void | Flush ()=0 |
virtual void | RenderDone () |
virtual void | DetermineEnabled (GoogleString *disabled_reason)=0 |
bool | is_enabled () const |
void | set_is_enabled (bool is_enabled) |
virtual bool | CanModifyUrls ()=0 |
virtual ScriptUsage | GetScriptUsage () const =0 |
virtual const char * | Name () const =0 |
The name of this filter – used for logging and debugging. | |
Base-class used to register for HTML Parser Callbacks. Derive from this class and register with HtmlParse::AddFilter to use the HTML Parser.
Describes a filter's relationship with scripts.
Enumerator | |
---|---|
kWillInjectScripts |
Indicates that this filter generally needs to inject scripts, and therefore should be disabled in environments where scripts are not allowed, such as amp. The system also DCHECKs of scripts are injected from a filter where CanInjectScripts() is false. |
kMayInjectScripts |
Indicates that this filter may in some cases inject scripts, but still has value even if scripts are forbidden. For the rare cases where this value is appropriate, the filter must be explicitly verified to function correctly. |
kNeverInjectsScripts |
Indicates this filter never injects scripts.
|
|
pure virtual |
Invoked by the rewrite driver to query whether this filter will rewrite any urls.
Implemented in net_instaweb::EmptyHtmlFilter, net_instaweb::HtmlWriterFilter, and net_instaweb::RewriteFilter.
|
pure virtual |
Invoked by rewrite driver where all filters should determine whether they are enabled for this request. The re-writer my optionally set disabled_reason to explain why it disabled itself, which will appear in the debug output.
Implemented in net_instaweb::CriticalSelectorFilter, net_instaweb::DelayImagesFilter, net_instaweb::CriticalCssBeaconFilter, net_instaweb::DeferIframeFilter, net_instaweb::DedupInlinedImagesFilter, net_instaweb::AddInstrumentationFilter, net_instaweb::CssCombineFilter, net_instaweb::HtmlWriterFilter, net_instaweb::EmptyHtmlFilter, net_instaweb::JsDisableFilter, net_instaweb::RewriteFilter, net_instaweb::CriticalImagesBeaconFilter, net_instaweb::PushPreloadFilter, net_instaweb::InsertDnsPrefetchFilter, net_instaweb::JsDeferDisabledFilter, net_instaweb::FixReflowFilter, net_instaweb::SupportNoscriptFilter, net_instaweb::InsertAmpLinkFilter, and net_instaweb::DisableTestFilter.
|
pure virtual |
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).
Implemented in net_instaweb::CssSummarizerBase, net_instaweb::GoogleAnalyticsFilter, net_instaweb::ImageRewriteFilter, net_instaweb::ResponsiveImageSecondFilter, net_instaweb::CriticalSelectorFilter, net_instaweb::DelayImagesFilter, net_instaweb::MockFilter, net_instaweb::LocalStorageCacheFilter, net_instaweb::AmpDocumentFilter, net_instaweb::DedupInlinedImagesFilter, net_instaweb::DomainRewriteFilter, net_instaweb::CssCombineFilter, net_instaweb::CssInlineImportToLinkFilter, net_instaweb::AddInstrumentationFilter, net_instaweb::CriticalImagesBeaconFilter, net_instaweb::JsInlineFilter, net_instaweb::HtmlWriterFilter, net_instaweb::EmptyHtmlFilter, net_instaweb::DebugFilter, net_instaweb::RewrittenContentScanningFilter, net_instaweb::InsertDnsPrefetchFilter, and net_instaweb::AddHeadFilter.
|
pure virtual |
Notifies the Filter that a flush is occurring. A filter that's generating streamed output should flush at this time. A filter that's mutating elements can mutate any element seen since the most recent flush; once an element is flushed it is already on the wire to its destination and it's too late to mutate. Flush is initiated by an application calling HttpParse::Flush().
Flush() is called after all other handlers during a HttpParse::Flush(), except RenderDone(), which (if in use) happens after Flush().
Implemented in net_instaweb::CombiningFilter, net_instaweb::GoogleAnalyticsFilter, net_instaweb::JsCombineFilter, net_instaweb::CssInlineImportToLinkFilter, net_instaweb::CssCombineFilter, net_instaweb::MetaTagFilter, net_instaweb::ScanFilter, net_instaweb::HtmlWriterFilter, net_instaweb::EmptyHtmlFilter, net_instaweb::CssOutlineFilter, net_instaweb::JsOutlineFilter, net_instaweb::DebugFilter, net_instaweb::FlushHtmlFilter, and net_instaweb::AddHeadFilter.
|
pure virtual |
Note: there is also kRequiresScriptExecutionFilterSet in rewrite_options.cc, which identifies filters that will leave broken pages if javascript is disabled, and hence require noscript handing. The set of filters that CanInjectScripts is larger, as it includes filters that might inject beacons or other optional functionality that is not page-critical.
Implemented in net_instaweb::GoogleAnalyticsFilter, net_instaweb::LocalStorageCacheFilter, net_instaweb::ResponsiveImageSecondFilter, net_instaweb::DelayImagesFilter, net_instaweb::LazyloadImagesFilter, net_instaweb::JsCombineFilter, net_instaweb::CriticalCssBeaconFilter, net_instaweb::DeferIframeFilter, net_instaweb::CriticalSelectorFilter, net_instaweb::JavascriptFilter, net_instaweb::InsertGAFilter, net_instaweb::DomainRewriteFilter, net_instaweb::JsInlineFilter, net_instaweb::DedupInlinedImagesFilter, net_instaweb::EmptyHtmlFilter, net_instaweb::MakeShowAdsAsyncFilter, net_instaweb::SupportNoscriptFilter, net_instaweb::AddInstrumentationFilter, net_instaweb::CriticalImagesBeaconFilter, net_instaweb::JsOutlineFilter, net_instaweb::HtmlWriterFilter, net_instaweb::JsDisableFilter, net_instaweb::JsDeferDisabledFilter, net_instaweb::InsertAmpLinkFilter, net_instaweb::DeterministicJsFilter, and net_instaweb::RedirectOnSizeLimitFilter.
|
pure virtual |
Called for an IE directive; typically used for CSS styling. See http://msdn.microsoft.com/en-us/library/ms537512(VS.85).aspx
Implemented in net_instaweb::GoogleAnalyticsFilter, net_instaweb::JsCombineFilter, net_instaweb::LoggingFilter, net_instaweb::JavascriptFilter, net_instaweb::CssCombineFilter, net_instaweb::ScanFilter, net_instaweb::HtmlWriterFilter, and net_instaweb::EmptyHtmlFilter.
|
inline |
Intended to be called from DetermineEnabled implementations in filters. Returns whether a filter is enabled.
|
virtual |
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.
Reimplemented in net_instaweb::CssSummarizerBase, net_instaweb::ImageRewriteFilter, and net_instaweb::CriticalSelectorFilter.
|
inline |
Set whether this filter is enabled or not. Note that a filter may be included in the filter-chain for a configuration, but be disabled for a request based on the request properties, or even due to content (see HtmlParse::set_is_buffered()).
|
pure virtual |
Starts a new document. Filters should clear their state in this function, as the same Filter instance may be used for multiple HTML documents.
Implemented in net_instaweb::GoogleAnalyticsFilter, net_instaweb::MockFilter, net_instaweb::CommonFilter, net_instaweb::LoggingFilter, net_instaweb::AmpDocumentFilter, net_instaweb::CssInlineImportToLinkFilter, net_instaweb::AddIdsFilter, net_instaweb::CollapseWhitespaceFilter, net_instaweb::ScanFilter, net_instaweb::HtmlWriterFilter, net_instaweb::FixReflowFilter, net_instaweb::EmptyHtmlFilter, net_instaweb::BaseTagFilter, net_instaweb::HandleNoscriptRedirectFilter, net_instaweb::RewrittenContentScanningFilter, net_instaweb::CanonicalAttributes, net_instaweb::AddHeadFilter, and net_instaweb::StripSubresourceHintsFilter.
|
pure virtual |
When an HTML element is encountered during parsing, each filter's StartElement method is called. The HtmlElement lives for the entire duration of the document.
Implemented in net_instaweb::GoogleAnalyticsFilter, net_instaweb::MockFilter, net_instaweb::CommonFilter, net_instaweb::LoggingFilter, net_instaweb::AmpDocumentFilter, net_instaweb::CssInlineImportToLinkFilter, net_instaweb::AddIdsFilter, net_instaweb::CollapseWhitespaceFilter, net_instaweb::HtmlAttributeQuoteRemoval, net_instaweb::ScanFilter, net_instaweb::HtmlWriterFilter, net_instaweb::EmptyHtmlFilter, net_instaweb::BaseTagFilter, net_instaweb::FixReflowFilter, net_instaweb::HandleNoscriptRedirectFilter, net_instaweb::RewrittenContentScanningFilter, net_instaweb::SupportNoscriptFilter, net_instaweb::ElideAttributesFilter, net_instaweb::CanonicalAttributes, net_instaweb::AddHeadFilter, net_instaweb::PedanticFilter, net_instaweb::StripSubresourceHintsFilter, and net_instaweb::DecodeRewrittenUrlsFilter.