Page Speed Optimization Libraries  1.9.32.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 
26 #include "net/instaweb/htmlparse/public/html_element.h"
33 #include "net/instaweb/util/public/url_multipart_encoder.h"
34 #include "pagespeed/kernel/base/string_util.h"
35 
36 namespace pagespeed { namespace js { struct JsTokenizerPatterns; } }
37 
38 namespace net_instaweb {
39 
40 class HtmlCharactersNode;
41 class HtmlIEDirectiveNode;
42 class RewriteDriver;
43 class RewriteContext;
44 class ServerContext;
45 class Statistics;
46 class UrlSegmentEncoder;
47 
68  public:
69  static const char kJsFileCountReduction[];
70 
73  explicit JsCombineFilter(RewriteDriver* rewrite_driver);
74  virtual ~JsCombineFilter();
75 
77  static void InitStats(Statistics* statistics);
78  virtual const char* id() const {
79  return RewriteOptions::kJavascriptCombinerId;
80  }
81 
85  static bool IsLikelyStrictMode(const pagespeed::js::JsTokenizerPatterns* jstp,
86  StringPiece input);
87 
88  protected:
90  virtual void StartDocumentImpl();
91  virtual void StartElementImpl(HtmlElement* element);
92  virtual void EndElementImpl(HtmlElement* element);
93  virtual void Characters(HtmlCharactersNode* characters);
94  virtual void Flush();
95  virtual void DetermineEnabled(GoogleString* disabled_reason);
96  virtual void IEDirective(HtmlIEDirectiveNode* directive);
97  virtual const char* Name() const { return "JsCombine"; }
98  virtual RewriteContext* MakeRewriteContext();
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,
110  HtmlElement::Attribute* src);
111 
113  static GoogleString VarName(const ServerContext* server_context,
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  DISALLOW_COPY_AND_ASSIGN(JsCombineFilter);
130 };
131 
132 }
133 
134 #endif
Definition: js_combine_filter.h:67
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:99
Definition: rewrite_filter.h:37
Definition: rewrite_driver.h:98
JsCombineFilter(RewriteDriver *rewrite_driver)
Definition: server_context.h:100
Definition: script_tag_scanner.h:30
static const char kJsFileCountReduction[]
statistics variable name
Definition: js_combine_filter.h:69
static bool IsLikelyStrictMode(const pagespeed::js::JsTokenizerPatterns *jstp, StringPiece input)