Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
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
Definition: statistics.h:43
Leaf node representing raw characters in HTML.
Definition: html_node.h:167
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
Definition: html_element.h:42
virtual void Characters(HtmlCharactersNode *characters)
virtual const char * Name() const
The name of this filter – used for logging and debugging.
Definition: js_inline_filter.h:53
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
ScriptUsage
Describes a filter's relationship with scripts.
Definition: html_filter.h:38
Definition: rewrite_driver.h:100
ScriptUsage GetScriptUsage() const override
Definition: js_inline_filter.h:65
Inline small Javascript files.
Definition: js_inline_filter.h:42
Definition: script_tag_scanner.h:30
virtual void StartDocumentImpl()
virtual bool IntendedForInlining() const
Definition: js_inline_filter.h:64
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:137
const RewriteOptions * options() const
Return the options used for this RewriteDriver.
Definition: rewrite_driver.h:496
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: js_inline_filter.h:57