Page Speed Optimization Libraries  1.13.35.1
 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 
40 
41 namespace pagespeed { namespace js { struct JsTokenizerPatterns; } }
42 
43 namespace net_instaweb {
44 
45 class Statistics;
46 
67  public:
68  static const char kJsFileCountReduction[];
69 
72  explicit JsCombineFilter(RewriteDriver* rewrite_driver);
73  virtual ~JsCombineFilter();
74 
76  static void InitStats(Statistics* statistics);
77  virtual const char* id() const {
78  return RewriteOptions::kJavascriptCombinerId;
79  }
80 
85  StringPiece input);
86 
87  ScriptUsage GetScriptUsage() const override { return kWillInjectScripts; }
88 
89  protected:
91  virtual void StartDocumentImpl();
92  virtual void StartElementImpl(HtmlElement* element);
93  virtual void EndElementImpl(HtmlElement* element);
94  virtual void Characters(HtmlCharactersNode* characters);
95  virtual void Flush();
96  virtual void IEDirective(HtmlIEDirectiveNode* directive);
97  virtual const char* Name() const { return "JsCombine"; }
99  virtual const UrlSegmentEncoder* encoder() const {
100  return &encoder_;
101  }
102 
103  private:
104  class JsCombiner;
105  class Context;
106 
107  friend class JsCombineFilterTest;
108 
109  void ConsiderJsForCombination(HtmlElement* element,
111 
113  static GoogleString VarName(const RewriteDriver* rewrite_driver,
114  const GoogleString& url);
115 
116  void NextCombination();
117 
118  Context* MakeContext();
119 
120  JsCombiner* combiner() const;
121 
122  ScriptTagScanner script_scanner_;
123  int script_depth_;
124  HtmlElement* current_js_script_;
126  scoped_ptr<Context> context_;
127  UrlMultipartEncoder encoder_;
128 
129 
130 };
131 
132 }
133 
134 #endif
Definition: html_element.h:66
Definition: url_multipart_encoder.h:45
Leaf node representing raw characters in HTML.
Definition: html_node.h:167
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Definition: js_combine_filter.h:66
Definition: html_element.h:42
virtual void StartDocumentImpl()
RewriteFilter overrides — HTML parsing event handlers.
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
virtual RewriteContext * MakeRewriteContext()
virtual void Characters(HtmlCharactersNode *characters)
static void InitStats(Statistics *statistics)
Registers the provided statistics variable names with 'statistics'.
Definition: js_tokenizer.h:194
virtual const UrlSegmentEncoder * encoder() const
Definition: js_combine_filter.h:99
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
virtual void IEDirective(HtmlIEDirectiveNode *directive)
Definition: rewrite_filter.h:35
Definition: rewrite_driver.h:100
JsCombineFilter(RewriteDriver *rewrite_driver)
Definition: script_tag_scanner.h:30
Definition: rewrite_context.h:155
Definition: url_segment_encoder.h:33
static const char kJsFileCountReduction[]
statistics variable name
Definition: js_combine_filter.h:68
ScriptUsage GetScriptUsage() const override
Definition: js_combine_filter.h:87
Leaf node representing an HTML IE directive.
Definition: html_node.h:213
static bool IsLikelyStrictMode(const pagespeed::js::JsTokenizerPatterns *jstp, StringPiece input)
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: js_combine_filter.h:97