Page Speed Optimization Libraries
1.2.24.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_JAVASCRIPT_MANAGER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_STATIC_JAVASCRIPT_MANAGER_H_ 00021 00022 #include <map> 00023 #include <utility> 00024 #include <vector> 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 class UrlNamer; 00037 00041 class StaticJavascriptManager { 00042 public: 00043 static const char kGStaticBase[]; 00044 static const char kDefaultLibraryUrlPrefix[]; 00045 static const char kBlinkGstaticSuffix[]; 00046 static const char kDeferJsGstaticSuffix[]; 00047 static const char kBlinkJsFileName[]; 00048 static const char kDeferJsFileName[]; 00049 static const char kDeferJsDebugFileName[]; 00050 static const char kJsExtension[]; 00051 00052 enum JsModule { 00053 kAddInstrumentationJs, 00054 kClientDomainRewriter, 00055 kDeferIframe, 00056 kDeferJs, 00057 kDelayImagesJs, 00058 kDelayImagesInlineJs, 00059 kDeterministicJs, 00060 kLazyloadImagesJs, 00061 kDetectReflowJs, 00062 kLocalStorageCacheJs, 00063 kEndOfModules, 00064 }; 00065 00066 StaticJavascriptManager(UrlNamer* url_namer, Hasher* hasher, 00067 MessageHandler* message_handler); 00068 00069 ~StaticJavascriptManager(); 00070 00073 const GoogleString& GetBlinkJsUrl(const RewriteOptions* options) const; 00074 00077 const GoogleString& GetDeferJsUrl(const RewriteOptions* options) const; 00078 00079 const char* GetJsSnippet(JsModule module, 00080 const RewriteOptions* options); 00081 00087 bool GetJsSnippet(StringPiece file_name, StringPiece* content, 00088 StringPiece* cache_header); 00089 00093 void AddJsToElement(StringPiece js, HtmlElement* script, 00094 RewriteDriver* driver); 00095 00096 00098 void set_gstatic_blink_hash(const GoogleString& hash); 00099 00101 void set_gstatic_defer_js_hash(const GoogleString& hash); 00102 00104 void set_serve_js_from_gstatic(bool serve_js_from_gstatic) { 00105 serve_js_from_gstatic_ = serve_js_from_gstatic; 00106 } 00107 00109 void set_library_url_prefix(const StringPiece& url_prefix) { 00110 url_prefix.CopyToString(&library_url_prefix_); 00111 InitBlink(); 00112 InitDeferJs(); 00113 } 00114 00115 private: 00118 typedef std::pair<StringPiece, GoogleString> JsSnippetHashPair; 00119 typedef std::map<GoogleString, JsSnippetHashPair> FileNameToStringsMap; 00120 typedef std::vector<const char*> StaticJsVector; 00122 StaticJsVector opt_js_vector_; 00123 StaticJsVector debug_js_vector_; 00124 00125 void InitializeFileNameToJsStringMap(); 00126 00128 void InitBlink(); 00129 00131 void InitDeferJs(); 00132 00133 void InitializeJsStrings(); 00134 00136 UrlNamer* url_namer_; 00137 Hasher* hasher_; 00138 MessageHandler* message_handler_; 00139 00140 bool serve_js_from_gstatic_; 00141 GoogleString blink_javascript_gstatic_url_; 00142 GoogleString blink_javascript_handler_url_; 00143 GoogleString defer_javascript_url_; 00144 GoogleString defer_javascript_debug_url_; 00145 GoogleString library_url_prefix_; 00146 GoogleString cache_header_with_long_ttl_; 00147 GoogleString cache_header_with_private_ttl_; 00148 FileNameToStringsMap file_name_to_js_map_; 00149 00150 DISALLOW_COPY_AND_ASSIGN(StaticJavascriptManager); 00151 }; 00152 00153 } 00154 00155 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_STATIC_JAVASCRIPT_MANAGER_H_