Page Speed Optimization Libraries  1.7.30.4
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 };
00052     virtual TransformStatus Transform(GoogleString* str) = 0;
00053   };
00054 
00055   static const char kStylesheet[];
00056   static const char kAlternate[];
00057   static const char kUriValue[];
00058 
00059   explicit CssTagScanner(HtmlParse* html_parse);
00060 
00065   bool ParseCssElement(HtmlElement* element,
00066                        HtmlElement::Attribute** href,
00067                        const char** media,
00068                        int* num_nonstandard_attributes);
00069 
00072   bool ParseCssElement(HtmlElement* element,
00073                        HtmlElement::Attribute** href,
00074                        const char** media) {
00075     int num_nonstandard_attributes;
00076     return ParseCssElement(element, href, media, &num_nonstandard_attributes);
00077   }
00078 
00083   static bool TransformUrls(
00084       const StringPiece& contents, Writer* writer, Transformer* transformer,
00085       MessageHandler* handler);
00086 
00089   static bool HasImport(const StringPiece& contents, MessageHandler* handler);
00090 
00092   static bool HasUrl(const StringPiece& contents);
00093 
00096   static bool IsStylesheetOrAlternate(const StringPiece& attribute_value);
00097 
00099   static bool IsAlternateStylesheet(const StringPiece& attribute_value);
00100 
00101  private:
00102   DISALLOW_COPY_AND_ASSIGN(CssTagScanner);
00103 };
00104 
00109 class RewriteDomainTransformer : public CssTagScanner::Transformer {
00110  public:
00111   RewriteDomainTransformer(const GoogleUrl* old_base_url,
00112                            const GoogleUrl* new_base_url,
00113                            RewriteDriver* driver);
00114   virtual ~RewriteDomainTransformer();
00115 
00116   virtual TransformStatus Transform(GoogleString* str);
00117 
00118   void set_trim_urls(bool x) { trim_urls_ = x; }
00119 
00120  private:
00121   const GoogleUrl* old_base_url_;
00122   const GoogleUrl* new_base_url_;
00123 
00124   DomainRewriteFilter* domain_rewriter_;
00125   UrlLeftTrimFilter* url_trim_filter_;
00126   MessageHandler* handler_;
00127   bool trim_urls_;
00128   RewriteDriver* driver_;
00129 
00130   DISALLOW_COPY_AND_ASSIGN(RewriteDomainTransformer);
00131 };
00132 
00133 
00134 }  
00135 
00136 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_TAG_SCANNER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines