Page Speed Optimization Libraries  1.3.25.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 
00058   bool ParseCssElement(
00059       HtmlElement* element, HtmlElement::Attribute** href, const char** media);
00060 
00065   static bool TransformUrls(
00066       const StringPiece& contents, Writer* writer, Transformer* transformer,
00067       MessageHandler* handler);
00068 
00071   static bool HasImport(const StringPiece& contents, MessageHandler* handler);
00072 
00074   static bool HasUrl(const StringPiece& contents);
00075 
00078   static bool IsStylesheetOrAlternate(const StringPiece& attribute_value);
00079 
00080  private:
00081   DISALLOW_COPY_AND_ASSIGN(CssTagScanner);
00082 };
00083 
00088 class RewriteDomainTransformer : public CssTagScanner::Transformer {
00089  public:
00090   RewriteDomainTransformer(const GoogleUrl* old_base_url,
00091                            const GoogleUrl* new_base_url,
00092                            RewriteDriver* driver);
00093   virtual ~RewriteDomainTransformer();
00094 
00095   virtual TransformStatus Transform(const StringPiece& in, GoogleString* out);
00096 
00097   void set_trim_urls(bool x) { trim_urls_ = x; }
00098 
00099  private:
00100   const GoogleUrl* old_base_url_;
00101   const GoogleUrl* new_base_url_;
00102 
00103   DomainRewriteFilter* domain_rewriter_;
00104   UrlLeftTrimFilter* url_trim_filter_;
00105   MessageHandler* handler_;
00106   bool trim_urls_;
00107 
00108   DISALLOW_COPY_AND_ASSIGN(RewriteDomainTransformer);
00109 };
00110 
00111 
00112 }  
00113 
00114 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_TAG_SCANNER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines