Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
css_tag_scanner.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_TAG_SCANNER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_TAG_SCANNER_H_
21 
22 #include "net/instaweb/htmlparse/public/html_element.h"
26 
27 namespace net_instaweb {
28 
29 class DomainRewriteFilter;
30 class GoogleUrl;
31 class HtmlParse;
32 class MessageHandler;
33 class RewriteDriver;
34 class UrlLeftTrimFilter;
35 class Writer;
36 
38  public:
41  class Transformer {
42  public:
43  virtual ~Transformer();
44 
45  enum TransformStatus { kSuccess, kNoChange, kFailure };
52  virtual TransformStatus Transform(GoogleString* str) = 0;
53  };
54 
55  static const char kStylesheet[];
56  static const char kAlternate[];
57  static const char kUriValue[];
58 
59  explicit CssTagScanner(HtmlParse* html_parse);
60 
66  bool ParseCssElement(HtmlElement* element,
67  HtmlElement::Attribute** href,
68  const char** media,
69  StringPieceVector* nonstandard_attributes);
70 
73  bool ParseCssElement(HtmlElement* element,
74  HtmlElement::Attribute** href,
75  const char** media) {
76  return ParseCssElement(element, href, media,
77  NULL );
78  }
79 
84  static bool TransformUrls(
85  const StringPiece& contents, Writer* writer, Transformer* transformer,
86  MessageHandler* handler);
87 
90  static bool HasImport(const StringPiece& contents, MessageHandler* handler);
91 
93  static bool HasUrl(const StringPiece& contents);
94 
97  static bool IsStylesheetOrAlternate(const StringPiece& attribute_value);
98 
100  static bool IsAlternateStylesheet(const StringPiece& attribute_value);
101 
102  private:
103  DISALLOW_COPY_AND_ASSIGN(CssTagScanner);
104 };
105 
111  public:
112  RewriteDomainTransformer(const GoogleUrl* old_base_url,
113  const GoogleUrl* new_base_url,
114  RewriteDriver* driver);
115  virtual ~RewriteDomainTransformer();
116 
117  virtual TransformStatus Transform(GoogleString* str);
118 
119  void set_trim_urls(bool x) { trim_urls_ = x; }
120 
121  private:
122  const GoogleUrl* old_base_url_;
123  const GoogleUrl* new_base_url_;
124 
125  DomainRewriteFilter* domain_rewriter_;
126  UrlLeftTrimFilter* url_trim_filter_;
127  MessageHandler* handler_;
128  bool trim_urls_;
129  RewriteDriver* driver_;
130 
131  DISALLOW_COPY_AND_ASSIGN(RewriteDomainTransformer);
132 };
133 
134 
135 }
136 
137 #endif
Definition: css_tag_scanner.h:41
static bool HasUrl(const StringPiece &contents)
Detemines whether this CSS contains a URI value (aka URL).
static bool IsAlternateStylesheet(const StringPiece &attribute_value)
Does this rel attribute value represent an alternate stylesheet?
Definition: css_tag_scanner.h:110
static bool IsStylesheetOrAlternate(const StringPiece &attribute_value)
bool ParseCssElement(HtmlElement *element, HtmlElement::Attribute **href, const char **media, StringPieceVector *nonstandard_attributes)
Definition: url_left_trim_filter.h:47
bool ParseCssElement(HtmlElement *element, HtmlElement::Attribute **href, const char **media)
Definition: css_tag_scanner.h:73
virtual TransformStatus Transform(GoogleString *str)
static bool HasImport(const StringPiece &contents, MessageHandler *handler)
Definition: rewrite_driver.h:98
Definition: css_tag_scanner.h:37
Definition: domain_rewrite_filter.h:40
static bool TransformUrls(const StringPiece &contents, Writer *writer, Transformer *transformer, MessageHandler *handler)
virtual TransformStatus Transform(GoogleString *str)=0