Page Speed Optimization Libraries
1.7.30.2
|
00001 /* 00002 * Copyright 2012 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_FILE_LOAD_RULE_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_FILE_LOAD_RULE_H_ 00021 00022 #include "net/instaweb/util/public/manually_ref_counted.h" 00023 #include "net/instaweb/util/public/basictypes.h" 00024 #include "net/instaweb/util/public/re2.h" 00025 #include "net/instaweb/util/public/string.h" 00026 00027 namespace net_instaweb { 00028 00031 class FileLoadRule : public ManuallyRefCounted { 00032 public: 00033 enum Classification { 00034 kAllowed, 00035 kDisallowed, 00036 kUnmatched, 00037 }; 00038 00039 virtual ~FileLoadRule(); 00040 explicit FileLoadRule(bool allowed) : allowed_(allowed) {} 00041 00043 Classification Classify(const GoogleString& filename) const; 00044 00045 protected: 00047 virtual bool Match(const GoogleString& filename) const = 0; 00048 const bool allowed_; 00049 }; 00050 00051 class FileLoadRuleRegexp : public FileLoadRule { 00052 public: 00053 virtual ~FileLoadRuleRegexp(); 00054 00057 FileLoadRuleRegexp(const GoogleString& filename_regexp, bool allowed) 00058 : FileLoadRule(allowed), 00059 filename_regexp_(filename_regexp), 00060 filename_regexp_str_(filename_regexp) 00061 {} 00062 00063 virtual bool Match(const GoogleString& filename) const; 00064 00065 private: 00066 const RE2 filename_regexp_; 00068 const GoogleString filename_regexp_str_; 00069 00070 DISALLOW_COPY_AND_ASSIGN(FileLoadRuleRegexp); 00071 }; 00072 00073 class FileLoadRuleLiteral : public FileLoadRule { 00074 public: 00075 virtual ~FileLoadRuleLiteral(); 00076 00079 FileLoadRuleLiteral(const GoogleString& filename_prefix, bool allowed) 00080 : FileLoadRule(allowed), filename_prefix_(filename_prefix) 00081 {} 00082 00083 virtual bool Match(const GoogleString& filename) const; 00084 00085 private: 00086 const GoogleString filename_prefix_; 00087 00088 DISALLOW_COPY_AND_ASSIGN(FileLoadRuleLiteral); 00089 }; 00090 00091 } 00092 00093 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_FILE_LOAD_RULE_H_