Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
js_combine_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
22 
23 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_JS_COMBINE_FILTER_H_
24 #define NET_INSTAWEB_REWRITER_PUBLIC_JS_COMBINE_FILTER_H_
25 
31 #include "pagespeed/kernel/base/basictypes.h"
32 #include "pagespeed/kernel/base/scoped_ptr.h"
33 #include "pagespeed/kernel/base/string.h"
34 #include "pagespeed/kernel/base/string_util.h"
35 #include "pagespeed/kernel/html/html_element.h"
36 #include "pagespeed/kernel/html/html_node.h"
37 #include "pagespeed/kernel/util/url_multipart_encoder.h"
38 #include "pagespeed/kernel/util/url_segment_encoder.h"
39 
40 namespace pagespeed { namespace js { struct JsTokenizerPatterns; } }
41 
42 namespace net_instaweb {
43 
44 class Statistics;
45 
66  public:
67  static const char kJsFileCountReduction[];
68 
71  explicit JsCombineFilter(RewriteDriver* rewrite_driver);
72  virtual ~JsCombineFilter();
73 
75  static void InitStats(Statistics* statistics);
76  virtual const char* id() const {
77  return RewriteOptions::kJavascriptCombinerId;
78  }
79 
83  static bool IsLikelyStrictMode(const pagespeed::js::JsTokenizerPatterns* jstp,
84  StringPiece input);
85 
86  protected:
88  virtual void StartDocumentImpl();
89  virtual void StartElementImpl(HtmlElement* element);
90  virtual void EndElementImpl(HtmlElement* element);
91  virtual void Characters(HtmlCharactersNode* characters);
92  virtual void Flush();
93  virtual void DetermineEnabled(GoogleString* disabled_reason);
94  virtual void IEDirective(HtmlIEDirectiveNode* directive);
95  virtual const char* Name() const { return "JsCombine"; }
96  virtual RewriteContext* MakeRewriteContext();
97  virtual const UrlSegmentEncoder* encoder() const {
98  return &encoder_;
99  }
100 
101  private:
102  class JsCombiner;
103  class Context;
104 
105  friend class JsCombineFilterTest;
106 
107  void ConsiderJsForCombination(HtmlElement* element,
108  HtmlElement::Attribute* src);
109 
111  static GoogleString VarName(const RewriteDriver* rewrite_driver,
112  const GoogleString& url);
113 
114  void NextCombination();
115 
116  Context* MakeContext();
117 
118  JsCombiner* combiner() const;
119 
120  ScriptTagScanner script_scanner_;
121  int script_depth_;
122  HtmlElement* current_js_script_;
124  scoped_ptr<Context> context_;
125  UrlMultipartEncoder encoder_;
126 
127  DISALLOW_COPY_AND_ASSIGN(JsCombineFilter);
128 };
129 
130 }
131 
132 #endif
Definition: js_combine_filter.h:65
virtual void StartDocumentImpl()
RewriteFilter overrides — HTML parsing event handlers.
virtual RewriteContext * MakeRewriteContext()
virtual void DetermineEnabled(GoogleString *disabled_reason)
virtual void Characters(HtmlCharactersNode *characters)
static void InitStats(Statistics *statistics)
Registers the provided statistics variable names with 'statistics'.
virtual const UrlSegmentEncoder * encoder() const
Definition: js_combine_filter.h:97
Definition: rewrite_filter.h:37
Definition: rewrite_driver.h:98
JsCombineFilter(RewriteDriver *rewrite_driver)
Definition: script_tag_scanner.h:30
static const char kJsFileCountReduction[]
statistics variable name
Definition: js_combine_filter.h:67
static bool IsLikelyStrictMode(const pagespeed::js::JsTokenizerPatterns *jstp, StringPiece input)