Page Speed Optimization Libraries  1.2.24.1
net/instaweb/rewriter/public/js_combine_filter.h
Go to the documentation of this file.
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 IEDirective(HtmlIEDirectiveNode* directive);
00087   virtual const char* Name() const { return "JsCombine"; }
00088   virtual RewriteContext* MakeRewriteContext();
00089   virtual const UrlSegmentEncoder* encoder() const {
00090     return &encoder_;
00091   }
00092 
00093  private:
00094   class JsCombiner;
00095   class Context;
00096 
00097   friend class JsCombineFilterTest;
00098 
00099   void ConsiderJsForCombination(HtmlElement* element,
00100                                 HtmlElement::Attribute* src);
00101 
00103   static GoogleString VarName(const ServerContext* server_context,
00104                               const GoogleString& url);
00105 
00106   void NextCombination();
00107 
00108   Context* MakeContext();
00109 
00110   JsCombiner* combiner() const;
00111   ServerContext* server_context() const { return server_context_; }
00112 
00113   ScriptTagScanner script_scanner_;
00114   int script_depth_; 
00115 
00116   HtmlElement* current_js_script_; 
00117   scoped_ptr<Context> context_;
00118   UrlMultipartEncoder encoder_;
00119 
00120   DISALLOW_COPY_AND_ASSIGN(JsCombineFilter);
00121 };
00122 
00123 }  
00124 
00125 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_JS_COMBINE_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines