Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
js_inline_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 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 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_JS_INLINE_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_JS_INLINE_FILTER_H_
21 
22 #include <cstddef>
23 
29 #include "pagespeed/kernel/base/basictypes.h"
30 #include "pagespeed/kernel/base/string.h"
31 #include "pagespeed/kernel/base/string_util.h"
32 #include "pagespeed/kernel/html/html_element.h"
33 #include "pagespeed/kernel/html/html_filter.h"
34 #include "pagespeed/kernel/html/html_node.h"
35 #include "pagespeed/kernel/http/semantic_type.h"
36 
37 namespace net_instaweb {
38 class Statistics;
39 class Variable;
40 
42 class JsInlineFilter : public CommonFilter {
43  public:
44  static const char kNumJsInlined[];
45  explicit JsInlineFilter(RewriteDriver* driver);
46  virtual ~JsInlineFilter();
47 
48  virtual void StartDocumentImpl();
49  virtual void EndDocument();
50  virtual void StartElementImpl(HtmlElement* element);
51  virtual void EndElementImpl(HtmlElement* element);
52  virtual void Characters(HtmlCharactersNode* characters);
53  virtual const char* Name() const { return "InlineJs"; }
58  const {
59  return driver()->options()->HasInlineUnauthorizedResourceType(
60  semantic_type::kScript) ?
61  RewriteDriver::kInlineUnauthorizedResources :
62  RewriteDriver::kInlineOnlyAuthorizedResources;
63  }
64  virtual bool IntendedForInlining() const { return true; }
65  ScriptUsage GetScriptUsage() const override { return kWillInjectScripts; }
66 
67  static void InitStats(Statistics* statistics);
68 
69  private:
70  class Context;
71  friend class Context;
72 
73  bool ShouldInline(const ResourcePtr& resource, GoogleString* reason) const;
74  void RenderInline(const ResourcePtr& resource, const StringPiece& text,
75  HtmlElement* element);
76 
77  const size_t size_threshold_bytes_;
78  ScriptTagScanner script_tag_scanner_;
79 
85  bool should_inline_;
86 
87  Variable* num_js_inlined_;
88 
89 
90 };
91 
92 }
93 
94 #endif
Definition: common_filter.h:47
virtual void Characters(HtmlCharactersNode *characters)
Definition: rewrite_driver.h:98
Inline small Javascript files.
Definition: js_inline_filter.h:42
virtual void StartDocumentImpl()
virtual bool IntendedForInlining() const
Definition: js_inline_filter.h:64
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:135
const RewriteOptions * options() const
Return the options used for this RewriteDriver.
Definition: rewrite_driver.h:490
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: js_inline_filter.h:57