Page Speed Optimization Libraries
1.4.26.1
|
00001 /* 00002 * Copyright 2011 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_HIERARCHY_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_CSS_HIERARCHY_H_ 00021 00022 #include <vector> 00023 00024 #include "net/instaweb/rewriter/public/resource.h" 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/google_url.h" 00027 #include "net/instaweb/util/public/scoped_ptr.h" 00028 #include "net/instaweb/util/public/string.h" 00029 #include "net/instaweb/util/public/string_util.h" 00030 00031 namespace Css { 00032 class Stylesheet; 00033 } 00034 00035 namespace net_instaweb { 00036 00037 class CssFilter; 00038 class MessageHandler; 00039 00063 class CssHierarchy { 00064 public: 00067 explicit CssHierarchy(CssFilter* filter); 00068 ~CssHierarchy(); 00069 00073 void InitializeRoot(const GoogleUrl& css_base_url, 00074 const GoogleUrl& css_trim_url, 00075 const StringPiece input_contents, 00076 bool has_unparseables, 00077 int64 flattened_result_limit, 00078 Css::Stylesheet* stylesheet, 00079 MessageHandler* message_handler); 00080 00082 bool NeedsRewriting() const { 00083 return flattening_succeeded_ && !url_.empty(); 00084 } 00085 00086 const StringPiece url() const { return url_; } 00087 00088 const GoogleUrl& css_base_url() const { return css_base_url_; } 00089 const GoogleUrl& css_trim_url() const { return css_trim_url_; } 00090 00091 const Css::Stylesheet* stylesheet() const { return stylesheet_.get(); } 00092 Css::Stylesheet* mutable_stylesheet() { return stylesheet_.get(); } 00093 void set_stylesheet(Css::Stylesheet* stylesheet); 00094 00095 const StringPiece input_contents() const { return input_contents_; } 00098 void set_input_contents(const StringPiece input_contents) { 00099 input_contents_ = input_contents; 00100 } 00101 00102 const GoogleString& minified_contents() const { return minified_contents_; } 00103 void set_minified_contents(const StringPiece minified_contents); 00104 00105 const GoogleString& charset() const { return charset_; } 00106 GoogleString* mutable_charset() { return &charset_; } 00107 00108 const StringVector& media() const { return media_; } 00109 StringVector* mutable_media() { return &media_; } 00110 00112 const std::vector<CssHierarchy*>& children() const { return children_; } 00113 std::vector<CssHierarchy*>& children() { return children_; } 00114 00115 bool flattening_succeeded() const { return flattening_succeeded_; } 00116 void set_flattening_succeeded(bool ok) { flattening_succeeded_ = ok; } 00117 00118 bool unparseable_detected() const { return unparseable_detected_; } 00119 void set_unparseable_detected(bool ok) { unparseable_detected_ = ok; } 00120 00121 int64 flattened_result_limit() const { return flattened_result_limit_; } 00122 void set_flattened_result_limit(int64 x) { flattened_result_limit_ = x; } 00123 00135 bool CheckCharsetOk(const ResourcePtr& resource); 00136 00142 bool Parse(); 00143 00156 bool ExpandChildren(); 00157 00171 void RollUpContents(); 00172 00187 bool RollUpStylesheets(); 00188 00189 private: 00190 friend class CssHierarchyTest; 00191 00195 void InitializeNested(const CssHierarchy& parent, 00196 const GoogleUrl& import_url); 00197 00199 void ResizeChildren(int n); 00200 00204 bool IsRecursive() const; 00205 00211 bool DetermineImportMedia(const StringVector& containing_media, 00212 const StringVector& import_media); 00213 00220 bool DetermineRulesetMedia(StringVector* ruleset_media); 00221 00223 CssFilter* filter_; 00224 00227 StringPiece url_; 00228 00230 GoogleUrl css_base_url_; 00231 00234 GoogleUrl css_trim_url_; 00235 00238 const CssHierarchy* parent_; 00239 00243 std::vector<CssHierarchy*> children_; 00244 00246 StringPiece input_contents_; 00247 00249 GoogleString minified_contents_; 00250 00254 scoped_ptr<Css::Stylesheet> stylesheet_; 00255 00258 GoogleString charset_; 00259 00265 StringVector media_; 00266 00270 bool flattening_succeeded_; 00271 00273 bool unparseable_detected_; 00274 00283 int64 flattened_result_limit_; 00284 00286 MessageHandler* message_handler_; 00287 00288 DISALLOW_COPY_AND_ASSIGN(CssHierarchy); 00289 }; 00290 00291 } 00292 00293 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_HIERARCHY_H_