Page Speed Optimization Libraries
1.4.26.1
|
00001 /* 00002 * Copyright 2010 Google Inc. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http:///www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00018 00019 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_ 00021 00022 #include <cstddef> 00023 #include <map> 00024 #include <set> 00025 #include <utility> 00026 #include <vector> 00027 00028 #include "base/logging.h" 00029 #include "net/instaweb/http/public/meta_data.h" 00030 #include "net/instaweb/http/public/semantic_type.h" 00031 #include "net/instaweb/rewriter/public/domain_lawyer.h" 00032 #include "net/instaweb/rewriter/public/file_load_policy.h" 00033 #include "net/instaweb/rewriter/public/javascript_library_identification.h" 00034 #include "net/instaweb/util/public/basictypes.h" 00035 #include "net/instaweb/util/public/gtest_prod.h" 00036 #include "net/instaweb/util/public/scoped_ptr.h" 00037 #include "net/instaweb/util/public/string.h" 00038 #include "net/instaweb/util/public/string_util.h" 00039 #include "net/instaweb/util/public/thread_system.h" 00040 #include "third_party/instaweb/util/fast_wildcard_group.h" 00041 #include "third_party/instaweb/util/wildcard.h" 00042 00043 namespace net_instaweb { 00044 00045 class GoogleUrl; 00046 class Hasher; 00047 class MessageHandler; 00048 00069 class RewriteOptions { 00070 public: 00077 enum Filter { 00078 kAddBaseTag, 00079 kAddHead, 00080 kAddInstrumentation, 00081 kComputeStatistics, 00082 kCacheHtml, 00083 kCanonicalizeJavascriptLibraries, 00084 kCollapseWhitespace, 00085 kCollectFlushEarlyContentFilter, 00086 kCombineCss, 00087 kCombineHeads, 00088 kCombineJavascript, 00089 kComputeCriticalCss, 00090 kComputeVisibleText, 00091 kConvertGifToPng, 00092 kConvertJpegToProgressive, 00093 kConvertJpegToWebp, 00094 kConvertMetaTags, 00095 kConvertPngToJpeg, 00096 kConvertToWebpLossless, 00097 kDebug, 00098 kDecodeRewrittenUrls, 00099 kDeferIframe, 00100 kDeferJavascript, 00101 kDelayImages, 00102 kDetectReflowWithDeferJavascript, 00103 kDeterministicJs, 00104 kDisableJavascript, 00105 kDivStructure, 00106 kElideAttributes, 00107 kExperimentSpdy, 00108 kExplicitCloseTags, 00109 kExtendCacheCss, 00110 kExtendCacheImages, 00111 kExtendCachePdfs, 00112 kExtendCacheScripts, 00113 kFallbackRewriteCssUrls, 00114 kFlattenCssImports, 00115 kFlushSubresources, 00116 kHandleNoscriptRedirect, 00117 kHtmlWriterFilter, 00118 kInlineCss, 00119 kInlineImages, 00120 kInlineImportToLink, 00121 kInlineJavascript, 00122 kInPlaceOptimizeForBrowser, 00123 kInsertDnsPrefetch, 00124 kInsertGA, 00125 kInsertImageDimensions, 00126 kJpegSubsampling, 00127 kLazyloadImages, 00128 kLeftTrimUrls, 00129 kLocalStorageCache, 00130 kMakeGoogleAnalyticsAsync, 00131 kMoveCssAboveScripts, 00132 kMoveCssToHead, 00133 kOutlineCss, 00134 kOutlineJavascript, 00135 kPedantic, 00136 kPrioritizeCriticalCss, 00137 kPrioritizeVisibleContent, 00138 kProcessBlinkInBackground, 00139 kRecompressJpeg, 00140 kRecompressPng, 00141 kRecompressWebp, 00142 kRemoveComments, 00143 kRemoveQuotes, 00144 kResizeImages, 00145 kResizeMobileImages, 00146 kRewriteCss, 00147 kRewriteDomains, 00148 kRewriteJavascript, 00149 kRewriteStyleAttributes, 00150 kRewriteStyleAttributesWithUrl, 00151 kServeNonCacheableNonCritical, 00152 kSplitHtml, 00153 kSpriteImages, 00154 kSquashImagesForMobileScreen, 00155 kStripImageColorProfile, 00156 kStripImageMetaData, 00157 kStripNonCacheable, 00158 kStripScripts, 00159 kEndOfFilters 00160 }; 00161 00162 enum EnabledEnum { 00165 kEnabledOff, 00167 kEnabledOn, 00170 kEnabledUnplugged, 00171 }; 00172 00179 enum OptionEnum { 00180 kAddOptionsToUrls, 00181 kAllowLoggingUrlsInLogRecord, 00182 kAlwaysRewriteCss, 00183 kAnalyticsID, 00184 kAvoidRenamingIntrospectiveJavascript, 00185 kBeaconReinstrumentTimeSec, 00186 kBeaconUrl, 00187 kBlinkDesktopUserAgent, 00188 kBlinkMaxHtmlSizeRewritable, 00189 kBlinkNonCacheablesForAllFamilies, 00190 kCacheInvalidationTimestamp, 00191 kCacheSmallImagesUnrewritten, 00192 kClientDomainRewrite, 00193 kCombineAcrossPaths, 00194 kCriticalImagesBeaconEnabled, 00195 kCriticalLineConfig, 00196 kCssFlattenMaxBytes, 00197 kCssImageInlineMaxBytes, 00198 kCssInlineMaxBytes, 00199 kCssOutlineMinBytes, 00200 kCssPreserveURLs, 00201 kDefaultCacheHtml, 00202 kDistributedRewriteServers, 00203 kDistributedRewriteTimeoutMs, 00204 kDomainRewriteHyperlinks, 00205 kDomainShardCount, 00206 kEnableAggressiveRewritersForMobile, 00207 kEnableBlinkCriticalLine, 00208 kEnableBlinkDashboard, 00209 kEnableBlinkForMobileDevices, 00210 kEnableBlinkHtmlChangeDetection, 00211 kEnableBlinkHtmlChangeDetectionLogging, 00212 kEnableDeferJsExperimental, 00213 kEnableFlushSubresourcesExperimental, 00214 kEnableInlinePreviewImagesExperimental, 00215 kEnableLazyLoadHighResImages, 00216 kEnableLazyloadInBlink, 00217 kEnablePrioritizingScripts, 00218 kEnabled, 00219 kFinderPropertiesCacheExpirationTimeMs, 00220 kFinderPropertiesCacheRefreshTimeMs, 00221 kFlushBufferLimitBytes, 00222 kFlushHtml, 00223 kFlushMoreResourcesEarlyIfTimePermits, 00224 kForbidAllDisabledFilters, 00225 kFuriousCookieDurationMs, 00226 kFuriousSlot, 00227 kIdleFlushTimeMs, 00228 kImageInlineMaxBytes, 00229 kImageJpegNumProgressiveScans, 00230 kImageJpegNumProgressiveScansForSmallScreens, 00231 kImageJpegRecompressionQuality, 00232 kImageJpegRecompressionQualityForSmallScreens, 00233 kImageLimitOptimizedPercent, 00234 kImageLimitResizeAreaPercent, 00235 kImageMaxRewritesAtOnce, 00236 kImagePreserveURLs, 00237 kImageRecompressionQuality, 00238 kImageResolutionLimitBytes, 00239 kImageRetainColorProfile, 00240 kImageRetainColorSampling, 00241 kImageRetainExifData, 00242 kImageWebpRecompressionQuality, 00243 kImageWebpRecompressionQualityForSmallScreens, 00244 kImageWebpTimeoutMs, 00245 kImplicitCacheTtlMs, 00246 kInPlaceResourceOptimization, 00247 kInPlaceWaitForOptimized, 00248 kInPlacePreemptiveRewriteCss, 00249 kInPlacePreemptiveRewriteCssImages, 00250 kInPlacePreemptiveRewriteImages, 00251 kInPlacePreemptiveRewriteJavascript, 00252 kInPlaceRewriteDeadlineMs, 00253 kIncreaseSpeedTracking, 00254 kInlineOnlyCriticalImages, 00255 kJsInlineMaxBytes, 00256 kJsOutlineMinBytes, 00257 kJsPreserveURLs, 00258 kLazyloadImagesAfterOnload, 00259 kLazyloadImagesBlankUrl, 00260 kLogRewriteTiming, 00261 kLogUrlIndices, 00262 kLowercaseHtmlNames, 00263 kMaxCacheableResponseContentLength, 00264 kMaxCombinedJsBytes, 00265 kMaxHtmlCacheTimeMs, 00266 kMaxHtmlParseBytes, 00267 kMaxImageBytesForWebpInCss, 00268 kMaxImageSizeLowResolutionBytes, 00269 kMaxInlinedPreviewImagesIndex, 00270 kMaxRewriteInfoLogSize, 00271 kMaxUrlSegmentSize, 00272 kMaxUrlSize, 00273 kMetadataCacheStalenessThresholdMs, 00274 kMinImageSizeLowResolutionBytes, 00275 kMinResourceCacheTimeToRewriteMs, 00276 kModifyCachingHeaders, 00277 kObliviousPagespeedUrls, 00278 kOverrideBlinkCacheTimeMs, 00279 kOverrideCachingTtlMs, 00280 kOverrideIeDocumentMode, 00281 kPassthroughBlinkForInvalidResponseCode, 00282 kProgressiveJpegMinBytes, 00283 kPropagateBlinkCacheDeletes, 00284 kRejectBlacklisted, 00285 kRejectBlacklistedStatusCode, 00286 kReportUnloadTime, 00287 kRespectVary, 00288 kRespectXForwardedProto, 00289 kRewriteDeadlineMs, 00290 kRewriteLevel, 00291 kRewriteUncacheableResources, 00292 kRunningFurious, 00293 kServeStaleIfFetchError, 00294 kSupportNoScriptEnabled, 00295 kUseSmartDiffInBlink, 00296 kXModPagespeedHeaderValue, 00297 kXPsaBlockingRewrite, 00298 00300 kAllow, 00301 kDisableFilters, 00302 kDisallow, 00303 kDistributableFilters, 00304 kDomain, 00305 kEnableFilters, 00306 kExperimentVariable, 00307 kExperimentSpec, 00308 kForbidFilters, 00309 kRetainComment, 00310 00312 kCustomFetchHeader, 00313 kLoadFromFile, 00314 kLoadFromFileMatch, 00315 kLoadFromFileRule, 00316 kLoadFromFileRuleMatch, 00317 kMapOriginDomain, 00318 kMapRewriteDomain, 00319 kMapProxyDomain, 00320 kShardDomain, 00321 00323 kUrlValuedAttribute, 00324 kLibrary, 00325 00327 kCacheFlushFilename, 00328 kCacheFlushPollIntervalSec, 00329 kExperimentalFetchFromModSpdy, 00330 kFetchHttps, 00331 kFetcherProxy, 00332 kFetcherTimeOutMs, 00333 kFileCacheCleanInodeLimit, 00334 kFileCacheCleanIntervalMs, 00335 kFileCacheCleanSizeKb, 00336 kFileCachePath, 00337 kLruCacheByteLimit, 00338 kLruCacheKbPerProcess, 00339 kMemcachedServers, 00340 kMemcachedThreads, 00341 kMemcachedTimeoutUs, 00342 kMessageBufferSize, 00343 kRateLimitBackgroundFetches, 00344 kSlurpDirectory, 00345 kSlurpFlushLimit, 00346 kSlurpReadOnly, 00347 kStatisticsEnabled, 00348 kStatisticsLoggingEnabled, 00349 kStatisticsLoggingFile, 00350 kStatisticsLoggingIntervalMs, 00351 kStatisticsLoggingChartsCSS, 00352 kStatisticsLoggingChartsJS, 00353 kTestProxy, 00354 kTestProxySlurp, 00355 kUseSharedMemLocking, 00356 00359 kEndOfOptions 00360 }; 00361 00362 struct BeaconUrl { 00363 GoogleString http; 00364 GoogleString https; 00365 }; 00366 00367 struct NameValue { 00368 NameValue(const StringPiece& name_in, const StringPiece& value_in) { 00369 name_in.CopyToString(&name); 00370 value_in.CopyToString(&value); 00371 } 00372 GoogleString name; 00373 GoogleString value; 00374 }; 00375 00391 static const int kOptionsVersion = 13; 00392 00397 enum OptionScope { 00398 kDirectoryScope, 00399 kServerScope, 00400 kProcessScope, 00401 }; 00402 00403 static const char kCacheExtenderId[]; 00404 static const char kCollectFlushEarlyContentFilterId[]; 00405 static const char kCssCombinerId[]; 00406 static const char kCssFilterId[]; 00407 static const char kCssImportFlattenerId[]; 00408 static const char kCssInlineId[]; 00409 static const char kImageCombineId[]; 00410 static const char kImageCompressionId[]; 00411 static const char kInPlaceRewriteId[]; 00412 static const char kJavascriptCombinerId[]; 00413 static const char kJavascriptInlineId[]; 00414 static const char kJavascriptMinId[]; 00415 static const char kLocalStorageCacheId[]; 00416 static const char kPrioritizeCriticalCssId[]; 00417 00418 static const char kPanelCommentPrefix[]; 00419 00422 static const char* FilterName(Filter filter); 00423 00426 static const char* FilterId(Filter filter); 00427 00429 static const Filter kFirstFilter = kAddBaseTag; 00430 00432 typedef std::set<Filter> FilterSet; 00433 00435 typedef std::set<GoogleString> FilterIdSet; 00436 00442 static bool AddByNameToFilterSet(const StringPiece& option, FilterSet* set, 00443 MessageHandler* handler); 00444 00447 typedef std::pair<StringPiece, StringPiece> OptionStringPair; 00448 typedef std::set<OptionStringPair> OptionSet; 00449 00452 class PropertyBase { 00453 public: 00454 PropertyBase(const char* id, OptionEnum option_enum) 00455 : id_(id), 00456 help_text_(NULL), 00457 option_enum_(option_enum), 00458 scope_(kDirectoryScope), 00459 do_not_use_for_signature_computation_(false), 00460 index_(-1) { 00461 } 00462 virtual ~PropertyBase(); 00463 00466 virtual void InitializeOption(RewriteOptions* options) const = 0; 00467 00468 void set_do_not_use_for_signature_computation(bool x) { 00469 do_not_use_for_signature_computation_ = x; 00470 } 00471 bool is_used_for_signature_computation() const { 00472 return !do_not_use_for_signature_computation_; 00473 } 00474 00475 void set_scope(OptionScope x) { scope_ = x; } 00476 OptionScope scope() const { return scope_; } 00477 00478 void set_help_text(const char* x) { help_text_ = x; } 00479 const char* help_text() const { return help_text_; } 00480 00481 void set_index(int index) { index_ = index; } 00482 const char* id() const { return id_; } 00483 OptionEnum option_enum() const { return option_enum_; } 00484 int index() const { return index_; } 00485 00486 private: 00487 const char* id_; 00488 const char* help_text_; 00489 OptionEnum option_enum_; 00490 OptionScope scope_; 00491 bool do_not_use_for_signature_computation_; 00492 int index_; 00493 00494 DISALLOW_COPY_AND_ASSIGN(PropertyBase); 00495 }; 00496 00497 typedef std::vector<PropertyBase*> PropertyVector; 00498 00501 class OptionBase { 00502 public: 00503 OptionBase() {} 00504 virtual ~OptionBase(); 00505 00507 virtual bool SetFromString(const GoogleString& value_string) = 0; 00508 virtual void Merge(const OptionBase* src) = 0; 00509 virtual bool was_set() const = 0; 00510 virtual GoogleString Signature(const Hasher* hasher) const = 0; 00511 virtual GoogleString ToString() const = 0; 00512 const char* id() const { return property()->id(); } 00513 const char* help_text() const { return property()->help_text(); } 00514 OptionScope scope() const { return property()->scope(); } 00515 OptionEnum option_enum() const { return property()->option_enum(); } 00516 bool is_used_for_signature_computation() const { 00517 return property()->is_used_for_signature_computation(); 00518 } 00519 virtual const PropertyBase* property() const = 0; 00520 }; 00521 00523 typedef std::vector<OptionBase*> OptionBaseVector; 00524 00525 enum RewriteLevel { 00530 kPassThrough, 00531 00537 kCoreFilters, 00538 00542 kTestingCoreFilters, 00543 00546 kAllFilters, 00547 }; 00548 00550 enum OptionSettingResult { 00551 kOptionOk, 00552 kOptionNameUnknown, 00553 kOptionValueInvalid 00554 }; 00555 00556 static const int kDefaultBeaconReinstrumentTimeSec; 00557 static const int64 kDefaultBlinkMaxHtmlSizeRewritable; 00558 static const int64 kDefaultCssFlattenMaxBytes; 00559 static const int64 kDefaultCssImageInlineMaxBytes; 00560 static const int64 kDefaultCssInlineMaxBytes; 00561 static const int64 kDefaultCssOutlineMinBytes; 00562 static const int64 kDefaultImageInlineMaxBytes; 00563 static const int64 kDefaultJsInlineMaxBytes; 00564 static const int64 kDefaultJsOutlineMinBytes; 00565 static const int64 kDefaultProgressiveJpegMinBytes; 00566 static const int64 kDefaultMaxCacheableResponseContentLength; 00567 static const int64 kDefaultMaxHtmlCacheTimeMs; 00568 static const int64 kDefaultMaxHtmlParseBytes; 00569 static const int64 kDefaultMaxImageBytesForWebpInCss; 00570 static const int64 kDefaultMetadataInputErrorsCacheTtlMs; 00571 static const int64 kDefaultMinResourceCacheTimeToRewriteMs; 00572 static const int64 kDefaultCacheInvalidationTimestamp; 00573 static const int64 kDefaultIdleFlushTimeMs; 00574 static const int64 kDefaultFlushBufferLimitBytes; 00575 static const int64 kDefaultImplicitCacheTtlMs; 00576 static const int64 kDefaultPrioritizeVisibleContentCacheTimeMs; 00577 static const char kDefaultBeaconUrl[]; 00578 static const int64 kDefaultImagesRecompressQuality; 00579 static const int64 kDefaultImageJpegRecompressQuality; 00580 static const int kDefaultImageLimitOptimizedPercent; 00581 static const int kDefaultImageLimitResizeAreaPercent; 00582 static const int64 kDefaultImageResolutionLimitBytes; 00583 static const int64 kDefaultImageJpegNumProgressiveScans; 00584 static const int64 kDefaultImageWebpRecompressQuality; 00585 static const int64 kDefaultImageWebpTimeoutMs; 00586 static const int kDefaultDomainShardCount; 00587 static const int64 kDefaultBlinkHtmlChangeDetectionTimeMs; 00588 static const int64 kDefaultOverrideBlinkCacheTimeMs; 00589 00592 static const int kDefaultMaxUrlSize; 00593 00594 static const int kDefaultImageMaxRewritesAtOnce; 00595 00600 static const int kDefaultMaxUrlSegmentSize; 00601 00603 static const int kDefaultRewriteDeadlineMs; 00604 00606 static const int64 kDefaultDistributedTimeoutMs; 00607 00610 static const int kDefaultMaxInlinedPreviewImagesIndex; 00613 static const int64 kDefaultMinImageSizeLowResolutionBytes; 00616 static const int64 kDefaultMaxImageSizeLowResolutionBytes; 00618 static const int64 kDefaultFinderPropertiesCacheExpirationTimeMs; 00620 static const int64 kDefaultFinderPropertiesCacheRefreshTimeMs; 00621 00624 static const int64 kDefaultFuriousCookieDurationMs; 00625 00628 static const int64 kDefaultMetadataCacheStalenessThresholdMs; 00629 00631 static const int64 kDefaultMaxCombinedJsBytes; 00632 00633 static const int kDefaultFuriousTrafficPercent; 00635 static const int kDefaultFuriousSlot; 00636 00637 static const char kDefaultBlockingRewriteKey[]; 00638 00639 static const char kRejectedRequestUrlKeyName[]; 00640 00641 static const int kDefaultPropertyCacheHttpStatusStabilityThreshold; 00642 00643 static const int kDefaultMaxRewriteInfoLogSize; 00644 00653 class FuriousSpec { 00654 public: 00659 FuriousSpec(const StringPiece& spec, RewriteOptions* options, 00660 MessageHandler* handler); 00661 00665 explicit FuriousSpec(int id); 00666 00667 virtual ~FuriousSpec(); 00668 00670 virtual FuriousSpec* Clone(); 00671 00672 bool is_valid() const { return id_ >= 0; } 00673 00675 int id() const { return id_; } 00676 int percent() const { return percent_; } 00677 GoogleString ga_id() const { return ga_id_; } 00678 int slot() const { return ga_variable_slot_; } 00679 RewriteLevel rewrite_level() const { return rewrite_level_; } 00680 FilterSet enabled_filters() const { return enabled_filters_; } 00681 FilterSet disabled_filters() const { return disabled_filters_; } 00682 OptionSet filter_options() const { return filter_options_; } 00683 int64 css_inline_max_bytes() const { return css_inline_max_bytes_; } 00684 int64 js_inline_max_bytes() const { return js_inline_max_bytes_; } 00685 int64 image_inline_max_bytes() const { return image_inline_max_bytes_; } 00686 bool use_default() const { return use_default_; } 00687 00688 protected: 00692 void Merge(const FuriousSpec& spec); 00693 00694 private: 00695 FRIEND_TEST(RewriteOptionsTest, FuriousMergeTest); 00696 00699 void Initialize(const StringPiece& spec, MessageHandler* handler); 00700 00701 int id_; 00702 GoogleString ga_id_; 00703 int ga_variable_slot_; 00704 int percent_; 00705 RewriteLevel rewrite_level_; 00706 FilterSet enabled_filters_; 00707 FilterSet disabled_filters_; 00708 OptionSet filter_options_; 00709 int64 css_inline_max_bytes_; 00710 int64 js_inline_max_bytes_; 00711 int64 image_inline_max_bytes_; 00714 bool use_default_; 00715 DISALLOW_COPY_AND_ASSIGN(FuriousSpec); 00716 }; 00717 00719 struct ElementAttributeCategory { 00720 GoogleString element; 00721 GoogleString attribute; 00722 semantic_type::Category category; 00723 }; 00724 00731 class Properties { 00732 public: 00741 static bool Initialize(Properties** properties); 00742 00751 static bool Terminate(Properties** properties_handle); 00752 00754 int size() const { return property_vector_.size(); } 00755 00756 const PropertyBase* property(int index) const { 00757 return property_vector_[index]; 00758 } 00759 PropertyBase* property(int index) { return property_vector_[index]; } 00760 00766 void Merge(Properties* properties); 00767 00768 void push_back(PropertyBase* p) { property_vector_.push_back(p); } 00769 00770 private: 00773 Properties(); 00774 ~Properties(); 00775 00779 int initialization_count_; 00780 00785 bool owns_properties_; 00786 PropertyVector property_vector_; 00787 }; 00788 00790 struct FilterEnumToIdAndNameEntry { 00791 RewriteOptions::Filter filter_enum; 00792 const char* filter_id; 00793 const char* filter_name; 00794 }; 00795 00796 static bool ParseRewriteLevel(const StringPiece& in, RewriteLevel* out); 00797 00801 static bool ParseBeaconUrl(const StringPiece& in, BeaconUrl* out); 00802 00806 bool ImageOptimizationEnabled() const; 00807 00808 RewriteOptions(); 00809 virtual ~RewriteOptions(); 00810 00814 static bool Initialize(); 00815 static bool Terminate(); 00816 00821 void InitializeOptions(const Properties* properties); 00822 00823 bool modified() const { return modified_; } 00824 00830 void SetDefaultRewriteLevel(RewriteLevel level) { 00832 level_.set_default(level); 00833 } 00834 void SetRewriteLevel(RewriteLevel level) { 00835 set_option(level, &level_); 00836 } 00837 00839 void AddCustomFetchHeader(const StringPiece& name, const StringPiece& value); 00840 00841 const NameValue* custom_fetch_header(int i) const { 00842 return custom_fetch_headers_[i]; 00843 } 00844 00845 int num_custom_fetch_headers() const { 00846 return custom_fetch_headers_.size(); 00847 } 00848 00851 FuriousSpec* GetFuriousSpec(int id) const; 00852 00856 bool AvailableFuriousId(int id); 00857 00860 virtual bool AddFuriousSpec(const StringPiece& spec, MessageHandler* handler); 00861 00869 virtual bool SetFuriousState(int id); 00870 00874 void SetFuriousStateStr(const StringPiece& experiment_index); 00875 00876 int furious_id() const { return furious_id_; } 00877 00878 int furious_spec_id(int i) const { 00879 return furious_specs_[i]->id(); 00880 } 00881 00885 GoogleString GetFuriousStateStr() const; 00886 00887 FuriousSpec* furious_spec(int i) const { 00888 return furious_specs_[i]; 00889 } 00890 00891 int num_furious_experiments() const { return furious_specs_.size(); } 00892 00904 void AddUrlValuedAttribute(const StringPiece& element, 00905 const StringPiece& attribute, 00906 semantic_type::Category category); 00907 00910 void UrlValuedAttribute(int index, 00911 StringPiece* element, 00912 StringPiece* attribute, 00913 semantic_type::Category* category) const; 00914 00915 int num_url_valued_attributes() const { 00916 if (url_valued_attributes_ == NULL) { 00917 return 0; 00918 } else { 00919 return url_valued_attributes_->size(); 00920 } 00921 } 00922 00924 bool RegisterLibrary( 00925 uint64 bytes, StringPiece md5_hash, StringPiece canonical_url) { 00926 return javascript_library_identification_.RegisterLibrary( 00927 bytes, md5_hash, canonical_url); 00928 } 00929 00932 const JavascriptLibraryIdentification* javascript_library_identification() 00933 const { 00934 if (Enabled(kCanonicalizeJavascriptLibraries)) { 00935 return &javascript_library_identification_; 00936 } else { 00937 return NULL; 00938 } 00939 } 00940 00941 RewriteLevel level() const { return level_.value(); } 00942 00947 bool AdjustFiltersByCommaSeparatedList(const StringPiece& filters, 00948 MessageHandler* handler); 00949 00953 bool EnableFiltersByCommaSeparatedList(const StringPiece& filters, 00954 MessageHandler* handler); 00955 00959 bool DisableFiltersByCommaSeparatedList(const StringPiece& filters, 00960 MessageHandler* handler); 00961 00965 bool ForbidFiltersByCommaSeparatedList(const StringPiece& filters, 00966 MessageHandler* handler); 00967 00969 void DisableAllFilters(); 00970 00978 void DisableAllFiltersNotExplicitlyEnabled(); 00979 00982 void DistributeFiltersByCommaSeparatedList(const StringPiece& filter_ids, 00983 MessageHandler* handler); 00986 void DistributeFilter(const StringPiece& filter_id); 00987 00990 bool Distributable(const StringPiece& filter_id) const; 00991 00995 void EnableFilter(Filter filter); 00998 void ForceEnableFilter(Filter filter); 00999 void DisableFilter(Filter filter); 01000 void ForbidFilter(Filter filter); 01001 void EnableFilters(const FilterSet& filter_set); 01002 void DisableFilters(const FilterSet& filter_set); 01003 void ForbidFilters(const FilterSet& filter_set); 01006 void ClearFilters(); 01007 01010 void EnableExtendCacheFilters(); 01011 01012 bool Enabled(Filter filter) const; 01013 bool Forbidden(StringPiece filter_id) const; 01014 01016 void GetEnabledFiltersRequiringScriptExecution(FilterSet* filter_set) const; 01017 01019 void DisableFiltersRequiringScriptExecution(); 01020 01025 static bool AddCommaSeparatedListToOptionSet( 01026 const StringPiece& options, OptionSet* set, MessageHandler* handler); 01027 01032 OptionSettingResult SetOptionFromName( 01033 StringPiece name, StringPiece value, GoogleString* msg); 01034 01040 OptionSettingResult ParseAndSetOptionFromName1( 01041 StringPiece name, StringPiece arg, 01042 GoogleString* msg, MessageHandler* handler); 01043 01044 OptionSettingResult ParseAndSetOptionFromName2( 01045 StringPiece name, StringPiece arg1, StringPiece arg2, 01046 GoogleString* msg, MessageHandler* handler); 01047 01048 OptionSettingResult ParseAndSetOptionFromName3( 01049 StringPiece name, StringPiece arg1, StringPiece arg2, StringPiece arg3, 01050 GoogleString* msg, MessageHandler* handler); 01051 01055 virtual OptionSettingResult ParseAndSetOptionFromEnum1( 01056 OptionEnum name, StringPiece arg, 01057 GoogleString* msg, MessageHandler* handler); 01058 01059 virtual OptionSettingResult ParseAndSetOptionFromEnum2( 01060 OptionEnum name, StringPiece arg1, StringPiece arg2, 01061 GoogleString* msg, MessageHandler* handler); 01062 01063 virtual OptionSettingResult ParseAndSetOptionFromEnum3( 01064 OptionEnum name, StringPiece arg1, StringPiece arg2, StringPiece arg3, 01065 GoogleString* msg, MessageHandler* handler); 01066 01068 OptionSettingResult SetOptionFromEnum(OptionEnum option_enum, 01069 StringPiece value); 01070 01076 bool OptionValue(OptionEnum option_enum, const char** id, 01077 bool* was_set, GoogleString* value) const; 01078 01081 bool SetOptionsFromName(const OptionSet& option_set); 01082 01085 bool SetOptionFromNameAndLog(StringPiece name, 01086 StringPiece value, 01087 MessageHandler* handler); 01088 01091 static bool ParseFromString(const GoogleString& value_string, bool* value); 01092 static bool ParseFromString(const GoogleString& value_string, 01093 EnabledEnum* value); 01094 static bool ParseFromString(const GoogleString& value_string, int* value) { 01095 return StringToInt(value_string, value); 01096 } 01097 static bool ParseFromString(const GoogleString& value_string, int64* value) { 01098 return StringToInt64(value_string, value); 01099 } 01100 static bool ParseFromString(const GoogleString& value_string, 01101 GoogleString* value) { 01102 *value = value_string; 01103 return true; 01104 } 01105 static bool ParseFromString(const GoogleString& value_string, 01106 RewriteLevel* value) { 01107 return ParseRewriteLevel(value_string, value); 01108 } 01109 static bool ParseFromString(const GoogleString& value_string, 01110 BeaconUrl* value) { 01111 return ParseBeaconUrl(value_string, value); 01112 } 01113 01116 int64 css_outline_min_bytes() const { return css_outline_min_bytes_.value(); } 01117 void set_css_outline_min_bytes(int64 x) { 01118 set_option(x, &css_outline_min_bytes_); 01119 } 01120 01121 GoogleString ga_id() const { return ga_id_.value(); } 01122 void set_ga_id(GoogleString id) { 01123 set_option(id, &ga_id_); 01124 } 01125 01126 bool increase_speed_tracking() const { 01127 return increase_speed_tracking_.value(); 01128 } 01129 void set_increase_speed_tracking(bool x) { 01130 set_option(x, &increase_speed_tracking_); 01131 } 01132 01133 int64 js_outline_min_bytes() const { return js_outline_min_bytes_.value(); } 01134 void set_js_outline_min_bytes(int64 x) { 01135 set_option(x, &js_outline_min_bytes_); 01136 } 01137 01138 int64 progressive_jpeg_min_bytes() const { 01139 return progressive_jpeg_min_bytes_.value(); 01140 } 01141 void set_progressive_jpeg_min_bytes(int64 x) { 01142 set_option(x, &progressive_jpeg_min_bytes_); 01143 } 01144 01145 int64 css_flatten_max_bytes() const { return css_flatten_max_bytes_.value(); } 01146 void set_css_flatten_max_bytes(int64 x) { 01147 set_option(x, &css_flatten_max_bytes_); 01148 } 01149 bool cache_small_images_unrewritten() const { 01150 return cache_small_images_unrewritten_.value(); 01151 } 01152 void set_cache_small_images_unrewritten(bool x) { 01153 set_option(x, &cache_small_images_unrewritten_); 01154 } 01155 int64 image_resolution_limit_bytes() const { 01156 return image_resolution_limit_bytes_.value(); 01157 } 01158 void set_image_resolution_limit_bytes(int64 x) { 01159 set_option(x, &image_resolution_limit_bytes_); 01160 } 01161 01163 int64 ImageInlineMaxBytes() const; 01164 void set_image_inline_max_bytes(int64 x); 01166 int64 CssImageInlineMaxBytes() const; 01167 void set_css_image_inline_max_bytes(int64 x) { 01168 set_option(x, &css_image_inline_max_bytes_); 01169 } 01171 int64 MaxImageInlineMaxBytes() const; 01172 int64 css_inline_max_bytes() const { return css_inline_max_bytes_.value(); } 01173 void set_css_inline_max_bytes(int64 x) { 01174 set_option(x, &css_inline_max_bytes_); 01175 } 01176 int64 js_inline_max_bytes() const { return js_inline_max_bytes_.value(); } 01177 void set_js_inline_max_bytes(int64 x) { 01178 set_option(x, &js_inline_max_bytes_); 01179 } 01180 int64 max_html_cache_time_ms() const { 01181 return max_html_cache_time_ms_.value(); 01182 } 01183 void set_max_html_cache_time_ms(int64 x) { 01184 set_option(x, &max_html_cache_time_ms_); 01185 } 01186 int64 max_html_parse_bytes() const { 01187 return max_html_parse_bytes_.value(); 01188 } 01189 void set_max_html_parse_bytes(int64 x) { 01190 set_option(x, &max_html_parse_bytes_); 01191 } 01192 int64 max_image_bytes_for_webp_in_css() const { 01193 return max_image_bytes_for_webp_in_css_.value(); 01194 } 01195 void set_max_image_bytes_for_webp_in_css(int64 x) { 01196 set_option(x, &max_image_bytes_for_webp_in_css_); 01197 } 01198 int64 max_cacheable_response_content_length() const { 01199 return max_cacheable_response_content_length_.value(); 01200 } 01201 void set_max_cacheable_response_content_length(int64 x) { 01202 set_option(x, &max_cacheable_response_content_length_); 01203 } 01204 int64 min_resource_cache_time_to_rewrite_ms() const { 01205 return min_resource_cache_time_to_rewrite_ms_.value(); 01206 } 01207 void set_min_resource_cache_time_to_rewrite_ms(int64 x) { 01208 set_option(x, &min_resource_cache_time_to_rewrite_ms_); 01209 } 01210 bool need_to_store_experiment_data() const { 01211 return need_to_store_experiment_data_; 01212 } 01213 void set_need_to_store_experiment_data(bool x) { 01214 need_to_store_experiment_data_ = x; 01215 } 01216 01217 int64 blocking_fetch_timeout_ms() const { 01218 return blocking_fetch_timeout_ms_.value(); 01219 } 01220 void set_blocking_fetch_timeout_ms(int64 x) { 01221 set_option(x, &blocking_fetch_timeout_ms_); 01222 } 01223 bool override_ie_document_mode() const { 01224 return override_ie_document_mode_.value(); 01225 } 01226 void set_override_ie_document_mode(bool x) { 01227 set_option(x, &override_ie_document_mode_); 01228 } 01229 01230 bool is_blink_auto_blacklisted() const { 01231 return is_blink_auto_blacklisted_.value(); 01232 } 01233 void set_is_blink_auto_blacklisted(bool x) { 01234 set_option(x, &is_blink_auto_blacklisted_); 01235 } 01236 01240 bool IsUrlCacheValid(StringPiece url, int64 time_ms) const; 01241 01246 void AddUrlCacheInvalidationEntry(StringPiece url_pattern, 01247 int64 timestamp_ms, 01248 bool is_strict); 01249 01252 bool IsUrlCacheInvalidationEntriesSorted() const; 01253 01256 void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock* lock) { 01257 cache_invalidation_timestamp_.set_mutex(lock); 01258 } 01259 01261 int64 cache_invalidation_timestamp() const { 01262 ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex()); 01263 return cache_invalidation_timestamp_.value(); 01264 } 01265 01272 void set_cache_invalidation_timestamp(int64 timestamp_ms) { 01273 cache_invalidation_timestamp_.mutex()->DCheckLocked(); 01274 DCHECK_LT(0, timestamp_ms); 01275 set_option(timestamp_ms, &cache_invalidation_timestamp_); 01276 } 01277 01284 bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms, 01285 const Hasher* hasher); 01286 01289 int64 idle_flush_time_ms() const { 01290 return idle_flush_time_ms_.value(); 01291 } 01292 void set_idle_flush_time_ms(int64 x) { 01293 set_option(x, &idle_flush_time_ms_); 01294 } 01295 01297 int64 flush_buffer_limit_bytes() const { 01298 return flush_buffer_limit_bytes_.value(); 01299 } 01300 01301 void set_flush_buffer_limit_bytes(int64 x) { 01302 set_option(x, &flush_buffer_limit_bytes_); 01303 } 01304 01307 int max_url_segment_size() const { return max_url_segment_size_.value(); } 01308 void set_max_url_segment_size(int x) { 01309 set_option(x, &max_url_segment_size_); 01310 } 01311 01312 int image_max_rewrites_at_once() const { 01313 return image_max_rewrites_at_once_.value(); 01314 } 01315 void set_image_max_rewrites_at_once(int x) { 01316 set_option(x, &image_max_rewrites_at_once_); 01317 } 01318 01320 int max_url_size() const { return max_url_size_.value(); } 01321 void set_max_url_size(int x) { 01322 set_option(x, &max_url_size_); 01323 } 01324 01325 int rewrite_deadline_ms() const { return rewrite_deadline_ms_.value(); } 01326 void set_rewrite_deadline_ms(int x) { 01327 set_option(x, &rewrite_deadline_ms_); 01328 } 01329 01330 bool test_instant_fetch_rewrite_deadline() const { 01331 return test_instant_fetch_rewrite_deadline_.value(); 01332 } 01333 void set_test_instant_fetch_rewrite_deadline(bool x) { 01334 set_option(x, &test_instant_fetch_rewrite_deadline_); 01335 } 01336 01337 int domain_shard_count() const { return domain_shard_count_.value(); } 01340 void set_domain_shard_count(int64 x) { 01341 int value = x; 01342 set_option(value, &domain_shard_count_); 01343 } 01344 01345 void set_enabled(EnabledEnum x) { 01346 set_option(x, &enabled_); 01347 } 01348 bool enabled() const { 01349 return enabled_.value() == kEnabledOn; 01350 } 01351 bool unplugged() const { 01352 return enabled_.value() == kEnabledUnplugged; 01353 } 01354 01355 void set_add_options_to_urls(bool x) { 01356 set_option(x, &add_options_to_urls_); 01357 } 01358 01359 bool add_options_to_urls() const { 01360 return add_options_to_urls_.value(); 01361 } 01362 01363 void set_in_place_rewriting_enabled(bool x) { 01364 set_option(x, &in_place_rewriting_enabled_); 01365 } 01366 01367 void set_oblivious_pagespeed_urls(bool x) { 01368 set_option(x, &oblivious_pagespeed_urls_); 01369 } 01370 01371 bool oblivious_pagespeed_urls() const { 01372 return oblivious_pagespeed_urls_.value(); 01373 } 01374 01375 bool in_place_rewriting_enabled() const { 01376 return in_place_rewriting_enabled_.value(); 01377 } 01378 01379 void set_in_place_wait_for_optimized(bool x) { 01380 set_option(x, &in_place_wait_for_optimized_); 01381 } 01382 01383 bool in_place_wait_for_optimized() const { 01384 return in_place_wait_for_optimized_.value(); 01385 } 01386 01387 void set_in_place_rewrite_deadline_ms(int x) { 01388 set_option(x, &in_place_rewrite_deadline_ms_); 01389 } 01390 01391 int in_place_rewrite_deadline_ms() const { 01392 return in_place_rewrite_deadline_ms_.value(); 01393 } 01394 01395 void set_in_place_preemptive_rewrite_css(bool x) { 01396 set_option(x, &in_place_preemptive_rewrite_css_); 01397 } 01398 bool in_place_preemptive_rewrite_css() const { 01399 return in_place_preemptive_rewrite_css_.value(); 01400 } 01401 01402 void set_in_place_preemptive_rewrite_css_images(bool x) { 01403 set_option(x, &in_place_preemptive_rewrite_css_images_); 01404 } 01405 bool in_place_preemptive_rewrite_css_images() const { 01406 return in_place_preemptive_rewrite_css_images_.value(); 01407 } 01408 01409 void set_in_place_preemptive_rewrite_images(bool x) { 01410 set_option(x, &in_place_preemptive_rewrite_images_); 01411 } 01412 bool in_place_preemptive_rewrite_images() const { 01413 return in_place_preemptive_rewrite_images_.value(); 01414 } 01415 01416 void set_in_place_preemptive_rewrite_javascript(bool x) { 01417 set_option(x, &in_place_preemptive_rewrite_javascript_); 01418 } 01419 bool in_place_preemptive_rewrite_javascript() const { 01420 return in_place_preemptive_rewrite_javascript_.value(); 01421 } 01422 01423 void set_combine_across_paths(bool x) { 01424 set_option(x, &combine_across_paths_); 01425 } 01426 bool combine_across_paths() const { return combine_across_paths_.value(); } 01427 01428 void set_log_rewrite_timing(bool x) { 01429 set_option(x, &log_rewrite_timing_); 01430 } 01431 bool log_rewrite_timing() const { return log_rewrite_timing_.value(); } 01432 01433 void set_log_url_indices(bool x) { 01434 set_option(x, &log_url_indices_); 01435 } 01436 bool log_url_indices() const { return log_url_indices_.value(); } 01437 01438 void set_lowercase_html_names(bool x) { 01439 set_option(x, &lowercase_html_names_); 01440 } 01441 bool lowercase_html_names() const { return lowercase_html_names_.value(); } 01442 01443 void set_always_rewrite_css(bool x) { 01444 set_option(x, &always_rewrite_css_); 01445 } 01446 bool always_rewrite_css() const { return always_rewrite_css_.value(); } 01447 01448 void set_respect_vary(bool x) { 01449 set_option(x, &respect_vary_); 01450 } 01451 bool respect_vary() const { return respect_vary_.value(); } 01452 01453 void set_respect_x_forwarded_proto(bool x) { 01454 set_option(x, &respect_x_forwarded_proto_); 01455 } 01456 bool respect_x_forwarded_proto() const { 01457 return respect_x_forwarded_proto_.value(); 01458 } 01459 01460 void set_flush_html(bool x) { set_option(x, &flush_html_); } 01461 bool flush_html() const { return flush_html_.value(); } 01462 01463 void set_serve_stale_if_fetch_error(bool x) { 01464 set_option(x, &serve_stale_if_fetch_error_); 01465 } 01466 bool serve_stale_if_fetch_error() const { 01467 return serve_stale_if_fetch_error_.value(); 01468 } 01469 01470 void set_enable_blink_critical_line(bool x) { 01471 set_option(x, &enable_blink_critical_line_); 01472 } 01473 bool enable_blink_critical_line() const { 01474 return enable_blink_critical_line_.value(); 01475 } 01476 01477 void set_default_cache_html(bool x) { set_option(x, &default_cache_html_); } 01478 bool default_cache_html() const { return default_cache_html_.value(); } 01479 01480 void set_modify_caching_headers(bool x) { 01481 set_option(x, &modify_caching_headers_); 01482 } 01483 bool modify_caching_headers() const { 01484 return modify_caching_headers_.value(); 01485 } 01486 01487 void set_inline_only_critical_images(bool x) { 01488 set_option(x, &inline_only_critical_images_); 01489 } 01490 bool inline_only_critical_images() const { 01491 return inline_only_critical_images_.value(); 01492 } 01493 01494 void set_critical_images_beacon_enabled(bool x) { 01495 set_option(x, &critical_images_beacon_enabled_); 01496 } 01497 bool critical_images_beacon_enabled() const { 01498 return critical_images_beacon_enabled_.value(); 01499 } 01500 01501 void set_beacon_reinstrument_beacon_time_sec(int x) { 01502 set_option(x, &beacon_reinstrument_time_sec_); 01503 } 01504 int beacon_reinstrument_time_sec() const { 01505 return beacon_reinstrument_time_sec_.value(); 01506 } 01507 01508 void set_lazyload_images_after_onload(bool x) { 01509 set_option(x, &lazyload_images_after_onload_); 01510 } 01511 bool lazyload_images_after_onload() const { 01512 return lazyload_images_after_onload_.value(); 01513 } 01514 01515 void set_lazyload_images_blank_url(const StringPiece& p) { 01516 set_option(GoogleString(p.data(), p.size()), &lazyload_images_blank_url_); 01517 } 01518 const GoogleString& lazyload_images_blank_url() const { 01519 return lazyload_images_blank_url_.value(); 01520 } 01521 01522 void set_max_inlined_preview_images_index(int x) { 01523 set_option(x, &max_inlined_preview_images_index_); 01524 } 01525 int max_inlined_preview_images_index() const { 01526 return max_inlined_preview_images_index_.value(); 01527 } 01528 01529 void set_min_image_size_low_resolution_bytes(int64 x) { 01530 set_option(x, &min_image_size_low_resolution_bytes_); 01531 } 01532 int64 min_image_size_low_resolution_bytes() const { 01533 return min_image_size_low_resolution_bytes_.value(); 01534 } 01535 01536 void set_max_image_size_low_resolution_bytes(int64 x) { 01537 set_option(x, &max_image_size_low_resolution_bytes_); 01538 } 01539 int64 max_image_size_low_resolution_bytes() const { 01540 return max_image_size_low_resolution_bytes_.value(); 01541 } 01542 01543 void set_furious_cookie_duration_ms(int64 x) { 01544 set_option(x, &furious_cookie_duration_ms_); 01545 } 01546 int64 furious_cookie_duration_ms() const { 01547 return furious_cookie_duration_ms_.value(); 01548 } 01549 01550 void set_finder_properties_cache_expiration_time_ms(int64 x) { 01551 set_option(x, &finder_properties_cache_expiration_time_ms_); 01552 } 01553 int64 finder_properties_cache_expiration_time_ms() const { 01554 return finder_properties_cache_expiration_time_ms_.value(); 01555 } 01556 01557 void set_finder_properties_cache_refresh_time_ms(int64 x) { 01558 set_option(x, &finder_properties_cache_refresh_time_ms_); 01559 } 01560 int64 finder_properties_cache_refresh_time_ms() const { 01561 return finder_properties_cache_refresh_time_ms_.value(); 01562 } 01563 bool css_preserve_urls() const { 01564 return css_preserve_urls_.value(); 01565 } 01566 void set_css_preserve_urls(bool x) { 01567 set_option(x, &css_preserve_urls_); 01568 } 01569 01570 bool image_preserve_urls() const { 01571 return image_preserve_urls_.value(); 01572 } 01573 void set_image_preserve_urls(bool x) { 01574 set_option(x, &image_preserve_urls_); 01575 } 01576 01577 bool js_preserve_urls() const { 01578 return js_preserve_urls_.value(); 01579 } 01580 void set_js_preserve_urls(bool x) { 01581 set_option(x, &js_preserve_urls_); 01582 } 01583 01584 bool image_retain_color_profile() const { 01585 return image_retain_color_profile_.value(); 01586 } 01587 void set_image_retain_color_profile(bool x) { 01588 set_option(x, &image_retain_color_profile_); 01589 } 01590 01591 bool image_retain_color_sampling() const { 01592 return image_retain_color_sampling_.value(); 01593 } 01594 void set_image_retain_color_sampling(bool x) { 01595 set_option(x, &image_retain_color_sampling_); 01596 } 01597 01598 bool image_retain_exif_data() const { 01599 return image_retain_exif_data_.value(); 01600 } 01601 void set_image_retain_exif_data(bool x) { 01602 set_option(x, &image_retain_exif_data_); 01603 } 01604 01605 void set_metadata_cache_staleness_threshold_ms(int64 x) { 01606 set_option(x, &metadata_cache_staleness_threshold_ms_); 01607 } 01608 int64 metadata_cache_staleness_threshold_ms() const { 01609 return metadata_cache_staleness_threshold_ms_.value(); 01610 } 01611 01612 void set_metadata_input_errors_cache_ttl_ms(int64 x) { 01613 set_option(x, &metadata_input_errors_cache_ttl_ms_); 01614 } 01615 int64 metadata_input_errors_cache_ttl_ms() const { 01616 return metadata_input_errors_cache_ttl_ms_.value(); 01617 } 01618 01619 const BeaconUrl& beacon_url() const { return beacon_url_.value(); } 01620 void set_beacon_url(const GoogleString& beacon_url) { 01621 beacon_url_.SetFromString(beacon_url); 01622 } 01623 01625 virtual bool trim_urls_in_css() const { return true; } 01626 01627 int64 image_jpeg_recompress_quality() const { 01628 return image_jpeg_recompress_quality_.value(); 01629 } 01630 void set_image_jpeg_recompress_quality(int64 x) { 01631 set_option(x, &image_jpeg_recompress_quality_); 01632 } 01633 01634 int64 image_jpeg_recompress_quality_for_small_screens() const { 01635 return image_jpeg_recompress_quality_for_small_screens_.value(); 01636 } 01637 void set_image_jpeg_recompress_quality_for_small_screens(int64 x) { 01638 set_option(x, &image_jpeg_recompress_quality_for_small_screens_); 01639 } 01640 01641 int64 image_recompress_quality() const { 01642 return image_recompress_quality_.value(); 01643 } 01644 void set_image_recompress_quality(int64 x) { 01645 set_option(x, &image_recompress_quality_); 01646 } 01647 01648 int image_limit_optimized_percent() const { 01649 return image_limit_optimized_percent_.value(); 01650 } 01651 void set_image_limit_optimized_percent(int x) { 01652 set_option(x, &image_limit_optimized_percent_); 01653 } 01654 int image_limit_resize_area_percent() const { 01655 return image_limit_resize_area_percent_.value(); 01656 } 01657 void set_image_limit_resize_area_percent(int x) { 01658 set_option(x, &image_limit_resize_area_percent_); 01659 } 01660 01661 int64 image_jpeg_num_progressive_scans() const { 01662 return image_jpeg_num_progressive_scans_.value(); 01663 } 01664 void set_image_jpeg_num_progressive_scans(int64 x) { 01665 set_option(x, &image_jpeg_num_progressive_scans_); 01666 } 01667 01668 int64 image_jpeg_num_progressive_scans_for_small_screens() const { 01669 return image_jpeg_num_progressive_scans_for_small_screens_.value(); 01670 } 01671 void set_image_jpeg_num_progressive_scans_for_small_screens(int64 x) { 01672 set_option(x, &image_jpeg_num_progressive_scans_for_small_screens_); 01673 } 01674 01675 int64 image_webp_recompress_quality() const { 01676 return image_webp_recompress_quality_.value(); 01677 } 01678 void set_image_webp_recompress_quality(int64 x) { 01679 set_option(x, &image_webp_recompress_quality_); 01680 } 01681 01682 int64 image_webp_recompress_quality_for_small_screens() const { 01683 return image_webp_recompress_quality_for_small_screens_.value(); 01684 } 01685 void set_image_webp_recompress_quality_for_small_screens(int64 x) { 01686 set_option(x, &image_webp_recompress_quality_for_small_screens_); 01687 } 01688 int64 image_webp_timeout_ms() const { 01689 return image_webp_timeout_ms_.value(); 01690 } 01691 void set_image_webp_timeout_ms(int64 x) { 01692 set_option(x, &image_webp_timeout_ms_); 01693 } 01694 01695 bool domain_rewrite_hyperlinks() const { 01696 return domain_rewrite_hyperlinks_.value(); 01697 } 01698 void set_domain_rewrite_hyperlinks(bool x) { 01699 set_option(x, &domain_rewrite_hyperlinks_); 01700 } 01701 01702 bool client_domain_rewrite() const { 01703 return client_domain_rewrite_.value(); 01704 } 01705 void set_client_domain_rewrite(bool x) { 01706 set_option(x, &client_domain_rewrite_); 01707 } 01708 01709 void set_flush_more_resources_early_if_time_permits(bool x) { 01710 set_option(x, &flush_more_resources_early_if_time_permits_); 01711 } 01712 bool flush_more_resources_early_if_time_permits() const { 01713 return flush_more_resources_early_if_time_permits_.value(); 01714 } 01715 01716 void set_flush_more_resources_in_ie_and_firefox(bool x) { 01717 set_option(x, &flush_more_resources_in_ie_and_firefox_); 01718 } 01719 bool flush_more_resources_in_ie_and_firefox() const { 01720 return flush_more_resources_in_ie_and_firefox_.value(); 01721 } 01722 01723 void set_enable_defer_js_experimental(bool x) { 01724 set_option(x, &enable_defer_js_experimental_); 01725 } 01726 bool enable_defer_js_experimental() const { 01727 return enable_defer_js_experimental_.value(); 01728 } 01729 01730 void set_enable_inline_preview_images_experimental(bool x) { 01731 set_option(x, &enable_inline_preview_images_experimental_); 01732 } 01733 bool enable_inline_preview_images_experimental() const { 01734 return enable_inline_preview_images_experimental_.value(); 01735 } 01736 01737 void set_lazyload_highres_images(bool x) { 01738 set_option(x, &lazyload_highres_images_); 01739 } 01740 bool lazyload_highres_images() const { 01741 return lazyload_highres_images_.value(); 01742 } 01743 01744 void set_enable_blink_debug_dashboard(bool x) { 01745 set_option(x, &enable_blink_debug_dashboard_); 01746 } 01747 bool enable_blink_debug_dashboard() const { 01748 return enable_blink_debug_dashboard_.value(); 01749 } 01750 01751 void set_enable_blink_html_change_detection(bool x) { 01752 set_option(x, &enable_blink_html_change_detection_); 01753 } 01754 bool enable_blink_html_change_detection() const { 01755 return enable_blink_html_change_detection_.value(); 01756 } 01757 01758 void set_enable_blink_html_change_detection_logging(bool x) { 01759 set_option(x, &enable_blink_html_change_detection_logging_); 01760 } 01761 bool enable_blink_html_change_detection_logging() const { 01762 return enable_blink_html_change_detection_logging_.value(); 01763 } 01764 01765 void set_use_smart_diff_in_blink(bool x) { 01766 set_option(x, &use_smart_diff_in_blink_); 01767 } 01768 bool use_smart_diff_in_blink() const { 01769 return use_smart_diff_in_blink_.value(); 01770 } 01771 01772 void set_enable_lazyload_in_blink(bool x) { 01773 set_option(x, &enable_lazyload_in_blink_); 01774 } 01775 bool enable_lazyload_in_blink() const { 01776 return enable_lazyload_in_blink_.value(); 01777 } 01778 01779 void set_enable_prioritizing_scripts(bool x) { 01780 set_option(x, &enable_prioritizing_scripts_); 01781 } 01782 bool enable_prioritizing_scripts() const { 01783 return enable_prioritizing_scripts_.value(); 01784 } 01785 01786 void set_blink_html_change_detection_time_ms(int64 x) { 01787 set_option(x, &blink_html_change_detection_time_ms_); 01788 } 01789 int64 blink_html_change_detection_time_ms() const { 01790 return blink_html_change_detection_time_ms_.value(); 01791 } 01792 01793 void set_override_blink_cache_time_ms(int64 x) { 01794 set_option(x, &override_blink_cache_time_ms_); 01795 } 01796 int64 override_blink_cache_time_ms() const { 01797 return override_blink_cache_time_ms_.value(); 01798 } 01799 01800 void set_blink_non_cacheables_for_all_families(const StringPiece& p) { 01801 set_option(GoogleString(p.data(), p.size()), 01802 &blink_non_cacheables_for_all_families_); 01803 } 01804 const GoogleString& blink_non_cacheables_for_all_families() const { 01805 return blink_non_cacheables_for_all_families_.value(); 01806 } 01807 01808 const GoogleString& blocking_rewrite_key() const { 01809 return blocking_rewrite_key_.value(); 01810 } 01811 void set_blocking_rewrite_key(const StringPiece& p) { 01812 set_option(p.as_string(), &blocking_rewrite_key_); 01813 } 01814 01815 bool rewrite_uncacheable_resources() const { 01816 return rewrite_uncacheable_resources_.value(); 01817 } 01818 01819 void set_rewrite_uncacheable_resources(bool x) { 01820 set_option(x, &rewrite_uncacheable_resources_); 01821 } 01822 01825 bool IsInBlinkCacheableFamily(const GoogleUrl& gurl) const; 01826 01831 int64 GetBlinkCacheTimeFor(const GoogleUrl& gurl) const; 01832 01837 GoogleString GetBlinkNonCacheableElementsFor(const GoogleUrl& gurl) const; 01838 01840 void AddBlinkCacheableFamily(const StringPiece url_pattern, 01841 int64 cache_time_ms, 01842 const StringPiece non_cacheable_elements); 01843 01844 void set_running_furious_experiment(bool x) { 01845 set_option(x, &running_furious_); 01846 } 01847 bool running_furious() const { 01848 return running_furious_.value(); 01849 } 01850 01852 void set_furious_ga_slot(int x) { 01853 set_option(x, &furious_ga_slot_); 01854 } 01855 01856 int furious_ga_slot() const { return furious_ga_slot_.value(); } 01857 01858 void set_report_unload_time(bool x) { 01859 set_option(x, &report_unload_time_); 01860 } 01861 bool report_unload_time() const { 01862 return report_unload_time_.value(); 01863 } 01864 01865 void set_implicit_cache_ttl_ms(int64 x) { 01866 set_option(x, &implicit_cache_ttl_ms_); 01867 } 01868 int64 implicit_cache_ttl_ms() const { 01869 return implicit_cache_ttl_ms_.value(); 01870 } 01871 01872 void set_x_header_value(const StringPiece& p) { 01873 set_option(p.as_string(), &x_header_value_); 01874 } 01875 const GoogleString& x_header_value() const { 01876 return x_header_value_.value(); 01877 } 01878 01879 void set_distributed_rewrite_servers(const StringPiece& p) { 01880 set_option(p.as_string(), &distributed_rewrite_servers_); 01881 } 01882 const GoogleString& distributed_rewrite_servers() const { 01883 return distributed_rewrite_servers_.value(); 01884 } 01885 01886 void set_distributed_rewrite_timeout_ms(const int64 x) { 01887 set_option(x, &distributed_rewrite_timeout_ms_); 01888 } 01889 int64 distributed_rewrite_timeout_ms() const { 01890 return distributed_rewrite_timeout_ms_.value(); 01891 } 01892 01893 void set_avoid_renaming_introspective_javascript(bool x) { 01894 set_option(x, &avoid_renaming_introspective_javascript_); 01895 } 01896 bool avoid_renaming_introspective_javascript() const { 01897 return avoid_renaming_introspective_javascript_.value(); 01898 } 01899 01900 void set_passthrough_blink_for_last_invalid_response_code(bool x) { 01901 set_option(x, &passthrough_blink_for_last_invalid_response_code_); 01902 } 01903 bool passthrough_blink_for_last_invalid_response_code() const { 01904 return passthrough_blink_for_last_invalid_response_code_.value(); 01905 } 01906 01907 int64 blink_max_html_size_rewritable() const { 01908 return blink_max_html_size_rewritable_.value(); 01909 } 01910 void set_blink_max_html_size_rewritable(int64 x) { 01911 set_option(x, &blink_max_html_size_rewritable_); 01912 } 01913 01914 void set_apply_blink_if_no_families(bool x) { 01915 set_option(x, &apply_blink_if_no_families_); 01916 } 01917 bool apply_blink_if_no_families() const { 01918 return apply_blink_if_no_families_.value(); 01919 } 01920 01921 void set_critical_line_config(const StringPiece& p) { 01922 set_option(GoogleString(p.data(), p.size()), &critical_line_config_); 01923 } 01924 const GoogleString& critical_line_config() const { 01925 return critical_line_config_.value(); 01926 } 01927 01928 void set_forbid_all_disabled_filters(bool x) { 01929 set_option(x, &forbid_all_disabled_filters_); 01930 } 01931 bool forbid_all_disabled_filters() const { 01932 return forbid_all_disabled_filters_.value(); 01933 } 01934 01935 bool reject_blacklisted() const { return reject_blacklisted_.value(); } 01936 void set_reject_blacklisted(bool x) { 01937 set_option(x, &reject_blacklisted_); 01938 } 01939 01940 HttpStatus::Code reject_blacklisted_status_code() const { 01941 return static_cast<HttpStatus::Code>( 01942 reject_blacklisted_status_code_.value()); 01943 } 01944 void set_reject_blacklisted_status_code(HttpStatus::Code x) { 01945 set_option(static_cast<int>(x), &reject_blacklisted_status_code_); 01946 } 01947 01948 bool support_noscript_enabled() const { 01949 return support_noscript_enabled_.value(); 01950 } 01951 void set_support_noscript_enabled(bool x) { 01952 set_option(x, &support_noscript_enabled_); 01953 } 01954 01955 void set_max_combined_js_bytes(int64 x) { 01956 set_option(x, &max_combined_js_bytes_); 01957 } 01958 int64 max_combined_js_bytes() const { 01959 return max_combined_js_bytes_.value(); 01960 } 01961 01962 void set_pre_connect_url(const StringPiece& p) { 01963 set_option(GoogleString(p.data(), p.size()), &pre_connect_url_); 01964 } 01965 const GoogleString& pre_connect_url() const { 01966 return pre_connect_url_.value(); 01967 } 01968 void set_property_cache_http_status_stability_threshold(int x) { 01969 set_option(x, &property_cache_http_status_stability_threshold_); 01970 } 01971 int property_cache_http_status_stability_threshold() const { 01972 return property_cache_http_status_stability_threshold_.value(); 01973 } 01974 01975 void set_max_rewrite_info_log_size(int x) { 01976 set_option(x, &max_rewrite_info_log_size_); 01977 } 01978 int max_rewrite_info_log_size() const { 01979 return max_rewrite_info_log_size_.value(); 01980 } 01981 01982 void set_enable_aggressive_rewriters_for_mobile(bool x) { 01983 set_option(x, &enable_aggressive_rewriters_for_mobile_); 01984 } 01985 bool enable_aggressive_rewriters_for_mobile() const { 01986 return enable_aggressive_rewriters_for_mobile_.value(); 01987 } 01988 01989 void set_allow_logging_urls_in_log_record(bool x) { 01990 set_option(x, &allow_logging_urls_in_log_record_); 01991 } 01992 bool allow_logging_urls_in_log_record() const { 01993 return allow_logging_urls_in_log_record_.value(); 01994 } 01995 02011 virtual void Merge(const RewriteOptions& src); 02012 02015 void Allow(const StringPiece& wildcard_pattern) { 02016 Modify(); 02017 allow_resources_.Allow(wildcard_pattern); 02018 } 02019 02022 void Disallow(const StringPiece& wildcard_pattern) { 02023 Modify(); 02024 allow_resources_.Disallow(wildcard_pattern); 02025 } 02026 02030 virtual void DisallowTroublesomeResources(); 02031 02036 virtual void DisallowResourcesForProxy(); 02037 02038 DomainLawyer* domain_lawyer() { return &domain_lawyer_; } 02039 const DomainLawyer* domain_lawyer() const { return &domain_lawyer_; } 02040 02041 FileLoadPolicy* file_load_policy() { return &file_load_policy_; } 02042 const FileLoadPolicy* file_load_policy() const { return &file_load_policy_; } 02043 02046 bool IsAllowed(const StringPiece& url) const { 02047 return allow_resources_.Match(url, true); 02048 } 02049 02051 void RetainComment(const StringPiece& comment) { 02052 Modify(); 02053 retain_comments_.Allow(comment); 02054 } 02055 02059 bool IsRetainedComment(const StringPiece& comment) const { 02060 return retain_comments_.Match(comment, false); 02061 } 02062 02064 void DisableLazyloadForClassName(const StringPiece& class_name) { 02065 Modify(); 02066 lazyload_enabled_classes_.Disallow(class_name); 02067 } 02068 02070 bool IsLazyloadEnabledForClassName(const StringPiece& class_name) const { 02071 return lazyload_enabled_classes_.Match(class_name, true); 02072 } 02073 02074 void set_override_caching_ttl_ms(int64 x) { 02075 set_option(x, &override_caching_ttl_ms_); 02076 } 02077 int64 override_caching_ttl_ms() const { 02078 return override_caching_ttl_ms_.value(); 02079 } 02080 02083 void AddOverrideCacheTtl(const StringPiece& wildcard) { 02084 Modify(); 02085 override_caching_wildcard_.Allow(wildcard); 02086 } 02087 02089 bool IsCacheTtlOverridden(const StringPiece& url) const { 02090 return override_caching_wildcard_.Match(url, false); 02091 } 02092 02093 void AddRejectedUrlWildcard(const GoogleString& wildcard) { 02094 AddRejectedHeaderWildcard(kRejectedRequestUrlKeyName, wildcard); 02095 } 02096 02097 void AddRejectedHeaderWildcard(const StringPiece& header_name, 02098 const GoogleString& wildcard) { 02099 Modify(); 02100 std::pair<FastWildcardGroupMap::iterator, bool> insert_result = 02101 rejected_request_map_.insert(std::make_pair( 02102 header_name, static_cast<FastWildcardGroup*>(NULL))); 02103 02104 if (insert_result.second) { 02105 insert_result.first->second = new FastWildcardGroup; 02106 } 02107 insert_result.first->second->Allow(wildcard); 02108 } 02109 02110 bool IsRejectedUrl(const GoogleString& url) const { 02111 return IsRejectedRequest(kRejectedRequestUrlKeyName, url); 02112 } 02113 02114 bool IsRejectedRequest(const StringPiece& header_name, 02115 const StringPiece& value) const { 02116 FastWildcardGroupMap::const_iterator it = rejected_request_map_.find( 02117 header_name); 02118 if (it != rejected_request_map_.end()) { 02119 return it->second->Match(value, false); 02120 } 02121 return false; 02122 } 02126 virtual RewriteOptions* Clone() const; 02127 02133 void ComputeSignature(const Hasher* hasher); 02134 02141 void ClearSignatureWithCaution() { 02142 frozen_ = false; 02143 signature_.clear(); 02144 } 02145 02148 void ClearSignatureForTesting() { 02149 ClearSignatureWithCaution(); 02150 } 02151 02153 const GoogleString& signature() const { 02161 ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex()); 02162 DCHECK(frozen_); 02163 return signature_; 02164 } 02165 02166 virtual GoogleString OptionsToString() const; 02167 02170 virtual GoogleString ToExperimentString() const; 02171 02175 virtual GoogleString ToExperimentDebugString() const; 02176 02178 virtual bool NeedLowResImages() const { 02179 return Enabled(kDelayImages); 02180 } 02181 02184 static Filter LookupFilterById(const StringPiece& filter_id); 02185 02189 static OptionEnum LookupOptionEnumById(const StringPiece& option_id); 02190 02192 static const char* LookupOptionEnum(OptionEnum option_enum) { 02193 return (option_enum < kEndOfOptions) ? 02194 option_enum_to_name_array_[option_enum] : NULL; 02195 } 02196 02197 static OptionEnum LookupOption(const StringPiece& option_name); 02198 02201 const OptionBaseVector& all_options() const { 02202 return all_options_; 02203 } 02204 02205 protected: 02209 template<class ValueType> 02210 class Property : public PropertyBase { 02211 public: 02216 Property(ValueType default_value, 02217 const char* id, 02218 OptionEnum option_enum) 02219 : PropertyBase(id, option_enum), 02220 default_value_(default_value) { 02221 } 02222 02223 void set_default(ValueType value) { default_value_ = value; } 02224 const ValueType& default_value() const { return default_value_; } 02225 02226 private: 02227 ValueType default_value_; 02228 02229 DISALLOW_COPY_AND_ASSIGN(Property); 02230 }; 02231 02246 template<class RewriteOptionsSubclass, class OptionClass> 02247 class PropertyLeaf : public Property<typename OptionClass::ValueType> { 02248 public: 02252 typedef OptionClass RewriteOptionsSubclass::*OptionOffset; 02253 typedef typename OptionClass::ValueType ValueType; 02254 02255 PropertyLeaf(ValueType default_value, 02256 OptionOffset offset, 02257 const char* id, 02258 OptionEnum option_enum) 02259 : Property<ValueType>(default_value, id, option_enum), 02260 offset_(offset) { 02261 } 02262 02263 virtual void InitializeOption(RewriteOptions* options) const { 02264 RewriteOptionsSubclass* options_subclass = 02265 static_cast<RewriteOptionsSubclass*>(options); 02266 OptionClass& option = options_subclass->*offset_; 02267 option.set_property(this); 02268 DCHECK_NE(-1, this->index()) << "Call Property::set_index first."; 02269 options->set_option_at(this->index(), &option); 02270 } 02271 02272 private: 02273 OptionOffset offset_; 02274 02275 DISALLOW_COPY_AND_ASSIGN(PropertyLeaf); 02276 }; 02277 02287 template<class T> class OptionTemplateBase : public OptionBase { 02288 public: 02289 typedef T ValueType; 02290 02291 OptionTemplateBase() : was_set_(false), property_(NULL) {} 02292 02293 virtual bool was_set() const { return was_set_; } 02294 02295 void set(const T& val) { 02296 was_set_ = true; 02297 value_ = val; 02298 } 02299 02300 void set_default(const T& val) { 02301 if (!was_set_) { 02302 value_ = val; 02303 } 02304 } 02305 02306 const T& value() const { return value_; } 02307 02313 virtual void Merge(const OptionBase* src) { 02314 DCHECK(option_enum() == src->option_enum()); 02315 MergeHelper(static_cast<const OptionTemplateBase*>(src)); 02316 } 02317 02318 void MergeHelper(const OptionTemplateBase* src) { 02321 if (src->was_set_ || !was_set_) { 02322 value_ = src->value_; 02323 was_set_ = src->was_set_; 02324 } 02325 } 02326 02328 void set_property(const Property<T>* property) { 02329 property_ = property; 02330 02335 value_ = property->default_value(); 02336 } 02337 virtual const Property<T>* property() const { return property_; } 02338 02347 void set_global_default(const T& val) { 02348 Property<T>* property = const_cast<Property<T>*>(property_); 02349 property->set_default(val); 02350 } 02351 02360 void DoNotUseForSignatureComputation() { 02361 Property<T>* property = const_cast<Property<T>*>(property_); 02362 property->set_do_not_use_for_signature_computation(true); 02363 } 02364 02365 private: 02366 bool was_set_; 02367 T value_; 02368 const Property<T>* property_; 02369 02370 DISALLOW_COPY_AND_ASSIGN(OptionTemplateBase); 02371 }; 02372 02377 template<class T> class Option : public OptionTemplateBase<T> { 02378 public: 02379 Option() {} 02380 02382 virtual bool SetFromString(const GoogleString& value_string) { 02383 T value; 02384 bool success = RewriteOptions::ParseFromString(value_string, &value); 02385 if (success) { 02386 this->set(value); 02387 } 02388 return success; 02389 } 02390 02391 virtual GoogleString Signature(const Hasher* hasher) const { 02392 return RewriteOptions::OptionSignature(this->value(), hasher); 02393 } 02394 02395 virtual GoogleString ToString() const { 02396 return RewriteOptions::ToString(this->value()); 02397 } 02398 02399 private: 02400 DISALLOW_COPY_AND_ASSIGN(Option); 02401 }; 02402 02415 class MutexedOptionInt64MergeWithMax : public Option<int64> { 02416 public: 02417 MutexedOptionInt64MergeWithMax(); 02418 virtual ~MutexedOptionInt64MergeWithMax(); 02419 02424 virtual void Merge(const OptionBase* src_base); 02425 02436 void checked_set(const int64& value) { 02437 mutex_->DCheckLocked(); 02438 Option<int64>::set(value); 02439 } 02440 02454 ThreadSystem::RWLock* mutex() const { return mutex_.get(); } 02455 02461 void set_mutex(ThreadSystem::RWLock* lock) { mutex_.reset(lock); } 02462 02463 private: 02464 scoped_ptr<ThreadSystem::RWLock> mutex_; 02465 }; 02466 02467 protected: 02469 template<class RewriteOptionsSubclass, class OptionClass> 02470 static PropertyBase* AddProperty( 02471 typename OptionClass::ValueType default_value, 02472 OptionClass RewriteOptionsSubclass::*offset, 02473 const char* id, 02474 OptionEnum option_enum, 02475 OptionScope scope, 02476 const char* help_text, 02477 Properties* properties) { 02478 PropertyBase* property = 02479 new PropertyLeaf<RewriteOptionsSubclass, OptionClass>( 02480 default_value, offset, id, option_enum); 02481 property->set_scope(scope); 02482 property->set_help_text(help_text); 02483 properties->push_back(property); 02484 return property; 02485 } 02486 02500 static void MergeSubclassProperties(Properties* properties); 02501 02503 void ForbidFiltersForPreserveUrl(); 02504 02510 void set_option_at(int index, OptionBase* option) { 02511 all_options_[index] = option; 02512 } 02513 02517 template<class T> 02518 void set_option(const T& new_value, OptionTemplateBase<T>* option) { 02519 option->set(new_value); 02520 Modify(); 02521 } 02522 02524 void Modify(); 02525 02533 void set_default_x_header_value(const StringPiece& x_header_value) { 02534 x_header_value_.set_global_default(x_header_value.as_string()); 02535 } 02536 02539 bool SetupFuriousRewriters(); 02540 02542 virtual void SetRequiredFuriousFilters(); 02543 02547 bool InsertFuriousSpecInVector(FuriousSpec* spec); 02548 02550 Option<BeaconUrl> beacon_url_; 02551 02553 Option<GoogleString> x_header_value_; 02554 02555 private: 02556 struct OptionIdCompare; 02557 02558 static Properties* properties_; 02559 static Properties* all_properties_; 02560 02561 FRIEND_TEST(RewriteOptionsTest, FuriousMergeTest); 02562 typedef std::vector<Filter> FilterVector; 02563 02570 struct PrioritizeVisibleContentFamily { 02571 PrioritizeVisibleContentFamily(StringPiece url_pattern_string, 02572 int64 cache_time_ms_in, 02573 StringPiece non_cacheable_elements_in) 02574 : url_pattern(url_pattern_string), 02575 cache_time_ms(cache_time_ms_in), 02576 non_cacheable_elements(non_cacheable_elements_in.data(), 02577 non_cacheable_elements_in.size()) {} 02578 02579 PrioritizeVisibleContentFamily* Clone() const { 02580 return new PrioritizeVisibleContentFamily( 02581 url_pattern.spec(), cache_time_ms, non_cacheable_elements); 02582 } 02583 02584 GoogleString ComputeSignature() const { 02585 return StrCat(url_pattern.spec(), ";", Integer64ToString(cache_time_ms), 02586 ";", non_cacheable_elements); 02587 } 02588 02589 GoogleString ToString() const { 02590 return StrCat("URL pattern: ", url_pattern.spec(), ", Cache time (ms): ", 02591 Integer64ToString(cache_time_ms), ", Non-cacheable: ", 02592 non_cacheable_elements); 02593 } 02594 02595 Wildcard url_pattern; 02596 int64 cache_time_ms; 02597 GoogleString non_cacheable_elements; 02598 }; 02599 02602 struct UrlCacheInvalidationEntry { 02603 UrlCacheInvalidationEntry(StringPiece url_pattern_in, 02604 int64 timestamp_ms_in, 02605 bool is_strict_in) 02606 : url_pattern(url_pattern_in), 02607 timestamp_ms(timestamp_ms_in), 02608 is_strict(is_strict_in) {} 02609 02610 UrlCacheInvalidationEntry* Clone() const { 02611 return new UrlCacheInvalidationEntry( 02612 url_pattern.spec(), timestamp_ms, is_strict); 02613 } 02614 02615 GoogleString ComputeSignature() const { 02616 if (is_strict) { 02617 return ""; 02618 } 02619 return StrCat(url_pattern.spec(), "@", Integer64ToString(timestamp_ms)); 02620 } 02621 02622 GoogleString ToString() const { 02623 return StrCat( 02624 url_pattern.spec(), ", ", (is_strict ? "STRICT" : "REFERENCE"), " @ ", 02625 Integer64ToString(timestamp_ms)); 02626 } 02627 02628 Wildcard url_pattern; 02629 int64 timestamp_ms; 02630 bool is_strict; 02631 }; 02632 02633 typedef std::vector<UrlCacheInvalidationEntry*> 02634 UrlCacheInvalidationEntryVector; 02635 02649 template<class OptionClass, class RewriteOptionsSubclass> 02650 static void AddRequestProperty(typename OptionClass::ValueType default_value, 02651 OptionClass RewriteOptionsSubclass::*offset, 02652 const char* id) { 02653 AddProperty(default_value, offset, id, kEndOfOptions, kProcessScope, 02654 NULL, properties_); 02655 } 02656 02659 template<class RewriteOptionsSubclass, class OptionClass> 02660 static void AddBaseProperty(typename OptionClass::ValueType default_value, 02661 OptionClass RewriteOptionsSubclass::*offset, 02662 const char* id, 02663 OptionEnum option_enum, 02664 OptionScope scope, 02665 const char* help) { 02666 AddProperty(default_value, offset, id, option_enum, scope, help, 02667 properties_); 02668 } 02669 02670 static void AddProperties(); 02671 bool AddCommaSeparatedListToFilterSetState( 02672 const StringPiece& filters, FilterSet* set, MessageHandler* handler); 02673 static bool AddCommaSeparatedListToFilterSet( 02674 const StringPiece& filters, FilterSet* set, MessageHandler* handler); 02675 static Filter LookupFilter(const StringPiece& filter_name); 02678 void ResolveConflicts(); 02681 static void InitOptionEnumToNameArray(); 02683 static void InitFilterIdToEnumArray(); 02684 static void InitOptionIdToEnumArray(); 02687 const PrioritizeVisibleContentFamily* FindPrioritizeVisibleContentFamily( 02688 const StringPiece str) const; 02689 02693 OptionSettingResult FormatSetOptionMessage( 02694 OptionSettingResult result, OptionEnum option_enum, StringPiece name, 02695 StringPiece value, GoogleString* msg); 02696 02699 static GoogleString OptionSignature(bool x, const Hasher* hasher) { 02700 return x ? "T" : "F"; 02701 } 02702 static GoogleString OptionSignature(int x, const Hasher* hasher) { 02703 return IntegerToString(x); 02704 } 02705 static GoogleString OptionSignature(int64 x, const Hasher* hasher) { 02706 return Integer64ToString(x); 02707 } 02708 static GoogleString OptionSignature(const GoogleString& x, 02709 const Hasher* hasher); 02710 static GoogleString OptionSignature(RewriteLevel x, 02711 const Hasher* hasher); 02712 static GoogleString OptionSignature(const BeaconUrl& beacon_url, 02713 const Hasher* hasher); 02714 02717 static GoogleString ToString(bool x) { 02718 return x ? "True" : "False"; 02719 } 02720 static GoogleString ToString(int x) { 02721 return IntegerToString(x); 02722 } 02723 static GoogleString ToString(int64 x) { 02724 return Integer64ToString(x); 02725 } 02726 static GoogleString ToString(const GoogleString& x) { 02727 return x; 02728 } 02729 static GoogleString ToString(RewriteLevel x); 02730 static GoogleString ToString(const BeaconUrl& beacon_url); 02731 02734 static bool PropertyLessThanByEnum(PropertyBase* p1, PropertyBase* p2) { 02735 return p1->option_enum() < p2->option_enum(); 02736 } 02737 02739 static bool OptionEnumLessThanArg(OptionBase* option, OptionEnum arg) { 02740 return option->option_enum() < arg; 02741 } 02742 02744 static bool CompareUrlCacheInvalidationEntry(UrlCacheInvalidationEntry* e1, 02745 UrlCacheInvalidationEntry* e2) { 02746 return e1->timestamp_ms < e2->timestamp_ms; 02747 } 02748 02750 static bool FilterEnumToIdAndNameEntryLessThanById( 02751 const FilterEnumToIdAndNameEntry* e1, 02752 const FilterEnumToIdAndNameEntry* e2) { 02753 return strcmp(e1->filter_id, e2->filter_id) < 0; 02754 } 02755 02756 bool modified_; 02757 bool frozen_; 02758 FilterSet enabled_filters_; 02759 FilterSet disabled_filters_; 02760 FilterSet forbidden_filters_; 02761 02764 FilterIdSet distributable_filters_; 02765 02771 Option<RewriteLevel> level_; 02772 02775 UrlCacheInvalidationEntryVector url_cache_invalidation_entries_; 02776 02777 MutexedOptionInt64MergeWithMax cache_invalidation_timestamp_; 02778 Option<int64> css_flatten_max_bytes_; 02779 Option<bool> cache_small_images_unrewritten_; 02781 Option<int64> image_resolution_limit_bytes_; 02782 Option<int64> css_image_inline_max_bytes_; 02783 Option<int64> css_inline_max_bytes_; 02784 Option<int64> css_outline_min_bytes_; 02785 02787 Option<bool> css_preserve_urls_; 02788 Option<bool> js_preserve_urls_; 02789 Option<bool> image_preserve_urls_; 02790 02791 Option<int64> image_inline_max_bytes_; 02792 Option<int64> js_inline_max_bytes_; 02793 Option<int64> js_outline_min_bytes_; 02794 Option<int64> progressive_jpeg_min_bytes_; 02796 Option<int64> max_html_cache_time_ms_; 02799 Option<int64> max_html_parse_bytes_; 02801 Option<int64> max_image_bytes_for_webp_in_css_; 02803 Option<int64> min_resource_cache_time_to_rewrite_ms_; 02804 Option<int64> idle_flush_time_ms_; 02805 Option<int64> flush_buffer_limit_bytes_; 02806 02810 Option<int64> blocking_fetch_timeout_ms_; 02811 02814 Option<int64> image_recompress_quality_; 02815 02817 Option<int64> image_jpeg_recompress_quality_; 02818 Option<int64> image_jpeg_recompress_quality_for_small_screens_; 02819 Option<int64> image_jpeg_num_progressive_scans_; 02820 Option<int64> image_jpeg_num_progressive_scans_for_small_screens_; 02821 Option<bool> image_retain_color_profile_; 02822 Option<bool> image_retain_color_sampling_; 02823 Option<bool> image_retain_exif_data_; 02824 02826 Option<int> image_limit_optimized_percent_; 02827 Option<int> image_limit_resize_area_percent_; 02828 02830 Option<int64> image_webp_recompress_quality_; 02831 Option<int64> image_webp_recompress_quality_for_small_screens_; 02832 Option<int64> image_webp_timeout_ms_; 02833 02834 Option<int> image_max_rewrites_at_once_; 02835 Option<int> max_url_segment_size_; 02836 Option<int> max_url_size_; 02837 02838 02839 Option<int> rewrite_deadline_ms_; 02841 Option<int> domain_shard_count_; 02842 02843 Option<EnabledEnum> enabled_; 02844 02845 Option<bool> distributable_; 02846 02849 Option<bool> add_options_to_urls_; 02850 02852 Option<bool> in_place_rewriting_enabled_; 02854 Option<bool> in_place_wait_for_optimized_; 02857 Option<int> in_place_rewrite_deadline_ms_; 02860 Option<bool> in_place_preemptive_rewrite_css_; 02862 Option<bool> in_place_preemptive_rewrite_css_images_; 02865 Option<bool> in_place_preemptive_rewrite_images_; 02868 Option<bool> in_place_preemptive_rewrite_javascript_; 02869 Option<bool> combine_across_paths_; 02870 Option<bool> log_rewrite_timing_; 02871 Option<bool> log_url_indices_; 02872 Option<bool> lowercase_html_names_; 02873 Option<bool> always_rewrite_css_; 02874 Option<bool> respect_vary_; 02875 Option<bool> respect_x_forwarded_proto_; 02876 Option<bool> flush_html_; 02879 Option<bool> serve_stale_if_fetch_error_; 02881 Option<bool> enable_blink_critical_line_; 02886 Option<bool> default_cache_html_; 02891 Option<bool> modify_caching_headers_; 02895 Option<bool> lazyload_images_after_onload_; 02898 Option<GoogleString> lazyload_images_blank_url_; 02902 Option<bool> inline_only_critical_images_; 02905 Option<bool> critical_images_beacon_enabled_; 02908 Option<bool> client_domain_rewrite_; 02911 Option<bool> domain_rewrite_hyperlinks_; 02912 02916 Option<bool> running_furious_; 02917 02918 Option<int> furious_ga_slot_; 02919 02922 Option<bool> increase_speed_tracking_; 02923 02927 Option<bool> report_unload_time_; 02928 02930 Option<bool> flush_more_resources_early_if_time_permits_; 02931 02933 Option<bool> flush_more_resources_in_ie_and_firefox_; 02934 02936 Option<bool> enable_defer_js_experimental_; 02937 02939 Option<bool> enable_inline_preview_images_experimental_; 02940 02942 Option<bool> lazyload_highres_images_; 02943 02946 Option<bool> avoid_renaming_introspective_javascript_; 02947 02949 Option<bool> override_ie_document_mode_; 02950 02952 Option<bool> test_instant_fetch_rewrite_deadline_; 02953 02959 Option<GoogleString> blocking_rewrite_key_; 02960 02964 Option<int> beacon_reinstrument_time_sec_; 02965 02968 Option<int> max_inlined_preview_images_index_; 02970 Option<int64> min_image_size_low_resolution_bytes_; 02972 Option<int64> max_image_size_low_resolution_bytes_; 02973 02976 Option<bool> oblivious_pagespeed_urls_; 02977 02979 Option<int64> finder_properties_cache_expiration_time_ms_; 02980 02984 Option<int64> finder_properties_cache_refresh_time_ms_; 02987 Option<int64> furious_cookie_duration_ms_; 02988 02991 Option<int64> metadata_cache_staleness_threshold_ms_; 02992 02994 Option<int64> metadata_input_errors_cache_ttl_ms_; 02995 02999 Option<int64> implicit_cache_ttl_ms_; 03000 03002 Option<int64> max_cacheable_response_content_length_; 03003 03010 std::vector<PrioritizeVisibleContentFamily*> 03011 prioritize_visible_content_families_; 03012 03013 Option<bool> is_blink_auto_blacklisted_; 03014 03015 Option<GoogleString> ga_id_; 03016 03019 Option<bool> passthrough_blink_for_last_invalid_response_code_; 03021 Option<int64> blink_max_html_size_rewritable_; 03024 Option<int64> blink_html_change_detection_time_ms_; 03028 Option<bool> apply_blink_if_no_families_; 03030 Option<bool> enable_blink_debug_dashboard_; 03032 Option<bool> enable_blink_html_change_detection_; 03034 Option<bool> enable_blink_html_change_detection_logging_; 03036 Option<bool> use_smart_diff_in_blink_; 03038 Option<bool> enable_lazyload_in_blink_; 03040 Option<bool> enable_prioritizing_scripts_; 03042 Option<bool> rewrite_uncacheable_resources_; 03044 Option<int64> override_blink_cache_time_ms_; 03047 Option<GoogleString> blink_non_cacheables_for_all_families_; 03049 Option<GoogleString> critical_line_config_; 03051 Option<GoogleString> distributed_rewrite_servers_; 03054 Option<int64> distributed_rewrite_timeout_ms_; 03060 Option<bool> forbid_all_disabled_filters_; 03062 Option<bool> enable_aggressive_rewriters_for_mobile_; 03063 03069 Option<bool> reject_blacklisted_; 03070 Option<int> reject_blacklisted_status_code_; 03071 03075 Option<bool> support_noscript_enabled_; 03076 03079 Option<int64> max_combined_js_bytes_; 03080 03082 Option<GoogleString> pre_connect_url_; 03085 Option<int> property_cache_http_status_stability_threshold_; 03087 Option<int> max_rewrite_info_log_size_; 03088 03093 Option<int64> override_caching_ttl_ms_; 03094 FastWildcardGroup override_caching_wildcard_; 03095 03097 Option<bool> allow_logging_urls_in_log_record_; 03098 03102 OptionBaseVector all_options_; 03103 size_t initialized_options_; 03104 03106 static const char* option_enum_to_name_array_[kEndOfOptions]; 03107 03110 static const FilterEnumToIdAndNameEntry* filter_id_to_enum_array_[ 03111 kEndOfFilters]; 03112 03117 static const PropertyBase** option_id_to_property_array_; 03118 03125 bool options_uniqueness_checked_; 03126 03128 bool need_to_store_experiment_data_; 03130 int furious_id_; 03131 int furious_percent_; 03132 std::vector<FuriousSpec*> furious_specs_; 03133 03135 std::vector<NameValue*> custom_fetch_headers_; 03136 03139 scoped_ptr<std::vector<ElementAttributeCategory> > url_valued_attributes_; 03140 03141 JavascriptLibraryIdentification javascript_library_identification_; 03142 03143 DomainLawyer domain_lawyer_; 03144 FileLoadPolicy file_load_policy_; 03145 03146 FastWildcardGroup allow_resources_; 03147 FastWildcardGroup retain_comments_; 03148 FastWildcardGroup lazyload_enabled_classes_; 03149 03152 typedef std::map<StringPiece, FastWildcardGroup*> FastWildcardGroupMap; 03153 FastWildcardGroupMap rejected_request_map_; 03154 03155 GoogleString signature_; 03156 03157 DISALLOW_COPY_AND_ASSIGN(RewriteOptions); 03158 }; 03159 03160 } 03161 03162 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_