Page Speed Optimization Libraries
1.7.30.1
|
00001 /* 00002 * Copyright 2012 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_ 00021 00022 #include <map> 00023 #include <vector> 00024 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/string.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 00029 namespace net_instaweb { 00030 00031 class Hasher; 00032 class HtmlElement; 00033 class MessageHandler; 00034 class RewriteDriver; 00035 class RewriteOptions; 00036 struct ContentType; 00037 00041 class StaticAssetManager { 00042 public: 00043 static const char kGStaticBase[]; 00044 static const char kDefaultLibraryUrlPrefix[]; 00045 00046 enum StaticAsset { 00047 kAddInstrumentationJs, 00048 kBlankGif, 00049 kBlinkJs, 00050 kClientDomainRewriter, 00051 kConsoleCss, 00052 kConsoleJs, 00053 kCriticalCssBeaconJs, 00054 kCriticalImagesBeaconJs, 00055 kDedupInlinedImagesJs, 00056 kDeferIframe, 00057 kDeferJs, 00058 kDelayImagesInlineJs, 00059 kDelayImagesJs, 00060 kDeterministicJs, 00061 kExtendedInstrumentationJs, 00062 kGhostClickBusterJs, 00063 kLazyloadImagesJs, 00064 kLocalStorageCacheJs, 00065 kSplitHtmlBeaconJs, 00066 kEndOfModules, 00067 }; 00068 00069 StaticAssetManager(const GoogleString& static_asset_base, 00070 Hasher* hasher, 00071 MessageHandler* message_handler); 00072 00073 ~StaticAssetManager(); 00074 00077 const GoogleString& GetAssetUrl(const StaticAsset& module, 00078 const RewriteOptions* options) const; 00079 00081 const char* GetAsset(const StaticAsset& module, 00082 const RewriteOptions* options) const; 00083 00089 bool GetAsset(StringPiece file_name, StringPiece* content, 00090 ContentType* content_type, StringPiece* cache_header) const; 00091 00095 void AddJsToElement(StringPiece js, HtmlElement* script, 00096 RewriteDriver* driver) const; 00097 00098 00101 void set_gstatic_hash(const StaticAsset& module, 00102 const GoogleString& gstatic_base, 00103 const GoogleString& hash); 00104 00110 void set_serve_asset_from_gstatic(bool serve_asset_from_gstatic) { 00111 serve_asset_from_gstatic_ = serve_asset_from_gstatic; 00112 } 00113 00115 void set_library_url_prefix(const StringPiece& url_prefix) { 00116 url_prefix.CopyToString(&library_url_prefix_); 00117 InitializeAssetUrls(); 00118 } 00119 00120 void set_static_asset_base(const StringPiece& x) { 00121 x.CopyToString(&static_asset_base_); 00122 InitializeAssetUrls(); 00123 } 00124 00125 private: 00126 class Asset; 00127 00128 typedef std::map<GoogleString, StaticAsset> FileNameToModuleMap; 00129 00130 void InitializeAssetStrings(); 00131 void InitializeAssetUrls(); 00132 00133 GoogleString static_asset_base_; 00135 Hasher* hasher_; 00136 MessageHandler* message_handler_; 00137 00138 std::vector<Asset*> assets_; 00139 FileNameToModuleMap file_name_to_module_map_; 00140 00141 bool serve_asset_from_gstatic_; 00142 GoogleString library_url_prefix_; 00143 GoogleString cache_header_with_long_ttl_; 00144 GoogleString cache_header_with_private_ttl_; 00145 00146 DISALLOW_COPY_AND_ASSIGN(StaticAssetManager); 00147 }; 00148 00149 } 00150 00151 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_