Page Speed Optimization Libraries
1.7.30.1
|
00001 /* 00002 * Copyright 2011 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 00022 00023 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_JS_COMBINE_FILTER_H_ 00024 #define NET_INSTAWEB_REWRITER_PUBLIC_JS_COMBINE_FILTER_H_ 00025 00026 #include "net/instaweb/htmlparse/public/html_element.h" 00027 #include "net/instaweb/rewriter/public/rewrite_filter.h" 00028 #include "net/instaweb/rewriter/public/rewrite_options.h" 00029 #include "net/instaweb/rewriter/public/script_tag_scanner.h" 00030 #include "net/instaweb/util/public/basictypes.h" 00031 #include "net/instaweb/util/public/scoped_ptr.h" 00032 #include "net/instaweb/util/public/string.h" 00033 #include "net/instaweb/util/public/url_multipart_encoder.h" 00034 00035 namespace net_instaweb { 00036 00037 class HtmlCharactersNode; 00038 class HtmlIEDirectiveNode; 00039 class RewriteDriver; 00040 class RewriteContext; 00041 class ServerContext; 00042 class Statistics; 00043 class UrlSegmentEncoder; 00044 00064 class JsCombineFilter : public RewriteFilter { 00065 public: 00066 static const char kJsFileCountReduction[]; 00067 00070 explicit JsCombineFilter(RewriteDriver* rewrite_driver); 00071 virtual ~JsCombineFilter(); 00072 00074 static void InitStats(Statistics* statistics); 00075 virtual const char* id() const { 00076 return RewriteOptions::kJavascriptCombinerId; 00077 } 00078 00079 protected: 00081 virtual void StartDocumentImpl(); 00082 virtual void StartElementImpl(HtmlElement* element); 00083 virtual void EndElementImpl(HtmlElement* element); 00084 virtual void Characters(HtmlCharactersNode* characters); 00085 virtual void Flush(); 00086 virtual void DetermineEnabled(); 00087 virtual void IEDirective(HtmlIEDirectiveNode* directive); 00088 virtual const char* Name() const { return "JsCombine"; } 00089 virtual RewriteContext* MakeRewriteContext(); 00090 virtual const UrlSegmentEncoder* encoder() const { 00091 return &encoder_; 00092 } 00093 00094 private: 00095 class JsCombiner; 00096 class Context; 00097 00098 friend class JsCombineFilterTest; 00099 00100 void ConsiderJsForCombination(HtmlElement* element, 00101 HtmlElement::Attribute* src); 00102 00104 static GoogleString VarName(const ServerContext* server_context, 00105 const GoogleString& url); 00106 00107 void NextCombination(); 00108 00109 Context* MakeContext(); 00110 00111 JsCombiner* combiner() const; 00112 ServerContext* server_context() const { return server_context_; } 00113 00114 ScriptTagScanner script_scanner_; 00115 int script_depth_; 00116 00117 HtmlElement* current_js_script_; 00118 scoped_ptr<Context> context_; 00119 UrlMultipartEncoder encoder_; 00120 00121 DISALLOW_COPY_AND_ASSIGN(JsCombineFilter); 00122 }; 00123 00124 } 00125 00126 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_JS_COMBINE_FILTER_H_