Page Speed Optimization Libraries
1.13.35.1
|
#include "resource_slot.h"
Public Member Functions | |
ResourceSlot (const ResourcePtr &resource) | |
ResourcePtr | resource () const |
virtual HtmlElement * | element () const =0 |
Return HTML element associated with slot, or NULL if none (CSS, IPRO) | |
void | SetResource (const ResourcePtr &resource) |
void | set_preserve_urls (bool x) |
bool | preserve_urls () const |
void | set_disable_rendering (bool x) |
bool | disable_rendering () const |
void | RequestDeleteElement () |
bool | should_delete_element () const |
bool | was_optimized () const |
void | set_was_optimized (bool x) |
Marks the slot as having been optimized. | |
void | set_disable_further_processing (bool x) |
bool | disable_further_processing () const |
void | set_need_aggregate_input_info (bool x) |
bool | need_aggregate_input_info () const |
void | ReportInput (const InputInfo &input) |
const std::vector< InputInfo > * | inputs () const |
may be nullptr. | |
virtual void | Render ()=0 |
virtual void | Finished () |
virtual bool | DirectSetUrl (const StringPiece &url) |
virtual bool | CanDirectSetUrl () |
RewriteContext * | LastContext () const |
void | AddContext (RewriteContext *context) |
Adds a new context to this slot. | |
void | DetachContext (RewriteContext *context) |
virtual GoogleString | LocationString () const =0 |
Public Member Functions inherited from net_instaweb::RefCounted< ResourceSlot > | |
void | Release () |
void | AddRef () |
bool | HasOneRef () |
Static Public Member Functions | |
static GoogleString | RelativizeOrPassthrough (const RewriteOptions *options, StringPiece url, UrlRelativity url_relativity, const GoogleUrl &base_url) |
Protected Member Functions | |
REFCOUNT_FRIEND_DECLARATION (ResourceSlot) | |
A slot is a place in a web-site resource a URL is found, and may be rewritten. Types of slots include HTML element attributes and CSS background URLs. In principle they could also include JS ajax requests, although this is NYI.
|
inlinevirtual |
Returns true if DirectSetUrl is supported by this slot (html and css right now).
Reimplemented in net_instaweb::HtmlResourceSlot, and net_instaweb::CssResourceSlot.
void net_instaweb::ResourceSlot::DetachContext | ( | RewriteContext * | context | ) |
Detaches a context from the slot. This must be the first or last context that was added.
|
virtual |
Update the URL in the slot target without touching the resource. This is intended for when we're inlining things as data: URLs and also for placing the rewritten version of the URL in the slot. The method returns true if it successfully updates the slot target. Resources that are not explicitly authorized will get rejected at this point. Note that if you call this you should also call set_disable_rendering(true), or otherwise the result will be overwritten. Does not alter the URL in any way. Not supported on all slot types — presently only slots representing things within CSS and HTML have this operation (others will DCHECK-fail). Must be called from within a context's Render() method.
Reimplemented in net_instaweb::HtmlResourceSlot, net_instaweb::AssociationSlot, and net_instaweb::CssResourceSlot.
|
inlinevirtual |
Called after all contexts have had a chance to Render. This is especially useful for cases where Render was never called but you want something to be done to all slots.
Reimplemented in net_instaweb::CssResourceSlot.
RewriteContext* net_instaweb::ResourceSlot::LastContext | ( | ) | const |
Return the last context to have been added to this slot. Returns NULL if no context has been added to the slot so far.
|
pure virtual |
Returns a human-readable description of where this slot occurs, for use in log messages.
Implemented in net_instaweb::HtmlResourceSlot, net_instaweb::FetchResourceSlot, net_instaweb::NullResourceSlot, net_instaweb::NestedFilter::NestedSlot, net_instaweb::SrcSetSlot, net_instaweb::AssociationSlot, net_instaweb::InPlaceRewriteResourceSlot, net_instaweb::CssResourceSlot, net_instaweb::InlineResourceSlot, and net_instaweb::InlineAttributeSlot.
|
static |
|
pure virtual |
Render is not thread-safe. This must be called from the thread that owns the DOM or CSS file. The RewriteContext state machine will only call ResourceSlot::Render() on slots that were optimized successfully, and whose partitions are safely url_relocatable(). (Note that this is different from RewriteContext::Render).
Implemented in net_instaweb::HtmlResourceSlot, net_instaweb::FetchResourceSlot, net_instaweb::NullResourceSlot, net_instaweb::NestedFilter::NestedSlot, net_instaweb::SrcSetSlot, net_instaweb::AssociationSlot, net_instaweb::InPlaceRewriteResourceSlot, net_instaweb::CssResourceSlot, net_instaweb::InlineResourceSlot, and net_instaweb::InlineAttributeSlot.
|
inline |
Determines whether rendering the slot deletes the HTML Element. For example, in the CSS combine filter we want the Render to rewrite the first <link href>="">, but delete all the other <link>s.
Calling RequestDeleteElement() also forces set_disable_further_processing(true);
|
inline |
If disable_further_processing is true, no further filter taking this slot as input will run. Note that this affects only HTML rewriting (or nested rewrites) since fetch-style rewrites do not share slots even when more than one filter was involved. For this to persist properly on cache hits it should be set before RewriteDone is called. (This also means you should not be using this when partitioning failed). Only later filters are affected, not the currently running one.
|
inline |
If disable_rendering is true, this slot will do nothing on rendering, neither changing the URL or deleting any elements. This is intended for use of filters which do the entire work in the Context.
|
inline |
If this is true, input info on all inputs affecting this slot will be collected from all RewriteContexts chained to it.
|
inline |
Disables changing the URL of resources (does nothing if slot is not associated with a URL (for example, InlineResourceSlot).
void net_instaweb::ResourceSlot::SetResource | ( | const ResourcePtr & | resource | ) |
Note that while slots can be mutated by multiple threads; they are implemented with thread-safety in mind – only mainline render their results back into the DOM.
For example, SetResource may be run from a helper-thread, but we would not want that threaded mutation to propagate instantly back into the HTML or CSS DOM. We buffer the changes in the ResoureSlot and then render them in the request thread, synchronous to the HTML filter execution.
|
inline |
Returns true if any of the contexts touching this slot optimized it successfully. This in particular includes the case where a call to RewriteContext::Rewrite() on a partition containing this slot returned kRewriteOk. Note in particular that was_optimized() does not tell you whether your filter optimized the slot! For this you should check output_partition(n)->optimizable().