Page Speed Optimization Libraries
1.2.24.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_REMOVE_COMMENTS_FILTER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_REMOVE_COMMENTS_FILTER_H_ 00021 00022 #include "net/instaweb/htmlparse/public/empty_html_filter.h" 00023 00024 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/fast_wildcard_group.h" 00026 #include "net/instaweb/util/public/scoped_ptr.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 00029 namespace net_instaweb { 00030 class HtmlCommentNode; 00031 class HtmlParse; 00032 00037 class RemoveCommentsFilter : public EmptyHtmlFilter { 00038 public: 00043 class OptionsInterface { 00044 public: 00045 OptionsInterface() {} 00046 virtual ~OptionsInterface(); 00047 00050 virtual bool IsRetainedComment(const StringPiece& comment) const = 0; 00051 00052 private: 00053 DISALLOW_COPY_AND_ASSIGN(OptionsInterface); 00054 }; 00055 00057 class OptionsImpl : public OptionsInterface { 00058 public: 00059 OptionsImpl() {} 00060 00061 void RetainComment(const StringPiece& comment) { 00062 retain_comments_.Allow(comment); 00063 } 00064 00065 virtual bool IsRetainedComment(const StringPiece& comment) const { 00066 return retain_comments_.Match(comment, false); 00067 } 00068 00069 private: 00070 FastWildcardGroup retain_comments_; 00071 00072 DISALLOW_COPY_AND_ASSIGN(OptionsImpl); 00073 }; 00074 00075 explicit RemoveCommentsFilter(HtmlParse* html_parse) 00076 : html_parse_(html_parse), 00077 options_(NULL) { 00078 } 00079 00083 RemoveCommentsFilter(HtmlParse* html_parse, 00084 const OptionsInterface* options) 00085 : html_parse_(html_parse), 00086 options_(options) { 00087 } 00088 00089 virtual ~RemoveCommentsFilter(); 00090 00091 virtual void Comment(HtmlCommentNode* comment); 00092 virtual const char* Name() const { return "RemoveComments"; } 00093 00094 private: 00095 HtmlParse* html_parse_; 00096 scoped_ptr<const OptionsInterface> options_; 00097 00098 DISALLOW_COPY_AND_ASSIGN(RemoveCommentsFilter); 00099 }; 00100 00101 } 00102 00103 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_REMOVE_COMMENTS_FILTER_H_