Page Speed Optimization Libraries  1.4.26.1
net/instaweb/rewriter/public/css_tag_scanner.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_CSS_TAG_SCANNER_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_TAG_SCANNER_H_
00021 
00022 #include "net/instaweb/htmlparse/public/html_element.h"
00023 #include "net/instaweb/util/public/basictypes.h"
00024 #include "net/instaweb/util/public/string.h"
00025 #include "net/instaweb/util/public/string_util.h"
00026 
00027 namespace net_instaweb {
00028 
00029 class DomainRewriteFilter;
00030 class GoogleUrl;
00031 class HtmlParse;
00032 class MessageHandler;
00033 class RewriteDriver;
00034 class UrlLeftTrimFilter;
00035 class Writer;
00036 
00037 class CssTagScanner {
00038  public:
00041   class Transformer {
00042    public:
00043     virtual ~Transformer();
00044 
00045     enum TransformStatus { kSuccess, kNoChange, kFailure };
00046     virtual TransformStatus Transform(const StringPiece& in,
00047                                       GoogleString* out) = 0;
00048   };
00049 
00050   static const char kStylesheet[];
00051   static const char kAlternate[];
00052   static const char kUriValue[];
00053 
00054   explicit CssTagScanner(HtmlParse* html_parse);
00055 
00060   bool ParseCssElement(HtmlElement* element,
00061                        HtmlElement::Attribute** href,
00062                        const char** media,
00063                        int* num_nonstandard_attributes);
00064 
00067   bool ParseCssElement(HtmlElement* element,
00068                        HtmlElement::Attribute** href,
00069                        const char** media) {
00070     int num_nonstandard_attributes;
00071     return ParseCssElement(element, href, media, &num_nonstandard_attributes);
00072   }
00073 
00078   static bool TransformUrls(
00079       const StringPiece& contents, Writer* writer, Transformer* transformer,
00080       MessageHandler* handler);
00081 
00084   static bool HasImport(const StringPiece& contents, MessageHandler* handler);
00085 
00087   static bool HasUrl(const StringPiece& contents);
00088 
00091   static bool IsStylesheetOrAlternate(const StringPiece& attribute_value);
00092 
00093  private:
00094   DISALLOW_COPY_AND_ASSIGN(CssTagScanner);
00095 };
00096 
00101 class RewriteDomainTransformer : public CssTagScanner::Transformer {
00102  public:
00103   RewriteDomainTransformer(const GoogleUrl* old_base_url,
00104                            const GoogleUrl* new_base_url,
00105                            RewriteDriver* driver);
00106   virtual ~RewriteDomainTransformer();
00107 
00108   virtual TransformStatus Transform(const StringPiece& in, GoogleString* out);
00109 
00110   void set_trim_urls(bool x) { trim_urls_ = x; }
00111 
00112  private:
00113   const GoogleUrl* old_base_url_;
00114   const GoogleUrl* new_base_url_;
00115 
00116   DomainRewriteFilter* domain_rewriter_;
00117   UrlLeftTrimFilter* url_trim_filter_;
00118   MessageHandler* handler_;
00119   bool trim_urls_;
00120 
00121   DISALLOW_COPY_AND_ASSIGN(RewriteDomainTransformer);
00122 };
00123 
00124 
00125 }  
00126 
00127 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_TAG_SCANNER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines