00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00018
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_LOCAL_STORAGE_CACHE_FILTER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_LOCAL_STORAGE_CACHE_FILTER_H_
00021
00022 #include <set>
00023
00024 #include "net/instaweb/rewriter/public/rewrite_filter.h"
00025 #include "net/instaweb/util/public/basictypes.h"
00026 #include "net/instaweb/rewriter/public/rewrite_options.h"
00027 #include "net/instaweb/util/public/string.h"
00028 #include "net/instaweb/util/public/string_util.h"
00029
00030 namespace net_instaweb {
00031
00032 class CachedResult;
00033 class HtmlElement;
00034 class RewriteDriver;
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 class LocalStorageCacheFilter : public RewriteFilter {
00047 public:
00048 static const char kLscCookieName[];
00049 static const char kLscInitializer[];
00050
00052 class InlineState {
00053 public:
00054 InlineState() : initialized_(false), enabled_(false) {}
00055
00056 private:
00057 friend class LocalStorageCacheFilter;
00058
00059 bool initialized_;
00060 bool enabled_;
00061 GoogleString url_;
00062 };
00063
00064 explicit LocalStorageCacheFilter(RewriteDriver* rewrite_driver);
00065 virtual ~LocalStorageCacheFilter();
00066
00067 virtual void StartDocumentImpl();
00068 virtual void EndDocument();
00069 virtual void StartElementImpl(HtmlElement* element);
00070 virtual void EndElementImpl(HtmlElement* element);
00071
00072 virtual const char* Name() const { return "LocalStorageCache"; }
00073 virtual const char* id() const {
00074 return RewriteOptions::kLocalStorageCacheId;
00075 }
00076
00077 std::set<StringPiece>* mutable_cookie_hashes() { return &cookie_hashes_; }
00078
00096 static bool AddStorableResource(const StringPiece& url,
00097 RewriteDriver* driver,
00098 bool skip_cookie_check,
00099 HtmlElement* element,
00100 InlineState* state);
00101
00112 static bool AddLscAttributes(const StringPiece url,
00113 const CachedResult& cached,
00114 bool has_url,
00115 RewriteDriver* driver,
00116 HtmlElement* element);
00117
00119 static void RemoveLscAttributes(HtmlElement* element);
00120
00121 private:
00122 void InsertOurScriptElement(HtmlElement* before);
00123 static bool IsHashInCookie(const RewriteDriver* driver,
00124 const StringPiece cookie_name,
00125 const StringPiece hash,
00126 std::set<StringPiece>* hash_set);
00127 static GoogleString ExtractOtherImgAttributes(const HtmlElement* element);
00128
00130 bool script_inserted_;
00132 bool script_needs_inserting_;
00135 std::set<StringPiece> cookie_hashes_;
00136
00137 DISALLOW_COPY_AND_ASSIGN(LocalStorageCacheFilter);
00138 };
00139
00140 }
00141
00142 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_LOCAL_STORAGE_CACHE_FILTER_H_