~alinuxninja/nginx-edge/trunk

« back to all changes in this revision

Viewing changes to debian/modules/ngx_pagespeed/psol/include/net/instaweb/rewriter/public/js_inline_filter.h

  • Committer: Vivian
  • Date: 2015-12-04 18:20:11 UTC
  • Revision ID: git-v1:a36f2bc32e884f7473b3a47040e5411306144d7d
* Do not extract psol.tar.gz

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
 
 
17
 
// Author: mdsteele@google.com (Matthew D. Steele)
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
 
 
24
 
#include "net/instaweb/http/public/semantic_type.h"
25
 
#include "net/instaweb/rewriter/public/common_filter.h"
26
 
#include "net/instaweb/rewriter/public/resource.h"
27
 
#include "net/instaweb/rewriter/public/rewrite_driver.h"
28
 
#include "net/instaweb/rewriter/public/rewrite_options.h"
29
 
#include "net/instaweb/rewriter/public/script_tag_scanner.h"
30
 
#include "net/instaweb/util/public/basictypes.h"
31
 
#include "net/instaweb/util/public/string_util.h"
32
 
#include "pagespeed/kernel/base/string.h"
33
 
 
34
 
namespace net_instaweb {
35
 
class HtmlElement;
36
 
class HtmlCharactersNode;
37
 
class Statistics;
38
 
class Variable;
39
 
 
40
 
// Inline small Javascript files.
41
 
class JsInlineFilter : public CommonFilter {
42
 
 public:
43
 
  static const char kNumJsInlined[];
44
 
  explicit JsInlineFilter(RewriteDriver* driver);
45
 
  virtual ~JsInlineFilter();
46
 
 
47
 
  virtual void StartDocumentImpl();
48
 
  virtual void EndDocument();
49
 
  virtual void StartElementImpl(HtmlElement* element);
50
 
  virtual void EndElementImpl(HtmlElement* element);
51
 
  virtual void Characters(HtmlCharactersNode* characters);
52
 
  virtual const char* Name() const { return "InlineJs"; }
53
 
  // Inlining javascript from unauthorized domains into HTML is considered
54
 
  // safe because it does not cause any new content to be executed compared
55
 
  // to the unoptimized page.
56
 
  virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain()
57
 
      const {
58
 
    return driver()->options()->HasInlineUnauthorizedResourceType(
59
 
               semantic_type::kScript) ?
60
 
           RewriteDriver::kInlineUnauthorizedResources :
61
 
           RewriteDriver::kInlineOnlyAuthorizedResources;
62
 
  }
63
 
  virtual bool IntendedForInlining() const { return true; }
64
 
 
65
 
  static void InitStats(Statistics* statistics);
66
 
 
67
 
 private:
68
 
  class Context;
69
 
  friend class Context;
70
 
 
71
 
  bool ShouldInline(const ResourcePtr& resource, GoogleString* reason) const;
72
 
  void RenderInline(const ResourcePtr& resource, const StringPiece& text,
73
 
                    HtmlElement* element);
74
 
 
75
 
  const size_t size_threshold_bytes_;
76
 
  ScriptTagScanner script_tag_scanner_;
77
 
 
78
 
  // This is set to true during StartElement() for a <script> tag that we
79
 
  // should maybe inline, but may be set back to false by Characters().  If it
80
 
  // is still true when we hit the corresponding EndElement(), then we'll
81
 
  // inline the script (and set it back to false).  It should never be true
82
 
  // outside of <script> and </script>.
83
 
  bool should_inline_;
84
 
 
85
 
  Variable* num_js_inlined_;
86
 
 
87
 
  DISALLOW_COPY_AND_ASSIGN(JsInlineFilter);
88
 
};
89
 
 
90
 
}  // namespace net_instaweb
91
 
 
92
 
#endif  // NET_INSTAWEB_REWRITER_PUBLIC_JS_INLINE_FILTER_H_