Page Speed Optimization Libraries
1.13.35.1
|
#include "common_filter.h"
Public Member Functions | |
CommonFilter (RewriteDriver *driver) | |
const GoogleUrl & | base_url () const |
Getters. More... | |
const GoogleUrl & | decoded_base_url () const |
RewriteDriver * | driver () const |
HtmlElement * | noscript_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) |
virtual void | Characters (HtmlCharactersNode *characters) |
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 | EndDocument () |
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 () |
virtual void | DetermineEnabled (GoogleString *disabled_reason) |
virtual bool | CanModifyUrls () |
ScriptUsage | GetScriptUsage () const override |
Public Member Functions inherited from net_instaweb::HtmlFilter | |
virtual void | RenderDone () |
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 bool | ExtractMetaTagDetails (const HtmlElement &element, const ResponseHeaders *headers, GoogleString *content, GoogleString *mime_type, GoogleString *charset) |
Static Public Attributes | |
static const char | kCreateResourceFailedDebugMsg [] |
Debug message to be inserted when resource creation fails. | |
Protected Member Functions | |
ServerContext * | server_context () const |
const RewriteOptions * | rewrite_options () |
virtual void | StartDocumentImpl ()=0 |
virtual void | StartElementImpl (HtmlElement *element)=0 |
virtual void | EndElementImpl (HtmlElement *element)=0 |
virtual const char * | LoggingId () |
Additional Inherited Members | |
Public Types inherited from net_instaweb::HtmlFilter | |
enum | ScriptUsage { kWillInjectScripts, kMayInjectScripts, kNeverInjectsScripts } |
Describes a filter's relationship with scripts. More... | |
CommonFilter encapsulates useful functionality that many filters will want. All filters who want this functionality should inherit from CommonFilter and define the Helper methods rather than the main methods.
Currently, it stores whether we are in a <noscript> element (in which case, we should be careful about moving things out of this element).
The base-tag is maintained in the RewriteDriver, although it can be accessed via a convenience method here for historical reasons.
void net_instaweb::CommonFilter::AddJsToElement | ( | StringPiece | js, |
HtmlElement * | script | ||
) |
Add JavaScript code to an HtmlElement*. Requires MimeTypeXhtmlStatus(), preventing this from going into HtmlParse.
|
inlinevirtual |
Returns true if this filter allows domains not authorized by any pagespeed directive to be optimized. Filters that end up inlining content onto the HTML are almost the only ones that can safely do this.
Reimplemented in net_instaweb::CriticalCssBeaconFilter, net_instaweb::CriticalSelectorFilter, net_instaweb::JsInlineFilter, and net_instaweb::CssInlineFilter.
const GoogleUrl& net_instaweb::CommonFilter::base_url | ( | ) | const |
Getters.
URL of the requested HTML or resource.
bool net_instaweb::CommonFilter::BaseUrlIsValid | ( | ) | const |
Returns whether or not the base url is valid. This value will change as a filter processes the document. E.g. If there are url refs before the base tag is reached, it will return false until the filter sees the base tag. After the filter sees the base tag, it will return true.
bool net_instaweb::CommonFilter::CanAddPagespeedOnloadToImage | ( | const HtmlElement & | ) |
Returns true if the image element is not in a <noscript> block and it has a) no onload attribute or b) an onload attribute exists with the value being equal to the CriticalImagesBeaconFilter::kImageOnloadCode.
|
virtual |
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::EmptyHtmlFilter.
Reimplemented in net_instaweb::CssSummarizerBase, net_instaweb::CssFilter, net_instaweb::JsCombineFilter, net_instaweb::JavascriptFilter, net_instaweb::InsertGAFilter, net_instaweb::MakeShowAdsAsyncFilter, net_instaweb::CssOutlineFilter, net_instaweb::JsOutlineFilter, and net_instaweb::JsInlineFilter.
ResourcePtr net_instaweb::CommonFilter::CreateInputResource | ( | StringPiece | input_url, |
RewriteDriver::InputRole | role, | ||
bool * | is_authorized | ||
) |
Creates an input resource with the url evaluated based on input_url which may need to be absolutified relative to base_url(). Returns NULL if input resource url isn't valid, or can't legally be rewritten in the context of this page. *is_authorized will be set to false if the domain of input_url is not authorized, which could true of false regardless of the return value: for example if we are allowing inlining of resources from unauthorized domains we will return non-NULL but *is_authorized will be false; converse cases are possible too (e.g. input_url is a data URI).
ResourcePtr net_instaweb::CommonFilter::CreateInputResourceOrInsertDebugComment | ( | StringPiece | input_url, |
RewriteDriver::InputRole | role, | ||
HtmlElement * | element | ||
) |
Similar to CreateInputResource except that if the input_url is not authorized we insert a debug comment after the given element if possible (debug is enabled and the element is writable). The returned ResourcePtr is guaranteed to be non-NULL iff the input_url is authorized.
|
inline |
Returns whether the current options specify the "debug" filter. If set, then other filters can annotate output HTML with HTML comments indicating why they did or did not do an optimization, using HtmlParse::InsertComment.
const GoogleUrl& net_instaweb::CommonFilter::decoded_base_url | ( | ) | const |
For rewritten resources, decoded_base_url() is the base of the original (un-rewritten) resource's URL.
|
static |
Utility function to extract the mime type and/or charset from a meta tag, either the HTML4 http-equiv form or the HTML5 charset form: element is the meta tag element to process. headers is optional: if provided it is checked to see if it already has a content type with the tag's value; if so, returns false. content is set to the content attribute's value, http-equiv form only. mime_type is set to the extracted mime type, if any. charset is the set to the extracted charset, if any. returns true if the details were extracted, false if not. If true is returned then content will be empty for the HTML5 charset form and non-empty for the HTML4 http-equiv form; also an http-equiv attribute with a blank mime type returns false as it's not a valid format.
void net_instaweb::CommonFilter::InsertNodeAtBodyEnd | ( | HtmlNode * | data | ) |
Insert a node at the best available location in or near the closing body tag during EndDocument. This is useful for filters that want to insert scripts or summary data at the end of body, but need to wait until EndDocument to do so.
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 breaks HTML validation (and is incredibly ugly). It can be necessitated by other post-</html> content, or by flushes in the body.
Note that if a subclass overloads the Characters function, it needs to call the parent implementation for this function to be correct.
|
inlinevirtual |
Returns true if the filter intends to inline the resource it fetches. This is to support AllowWhenInlining. Unlike AllowUnauthorizedDomain() this doesn't have security implications and is just used for performance tuning.
Reimplemented in net_instaweb::CriticalCssBeaconFilter, net_instaweb::CriticalSelectorFilter, net_instaweb::JsInlineFilter, and net_instaweb::CssInlineFilter.
|
virtual |
Add this filter to the logged list of applied rewriters. The intended semantics of this are that it should only include filters that modified the content of the response to the request being processed. This class logs using Name(); subclasses may do otherwise.
|
inlineprotectedvirtual |
ID string used in logging. Inheritors should supply whatever short ID string they use.
Reimplemented in net_instaweb::RewriteFilter.
void net_instaweb::CommonFilter::ResolveUrl | ( | StringPiece | input_url, |
GoogleUrl * | out_url | ||
) |
Resolves input_url based on the driver's location and any base tag into out_url. If resolution fails, the resulting URL may be invalid.
|
protectedpure virtual |
Overload these implementer methods: Intentionally left abstract so that implementers don't forget to change the name from Blah to BlahImpl.
Implemented in net_instaweb::CombiningFilter, net_instaweb::NestedFilter, net_instaweb::CssSummarizerBase, net_instaweb::ImageRewriteFilter, net_instaweb::ResponsiveImageSecondFilter, net_instaweb::SimpleTextFilter, net_instaweb::CriticalSelectorFilter, net_instaweb::ImageCombineFilter, net_instaweb::CssFilter, net_instaweb::DelayImagesFilter, net_instaweb::JsCombineFilter, net_instaweb::FakeFilter, net_instaweb::ResponsiveImageFirstFilter, net_instaweb::LocalStorageCacheFilter, net_instaweb::DeferIframeFilter, net_instaweb::JavascriptFilter, net_instaweb::InsertGAFilter, net_instaweb::CacheExtender, net_instaweb::DedupInlinedImagesFilter, net_instaweb::DomainRewriteFilter, net_instaweb::CssCombineFilter, net_instaweb::UrlLeftTrimFilter, net_instaweb::AddInstrumentationFilter, net_instaweb::CriticalImagesBeaconFilter, net_instaweb::CssInlineFilter, net_instaweb::MakeShowAdsAsyncFilter, net_instaweb::JsInlineFilter, net_instaweb::MetaTagFilter, net_instaweb::CssOutlineFilter, net_instaweb::JsOutlineFilter, net_instaweb::CssMoveToHeadFilter, net_instaweb::PushPreloadFilter, net_instaweb::DeterministicJsFilter, net_instaweb::FlushHtmlFilter, net_instaweb::InsertDnsPrefetchFilter, net_instaweb::RedirectOnSizeLimitFilter, net_instaweb::InsertAmpLinkFilter, and net_instaweb::CollectDependenciesFilter.
|
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.
Reimplemented from net_instaweb::EmptyHtmlFilter.