00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 "base/scoped_ptr.h"
00025 #include "net/instaweb/rewriter/public/resource.h"
00026 #include "net/instaweb/util/public/basictypes.h"
00027 #include "net/instaweb/util/public/google_url.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 class UnicodeText;
00036
00037 namespace net_instaweb {
00038
00039 class MessageHandler;
00040
00064 class CssHierarchy {
00065 public:
00068 CssHierarchy();
00069 ~CssHierarchy();
00070
00074 void InitializeRoot(const GoogleUrl& css_base_url,
00075 const GoogleUrl& css_trim_url,
00076 const StringPiece input_contents,
00077 bool is_xhtml,
00078 bool has_unparseables,
00079 Css::Stylesheet* stylesheet,
00080 MessageHandler* message_handler);
00081
00083 bool NeedsRewriting() const {
00084 return flattening_succeeded_ && !url_.empty();
00085 }
00086
00087 const StringPiece url() const { return url_; }
00088
00089 const GoogleUrl& css_base_url() const { return css_base_url_; }
00090 const GoogleUrl& css_trim_url() const { return css_trim_url_; }
00091
00092 const Css::Stylesheet* stylesheet() const { return stylesheet_.get(); }
00093 Css::Stylesheet* mutable_stylesheet() { return stylesheet_.get(); }
00094 void set_stylesheet(Css::Stylesheet* stylesheet);
00095
00096 const StringPiece input_contents() const { return input_contents_; }
00099 void set_input_contents(const StringPiece input_contents) {
00100 input_contents_ = input_contents;
00101 }
00102
00103 const GoogleString& minified_contents() const { return minified_contents_; }
00104 void set_minified_contents(const StringPiece minified_contents);
00105
00106 const GoogleString& charset() const { return charset_; }
00107 GoogleString* mutable_charset() { return &charset_; }
00108
00109 const StringVector& media() const { return media_; }
00110 StringVector* mutable_media() { return &media_; }
00111
00113 const std::vector<CssHierarchy*>& children() const { return children_; }
00114 std::vector<CssHierarchy*>& children() { return children_; }
00115
00116 bool flattening_succeeded() const { return flattening_succeeded_; }
00117 void set_flattening_succeeded(bool ok) { flattening_succeeded_ = ok; }
00118
00119 bool unparseable_detected() const { return unparseable_detected_; }
00120 void set_unparseable_detected(bool ok) { unparseable_detected_ = ok; }
00121
00133 bool CheckCharsetOk(const ResourcePtr& resource);
00134
00140 bool Parse();
00141
00154 bool ExpandChildren();
00155
00169 void RollUpContents();
00170
00185 bool RollUpStylesheets();
00186
00187 private:
00188 friend class CssHierarchyTest;
00189
00193 void InitializeNested(const CssHierarchy& parent,
00194 const GoogleUrl& import_url);
00195
00197 void ResizeChildren(int n);
00198
00202 bool IsRecursive() const;
00203
00209 bool DetermineImportMedia(const StringVector& containing_media,
00210 const std::vector<UnicodeText>& import_media_in);
00211
00218 bool DetermineRulesetMedia(const std::vector<UnicodeText>& ruleset_media_in,
00219 StringVector* ruleset_media_out);
00220
00223 StringPiece url_;
00224
00226 GoogleUrl css_base_url_;
00227
00230 GoogleUrl css_trim_url_;
00231
00234 const CssHierarchy* parent_;
00235
00239 std::vector<CssHierarchy*> children_;
00240
00242 StringPiece input_contents_;
00243
00245 GoogleString minified_contents_;
00246
00250 scoped_ptr<Css::Stylesheet> stylesheet_;
00251 bool is_xhtml_;
00252
00255 GoogleString charset_;
00256
00262 StringVector media_;
00263
00267 bool flattening_succeeded_;
00268
00270 bool unparseable_detected_;
00271
00273 MessageHandler* message_handler_;
00274
00275 DISALLOW_COPY_AND_ASSIGN(CssHierarchy);
00276 };
00277
00278 }
00279
00280 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_CSS_HIERARCHY_H_