#include "javascript_code_block.h"
Public Member Functions | |
JavascriptCodeBlock (const StringPiece &original_code, JavascriptRewriteConfig *config, const StringPiece &message_id, MessageHandler *handler) | |
bool | ProfitableToRewrite () |
const StringPiece | Rewritten () |
GoogleString * | RewrittenString () |
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 | |
JavascriptRewriteConfig * | config_ |
const GoogleString | message_id_ |
ID to stick at begining of message. | |
MessageHandler * | handler_ |
const GoogleString | original_code_ |
StringPiece | output_code_ |
bool | rewritten_ |
GoogleString | rewritten_code_ |
Object representing a block of Javascript code that might be a candidate for rewriting.
For now, we're content just being able to pull data in and parse it at all.
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] |
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.
StringPiece net_instaweb::JavascriptCodeBlock::output_code_ [protected] |
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).