Page Speed Optimization Libraries  1.7.30.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Protected Member Functions
net_instaweb::ResourceSlot Class Reference

#include "resource_slot.h"

Inheritance diagram for net_instaweb::ResourceSlot:
net_instaweb::AssociationSlot net_instaweb::CssResourceSlot net_instaweb::FetchResourceSlot net_instaweb::HtmlResourceSlot net_instaweb::InPlaceRewriteResourceSlot net_instaweb::NestedFilter::NestedSlot

List of all members.

Public Member Functions

 ResourceSlot (const ResourcePtr &resource)
ResourcePtr resource () const
void SetResource (const ResourcePtr &resource)
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
virtual void Render ()=0
virtual void Finished ()
virtual void 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 ()=0

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 ( ) [inline, virtual]

Returns true if DirectSetUrl is supported by this slot (html and css right now).

Reimplemented in net_instaweb::HtmlResourceSlot, and net_instaweb::CssResourceSlot.

Detaches a context from the slot. This must be the first or last context that was added.

virtual void 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. 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 ( ) [inline, virtual]

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.

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 ( ) [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::NestedFilter::NestedSlot, net_instaweb::FetchResourceSlot, net_instaweb::AssociationSlot, net_instaweb::InPlaceRewriteResourceSlot, and net_instaweb::CssResourceSlot.

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);

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.

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::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.

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:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines