Page Speed Optimization Libraries
1.7.30.1
|
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 00094 static bool IsAlternateStylesheet(const StringPiece& attribute_value); 00095 00096 private: 00097 DISALLOW_COPY_AND_ASSIGN(CssTagScanner); 00098 }; 00099 00104 class RewriteDomainTransformer : public CssTagScanner::Transformer { 00105 public: 00106 RewriteDomainTransformer(const GoogleUrl* old_base_url, 00107 const GoogleUrl* new_base_url, 00108 RewriteDriver* driver); 00109 virtual ~RewriteDomainTransformer(); 00110 00111 virtual TransformStatus Transform(const StringPiece& in, GoogleString* out); 00112 00113 void set_trim_urls(bool x) { trim_urls_ = x; } 00114 00115 private: 00116 const GoogleUrl* old_base_url_; 00117 const GoogleUrl* new_base_url_; 00118 00119 DomainRewriteFilter* domain_rewriter_; 00120 UrlLeftTrimFilter* url_trim_filter_; 00121 MessageHandler* handler_; 00122 bool trim_urls_; 00123 RewriteDriver* driver_; 00124 00125 DISALLOW_COPY_AND_ASSIGN(RewriteDomainTransformer); 00126 }; 00127 00128 00129 } 00130 00131 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_TAG_SCANNER_H_