Page Speed Optimization Libraries  1.7.30.1
net/instaweb/rewriter/public/rewrite_options.h
Go to the documentation of this file.
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_REWRITE_OPTIONS_H_
00020 #define NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_
00021 
00022 #include <cstddef>                      
00023 #include <map>
00024 #include <set>
00025 #include <utility>                      
00026 #include <vector>
00027 
00028 #include "base/logging.h"
00029 #include "net/instaweb/http/public/meta_data.h"
00030 #include "net/instaweb/http/public/semantic_type.h"
00031 #include "net/instaweb/rewriter/public/domain_lawyer.h"
00032 #include "net/instaweb/rewriter/public/file_load_policy.h"
00033 #include "net/instaweb/rewriter/public/javascript_library_identification.h"
00034 #include "net/instaweb/util/public/basictypes.h"
00035 #include "net/instaweb/util/public/enum_set.h"
00036 #include "net/instaweb/util/public/gtest_prod.h"
00037 #include "net/instaweb/util/public/md5_hasher.h"
00038 #include "net/instaweb/util/public/scoped_ptr.h"
00039 #include "net/instaweb/util/public/string.h"
00040 #include "net/instaweb/util/public/string_util.h"
00041 #include "net/instaweb/util/public/thread_system.h"
00042 #include "pagespeed/kernel/base/dense_hash_map.h"
00043 #include "pagespeed/kernel/base/fast_wildcard_group.h"
00044 #include "pagespeed/kernel/base/rde_hash_map.h"
00045 #include "pagespeed/kernel/base/string_hash.h"
00046 #include "pagespeed/kernel/base/wildcard.h"
00047 #include "pagespeed/kernel/util/copy_on_write.h"
00048 
00049 namespace net_instaweb {
00050 
00051 class Hasher;
00052 class MessageHandler;
00053 class RequestHeaders;
00054 
00075 class RewriteOptions {
00076  private:
00081   class PropertyBase;
00082   template<class ValueType> class Property;
00083   template<class RewriteOptionsSubclass, class OptionClass> class PropertyLeaf;
00084 
00085  public:
00090   enum Filter {
00091     kAddBaseTag,  
00092     kAddHead,
00093     kAddInstrumentation,
00094     kComputeStatistics,
00095     kCachePartialHtml,
00096     kCanonicalizeJavascriptLibraries,
00097     kCollapseWhitespace,
00098     kCollectFlushEarlyContentFilter,
00099     kCombineCss,
00100     kCombineHeads,
00101     kCombineJavascript,
00102     kComputeCriticalCss,
00103     kComputeVisibleText,
00104     kConvertGifToPng,
00105     kConvertJpegToProgressive,
00106     kConvertJpegToWebp,
00107     kConvertMetaTags,
00108     kConvertPngToJpeg,
00109     kConvertToWebpLossless,
00110     kDebug,
00111     kDecodeRewrittenUrls,
00112     kDedupInlinedImages,
00113     kDeferIframe,
00114     kDeferJavascript,
00115     kDelayImages,
00116     kDeterministicJs,
00117     kDisableJavascript,
00118     kDivStructure,
00119     kElideAttributes,
00120     kExperimentSpdy,  
00121     kExplicitCloseTags,
00122     kExtendCacheCss,
00123     kExtendCacheImages,
00124     kExtendCachePdfs,
00125     kExtendCacheScripts,
00126     kFallbackRewriteCssUrls,
00127     kFixReflows,
00128     kFlattenCssImports,
00129     kFlushSubresources,
00130     kHandleNoscriptRedirect,
00131     kHtmlWriterFilter,
00132     kInlineCss,
00133     kInlineGoogleFontCss,
00134     kInlineImages,
00135     kInlineImportToLink,
00136     kInlineJavascript,
00137     kInPlaceOptimizeForBrowser,
00138     kInsertDnsPrefetch,
00139     kInsertGA,
00140     kInsertImageDimensions,
00141     kJpegSubsampling,
00142     kLazyloadImages,
00143     kLeftTrimUrls,
00144     kLocalStorageCache,
00145     kMakeGoogleAnalyticsAsync,
00146     kMoveCssAboveScripts,
00147     kMoveCssToHead,
00148     kOutlineCss,
00149     kOutlineJavascript,
00150     kPedantic,
00151     kPrioritizeCriticalCss,
00152     kRecompressJpeg,
00153     kRecompressPng,
00154     kRecompressWebp,
00155     kRemoveComments,
00156     kRemoveQuotes,
00157     kResizeImages,
00158     kResizeMobileImages,
00159     kResizeToRenderedImageDimensions,
00160     kRewriteCss,
00161     kRewriteDomains,
00162     kRewriteJavascript,
00163     kRewriteStyleAttributes,
00164     kRewriteStyleAttributesWithUrl,
00165     kSplitHtml,
00166     kSplitHtmlHelper,
00167     kSpriteImages,
00168     kSquashImagesForMobileScreen,
00169     kStripImageColorProfile,
00170     kStripImageMetaData,
00171     kStripNonCacheable,
00172     kStripScripts,
00173     kEndOfFilters
00174   };
00175 
00176   enum EnabledEnum {
00179     kEnabledOff,
00181     kEnabledOn,
00184     kEnabledUnplugged,
00185   };
00186 
00193   static const char kAccessControlAllowOrigins[];
00194   static const char kAddOptionsToUrls[];
00195   static const char kAllowLoggingUrlsInLogRecord[];
00196   static const char kAlwaysRewriteCss[];
00197   static const char kAnalyticsID[];
00198   static const char kAvoidRenamingIntrospectiveJavascript[];
00199   static const char kAwaitPcacheLookup[];
00200   static const char kBeaconReinstrumentTimeSec[];
00201   static const char kBeaconUrl[];
00202   static const char kBlinkMaxHtmlSizeRewritable[];
00203   static const char kCacheInvalidationTimestamp[];
00204   static const char kCacheSmallImagesUnrewritten[];
00205   static const char kClientDomainRewrite[];
00206   static const char kCombineAcrossPaths[];
00207   static const char kCriticalImagesBeaconEnabled[];
00208   static const char kCriticalLineConfig[];
00209   static const char kCssFlattenMaxBytes[];
00210   static const char kCssImageInlineMaxBytes[];
00211   static const char kCssInlineMaxBytes[];
00212   static const char kCssOutlineMinBytes[];
00213   static const char kCssPreserveURLs[];
00214   static const char kDefaultCacheHtml[];
00215   static const char kDisableBackgroundFetchesForBots[];
00216   static const char kDisableRewriteOnNoTransform[];
00217   static const char kDistributeFetches[];
00218   static const char kDistributedRewriteKey[];
00219   static const char kDistributedRewriteServers[];
00220   static const char kDistributedRewriteTimeoutMs[];
00221   static const char kDomainRewriteHyperlinks[];
00222   static const char kDomainShardCount[];
00223   static const char kDownstreamCachePurgeMethod[];
00224   static const char kDownstreamCacheRewrittenPercentageThreshold[];
00225   static const char kEnableAggressiveRewritersForMobile[];
00226   static const char kEnableBlinkHtmlChangeDetection[];
00227   static const char kEnableBlinkHtmlChangeDetectionLogging[];
00228   static const char kEnableCachePurge[];
00229   static const char kEnableDeferJsExperimental[];
00230   static const char kEnableExtendedInstrumentation[];
00231   static const char kEnableFlushEarlyCriticalCss[];
00232   static const char kEnableLazyLoadHighResImages[];
00233   static const char kEnablePrioritizingScripts[];
00234   static const char kEnabled[];
00235   static const char kExperimentCookieDurationMs[];
00236   static const char kExperimentSlot[];
00237   static const char kFetcherTimeOutMs[];
00238   static const char kFinderPropertiesCacheExpirationTimeMs[];
00239   static const char kFinderPropertiesCacheRefreshTimeMs[];
00240   static const char kFlushBufferLimitBytes[];
00241   static const char kFlushHtml[];
00242   static const char kFlushMoreResourcesEarlyIfTimePermits[];
00243   static const char kForbidAllDisabledFilters[];
00244   static const char kHideRefererUsingMeta[];
00245   static const char kIdleFlushTimeMs[];
00246   static const char kImageInlineMaxBytes[];
00247   static const char kImageJpegNumProgressiveScans[];
00248   static const char kImageJpegNumProgressiveScansForSmallScreens[];
00249   static const char kImageJpegRecompressionQuality[];
00250   static const char kImageJpegRecompressionQualityForSmallScreens[];
00251   static const char kImageLimitOptimizedPercent[];
00252   static const char kImageLimitRenderedAreaPercent[];
00253   static const char kImageLimitResizeAreaPercent[];
00254   static const char kImageMaxRewritesAtOnce[];
00255   static const char kImagePreserveURLs[];
00256   static const char kImageRecompressionQuality[];
00257   static const char kImageResolutionLimitBytes[];
00258   static const char kImageWebpRecompressionQuality[];
00259   static const char kImageWebpRecompressionQualityForSmallScreens[];
00260   static const char kImageWebpTimeoutMs[];
00261   static const char kImplicitCacheTtlMs[];
00262   static const char kIncreaseSpeedTracking[];
00263   static const char kInlineOnlyCriticalImages[];
00264   static const char kInPlacePreemptiveRewriteCss[];
00265   static const char kInPlacePreemptiveRewriteCssImages[];
00266   static const char kInPlacePreemptiveRewriteImages[];
00267   static const char kInPlacePreemptiveRewriteJavascript[];
00268   static const char kInPlaceResourceOptimization[];
00269   static const char kInPlaceRewriteDeadlineMs[];
00270   static const char kInPlaceWaitForOptimized[];
00271   static const char kJsInlineMaxBytes[];
00272   static const char kJsOutlineMinBytes[];
00273   static const char kJsPreserveURLs[];
00274   static const char kLazyloadImagesAfterOnload[];
00275   static const char kLazyloadImagesBlankUrl[];
00276   static const char kLogBackgroundRewrite[];
00277   static const char kLogRewriteTiming[];
00278   static const char kLogUrlIndices[];
00279   static const char kLowercaseHtmlNames[];
00280   static const char kMaxCacheableResponseContentLength[];
00281   static const char kMaxCombinedCssBytes[];
00282   static const char kMaxCombinedJsBytes[];
00283   static const char kMaxHtmlCacheTimeMs[];
00284   static const char kMaxHtmlParseBytes[];
00285   static const char kMaxImageBytesForWebpInCss[];
00286   static const char kMaxImageSizeLowResolutionBytes[];
00287   static const char kMaxInlinedPreviewImagesIndex[];
00288   static const char kMaxLowResImageSizeBytes[];
00289   static const char kMaxLowResToHighResImageSizePercentage[];
00290   static const char kMaxPrefetchJsElements[];
00291   static const char kMaxRewriteInfoLogSize[];
00292   static const char kMaxUrlSegmentSize[];
00293   static const char kMaxUrlSize[];
00294   static const char kMetadataCacheStalenessThresholdMs[];
00295   static const char kMinCacheTtlMs[];
00296   static const char kMinImageSizeLowResolutionBytes[];
00297   static const char kMinResourceCacheTimeToRewriteMs[];
00298   static const char kModifyCachingHeaders[];
00299   static const char kNonCacheablesForCachePartialHtml[];
00300   static const char kObliviousPagespeedUrls[];
00301   static const char kOverrideCachingTtlMs[];
00302   static const char kPersistBlinkBlacklist[];
00303   static const char kPreserveUrlRelativity[];
00304   static const char kProactivelyFreshenUserFacingRequest[];
00305   static const char kProactiveResourceFreshening[];
00306   static const char kProgressiveJpegMinBytes[];
00307   static const char kRejectBlacklisted[];
00308   static const char kRejectBlacklistedStatusCode[];
00309   static const char kReportUnloadTime[];
00310   static const char kRespectVary[];
00311   static const char kRespectXForwardedProto[];
00312   static const char kRewriteDeadlineMs[];
00313   static const char kRewriteLevel[];
00314   static const char kRewriteRandomDropPercentage[];
00315   static const char kRewriteRequestUrlsEarly[];
00316   static const char kRewriteUncacheableResources[];
00317   static const char kRunningExperiment[];
00318   static const char kServeGhostClickBusterWithSplitHtml[];
00319   static const char kServeSplitHtmlInTwoChunks[];
00320   static const char kServeStaleIfFetchError[];
00321   static const char kServeStaleWhileRevalidateThresholdSec[];
00322   static const char kServeXhrAccessControlHeaders[];
00323   static const char kSupportNoScriptEnabled[];
00324   static const char kTestOnlyPrioritizeCriticalCssDontApplyOriginalCss[];
00325   static const char kUseBlankImageForInlinePreview[];
00326   static const char kUseFallbackPropertyCacheValues[];
00327   static const char kUseImageScanlineApi[];
00328   static const char kUseSelectorsForCriticalCss[];
00329   static const char kUseSmartDiffInBlink[];
00330   static const char kXModPagespeedHeaderValue[];
00331   static const char kXPsaBlockingRewrite[];
00333   static const char kAllow[];
00334   static const char kBlockingRewriteRefererUrls[];
00335   static const char kDisableFilters[];
00336   static const char kDisallow[];
00337   static const char kDistributableFilters[]; 
00338   static const char kDomain[];
00339   static const char kDownstreamCachePurgeLocationPrefix[];
00340   static const char kEnableFilters[];
00341   static const char kExperimentVariable[];
00342   static const char kExperimentSpec[];
00343   static const char kForbidFilters[];
00344   static const char kRetainComment[];
00346   static const char kCustomFetchHeader[];
00347   static const char kLoadFromFile[];
00348   static const char kLoadFromFileMatch[];
00349   static const char kLoadFromFileRule[];
00350   static const char kLoadFromFileRuleMatch[];
00351   static const char kMapOriginDomain[];
00352   static const char kMapProxyDomain[];
00353   static const char kMapRewriteDomain[];
00354   static const char kShardDomain[];
00356   static const char kLibrary[];
00357   static const char kUrlValuedAttribute[];
00360   static const char kCacheFlushFilename[];
00361   static const char kCacheFlushPollIntervalSec[];
00362   static const char kCompressMetadataCache[];
00363   static const char kFetcherProxy[];
00364   static const char kFetchFromModSpdy[];
00365   static const char kFetchHttps[];
00366   static const char kFileCacheCleanInodeLimit[];
00367   static const char kFileCacheCleanIntervalMs[];
00368   static const char kFileCacheCleanSizeKb[];
00369   static const char kFileCachePath[];
00370   static const char kLogDir[];
00371   static const char kLruCacheByteLimit[];
00372   static const char kLruCacheKbPerProcess[];
00373   static const char kMemcachedServers[];
00374   static const char kMemcachedThreads[];
00375   static const char kMemcachedTimeoutUs[];
00376   static const char kRateLimitBackgroundFetches[];
00377   static const char kSlurpDirectory[];
00378   static const char kSlurpFlushLimit[];
00379   static const char kSlurpReadOnly[];
00380   static const char kSslCertDirectory[];
00381   static const char kSslCertFile[];
00382   static const char kStatisticsEnabled[];
00383   static const char kStatisticsHandlerPath[];
00384   static const char kStatisticsLoggingChartsCSS[];
00385   static const char kStatisticsLoggingChartsJS[];
00386   static const char kStatisticsLoggingEnabled[];
00387   static const char kStatisticsLoggingIntervalMs[];
00388   static const char kStatisticsLoggingMaxFileSizeKb[];
00389   static const char kTestProxy[];
00390   static const char kTestProxySlurp[];
00391   static const char kUseSharedMemLocking[];
00393   static const char kNullOption[];
00394 
00402   struct BeaconUrl {
00403     GoogleString http;
00404     GoogleString https;
00405     GoogleString http_in;
00406     GoogleString https_in;
00407   };
00408 
00409   struct NameValue {
00410     NameValue(const StringPiece& name_in, const StringPiece& value_in) {
00411       name_in.CopyToString(&name);
00412       value_in.CopyToString(&value);
00413     }
00414     GoogleString name;
00415     GoogleString value;
00416   };
00417 
00433   static const int kOptionsVersion = 13;
00434 
00436   static const int kHashBytes = 20;
00437 
00442   enum OptionScope {
00443     kDirectoryScope,  
00444     kServerScope,     
00445     kProcessScope,    
00446     kProcessScopeStrict,  
00447   };
00448 
00449   static const char kCacheExtenderId[];
00450   static const char kCollectFlushEarlyContentFilterId[];
00451   static const char kCssCombinerId[];
00452   static const char kCssFilterId[];
00453   static const char kCssImportFlattenerId[];
00454   static const char kCssInlineId[];
00455   static const char kGoogleFontCssInlineId[];
00456   static const char kImageCombineId[];
00457   static const char kImageCompressionId[];
00458   static const char kInPlaceRewriteId[];
00459   static const char kJavascriptCombinerId[];
00460   static const char kJavascriptInlineId[];
00461   static const char kJavascriptMinId[];
00462   static const char kLocalStorageCacheId[];
00463   static const char kPrioritizeCriticalCssId[];
00464 
00465   static const char kPanelCommentPrefix[];
00466 
00469   static const char* FilterName(Filter filter);
00470 
00473   static const char* FilterId(Filter filter);
00474 
00477   static int NumFilterIds();
00478 
00480   static const Filter kFirstFilter = kAddBaseTag;
00481 
00482   typedef EnumSet<Filter, kEndOfFilters> FilterSet;
00483   typedef std::vector<Filter> FilterVector;
00484 
00486   typedef std::set<GoogleString> FilterIdSet;
00487 
00493   static bool AddByNameToFilterSet(const StringPiece& option, FilterSet* set,
00494                                    MessageHandler* handler);
00495 
00498   typedef std::pair<StringPiece, StringPiece> OptionStringPair;
00499   typedef std::set<OptionStringPair> OptionSet;
00500 
00501   typedef std::vector<PropertyBase*> PropertyVector;
00502 
00505   class OptionBase {
00506    public:
00507     OptionBase() {}
00508     virtual ~OptionBase();
00509 
00511     virtual bool SetFromString(const GoogleString& value_string) = 0;
00512     virtual void Merge(const OptionBase* src) = 0;
00513     virtual bool was_set() const = 0;
00514     virtual GoogleString Signature(const Hasher* hasher) const = 0;
00515     virtual GoogleString ToString() const = 0;
00516     const char* id() const { return property()->id(); }
00517     const char* help_text() const { return property()->help_text(); }
00518     OptionScope scope() const { return property()->scope(); }
00519     StringPiece option_name() const { return property()->option_name(); }
00520     bool is_used_for_signature_computation() const {
00521       return property()->is_used_for_signature_computation();
00522     }
00523     virtual const PropertyBase* property() const = 0;
00524   };
00525 
00527   typedef std::vector<OptionBase*> OptionBaseVector;
00528 
00529   enum RewriteLevel {
00534     kPassThrough,
00535 
00541     kCoreFilters,
00542 
00546     kTestingCoreFilters,
00547 
00550     kAllFilters,
00551   };
00552 
00554   enum OptionSettingResult {
00555     kOptionOk,
00556     kOptionNameUnknown,
00557     kOptionValueInvalid
00558   };
00559 
00560   static const int kDefaultBeaconReinstrumentTimeSec;
00561   static const int64 kDefaultBlinkMaxHtmlSizeRewritable;
00562   static const int64 kDefaultCssFlattenMaxBytes;
00563   static const int64 kDefaultCssImageInlineMaxBytes;
00564   static const int64 kDefaultCssInlineMaxBytes;
00565   static const int64 kDefaultCssOutlineMinBytes;
00566   static const int64 kDefaultImageInlineMaxBytes;
00567   static const int64 kDefaultJsInlineMaxBytes;
00568   static const int64 kDefaultJsOutlineMinBytes;
00569   static const int64 kDefaultProgressiveJpegMinBytes;
00570   static const int64 kDefaultMaxCacheableResponseContentLength;
00571   static const int64 kDefaultMaxHtmlCacheTimeMs;
00572   static const int64 kDefaultMaxHtmlParseBytes;
00573   static const int64 kDefaultMaxImageBytesForWebpInCss;
00574   static const int64 kDefaultMaxLowResImageSizeBytes;
00575   static const int kDefaultMaxLowResToFullResImageSizePercentage;
00576   static const int64 kDefaultMetadataInputErrorsCacheTtlMs;
00577   static const int64 kDefaultMinResourceCacheTimeToRewriteMs;
00578   static const char kDefaultDownstreamCachePurgeMethod[];
00579   static const int64 kDefaultDownstreamCacheRewrittenPercentageThreshold;
00580   static const int64 kDefaultCacheInvalidationTimestamp;
00581   static const int64 kDefaultIdleFlushTimeMs;
00582   static const int64 kDefaultFlushBufferLimitBytes;
00583   static const int64 kDefaultImplicitCacheTtlMs;
00584   static const int64 kDefaultMinCacheTtlMs;
00585   static const int64 kDefaultPrioritizeVisibleContentCacheTimeMs;
00586   static const char kDefaultBeaconUrl[];
00587   static const int64 kDefaultImageRecompressQuality;
00588   static const int64 kDefaultImageJpegRecompressQuality;
00589   static const int64 kDefaultImageJpegRecompressQualityForSmallScreens;
00590   static const int kDefaultImageLimitOptimizedPercent;
00591   static const int kDefaultImageLimitRenderedAreaPercent;
00592   static const int kDefaultImageLimitResizeAreaPercent;
00593   static const int64 kDefaultImageResolutionLimitBytes;
00594   static const int64 kDefaultImageJpegNumProgressiveScans;
00595   static const int64 kDefaultImageWebpRecompressQuality;
00596   static const int64 kDefaultImageWebpRecompressQualityForSmallScreens;
00597   static const int64 kDefaultImageWebpTimeoutMs;
00598   static const int kDefaultDomainShardCount;
00599   static const int64 kDefaultBlinkHtmlChangeDetectionTimeMs;
00600   static const int kDefaultMaxPrefetchJsElements;
00601 
00604   static const int kDefaultMaxUrlSize;
00605 
00606   static const int kDefaultImageMaxRewritesAtOnce;
00607 
00612   static const int kDefaultMaxUrlSegmentSize;
00613 
00615   static const int kDefaultRewriteDeadlineMs;
00616 
00618   static const int64 kDefaultDistributedTimeoutMs;
00619 
00622   static const int kDefaultMaxInlinedPreviewImagesIndex;
00625   static const int64 kDefaultMinImageSizeLowResolutionBytes;
00628   static const int64 kDefaultMaxImageSizeLowResolutionBytes;
00630   static const int64 kDefaultFinderPropertiesCacheExpirationTimeMs;
00632   static const int64 kDefaultFinderPropertiesCacheRefreshTimeMs;
00633 
00636   static const int64 kDefaultExperimentCookieDurationMs;
00637 
00640   static const int64 kDefaultMetadataCacheStalenessThresholdMs;
00641 
00643   static const int64 kDefaultMaxCombinedCssBytes;
00644 
00646   static const int64 kDefaultMaxCombinedJsBytes;
00647 
00648   static const int kDefaultExperimentTrafficPercent;
00650   static const int kDefaultExperimentSlot;
00651 
00652   static const char kDefaultBlockingRewriteKey[];
00653 
00654   static const char kRejectedRequestUrlKeyName[];
00655 
00656   static const int kDefaultPropertyCacheHttpStatusStabilityThreshold;
00657 
00658   static const int kDefaultMaxRewriteInfoLogSize;
00659 
00667   class ExperimentSpec {
00668    public:
00673     ExperimentSpec(const StringPiece& spec, RewriteOptions* options,
00674                    MessageHandler* handler);
00675 
00679     explicit ExperimentSpec(int id);
00680 
00681     virtual ~ExperimentSpec();
00682 
00684     virtual ExperimentSpec* Clone();
00685 
00686     bool is_valid() const { return id_ >= 0; }
00687 
00689     int id() const { return id_; }
00690     int percent() const { return percent_; }
00691     GoogleString ga_id() const { return ga_id_; }
00692     int slot() const { return ga_variable_slot_; }
00693     RewriteLevel rewrite_level() const { return rewrite_level_; }
00694     FilterSet enabled_filters() const { return enabled_filters_; }
00695     FilterSet disabled_filters() const { return disabled_filters_; }
00696     OptionSet filter_options() const { return filter_options_; }
00697     int64 css_inline_max_bytes() const { return css_inline_max_bytes_; }
00698     int64 js_inline_max_bytes() const { return js_inline_max_bytes_; }
00699     int64 image_inline_max_bytes() const { return image_inline_max_bytes_; }
00700     bool use_default() const { return use_default_; }
00701 
00702    protected:
00706     void Merge(const ExperimentSpec& spec);
00707 
00708    private:
00709     FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
00710 
00713     void Initialize(const StringPiece& spec, MessageHandler* handler);
00714 
00715     int id_; 
00716     GoogleString ga_id_; 
00717     int ga_variable_slot_;
00718     int percent_; 
00719     RewriteLevel rewrite_level_;
00720     FilterSet enabled_filters_;
00721     FilterSet disabled_filters_;
00722     OptionSet filter_options_;
00723     int64 css_inline_max_bytes_;
00724     int64 js_inline_max_bytes_;
00725     int64 image_inline_max_bytes_;
00728     bool use_default_;
00729     DISALLOW_COPY_AND_ASSIGN(ExperimentSpec);
00730   };
00731 
00733   struct ElementAttributeCategory {
00734     GoogleString element;
00735     GoogleString attribute;
00736     semantic_type::Category category;
00737   };
00738 
00745   class Properties {
00746    public:
00755     static bool Initialize(Properties** properties);
00756 
00765     static bool Terminate(Properties** properties_handle);
00766 
00768     int size() const { return property_vector_.size(); }
00769 
00770     const PropertyBase* property(int index) const {
00771       return property_vector_[index];
00772     }
00773     PropertyBase* property(int index) { return property_vector_[index]; }
00774 
00780     void Merge(Properties* properties);
00781 
00782     void push_back(PropertyBase* p) { property_vector_.push_back(p); }
00783 
00784    private:
00787     Properties();
00788     ~Properties();
00789 
00793     int initialization_count_;
00794 
00799     bool owns_properties_;
00800     PropertyVector property_vector_;
00801   };
00802 
00804   struct FilterEnumToIdAndNameEntry {
00805     RewriteOptions::Filter filter_enum;
00806     const char* filter_id;
00807     const char* filter_name;
00808   };
00809 
00810   static bool ParseRewriteLevel(const StringPiece& in, RewriteLevel* out);
00811 
00815   static bool ParseBeaconUrl(const StringPiece& in, BeaconUrl* out);
00816 
00820   bool ImageOptimizationEnabled() const;
00821 
00822   explicit RewriteOptions(ThreadSystem* thread_system);
00823   virtual ~RewriteOptions();
00824 
00828   static bool Initialize();
00829   static bool Terminate();
00830 
00831 #ifndef NDEBUG
00832 
00833 
00834 
00835 
00836 
00837 
00838   bool ModificationOK() const;
00839 
00846   bool MergeOK() const;
00847 #endif
00848 
00853   void InitializeOptions(const Properties* properties);
00854 
00855   bool modified() const { return modified_; }
00856 
00862   void SetDefaultRewriteLevel(RewriteLevel level) {
00864     level_.set_default(level);
00865   }
00866   void SetRewriteLevel(RewriteLevel level) {
00867     set_option(level, &level_);
00868   }
00869 
00871   void AddCustomFetchHeader(const StringPiece& name, const StringPiece& value);
00872 
00873   const NameValue* custom_fetch_header(int i) const {
00874     return custom_fetch_headers_[i];
00875   }
00876 
00877   int num_custom_fetch_headers() const {
00878     return custom_fetch_headers_.size();
00879   }
00880 
00883   ExperimentSpec* GetExperimentSpec(int id) const;
00884 
00888   bool AvailableExperimentId(int id);
00889 
00892   virtual bool AddExperimentSpec(const StringPiece& spec,
00893                                  MessageHandler* handler);
00894 
00902   virtual bool SetExperimentState(int id);
00903 
00907   void SetExperimentStateStr(const StringPiece& experiment_index);
00908 
00909   int experiment_id() const { return experiment_id_; }
00910 
00911   int experiment_spec_id(int i) const {
00912     return experiment_specs_[i]->id();
00913   }
00914 
00919   GoogleString GetExperimentStateStr() const;
00920 
00921   ExperimentSpec* experiment_spec(int i) const {
00922     return experiment_specs_[i];
00923   }
00924 
00925   int num_experiments() const { return experiment_specs_.size(); }
00926 
00938   void AddUrlValuedAttribute(const StringPiece& element,
00939                              const StringPiece& attribute,
00940                              semantic_type::Category category);
00941 
00944   void UrlValuedAttribute(int index,
00945                           StringPiece* element,
00946                           StringPiece* attribute,
00947                           semantic_type::Category* category) const;
00948 
00949   int num_url_valued_attributes() const {
00950     if (url_valued_attributes_ == NULL) {
00951       return 0;
00952     } else {
00953       return url_valued_attributes_->size();
00954     }
00955   }
00956 
00958   bool RegisterLibrary(
00959       uint64 bytes, StringPiece md5_hash, StringPiece canonical_url) {
00960     return WriteableJavascriptLibraryIdentification()->RegisterLibrary(
00961         bytes, md5_hash, canonical_url);
00962   }
00963 
00966   const JavascriptLibraryIdentification* javascript_library_identification()
00967       const {
00968     if (Enabled(kCanonicalizeJavascriptLibraries)) {
00969       return javascript_library_identification_.get();
00970     } else {
00971       return NULL;
00972     }
00973   }
00974 
00975   RewriteLevel level() const { return level_.value(); }
00976 
00981   bool AdjustFiltersByCommaSeparatedList(const StringPiece& filters,
00982                                          MessageHandler* handler);
00983 
00987   bool EnableFiltersByCommaSeparatedList(const StringPiece& filters,
00988                                          MessageHandler* handler);
00989 
00993   bool DisableFiltersByCommaSeparatedList(const StringPiece& filters,
00994                                           MessageHandler* handler);
00995 
00999   bool ForbidFiltersByCommaSeparatedList(const StringPiece& filters,
01000                                          MessageHandler* handler);
01001 
01003   void DisableAllFilters();
01004 
01012   void DisableAllFiltersNotExplicitlyEnabled();
01013 
01016   void DistributeFiltersByCommaSeparatedList(const StringPiece& filter_ids,
01017                                                MessageHandler* handler);
01020   void DistributeFilter(const StringPiece& filter_id);
01021 
01024   bool Distributable(const StringPiece& filter_id) const;
01025 
01029   void EnableFilter(Filter filter);
01032   void ForceEnableFilter(Filter filter);
01033   void DisableFilter(Filter filter);
01034   void ForbidFilter(Filter filter);
01035   void EnableFilters(const FilterSet& filter_set);
01036   void DisableFilters(const FilterSet& filter_set);
01037   void ForbidFilters(const FilterSet& filter_set);
01040   void ClearFilters();
01041 
01044   void EnableExtendCacheFilters();
01045 
01046   bool Enabled(Filter filter) const;
01047   bool Forbidden(Filter filter) const;
01048   bool Forbidden(StringPiece filter_id) const;
01049 
01051   void GetEnabledFiltersRequiringScriptExecution(FilterVector* filters) const;
01052 
01054   void DisableFiltersRequiringScriptExecution();
01055 
01060   static bool AddCommaSeparatedListToOptionSet(
01061       const StringPiece& options, OptionSet* set, MessageHandler* handler);
01062 
01067   OptionSettingResult SetOptionFromName(
01068       StringPiece name, StringPiece value, GoogleString* msg);
01069 
01074   virtual OptionSettingResult ParseAndSetOptionFromName1(
01075       StringPiece name, StringPiece arg,
01076       GoogleString* msg, MessageHandler* handler);
01077 
01078   virtual OptionSettingResult ParseAndSetOptionFromName2(
01079       StringPiece name, StringPiece arg1, StringPiece arg2,
01080       GoogleString* msg, MessageHandler* handler);
01081 
01082   virtual OptionSettingResult ParseAndSetOptionFromName3(
01083       StringPiece name, StringPiece arg1, StringPiece arg2, StringPiece arg3,
01084       GoogleString* msg, MessageHandler* handler);
01085 
01090   OptionSettingResult SetOptionFromName(StringPiece name, StringPiece value);
01091 
01097   bool OptionValue(StringPiece option_name, const char** id,
01098                    bool* was_set, GoogleString* value) const;
01099 
01102   bool SetOptionsFromName(const OptionSet& option_set);
01103 
01106   bool SetOptionFromNameAndLog(StringPiece name,
01107                                StringPiece value,
01108                                MessageHandler* handler);
01109 
01112   static bool ParseFromString(const GoogleString& value_string, bool* value);
01113   static bool ParseFromString(const GoogleString& value_string,
01114                               EnabledEnum* value);
01115   static bool ParseFromString(const GoogleString& value_string, int* value) {
01116     return StringToInt(value_string, value);
01117   }
01118   static bool ParseFromString(const GoogleString& value_string, int64* value) {
01119     return StringToInt64(value_string, value);
01120   }
01121   static bool ParseFromString(const GoogleString& value_string,
01122                               GoogleString* value) {
01123     *value = value_string;
01124     return true;
01125   }
01126   static bool ParseFromString(const GoogleString& value_string,
01127                               RewriteLevel* value) {
01128     return ParseRewriteLevel(value_string, value);
01129   }
01130   static bool ParseFromString(const GoogleString& value_string,
01131                               BeaconUrl* value) {
01132     return ParseBeaconUrl(value_string, value);
01133   }
01134 
01137   int64 css_outline_min_bytes() const { return css_outline_min_bytes_.value(); }
01138   void set_css_outline_min_bytes(int64 x) {
01139     set_option(x, &css_outline_min_bytes_);
01140   }
01141 
01142   GoogleString ga_id() const { return ga_id_.value(); }
01143   void set_ga_id(GoogleString id) {
01144     set_option(id, &ga_id_);
01145   }
01146 
01147   bool increase_speed_tracking() const {
01148     return increase_speed_tracking_.value();
01149   }
01150   void set_increase_speed_tracking(bool x) {
01151     set_option(x, &increase_speed_tracking_);
01152   }
01153 
01154   int64 js_outline_min_bytes() const { return js_outline_min_bytes_.value(); }
01155   void set_js_outline_min_bytes(int64 x) {
01156     set_option(x, &js_outline_min_bytes_);
01157   }
01158 
01159   int64 progressive_jpeg_min_bytes() const {
01160     return progressive_jpeg_min_bytes_.value();
01161   }
01162   void set_progressive_jpeg_min_bytes(int64 x) {
01163     set_option(x, &progressive_jpeg_min_bytes_);
01164   }
01165 
01166   int64 css_flatten_max_bytes() const { return css_flatten_max_bytes_.value(); }
01167   void set_css_flatten_max_bytes(int64 x) {
01168     set_option(x, &css_flatten_max_bytes_);
01169   }
01170   bool cache_small_images_unrewritten() const {
01171     return cache_small_images_unrewritten_.value();
01172   }
01173   void set_cache_small_images_unrewritten(bool x) {
01174     set_option(x, &cache_small_images_unrewritten_);
01175   }
01176   int64 image_resolution_limit_bytes() const {
01177     return image_resolution_limit_bytes_.value();
01178   }
01179   void set_image_resolution_limit_bytes(int64 x) {
01180     set_option(x, &image_resolution_limit_bytes_);
01181   }
01182 
01184   int64 ImageInlineMaxBytes() const;
01185   void set_image_inline_max_bytes(int64 x);
01187   int64 CssImageInlineMaxBytes() const;
01188   void set_css_image_inline_max_bytes(int64 x) {
01189     set_option(x, &css_image_inline_max_bytes_);
01190   }
01192   int64 MaxImageInlineMaxBytes() const;
01193   int64 css_inline_max_bytes() const { return css_inline_max_bytes_.value(); }
01194   void set_css_inline_max_bytes(int64 x) {
01195     set_option(x, &css_inline_max_bytes_);
01196   }
01197   int64 js_inline_max_bytes() const { return js_inline_max_bytes_.value(); }
01198   void set_js_inline_max_bytes(int64 x) {
01199     set_option(x, &js_inline_max_bytes_);
01200   }
01201   int64 max_html_cache_time_ms() const {
01202     return max_html_cache_time_ms_.value();
01203   }
01204   void set_max_html_cache_time_ms(int64 x) {
01205     set_option(x, &max_html_cache_time_ms_);
01206   }
01207   int64 max_html_parse_bytes() const {
01208     return max_html_parse_bytes_.value();
01209   }
01210   void set_max_html_parse_bytes(int64 x) {
01211     set_option(x, &max_html_parse_bytes_);
01212   }
01213   int64 max_image_bytes_for_webp_in_css() const {
01214     return max_image_bytes_for_webp_in_css_.value();
01215   }
01216   void set_max_image_bytes_for_webp_in_css(int64 x) {
01217     set_option(x, &max_image_bytes_for_webp_in_css_);
01218   }
01219   int64 max_cacheable_response_content_length() const {
01220     return max_cacheable_response_content_length_.value();
01221   }
01222   void set_max_cacheable_response_content_length(int64 x) {
01223     set_option(x, &max_cacheable_response_content_length_);
01224   }
01225   int64 min_resource_cache_time_to_rewrite_ms() const {
01226     return min_resource_cache_time_to_rewrite_ms_.value();
01227   }
01228   void set_min_resource_cache_time_to_rewrite_ms(int64 x) {
01229     set_option(x, &min_resource_cache_time_to_rewrite_ms_);
01230   }
01231   bool need_to_store_experiment_data() const {
01232     return need_to_store_experiment_data_;
01233   }
01234   void set_need_to_store_experiment_data(bool x) {
01235     need_to_store_experiment_data_ = x;
01236   }
01237 
01238   int64 blocking_fetch_timeout_ms() const {
01239     return blocking_fetch_timeout_ms_.value();
01240   }
01241   void set_blocking_fetch_timeout_ms(int64 x) {
01242     set_option(x, &blocking_fetch_timeout_ms_);
01243   }
01244   bool override_ie_document_mode() const {
01245     return override_ie_document_mode_.value();
01246   }
01247   void set_override_ie_document_mode(bool x) {
01248     set_option(x, &override_ie_document_mode_);
01249   }
01250 
01251   int64 blink_blacklist_end_timestamp_ms() const {
01252     return blink_blacklist_end_timestamp_ms_.value();
01253   }
01254   void set_blink_blacklist_end_timestamp_ms(int64 x) {
01255     set_option(x, &blink_blacklist_end_timestamp_ms_);
01256   }
01257 
01258   bool persist_blink_blacklist() const {
01259     return persist_blink_blacklist_.value();
01260   }
01261   void set_persist_blink_blacklist(bool x) {
01262     set_option(x, &persist_blink_blacklist_);
01263   }
01264 
01265   bool preserve_url_relativity() const {
01266     return preserve_url_relativity_.value();
01267   }
01268   void set_preserve_url_relativity(bool x) {
01269     set_option(x, &preserve_url_relativity_);
01270   }
01271 
01272   bool use_image_scanline_api() const {
01273     return use_image_scanline_api_.value();
01274   }
01275   void set_use_image_scanline_api(bool x) {
01276     set_option(x, &use_image_scanline_api_);
01277   }
01278 
01282   bool IsUrlCacheValid(StringPiece url, int64 time_ms) const;
01283 
01287   bool IsUrlPurged(StringPiece url, int64 time_ms) const;
01288 
01305   void AddUrlCacheInvalidationEntry(StringPiece url_pattern,
01306                                     int64 timestamp_ms,
01307                                     bool ignores_metadata_and_pcache);
01308 
01310   void PurgeUrl(StringPiece url, int64 timestamp_ms);
01311 
01314   bool IsUrlCacheInvalidationEntriesSorted() const;
01315 
01318   void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock* lock) {
01319     cache_invalidation_timestamp_.set_mutex(lock);
01320   }
01321 
01323   int64 cache_invalidation_timestamp() const {
01324     ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex());
01325     return cache_invalidation_timestamp_.value();
01326   }
01327 
01334   void set_cache_invalidation_timestamp(int64 timestamp_ms) {
01335     cache_invalidation_timestamp_.mutex()->DCheckLocked();
01336     DCHECK_LT(0, timestamp_ms);
01337     set_option(timestamp_ms, &cache_invalidation_timestamp_);
01338   }
01339 
01346   bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms);
01347 
01350   int64 idle_flush_time_ms() const {
01351     return idle_flush_time_ms_.value();
01352   }
01353   void set_idle_flush_time_ms(int64 x) {
01354     set_option(x, &idle_flush_time_ms_);
01355   }
01356 
01358   int64 flush_buffer_limit_bytes() const {
01359     return flush_buffer_limit_bytes_.value();
01360   }
01361 
01362   void set_flush_buffer_limit_bytes(int64 x) {
01363     set_option(x, &flush_buffer_limit_bytes_);
01364   }
01365 
01368   int max_url_segment_size() const { return max_url_segment_size_.value(); }
01369   void set_max_url_segment_size(int x) {
01370     set_option(x, &max_url_segment_size_);
01371   }
01372 
01373   int image_max_rewrites_at_once() const {
01374     return image_max_rewrites_at_once_.value();
01375   }
01376   void set_image_max_rewrites_at_once(int x) {
01377     set_option(x, &image_max_rewrites_at_once_);
01378   }
01379 
01381   int max_url_size() const { return max_url_size_.value(); }
01382   void set_max_url_size(int x) {
01383     set_option(x, &max_url_size_);
01384   }
01385 
01386   int rewrite_deadline_ms() const { return rewrite_deadline_ms_.value(); }
01387   void set_rewrite_deadline_ms(int x) {
01388     set_option(x, &rewrite_deadline_ms_);
01389   }
01390 
01391   bool test_instant_fetch_rewrite_deadline() const {
01392     return test_instant_fetch_rewrite_deadline_.value();
01393   }
01394   void set_test_instant_fetch_rewrite_deadline(bool x) {
01395     set_option(x, &test_instant_fetch_rewrite_deadline_);
01396   }
01397 
01398   void set_test_only_prioritize_critical_css_dont_apply_original_css(bool x) {
01399     set_option(x, &test_only_prioritize_critical_css_dont_apply_original_css_);
01400   }
01401   bool test_only_prioritize_critical_css_dont_apply_original_css() const {
01402     return test_only_prioritize_critical_css_dont_apply_original_css_.value();
01403   }
01404 
01405   int domain_shard_count() const { return domain_shard_count_.value(); }
01408   void set_domain_shard_count(int64 x) {
01409     int value = x;
01410     set_option(value, &domain_shard_count_);
01411   }
01412 
01413   void set_enabled(EnabledEnum x) {
01414     set_option(x, &enabled_);
01415   }
01416   bool enabled() const {
01417     return enabled_.value() == kEnabledOn;
01418   }
01419   bool unplugged() const {
01420     return enabled_.value() == kEnabledUnplugged;
01421   }
01422 
01423   void set_add_options_to_urls(bool x) {
01424     set_option(x, &add_options_to_urls_);
01425   }
01426 
01427   bool add_options_to_urls() const {
01428     return add_options_to_urls_.value();
01429   }
01430 
01431   void set_in_place_rewriting_enabled(bool x) {
01432     set_option(x, &in_place_rewriting_enabled_);
01433   }
01434 
01435   void set_oblivious_pagespeed_urls(bool x) {
01436     set_option(x, &oblivious_pagespeed_urls_);
01437   }
01438 
01439   bool oblivious_pagespeed_urls() const {
01440     return oblivious_pagespeed_urls_.value();
01441   }
01442 
01443   bool in_place_rewriting_enabled() const {
01444     return in_place_rewriting_enabled_.value();
01445   }
01446 
01447   void set_in_place_wait_for_optimized(bool x) {
01448     set_option(x, &in_place_wait_for_optimized_);
01449   }
01450 
01451   bool in_place_wait_for_optimized() const {
01452     return in_place_wait_for_optimized_.value();
01453   }
01454 
01455   void set_in_place_rewrite_deadline_ms(int x) {
01456     set_option(x, &in_place_rewrite_deadline_ms_);
01457   }
01458 
01459   int in_place_rewrite_deadline_ms() const {
01460     return in_place_rewrite_deadline_ms_.value();
01461   }
01462 
01463   void set_in_place_preemptive_rewrite_css(bool x) {
01464     set_option(x, &in_place_preemptive_rewrite_css_);
01465   }
01466   bool in_place_preemptive_rewrite_css() const {
01467     return in_place_preemptive_rewrite_css_.value();
01468   }
01469 
01470   void set_in_place_preemptive_rewrite_css_images(bool x) {
01471     set_option(x, &in_place_preemptive_rewrite_css_images_);
01472   }
01473   bool in_place_preemptive_rewrite_css_images() const {
01474     return in_place_preemptive_rewrite_css_images_.value();
01475   }
01476 
01477   void set_in_place_preemptive_rewrite_images(bool x) {
01478     set_option(x, &in_place_preemptive_rewrite_images_);
01479   }
01480   bool in_place_preemptive_rewrite_images() const {
01481     return in_place_preemptive_rewrite_images_.value();
01482   }
01483 
01484   void set_in_place_preemptive_rewrite_javascript(bool x) {
01485     set_option(x, &in_place_preemptive_rewrite_javascript_);
01486   }
01487   bool in_place_preemptive_rewrite_javascript() const {
01488     return in_place_preemptive_rewrite_javascript_.value();
01489   }
01490 
01491   void set_combine_across_paths(bool x) {
01492     set_option(x, &combine_across_paths_);
01493   }
01494   bool combine_across_paths() const { return combine_across_paths_.value(); }
01495 
01496   void set_log_background_rewrites(bool x) {
01497     set_option(x, &log_background_rewrites_);
01498   }
01499   bool log_background_rewrites() const {
01500     return log_background_rewrites_.value();
01501   }
01502 
01503   void set_log_rewrite_timing(bool x) {
01504     set_option(x, &log_rewrite_timing_);
01505   }
01506   bool log_rewrite_timing() const { return log_rewrite_timing_.value(); }
01507 
01508   void set_log_url_indices(bool x) {
01509     set_option(x, &log_url_indices_);
01510   }
01511   bool log_url_indices() const { return log_url_indices_.value(); }
01512 
01513   void set_lowercase_html_names(bool x) {
01514     set_option(x, &lowercase_html_names_);
01515   }
01516   bool lowercase_html_names() const { return lowercase_html_names_.value(); }
01517 
01518   void set_always_rewrite_css(bool x) {
01519     set_option(x, &always_rewrite_css_);
01520   }
01521   bool always_rewrite_css() const { return always_rewrite_css_.value(); }
01522 
01523   void set_respect_vary(bool x) {
01524     set_option(x, &respect_vary_);
01525   }
01526   bool respect_vary() const { return respect_vary_.value(); }
01527 
01528   void set_respect_x_forwarded_proto(bool x) {
01529     set_option(x, &respect_x_forwarded_proto_);
01530   }
01531   bool respect_x_forwarded_proto() const {
01532     return respect_x_forwarded_proto_.value();
01533   }
01534 
01535   void set_flush_html(bool x) { set_option(x, &flush_html_); }
01536   bool flush_html() const { return flush_html_.value(); }
01537 
01538   void set_serve_split_html_in_two_chunks(bool x) {
01539     set_option(x, &serve_split_html_in_two_chunks_);
01540   }
01541   bool serve_split_html_in_two_chunks() const {
01542     return serve_split_html_in_two_chunks_.value();
01543   }
01544 
01545   void set_serve_stale_if_fetch_error(bool x) {
01546     set_option(x, &serve_stale_if_fetch_error_);
01547   }
01548   bool serve_stale_if_fetch_error() const {
01549     return serve_stale_if_fetch_error_.value();
01550   }
01551 
01552   void set_serve_ghost_click_buster_with_split_html(bool x) {
01553     set_option(x, &serve_ghost_click_buster_with_split_html_);
01554   }
01555   bool serve_ghost_click_buster_with_split_html() const {
01556     return serve_ghost_click_buster_with_split_html_.value();
01557   }
01558 
01559   void set_serve_xhr_access_control_headers(bool x) {
01560     set_option(x, &serve_xhr_access_control_headers_);
01561   }
01562   bool serve_xhr_access_control_headers() const {
01563     return serve_xhr_access_control_headers_.value();
01564   }
01565 
01566   void set_proactively_freshen_user_facing_request(bool x) {
01567     set_option(x, &proactively_freshen_user_facing_request_);
01568   }
01569   bool proactively_freshen_user_facing_request() const {
01570     return proactively_freshen_user_facing_request_.value();
01571   }
01572 
01573   void set_serve_stale_while_revalidate_threshold_sec(int64 x) {
01574     set_option(x, &serve_stale_while_revalidate_threshold_sec_);
01575   }
01576   int64 serve_stale_while_revalidate_threshold_sec() const {
01577     return serve_stale_while_revalidate_threshold_sec_.value();
01578   }
01579 
01580   void set_enable_flush_early_critical_css(bool x) {
01581     set_option(x, &enable_flush_early_critical_css_);
01582   }
01583   bool enable_flush_early_critical_css() const {
01584     return enable_flush_early_critical_css_.value();
01585   }
01586 
01587   void set_use_selectors_for_critical_css(bool x) {
01588     set_option(x, &use_selectors_for_critical_css_);
01589   }
01590   bool use_selectors_for_critical_css() const {
01591     return use_selectors_for_critical_css_.value();
01592   }
01593 
01594   void set_default_cache_html(bool x) { set_option(x, &default_cache_html_); }
01595   bool default_cache_html() const { return default_cache_html_.value(); }
01596 
01597   void set_modify_caching_headers(bool x) {
01598     set_option(x, &modify_caching_headers_);
01599   }
01600   bool modify_caching_headers() const {
01601     return modify_caching_headers_.value();
01602   }
01603 
01604   void set_inline_only_critical_images(bool x) {
01605     set_option(x, &inline_only_critical_images_);
01606   }
01607   bool inline_only_critical_images() const {
01608     return inline_only_critical_images_.value();
01609   }
01610 
01611   void set_critical_images_beacon_enabled(bool x) {
01612     set_option(x, &critical_images_beacon_enabled_);
01613   }
01614   bool critical_images_beacon_enabled() const {
01615     return critical_images_beacon_enabled_.value();
01616   }
01617 
01618   void set_beacon_reinstrument_beacon_time_sec(int x) {
01619     set_option(x, &beacon_reinstrument_time_sec_);
01620   }
01621   int beacon_reinstrument_time_sec() const {
01622     return beacon_reinstrument_time_sec_.value();
01623   }
01624 
01625   void set_lazyload_images_after_onload(bool x) {
01626     set_option(x, &lazyload_images_after_onload_);
01627   }
01628   bool lazyload_images_after_onload() const {
01629     return lazyload_images_after_onload_.value();
01630   }
01631 
01632   void set_lazyload_images_blank_url(const StringPiece& p) {
01633     set_option(GoogleString(p.data(), p.size()), &lazyload_images_blank_url_);
01634   }
01635   const GoogleString& lazyload_images_blank_url() const {
01636     return lazyload_images_blank_url_.value();
01637   }
01638 
01639   void set_max_inlined_preview_images_index(int x) {
01640     set_option(x, &max_inlined_preview_images_index_);
01641   }
01642   int max_inlined_preview_images_index() const {
01643     return max_inlined_preview_images_index_.value();
01644   }
01645 
01646   void set_use_blank_image_for_inline_preview(bool x) {
01647     set_option(x, &use_blank_image_for_inline_preview_);
01648   }
01649   bool use_blank_image_for_inline_preview() const {
01650     return use_blank_image_for_inline_preview_.value();
01651   }
01652 
01653   void set_min_image_size_low_resolution_bytes(int64 x) {
01654     set_option(x, &min_image_size_low_resolution_bytes_);
01655   }
01656   int64 min_image_size_low_resolution_bytes() const {
01657     return min_image_size_low_resolution_bytes_.value();
01658   }
01659 
01660   void set_max_image_size_low_resolution_bytes(int64 x) {
01661     set_option(x, &max_image_size_low_resolution_bytes_);
01662   }
01663   int64 max_image_size_low_resolution_bytes() const {
01664     return max_image_size_low_resolution_bytes_.value();
01665   }
01666 
01667   void set_experiment_cookie_duration_ms(int64 x) {
01668     set_option(x, &experiment_cookie_duration_ms_);
01669   }
01670   int64 experiment_cookie_duration_ms() const {
01671     return experiment_cookie_duration_ms_.value();
01672   }
01673 
01674   void set_finder_properties_cache_expiration_time_ms(int64 x) {
01675     set_option(x, &finder_properties_cache_expiration_time_ms_);
01676   }
01677   int64 finder_properties_cache_expiration_time_ms() const {
01678     return finder_properties_cache_expiration_time_ms_.value();
01679   }
01680 
01681   void set_finder_properties_cache_refresh_time_ms(int64 x) {
01682     set_option(x, &finder_properties_cache_refresh_time_ms_);
01683   }
01684   int64 finder_properties_cache_refresh_time_ms() const {
01685     return finder_properties_cache_refresh_time_ms_.value();
01686   }
01687 
01688   void set_rewrite_random_drop_percentage(int x) {
01689     set_option(x, &rewrite_random_drop_percentage_);
01690   }
01691   int rewrite_random_drop_percentage() const {
01692     return rewrite_random_drop_percentage_.value();
01693   }
01694 
01695   bool css_preserve_urls() const {
01696     return css_preserve_urls_.value();
01697   }
01698   void set_css_preserve_urls(bool x) {
01699     set_option(x, &css_preserve_urls_);
01700   }
01701 
01702   bool image_preserve_urls() const {
01703     return image_preserve_urls_.value();
01704   }
01705   void set_image_preserve_urls(bool x) {
01706     set_option(x, &image_preserve_urls_);
01707   }
01708 
01709   bool js_preserve_urls() const {
01710     return js_preserve_urls_.value();
01711   }
01712   void set_js_preserve_urls(bool x) {
01713     set_option(x, &js_preserve_urls_);
01714   }
01715 
01716   bool rewrite_request_urls_early() const {
01717     return rewrite_request_urls_early_.value();
01718   }
01719   void set_rewrite_request_urls_early(bool x) {
01720     set_option(x, &rewrite_request_urls_early_);
01721   }
01722 
01723   void set_metadata_cache_staleness_threshold_ms(int64 x) {
01724     set_option(x, &metadata_cache_staleness_threshold_ms_);
01725   }
01726   int64 metadata_cache_staleness_threshold_ms() const {
01727     return metadata_cache_staleness_threshold_ms_.value();
01728   }
01729 
01730   void set_metadata_input_errors_cache_ttl_ms(int64 x) {
01731     set_option(x, &metadata_input_errors_cache_ttl_ms_);
01732   }
01733   int64 metadata_input_errors_cache_ttl_ms() const {
01734     return metadata_input_errors_cache_ttl_ms_.value();
01735   }
01736 
01737   const GoogleString& downstream_cache_purge_method() const {
01738     return downstream_cache_purge_method_.value();
01739   }
01740   void set_downstream_cache_purge_method(const StringPiece& p) {
01741     set_option(p.as_string(), &downstream_cache_purge_method_);
01742   }
01743 
01744   const GoogleString& downstream_cache_purge_location_prefix() const {
01745     return downstream_cache_purge_location_prefix_.value();
01746   }
01747   void set_downstream_cache_purge_location_prefix(const StringPiece& p) {
01748     set_option(p.as_string(), &downstream_cache_purge_location_prefix_);
01749   }
01750 
01751   void set_downstream_cache_rewritten_percentage_threshold(int64 x) {
01752     set_option(x, &downstream_cache_rewritten_percentage_threshold_);
01753   }
01754   int64 downstream_cache_rewritten_percentage_threshold() const {
01755     return downstream_cache_rewritten_percentage_threshold_.value();
01756   }
01757 
01758   const BeaconUrl& beacon_url() const { return beacon_url_.value(); }
01759   void set_beacon_url(const GoogleString& beacon_url) {
01760     beacon_url_.SetFromString(beacon_url);
01761   }
01762 
01764   virtual bool trim_urls_in_css() const { return true; }
01765 
01766   int64 image_jpeg_recompress_quality() const {
01767     return image_jpeg_recompress_quality_.value();
01768   }
01769   void set_image_jpeg_recompress_quality(int64 x) {
01770     set_option(x, &image_jpeg_recompress_quality_);
01771   }
01772 
01773   int64 image_jpeg_recompress_quality_for_small_screens() const {
01774     return image_jpeg_recompress_quality_for_small_screens_.value();
01775   }
01776   void set_image_jpeg_recompress_quality_for_small_screens(int64 x) {
01777     set_option(x, &image_jpeg_recompress_quality_for_small_screens_);
01778   }
01779 
01780   int64 image_recompress_quality() const {
01781     return image_recompress_quality_.value();
01782   }
01783   void set_image_recompress_quality(int64 x) {
01784     set_option(x, &image_recompress_quality_);
01785   }
01786 
01787   int image_limit_optimized_percent() const {
01788     return image_limit_optimized_percent_.value();
01789   }
01790   void set_image_limit_optimized_percent(int x) {
01791     set_option(x, &image_limit_optimized_percent_);
01792   }
01793   int image_limit_resize_area_percent() const {
01794     return image_limit_resize_area_percent_.value();
01795   }
01796   void set_image_limit_resize_area_percent(int x) {
01797     set_option(x, &image_limit_resize_area_percent_);
01798   }
01799 
01800   int image_limit_rendered_area_percent() const {
01801     return image_limit_rendered_area_percent_.value();
01802   }
01803   void set_image_limit_rendered_area_percent(int x) {
01804     set_option(x, &image_limit_rendered_area_percent_);
01805   }
01806 
01807   int64 image_jpeg_num_progressive_scans() const {
01808     return image_jpeg_num_progressive_scans_.value();
01809   }
01810   void set_image_jpeg_num_progressive_scans(int64 x) {
01811     set_option(x, &image_jpeg_num_progressive_scans_);
01812   }
01813 
01814   int64 image_jpeg_num_progressive_scans_for_small_screens() const {
01815     return image_jpeg_num_progressive_scans_for_small_screens_.value();
01816   }
01817   void set_image_jpeg_num_progressive_scans_for_small_screens(int64 x) {
01818     set_option(x, &image_jpeg_num_progressive_scans_for_small_screens_);
01819   }
01820 
01821   int64 image_webp_recompress_quality() const {
01822     return image_webp_recompress_quality_.value();
01823   }
01824   void set_image_webp_recompress_quality(int64 x) {
01825     set_option(x, &image_webp_recompress_quality_);
01826   }
01827 
01828   int64 image_webp_recompress_quality_for_small_screens() const {
01829     return image_webp_recompress_quality_for_small_screens_.value();
01830   }
01831   void set_image_webp_recompress_quality_for_small_screens(int64 x) {
01832     set_option(x, &image_webp_recompress_quality_for_small_screens_);
01833   }
01834   int64 image_webp_timeout_ms() const {
01835     return image_webp_timeout_ms_.value();
01836   }
01837   void set_image_webp_timeout_ms(int64 x) {
01838     set_option(x, &image_webp_timeout_ms_);
01839   }
01840 
01841   bool domain_rewrite_hyperlinks() const {
01842     return domain_rewrite_hyperlinks_.value();
01843   }
01844   void set_domain_rewrite_hyperlinks(bool x) {
01845     set_option(x, &domain_rewrite_hyperlinks_);
01846   }
01847 
01848   bool client_domain_rewrite() const {
01849     return client_domain_rewrite_.value();
01850   }
01851   void set_client_domain_rewrite(bool x) {
01852     set_option(x, &client_domain_rewrite_);
01853   }
01854 
01855   void set_flush_more_resources_early_if_time_permits(bool x) {
01856     set_option(x, &flush_more_resources_early_if_time_permits_);
01857   }
01858   bool flush_more_resources_early_if_time_permits() const {
01859     return flush_more_resources_early_if_time_permits_.value();
01860   }
01861 
01862   void set_flush_more_resources_in_ie_and_firefox(bool x) {
01863     set_option(x, &flush_more_resources_in_ie_and_firefox_);
01864   }
01865   bool flush_more_resources_in_ie_and_firefox() const {
01866     return flush_more_resources_in_ie_and_firefox_.value();
01867   }
01868 
01869   void set_max_prefetch_js_elements(int x) {
01870     set_option(x, &max_prefetch_js_elements_);
01871   }
01872   int max_prefetch_js_elements() const {
01873     return max_prefetch_js_elements_.value();
01874   }
01875 
01876   void set_enable_defer_js_experimental(bool x) {
01877     set_option(x, &enable_defer_js_experimental_);
01878   }
01879   bool enable_defer_js_experimental() const {
01880     return enable_defer_js_experimental_.value();
01881   }
01882 
01883   void set_disable_rewrite_on_no_transform(bool x) {
01884     set_option(x, &disable_rewrite_on_no_transform_);
01885   }
01886   bool disable_rewrite_on_no_transform() const {
01887     return disable_rewrite_on_no_transform_.value();
01888   }
01889 
01890   void set_disable_background_fetches_for_bots(bool x) {
01891     set_option(x, &disable_background_fetches_for_bots_);
01892   }
01893   bool disable_background_fetches_for_bots() const {
01894     return disable_background_fetches_for_bots_.value();
01895   }
01896 
01897   void set_enable_cache_purge(bool x) {
01898     set_option(x, &enable_cache_purge_);
01899   }
01900   bool enable_cache_purge() const {
01901     return enable_cache_purge_.value();
01902   }
01903 
01904   void set_proactive_resource_freshening(bool x) {
01905     set_option(x, &proactive_resource_freshening_);
01906   }
01907   bool proactive_resource_freshening() const {
01908     return proactive_resource_freshening_.value();
01909   }
01910 
01911   void set_lazyload_highres_images(bool x) {
01912     set_option(x, &lazyload_highres_images_);
01913   }
01914   bool lazyload_highres_images() const {
01915     return lazyload_highres_images_.value();
01916   }
01917 
01918   void set_enable_blink_debug_dashboard(bool x) {
01919     set_option(x, &enable_blink_debug_dashboard_);
01920   }
01921   bool enable_blink_debug_dashboard() const {
01922     return enable_blink_debug_dashboard_.value();
01923   }
01924 
01925   void set_enable_blink_html_change_detection(bool x) {
01926     set_option(x, &enable_blink_html_change_detection_);
01927   }
01928   bool enable_blink_html_change_detection() const {
01929     return enable_blink_html_change_detection_.value();
01930   }
01931 
01932   void set_enable_blink_html_change_detection_logging(bool x) {
01933     set_option(x, &enable_blink_html_change_detection_logging_);
01934   }
01935   bool enable_blink_html_change_detection_logging() const {
01936     return enable_blink_html_change_detection_logging_.value();
01937   }
01938 
01939   void set_use_smart_diff_in_blink(bool x) {
01940     set_option(x, &use_smart_diff_in_blink_);
01941   }
01942   bool use_smart_diff_in_blink() const {
01943     return use_smart_diff_in_blink_.value();
01944   }
01945 
01946   void set_use_fallback_property_cache_values(bool x) {
01947     set_option(x, &use_fallback_property_cache_values_);
01948   }
01949   bool use_fallback_property_cache_values() const {
01950     return use_fallback_property_cache_values_.value();
01951   }
01952 
01953   void set_await_pcache_lookup(bool x) {
01954     set_option(x, &await_pcache_lookup_);
01955   }
01956   bool await_pcache_lookup() const {
01957     return await_pcache_lookup_.value();
01958   }
01959 
01960   void set_enable_prioritizing_scripts(bool x) {
01961     set_option(x, &enable_prioritizing_scripts_);
01962   }
01963   bool enable_prioritizing_scripts() const {
01964     return enable_prioritizing_scripts_.value();
01965   }
01966 
01967   void set_blink_html_change_detection_time_ms(int64 x) {
01968     set_option(x, &blink_html_change_detection_time_ms_);
01969   }
01970   int64 blink_html_change_detection_time_ms() const {
01971     return blink_html_change_detection_time_ms_.value();
01972   }
01973 
01974   const GoogleString& blocking_rewrite_key() const {
01975     return blocking_rewrite_key_.value();
01976   }
01977   void set_blocking_rewrite_key(const StringPiece& p) {
01978     set_option(p.as_string(), &blocking_rewrite_key_);
01979   }
01980 
01981   void EnableBlockingRewriteForRefererUrlPattern(
01982       const StringPiece& url_pattern) {
01983     Modify();
01984     blocking_rewrite_referer_urls_.Allow(url_pattern);
01985   }
01986 
01987   bool IsBlockingRewriteEnabledForReferer(const StringPiece& url) const {
01988     return blocking_rewrite_referer_urls_.Match(url, false);
01989   }
01990 
01991   bool IsBlockingRewriteRefererUrlPatternPresent() const {
01992     return blocking_rewrite_referer_urls_.num_wildcards() > 0;
01993   }
01994 
01995   bool rewrite_uncacheable_resources() const {
01996     return rewrite_uncacheable_resources_.value();
01997   }
01998 
01999   void set_rewrite_uncacheable_resources(bool x) {
02000     set_option(x, &rewrite_uncacheable_resources_);
02001   }
02002 
02003   void set_running_experiment(bool x) {
02004     set_option(x, &running_experiment_);
02005   }
02006   bool running_experiment() const {
02007     return running_experiment_.value();
02008   }
02009 
02011   void set_experiment_ga_slot(int x) {
02012     set_option(x, &experiment_ga_slot_);
02013   }
02014 
02015   int experiment_ga_slot() const { return experiment_ga_slot_.value(); }
02016 
02017   void set_report_unload_time(bool x) {
02018     set_option(x, &report_unload_time_);
02019   }
02020   bool report_unload_time() const {
02021     return report_unload_time_.value();
02022   }
02023 
02024   void set_implicit_cache_ttl_ms(int64 x) {
02025     set_option(x, &implicit_cache_ttl_ms_);
02026   }
02027   int64 implicit_cache_ttl_ms() const {
02028     return implicit_cache_ttl_ms_.value();
02029   }
02030 
02031   void set_x_header_value(const StringPiece& p) {
02032     set_option(p.as_string(), &x_header_value_);
02033   }
02034   const GoogleString& x_header_value() const {
02035     return x_header_value_.value();
02036   }
02037 
02038   void set_distributed_rewrite_key(const StringPiece& p) {
02039       set_option(p.as_string(), &distributed_rewrite_key_);
02040   }
02041   const GoogleString& distributed_rewrite_key() const {
02042     return distributed_rewrite_key_.value();
02043   }
02044 
02045   void set_distribute_fetches(bool x) {
02046     set_option(x, &distribute_fetches_);
02047   }
02048   bool distribute_fetches() const {
02049     return distribute_fetches_.value();
02050   }
02051 
02052   void set_distributed_rewrite_servers(const StringPiece& p) {
02053       set_option(p.as_string(), &distributed_rewrite_servers_);
02054   }
02055   const GoogleString& distributed_rewrite_servers() const {
02056     return distributed_rewrite_servers_.value();
02057   }
02058 
02059   void set_distributed_rewrite_timeout_ms(const int64 x) {
02060     set_option(x, &distributed_rewrite_timeout_ms_);
02061   }
02062   int64 distributed_rewrite_timeout_ms() const {
02063     return distributed_rewrite_timeout_ms_.value();
02064   }
02065 
02066   void set_avoid_renaming_introspective_javascript(bool x) {
02067     set_option(x, &avoid_renaming_introspective_javascript_);
02068   }
02069   bool avoid_renaming_introspective_javascript() const {
02070     return avoid_renaming_introspective_javascript_.value();
02071   }
02072 
02073   int64 blink_max_html_size_rewritable() const {
02074     return blink_max_html_size_rewritable_.value();
02075   }
02076   void set_blink_max_html_size_rewritable(int64 x) {
02077     set_option(x, &blink_max_html_size_rewritable_);
02078   }
02079 
02080   void set_critical_line_config(const StringPiece& p) {
02081       set_option(GoogleString(p.data(), p.size()), &critical_line_config_);
02082   }
02083   const GoogleString& critical_line_config() const {
02084     return critical_line_config_.value();
02085   }
02086 
02087   void set_forbid_all_disabled_filters(bool x) {
02088     set_option(x, &forbid_all_disabled_filters_);
02089   }
02090   bool forbid_all_disabled_filters() const {
02091     return forbid_all_disabled_filters_.value();
02092   }
02093 
02094   bool reject_blacklisted() const { return reject_blacklisted_.value(); }
02095   void set_reject_blacklisted(bool x) {
02096     set_option(x, &reject_blacklisted_);
02097   }
02098 
02099   HttpStatus::Code reject_blacklisted_status_code() const {
02100     return static_cast<HttpStatus::Code>(
02101         reject_blacklisted_status_code_.value());
02102   }
02103   void set_reject_blacklisted_status_code(HttpStatus::Code x) {
02104     set_option(static_cast<int>(x), &reject_blacklisted_status_code_);
02105   }
02106 
02107   bool support_noscript_enabled() const {
02108     return support_noscript_enabled_.value();
02109   }
02110   void set_support_noscript_enabled(bool x) {
02111     set_option(x, &support_noscript_enabled_);
02112   }
02113 
02114   bool enable_extended_instrumentation() const {
02115     return enable_extended_instrumentation_.value();
02116   }
02117   void set_enable_extended_instrumentation(bool x) {
02118     set_option(x, &enable_extended_instrumentation_);
02119   }
02120 
02121   void set_max_combined_css_bytes(int64 x) {
02122     set_option(x, &max_combined_css_bytes_);
02123   }
02124   int64 max_combined_css_bytes() const {
02125     return max_combined_css_bytes_.value();
02126   }
02127 
02128   void set_max_combined_js_bytes(int64 x) {
02129     set_option(x, &max_combined_js_bytes_);
02130   }
02131   int64 max_combined_js_bytes() const {
02132     return max_combined_js_bytes_.value();
02133   }
02134 
02135   void set_pre_connect_url(const StringPiece& p) {
02136     set_option(GoogleString(p.data(), p.size()), &pre_connect_url_);
02137   }
02138   const GoogleString& pre_connect_url() const {
02139     return pre_connect_url_.value();
02140   }
02141   void set_property_cache_http_status_stability_threshold(int x) {
02142     set_option(x, &property_cache_http_status_stability_threshold_);
02143   }
02144   int property_cache_http_status_stability_threshold() const {
02145     return property_cache_http_status_stability_threshold_.value();
02146   }
02147 
02148   void set_max_rewrite_info_log_size(int x) {
02149     set_option(x, &max_rewrite_info_log_size_);
02150   }
02151   int max_rewrite_info_log_size() const {
02152     return max_rewrite_info_log_size_.value();
02153   }
02154 
02155   void set_enable_aggressive_rewriters_for_mobile(bool x) {
02156     set_option(x, &enable_aggressive_rewriters_for_mobile_);
02157   }
02158   bool enable_aggressive_rewriters_for_mobile() const {
02159     return enable_aggressive_rewriters_for_mobile_.value();
02160   }
02161 
02162   void set_allow_logging_urls_in_log_record(bool x) {
02163     set_option(x, &allow_logging_urls_in_log_record_);
02164   }
02165   bool allow_logging_urls_in_log_record() const {
02166     return allow_logging_urls_in_log_record_.value();
02167   }
02168 
02169   void set_non_cacheables_for_cache_partial_html(const StringPiece& p) {
02170     set_option(p.as_string(), &non_cacheables_for_cache_partial_html_);
02171   }
02172   const GoogleString& non_cacheables_for_cache_partial_html() const {
02173     return non_cacheables_for_cache_partial_html_.value();
02174   }
02175 
02176   void set_access_control_allow_origins(const StringPiece& p) {
02177     set_option(p.as_string(), &access_control_allow_origins_);
02178   }
02179   const GoogleString& access_control_allow_origins() const {
02180     return access_control_allow_origins_.value();
02181   }
02182 
02183   void set_hide_referer_using_meta(bool x) {
02184     set_option(x, &hide_referer_using_meta_);
02185   }
02186   bool hide_referer_using_meta() const {
02187     return hide_referer_using_meta_.value();
02188   }
02189 
02190   void set_max_low_res_image_size_bytes(int64 x) {
02191     set_option(x, &max_low_res_image_size_bytes_);
02192   }
02193   int64 max_low_res_image_size_bytes() const {
02194     return max_low_res_image_size_bytes_.value();
02195   }
02196 
02197   void set_max_low_res_to_full_res_image_size_percentage(int x) {
02198     set_option(x, &max_low_res_to_full_res_image_size_percentage_);
02199   }
02200   int max_low_res_to_full_res_image_size_percentage() const {
02201     return max_low_res_to_full_res_image_size_percentage_.value();
02202   }
02203 
02219   virtual void Merge(const RewriteOptions& src);
02220 
02223   void Allow(const StringPiece& wildcard_pattern) {
02224     Modify();
02225     allow_resources_.Allow(wildcard_pattern);
02226   }
02227 
02230   void Disallow(const StringPiece& wildcard_pattern) {
02231     Modify();
02232     allow_resources_.Disallow(wildcard_pattern);
02233   }
02234 
02238   virtual void DisallowTroublesomeResources();
02239 
02244   virtual void DisallowResourcesForProxy();
02245 
02266   const DomainLawyer* domain_lawyer() const { return domain_lawyer_.get(); }
02267   DomainLawyer* WriteableDomainLawyer();
02268 
02269   FileLoadPolicy* file_load_policy() { return &file_load_policy_; }
02270   const FileLoadPolicy* file_load_policy() const { return &file_load_policy_; }
02271 
02274   bool IsAllowed(const StringPiece& url) const {
02275     return allow_resources_.Match(url, true);
02276   }
02277 
02279   void RetainComment(const StringPiece& comment) {
02280     Modify();
02281     retain_comments_.Allow(comment);
02282   }
02283 
02287   bool IsRetainedComment(const StringPiece& comment) const {
02288     return retain_comments_.Match(comment, false);
02289   }
02290 
02292   void DisableLazyloadForClassName(const StringPiece& class_name) {
02293     Modify();
02294     lazyload_enabled_classes_.Disallow(class_name);
02295   }
02296 
02298   bool IsLazyloadEnabledForClassName(const StringPiece& class_name) const {
02299     return lazyload_enabled_classes_.Match(class_name, true);
02300   }
02301 
02302   void set_override_caching_ttl_ms(int64 x) {
02303     set_option(x, &override_caching_ttl_ms_);
02304   }
02305   int64 override_caching_ttl_ms() const {
02306     return override_caching_ttl_ms_.value();
02307   }
02308 
02311   void AddOverrideCacheTtl(const StringPiece& wildcard) {
02312     Modify();
02313     override_caching_wildcard_.Allow(wildcard);
02314   }
02315 
02317   bool IsCacheTtlOverridden(const StringPiece& url) const {
02318     return override_caching_wildcard_.Match(url, false);
02319   }
02320 
02321   void AddRejectedUrlWildcard(const GoogleString& wildcard) {
02322     AddRejectedHeaderWildcard(kRejectedRequestUrlKeyName, wildcard);
02323   }
02324 
02325   void AddRejectedHeaderWildcard(const StringPiece& header_name,
02326                                  const GoogleString& wildcard) {
02327     Modify();
02328     std::pair<FastWildcardGroupMap::iterator, bool> insert_result =
02329         rejected_request_map_.insert(std::make_pair(
02330             header_name, static_cast<FastWildcardGroup*>(NULL)));
02331 
02332     if (insert_result.second) {
02333       insert_result.first->second = new FastWildcardGroup;
02334     }
02335     insert_result.first->second->Allow(wildcard);
02336   }
02337 
02338   void set_min_cache_ttl_ms(int64 x) {
02339     set_option(x, &min_cache_ttl_ms_);
02340   }
02341   int64 min_cache_ttl_ms() const {
02342     return min_cache_ttl_ms_.value();
02343   }
02344 
02347   bool IsRequestDeclined(const GoogleString& url,
02348                          const RequestHeaders* request_headers) const;
02349 
02353   virtual RewriteOptions* Clone() const;
02354 
02356   virtual RewriteOptions* NewOptions() const;
02357 
02363   void ComputeSignature();
02364 
02369   void Freeze();
02370 
02377   void ClearSignatureWithCaution();
02378 
02379   bool frozen() const { return frozen_; }
02380 
02384   bool ClearSignatureForTesting() {
02385     bool frozen = frozen_;
02386     ClearSignatureWithCaution();
02387     return frozen;
02388   }
02389 
02391   const GoogleString& signature() const {
02399     ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex());
02400     DCHECK(frozen_);
02401     DCHECK(!signature_.empty());
02402     return signature_;
02403   }
02404 
02405   virtual GoogleString OptionsToString() const;
02406   GoogleString FilterSetToString(const FilterSet& filter_set) const;
02407 
02410   virtual GoogleString ToExperimentString() const;
02411 
02415   virtual GoogleString ToExperimentDebugString() const;
02416 
02419   static Filter LookupFilterById(const StringPiece& filter_id);
02420 
02422   static Filter LookupFilter(const StringPiece& filter_name);
02423 
02426   static const PropertyBase* LookupOptionById(StringPiece option_id);
02427   static const PropertyBase* LookupOptionByName(StringPiece option_name);
02428 
02431   static const StringPiece LookupOptionNameById(StringPiece option_id);
02432 
02434   static bool IsValidOptionName(StringPiece name);
02435 
02438   const OptionBaseVector& all_options() const {
02439     return all_options_;
02440   }
02441 
02445   bool IsEqual(const RewriteOptions& that) const;
02446 
02448   const Hasher* hasher() const { return &hasher_; }
02449 
02450   ThreadSystem* thread_system() const { return thread_system_; }
02451 
02452  protected:
02462   template<class T> class OptionTemplateBase : public OptionBase {
02463    public:
02464     typedef T ValueType;
02465 
02466     OptionTemplateBase() : was_set_(false), property_(NULL) {}
02467 
02468     virtual bool was_set() const { return was_set_; }
02469 
02470     void set(const T& val) {
02471       was_set_ = true;
02472       value_ = val;
02473     }
02474 
02475     void set_default(const T& val) {
02476       if (!was_set_) {
02477         value_ = val;
02478       }
02479     }
02480 
02481     const T& value() const { return value_; }
02482 
02488     virtual void Merge(const OptionBase* src) {
02489       DCHECK(option_name() == src->option_name());
02490       MergeHelper(static_cast<const OptionTemplateBase*>(src));
02491     }
02492 
02493     void MergeHelper(const OptionTemplateBase* src) {
02496       if (src->was_set_ || !was_set_) {
02497         value_ = src->value_;
02498         was_set_ = src->was_set_;
02499       }
02500     }
02501 
02503     void set_property(const Property<T>* property) {
02504       property_ = property;
02505 
02510       value_ = property->default_value();
02511     }
02512     virtual const PropertyBase* property() const { return property_; }
02513 
02522     void set_global_default(const T& val) {
02523       Property<T>* property = const_cast<Property<T>*>(property_);
02524       property->set_default(val);
02525     }
02526 
02535     void DoNotUseForSignatureComputation() {
02536       Property<T>* property = const_cast<Property<T>*>(property_);
02537       property->set_do_not_use_for_signature_computation(true);
02538     }
02539 
02540    private:
02541     bool was_set_;
02542     T value_;
02543     const Property<T>* property_;
02544 
02545     DISALLOW_COPY_AND_ASSIGN(OptionTemplateBase);
02546   };
02547 
02552   template<class T> class Option : public OptionTemplateBase<T> {
02553    public:
02554     Option() {}
02555 
02557     virtual bool SetFromString(const GoogleString& value_string) {
02558       T value;
02559       bool success = RewriteOptions::ParseFromString(value_string, &value);
02560       if (success) {
02561         this->set(value);
02562       }
02563       return success;
02564     }
02565 
02566     virtual GoogleString Signature(const Hasher* hasher) const {
02567       return RewriteOptions::OptionSignature(this->value(), hasher);
02568     }
02569 
02570     virtual GoogleString ToString() const {
02571       return RewriteOptions::ToString(this->value());
02572     }
02573 
02574    private:
02575     DISALLOW_COPY_AND_ASSIGN(Option);
02576   };
02577 
02590   class MutexedOptionInt64MergeWithMax : public Option<int64> {
02591    public:
02592     MutexedOptionInt64MergeWithMax();
02593     virtual ~MutexedOptionInt64MergeWithMax();
02594 
02599     virtual void Merge(const OptionBase* src_base);
02600 
02611     void checked_set(const int64& value) {
02612       mutex_->DCheckLocked();
02613       Option<int64>::set(value);
02614     }
02615 
02629     ThreadSystem::RWLock* mutex() const { return mutex_.get(); }
02630 
02636     void set_mutex(ThreadSystem::RWLock* lock) { mutex_.reset(lock); }
02637 
02638    private:
02639     scoped_ptr<ThreadSystem::RWLock> mutex_;
02640   };
02641 
02642  protected:
02644   template<class RewriteOptionsSubclass, class OptionClass>
02645   static void AddProperty(
02646       typename OptionClass::ValueType default_value,
02647       OptionClass RewriteOptionsSubclass::*offset,
02648       const char* id,
02649       StringPiece option_name,
02650       OptionScope scope,
02651       const char* help_text,
02652       Properties* properties) {
02653     PropertyBase* property =
02654         new PropertyLeaf<RewriteOptionsSubclass, OptionClass>(
02655             default_value, offset, id, option_name);
02656     property->set_scope(scope);
02657     property->set_help_text(help_text);
02658     properties->push_back(property);
02659   }
02660 
02674   static void MergeSubclassProperties(Properties* properties);
02675 
02677   void ForbidFiltersForPreserveUrl();
02678 
02684   void set_option_at(int index, OptionBase* option) {
02685     all_options_[index] = option;
02686   }
02687 
02691   template<class T>
02692   void set_option(const T& new_value, OptionTemplateBase<T>* option) {
02693     option->set(new_value);
02694     Modify();
02695   }
02696 
02698   void Modify();
02699 
02707   void set_default_x_header_value(const StringPiece& x_header_value) {
02708     x_header_value_.set_global_default(x_header_value.as_string());
02709   }
02710 
02714   bool SetupExperimentRewriters();
02715 
02717   virtual void SetRequiredExperimentFilters();
02718 
02722   bool InsertExperimentSpecInVector(ExperimentSpec* spec);
02723 
02725   Option<BeaconUrl> beacon_url_;
02726 
02728   Option<GoogleString> x_header_value_;
02729 
02730  private:
02731   struct OptionIdCompare;
02732 
02735   class PropertyBase {
02736    public:
02737     PropertyBase(const char* id, StringPiece option_name)
02738         : id_(id),
02739           help_text_(NULL),
02740           option_name_(option_name),
02741           scope_(kDirectoryScope),
02742           do_not_use_for_signature_computation_(false),
02743           index_(-1) {
02744     }
02745     virtual ~PropertyBase();
02746 
02749     virtual void InitializeOption(RewriteOptions* options) const = 0;
02750 
02751     void set_do_not_use_for_signature_computation(bool x) {
02752       do_not_use_for_signature_computation_ = x;
02753     }
02754     bool is_used_for_signature_computation() const {
02755       return !do_not_use_for_signature_computation_;
02756     }
02757 
02758     void set_scope(OptionScope x) { scope_ = x; }
02759     OptionScope scope() const { return scope_; }
02760 
02761     void set_help_text(const char* x) { help_text_ = x; }
02762     const char* help_text() const { return help_text_; }
02763 
02764     void set_index(int index) { index_ = index; }
02765     const char* id() const { return id_; }
02766     StringPiece option_name() const { return option_name_; }
02767     int index() const { return index_; }
02768 
02769    private:
02770     const char* id_;
02771     const char* help_text_;
02772     StringPiece option_name_; 
02773     OptionScope scope_;
02774     bool do_not_use_for_signature_computation_; 
02775     int index_;
02776 
02777     DISALLOW_COPY_AND_ASSIGN(PropertyBase);
02778   };
02779 
02783   template<class ValueType>
02784   class Property : public PropertyBase {
02785    public:
02790     Property(ValueType default_value,
02791              const char* id,
02792              StringPiece option_name)
02793         : PropertyBase(id, option_name),
02794           default_value_(default_value) {
02795     }
02796 
02797     void set_default(ValueType value) { default_value_ = value; }
02798     const ValueType& default_value() const { return default_value_; }
02799 
02800    private:
02801     ValueType default_value_;
02802 
02803     DISALLOW_COPY_AND_ASSIGN(Property);
02804   };
02805 
02820   template<class RewriteOptionsSubclass, class OptionClass>
02821   class PropertyLeaf : public Property<typename OptionClass::ValueType> {
02822    public:
02826     typedef OptionClass RewriteOptionsSubclass::*OptionOffset;
02827     typedef typename OptionClass::ValueType ValueType;
02828 
02829     PropertyLeaf(ValueType default_value,
02830                  OptionOffset offset,
02831                  const char* id,
02832                  StringPiece option_name)
02833         : Property<ValueType>(default_value, id, option_name),
02834           offset_(offset) {
02835     }
02836 
02837     virtual void InitializeOption(RewriteOptions* options) const {
02838       RewriteOptionsSubclass* options_subclass =
02839           static_cast<RewriteOptionsSubclass*>(options);
02840       OptionClass& option = options_subclass->*offset_;
02841       option.set_property(this);
02842       DCHECK_NE(-1, this->index()) << "Call Property::set_index first.";
02843       options->set_option_at(this->index(), &option);
02844     }
02845 
02846    private:
02847     OptionOffset offset_;
02848 
02849     DISALLOW_COPY_AND_ASSIGN(PropertyLeaf);
02850   };
02851 
02852   static Properties* properties_; 
02853   static Properties* all_properties_; 
02854 
02855   FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
02856   FRIEND_TEST(RewriteOptionsTest, LookupOptionByNameTest);
02857 
02859   bool HasRejectedHeader(const StringPiece& header_name,
02860                          const RequestHeaders* request_headers) const;
02861 
02862   bool IsRejectedUrl(const GoogleString& url) const {
02863     return IsRejectedRequest(kRejectedRequestUrlKeyName, url);
02864   }
02865 
02866   bool IsRejectedRequest(const StringPiece& header_name,
02867                          const StringPiece& value) const {
02868     FastWildcardGroupMap::const_iterator it = rejected_request_map_.find(
02869         header_name);
02870     if (it != rejected_request_map_.end()) {
02871       return it->second->Match(value, false);
02872     }
02873     return false;
02874   }
02875 
02878   JavascriptLibraryIdentification* WriteableJavascriptLibraryIdentification();
02879 
02886   struct PrioritizeVisibleContentFamily {
02887     PrioritizeVisibleContentFamily(StringPiece url_pattern_string,
02888                                    int64 cache_time_ms_in,
02889                                    StringPiece non_cacheable_elements_in)
02890         : url_pattern(url_pattern_string),
02891           cache_time_ms(cache_time_ms_in),
02892           non_cacheable_elements(non_cacheable_elements_in.data(),
02893                                  non_cacheable_elements_in.size()) {}
02894 
02895     PrioritizeVisibleContentFamily* Clone() const {
02896       return new PrioritizeVisibleContentFamily(
02897           url_pattern.spec(), cache_time_ms, non_cacheable_elements);
02898     }
02899 
02900     GoogleString ComputeSignature() const {
02901       return StrCat(url_pattern.spec(), ";", Integer64ToString(cache_time_ms),
02902                     ";", non_cacheable_elements);
02903     }
02904 
02905     GoogleString ToString() const {
02906       return StrCat("URL pattern: ", url_pattern.spec(), ",  Cache time (ms): ",
02907                     Integer64ToString(cache_time_ms), ",  Non-cacheable: ",
02908                     non_cacheable_elements);
02909     }
02910 
02911     Wildcard url_pattern;
02912     int64 cache_time_ms;
02913     GoogleString non_cacheable_elements;
02914   };
02915 
02918   struct UrlCacheInvalidationEntry {
02919     UrlCacheInvalidationEntry(StringPiece url_pattern_in,
02920                               int64 timestamp_ms_in,
02921                               bool ignores_metadata_and_pcache_in)
02922         : url_pattern(url_pattern_in),
02923           timestamp_ms(timestamp_ms_in),
02924           ignores_metadata_and_pcache(ignores_metadata_and_pcache_in) {}
02925 
02926     UrlCacheInvalidationEntry* Clone() const {
02927       return new UrlCacheInvalidationEntry(
02928           url_pattern.spec(), timestamp_ms, ignores_metadata_and_pcache);
02929     }
02930 
02931     GoogleString ComputeSignature() const {
02932       if (ignores_metadata_and_pcache) {
02933         return "";
02934       }
02935       return StrCat(url_pattern.spec(), "@", Integer64ToString(timestamp_ms));
02936     }
02937 
02938     GoogleString ToString() const {
02939       return StrCat(
02940           url_pattern.spec(), ", ",
02941           (ignores_metadata_and_pcache ? "STRICT" : "REFERENCE"), " @ ",
02942           Integer64ToString(timestamp_ms));
02943     }
02944 
02945     Wildcard url_pattern;
02946     int64 timestamp_ms;
02947     bool ignores_metadata_and_pcache;
02948   };
02949 
02950   typedef std::vector<UrlCacheInvalidationEntry*>
02951       UrlCacheInvalidationEntryVector;
02952   typedef dense_hash_map<GoogleString, int64> UrlCacheInvalidationMap;
02953 
02957   typedef rde::hash_map<StringPiece, const PropertyBase*,
02958                         CaseFoldStringPieceHash,  6,
02959                         CaseFoldStringPieceEqual> PropertyNameMap;
02960 
02973   template<class OptionClass>
02974   static void AddRequestProperty(typename OptionClass::ValueType default_value,
02975                                  OptionClass RewriteOptions::*offset,
02976                                  const char* id) {
02977     AddProperty(default_value, offset, id, kNullOption, kProcessScope,
02978                 NULL, properties_);
02979   }
02980 
02983   template<class OptionClass>
02984   static void AddBaseProperty(typename OptionClass::ValueType default_value,
02985                               OptionClass RewriteOptions::*offset,
02986                               const char* id,
02987                               StringPiece option_name,
02988                               OptionScope scope,
02989                               const char* help) {
02990     AddProperty(default_value, offset, id, option_name, scope, help,
02991                 properties_);
02992   }
02993 
02994   static void AddProperties();
02995   bool AddCommaSeparatedListToFilterSetState(
02996       const StringPiece& filters, FilterSet* set, MessageHandler* handler);
02997   static bool AddCommaSeparatedListToFilterSet(
02998       const StringPiece& filters, FilterSet* set, MessageHandler* handler);
03001   void ResolveConflicts();
03003   static void InitFilterIdToEnumArray();
03004   static void InitOptionIdToPropertyArray();
03005   static void InitOptionNameToPropertyArray();
03006 
03010   OptionSettingResult FormatSetOptionMessage(
03011       OptionSettingResult result, StringPiece name, StringPiece value,
03012       GoogleString* msg);
03013 
03016   static GoogleString OptionSignature(bool x, const Hasher* hasher) {
03017     return x ? "T" : "F";
03018   }
03019   static GoogleString OptionSignature(int x, const Hasher* hasher) {
03020     return IntegerToString(x);
03021   }
03022   static GoogleString OptionSignature(int64 x, const Hasher* hasher) {
03023     return Integer64ToString(x);
03024   }
03025   static GoogleString OptionSignature(const GoogleString& x,
03026                                       const Hasher* hasher);
03027   static GoogleString OptionSignature(RewriteLevel x,
03028                                       const Hasher* hasher);
03029   static GoogleString OptionSignature(const BeaconUrl& beacon_url,
03030                                       const Hasher* hasher);
03031 
03034   static GoogleString ToString(bool x) {
03035     return x ? "True" : "False";
03036   }
03037   static GoogleString ToString(int x) {
03038     return IntegerToString(x);
03039   }
03040   static GoogleString ToString(int64 x) {
03041     return Integer64ToString(x);
03042   }
03043   static GoogleString ToString(const GoogleString& x) {
03044     return x;
03045   }
03046   static GoogleString ToString(RewriteLevel x);
03047   static GoogleString ToString(const BeaconUrl& beacon_url);
03048 
03051   static bool PropertyLessThanByOptionName(PropertyBase* p1, PropertyBase* p2) {
03052     return StringCaseCompare(p1->option_name(), p2->option_name()) < 0;
03053   }
03054 
03056   static bool OptionNameLessThanArg(OptionBase* option, StringPiece arg) {
03057     return StringCaseCompare(option->option_name(), arg) < 0;
03058   }
03059 
03061   static bool CompareUrlCacheInvalidationEntry(UrlCacheInvalidationEntry* e1,
03062                                                UrlCacheInvalidationEntry* e2) {
03063     return e1->timestamp_ms < e2->timestamp_ms;
03064   }
03065 
03067   static bool FilterEnumToIdAndNameEntryLessThanById(
03068       const FilterEnumToIdAndNameEntry* e1,
03069       const FilterEnumToIdAndNameEntry* e2) {
03070     return strcmp(e1->filter_id, e2->filter_id) < 0;
03071   }
03072 
03073   bool modified_;
03074   bool frozen_;
03075   FilterSet enabled_filters_;
03076   FilterSet disabled_filters_;
03077   FilterSet forbidden_filters_;
03078 
03081   FilterIdSet distributable_filters_;
03082 
03088   Option<RewriteLevel> level_;
03089 
03092   UrlCacheInvalidationEntryVector url_cache_invalidation_entries_;
03093 
03095   UrlCacheInvalidationMap url_cache_invalidation_map_;
03096 
03097   MutexedOptionInt64MergeWithMax cache_invalidation_timestamp_;
03098   Option<int64> css_flatten_max_bytes_;
03099   Option<bool> cache_small_images_unrewritten_;
03101   Option<int64> image_resolution_limit_bytes_;
03102   Option<int64> css_image_inline_max_bytes_;
03103   Option<int64> css_inline_max_bytes_;
03104   Option<int64> css_outline_min_bytes_;
03105 
03107   Option<bool> css_preserve_urls_;
03108   Option<bool> js_preserve_urls_;
03109   Option<bool> image_preserve_urls_;
03110 
03113   Option<bool> rewrite_request_urls_early_;
03114 
03115   Option<int64> image_inline_max_bytes_;
03116   Option<int64> js_inline_max_bytes_;
03117   Option<int64> js_outline_min_bytes_;
03118   Option<int64> progressive_jpeg_min_bytes_;
03120   Option<int64> max_html_cache_time_ms_;
03123   Option<int64> max_html_parse_bytes_;
03125   Option<int64> max_image_bytes_for_webp_in_css_;
03127   Option<int64> min_resource_cache_time_to_rewrite_ms_;
03128   Option<int64> idle_flush_time_ms_;
03129   Option<int64> flush_buffer_limit_bytes_;
03130 
03134   Option<int64> blocking_fetch_timeout_ms_;
03135 
03138   Option<int64> image_recompress_quality_;
03139 
03141   Option<int64> image_jpeg_recompress_quality_;
03142   Option<int64> image_jpeg_recompress_quality_for_small_screens_;
03143   Option<int64> image_jpeg_num_progressive_scans_;
03144   Option<int64> image_jpeg_num_progressive_scans_for_small_screens_;
03145 
03147   Option<int> image_limit_optimized_percent_;
03148   Option<int> image_limit_resize_area_percent_;
03149   Option<int> image_limit_rendered_area_percent_;
03150 
03152   Option<int64> image_webp_recompress_quality_;
03153   Option<int64> image_webp_recompress_quality_for_small_screens_;
03154   Option<int64> image_webp_timeout_ms_;
03155 
03156   Option<int> image_max_rewrites_at_once_;
03157   Option<int> max_url_segment_size_; 
03158   Option<int> max_url_size_; 
03159 
03160 
03161   Option<int> rewrite_deadline_ms_;
03163   Option<int> domain_shard_count_;
03164 
03165   Option<EnabledEnum> enabled_;
03166 
03167   Option<bool> distributable_;
03168 
03171   Option<bool> add_options_to_urls_;
03172 
03174   Option<bool> in_place_rewriting_enabled_;
03176   Option<bool> in_place_wait_for_optimized_;
03179   Option<int> in_place_rewrite_deadline_ms_;
03182   Option<bool> in_place_preemptive_rewrite_css_;
03184   Option<bool> in_place_preemptive_rewrite_css_images_;
03187   Option<bool> in_place_preemptive_rewrite_images_;
03190   Option<bool> in_place_preemptive_rewrite_javascript_;
03191   Option<bool> combine_across_paths_;
03192   Option<bool> log_background_rewrites_;
03193   Option<bool> log_rewrite_timing_; 
03194   Option<bool> log_url_indices_;
03195   Option<bool> lowercase_html_names_;
03196   Option<bool> always_rewrite_css_; 
03197   Option<bool> respect_vary_;
03198   Option<bool> respect_x_forwarded_proto_;
03199   Option<bool> flush_html_;
03203   Option<bool> serve_split_html_in_two_chunks_;
03206   Option<bool> serve_stale_if_fetch_error_;
03208   Option<bool> serve_ghost_click_buster_with_split_html_;
03210   Option<bool> serve_xhr_access_control_headers_;
03213   Option<bool> proactively_freshen_user_facing_request_;
03216   Option<int64> serve_stale_while_revalidate_threshold_sec_;
03218   Option<bool> enable_flush_early_critical_css_;
03220   Option<bool> use_selectors_for_critical_css_;
03225   Option<bool> default_cache_html_;
03230   Option<bool> modify_caching_headers_;
03234   Option<bool> lazyload_images_after_onload_;
03237   Option<GoogleString> lazyload_images_blank_url_;
03240   Option<bool> use_blank_image_for_inline_preview_;
03244   Option<bool> inline_only_critical_images_;
03247   Option<bool> critical_images_beacon_enabled_;
03250   Option<bool> client_domain_rewrite_;
03253   Option<bool> domain_rewrite_hyperlinks_;
03256   Option<bool> running_experiment_;
03259   Option<int> experiment_ga_slot_;
03260 
03263   Option<bool> increase_speed_tracking_;
03264 
03268   Option<bool> report_unload_time_;
03269 
03271   Option<bool> flush_more_resources_early_if_time_permits_;
03272 
03274   Option<bool> flush_more_resources_in_ie_and_firefox_;
03275 
03278   Option<int> max_prefetch_js_elements_;
03279 
03281   Option<bool> enable_defer_js_experimental_;
03282 
03284   Option<bool> disable_rewrite_on_no_transform_;
03285 
03287   Option<bool> disable_background_fetches_for_bots_;
03288 
03298   Option<bool> enable_cache_purge_;
03299 
03303   Option<bool> proactive_resource_freshening_;
03304 
03306   Option<bool> lazyload_highres_images_;
03307 
03310   Option<bool> avoid_renaming_introspective_javascript_;
03311 
03313   Option<bool> override_ie_document_mode_;
03314 
03316   Option<bool> test_instant_fetch_rewrite_deadline_;
03317 
03321   Option<bool> test_only_prioritize_critical_css_dont_apply_original_css_;
03322 
03328   Option<GoogleString> blocking_rewrite_key_;
03329 
03333   Option<int> beacon_reinstrument_time_sec_;
03334 
03337   Option<int> max_inlined_preview_images_index_;
03339   Option<int64> min_image_size_low_resolution_bytes_;
03341   Option<int64> max_image_size_low_resolution_bytes_;
03344   Option<int> rewrite_random_drop_percentage_;
03345 
03348   Option<bool> oblivious_pagespeed_urls_;
03349 
03351   Option<int64> finder_properties_cache_expiration_time_ms_;
03352 
03356   Option<int64> finder_properties_cache_refresh_time_ms_;
03359   Option<int64> experiment_cookie_duration_ms_;
03360 
03363   Option<int64> metadata_cache_staleness_threshold_ms_;
03364 
03366   Option<int64> metadata_input_errors_cache_ttl_ms_;
03367 
03370   Option<GoogleString> downstream_cache_purge_method_;
03371 
03373   Option<GoogleString> downstream_cache_purge_location_prefix_;
03374 
03380   Option<int64> downstream_cache_rewritten_percentage_threshold_;
03381 
03385   Option<int64> implicit_cache_ttl_ms_;
03386 
03388   Option<int64> max_cacheable_response_content_length_;
03389 
03391   Option<int64> blink_blacklist_end_timestamp_ms_;
03393   Option<bool> persist_blink_blacklist_;
03394 
03397   Option<bool> preserve_url_relativity_;
03398 
03399   Option<GoogleString> ga_id_;
03400 
03401   Option<int64> blink_max_html_size_rewritable_;
03404   Option<int64> blink_html_change_detection_time_ms_;
03406   Option<bool> enable_blink_debug_dashboard_;
03408   Option<bool> enable_blink_html_change_detection_;
03410   Option<bool> enable_blink_html_change_detection_logging_;
03412   Option<bool> use_smart_diff_in_blink_;
03414   Option<bool> use_fallback_property_cache_values_;
03416   Option<bool> await_pcache_lookup_;
03418   Option<bool> enable_prioritizing_scripts_;
03420   Option<bool> rewrite_uncacheable_resources_;
03422   Option<GoogleString> critical_line_config_;
03425   Option<GoogleString> distributed_rewrite_key_;
03427   Option<GoogleString> distributed_rewrite_servers_;
03432   Option<bool> distribute_fetches_;
03435   Option<int64> distributed_rewrite_timeout_ms_;
03441   Option<bool> forbid_all_disabled_filters_;
03443   Option<bool> enable_aggressive_rewriters_for_mobile_;
03444 
03450   Option<bool> reject_blacklisted_;
03451   Option<int> reject_blacklisted_status_code_;
03452 
03456   Option<bool> support_noscript_enabled_;
03457 
03460   Option<bool> enable_extended_instrumentation_;
03461 
03464   Option<int64> max_combined_css_bytes_;
03465 
03468   Option<int64> max_combined_js_bytes_;
03469 
03471   Option<GoogleString> pre_connect_url_;
03474   Option<int> property_cache_http_status_stability_threshold_;
03476   Option<int> max_rewrite_info_log_size_;
03477 
03482   Option<int64> override_caching_ttl_ms_;
03483   FastWildcardGroup override_caching_wildcard_;
03484 
03488   Option<int64> min_cache_ttl_ms_;
03489 
03491   Option<bool> allow_logging_urls_in_log_record_;
03492 
03494   Option<GoogleString> non_cacheables_for_cache_partial_html_;
03495 
03499   Option<GoogleString> access_control_allow_origins_;
03500 
03502   Option<bool> hide_referer_using_meta_;
03503 
03508   Option<int64> max_low_res_image_size_bytes_;
03509   Option<int> max_low_res_to_full_res_image_size_percentage_;
03510 
03511   Option<bool> use_image_scanline_api_;
03512 
03515   OptionBaseVector all_options_;
03516   size_t initialized_options_; 
03517 
03520   static const FilterEnumToIdAndNameEntry* filter_id_to_enum_array_[
03521       kEndOfFilters];
03522 
03524   static PropertyNameMap* option_name_to_property_map_;
03525 
03527   static const PropertyBase** option_id_to_property_array_;
03528 
03535   bool options_uniqueness_checked_;
03536 
03537   bool need_to_store_experiment_data_;
03538   int experiment_id_; 
03539   int experiment_percent_; 
03540   std::vector<ExperimentSpec*> experiment_specs_;
03541 
03543   std::vector<NameValue*> custom_fetch_headers_;
03544 
03547   scoped_ptr<std::vector<ElementAttributeCategory> > url_valued_attributes_;
03548 
03549   CopyOnWrite<JavascriptLibraryIdentification>
03550       javascript_library_identification_;
03551 
03552   CopyOnWrite<DomainLawyer> domain_lawyer_;
03553   FileLoadPolicy file_load_policy_;
03554 
03555   FastWildcardGroup allow_resources_;
03556   FastWildcardGroup retain_comments_;
03557   FastWildcardGroup lazyload_enabled_classes_;
03560   FastWildcardGroup blocking_rewrite_referer_urls_;
03561 
03564   typedef std::map<StringPiece, FastWildcardGroup*> FastWildcardGroupMap;
03565   FastWildcardGroupMap rejected_request_map_;
03566 
03567   GoogleString signature_;
03568   MD5Hasher hasher_; 
03569 
03570   ThreadSystem* thread_system_;
03571 
03584   scoped_ptr<ThreadSystem::ThreadId> last_thread_id_;
03585 
03586   DISALLOW_COPY_AND_ASSIGN(RewriteOptions);
03587 };
03588 
03589 }  
03590 
03591 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines