net_instaweb::JavascriptCodeBlock Class Reference

#include "javascript_code_block.h"

List of all members.

Public Member Functions

 JavascriptCodeBlock (const StringPiece &original_code, JavascriptRewriteConfig *config, const StringPiece &message_id, MessageHandler *handler)
bool ProfitableToRewrite ()
const StringPiece Rewritten ()
GoogleStringRewrittenString ()
const JavascriptLibraryId ComputeJavascriptLibrary ()

Static Public Member Functions

static bool UnsafeToRename (const StringPiece &script)
static void ToJsStringLiteral (const StringPiece &original, GoogleString *escaped)
static GoogleString JsUrlHash (const GoogleString &url, Hasher *hasher)

Protected Member Functions

void Rewrite ()

Protected Attributes

JavascriptRewriteConfigconfig_
const GoogleString message_id_
 ID to stick at begining of message.
MessageHandlerhandler_
const GoogleString original_code_
StringPiece output_code_
bool rewritten_
GoogleString rewritten_code_

Detailed Description

Object representing a block of Javascript code that might be a candidate for rewriting.

Todo:
TODO(jmaessen): Does this architecture make sense when we have multiple scripts on a page and the ability to move code around a bunch? How do we maintain JS context in that setting?

For now, we're content just being able to pull data in and parse it at all.


Member Function Documentation

const JavascriptLibraryId net_instaweb::JavascriptCodeBlock::ComputeJavascriptLibrary (  ) 

Is the current block a JS library that can be redirected to Google? If so, return the info necessary to do so. Otherwise returns a block for which .recognized() is false.

static GoogleString net_instaweb::JavascriptCodeBlock::JsUrlHash ( const GoogleString url,
Hasher hasher 
) [inline, static]

Generates a hash of a URL escaped to be safe to use in a Javascript identifier, so that variable names can be safely created that won't collide with other local Javascript.

Hashes may contain '-', which isn't valid in a JavaScript name, so replace every '-' with '$'.

bool net_instaweb::JavascriptCodeBlock::ProfitableToRewrite (  )  [inline]

Rewrites the javascript code and returns whether that successfully made it smaller.

const StringPiece net_instaweb::JavascriptCodeBlock::Rewritten (  )  [inline]
Todo:
TODO(jmaessen): Other questions we might reasonably ask: Can this code be floated downwards?

Returns the current (maximally-rewritten) contents of the code block.

GoogleString* net_instaweb::JavascriptCodeBlock::RewrittenString (  )  [inline]

Returns the rewritten contents as a mutable GoogleString* suitable for swap(). This should only be used if ProfitableToRewrite() holds.

static void net_instaweb::JavascriptCodeBlock::ToJsStringLiteral ( const StringPiece &  original,
GoogleString escaped 
) [inline, static]

Converts a regular string to what can be used in Javascript directly. Note that output also contains starting and ending quotes, to facilitate embedding.

add quotes

static bool net_instaweb::JavascriptCodeBlock::UnsafeToRename ( const StringPiece &  script  )  [static]

Determines whether the javascript is brittle and will likely break if we alter its url.


Member Data Documentation

Note that output_code_ points to either original_code_ or to rewritten_code_ depending upon the results of processing (ie it's an indirection to locally-owned data).


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Tue May 29 16:34:01 2012 for Page Speed Optimization Libraries by  doxygen 1.6.3