Page Speed Optimization Libraries
1.8.31.3
|
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/experiment_util.h" 00033 #include "net/instaweb/rewriter/public/file_load_policy.h" 00034 #include "net/instaweb/rewriter/public/javascript_library_identification.h" 00035 #include "net/instaweb/util/public/basictypes.h" 00036 #include "net/instaweb/util/public/enum_set.h" 00037 #include "net/instaweb/util/public/gtest_prod.h" 00038 #include "net/instaweb/util/public/md5_hasher.h" 00039 #include "net/instaweb/util/public/proto_util.h" 00040 #include "net/instaweb/util/public/scoped_ptr.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.h" 00046 #include "pagespeed/kernel/base/string_hash.h" 00047 #include "pagespeed/kernel/base/string_util.h" 00048 #include "pagespeed/kernel/base/thread_annotations.h" 00049 #include "pagespeed/kernel/base/wildcard.h" 00050 #include "pagespeed/kernel/util/copy_on_write.h" 00051 00052 namespace net_instaweb { 00053 00054 class Hasher; 00055 class MessageHandler; 00056 class RequestHeaders; 00057 00078 class RewriteOptions { 00079 private: 00084 class PropertyBase; 00085 template<class ValueType> class Property; 00086 template<class RewriteOptionsSubclass, class OptionClass> class PropertyLeaf; 00087 00088 public: 00101 enum Filter { 00102 kAddBaseTag, 00103 kAddHead, 00104 kAddInstrumentation, 00105 kComputeStatistics, 00106 kCachePartialHtml, 00107 kCanonicalizeJavascriptLibraries, 00108 kCollapseWhitespace, 00109 kCollectFlushEarlyContentFilter, 00110 kCombineCss, 00111 kCombineHeads, 00112 kCombineJavascript, 00113 kComputeCriticalCss, 00114 kComputeVisibleText, 00115 kConvertGifToPng, 00116 kConvertJpegToProgressive, 00117 kConvertJpegToWebp, 00118 kConvertMetaTags, 00119 kConvertPngToJpeg, 00120 kConvertToWebpLossless, 00121 kDebug, 00122 kDecodeRewrittenUrls, 00123 kDedupInlinedImages, 00124 kDeferIframe, 00125 kDeferJavascript, 00126 kDelayImages, 00127 kDeterministicJs, 00128 kDisableJavascript, 00129 kDivStructure, 00130 kElideAttributes, 00131 kExperimentSpdy, 00132 kExplicitCloseTags, 00133 kExtendCacheCss, 00134 kExtendCacheImages, 00135 kExtendCachePdfs, 00136 kExtendCacheScripts, 00137 kFallbackRewriteCssUrls, 00138 kFixReflows, 00139 kFlattenCssImports, 00140 kFlushSubresources, 00141 kHandleNoscriptRedirect, 00142 kHtmlWriterFilter, 00143 kIncludeJsSourceMaps, 00144 kInlineCss, 00145 kInlineGoogleFontCss, 00146 kInlineImages, 00147 kInlineImportToLink, 00148 kInlineJavascript, 00149 kInPlaceOptimizeForBrowser, 00150 kInsertDnsPrefetch, 00151 kInsertGA, 00152 kInsertImageDimensions, 00153 kJpegSubsampling, 00154 kLazyloadImages, 00155 kLeftTrimUrls, 00156 kLocalStorageCache, 00157 kMakeGoogleAnalyticsAsync, 00158 kMoveCssAboveScripts, 00159 kMoveCssToHead, 00160 kOutlineCss, 00161 kOutlineJavascript, 00162 kPedantic, 00163 kPrioritizeCriticalCss, 00164 kRecompressJpeg, 00165 kRecompressPng, 00166 kRecompressWebp, 00167 kRemoveComments, 00168 kRemoveQuotes, 00169 kResizeImages, 00170 kResizeMobileImages, 00171 kResizeToRenderedImageDimensions, 00172 kRewriteCss, 00173 kRewriteDomains, 00174 kRewriteJavascript, 00175 kRewriteStyleAttributes, 00176 kRewriteStyleAttributesWithUrl, 00177 kSplitHtml, 00178 kSplitHtmlHelper, 00179 kSpriteImages, 00180 kSquashImagesForMobileScreen, 00181 kStripImageColorProfile, 00182 kStripImageMetaData, 00183 kStripNonCacheable, 00184 kStripScripts, 00185 kEndOfFilters 00186 }; 00187 00188 enum EnabledEnum { 00191 kEnabledOff, 00193 kEnabledOn, 00196 kEnabledUnplugged, 00197 }; 00198 00205 static const char kAccessControlAllowOrigins[]; 00206 static const char kAddOptionsToUrls[]; 00207 static const char kAllowLoggingUrlsInLogRecord[]; 00208 static const char kAllowOptionsToBeSetByCookies[]; 00209 static const char kAlwaysRewriteCss[]; 00210 static const char kAnalyticsID[]; 00211 static const char kAvoidRenamingIntrospectiveJavascript[]; 00212 static const char kAwaitPcacheLookup[]; 00213 static const char kBeaconReinstrumentTimeSec[]; 00214 static const char kBeaconUrl[]; 00215 static const char kBlinkMaxHtmlSizeRewritable[]; 00216 static const char kCacheFragment[]; 00217 static const char kCacheInvalidationTimestamp[]; 00218 static const char kCacheSmallImagesUnrewritten[]; 00219 static const char kClientDomainRewrite[]; 00220 static const char kCombineAcrossPaths[]; 00221 static const char kCriticalImagesBeaconEnabled[]; 00222 static const char kCriticalLineConfig[]; 00223 static const char kCssFlattenMaxBytes[]; 00224 static const char kCssImageInlineMaxBytes[]; 00225 static const char kCssInlineMaxBytes[]; 00226 static const char kCssOutlineMinBytes[]; 00227 static const char kCssPreserveURLs[]; 00228 static const char kDefaultCacheHtml[]; 00229 static const char kDisableBackgroundFetchesForBots[]; 00230 static const char kDisableRewriteOnNoTransform[]; 00231 static const char kDistributeFetches[]; 00232 static const char kDistributedRewriteKey[]; 00233 static const char kDistributedRewriteServers[]; 00234 static const char kDistributedRewriteTimeoutMs[]; 00235 static const char kDomainRewriteHyperlinks[]; 00236 static const char kDomainShardCount[]; 00237 static const char kDownstreamCachePurgeMethod[]; 00238 static const char kDownstreamCacheRebeaconingKey[]; 00239 static const char kDownstreamCacheRewrittenPercentageThreshold[]; 00240 static const char kEnableAggressiveRewritersForMobile[]; 00241 static const char kEnableBlinkHtmlChangeDetection[]; 00242 static const char kEnableBlinkHtmlChangeDetectionLogging[]; 00243 static const char kEnableCachePurge[]; 00244 static const char kEnableDeferJsExperimental[]; 00245 static const char kEnableExtendedInstrumentation[]; 00246 static const char kEnableFlushEarlyCriticalCss[]; 00247 static const char kEnableLazyLoadHighResImages[]; 00248 static const char kEnablePrioritizingScripts[]; 00249 static const char kEnabled[]; 00250 static const char kEnrollExperiment[]; 00251 static const char kExperimentCookieDurationMs[]; 00252 static const char kExperimentSlot[]; 00253 static const char kFetcherTimeOutMs[]; 00254 static const char kFinderPropertiesCacheExpirationTimeMs[]; 00255 static const char kFinderPropertiesCacheRefreshTimeMs[]; 00256 static const char kFlushBufferLimitBytes[]; 00257 static const char kFlushHtml[]; 00258 static const char kFlushMoreResourcesEarlyIfTimePermits[]; 00259 static const char kForbidAllDisabledFilters[]; 00260 static const char kHideRefererUsingMeta[]; 00261 static const char kIdleFlushTimeMs[]; 00262 static const char kImageInlineMaxBytes[]; 00263 static const char kImageJpegNumProgressiveScans[]; 00264 static const char kImageJpegNumProgressiveScansForSmallScreens[]; 00265 static const char kImageJpegRecompressionQuality[]; 00266 static const char kImageJpegRecompressionQualityForSmallScreens[]; 00267 static const char kImageLimitOptimizedPercent[]; 00268 static const char kImageLimitRenderedAreaPercent[]; 00269 static const char kImageLimitResizeAreaPercent[]; 00270 static const char kImageMaxRewritesAtOnce[]; 00271 static const char kImagePreserveURLs[]; 00272 static const char kImageRecompressionQuality[]; 00273 static const char kImageResolutionLimitBytes[]; 00274 static const char kImageWebpRecompressionQuality[]; 00275 static const char kImageWebpRecompressionQualityForSmallScreens[]; 00276 static const char kImageWebpTimeoutMs[]; 00277 static const char kImplicitCacheTtlMs[]; 00278 static const char kIncreaseSpeedTracking[]; 00279 static const char kInlineOnlyCriticalImages[]; 00280 static const char kInPlacePreemptiveRewriteCss[]; 00281 static const char kInPlacePreemptiveRewriteCssImages[]; 00282 static const char kInPlacePreemptiveRewriteImages[]; 00283 static const char kInPlacePreemptiveRewriteJavascript[]; 00284 static const char kInPlaceResourceOptimization[]; 00285 static const char kInPlaceRewriteDeadlineMs[]; 00286 static const char kInPlaceWaitForOptimized[]; 00287 static const char kJsInlineMaxBytes[]; 00288 static const char kJsOutlineMinBytes[]; 00289 static const char kJsPreserveURLs[]; 00290 static const char kLazyloadImagesAfterOnload[]; 00291 static const char kLazyloadImagesBlankUrl[]; 00292 static const char kLogBackgroundRewrite[]; 00293 static const char kLogRewriteTiming[]; 00294 static const char kLogUrlIndices[]; 00295 static const char kLowercaseHtmlNames[]; 00296 static const char kMaxCacheableResponseContentLength[]; 00297 static const char kMaxCombinedCssBytes[]; 00298 static const char kMaxCombinedJsBytes[]; 00299 static const char kMaxHtmlCacheTimeMs[]; 00300 static const char kMaxHtmlParseBytes[]; 00301 static const char kMaxImageBytesForWebpInCss[]; 00302 static const char kMaxImageSizeLowResolutionBytes[]; 00303 static const char kMaxInlinedPreviewImagesIndex[]; 00304 static const char kMaxLowResImageSizeBytes[]; 00305 static const char kMaxLowResToHighResImageSizePercentage[]; 00306 static const char kMaxPrefetchJsElements[]; 00307 static const char kMaxRewriteInfoLogSize[]; 00308 static const char kMaxUrlSegmentSize[]; 00309 static const char kMaxUrlSize[]; 00310 static const char kMetadataCacheStalenessThresholdMs[]; 00311 static const char kMinCacheTtlMs[]; 00312 static const char kMinImageSizeLowResolutionBytes[]; 00313 static const char kMinResourceCacheTimeToRewriteMs[]; 00314 static const char kModifyCachingHeaders[]; 00315 static const char kNoTransformOptimizedImages[]; 00316 static const char kNonCacheablesForCachePartialHtml[]; 00317 static const char kObliviousPagespeedUrls[]; 00318 static const char kOptionCookiesDurationMs[]; 00319 static const char kOverrideCachingTtlMs[]; 00320 static const char kPersistBlinkBlacklist[]; 00321 static const char kPreserveUrlRelativity[]; 00322 static const char kPrivateNotVaryForIE[]; 00323 static const char kPubliclyCacheMismatchedHashesExperimental[]; 00324 static const char kProactivelyFreshenUserFacingRequest[]; 00325 static const char kProactiveResourceFreshening[]; 00326 static const char kProgressiveJpegMinBytes[]; 00327 static const char kRejectBlacklisted[]; 00328 static const char kRejectBlacklistedStatusCode[]; 00329 static const char kReportUnloadTime[]; 00330 static const char kRespectVary[]; 00331 static const char kRespectXForwardedProto[]; 00332 static const char kRewriteDeadlineMs[]; 00333 static const char kRewriteLevel[]; 00334 static const char kRewriteRandomDropPercentage[]; 00335 static const char kRewriteUncacheableResources[]; 00336 static const char kRunningExperiment[]; 00337 static const char kServeGhostClickBusterWithSplitHtml[]; 00338 static const char kServeSplitHtmlInTwoChunks[]; 00339 static const char kServeStaleIfFetchError[]; 00340 static const char kServeStaleWhileRevalidateThresholdSec[]; 00341 static const char kServeXhrAccessControlHeaders[]; 00342 static const char kStickyQueryParameters[]; 00343 static const char kSupportNoScriptEnabled[]; 00344 static const char kTestOnlyPrioritizeCriticalCssDontApplyOriginalCss[]; 00345 static const char kUseBlankImageForInlinePreview[]; 00346 static const char kUseExperimentalJsMinifier[]; 00347 static const char kUseFallbackPropertyCacheValues[]; 00348 static const char kUseImageScanlineApi[]; 00349 static const char kUseSelectorsForCriticalCss[]; 00350 static const char kUseSmartDiffInBlink[]; 00351 static const char kXModPagespeedHeaderValue[]; 00352 static const char kXPsaBlockingRewrite[]; 00353 static const char kRequestOptionOverride[]; 00355 static const char kAllow[]; 00356 static const char kBlockingRewriteRefererUrls[]; 00357 static const char kDisableFilters[]; 00358 static const char kDisallow[]; 00359 static const char kDistributableFilters[]; 00360 static const char kDomain[]; 00361 static const char kDownstreamCachePurgeLocationPrefix[]; 00362 static const char kEnableFilters[]; 00363 static const char kExperimentVariable[]; 00364 static const char kExperimentSpec[]; 00365 static const char kForbidFilters[]; 00366 static const char kInlineResourcesWithoutExplicitAuthorization[]; 00367 static const char kRetainComment[]; 00369 static const char kCustomFetchHeader[]; 00370 static const char kLoadFromFile[]; 00371 static const char kLoadFromFileMatch[]; 00372 static const char kLoadFromFileRule[]; 00373 static const char kLoadFromFileRuleMatch[]; 00374 static const char kMapOriginDomain[]; 00375 static const char kMapProxyDomain[]; 00376 static const char kMapRewriteDomain[]; 00377 static const char kShardDomain[]; 00379 static const char kLibrary[]; 00380 static const char kUrlValuedAttribute[]; 00383 static const char kCacheFlushFilename[]; 00384 static const char kCacheFlushPollIntervalSec[]; 00385 static const char kCompressMetadataCache[]; 00386 static const char kFetcherProxy[]; 00387 static const char kFetchFromModSpdy[]; 00388 static const char kFetchHttps[]; 00389 static const char kFileCacheCleanInodeLimit[]; 00390 static const char kFileCacheCleanIntervalMs[]; 00391 static const char kFileCacheCleanSizeKb[]; 00392 static const char kFileCachePath[]; 00393 static const char kLogDir[]; 00394 static const char kLruCacheByteLimit[]; 00395 static const char kLruCacheKbPerProcess[]; 00396 static const char kMemcachedServers[]; 00397 static const char kMemcachedThreads[]; 00398 static const char kMemcachedTimeoutUs[]; 00399 static const char kRateLimitBackgroundFetches[]; 00400 static const char kServeWebpToAnyAgent[]; 00401 static const char kSlurpDirectory[]; 00402 static const char kSlurpFlushLimit[]; 00403 static const char kSlurpReadOnly[]; 00404 static const char kSslCertDirectory[]; 00405 static const char kSslCertFile[]; 00406 static const char kStatisticsEnabled[]; 00407 static const char kStatisticsLoggingChartsCSS[]; 00408 static const char kStatisticsLoggingChartsJS[]; 00409 static const char kStatisticsLoggingEnabled[]; 00410 static const char kStatisticsLoggingIntervalMs[]; 00411 static const char kStatisticsLoggingMaxFileSizeKb[]; 00412 static const char kTestProxy[]; 00413 static const char kTestProxySlurp[]; 00414 static const char kUseSharedMemLocking[]; 00416 static const char kNullOption[]; 00417 00425 struct BeaconUrl { 00426 GoogleString http; 00427 GoogleString https; 00428 GoogleString http_in; 00429 GoogleString https_in; 00430 }; 00431 00432 struct NameValue { 00433 NameValue(const StringPiece& name_in, const StringPiece& value_in) { 00434 name_in.CopyToString(&name); 00435 value_in.CopyToString(&value); 00436 } 00437 GoogleString name; 00438 GoogleString value; 00439 }; 00440 00456 static const int kOptionsVersion = 13; 00457 00459 static const int kHashBytes = 20; 00460 00467 enum OptionScope { 00468 kQueryScope, 00469 00470 kDirectoryScope, 00471 kServerScope, 00472 kProcessScope, 00473 kProcessScopeStrict, 00474 }; 00475 00476 static const char kCacheExtenderId[]; 00477 static const char kCollectFlushEarlyContentFilterId[]; 00478 static const char kCssCombinerId[]; 00479 static const char kCssFilterId[]; 00480 static const char kCssImportFlattenerId[]; 00481 static const char kCssInlineId[]; 00482 static const char kGoogleFontCssInlineId[]; 00483 static const char kImageCombineId[]; 00484 static const char kImageCompressionId[]; 00485 static const char kInPlaceRewriteId[]; 00486 static const char kJavascriptCombinerId[]; 00487 static const char kJavascriptInlineId[]; 00488 static const char kJavascriptMinId[]; 00489 static const char kJavascriptMinSourceMapId[]; 00490 static const char kLocalStorageCacheId[]; 00491 static const char kPrioritizeCriticalCssId[]; 00492 00493 static const char kPanelCommentPrefix[]; 00494 00497 static const char* FilterName(Filter filter); 00498 00501 static const char* FilterId(Filter filter); 00502 00505 static int NumFilterIds(); 00506 00508 static const Filter kFirstFilter = kAddBaseTag; 00509 00510 typedef EnumSet<Filter, kEndOfFilters> FilterSet; 00511 typedef std::vector<Filter> FilterVector; 00512 00514 typedef std::set<GoogleString> FilterIdSet; 00515 00521 static bool AddByNameToFilterSet(const StringPiece& option, FilterSet* set, 00522 MessageHandler* handler); 00523 00526 typedef std::pair<GoogleString, GoogleString> OptionStringPair; 00527 typedef std::set<OptionStringPair> OptionSet; 00528 00529 typedef std::vector<PropertyBase*> PropertyVector; 00530 00533 class OptionBase { 00534 public: 00535 OptionBase() {} 00536 virtual ~OptionBase(); 00537 00541 virtual bool SetFromString(StringPiece value_string, 00542 GoogleString* error_detail) = 0; 00543 virtual void Merge(const OptionBase* src) = 0; 00544 virtual bool was_set() const = 0; 00545 virtual GoogleString Signature(const Hasher* hasher) const = 0; 00546 virtual GoogleString ToString() const = 0; 00547 const char* id() const { return property()->id(); } 00548 const char* help_text() const { return property()->help_text(); } 00549 OptionScope scope() const { return property()->scope(); } 00550 StringPiece option_name() const { return property()->option_name(); } 00551 bool is_used_for_signature_computation() const { 00552 return property()->is_used_for_signature_computation(); 00553 } 00554 virtual const PropertyBase* property() const = 0; 00555 }; 00556 00558 typedef std::vector<OptionBase*> OptionBaseVector; 00559 00560 enum RewriteLevel { 00565 kPassThrough, 00566 00570 kOptimizeForBandwidth, 00571 00577 kCoreFilters, 00578 00582 kTestingCoreFilters, 00583 00586 kAllFilters, 00587 }; 00588 00590 enum OptionSettingResult { 00591 kOptionOk, 00592 kOptionNameUnknown, 00593 kOptionValueInvalid 00594 }; 00595 00596 static const int kDefaultBeaconReinstrumentTimeSec; 00597 static const int64 kDefaultBlinkMaxHtmlSizeRewritable; 00598 static const int64 kDefaultCssFlattenMaxBytes; 00599 static const int64 kDefaultCssImageInlineMaxBytes; 00600 static const int64 kDefaultCssInlineMaxBytes; 00601 static const int64 kDefaultCssOutlineMinBytes; 00602 static const int64 kDefaultImageInlineMaxBytes; 00603 static const int64 kDefaultJsInlineMaxBytes; 00604 static const int64 kDefaultJsOutlineMinBytes; 00605 static const int64 kDefaultProgressiveJpegMinBytes; 00606 static const int64 kDefaultMaxCacheableResponseContentLength; 00607 static const int64 kDefaultMaxHtmlCacheTimeMs; 00608 static const int64 kDefaultMaxHtmlParseBytes; 00609 static const int64 kDefaultMaxImageBytesForWebpInCss; 00610 static const int64 kDefaultMaxLowResImageSizeBytes; 00611 static const int kDefaultMaxLowResToFullResImageSizePercentage; 00612 static const int64 kDefaultMetadataInputErrorsCacheTtlMs; 00613 static const int64 kDefaultMinResourceCacheTimeToRewriteMs; 00614 static const char kDefaultDownstreamCachePurgeMethod[]; 00615 static const int64 kDefaultDownstreamCacheRewrittenPercentageThreshold; 00616 static const int64 kDefaultCacheInvalidationTimestamp; 00617 static const int64 kDefaultIdleFlushTimeMs; 00618 static const int64 kDefaultFlushBufferLimitBytes; 00619 static const int64 kDefaultImplicitCacheTtlMs; 00620 static const int64 kDefaultMinCacheTtlMs; 00621 static const int64 kDefaultPrioritizeVisibleContentCacheTimeMs; 00622 static const char kDefaultBeaconUrl[]; 00623 static const int64 kDefaultImageRecompressQuality; 00624 static const int64 kDefaultImageJpegRecompressQuality; 00625 static const int64 kDefaultImageJpegRecompressQualityForSmallScreens; 00626 static const int kDefaultImageLimitOptimizedPercent; 00627 static const int kDefaultImageLimitRenderedAreaPercent; 00628 static const int kDefaultImageLimitResizeAreaPercent; 00629 static const int64 kDefaultImageResolutionLimitBytes; 00630 static const int64 kDefaultImageJpegNumProgressiveScans; 00631 static const int64 kDefaultImageWebpRecompressQuality; 00632 static const int64 kDefaultImageWebpRecompressQualityForSmallScreens; 00633 static const int64 kDefaultImageWebpTimeoutMs; 00634 static const int kDefaultDomainShardCount; 00635 static const int64 kDefaultBlinkHtmlChangeDetectionTimeMs; 00636 static const int kDefaultMaxPrefetchJsElements; 00637 static const int64 kDefaultOptionCookiesDurationMs; 00638 00641 static const int kDefaultMaxUrlSize; 00642 00643 static const int kDefaultImageMaxRewritesAtOnce; 00644 00649 static const int kDefaultMaxUrlSegmentSize; 00650 00652 static const int kDefaultRewriteDeadlineMs; 00653 00655 static const int64 kDefaultDistributedTimeoutMs; 00656 00659 static const int kDefaultMaxInlinedPreviewImagesIndex; 00662 static const int64 kDefaultMinImageSizeLowResolutionBytes; 00665 static const int64 kDefaultMaxImageSizeLowResolutionBytes; 00667 static const int64 kDefaultFinderPropertiesCacheExpirationTimeMs; 00669 static const int64 kDefaultFinderPropertiesCacheRefreshTimeMs; 00670 00673 static const int64 kDefaultExperimentCookieDurationMs; 00674 00677 static const int64 kDefaultMetadataCacheStalenessThresholdMs; 00678 00680 static const int64 kDefaultMaxCombinedCssBytes; 00681 00683 static const int64 kDefaultMaxCombinedJsBytes; 00684 00685 static const int kDefaultExperimentTrafficPercent; 00687 static const int kDefaultExperimentSlot; 00688 00689 static const char kDefaultBlockingRewriteKey[]; 00690 00691 static const char kRejectedRequestUrlKeyName[]; 00692 00693 static const int kDefaultPropertyCacheHttpStatusStabilityThreshold; 00694 00695 static const int kDefaultMaxRewriteInfoLogSize; 00696 00703 class ExperimentSpec { 00704 public: 00709 ExperimentSpec(const StringPiece& spec, RewriteOptions* options, 00710 MessageHandler* handler); 00711 00715 explicit ExperimentSpec(int id); 00716 00717 virtual ~ExperimentSpec(); 00718 00720 virtual ExperimentSpec* Clone(); 00721 00722 bool is_valid() const { return id_ >= 0; } 00723 00725 int id() const { return id_; } 00726 int percent() const { return percent_; } 00727 GoogleString ga_id() const { return ga_id_; } 00728 int slot() const { return ga_variable_slot_; } 00729 RewriteLevel rewrite_level() const { return rewrite_level_; } 00730 FilterSet enabled_filters() const { return enabled_filters_; } 00731 FilterSet disabled_filters() const { return disabled_filters_; } 00732 OptionSet filter_options() const { return filter_options_; } 00733 bool use_default() const { return use_default_; } 00734 GoogleString ToString() const; 00735 00736 protected: 00741 void Merge(const ExperimentSpec& spec); 00742 00743 private: 00744 FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest); 00745 00748 void Initialize(const StringPiece& spec, MessageHandler* handler); 00749 00750 int id_; 00751 GoogleString ga_id_; 00752 int ga_variable_slot_; 00753 int percent_; 00754 RewriteLevel rewrite_level_; 00755 FilterSet enabled_filters_; 00756 FilterSet disabled_filters_; 00757 OptionSet filter_options_; 00760 bool use_default_; 00761 DISALLOW_COPY_AND_ASSIGN(ExperimentSpec); 00762 }; 00763 00765 struct ElementAttributeCategory { 00766 GoogleString element; 00767 GoogleString attribute; 00768 semantic_type::Category category; 00769 }; 00770 00777 class Properties { 00778 public: 00787 static bool Initialize(Properties** properties); 00788 00797 static bool Terminate(Properties** properties_handle); 00798 00800 int size() const { return property_vector_.size(); } 00801 00802 const PropertyBase* property(int index) const { 00803 return property_vector_[index]; 00804 } 00805 PropertyBase* property(int index) { return property_vector_[index]; } 00806 00812 void Merge(Properties* properties); 00813 00814 void push_back(PropertyBase* p) { property_vector_.push_back(p); } 00815 00816 private: 00819 Properties(); 00820 ~Properties(); 00821 00825 int initialization_count_; 00826 00831 bool owns_properties_; 00832 PropertyVector property_vector_; 00833 }; 00834 00836 struct FilterEnumToIdAndNameEntry { 00837 RewriteOptions::Filter filter_enum; 00838 const char* filter_id; 00839 const char* filter_name; 00840 }; 00841 00842 static bool ParseRewriteLevel(const StringPiece& in, RewriteLevel* out); 00843 00844 typedef std::set<semantic_type::Category> ResourceCategorySet; 00845 00846 static bool ParseInlineUnauthorizedResourceType( 00847 const StringPiece& in, 00848 ResourceCategorySet* resource_types); 00849 00853 static bool ParseBeaconUrl(const StringPiece& in, BeaconUrl* out); 00854 00858 bool ImageOptimizationEnabled() const; 00859 00860 explicit RewriteOptions(ThreadSystem* thread_system); 00861 virtual ~RewriteOptions(); 00862 00866 static bool Initialize(); 00867 static bool Terminate(); 00868 00869 #ifndef NDEBUG 00870 00871 00872 00873 00874 00875 00876 bool ModificationOK() const; 00877 00884 bool MergeOK() const; 00885 #endif 00886 00891 void InitializeOptions(const Properties* properties); 00892 00893 bool modified() const { return modified_; } 00894 00900 void SetDefaultRewriteLevel(RewriteLevel level) { 00902 level_.set_default(level); 00903 } 00904 void SetRewriteLevel(RewriteLevel level) { 00905 set_option(level, &level_); 00906 } 00907 00909 void AddCustomFetchHeader(const StringPiece& name, const StringPiece& value); 00910 00911 const NameValue* custom_fetch_header(int i) const { 00912 return custom_fetch_headers_[i]; 00913 } 00914 00915 int num_custom_fetch_headers() const { 00916 return custom_fetch_headers_.size(); 00917 } 00918 00921 ExperimentSpec* GetExperimentSpec(int id) const; 00922 00926 bool AvailableExperimentId(int id); 00927 00930 virtual ExperimentSpec* AddExperimentSpec(const StringPiece& spec, 00931 MessageHandler* handler); 00932 00940 virtual bool SetExperimentState(int id); 00941 00945 void SetExperimentStateStr(const StringPiece& experiment_index); 00946 00947 int experiment_id() const { return experiment_id_; } 00948 00949 int experiment_spec_id(int i) const { 00950 return experiment_specs_[i]->id(); 00951 } 00952 00957 GoogleString GetExperimentStateStr() const; 00958 00959 ExperimentSpec* experiment_spec(int i) const { 00960 return experiment_specs_[i]; 00961 } 00962 00963 int num_experiments() const { return experiment_specs_.size(); } 00964 00965 bool enroll_experiment() const { 00966 return enroll_experiment_id() != experiment::kForceNoExperiment; 00967 } 00968 00980 void AddUrlValuedAttribute(const StringPiece& element, 00981 const StringPiece& attribute, 00982 semantic_type::Category category); 00983 00986 void UrlValuedAttribute(int index, 00987 StringPiece* element, 00988 StringPiece* attribute, 00989 semantic_type::Category* category) const; 00990 00991 int num_url_valued_attributes() const { 00992 if (url_valued_attributes_ == NULL) { 00993 return 0; 00994 } else { 00995 return url_valued_attributes_->size(); 00996 } 00997 } 00998 00999 void AddInlineUnauthorizedResourceType(semantic_type::Category category); 01000 bool HasInlineUnauthorizedResourceType( 01001 semantic_type::Category category) const; 01002 void ClearInlineUnauthorizedResourceTypes(); 01003 void set_inline_unauthorized_resource_types(ResourceCategorySet x); 01004 01006 bool RegisterLibrary( 01007 uint64 bytes, StringPiece md5_hash, StringPiece canonical_url) { 01008 return WriteableJavascriptLibraryIdentification()->RegisterLibrary( 01009 bytes, md5_hash, canonical_url); 01010 } 01011 01014 const JavascriptLibraryIdentification* javascript_library_identification() 01015 const { 01016 if (Enabled(kCanonicalizeJavascriptLibraries)) { 01017 return javascript_library_identification_.get(); 01018 } else { 01019 return NULL; 01020 } 01021 } 01022 01023 RewriteLevel level() const { return level_.value(); } 01024 01029 bool AdjustFiltersByCommaSeparatedList(const StringPiece& filters, 01030 MessageHandler* handler); 01031 01035 bool EnableFiltersByCommaSeparatedList(const StringPiece& filters, 01036 MessageHandler* handler); 01037 01041 bool DisableFiltersByCommaSeparatedList(const StringPiece& filters, 01042 MessageHandler* handler); 01043 01047 bool ForbidFiltersByCommaSeparatedList(const StringPiece& filters, 01048 MessageHandler* handler); 01049 01051 void DisableAllFilters(); 01052 01060 void DisableAllFiltersNotExplicitlyEnabled(); 01061 01064 void DistributeFiltersByCommaSeparatedList(const StringPiece& filter_ids, 01065 MessageHandler* handler); 01068 void DistributeFilter(const StringPiece& filter_id); 01069 01072 bool Distributable(const StringPiece& filter_id) const; 01073 01077 void EnableFilter(Filter filter); 01080 void ForceEnableFilter(Filter filter); 01081 void DisableFilter(Filter filter); 01082 void DisableIfNotExplictlyEnabled(Filter filter); 01083 void ForbidFilter(Filter filter); 01084 void EnableFilters(const FilterSet& filter_set); 01085 void DisableFilters(const FilterSet& filter_set); 01086 void ForbidFilters(const FilterSet& filter_set); 01089 void ClearFilters(); 01090 01108 void SoftEnableFilterForTesting(Filter filter); 01109 01112 void EnableExtendCacheFilters(); 01113 01114 bool Enabled(Filter filter) const; 01115 bool Forbidden(Filter filter) const; 01116 bool Forbidden(StringPiece filter_id) const; 01117 01119 void GetEnabledFiltersRequiringScriptExecution(FilterVector* filters) const; 01120 01122 void DisableFiltersRequiringScriptExecution(); 01123 01128 static bool AddCommaSeparatedListToOptionSet( 01129 const StringPiece& options, OptionSet* set, MessageHandler* handler); 01130 01135 OptionSettingResult SetOptionFromName( 01136 StringPiece name, StringPiece value, GoogleString* msg); 01137 01139 OptionSettingResult SetOptionFromName( 01140 StringPiece name, StringPiece value); 01141 01145 OptionSettingResult SetOptionFromQuery(StringPiece name, StringPiece value); 01146 01151 virtual OptionSettingResult ParseAndSetOptionFromName1( 01152 StringPiece name, StringPiece arg, 01153 GoogleString* msg, MessageHandler* handler); 01154 01155 virtual OptionSettingResult ParseAndSetOptionFromName2( 01156 StringPiece name, StringPiece arg1, StringPiece arg2, 01157 GoogleString* msg, MessageHandler* handler); 01158 01159 virtual OptionSettingResult ParseAndSetOptionFromName3( 01160 StringPiece name, StringPiece arg1, StringPiece arg2, StringPiece arg3, 01161 GoogleString* msg, MessageHandler* handler); 01162 01168 bool OptionValue(StringPiece option_name, const char** id, 01169 bool* was_set, GoogleString* value) const; 01170 01173 bool SetOptionsFromName(const OptionSet& option_set, MessageHandler* handler); 01174 01177 bool SetOptionFromNameAndLog(StringPiece name, 01178 StringPiece value, 01179 MessageHandler* handler); 01180 01183 static bool ParseFromString(StringPiece value_string, bool* value); 01184 static bool ParseFromString(StringPiece value_string, EnabledEnum* value); 01185 static bool ParseFromString(StringPiece value_string, int* value) { 01186 return StringToInt(value_string, value); 01187 } 01188 static bool ParseFromString(StringPiece value_string, int64* value) { 01189 return StringToInt64(value_string, value); 01190 } 01191 static bool ParseFromString(StringPiece value_string, GoogleString* value) { 01192 value_string.CopyToString(value); 01193 return true; 01194 } 01195 static bool ParseFromString(StringPiece value_string, RewriteLevel* value) { 01196 return ParseRewriteLevel(value_string, value); 01197 } 01198 static bool ParseFromString(StringPiece value_string, 01199 ResourceCategorySet* value) { 01200 return ParseInlineUnauthorizedResourceType(value_string, value); 01201 } 01202 static bool ParseFromString(StringPiece value_string, BeaconUrl* value) { 01203 return ParseBeaconUrl(value_string, value); 01204 } 01205 static bool ParseFromString(StringPiece value_string, 01206 protobuf::MessageLite* proto); 01207 01210 int64 css_outline_min_bytes() const { return css_outline_min_bytes_.value(); } 01211 void set_css_outline_min_bytes(int64 x) { 01212 set_option(x, &css_outline_min_bytes_); 01213 } 01214 01215 GoogleString ga_id() const { return ga_id_.value(); } 01216 void set_ga_id(GoogleString id) { 01217 set_option(id, &ga_id_); 01218 } 01219 01220 bool increase_speed_tracking() const { 01221 return increase_speed_tracking_.value(); 01222 } 01223 void set_increase_speed_tracking(bool x) { 01224 set_option(x, &increase_speed_tracking_); 01225 } 01226 01227 int64 js_outline_min_bytes() const { return js_outline_min_bytes_.value(); } 01228 void set_js_outline_min_bytes(int64 x) { 01229 set_option(x, &js_outline_min_bytes_); 01230 } 01231 01232 int64 progressive_jpeg_min_bytes() const { 01233 return progressive_jpeg_min_bytes_.value(); 01234 } 01235 void set_progressive_jpeg_min_bytes(int64 x) { 01236 set_option(x, &progressive_jpeg_min_bytes_); 01237 } 01238 01239 int64 css_flatten_max_bytes() const { return css_flatten_max_bytes_.value(); } 01240 void set_css_flatten_max_bytes(int64 x) { 01241 set_option(x, &css_flatten_max_bytes_); 01242 } 01243 bool cache_small_images_unrewritten() const { 01244 return cache_small_images_unrewritten_.value(); 01245 } 01246 void set_cache_small_images_unrewritten(bool x) { 01247 set_option(x, &cache_small_images_unrewritten_); 01248 } 01249 int64 image_resolution_limit_bytes() const { 01250 return image_resolution_limit_bytes_.value(); 01251 } 01252 void set_image_resolution_limit_bytes(int64 x) { 01253 set_option(x, &image_resolution_limit_bytes_); 01254 } 01255 01257 int64 ImageInlineMaxBytes() const; 01258 void set_image_inline_max_bytes(int64 x); 01260 int64 CssImageInlineMaxBytes() const; 01261 void set_css_image_inline_max_bytes(int64 x) { 01262 set_option(x, &css_image_inline_max_bytes_); 01263 } 01265 int64 MaxImageInlineMaxBytes() const; 01266 int64 css_inline_max_bytes() const { return css_inline_max_bytes_.value(); } 01267 void set_css_inline_max_bytes(int64 x) { 01268 set_option(x, &css_inline_max_bytes_); 01269 } 01270 int64 js_inline_max_bytes() const { return js_inline_max_bytes_.value(); } 01271 void set_js_inline_max_bytes(int64 x) { 01272 set_option(x, &js_inline_max_bytes_); 01273 } 01274 int64 max_html_cache_time_ms() const { 01275 return max_html_cache_time_ms_.value(); 01276 } 01277 void set_max_html_cache_time_ms(int64 x) { 01278 set_option(x, &max_html_cache_time_ms_); 01279 } 01280 int64 max_html_parse_bytes() const { 01281 return max_html_parse_bytes_.value(); 01282 } 01283 void set_max_html_parse_bytes(int64 x) { 01284 set_option(x, &max_html_parse_bytes_); 01285 } 01286 int64 max_image_bytes_for_webp_in_css() const { 01287 return max_image_bytes_for_webp_in_css_.value(); 01288 } 01289 void set_max_image_bytes_for_webp_in_css(int64 x) { 01290 set_option(x, &max_image_bytes_for_webp_in_css_); 01291 } 01292 int64 max_cacheable_response_content_length() const { 01293 return max_cacheable_response_content_length_.value(); 01294 } 01295 void set_max_cacheable_response_content_length(int64 x) { 01296 set_option(x, &max_cacheable_response_content_length_); 01297 } 01298 int64 min_resource_cache_time_to_rewrite_ms() const { 01299 return min_resource_cache_time_to_rewrite_ms_.value(); 01300 } 01301 void set_min_resource_cache_time_to_rewrite_ms(int64 x) { 01302 set_option(x, &min_resource_cache_time_to_rewrite_ms_); 01303 } 01304 bool need_to_store_experiment_data() const { 01305 return need_to_store_experiment_data_; 01306 } 01307 void set_need_to_store_experiment_data(bool x) { 01308 need_to_store_experiment_data_ = x; 01309 } 01310 01311 int64 blocking_fetch_timeout_ms() const { 01312 return blocking_fetch_timeout_ms_.value(); 01313 } 01314 void set_blocking_fetch_timeout_ms(int64 x) { 01315 set_option(x, &blocking_fetch_timeout_ms_); 01316 } 01317 bool override_ie_document_mode() const { 01318 return override_ie_document_mode_.value(); 01319 } 01320 void set_override_ie_document_mode(bool x) { 01321 set_option(x, &override_ie_document_mode_); 01322 } 01323 01324 int64 blink_blacklist_end_timestamp_ms() const { 01325 return blink_blacklist_end_timestamp_ms_.value(); 01326 } 01327 void set_blink_blacklist_end_timestamp_ms(int64 x) { 01328 set_option(x, &blink_blacklist_end_timestamp_ms_); 01329 } 01330 01331 bool persist_blink_blacklist() const { 01332 return persist_blink_blacklist_.value(); 01333 } 01334 void set_persist_blink_blacklist(bool x) { 01335 set_option(x, &persist_blink_blacklist_); 01336 } 01337 01338 bool preserve_url_relativity() const { 01339 return preserve_url_relativity_.value(); 01340 } 01341 void set_preserve_url_relativity(bool x) { 01342 set_option(x, &preserve_url_relativity_); 01343 } 01344 01352 bool IsUrlCacheValid(StringPiece url, int64 time_ms) const; 01353 01357 bool IsUrlPurged(StringPiece url, int64 time_ms) const; 01358 01375 void AddUrlCacheInvalidationEntry(StringPiece url_pattern, 01376 int64 timestamp_ms, 01377 bool ignores_metadata_and_pcache); 01378 01380 void PurgeUrl(StringPiece url, int64 timestamp_ms); 01381 01384 bool IsUrlCacheInvalidationEntriesSorted() const; 01385 01388 void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock* lock) { 01389 cache_invalidation_timestamp_.set_mutex(lock); 01390 } 01391 01393 int64 cache_invalidation_timestamp() const { 01394 ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex()); 01395 return cache_invalidation_timestamp_.value(); 01396 } 01397 01404 void set_cache_invalidation_timestamp(int64 timestamp_ms) { 01405 cache_invalidation_timestamp_.mutex()->DCheckLocked(); 01406 DCHECK_LT(0, timestamp_ms); 01407 set_option(timestamp_ms, &cache_invalidation_timestamp_); 01408 } 01409 01416 bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms) 01417 LOCKS_EXCLUDED(cache_invalidation_timestamp_.mutex()); 01418 01421 int64 idle_flush_time_ms() const { 01422 return idle_flush_time_ms_.value(); 01423 } 01424 void set_idle_flush_time_ms(int64 x) { 01425 set_option(x, &idle_flush_time_ms_); 01426 } 01427 01429 int64 flush_buffer_limit_bytes() const { 01430 return flush_buffer_limit_bytes_.value(); 01431 } 01432 01433 void set_flush_buffer_limit_bytes(int64 x) { 01434 set_option(x, &flush_buffer_limit_bytes_); 01435 } 01436 01439 int max_url_segment_size() const { return max_url_segment_size_.value(); } 01440 void set_max_url_segment_size(int x) { 01441 set_option(x, &max_url_segment_size_); 01442 } 01443 01444 int image_max_rewrites_at_once() const { 01445 return image_max_rewrites_at_once_.value(); 01446 } 01447 void set_image_max_rewrites_at_once(int x) { 01448 set_option(x, &image_max_rewrites_at_once_); 01449 } 01450 01452 int max_url_size() const { return max_url_size_.value(); } 01453 void set_max_url_size(int x) { 01454 set_option(x, &max_url_size_); 01455 } 01456 01457 int rewrite_deadline_ms() const { return rewrite_deadline_ms_.value(); } 01458 void set_rewrite_deadline_ms(int x) { 01459 set_option(x, &rewrite_deadline_ms_); 01460 } 01461 01462 bool test_instant_fetch_rewrite_deadline() const { 01463 return test_instant_fetch_rewrite_deadline_.value(); 01464 } 01465 void set_test_instant_fetch_rewrite_deadline(bool x) { 01466 set_option(x, &test_instant_fetch_rewrite_deadline_); 01467 } 01468 01469 void set_test_only_prioritize_critical_css_dont_apply_original_css(bool x) { 01470 set_option(x, &test_only_prioritize_critical_css_dont_apply_original_css_); 01471 } 01472 bool test_only_prioritize_critical_css_dont_apply_original_css() const { 01473 return test_only_prioritize_critical_css_dont_apply_original_css_.value(); 01474 } 01475 01476 int domain_shard_count() const { return domain_shard_count_.value(); } 01479 void set_domain_shard_count(int64 x) { 01480 int value = x; 01481 set_option(value, &domain_shard_count_); 01482 } 01483 01484 void set_enabled(EnabledEnum x) { 01485 set_option(x, &enabled_); 01486 } 01487 bool enabled() const { 01488 return enabled_.value() == kEnabledOn; 01489 } 01490 bool unplugged() const { 01491 return enabled_.value() == kEnabledUnplugged; 01492 } 01493 01494 void set_add_options_to_urls(bool x) { 01495 set_option(x, &add_options_to_urls_); 01496 } 01497 01498 bool add_options_to_urls() const { 01499 return add_options_to_urls_.value(); 01500 } 01501 01502 void set_publicly_cache_mismatched_hashes_experimental(bool x) { 01503 set_option(x, &publicly_cache_mismatched_hashes_experimental_); 01504 } 01505 01506 bool publicly_cache_mismatched_hashes_experimental() const { 01507 return publicly_cache_mismatched_hashes_experimental_.value(); 01508 } 01509 01510 void set_oblivious_pagespeed_urls(bool x) { 01511 set_option(x, &oblivious_pagespeed_urls_); 01512 } 01513 01514 bool oblivious_pagespeed_urls() const { 01515 return oblivious_pagespeed_urls_.value(); 01516 } 01517 01518 void set_in_place_rewriting_enabled(bool x) { 01519 set_option(x, &in_place_rewriting_enabled_); 01520 } 01521 01522 bool in_place_rewriting_enabled() const { 01523 return CheckBandwidthOption(in_place_rewriting_enabled_); 01524 } 01525 01526 void set_in_place_wait_for_optimized(bool x) { 01527 set_option(x, &in_place_wait_for_optimized_); 01528 } 01529 01530 bool in_place_wait_for_optimized() const { 01531 return (in_place_wait_for_optimized_.value() || 01532 (in_place_rewrite_deadline_ms() < 0)); 01533 } 01534 01535 void set_in_place_rewrite_deadline_ms(int x) { 01536 set_option(x, &in_place_rewrite_deadline_ms_); 01537 } 01538 01539 int in_place_rewrite_deadline_ms() const { 01540 return in_place_rewrite_deadline_ms_.value(); 01541 } 01542 01543 void set_in_place_preemptive_rewrite_css(bool x) { 01544 set_option(x, &in_place_preemptive_rewrite_css_); 01545 } 01546 bool in_place_preemptive_rewrite_css() const { 01547 return CheckBandwidthOption(in_place_preemptive_rewrite_css_); 01548 } 01549 01550 void set_in_place_preemptive_rewrite_css_images(bool x) { 01551 set_option(x, &in_place_preemptive_rewrite_css_images_); 01552 } 01553 bool in_place_preemptive_rewrite_css_images() const { 01554 return CheckBandwidthOption(in_place_preemptive_rewrite_css_images_); 01555 } 01556 01557 void set_in_place_preemptive_rewrite_images(bool x) { 01558 set_option(x, &in_place_preemptive_rewrite_images_); 01559 } 01560 bool in_place_preemptive_rewrite_images() const { 01561 return CheckBandwidthOption(in_place_preemptive_rewrite_images_); 01562 } 01563 01564 void set_in_place_preemptive_rewrite_javascript(bool x) { 01565 set_option(x, &in_place_preemptive_rewrite_javascript_); 01566 } 01567 bool in_place_preemptive_rewrite_javascript() const { 01568 return CheckBandwidthOption(in_place_preemptive_rewrite_javascript_); 01569 } 01570 01571 void set_private_not_vary_for_ie(bool x) { 01572 set_option(x, &private_not_vary_for_ie_); 01573 } 01574 bool private_not_vary_for_ie() const { 01575 return private_not_vary_for_ie_.value(); 01576 } 01577 01578 void set_combine_across_paths(bool x) { 01579 set_option(x, &combine_across_paths_); 01580 } 01581 bool combine_across_paths() const { return combine_across_paths_.value(); } 01582 01583 void set_log_background_rewrites(bool x) { 01584 set_option(x, &log_background_rewrites_); 01585 } 01586 bool log_background_rewrites() const { 01587 return log_background_rewrites_.value(); 01588 } 01589 01590 void set_log_rewrite_timing(bool x) { 01591 set_option(x, &log_rewrite_timing_); 01592 } 01593 bool log_rewrite_timing() const { return log_rewrite_timing_.value(); } 01594 01595 void set_log_url_indices(bool x) { 01596 set_option(x, &log_url_indices_); 01597 } 01598 bool log_url_indices() const { return log_url_indices_.value(); } 01599 01600 void set_lowercase_html_names(bool x) { 01601 set_option(x, &lowercase_html_names_); 01602 } 01603 bool lowercase_html_names() const { return lowercase_html_names_.value(); } 01604 01605 void set_always_rewrite_css(bool x) { 01606 set_option(x, &always_rewrite_css_); 01607 } 01608 bool always_rewrite_css() const { return always_rewrite_css_.value(); } 01609 01610 void set_respect_vary(bool x) { 01611 set_option(x, &respect_vary_); 01612 } 01613 bool respect_vary() const { return respect_vary_.value(); } 01614 01615 void set_respect_x_forwarded_proto(bool x) { 01616 set_option(x, &respect_x_forwarded_proto_); 01617 } 01618 bool respect_x_forwarded_proto() const { 01619 return respect_x_forwarded_proto_.value(); 01620 } 01621 01622 void set_flush_html(bool x) { set_option(x, &flush_html_); } 01623 bool flush_html() const { return flush_html_.value(); } 01624 01625 void set_serve_split_html_in_two_chunks(bool x) { 01626 set_option(x, &serve_split_html_in_two_chunks_); 01627 } 01628 bool serve_split_html_in_two_chunks() const { 01629 return serve_split_html_in_two_chunks_.value(); 01630 } 01631 01632 void set_serve_stale_if_fetch_error(bool x) { 01633 set_option(x, &serve_stale_if_fetch_error_); 01634 } 01635 bool serve_stale_if_fetch_error() const { 01636 return serve_stale_if_fetch_error_.value(); 01637 } 01638 01639 void set_serve_ghost_click_buster_with_split_html(bool x) { 01640 set_option(x, &serve_ghost_click_buster_with_split_html_); 01641 } 01642 bool serve_ghost_click_buster_with_split_html() const { 01643 return serve_ghost_click_buster_with_split_html_.value(); 01644 } 01645 01646 void set_serve_xhr_access_control_headers(bool x) { 01647 set_option(x, &serve_xhr_access_control_headers_); 01648 } 01649 bool serve_xhr_access_control_headers() const { 01650 return serve_xhr_access_control_headers_.value(); 01651 } 01652 01653 void set_proactively_freshen_user_facing_request(bool x) { 01654 set_option(x, &proactively_freshen_user_facing_request_); 01655 } 01656 bool proactively_freshen_user_facing_request() const { 01657 return proactively_freshen_user_facing_request_.value(); 01658 } 01659 01660 void set_serve_stale_while_revalidate_threshold_sec(int64 x) { 01661 set_option(x, &serve_stale_while_revalidate_threshold_sec_); 01662 } 01663 int64 serve_stale_while_revalidate_threshold_sec() const { 01664 return serve_stale_while_revalidate_threshold_sec_.value(); 01665 } 01666 01667 void set_enable_flush_early_critical_css(bool x) { 01668 set_option(x, &enable_flush_early_critical_css_); 01669 } 01670 bool enable_flush_early_critical_css() const { 01671 return enable_flush_early_critical_css_.value(); 01672 } 01673 01674 void set_use_selectors_for_critical_css(bool x) { 01675 set_option(x, &use_selectors_for_critical_css_); 01676 } 01677 bool use_selectors_for_critical_css() const { 01678 return use_selectors_for_critical_css_.value(); 01679 } 01680 01681 void set_default_cache_html(bool x) { set_option(x, &default_cache_html_); } 01682 bool default_cache_html() const { return default_cache_html_.value(); } 01683 01684 void set_modify_caching_headers(bool x) { 01685 set_option(x, &modify_caching_headers_); 01686 } 01687 bool modify_caching_headers() const { 01688 return modify_caching_headers_.value(); 01689 } 01690 01691 void set_inline_only_critical_images(bool x) { 01692 set_option(x, &inline_only_critical_images_); 01693 } 01694 bool inline_only_critical_images() const { 01695 return inline_only_critical_images_.value(); 01696 } 01697 01698 void set_critical_images_beacon_enabled(bool x) { 01699 set_option(x, &critical_images_beacon_enabled_); 01700 } 01701 bool critical_images_beacon_enabled() const { 01702 return critical_images_beacon_enabled_.value(); 01703 } 01704 01705 void set_beacon_reinstrument_time_sec(int x) { 01706 set_option(x, &beacon_reinstrument_time_sec_); 01707 } 01708 int beacon_reinstrument_time_sec() const { 01709 return beacon_reinstrument_time_sec_.value(); 01710 } 01711 01712 void set_request_option_override(StringPiece p) { 01713 set_option(GoogleString(p.data(), p.size()), &request_option_override_); 01714 } 01715 const GoogleString& request_option_override() const { 01716 return request_option_override_.value(); 01717 } 01718 01719 void set_lazyload_images_after_onload(bool x) { 01720 set_option(x, &lazyload_images_after_onload_); 01721 } 01722 bool lazyload_images_after_onload() const { 01723 return lazyload_images_after_onload_.value(); 01724 } 01725 01726 void set_lazyload_images_blank_url(const StringPiece& p) { 01727 set_option(GoogleString(p.data(), p.size()), &lazyload_images_blank_url_); 01728 } 01729 const GoogleString& lazyload_images_blank_url() const { 01730 return lazyload_images_blank_url_.value(); 01731 } 01732 01733 void set_max_inlined_preview_images_index(int x) { 01734 set_option(x, &max_inlined_preview_images_index_); 01735 } 01736 int max_inlined_preview_images_index() const { 01737 return max_inlined_preview_images_index_.value(); 01738 } 01739 01740 void set_use_blank_image_for_inline_preview(bool x) { 01741 set_option(x, &use_blank_image_for_inline_preview_); 01742 } 01743 bool use_blank_image_for_inline_preview() const { 01744 return use_blank_image_for_inline_preview_.value(); 01745 } 01746 01747 void set_min_image_size_low_resolution_bytes(int64 x) { 01748 set_option(x, &min_image_size_low_resolution_bytes_); 01749 } 01750 int64 min_image_size_low_resolution_bytes() const { 01751 return min_image_size_low_resolution_bytes_.value(); 01752 } 01753 01754 void set_max_image_size_low_resolution_bytes(int64 x) { 01755 set_option(x, &max_image_size_low_resolution_bytes_); 01756 } 01757 int64 max_image_size_low_resolution_bytes() const { 01758 return max_image_size_low_resolution_bytes_.value(); 01759 } 01760 01761 void set_experiment_cookie_duration_ms(int64 x) { 01762 set_option(x, &experiment_cookie_duration_ms_); 01763 } 01764 int64 experiment_cookie_duration_ms() const { 01765 return experiment_cookie_duration_ms_.value(); 01766 } 01767 01768 void set_finder_properties_cache_expiration_time_ms(int64 x) { 01769 set_option(x, &finder_properties_cache_expiration_time_ms_); 01770 } 01771 int64 finder_properties_cache_expiration_time_ms() const { 01772 return finder_properties_cache_expiration_time_ms_.value(); 01773 } 01774 01775 void set_finder_properties_cache_refresh_time_ms(int64 x) { 01776 set_option(x, &finder_properties_cache_refresh_time_ms_); 01777 } 01778 int64 finder_properties_cache_refresh_time_ms() const { 01779 return finder_properties_cache_refresh_time_ms_.value(); 01780 } 01781 01782 void set_rewrite_random_drop_percentage(int x) { 01783 set_option(x, &rewrite_random_drop_percentage_); 01784 } 01785 int rewrite_random_drop_percentage() const { 01786 return rewrite_random_drop_percentage_.value(); 01787 } 01788 01789 bool css_preserve_urls() const { 01790 return CheckBandwidthOption(css_preserve_urls_); 01791 } 01792 void set_css_preserve_urls(bool x) { 01793 set_option(x, &css_preserve_urls_); 01794 } 01795 01796 bool image_preserve_urls() const { 01797 return CheckBandwidthOption(image_preserve_urls_); 01798 } 01799 void set_image_preserve_urls(bool x) { 01800 set_option(x, &image_preserve_urls_); 01801 } 01802 01803 bool js_preserve_urls() const { 01804 return CheckBandwidthOption(js_preserve_urls_); 01805 } 01806 void set_js_preserve_urls(bool x) { 01807 set_option(x, &js_preserve_urls_); 01808 } 01809 01810 void set_metadata_cache_staleness_threshold_ms(int64 x) { 01811 set_option(x, &metadata_cache_staleness_threshold_ms_); 01812 } 01813 int64 metadata_cache_staleness_threshold_ms() const { 01814 return metadata_cache_staleness_threshold_ms_.value(); 01815 } 01816 01817 void set_metadata_input_errors_cache_ttl_ms(int64 x) { 01818 set_option(x, &metadata_input_errors_cache_ttl_ms_); 01819 } 01820 int64 metadata_input_errors_cache_ttl_ms() const { 01821 return metadata_input_errors_cache_ttl_ms_.value(); 01822 } 01823 01824 const GoogleString& downstream_cache_purge_method() const { 01825 return downstream_cache_purge_method_.value(); 01826 } 01827 void set_downstream_cache_purge_method(const StringPiece& p) { 01828 set_option(p.as_string(), &downstream_cache_purge_method_); 01829 } 01830 01831 const GoogleString& downstream_cache_purge_location_prefix() const { 01832 return downstream_cache_purge_location_prefix_.value(); 01833 } 01834 void set_downstream_cache_purge_location_prefix(StringPiece p) { 01837 while (p.ends_with("/")) { 01838 p.remove_suffix(1); 01839 } 01840 set_option(p.as_string(), &downstream_cache_purge_location_prefix_); 01841 } 01842 bool IsDownstreamCacheIntegrationEnabled() const { 01843 return !downstream_cache_purge_location_prefix().empty(); 01844 } 01845 01846 void set_downstream_cache_rebeaconing_key(const StringPiece& p) { 01847 set_option(p.as_string(), &downstream_cache_rebeaconing_key_); 01848 } 01849 const GoogleString& downstream_cache_rebeaconing_key() const { 01850 return downstream_cache_rebeaconing_key_.value(); 01851 } 01852 bool IsDownstreamCacheRebeaconingKeyConfigured() const { 01853 return !downstream_cache_rebeaconing_key().empty(); 01854 } 01857 bool MatchesDownstreamCacheRebeaconingKey(StringPiece key) const { 01858 if (!IsDownstreamCacheRebeaconingKeyConfigured()) { 01859 return false; 01860 } 01861 return StringCaseEqual(key, downstream_cache_rebeaconing_key()); 01862 } 01863 01864 void set_downstream_cache_rewritten_percentage_threshold(int64 x) { 01865 set_option(x, &downstream_cache_rewritten_percentage_threshold_); 01866 } 01867 int64 downstream_cache_rewritten_percentage_threshold() const { 01868 return downstream_cache_rewritten_percentage_threshold_.value(); 01869 } 01870 01871 const BeaconUrl& beacon_url() const { return beacon_url_.value(); } 01872 void set_beacon_url(const GoogleString& beacon_url) { 01873 GoogleString ignored_error_detail; 01874 beacon_url_.SetFromString(beacon_url, &ignored_error_detail); 01875 } 01876 01878 virtual bool trim_urls_in_css() const { return true; } 01879 01880 int64 image_jpeg_recompress_quality() const { 01881 return image_jpeg_recompress_quality_.value(); 01882 } 01883 void set_image_jpeg_recompress_quality(int64 x) { 01884 set_option(x, &image_jpeg_recompress_quality_); 01885 } 01886 01887 int64 image_jpeg_recompress_quality_for_small_screens() const { 01888 return image_jpeg_recompress_quality_for_small_screens_.value(); 01889 } 01890 void set_image_jpeg_recompress_quality_for_small_screens(int64 x) { 01891 set_option(x, &image_jpeg_recompress_quality_for_small_screens_); 01892 } 01893 01894 int64 image_recompress_quality() const { 01895 return image_recompress_quality_.value(); 01896 } 01897 void set_image_recompress_quality(int64 x) { 01898 set_option(x, &image_recompress_quality_); 01899 } 01900 01901 int image_limit_optimized_percent() const { 01902 return image_limit_optimized_percent_.value(); 01903 } 01904 void set_image_limit_optimized_percent(int x) { 01905 set_option(x, &image_limit_optimized_percent_); 01906 } 01907 int image_limit_resize_area_percent() const { 01908 return image_limit_resize_area_percent_.value(); 01909 } 01910 void set_image_limit_resize_area_percent(int x) { 01911 set_option(x, &image_limit_resize_area_percent_); 01912 } 01913 01914 int image_limit_rendered_area_percent() const { 01915 return image_limit_rendered_area_percent_.value(); 01916 } 01917 void set_image_limit_rendered_area_percent(int x) { 01918 set_option(x, &image_limit_rendered_area_percent_); 01919 } 01920 01921 int64 image_jpeg_num_progressive_scans() const { 01922 return image_jpeg_num_progressive_scans_.value(); 01923 } 01924 void set_image_jpeg_num_progressive_scans(int64 x) { 01925 set_option(x, &image_jpeg_num_progressive_scans_); 01926 } 01927 01928 int64 image_jpeg_num_progressive_scans_for_small_screens() const { 01929 return image_jpeg_num_progressive_scans_for_small_screens_.value(); 01930 } 01931 void set_image_jpeg_num_progressive_scans_for_small_screens(int64 x) { 01932 set_option(x, &image_jpeg_num_progressive_scans_for_small_screens_); 01933 } 01934 01935 int64 image_webp_recompress_quality() const { 01936 return image_webp_recompress_quality_.value(); 01937 } 01938 void set_image_webp_recompress_quality(int64 x) { 01939 set_option(x, &image_webp_recompress_quality_); 01940 } 01941 01942 int64 image_webp_recompress_quality_for_small_screens() const { 01943 return image_webp_recompress_quality_for_small_screens_.value(); 01944 } 01945 void set_image_webp_recompress_quality_for_small_screens(int64 x) { 01946 set_option(x, &image_webp_recompress_quality_for_small_screens_); 01947 } 01948 int64 image_webp_timeout_ms() const { 01949 return image_webp_timeout_ms_.value(); 01950 } 01951 void set_image_webp_timeout_ms(int64 x) { 01952 set_option(x, &image_webp_timeout_ms_); 01953 } 01954 01955 bool domain_rewrite_hyperlinks() const { 01956 return domain_rewrite_hyperlinks_.value(); 01957 } 01958 void set_domain_rewrite_hyperlinks(bool x) { 01959 set_option(x, &domain_rewrite_hyperlinks_); 01960 } 01961 01962 bool client_domain_rewrite() const { 01963 return client_domain_rewrite_.value(); 01964 } 01965 void set_client_domain_rewrite(bool x) { 01966 set_option(x, &client_domain_rewrite_); 01967 } 01968 01969 void set_flush_more_resources_early_if_time_permits(bool x) { 01970 set_option(x, &flush_more_resources_early_if_time_permits_); 01971 } 01972 bool flush_more_resources_early_if_time_permits() const { 01973 return flush_more_resources_early_if_time_permits_.value(); 01974 } 01975 01976 void set_flush_more_resources_in_ie_and_firefox(bool x) { 01977 set_option(x, &flush_more_resources_in_ie_and_firefox_); 01978 } 01979 bool flush_more_resources_in_ie_and_firefox() const { 01980 return flush_more_resources_in_ie_and_firefox_.value(); 01981 } 01982 01983 void set_max_prefetch_js_elements(int x) { 01984 set_option(x, &max_prefetch_js_elements_); 01985 } 01986 int max_prefetch_js_elements() const { 01987 return max_prefetch_js_elements_.value(); 01988 } 01989 01990 void set_enable_defer_js_experimental(bool x) { 01991 set_option(x, &enable_defer_js_experimental_); 01992 } 01993 bool enable_defer_js_experimental() const { 01994 return enable_defer_js_experimental_.value(); 01995 } 01996 01997 void set_disable_rewrite_on_no_transform(bool x) { 01998 set_option(x, &disable_rewrite_on_no_transform_); 01999 } 02000 bool disable_rewrite_on_no_transform() const { 02001 return disable_rewrite_on_no_transform_.value(); 02002 } 02003 02004 void set_disable_background_fetches_for_bots(bool x) { 02005 set_option(x, &disable_background_fetches_for_bots_); 02006 } 02007 bool disable_background_fetches_for_bots() const { 02008 return disable_background_fetches_for_bots_.value(); 02009 } 02010 02011 void set_enable_cache_purge(bool x) { 02012 set_option(x, &enable_cache_purge_); 02013 } 02014 bool enable_cache_purge() const { 02015 return enable_cache_purge_.value(); 02016 } 02017 02018 void set_proactive_resource_freshening(bool x) { 02019 set_option(x, &proactive_resource_freshening_); 02020 } 02021 bool proactive_resource_freshening() const { 02022 return proactive_resource_freshening_.value(); 02023 } 02024 02025 void set_lazyload_highres_images(bool x) { 02026 set_option(x, &lazyload_highres_images_); 02027 } 02028 bool lazyload_highres_images() const { 02029 return lazyload_highres_images_.value(); 02030 } 02031 02032 void set_enable_blink_debug_dashboard(bool x) { 02033 set_option(x, &enable_blink_debug_dashboard_); 02034 } 02035 bool enable_blink_debug_dashboard() const { 02036 return enable_blink_debug_dashboard_.value(); 02037 } 02038 02039 void set_enable_blink_html_change_detection(bool x) { 02040 set_option(x, &enable_blink_html_change_detection_); 02041 } 02042 bool enable_blink_html_change_detection() const { 02043 return enable_blink_html_change_detection_.value(); 02044 } 02045 02046 void set_enable_blink_html_change_detection_logging(bool x) { 02047 set_option(x, &enable_blink_html_change_detection_logging_); 02048 } 02049 bool enable_blink_html_change_detection_logging() const { 02050 return enable_blink_html_change_detection_logging_.value(); 02051 } 02052 02053 void set_use_smart_diff_in_blink(bool x) { 02054 set_option(x, &use_smart_diff_in_blink_); 02055 } 02056 bool use_smart_diff_in_blink() const { 02057 return use_smart_diff_in_blink_.value(); 02058 } 02059 02060 void set_use_fallback_property_cache_values(bool x) { 02061 set_option(x, &use_fallback_property_cache_values_); 02062 } 02063 bool use_fallback_property_cache_values() const { 02064 return use_fallback_property_cache_values_.value(); 02065 } 02066 02067 void set_await_pcache_lookup(bool x) { 02068 set_option(x, &await_pcache_lookup_); 02069 } 02070 bool await_pcache_lookup() const { 02071 return await_pcache_lookup_.value(); 02072 } 02073 02074 void set_enable_prioritizing_scripts(bool x) { 02075 set_option(x, &enable_prioritizing_scripts_); 02076 } 02077 bool enable_prioritizing_scripts() const { 02078 return enable_prioritizing_scripts_.value(); 02079 } 02080 02081 void set_blink_html_change_detection_time_ms(int64 x) { 02082 set_option(x, &blink_html_change_detection_time_ms_); 02083 } 02084 int64 blink_html_change_detection_time_ms() const { 02085 return blink_html_change_detection_time_ms_.value(); 02086 } 02087 02088 const GoogleString& blocking_rewrite_key() const { 02089 return blocking_rewrite_key_.value(); 02090 } 02091 void set_blocking_rewrite_key(const StringPiece& p) { 02092 set_option(p.as_string(), &blocking_rewrite_key_); 02093 } 02094 02095 void EnableBlockingRewriteForRefererUrlPattern( 02096 const StringPiece& url_pattern) { 02097 Modify(); 02098 blocking_rewrite_referer_urls_.MakeWriteable()->Allow(url_pattern); 02099 } 02100 02101 bool IsBlockingRewriteEnabledForReferer(const StringPiece& url) const { 02102 return blocking_rewrite_referer_urls_->Match(url, false); 02103 } 02104 02105 bool IsBlockingRewriteRefererUrlPatternPresent() const { 02106 return blocking_rewrite_referer_urls_->num_wildcards() > 0; 02107 } 02108 02109 bool rewrite_uncacheable_resources() const { 02110 return rewrite_uncacheable_resources_.value(); 02111 } 02112 02113 void set_rewrite_uncacheable_resources(bool x) { 02114 set_option(x, &rewrite_uncacheable_resources_); 02115 } 02116 02117 void set_running_experiment(bool x) { 02118 set_option(x, &running_experiment_); 02119 } 02120 bool running_experiment() const { 02121 return running_experiment_.value(); 02122 } 02123 02125 void set_experiment_ga_slot(int x) { 02126 set_option(x, &experiment_ga_slot_); 02127 } 02128 int experiment_ga_slot() const { return experiment_ga_slot_.value(); } 02129 02130 void set_enroll_experiment_id(int x) { 02131 set_option(x, &enroll_experiment_id_); 02132 } 02133 int enroll_experiment_id() const { return enroll_experiment_id_.value(); } 02134 02135 void set_report_unload_time(bool x) { 02136 set_option(x, &report_unload_time_); 02137 } 02138 bool report_unload_time() const { 02139 return report_unload_time_.value(); 02140 } 02141 02142 void set_implicit_cache_ttl_ms(int64 x) { 02143 set_option(x, &implicit_cache_ttl_ms_); 02144 } 02145 int64 implicit_cache_ttl_ms() const { 02146 return implicit_cache_ttl_ms_.value(); 02147 } 02148 02149 void set_x_header_value(const StringPiece& p) { 02150 set_option(p.as_string(), &x_header_value_); 02151 } 02152 const GoogleString& x_header_value() const { 02153 return x_header_value_.value(); 02154 } 02155 02156 void set_distributed_rewrite_key(const StringPiece& p) { 02157 set_option(p.as_string(), &distributed_rewrite_key_); 02158 } 02159 const GoogleString& distributed_rewrite_key() const { 02160 return distributed_rewrite_key_.value(); 02161 } 02162 02163 void set_distribute_fetches(bool x) { 02164 set_option(x, &distribute_fetches_); 02165 } 02166 bool distribute_fetches() const { 02167 return distribute_fetches_.value(); 02168 } 02169 02170 void set_distributed_rewrite_servers(const StringPiece& p) { 02171 set_option(p.as_string(), &distributed_rewrite_servers_); 02172 } 02173 const GoogleString& distributed_rewrite_servers() const { 02174 return distributed_rewrite_servers_.value(); 02175 } 02176 02177 void set_distributed_rewrite_timeout_ms(const int64 x) { 02178 set_option(x, &distributed_rewrite_timeout_ms_); 02179 } 02180 int64 distributed_rewrite_timeout_ms() const { 02181 return distributed_rewrite_timeout_ms_.value(); 02182 } 02183 02184 void set_avoid_renaming_introspective_javascript(bool x) { 02185 set_option(x, &avoid_renaming_introspective_javascript_); 02186 } 02187 bool avoid_renaming_introspective_javascript() const { 02188 return avoid_renaming_introspective_javascript_.value(); 02189 } 02190 02191 int64 blink_max_html_size_rewritable() const { 02192 return blink_max_html_size_rewritable_.value(); 02193 } 02194 void set_blink_max_html_size_rewritable(int64 x) { 02195 set_option(x, &blink_max_html_size_rewritable_); 02196 } 02197 02198 void set_critical_line_config(const StringPiece& p) { 02199 set_option(GoogleString(p.data(), p.size()), &critical_line_config_); 02200 } 02201 const GoogleString& critical_line_config() const { 02202 return critical_line_config_.value(); 02203 } 02204 02205 void set_forbid_all_disabled_filters(bool x) { 02206 set_option(x, &forbid_all_disabled_filters_); 02207 } 02208 bool forbid_all_disabled_filters() const { 02209 return forbid_all_disabled_filters_.value(); 02210 } 02211 02212 bool reject_blacklisted() const { return reject_blacklisted_.value(); } 02213 void set_reject_blacklisted(bool x) { 02214 set_option(x, &reject_blacklisted_); 02215 } 02216 02217 HttpStatus::Code reject_blacklisted_status_code() const { 02218 return static_cast<HttpStatus::Code>( 02219 reject_blacklisted_status_code_.value()); 02220 } 02221 void set_reject_blacklisted_status_code(HttpStatus::Code x) { 02222 set_option(static_cast<int>(x), &reject_blacklisted_status_code_); 02223 } 02224 02225 bool support_noscript_enabled() const { 02226 return support_noscript_enabled_.value(); 02227 } 02228 void set_support_noscript_enabled(bool x) { 02229 set_option(x, &support_noscript_enabled_); 02230 } 02231 02232 bool enable_extended_instrumentation() const { 02233 return enable_extended_instrumentation_.value(); 02234 } 02235 void set_enable_extended_instrumentation(bool x) { 02236 set_option(x, &enable_extended_instrumentation_); 02237 } 02238 02239 bool use_experimental_js_minifier() const { 02240 return use_experimental_js_minifier_.value(); 02241 } 02242 void set_use_experimental_js_minifier(bool x) { 02243 set_option(x, &use_experimental_js_minifier_); 02244 } 02245 02246 void set_max_combined_css_bytes(int64 x) { 02247 set_option(x, &max_combined_css_bytes_); 02248 } 02249 int64 max_combined_css_bytes() const { 02250 return max_combined_css_bytes_.value(); 02251 } 02252 02253 void set_max_combined_js_bytes(int64 x) { 02254 set_option(x, &max_combined_js_bytes_); 02255 } 02256 int64 max_combined_js_bytes() const { 02257 return max_combined_js_bytes_.value(); 02258 } 02259 02260 void set_pre_connect_url(const StringPiece& p) { 02261 set_option(GoogleString(p.data(), p.size()), &pre_connect_url_); 02262 } 02263 const GoogleString& pre_connect_url() const { 02264 return pre_connect_url_.value(); 02265 } 02266 void set_property_cache_http_status_stability_threshold(int x) { 02267 set_option(x, &property_cache_http_status_stability_threshold_); 02268 } 02269 int property_cache_http_status_stability_threshold() const { 02270 return property_cache_http_status_stability_threshold_.value(); 02271 } 02272 02273 void set_max_rewrite_info_log_size(int x) { 02274 set_option(x, &max_rewrite_info_log_size_); 02275 } 02276 int max_rewrite_info_log_size() const { 02277 return max_rewrite_info_log_size_.value(); 02278 } 02279 02280 void set_enable_aggressive_rewriters_for_mobile(bool x) { 02281 set_option(x, &enable_aggressive_rewriters_for_mobile_); 02282 } 02283 bool enable_aggressive_rewriters_for_mobile() const { 02284 return enable_aggressive_rewriters_for_mobile_.value(); 02285 } 02286 02287 void set_allow_logging_urls_in_log_record(bool x) { 02288 set_option(x, &allow_logging_urls_in_log_record_); 02289 } 02290 bool allow_logging_urls_in_log_record() const { 02291 return allow_logging_urls_in_log_record_.value(); 02292 } 02293 02294 void set_allow_options_to_be_set_by_cookies(bool x) { 02295 set_option(x, &allow_options_to_be_set_by_cookies_); 02296 } 02297 bool allow_options_to_be_set_by_cookies() const { 02298 return allow_options_to_be_set_by_cookies_.value(); 02299 } 02300 02301 void set_non_cacheables_for_cache_partial_html(const StringPiece& p) { 02302 set_option(p.as_string(), &non_cacheables_for_cache_partial_html_); 02303 } 02304 const GoogleString& non_cacheables_for_cache_partial_html() const { 02305 return non_cacheables_for_cache_partial_html_.value(); 02306 } 02307 02308 void set_no_transform_optimized_images(bool x) { 02309 set_option(x, &no_transform_optimized_images_); 02310 } 02311 bool no_transform_optimized_images() const { 02312 return no_transform_optimized_images_.value(); 02313 } 02314 02315 void set_access_control_allow_origins(const StringPiece& p) { 02316 set_option(p.as_string(), &access_control_allow_origins_); 02317 } 02318 const GoogleString& access_control_allow_origins() const { 02319 return access_control_allow_origins_.value(); 02320 } 02321 02322 void set_hide_referer_using_meta(bool x) { 02323 set_option(x, &hide_referer_using_meta_); 02324 } 02325 bool hide_referer_using_meta() const { 02326 return hide_referer_using_meta_.value(); 02327 } 02328 02329 void set_max_low_res_image_size_bytes(int64 x) { 02330 set_option(x, &max_low_res_image_size_bytes_); 02331 } 02332 int64 max_low_res_image_size_bytes() const { 02333 return max_low_res_image_size_bytes_.value(); 02334 } 02335 02336 void set_max_low_res_to_full_res_image_size_percentage(int x) { 02337 set_option(x, &max_low_res_to_full_res_image_size_percentage_); 02338 } 02339 int max_low_res_to_full_res_image_size_percentage() const { 02340 return max_low_res_to_full_res_image_size_percentage_.value(); 02341 } 02342 02343 void set_serve_rewritten_webp_urls_to_any_agent(bool x) { 02344 set_option(x, &serve_rewritten_webp_urls_to_any_agent_); 02345 } 02346 bool serve_rewritten_webp_urls_to_any_agent() const { 02347 return serve_rewritten_webp_urls_to_any_agent_.value(); 02348 } 02349 02350 void set_cache_fragment(const StringPiece& p) { 02351 set_option(p.as_string(), &cache_fragment_); 02352 } 02353 const GoogleString& cache_fragment() const { 02354 return cache_fragment_.value(); 02355 } 02356 02357 void set_sticky_query_parameters(StringPiece p) { 02358 set_option(p.as_string(), &sticky_query_parameters_); 02359 } 02360 const GoogleString& sticky_query_parameters() const { 02361 return sticky_query_parameters_.value(); 02362 } 02363 02364 void set_option_cookies_duration_ms(int64 x) { 02365 set_option(x, &option_cookies_duration_ms_); 02366 } 02367 int64 option_cookies_duration_ms() const { 02368 return option_cookies_duration_ms_.value(); 02369 } 02370 02386 virtual void Merge(const RewriteOptions& src); 02387 02390 void Allow(const StringPiece& wildcard_pattern) { 02391 Modify(); 02392 allow_resources_.MakeWriteable()->Allow(wildcard_pattern); 02393 } 02394 02397 void Disallow(const StringPiece& wildcard_pattern) { 02398 Modify(); 02399 allow_resources_.MakeWriteable()->Disallow(wildcard_pattern); 02400 } 02401 02403 void AllowWhenInlining(const StringPiece& wildcard_pattern) { 02404 Modify(); 02405 allow_when_inlining_resources_.MakeWriteable()->Allow(wildcard_pattern); 02406 } 02407 02411 void AllowOnlyWhenInlining(const StringPiece& wildcard_pattern) { 02412 Disallow(wildcard_pattern); 02413 AllowWhenInlining(wildcard_pattern); 02414 } 02415 02417 void DisallowWhenInlining(const StringPiece& wildcard_pattern) { 02418 Modify(); 02419 allow_when_inlining_resources_.MakeWriteable()->Disallow(wildcard_pattern); 02420 } 02421 02425 virtual void DisallowTroublesomeResources(); 02426 02431 virtual void DisallowResourcesForProxy(); 02432 02453 const DomainLawyer* domain_lawyer() const { return domain_lawyer_.get(); } 02454 DomainLawyer* WriteableDomainLawyer(); 02455 02456 FileLoadPolicy* file_load_policy() { return &file_load_policy_; } 02457 const FileLoadPolicy* file_load_policy() const { return &file_load_policy_; } 02458 02461 bool IsAllowed(const StringPiece& url) const { 02462 return allow_resources_->Match(url, true ); 02463 } 02464 02472 bool IsAllowedWhenInlining(const StringPiece& url) const { 02473 return allow_when_inlining_resources_->Match( 02474 url, false ); 02475 } 02476 02478 void RetainComment(const StringPiece& comment) { 02479 Modify(); 02480 retain_comments_.MakeWriteable()->Allow(comment); 02481 } 02482 02486 bool IsRetainedComment(const StringPiece& comment) const { 02487 return retain_comments_->Match(comment, false); 02488 } 02489 02491 void DisableLazyloadForClassName(const StringPiece& class_name) { 02492 Modify(); 02493 lazyload_enabled_classes_.MakeWriteable()->Disallow(class_name); 02494 } 02495 02497 bool IsLazyloadEnabledForClassName(const StringPiece& class_name) const { 02498 return lazyload_enabled_classes_->Match(class_name, true); 02499 } 02500 02501 void set_override_caching_ttl_ms(int64 x) { 02502 set_option(x, &override_caching_ttl_ms_); 02503 } 02504 int64 override_caching_ttl_ms() const { 02505 return override_caching_ttl_ms_.value(); 02506 } 02507 02510 void AddOverrideCacheTtl(const StringPiece& wildcard) { 02511 Modify(); 02512 override_caching_wildcard_.MakeWriteable()->Allow(wildcard); 02513 } 02514 02516 bool IsCacheTtlOverridden(const StringPiece& url) const { 02517 return override_caching_wildcard_->Match(url, false); 02518 } 02519 02520 void AddRejectedUrlWildcard(const GoogleString& wildcard) { 02521 AddRejectedHeaderWildcard(kRejectedRequestUrlKeyName, wildcard); 02522 } 02523 02524 void AddRejectedHeaderWildcard(const StringPiece& header_name, 02525 const GoogleString& wildcard) { 02526 Modify(); 02527 std::pair<FastWildcardGroupMap::iterator, bool> insert_result = 02528 rejected_request_map_.insert(std::make_pair( 02529 header_name, static_cast<FastWildcardGroup*>(NULL))); 02530 02531 if (insert_result.second) { 02532 insert_result.first->second = new FastWildcardGroup; 02533 } 02534 insert_result.first->second->Allow(wildcard); 02535 } 02536 02537 void set_min_cache_ttl_ms(int64 x) { 02538 set_option(x, &min_cache_ttl_ms_); 02539 } 02540 int64 min_cache_ttl_ms() const { 02541 return min_cache_ttl_ms_.value(); 02542 } 02543 02546 bool IsRequestDeclined(const GoogleString& url, 02547 const RequestHeaders* request_headers) const; 02548 02552 virtual RewriteOptions* Clone() const; 02553 02555 virtual RewriteOptions* NewOptions() const; 02556 02562 void ComputeSignature(); 02563 02568 void Freeze(); 02569 02576 void ClearSignatureWithCaution(); 02577 02578 bool frozen() const { return frozen_; } 02579 02583 bool ClearSignatureForTesting() { 02584 bool frozen = frozen_; 02585 ClearSignatureWithCaution(); 02586 return frozen; 02587 } 02588 02590 const GoogleString& signature() const { 02598 ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex()); 02599 DCHECK(frozen_); 02600 DCHECK(!signature_.empty()); 02601 return signature_; 02602 } 02603 02604 virtual GoogleString OptionsToString() const; 02605 GoogleString FilterSetToString(const FilterSet& filter_set) const; 02606 02609 virtual GoogleString ToExperimentString() const; 02610 02614 virtual GoogleString ToExperimentDebugString() const; 02615 02618 static Filter LookupFilterById(const StringPiece& filter_id); 02619 02621 static Filter LookupFilter(const StringPiece& filter_name); 02622 02625 static const PropertyBase* LookupOptionById(StringPiece option_id); 02626 static const PropertyBase* LookupOptionByName(StringPiece option_name); 02627 02630 static const StringPiece LookupOptionNameById(StringPiece option_id); 02631 02633 static bool IsValidOptionName(StringPiece name); 02634 02637 const OptionBaseVector& all_options() const { 02638 return all_options_; 02639 } 02640 02644 bool IsEqual(const RewriteOptions& that) const; 02645 02647 const Hasher* hasher() const { return &hasher_; } 02648 02649 ThreadSystem* thread_system() const { return thread_system_; } 02650 02651 protected: 02661 template<class T> class OptionTemplateBase : public OptionBase { 02662 public: 02663 typedef T ValueType; 02664 02665 OptionTemplateBase() : was_set_(false), property_(NULL) {} 02666 02667 virtual bool was_set() const { return was_set_; } 02668 02669 void set(const T& val) { 02670 was_set_ = true; 02671 value_ = val; 02672 } 02673 02674 void set_default(const T& val) { 02675 if (!was_set_) { 02676 value_ = val; 02677 } 02678 } 02679 02680 const T& value() const { return value_; } 02681 T& mutable_value() { was_set_ = true; return value_; } 02682 02688 virtual void Merge(const OptionBase* src) { 02689 DCHECK(option_name() == src->option_name()); 02690 MergeHelper(static_cast<const OptionTemplateBase*>(src)); 02691 } 02692 02693 void MergeHelper(const OptionTemplateBase* src) { 02696 if (src->was_set_ || !was_set_) { 02697 value_ = src->value_; 02698 was_set_ = src->was_set_; 02699 } 02700 } 02701 02703 void set_property(const Property<T>* property) { 02704 property_ = property; 02705 02710 value_ = property->default_value(); 02711 } 02712 virtual const PropertyBase* property() const { return property_; } 02713 02722 void set_global_default(const T& val) { 02723 Property<T>* property = const_cast<Property<T>*>(property_); 02724 property->set_default(val); 02725 } 02726 02735 void DoNotUseForSignatureComputation() { 02736 Property<T>* property = const_cast<Property<T>*>(property_); 02737 property->set_do_not_use_for_signature_computation(true); 02738 } 02739 02740 private: 02741 bool was_set_; 02742 T value_; 02743 const Property<T>* property_; 02744 02745 DISALLOW_COPY_AND_ASSIGN(OptionTemplateBase); 02746 }; 02747 02752 template<class T> class Option : public OptionTemplateBase<T> { 02753 public: 02754 Option() {} 02755 02757 virtual bool SetFromString(StringPiece value_string, 02758 GoogleString* error_detail) { 02759 T value; 02760 bool success = RewriteOptions::ParseFromString(value_string, &value); 02761 if (success) { 02762 this->set(value); 02763 } 02764 return success; 02765 } 02766 02767 virtual GoogleString Signature(const Hasher* hasher) const { 02768 return RewriteOptions::OptionSignature(this->value(), hasher); 02769 } 02770 02771 virtual GoogleString ToString() const { 02772 return RewriteOptions::ToString(this->value()); 02773 } 02774 02775 private: 02776 DISALLOW_COPY_AND_ASSIGN(Option); 02777 }; 02778 02791 class MutexedOptionInt64MergeWithMax : public Option<int64> { 02792 public: 02793 MutexedOptionInt64MergeWithMax(); 02794 virtual ~MutexedOptionInt64MergeWithMax(); 02795 02800 virtual void Merge(const OptionBase* src_base); 02801 02804 void Merge(const MutexedOptionInt64MergeWithMax* src) 02805 LOCKS_EXCLUDED(src->mutex()); 02806 02817 void checked_set(const int64& value) EXCLUSIVE_LOCKS_REQUIRED(mutex()) { 02818 mutex_->DCheckLocked(); 02819 Option<int64>::set(value); 02820 } 02821 02835 ThreadSystem::RWLock* mutex() const LOCK_RETURNED(mutex_) { 02836 return mutex_.get(); 02837 } 02838 02844 void set_mutex(ThreadSystem::RWLock* lock) { mutex_.reset(lock); } 02845 02846 private: 02847 scoped_ptr<ThreadSystem::RWLock> mutex_; 02848 }; 02849 02850 protected: 02852 template<class RewriteOptionsSubclass, class OptionClass> 02853 static void AddProperty( 02854 typename OptionClass::ValueType default_value, 02855 OptionClass RewriteOptionsSubclass::*offset, 02856 const char* id, 02857 StringPiece option_name, 02858 OptionScope scope, 02859 const char* help_text, 02860 Properties* properties) { 02861 PropertyBase* property = 02862 new PropertyLeaf<RewriteOptionsSubclass, OptionClass>( 02863 default_value, offset, id, option_name); 02864 property->set_scope(scope); 02865 property->set_help_text(help_text); 02866 properties->push_back(property); 02867 } 02868 02882 static void MergeSubclassProperties(Properties* properties); 02883 02889 void set_option_at(int index, OptionBase* option) { 02890 all_options_[index] = option; 02891 } 02892 02896 template<class T> 02897 void set_option(const T& new_value, OptionTemplateBase<T>* option) { 02898 option->set(new_value); 02899 Modify(); 02900 } 02901 02903 void Modify(); 02904 02912 void set_default_x_header_value(const StringPiece& x_header_value) { 02913 x_header_value_.set_global_default(x_header_value.as_string()); 02914 } 02915 02919 bool SetupExperimentRewriters(); 02920 02922 virtual void SetRequiredExperimentFilters(); 02923 02927 bool InsertExperimentSpecInVector(ExperimentSpec* spec); 02928 02930 Option<BeaconUrl> beacon_url_; 02931 02933 Option<GoogleString> x_header_value_; 02934 02935 private: 02937 class CacheFragmentOption : public Option<GoogleString> { 02938 public: 02939 virtual bool SetFromString(StringPiece value_string, 02940 GoogleString* error_detail); 02941 }; 02942 02943 struct OptionIdCompare; 02944 02949 enum MergeOverride { kNoAction, kDisablePreserve, kDisableFilter }; 02950 02953 class PropertyBase { 02954 public: 02955 PropertyBase(const char* id, StringPiece option_name) 02956 : id_(id), 02957 help_text_(NULL), 02958 option_name_(option_name), 02959 scope_(kDirectoryScope), 02960 do_not_use_for_signature_computation_(false), 02961 index_(-1) { 02962 } 02963 virtual ~PropertyBase(); 02964 02967 virtual void InitializeOption(RewriteOptions* options) const = 0; 02968 02969 void set_do_not_use_for_signature_computation(bool x) { 02970 do_not_use_for_signature_computation_ = x; 02971 } 02972 bool is_used_for_signature_computation() const { 02973 return !do_not_use_for_signature_computation_; 02974 } 02975 02976 void set_scope(OptionScope x) { scope_ = x; } 02977 OptionScope scope() const { return scope_; } 02978 02979 void set_help_text(const char* x) { help_text_ = x; } 02980 const char* help_text() const { return help_text_; } 02981 02982 void set_index(int index) { index_ = index; } 02983 const char* id() const { return id_; } 02984 StringPiece option_name() const { return option_name_; } 02985 int index() const { return index_; } 02986 02987 private: 02988 const char* id_; 02989 const char* help_text_; 02990 StringPiece option_name_; 02991 OptionScope scope_; 02992 bool do_not_use_for_signature_computation_; 02993 int index_; 02994 02995 DISALLOW_COPY_AND_ASSIGN(PropertyBase); 02996 }; 02997 03001 template<class ValueType> 03002 class Property : public PropertyBase { 03003 public: 03008 Property(ValueType default_value, 03009 const char* id, 03010 StringPiece option_name) 03011 : PropertyBase(id, option_name), 03012 default_value_(default_value) { 03013 } 03014 03015 void set_default(ValueType value) { default_value_ = value; } 03016 const ValueType& default_value() const { return default_value_; } 03017 03018 private: 03019 ValueType default_value_; 03020 03021 DISALLOW_COPY_AND_ASSIGN(Property); 03022 }; 03023 03038 template<class RewriteOptionsSubclass, class OptionClass> 03039 class PropertyLeaf : public Property<typename OptionClass::ValueType> { 03040 public: 03044 typedef OptionClass RewriteOptionsSubclass::*OptionOffset; 03045 typedef typename OptionClass::ValueType ValueType; 03046 03047 PropertyLeaf(ValueType default_value, 03048 OptionOffset offset, 03049 const char* id, 03050 StringPiece option_name) 03051 : Property<ValueType>(default_value, id, option_name), 03052 offset_(offset) { 03053 } 03054 03055 virtual void InitializeOption(RewriteOptions* options) const { 03056 RewriteOptionsSubclass* options_subclass = 03057 static_cast<RewriteOptionsSubclass*>(options); 03058 OptionClass& option = options_subclass->*offset_; 03059 option.set_property(this); 03060 DCHECK_NE(-1, this->index()) << "Call Property::set_index first."; 03061 options->set_option_at(this->index(), &option); 03062 } 03063 03064 private: 03065 OptionOffset offset_; 03066 03067 DISALLOW_COPY_AND_ASSIGN(PropertyLeaf); 03068 }; 03069 03070 static Properties* properties_; 03071 static Properties* all_properties_; 03072 03073 FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest); 03074 FRIEND_TEST(RewriteOptionsTest, LookupOptionByNameTest); 03075 03077 bool HasRejectedHeader(const StringPiece& header_name, 03078 const RequestHeaders* request_headers) const; 03079 03080 bool IsRejectedUrl(const GoogleString& url) const { 03081 return IsRejectedRequest(kRejectedRequestUrlKeyName, url); 03082 } 03083 03084 bool IsRejectedRequest(const StringPiece& header_name, 03085 const StringPiece& value) const { 03086 FastWildcardGroupMap::const_iterator it = rejected_request_map_.find( 03087 header_name); 03088 if (it != rejected_request_map_.end()) { 03089 return it->second->Match(value, false); 03090 } 03091 return false; 03092 } 03093 03096 JavascriptLibraryIdentification* WriteableJavascriptLibraryIdentification(); 03097 03104 struct PrioritizeVisibleContentFamily { 03105 PrioritizeVisibleContentFamily(StringPiece url_pattern_string, 03106 int64 cache_time_ms_in, 03107 StringPiece non_cacheable_elements_in) 03108 : url_pattern(url_pattern_string), 03109 cache_time_ms(cache_time_ms_in), 03110 non_cacheable_elements(non_cacheable_elements_in.data(), 03111 non_cacheable_elements_in.size()) {} 03112 03113 PrioritizeVisibleContentFamily* Clone() const { 03114 return new PrioritizeVisibleContentFamily( 03115 url_pattern.spec(), cache_time_ms, non_cacheable_elements); 03116 } 03117 03118 GoogleString ComputeSignature() const { 03119 return StrCat(url_pattern.spec(), ";", Integer64ToString(cache_time_ms), 03120 ";", non_cacheable_elements); 03121 } 03122 03123 GoogleString ToString() const { 03124 return StrCat("URL pattern: ", url_pattern.spec(), ", Cache time (ms): ", 03125 Integer64ToString(cache_time_ms), ", Non-cacheable: ", 03126 non_cacheable_elements); 03127 } 03128 03129 Wildcard url_pattern; 03130 int64 cache_time_ms; 03131 GoogleString non_cacheable_elements; 03132 }; 03133 03136 struct UrlCacheInvalidationEntry { 03137 UrlCacheInvalidationEntry(StringPiece url_pattern_in, 03138 int64 timestamp_ms_in, 03139 bool ignores_metadata_and_pcache_in) 03140 : url_pattern(url_pattern_in), 03141 timestamp_ms(timestamp_ms_in), 03142 ignores_metadata_and_pcache(ignores_metadata_and_pcache_in) {} 03143 03144 UrlCacheInvalidationEntry* Clone() const { 03145 return new UrlCacheInvalidationEntry( 03146 url_pattern.spec(), timestamp_ms, ignores_metadata_and_pcache); 03147 } 03148 03149 GoogleString ComputeSignature() const { 03150 if (ignores_metadata_and_pcache) { 03151 return ""; 03152 } 03153 return StrCat(url_pattern.spec(), "@", Integer64ToString(timestamp_ms)); 03154 } 03155 03156 GoogleString ToString() const { 03157 return StrCat( 03158 url_pattern.spec(), ", ", 03159 (ignores_metadata_and_pcache ? "STRICT" : "REFERENCE"), " @ ", 03160 Integer64ToString(timestamp_ms)); 03161 } 03162 03163 Wildcard url_pattern; 03164 int64 timestamp_ms; 03165 bool ignores_metadata_and_pcache; 03166 }; 03167 03168 typedef std::vector<UrlCacheInvalidationEntry*> 03169 UrlCacheInvalidationEntryVector; 03170 typedef dense_hash_map<GoogleString, int64> UrlCacheInvalidationMap; 03171 03175 typedef rde::hash_map<StringPiece, const PropertyBase*, 03176 CaseFoldStringPieceHash, 6, 03177 CaseFoldStringPieceEqual> PropertyNameMap; 03178 03191 template<class OptionClass> 03192 static void AddRequestProperty(typename OptionClass::ValueType default_value, 03193 OptionClass RewriteOptions::*offset, 03194 const char* id) { 03195 AddProperty(default_value, offset, id, kNullOption, kProcessScope, 03196 NULL, properties_); 03197 } 03198 03201 template<class OptionClass> 03202 static void AddBaseProperty(typename OptionClass::ValueType default_value, 03203 OptionClass RewriteOptions::*offset, 03204 const char* id, 03205 StringPiece option_name, 03206 OptionScope scope, 03207 const char* help) { 03208 AddProperty(default_value, offset, id, option_name, scope, help, 03209 properties_); 03210 } 03211 03212 static void AddProperties(); 03213 bool AddCommaSeparatedListToFilterSetState( 03214 const StringPiece& filters, FilterSet* set, MessageHandler* handler); 03215 static bool AddCommaSeparatedListToFilterSet( 03216 const StringPiece& filters, FilterSet* set, MessageHandler* handler); 03218 static void InitFilterIdToEnumArray(); 03219 static void InitOptionIdToPropertyArray(); 03220 static void InitOptionNameToPropertyArray(); 03221 03225 OptionSettingResult FormatSetOptionMessage( 03226 OptionSettingResult result, StringPiece name, StringPiece value, 03227 StringPiece error_detail, GoogleString* msg); 03228 03231 OptionSettingResult SetOptionFromNameInternal( 03232 StringPiece name, StringPiece value, bool from_query, 03233 GoogleString* error_detail); 03234 03237 static GoogleString OptionSignature(bool x, const Hasher* hasher) { 03238 return x ? "T" : "F"; 03239 } 03240 static GoogleString OptionSignature(int x, const Hasher* hasher) { 03241 return IntegerToString(x); 03242 } 03243 static GoogleString OptionSignature(int64 x, const Hasher* hasher) { 03244 return Integer64ToString(x); 03245 } 03246 static GoogleString OptionSignature(const GoogleString& x, 03247 const Hasher* hasher); 03248 static GoogleString OptionSignature(RewriteLevel x, 03249 const Hasher* hasher); 03250 static GoogleString OptionSignature(ResourceCategorySet x, 03251 const Hasher* hasher); 03252 static GoogleString OptionSignature(const BeaconUrl& beacon_url, 03253 const Hasher* hasher); 03254 static GoogleString OptionSignature( 03255 const protobuf::MessageLite& proto, 03256 const Hasher* hasher); 03257 03260 static GoogleString ToString(bool x) { 03261 return x ? "True" : "False"; 03262 } 03263 static GoogleString ToString(int x) { 03264 return IntegerToString(x); 03265 } 03266 static GoogleString ToString(int64 x) { 03267 return Integer64ToString(x); 03268 } 03269 static GoogleString ToString(const GoogleString& x) { 03270 return x; 03271 } 03272 static GoogleString ToString(RewriteLevel x); 03273 static GoogleString ToString(const ResourceCategorySet &x); 03274 static GoogleString ToString(const BeaconUrl& beacon_url); 03275 static GoogleString ToString(const protobuf::MessageLite& proto); 03276 03279 static bool PropertyLessThanByOptionName(PropertyBase* p1, PropertyBase* p2) { 03280 return StringCaseCompare(p1->option_name(), p2->option_name()) < 0; 03281 } 03282 03284 static bool OptionNameLessThanArg(OptionBase* option, StringPiece arg) { 03285 return StringCaseCompare(option->option_name(), arg) < 0; 03286 } 03287 03289 static bool CompareUrlCacheInvalidationEntry(UrlCacheInvalidationEntry* e1, 03290 UrlCacheInvalidationEntry* e2) { 03291 return e1->timestamp_ms < e2->timestamp_ms; 03292 } 03293 03295 static bool FilterEnumToIdAndNameEntryLessThanById( 03296 const FilterEnumToIdAndNameEntry* e1, 03297 const FilterEnumToIdAndNameEntry* e2) { 03298 return strcmp(e1->filter_id, e2->filter_id) < 0; 03299 } 03300 03303 static StringPiece GetEffectiveOptionName(StringPiece name); 03304 03307 bool CheckBandwidthOption(const Option<bool>& option) const { 03308 if (option.was_set() || (level() != kOptimizeForBandwidth)) { 03309 return option.value(); 03310 } 03311 return true; 03312 } 03313 03320 MergeOverride ComputeMergeOverride( 03321 Filter filter, 03322 const Option<bool>& src_preserve_option, 03323 const Option<bool>& preserve_option, 03324 const RewriteOptions& src); 03325 03327 void ApplyMergeOverride( 03328 MergeOverride merge_override, 03329 Filter filter, 03330 Option<bool>* preserve_option); 03331 03332 bool modified_; 03333 bool frozen_; 03334 FilterSet enabled_filters_; 03335 FilterSet disabled_filters_; 03336 FilterSet forbidden_filters_; 03337 03340 FilterIdSet distributable_filters_; 03341 03347 Option<RewriteLevel> level_; 03348 03351 UrlCacheInvalidationEntryVector url_cache_invalidation_entries_; 03352 03354 UrlCacheInvalidationMap url_cache_invalidation_map_; 03355 03356 MutexedOptionInt64MergeWithMax cache_invalidation_timestamp_; 03357 Option<int64> css_flatten_max_bytes_; 03358 Option<bool> cache_small_images_unrewritten_; 03359 Option<bool> no_transform_optimized_images_; 03360 03362 Option<int64> image_resolution_limit_bytes_; 03363 Option<int64> css_image_inline_max_bytes_; 03364 Option<int64> css_inline_max_bytes_; 03365 Option<int64> css_outline_min_bytes_; 03366 03368 Option<bool> css_preserve_urls_; 03369 Option<bool> js_preserve_urls_; 03370 Option<bool> image_preserve_urls_; 03371 03372 Option<int64> image_inline_max_bytes_; 03373 Option<int64> js_inline_max_bytes_; 03374 Option<int64> js_outline_min_bytes_; 03375 Option<int64> progressive_jpeg_min_bytes_; 03377 Option<int64> max_html_cache_time_ms_; 03380 Option<int64> max_html_parse_bytes_; 03382 Option<int64> max_image_bytes_for_webp_in_css_; 03384 Option<int64> min_resource_cache_time_to_rewrite_ms_; 03385 Option<int64> idle_flush_time_ms_; 03386 Option<int64> flush_buffer_limit_bytes_; 03387 03391 Option<int64> blocking_fetch_timeout_ms_; 03392 03395 Option<int64> image_recompress_quality_; 03396 03398 Option<int64> image_jpeg_recompress_quality_; 03399 Option<int64> image_jpeg_recompress_quality_for_small_screens_; 03400 Option<int64> image_jpeg_num_progressive_scans_; 03401 Option<int64> image_jpeg_num_progressive_scans_for_small_screens_; 03402 03404 Option<int> image_limit_optimized_percent_; 03405 Option<int> image_limit_resize_area_percent_; 03406 Option<int> image_limit_rendered_area_percent_; 03407 03409 Option<int64> image_webp_recompress_quality_; 03410 Option<int64> image_webp_recompress_quality_for_small_screens_; 03411 Option<int64> image_webp_timeout_ms_; 03412 03413 Option<int> image_max_rewrites_at_once_; 03414 Option<int> max_url_segment_size_; 03415 Option<int> max_url_size_; 03416 03417 03418 Option<int> rewrite_deadline_ms_; 03420 Option<int> domain_shard_count_; 03421 03422 Option<EnabledEnum> enabled_; 03423 03424 Option<bool> distributable_; 03425 03428 Option<bool> add_options_to_urls_; 03429 03435 Option<bool> publicly_cache_mismatched_hashes_experimental_; 03436 03438 Option<bool> in_place_rewriting_enabled_; 03440 Option<bool> in_place_wait_for_optimized_; 03443 Option<int> in_place_rewrite_deadline_ms_; 03446 Option<bool> in_place_preemptive_rewrite_css_; 03448 Option<bool> in_place_preemptive_rewrite_css_images_; 03451 Option<bool> in_place_preemptive_rewrite_images_; 03454 Option<bool> in_place_preemptive_rewrite_javascript_; 03460 Option<bool> private_not_vary_for_ie_; 03461 Option<bool> combine_across_paths_; 03462 Option<bool> log_background_rewrites_; 03463 Option<bool> log_rewrite_timing_; 03464 Option<bool> log_url_indices_; 03465 Option<bool> lowercase_html_names_; 03466 Option<bool> always_rewrite_css_; 03467 Option<bool> respect_vary_; 03468 Option<bool> respect_x_forwarded_proto_; 03469 Option<bool> flush_html_; 03473 Option<bool> serve_split_html_in_two_chunks_; 03476 Option<bool> serve_stale_if_fetch_error_; 03478 Option<bool> serve_ghost_click_buster_with_split_html_; 03480 Option<bool> serve_xhr_access_control_headers_; 03483 Option<bool> proactively_freshen_user_facing_request_; 03486 Option<int64> serve_stale_while_revalidate_threshold_sec_; 03488 Option<bool> enable_flush_early_critical_css_; 03490 Option<bool> use_selectors_for_critical_css_; 03495 Option<bool> default_cache_html_; 03500 Option<bool> modify_caching_headers_; 03504 Option<bool> lazyload_images_after_onload_; 03507 Option<GoogleString> lazyload_images_blank_url_; 03510 Option<bool> use_blank_image_for_inline_preview_; 03514 Option<bool> inline_only_critical_images_; 03517 Option<bool> critical_images_beacon_enabled_; 03520 Option<bool> client_domain_rewrite_; 03523 Option<bool> domain_rewrite_hyperlinks_; 03526 Option<bool> running_experiment_; 03529 Option<int> experiment_ga_slot_; 03532 Option<int> enroll_experiment_id_; 03533 03536 Option<bool> increase_speed_tracking_; 03537 03541 Option<bool> report_unload_time_; 03542 03543 Option<bool> serve_rewritten_webp_urls_to_any_agent_; 03544 03546 Option<bool> flush_more_resources_early_if_time_permits_; 03547 03549 Option<bool> flush_more_resources_in_ie_and_firefox_; 03550 03553 Option<int> max_prefetch_js_elements_; 03554 03556 Option<bool> enable_defer_js_experimental_; 03557 03559 Option<bool> disable_rewrite_on_no_transform_; 03560 03562 Option<bool> disable_background_fetches_for_bots_; 03563 03573 Option<bool> enable_cache_purge_; 03574 03578 Option<bool> proactive_resource_freshening_; 03579 03581 Option<bool> lazyload_highres_images_; 03582 03585 Option<bool> avoid_renaming_introspective_javascript_; 03586 03588 Option<bool> override_ie_document_mode_; 03589 03591 Option<bool> test_instant_fetch_rewrite_deadline_; 03592 03596 Option<bool> test_only_prioritize_critical_css_dont_apply_original_css_; 03597 03603 Option<GoogleString> blocking_rewrite_key_; 03604 03608 Option<int> beacon_reinstrument_time_sec_; 03609 03612 Option<int> max_inlined_preview_images_index_; 03614 Option<int64> min_image_size_low_resolution_bytes_; 03616 Option<int64> max_image_size_low_resolution_bytes_; 03619 Option<int> rewrite_random_drop_percentage_; 03620 03623 Option<bool> oblivious_pagespeed_urls_; 03624 03626 Option<int64> finder_properties_cache_expiration_time_ms_; 03627 03631 Option<int64> finder_properties_cache_refresh_time_ms_; 03634 Option<int64> experiment_cookie_duration_ms_; 03635 03638 Option<int64> metadata_cache_staleness_threshold_ms_; 03639 03641 Option<int64> metadata_input_errors_cache_ttl_ms_; 03642 03645 Option<GoogleString> downstream_cache_purge_method_; 03646 03648 Option<GoogleString> downstream_cache_purge_location_prefix_; 03649 03652 Option<GoogleString> downstream_cache_rebeaconing_key_; 03653 03659 Option<int64> downstream_cache_rewritten_percentage_threshold_; 03660 03664 Option<int64> implicit_cache_ttl_ms_; 03665 03667 Option<int64> max_cacheable_response_content_length_; 03668 03670 Option<int64> blink_blacklist_end_timestamp_ms_; 03672 Option<bool> persist_blink_blacklist_; 03673 03676 Option<bool> preserve_url_relativity_; 03677 03678 Option<GoogleString> ga_id_; 03679 03680 Option<int64> blink_max_html_size_rewritable_; 03683 Option<int64> blink_html_change_detection_time_ms_; 03685 Option<bool> enable_blink_debug_dashboard_; 03687 Option<bool> enable_blink_html_change_detection_; 03689 Option<bool> enable_blink_html_change_detection_logging_; 03691 Option<bool> use_smart_diff_in_blink_; 03693 Option<bool> use_fallback_property_cache_values_; 03695 Option<bool> await_pcache_lookup_; 03697 Option<bool> enable_prioritizing_scripts_; 03699 Option<bool> rewrite_uncacheable_resources_; 03701 Option<GoogleString> critical_line_config_; 03704 Option<GoogleString> distributed_rewrite_key_; 03706 Option<GoogleString> distributed_rewrite_servers_; 03711 Option<bool> distribute_fetches_; 03714 Option<int64> distributed_rewrite_timeout_ms_; 03720 Option<bool> forbid_all_disabled_filters_; 03722 Option<bool> enable_aggressive_rewriters_for_mobile_; 03723 03729 Option<bool> reject_blacklisted_; 03730 Option<int> reject_blacklisted_status_code_; 03731 03735 Option<bool> support_noscript_enabled_; 03736 03739 Option<bool> enable_extended_instrumentation_; 03740 03741 Option<bool> use_experimental_js_minifier_; 03742 03745 Option<int64> max_combined_css_bytes_; 03746 03749 Option<int64> max_combined_js_bytes_; 03750 03752 Option<GoogleString> pre_connect_url_; 03755 Option<int> property_cache_http_status_stability_threshold_; 03757 Option<int> max_rewrite_info_log_size_; 03758 03763 Option<int64> override_caching_ttl_ms_; 03764 CopyOnWrite<FastWildcardGroup> override_caching_wildcard_; 03765 03769 Option<int64> min_cache_ttl_ms_; 03770 03772 Option<bool> allow_logging_urls_in_log_record_; 03773 03775 Option<bool> allow_options_to_be_set_by_cookies_; 03776 03778 Option<GoogleString> non_cacheables_for_cache_partial_html_; 03779 03783 Option<GoogleString> access_control_allow_origins_; 03784 03786 Option<bool> hide_referer_using_meta_; 03787 03792 Option<int64> max_low_res_image_size_bytes_; 03793 Option<int> max_low_res_to_full_res_image_size_percentage_; 03794 03796 Option<GoogleString> request_option_override_; 03797 03802 Option<GoogleString> sticky_query_parameters_; 03803 Option<int64> option_cookies_duration_ms_; 03804 03807 CacheFragmentOption cache_fragment_; 03808 03811 OptionBaseVector all_options_; 03812 size_t initialized_options_; 03813 03816 static const FilterEnumToIdAndNameEntry* filter_id_to_enum_array_[ 03817 kEndOfFilters]; 03818 03820 static PropertyNameMap* option_name_to_property_map_; 03821 03823 static const PropertyBase** option_id_to_property_array_; 03824 03831 bool options_uniqueness_checked_; 03832 03833 bool need_to_store_experiment_data_; 03834 int experiment_id_; 03835 int experiment_percent_; 03836 std::vector<ExperimentSpec*> experiment_specs_; 03837 03839 std::vector<NameValue*> custom_fetch_headers_; 03840 03843 scoped_ptr<std::vector<ElementAttributeCategory> > url_valued_attributes_; 03844 03845 Option<ResourceCategorySet> inline_unauthorized_resource_types_; 03846 03847 CopyOnWrite<JavascriptLibraryIdentification> 03848 javascript_library_identification_; 03849 03850 CopyOnWrite<DomainLawyer> domain_lawyer_; 03851 FileLoadPolicy file_load_policy_; 03852 03853 CopyOnWrite<FastWildcardGroup> allow_resources_; 03854 CopyOnWrite<FastWildcardGroup> allow_when_inlining_resources_; 03855 CopyOnWrite<FastWildcardGroup> retain_comments_; 03856 CopyOnWrite<FastWildcardGroup> lazyload_enabled_classes_; 03857 03860 CopyOnWrite<FastWildcardGroup> blocking_rewrite_referer_urls_; 03861 03864 typedef std::map<StringPiece, FastWildcardGroup*> FastWildcardGroupMap; 03865 FastWildcardGroupMap rejected_request_map_; 03866 03867 GoogleString signature_; 03868 MD5Hasher hasher_; 03869 03870 ThreadSystem* thread_system_; 03871 03884 scoped_ptr<ThreadSystem::ThreadId> last_thread_id_; 03885 03886 DISALLOW_COPY_AND_ASSIGN(RewriteOptions); 03887 }; 03888 03889 } 03890 03891 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_