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

#include "resource_slot.h"

Inheritance diagram for net_instaweb::ResourceSlot:
net_instaweb::RefCounted< ResourceSlot > net_instaweb::AssociationSlot net_instaweb::CssResourceSlot net_instaweb::FetchResourceSlot net_instaweb::HtmlResourceSlot net_instaweb::InlineAttributeSlot net_instaweb::InlineResourceSlot net_instaweb::InPlaceRewriteResourceSlot net_instaweb::NestedFilter::NestedSlot net_instaweb::NullResourceSlot net_instaweb::SrcSetSlot

Public Member Functions

 ResourceSlot (const ResourcePtr &resource)
 
ResourcePtr resource () const
 
virtual HtmlElementelement () 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 ()
 
RewriteContextLastContext () 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)
 

Detailed Description

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.

Todo:
TODO(jmarantz): make this class thread-safe.

Member Function Documentation

virtual bool net_instaweb::ResourceSlot::CanDirectSetUrl ( )
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 bool net_instaweb::ResourceSlot::DirectSetUrl ( const StringPiece &  url)
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.

virtual void net_instaweb::ResourceSlot::Finished ( )
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.

virtual GoogleString net_instaweb::ResourceSlot::LocationString ( ) const
pure virtual
static GoogleString net_instaweb::ResourceSlot::RelativizeOrPassthrough ( const RewriteOptions options,
StringPiece  url,
UrlRelativity  url_relativity,
const GoogleUrl base_url 
)
static

Either relativize the URL or pass it through depending on options set. PRECONDITION: url must parse as a valid GoogleUrl.

Todo:
TODO(sligocki): Take a GoogleUrl for url?
virtual void net_instaweb::ResourceSlot::Render ( )
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.

void net_instaweb::ResourceSlot::RequestDeleteElement ( )
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);

void net_instaweb::ResourceSlot::set_disable_further_processing ( bool  x)
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.

void net_instaweb::ResourceSlot::set_disable_rendering ( bool  x)
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.

void net_instaweb::ResourceSlot::set_need_aggregate_input_info ( bool  x)
inline

If this is true, input info on all inputs affecting this slot will be collected from all RewriteContexts chained to it.

void net_instaweb::ResourceSlot::set_preserve_urls ( bool  x)
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.

Todo:
TODO(jmarantz): Add a lock or that we or an overall protocol preventing unwanted interference between renderer's reads and worker writes.
bool net_instaweb::ResourceSlot::was_optimized ( ) const
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().


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