Page Speed Optimization Libraries  1.9.32.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
css_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_CSS_INLINE_FILTER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_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/http/semantic_type.h"
33 
34 namespace net_instaweb {
35 
36 class CachedResult;
37 class GoogleUrl;
38 class HtmlElement;
39 class Statistics;
40 class Variable;
41 
43 class CssInlineFilter : public CommonFilter {
44  public:
45  static const char kNumCssInlined[];
46 
47  explicit CssInlineFilter(RewriteDriver* driver);
48  virtual ~CssInlineFilter();
49 
50  virtual void StartDocumentImpl();
51  virtual void StartElementImpl(HtmlElement* element) {}
52  virtual void EndElementImpl(HtmlElement* element);
53  virtual const char* Name() const { return "InlineCss"; }
58  const {
59  return driver()->options()->HasInlineUnauthorizedResourceType(
60  semantic_type::kStylesheet) ?
61  RewriteDriver::kInlineUnauthorizedResources :
62  RewriteDriver::kInlineOnlyAuthorizedResources;
63  }
64  virtual bool IntendedForInlining() const { return true; }
65 
66  static void InitStats(Statistics* statistics);
67  static bool HasClosingStyleTag(StringPiece contents);
68 
69  protected:
72  void set_id(const char* id) { id_ = id; }
73 
76  virtual ResourcePtr CreateResource(const char* url, bool* is_authorized);
77 
78  private:
79  class Context;
80  friend class Context;
81 
82  bool ShouldInline(const ResourcePtr& resource,
83  const StringPiece& attrs_attribute,
84  GoogleString* reason) const;
85  void RenderInline(const ResourcePtr& resource, const CachedResult& cached,
86  const GoogleUrl& base_url, const StringPiece& text,
87  HtmlElement* element);
88 
89  const char* id_;
90  const size_t size_threshold_bytes_;
91 
92  GoogleString domain_;
93  CssTagScanner css_tag_scanner_;
94 
95  Variable* num_css_inlined_;
96 
97  DISALLOW_COPY_AND_ASSIGN(CssInlineFilter);
98 };
99 
100 }
101 
102 #endif
Definition: common_filter.h:48
virtual bool IntendedForInlining() const
Definition: css_inline_filter.h:64
virtual void StartDocumentImpl()
void set_id(const char *id)
Definition: css_inline_filter.h:72
Definition: rewrite_driver.h:98
Definition: css_tag_scanner.h:37
InlineAuthorizationPolicy
See CreateInputResource.
Definition: rewrite_driver.h:135
Inline small CSS files.
Definition: css_inline_filter.h:43
virtual RewriteDriver::InlineAuthorizationPolicy AllowUnauthorizedDomain() const
Definition: css_inline_filter.h:57
virtual ResourcePtr CreateResource(const char *url, bool *is_authorized)
const GoogleUrl & base_url() const
Getters.
const RewriteOptions * options() const
Return the options used for this RewriteDriver.
Definition: rewrite_driver.h:478