Page Speed Optimization Libraries
1.3.25.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/fast_wildcard_group.h" 00036 #include "net/instaweb/util/public/gtest_prod.h" 00037 #include "net/instaweb/util/public/scoped_ptr.h" 00038 #include "net/instaweb/util/public/string.h" 00039 #include "net/instaweb/util/public/string_util.h" 00040 #include "net/instaweb/util/public/thread_system.h" 00041 #include "net/instaweb/util/public/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 kCacheHtml, 00082 kCanonicalizeJavascriptLibraries, 00083 kCollapseWhitespace, 00084 kCollectFlushEarlyContentFilter, 00085 kCombineCss, 00086 kCombineHeads, 00087 kCombineJavascript, 00088 kComputeCriticalCss, 00089 kComputeVisibleText, 00090 kConvertGifToPng, 00091 kConvertJpegToProgressive, 00092 kConvertJpegToWebp, 00093 kConvertMetaTags, 00094 kConvertPngToJpeg, 00095 kConvertToWebpLossless, 00096 kDebug, 00097 kDecodeRewrittenUrls, 00098 kDeferIframe, 00099 kDeferJavascript, 00100 kDelayImages, 00101 kDetectReflowWithDeferJavascript, 00102 kDeterministicJs, 00103 kDisableJavascript, 00104 kDivStructure, 00105 kElideAttributes, 00106 kExperimentSpdy, 00107 kExplicitCloseTags, 00108 kExtendCacheCss, 00109 kExtendCacheImages, 00110 kExtendCachePdfs, 00111 kExtendCacheScripts, 00112 kFallbackRewriteCssUrls, 00113 kFlattenCssImports, 00114 kFlushSubresources, 00115 kHandleNoscriptRedirect, 00116 kHtmlWriterFilter, 00117 kInlineCss, 00118 kInlineImages, 00119 kInlineImportToLink, 00120 kInlineJavascript, 00121 kInPlaceOptimizeForBrowser, 00122 kInsertDnsPrefetch, 00123 kInsertGA, 00124 kInsertImageDimensions, 00125 kJpegSubsampling, 00126 kLazyloadImages, 00127 kLeftTrimUrls, 00128 kLocalStorageCache, 00129 kMakeGoogleAnalyticsAsync, 00130 kMoveCssAboveScripts, 00131 kMoveCssToHead, 00132 kOutlineCss, 00133 kOutlineJavascript, 00134 kPedantic, 00135 kPrioritizeCriticalCss, 00136 kPrioritizeVisibleContent, 00137 kProcessBlinkInBackground, 00138 kRecompressJpeg, 00139 kRecompressPng, 00140 kRecompressWebp, 00141 kRemoveComments, 00142 kRemoveQuotes, 00143 kResizeImages, 00144 kResizeMobileImages, 00145 kRewriteCss, 00146 kRewriteDomains, 00147 kRewriteJavascript, 00148 kRewriteStyleAttributes, 00149 kRewriteStyleAttributesWithUrl, 00150 kServeNonCacheableNonCritical, 00151 kSplitHtml, 00152 kSpriteImages, 00153 kSquashImagesForMobileScreen, 00154 kStripImageColorProfile, 00155 kStripImageMetaData, 00156 kStripNonCacheable, 00157 kStripScripts, 00158 kEndOfFilters 00159 }; 00160 00161 enum EnabledEnum { 00164 kEnabledOff, 00166 kEnabledOn, 00169 kEnabledUnplugged, 00170 }; 00171 00178 enum OptionEnum { 00179 kAddOptionsToUrls, 00180 kAlwaysRewriteCss, 00181 kAnalyticsID, 00182 kAvoidRenamingIntrospectiveJavascript, 00183 kBeaconUrl, 00184 kBlinkDesktopUserAgent, 00185 kBlinkMaxHtmlSizeRewritable, 00186 kBlinkNonCacheablesForAllFamilies, 00187 kCacheInvalidationTimestamp, 00188 kCacheSmallImagesUnrewritten, 00189 kClientDomainRewrite, 00190 kCombineAcrossPaths, 00191 kCriticalImagesBeaconEnabled, 00192 kCriticalLineConfig, 00193 kCssFlattenMaxBytes, 00194 kCssImageInlineMaxBytes, 00195 kCssInlineMaxBytes, 00196 kCssOutlineMinBytes, 00197 kCssPreserveURLs, 00198 kDefaultCacheHtml, 00199 kDomainRewriteHyperlinks, 00200 kDomainShardCount, 00201 kEnableAggressiveRewritersForMobile, 00202 kEnableBlinkCriticalLine, 00203 kEnableBlinkDashboard, 00204 kEnableBlinkForMobileDevices, 00205 kEnableBlinkHtmlChangeDetection, 00206 kEnableBlinkHtmlChangeDetectionLogging, 00207 kEnableDeferJsExperimental, 00208 kEnableFlushSubresourcesExperimental, 00209 kEnableInlinePreviewImagesExperimental, 00210 kEnableLazyloadInBlink, 00211 kEnablePrioritizingScripts, 00212 kEnabled, 00213 kFinderPropertiesCacheExpirationTimeMs, 00214 kFinderPropertiesCacheRefreshTimeMs, 00215 kFlushBufferLimitBytes, 00216 kFlushHtml, 00217 kFlushMoreResourcesEarlyIfTimePermits, 00218 kForbidAllDisabledFilters, 00219 kFuriousCookieDurationMs, 00220 kFuriousSlot, 00221 kIdleFlushTimeMs, 00222 kImageInlineMaxBytes, 00223 kImageJpegNumProgressiveScans, 00224 kImageJpegRecompressionQuality, 00225 kImageLimitOptimizedPercent, 00226 kImageLimitResizeAreaPercent, 00227 kImageMaxRewritesAtOnce, 00228 kImagePreserveURLs, 00229 kImageRecompressionQuality, 00230 kImageResolutionLimitBytes, 00231 kImageRetainColorProfile, 00232 kImageRetainColorSampling, 00233 kImageRetainExifData, 00234 kImageWebpRecompressionQuality, 00235 kImageWebpTimeoutMs, 00236 kImplicitCacheTtlMs, 00237 kInPlaceResourceOptimization, 00238 kInPlaceWaitForOptimized, 00239 kInPlacePreemptiveRewriteCss, 00240 kInPlacePreemptiveRewriteCssImages, 00241 kInPlacePreemptiveRewriteImages, 00242 kInPlacePreemptiveRewriteJavascript, 00243 kInPlaceRewriteDeadlineMs, 00244 kIncreaseSpeedTracking, 00245 kInlineOnlyCriticalImages, 00246 kJsInlineMaxBytes, 00247 kJsOutlineMinBytes, 00248 kJsPreserveURLs, 00249 kLazyloadImagesAfterOnload, 00250 kLazyloadImagesBlankUrl, 00251 kLogRewriteTiming, 00252 kLowercaseHtmlNames, 00253 kMaxCacheableResponseContentLength, 00254 kMaxCombinedJsBytes, 00255 kMaxHtmlCacheTimeMs, 00256 kMaxHtmlParseBytes, 00257 kMaxImageBytesForWebpInCss, 00258 kMaxImageSizeLowResolutionBytes, 00259 kMaxInlinedPreviewImagesIndex, 00260 kMaxRewriteInfoLogSize, 00261 kMaxUrlSegmentSize, 00262 kMaxUrlSize, 00263 kMinImageSizeLowResolutionBytes, 00264 kMinResourceCacheTimeToRewriteMs, 00265 kModifyCachingHeaders, 00266 kObliviousPagespeedUrls, 00267 kOverrideBlinkCacheTimeMs, 00268 kOverrideCachingTtlMs, 00269 kOverrideIeDocumentMode, 00270 kPassthroughBlinkForInvalidResponseCode, 00271 kProgressiveJpegMinBytes, 00272 kPropagateBlinkCacheDeletes, 00273 kRejectBlacklisted, 00274 kRejectBlacklistedStatusCode, 00275 kReportUnloadTime, 00276 kRespectVary, 00277 kRespectXForwardedProto, 00278 kRewriteDeadlineMs, 00279 kRewriteLevel, 00280 kRunningFurious, 00281 kServeStaleIfFetchError, 00282 kSupportNoScriptEnabled, 00283 kUseFixedUserAgentForBlinkCacheMisses, 00284 kUseSmartDiffInBlink, 00285 kXModPagespeedHeaderValue, 00286 kXPsaBlockingRewrite, 00287 00289 kAllow, 00290 kDisableFilters, 00291 kDisallow, 00292 kDomain, 00293 kEnableFilters, 00294 kExperimentVariable, 00295 kExperimentSpec, 00296 kForbidFilters, 00297 kRetainComment, 00298 00300 kCustomFetchHeader, 00301 kLoadFromFile, 00302 kLoadFromFileMatch, 00303 kLoadFromFileRule, 00304 kLoadFromFileRuleMatch, 00305 kMapOriginDomain, 00306 kMapRewriteDomain, 00307 kMapProxyDomain, 00308 kShardDomain, 00309 00311 kUrlValuedAttribute, 00312 kLibrary, 00313 00315 kCacheFlushFilename, 00316 kCacheFlushPollIntervalSec, 00317 kCollectRefererStatistics, 00318 kExperimentalFetchFromModSpdy, 00319 kFetchHttps, 00320 kFetcherProxy, 00321 kFetcherTimeOutMs, 00322 kFileCacheCleanInodeLimit, 00323 kFileCacheCleanIntervalMs, 00324 kFileCacheCleanSizeKb, 00325 kFileCachePath, 00326 kHashRefererStatistics, 00327 kLruCacheByteLimit, 00328 kLruCacheKbPerProcess, 00329 kMemcachedServers, 00330 kMemcachedThreads, 00331 kMemcachedTimeoutUs, 00332 kMessageBufferSize, 00333 kRateLimitBackgroundFetches, 00334 kRefererStatisticsOutputLevel, 00335 kSlurpDirectory, 00336 kSlurpFlushLimit, 00337 kSlurpReadOnly, 00338 kStatisticsEnabled, 00339 kStatisticsLoggingEnabled, 00340 kStatisticsLoggingFile, 00341 kStatisticsLoggingIntervalMs, 00342 kStatisticsLoggingChartsCSS, 00343 kStatisticsLoggingChartsJS, 00344 kTestProxy, 00345 kTestProxySlurp, 00346 kUseSharedMemLocking, 00347 kUseSharedMemMetadataCache, 00348 00351 kEndOfOptions 00352 }; 00353 00354 struct BeaconUrl { 00355 GoogleString http; 00356 GoogleString https; 00357 }; 00358 00359 struct NameValue { 00360 NameValue(const StringPiece& name_in, const StringPiece& value_in) { 00361 name_in.CopyToString(&name); 00362 value_in.CopyToString(&value); 00363 } 00364 GoogleString name; 00365 GoogleString value; 00366 }; 00367 00383 static const int kOptionsVersion = 13; 00384 00385 static const char kCacheExtenderId[]; 00386 static const char kCollectFlushEarlyContentFilterId[]; 00387 static const char kCssCombinerId[]; 00388 static const char kCssFilterId[]; 00389 static const char kCssImportFlattenerId[]; 00390 static const char kCssInlineId[]; 00391 static const char kImageCombineId[]; 00392 static const char kImageCompressionId[]; 00393 static const char kInPlaceRewriteId[]; 00394 static const char kJavascriptCombinerId[]; 00395 static const char kJavascriptInlineId[]; 00396 static const char kJavascriptMinId[]; 00397 static const char kLocalStorageCacheId[]; 00398 static const char kPrioritizeCriticalCssId[]; 00399 00400 static const char kPanelCommentPrefix[]; 00401 00404 static const char* FilterName(Filter filter); 00405 00408 static const char* FilterId(Filter filter); 00409 00411 static const Filter kFirstFilter = kAddBaseTag; 00412 00414 typedef std::set<Filter> FilterSet; 00415 00421 static bool AddByNameToFilterSet(const StringPiece& option, FilterSet* set, 00422 MessageHandler* handler); 00423 00426 typedef std::pair<StringPiece, StringPiece> OptionStringPair; 00427 typedef std::set<OptionStringPair> OptionSet; 00428 00431 class PropertyBase { 00432 public: 00433 PropertyBase(const char* id, OptionEnum option_enum) 00434 : id_(id), 00435 option_enum_(option_enum), 00436 do_not_use_for_signature_computation_(false), 00437 index_(-1) { 00438 } 00439 virtual ~PropertyBase(); 00440 00443 virtual void InitializeOption(RewriteOptions* options) const = 0; 00444 00445 void set_do_not_use_for_signature_computation(bool x) { 00446 do_not_use_for_signature_computation_ = x; 00447 } 00448 bool is_used_for_signature_computation() const { 00449 return !do_not_use_for_signature_computation_; 00450 } 00451 00452 void set_index(int index) { index_ = index; } 00453 const char* id() const { return id_; } 00454 OptionEnum option_enum() const { return option_enum_; } 00455 int index() const { return index_; } 00456 00457 private: 00458 const char* id_; 00459 OptionEnum option_enum_; 00460 bool do_not_use_for_signature_computation_; 00461 int index_; 00462 00463 DISALLOW_COPY_AND_ASSIGN(PropertyBase); 00464 }; 00465 00466 typedef std::vector<PropertyBase*> PropertyVector; 00467 00470 class OptionBase { 00471 public: 00472 OptionBase() {} 00473 virtual ~OptionBase(); 00474 00476 virtual bool SetFromString(const GoogleString& value_string) = 0; 00477 virtual void Merge(const OptionBase* src) = 0; 00478 virtual bool was_set() const = 0; 00479 virtual GoogleString Signature(const Hasher* hasher) const = 0; 00480 virtual GoogleString ToString() const = 0; 00481 const char* id() { return property()->id(); } 00482 OptionEnum option_enum() const { return property()->option_enum(); } 00483 bool is_used_for_signature_computation() const { 00484 return property()->is_used_for_signature_computation(); 00485 } 00486 virtual const PropertyBase* property() const = 0; 00487 }; 00488 00490 typedef std::vector<OptionBase*> OptionBaseVector; 00491 00492 enum RewriteLevel { 00497 kPassThrough, 00498 00504 kCoreFilters, 00505 00509 kTestingCoreFilters, 00510 00513 kAllFilters, 00514 }; 00515 00517 enum OptionSettingResult { 00518 kOptionOk, 00519 kOptionNameUnknown, 00520 kOptionValueInvalid 00521 }; 00522 00523 static const int64 kDefaultBlinkMaxHtmlSizeRewritable; 00524 static const int64 kDefaultCssFlattenMaxBytes; 00525 static const int64 kDefaultCssImageInlineMaxBytes; 00526 static const int64 kDefaultCssInlineMaxBytes; 00527 static const int64 kDefaultCssOutlineMinBytes; 00528 static const int64 kDefaultImageInlineMaxBytes; 00529 static const int64 kDefaultJsInlineMaxBytes; 00530 static const int64 kDefaultJsOutlineMinBytes; 00531 static const int64 kDefaultProgressiveJpegMinBytes; 00532 static const int64 kDefaultMaxCacheableResponseContentLength; 00533 static const int64 kDefaultMaxHtmlCacheTimeMs; 00534 static const int64 kDefaultMaxHtmlParseBytes; 00535 static const int64 kDefaultMaxImageBytesForWebpInCss; 00536 static const int64 kDefaultMetadataInputErrorsCacheTtlMs; 00537 static const int64 kDefaultMinResourceCacheTimeToRewriteMs; 00538 static const int64 kDefaultCacheInvalidationTimestamp; 00539 static const int64 kDefaultIdleFlushTimeMs; 00540 static const int64 kDefaultFlushBufferLimitBytes; 00541 static const int64 kDefaultImplicitCacheTtlMs; 00542 static const int64 kDefaultPrioritizeVisibleContentCacheTimeMs; 00543 static const char kDefaultBeaconUrl[]; 00544 static const int64 kDefaultImagesRecompressQuality; 00545 static const int64 kDefaultImageJpegRecompressQuality; 00546 static const int kDefaultImageLimitOptimizedPercent; 00547 static const int kDefaultImageLimitResizeAreaPercent; 00548 static const int64 kDefaultImageResolutionLimitBytes; 00549 static const int kDefaultImageJpegNumProgressiveScans; 00550 static const int64 kDefaultImageWebpRecompressQuality; 00551 static const int64 kDefaultImageWebpTimeoutMs; 00552 static const int kDefaultDomainShardCount; 00553 static const int64 kDefaultBlinkHtmlChangeDetectionTimeMs; 00554 static const int64 kDefaultOverrideBlinkCacheTimeMs; 00555 00558 static const int kDefaultMaxUrlSize; 00559 00560 static const int kDefaultImageMaxRewritesAtOnce; 00561 00566 static const int kDefaultMaxUrlSegmentSize; 00567 00569 static const int kDefaultRewriteDeadlineMs; 00570 00573 static const int kDefaultMaxInlinedPreviewImagesIndex; 00576 static const int64 kDefaultMinImageSizeLowResolutionBytes; 00579 static const int64 kDefaultMaxImageSizeLowResolutionBytes; 00581 static const int64 kDefaultFinderPropertiesCacheExpirationTimeMs; 00583 static const int64 kDefaultFinderPropertiesCacheRefreshTimeMs; 00584 00587 static const int64 kDefaultFuriousCookieDurationMs; 00588 00591 static const int64 kDefaultMetadataCacheStalenessThresholdMs; 00592 00594 static const int64 kDefaultMaxCombinedJsBytes; 00595 00596 static const int kDefaultFuriousTrafficPercent; 00598 static const int kDefaultFuriousSlot; 00599 00600 static const char kDefaultBlinkDesktopUserAgentValue[]; 00601 00602 static const char kDefaultBlockingRewriteKey[]; 00603 00604 static const char kRejectedRequestUrlKeyName[]; 00605 00606 static const int kDefaultPropertyCacheHttpStatusStabilityThreshold; 00607 00608 static const int kDefaultMaxRewriteInfoLogSize; 00609 00618 class FuriousSpec { 00619 public: 00624 FuriousSpec(const StringPiece& spec, RewriteOptions* options, 00625 MessageHandler* handler); 00626 00630 explicit FuriousSpec(int id); 00631 00632 virtual ~FuriousSpec(); 00633 00635 virtual FuriousSpec* Clone(); 00636 00637 bool is_valid() const { return id_ >= 0; } 00638 00640 int id() const { return id_; } 00641 int percent() const { return percent_; } 00642 GoogleString ga_id() const { return ga_id_; } 00643 int slot() const { return ga_variable_slot_; } 00644 RewriteLevel rewrite_level() const { return rewrite_level_; } 00645 FilterSet enabled_filters() const { return enabled_filters_; } 00646 FilterSet disabled_filters() const { return disabled_filters_; } 00647 OptionSet filter_options() const { return filter_options_; } 00648 int64 css_inline_max_bytes() const { return css_inline_max_bytes_; } 00649 int64 js_inline_max_bytes() const { return js_inline_max_bytes_; } 00650 int64 image_inline_max_bytes() const { return image_inline_max_bytes_; } 00651 bool use_default() const { return use_default_; } 00652 00653 protected: 00657 void Merge(const FuriousSpec& spec); 00658 00659 private: 00660 FRIEND_TEST(RewriteOptionsTest, FuriousMergeTest); 00661 00664 void Initialize(const StringPiece& spec, MessageHandler* handler); 00665 00666 int id_; 00667 GoogleString ga_id_; 00668 int ga_variable_slot_; 00669 int percent_; 00670 RewriteLevel rewrite_level_; 00671 FilterSet enabled_filters_; 00672 FilterSet disabled_filters_; 00673 OptionSet filter_options_; 00674 int64 css_inline_max_bytes_; 00675 int64 js_inline_max_bytes_; 00676 int64 image_inline_max_bytes_; 00679 bool use_default_; 00680 DISALLOW_COPY_AND_ASSIGN(FuriousSpec); 00681 }; 00682 00684 struct ElementAttributeCategory { 00685 GoogleString element; 00686 GoogleString attribute; 00687 semantic_type::Category category; 00688 }; 00689 00696 class Properties { 00697 public: 00706 static bool Initialize(Properties** properties); 00707 00716 static bool Terminate(Properties** properties_handle); 00717 00719 int size() const { return property_vector_.size(); } 00720 00721 const PropertyBase* property(int index) const { 00722 return property_vector_[index]; 00723 } 00724 PropertyBase* property(int index) { return property_vector_[index]; } 00725 00731 void Merge(Properties* properties); 00732 00733 void push_back(PropertyBase* p) { property_vector_.push_back(p); } 00734 00735 private: 00738 Properties(); 00739 ~Properties(); 00740 00744 int initialization_count_; 00745 00750 bool owns_properties_; 00751 PropertyVector property_vector_; 00752 }; 00753 00755 struct FilterEnumToIdAndNameEntry { 00756 RewriteOptions::Filter filter_enum; 00757 const char* filter_id; 00758 const char* filter_name; 00759 }; 00760 00761 static bool ParseRewriteLevel(const StringPiece& in, RewriteLevel* out); 00762 00766 static bool ParseBeaconUrl(const StringPiece& in, BeaconUrl* out); 00767 00771 bool ImageOptimizationEnabled() const; 00772 00773 RewriteOptions(); 00774 virtual ~RewriteOptions(); 00775 00779 static bool Initialize(); 00780 static bool Terminate(); 00781 00786 void InitializeOptions(const Properties* properties); 00787 00788 bool modified() const { return modified_; } 00789 00795 void SetDefaultRewriteLevel(RewriteLevel level) { 00797 level_.set_default(level); 00798 } 00799 void SetRewriteLevel(RewriteLevel level) { 00800 set_option(level, &level_); 00801 } 00802 00804 void AddCustomFetchHeader(const StringPiece& name, const StringPiece& value); 00805 00806 const NameValue* custom_fetch_header(int i) const { 00807 return custom_fetch_headers_[i]; 00808 } 00809 00810 int num_custom_fetch_headers() const { 00811 return custom_fetch_headers_.size(); 00812 } 00813 00816 FuriousSpec* GetFuriousSpec(int id) const; 00817 00821 bool AvailableFuriousId(int id); 00822 00825 virtual bool AddFuriousSpec(const StringPiece& spec, MessageHandler* handler); 00826 00834 virtual bool SetFuriousState(int id); 00835 00839 void SetFuriousStateStr(const StringPiece& experiment_index); 00840 00841 int furious_id() const { return furious_id_; } 00842 00843 int furious_spec_id(int i) const { 00844 return furious_specs_[i]->id(); 00845 } 00846 00850 GoogleString GetFuriousStateStr() const; 00851 00852 FuriousSpec* furious_spec(int i) const { 00853 return furious_specs_[i]; 00854 } 00855 00856 int num_furious_experiments() const { return furious_specs_.size(); } 00857 00869 void AddUrlValuedAttribute(const StringPiece& element, 00870 const StringPiece& attribute, 00871 semantic_type::Category category); 00872 00875 void UrlValuedAttribute(int index, 00876 StringPiece* element, 00877 StringPiece* attribute, 00878 semantic_type::Category* category) const; 00879 00880 int num_url_valued_attributes() const { 00881 if (url_valued_attributes_ == NULL) { 00882 return 0; 00883 } else { 00884 return url_valued_attributes_->size(); 00885 } 00886 } 00887 00889 bool RegisterLibrary( 00890 uint64 bytes, StringPiece md5_hash, StringPiece canonical_url) { 00891 return javascript_library_identification_.RegisterLibrary( 00892 bytes, md5_hash, canonical_url); 00893 } 00894 00897 const JavascriptLibraryIdentification* javascript_library_identification() 00898 const { 00899 if (Enabled(kCanonicalizeJavascriptLibraries)) { 00900 return &javascript_library_identification_; 00901 } else { 00902 return NULL; 00903 } 00904 } 00905 00906 RewriteLevel level() const { return level_.value(); } 00907 00912 bool AdjustFiltersByCommaSeparatedList(const StringPiece& filters, 00913 MessageHandler* handler); 00914 00918 bool EnableFiltersByCommaSeparatedList(const StringPiece& filters, 00919 MessageHandler* handler); 00920 00924 bool DisableFiltersByCommaSeparatedList(const StringPiece& filters, 00925 MessageHandler* handler); 00926 00930 bool ForbidFiltersByCommaSeparatedList(const StringPiece& filters, 00931 MessageHandler* handler); 00932 00940 void DisableAllFiltersNotExplicitlyEnabled(); 00941 00945 void EnableFilter(Filter filter); 00948 void ForceEnableFilter(Filter filter); 00949 void DisableFilter(Filter filter); 00950 void ForbidFilter(Filter filter); 00951 void EnableFilters(const FilterSet& filter_set); 00952 void DisableFilters(const FilterSet& filter_set); 00953 void ForbidFilters(const FilterSet& filter_set); 00956 void ClearFilters(); 00957 00960 void EnableExtendCacheFilters(); 00961 00962 bool Enabled(Filter filter) const; 00963 bool Forbidden(StringPiece filter_id) const; 00964 00966 void GetEnabledFiltersRequiringScriptExecution(FilterSet* filter_set) const; 00967 00969 void DisableFiltersRequiringScriptExecution(); 00970 00975 static bool AddCommaSeparatedListToOptionSet( 00976 const StringPiece& options, OptionSet* set, MessageHandler* handler); 00977 00982 OptionSettingResult SetOptionFromName( 00983 StringPiece name, StringPiece value, GoogleString* msg); 00984 00990 OptionSettingResult ParseAndSetOptionFromName1( 00991 StringPiece name, StringPiece arg, 00992 GoogleString* msg, MessageHandler* handler); 00993 00994 OptionSettingResult ParseAndSetOptionFromName2( 00995 StringPiece name, StringPiece arg1, StringPiece arg2, 00996 GoogleString* msg, MessageHandler* handler); 00997 00998 OptionSettingResult ParseAndSetOptionFromName3( 00999 StringPiece name, StringPiece arg1, StringPiece arg2, StringPiece arg3, 01000 GoogleString* msg, MessageHandler* handler); 01001 01005 virtual OptionSettingResult ParseAndSetOptionFromEnum1( 01006 OptionEnum name, StringPiece arg, 01007 GoogleString* msg, MessageHandler* handler); 01008 01009 virtual OptionSettingResult ParseAndSetOptionFromEnum2( 01010 OptionEnum name, StringPiece arg1, StringPiece arg2, 01011 GoogleString* msg, MessageHandler* handler); 01012 01013 virtual OptionSettingResult ParseAndSetOptionFromEnum3( 01014 OptionEnum name, StringPiece arg1, StringPiece arg2, StringPiece arg3, 01015 GoogleString* msg, MessageHandler* handler); 01016 01018 OptionSettingResult SetOptionFromEnum(OptionEnum option_enum, 01019 StringPiece value); 01020 01026 bool OptionValue(OptionEnum option_enum, const char** id, 01027 bool* was_set, GoogleString* value) const; 01028 01031 bool SetOptionsFromName(const OptionSet& option_set); 01032 01035 bool SetOptionFromNameAndLog(StringPiece name, 01036 StringPiece value, 01037 MessageHandler* handler); 01038 01041 static bool ParseFromString(const GoogleString& value_string, bool* value); 01042 static bool ParseFromString(const GoogleString& value_string, 01043 EnabledEnum* value); 01044 static bool ParseFromString(const GoogleString& value_string, int* value) { 01045 return StringToInt(value_string, value); 01046 } 01047 static bool ParseFromString(const GoogleString& value_string, int64* value) { 01048 return StringToInt64(value_string, value); 01049 } 01050 static bool ParseFromString(const GoogleString& value_string, 01051 GoogleString* value) { 01052 *value = value_string; 01053 return true; 01054 } 01055 static bool ParseFromString(const GoogleString& value_string, 01056 RewriteLevel* value) { 01057 return ParseRewriteLevel(value_string, value); 01058 } 01059 static bool ParseFromString(const GoogleString& value_string, 01060 BeaconUrl* value) { 01061 return ParseBeaconUrl(value_string, value); 01062 } 01063 01066 int64 css_outline_min_bytes() const { return css_outline_min_bytes_.value(); } 01067 void set_css_outline_min_bytes(int64 x) { 01068 set_option(x, &css_outline_min_bytes_); 01069 } 01070 01071 GoogleString ga_id() const { return ga_id_.value(); } 01072 void set_ga_id(GoogleString id) { 01073 set_option(id, &ga_id_); 01074 } 01075 01076 bool increase_speed_tracking() const { 01077 return increase_speed_tracking_.value(); 01078 } 01079 void set_increase_speed_tracking(bool x) { 01080 set_option(x, &increase_speed_tracking_); 01081 } 01082 01083 int64 js_outline_min_bytes() const { return js_outline_min_bytes_.value(); } 01084 void set_js_outline_min_bytes(int64 x) { 01085 set_option(x, &js_outline_min_bytes_); 01086 } 01087 01088 int64 progressive_jpeg_min_bytes() const { 01089 return progressive_jpeg_min_bytes_.value(); 01090 } 01091 void set_progressive_jpeg_min_bytes(int64 x) { 01092 set_option(x, &progressive_jpeg_min_bytes_); 01093 } 01094 01095 int64 css_flatten_max_bytes() const { return css_flatten_max_bytes_.value(); } 01096 void set_css_flatten_max_bytes(int64 x) { 01097 set_option(x, &css_flatten_max_bytes_); 01098 } 01099 bool cache_small_images_unrewritten() const { 01100 return cache_small_images_unrewritten_.value(); 01101 } 01102 void set_cache_small_images_unrewritten(bool x) { 01103 set_option(x, &cache_small_images_unrewritten_); 01104 } 01105 int64 image_resolution_limit_bytes() const { 01106 return image_resolution_limit_bytes_.value(); 01107 } 01108 void set_image_resolution_limit_bytes(int64 x) { 01109 set_option(x, &image_resolution_limit_bytes_); 01110 } 01111 01113 int64 ImageInlineMaxBytes() const; 01114 void set_image_inline_max_bytes(int64 x); 01116 int64 CssImageInlineMaxBytes() const; 01117 void set_css_image_inline_max_bytes(int64 x) { 01118 set_option(x, &css_image_inline_max_bytes_); 01119 } 01121 int64 MaxImageInlineMaxBytes() const; 01122 int64 css_inline_max_bytes() const { return css_inline_max_bytes_.value(); } 01123 void set_css_inline_max_bytes(int64 x) { 01124 set_option(x, &css_inline_max_bytes_); 01125 } 01126 int64 js_inline_max_bytes() const { return js_inline_max_bytes_.value(); } 01127 void set_js_inline_max_bytes(int64 x) { 01128 set_option(x, &js_inline_max_bytes_); 01129 } 01130 int64 max_html_cache_time_ms() const { 01131 return max_html_cache_time_ms_.value(); 01132 } 01133 void set_max_html_cache_time_ms(int64 x) { 01134 set_option(x, &max_html_cache_time_ms_); 01135 } 01136 int64 max_html_parse_bytes() const { 01137 return max_html_parse_bytes_.value(); 01138 } 01139 void set_max_html_parse_bytes(int64 x) { 01140 set_option(x, &max_html_parse_bytes_); 01141 } 01142 int64 max_image_bytes_for_webp_in_css() const { 01143 return max_image_bytes_for_webp_in_css_.value(); 01144 } 01145 void set_max_image_bytes_for_webp_in_css(int64 x) { 01146 set_option(x, &max_image_bytes_for_webp_in_css_); 01147 } 01148 int64 max_cacheable_response_content_length() const { 01149 return max_cacheable_response_content_length_.value(); 01150 } 01151 void set_max_cacheable_response_content_length(int64 x) { 01152 set_option(x, &max_cacheable_response_content_length_); 01153 } 01154 int64 min_resource_cache_time_to_rewrite_ms() const { 01155 return min_resource_cache_time_to_rewrite_ms_.value(); 01156 } 01157 void set_min_resource_cache_time_to_rewrite_ms(int64 x) { 01158 set_option(x, &min_resource_cache_time_to_rewrite_ms_); 01159 } 01160 bool need_to_store_experiment_data() const { 01161 return need_to_store_experiment_data_; 01162 } 01163 void set_need_to_store_experiment_data(bool x) { 01164 need_to_store_experiment_data_ = x; 01165 } 01166 01167 int64 blocking_fetch_timeout_ms() const { 01168 return blocking_fetch_timeout_ms_.value(); 01169 } 01170 void set_blocking_fetch_timeout_ms(int64 x) { 01171 set_option(x, &blocking_fetch_timeout_ms_); 01172 } 01173 bool override_ie_document_mode() const { 01174 return override_ie_document_mode_.value(); 01175 } 01176 void set_override_ie_document_mode(bool x) { 01177 set_option(x, &override_ie_document_mode_); 01178 } 01179 01183 bool IsUrlCacheValid(StringPiece url, int64 time_ms) const; 01184 01189 void AddUrlCacheInvalidationEntry(StringPiece url_pattern, 01190 int64 timestamp_ms, 01191 bool is_strict); 01192 01195 bool IsUrlCacheInvalidationEntriesSorted() const; 01196 01199 void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock* lock) { 01200 cache_invalidation_timestamp_.set_mutex(lock); 01201 } 01202 01204 int64 cache_invalidation_timestamp() const { 01205 ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex()); 01206 return cache_invalidation_timestamp_.value(); 01207 } 01208 01215 void set_cache_invalidation_timestamp(int64 timestamp_ms) { 01216 cache_invalidation_timestamp_.mutex()->DCheckLocked(); 01217 DCHECK_LT(0, timestamp_ms); 01218 set_option(timestamp_ms, &cache_invalidation_timestamp_); 01219 } 01220 01227 bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms, 01228 const Hasher* hasher); 01229 01232 int64 idle_flush_time_ms() const { 01233 return idle_flush_time_ms_.value(); 01234 } 01235 void set_idle_flush_time_ms(int64 x) { 01236 set_option(x, &idle_flush_time_ms_); 01237 } 01238 01240 int64 flush_buffer_limit_bytes() const { 01241 return flush_buffer_limit_bytes_.value(); 01242 } 01243 01244 void set_flush_buffer_limit_bytes(int64 x) { 01245 set_option(x, &flush_buffer_limit_bytes_); 01246 } 01247 01250 int max_url_segment_size() const { return max_url_segment_size_.value(); } 01251 void set_max_url_segment_size(int x) { 01252 set_option(x, &max_url_segment_size_); 01253 } 01254 01255 int image_max_rewrites_at_once() const { 01256 return image_max_rewrites_at_once_.value(); 01257 } 01258 void set_image_max_rewrites_at_once(int x) { 01259 set_option(x, &image_max_rewrites_at_once_); 01260 } 01261 01263 int max_url_size() const { return max_url_size_.value(); } 01264 void set_max_url_size(int x) { 01265 set_option(x, &max_url_size_); 01266 } 01267 01268 int rewrite_deadline_ms() const { return rewrite_deadline_ms_.value(); } 01269 void set_rewrite_deadline_ms(int x) { 01270 set_option(x, &rewrite_deadline_ms_); 01271 } 01272 01273 bool test_instant_fetch_rewrite_deadline() const { 01274 return test_instant_fetch_rewrite_deadline_.value(); 01275 } 01276 void set_test_instant_fetch_rewrite_deadline(bool x) { 01277 set_option(x, &test_instant_fetch_rewrite_deadline_); 01278 } 01279 01280 int domain_shard_count() const { return domain_shard_count_.value(); } 01283 void set_domain_shard_count(int64 x) { 01284 int value = x; 01285 set_option(value, &domain_shard_count_); 01286 } 01287 01288 void set_enabled(EnabledEnum x) { 01289 set_option(x, &enabled_); 01290 } 01291 bool enabled() const { 01292 return enabled_.value() == kEnabledOn; 01293 } 01294 bool unplugged() const { 01295 return enabled_.value() == kEnabledUnplugged; 01296 } 01297 01298 void set_add_options_to_urls(bool x) { 01299 set_option(x, &add_options_to_urls_); 01300 } 01301 01302 bool add_options_to_urls() const { 01303 return add_options_to_urls_.value(); 01304 } 01305 01306 void set_in_place_rewriting_enabled(bool x) { 01307 set_option(x, &in_place_rewriting_enabled_); 01308 } 01309 01310 void set_oblivious_pagespeed_urls(bool x) { 01311 set_option(x, &oblivious_pagespeed_urls_); 01312 } 01313 01314 bool oblivious_pagespeed_urls() const { 01315 return oblivious_pagespeed_urls_.value(); 01316 } 01317 01318 bool in_place_rewriting_enabled() const { 01319 return in_place_rewriting_enabled_.value(); 01320 } 01321 01322 void set_in_place_wait_for_optimized(bool x) { 01323 set_option(x, &in_place_wait_for_optimized_); 01324 } 01325 01326 bool in_place_wait_for_optimized() const { 01327 return in_place_wait_for_optimized_.value(); 01328 } 01329 01330 void set_in_place_rewrite_deadline_ms(int x) { 01331 set_option(x, &in_place_rewrite_deadline_ms_); 01332 } 01333 01334 int in_place_rewrite_deadline_ms() const { 01335 return in_place_rewrite_deadline_ms_.value(); 01336 } 01337 01338 void set_in_place_preemptive_rewrite_css(bool x) { 01339 set_option(x, &in_place_preemptive_rewrite_css_); 01340 } 01341 bool in_place_preemptive_rewrite_css() const { 01342 return in_place_preemptive_rewrite_css_.value(); 01343 } 01344 01345 void set_in_place_preemptive_rewrite_css_images(bool x) { 01346 set_option(x, &in_place_preemptive_rewrite_css_images_); 01347 } 01348 bool in_place_preemptive_rewrite_css_images() const { 01349 return in_place_preemptive_rewrite_css_images_.value(); 01350 } 01351 01352 void set_in_place_preemptive_rewrite_images(bool x) { 01353 set_option(x, &in_place_preemptive_rewrite_images_); 01354 } 01355 bool in_place_preemptive_rewrite_images() const { 01356 return in_place_preemptive_rewrite_images_.value(); 01357 } 01358 01359 void set_in_place_preemptive_rewrite_javascript(bool x) { 01360 set_option(x, &in_place_preemptive_rewrite_javascript_); 01361 } 01362 bool in_place_preemptive_rewrite_javascript() const { 01363 return in_place_preemptive_rewrite_javascript_.value(); 01364 } 01365 01366 void set_combine_across_paths(bool x) { 01367 set_option(x, &combine_across_paths_); 01368 } 01369 bool combine_across_paths() const { return combine_across_paths_.value(); } 01370 01371 void set_log_rewrite_timing(bool x) { 01372 set_option(x, &log_rewrite_timing_); 01373 } 01374 bool log_rewrite_timing() const { return log_rewrite_timing_.value(); } 01375 01376 void set_lowercase_html_names(bool x) { 01377 set_option(x, &lowercase_html_names_); 01378 } 01379 bool lowercase_html_names() const { return lowercase_html_names_.value(); } 01380 01381 void set_always_rewrite_css(bool x) { 01382 set_option(x, &always_rewrite_css_); 01383 } 01384 bool always_rewrite_css() const { return always_rewrite_css_.value(); } 01385 01386 void set_respect_vary(bool x) { 01387 set_option(x, &respect_vary_); 01388 } 01389 bool respect_vary() const { return respect_vary_.value(); } 01390 01391 void set_respect_x_forwarded_proto(bool x) { 01392 set_option(x, &respect_x_forwarded_proto_); 01393 } 01394 bool respect_x_forwarded_proto() const { 01395 return respect_x_forwarded_proto_.value(); 01396 } 01397 01398 void set_flush_html(bool x) { set_option(x, &flush_html_); } 01399 bool flush_html() const { return flush_html_.value(); } 01400 01401 void set_serve_stale_if_fetch_error(bool x) { 01402 set_option(x, &serve_stale_if_fetch_error_); 01403 } 01404 bool serve_stale_if_fetch_error() const { 01405 return serve_stale_if_fetch_error_.value(); 01406 } 01407 01408 void set_enable_blink_critical_line(bool x) { 01409 set_option(x, &enable_blink_critical_line_); 01410 } 01411 bool enable_blink_critical_line() const { 01412 return enable_blink_critical_line_.value(); 01413 } 01414 01415 void set_default_cache_html(bool x) { set_option(x, &default_cache_html_); } 01416 bool default_cache_html() const { return default_cache_html_.value(); } 01417 01418 void set_modify_caching_headers(bool x) { 01419 set_option(x, &modify_caching_headers_); 01420 } 01421 bool modify_caching_headers() const { 01422 return modify_caching_headers_.value(); 01423 } 01424 01425 void set_inline_only_critical_images(bool x) { 01426 set_option(x, &inline_only_critical_images_); 01427 } 01428 bool inline_only_critical_images() const { 01429 return inline_only_critical_images_.value(); 01430 } 01431 01432 void set_critical_images_beacon_enabled(bool x) { 01433 set_option(x, &critical_images_beacon_enabled_); 01434 } 01435 bool critical_images_beacon_enabled() const { 01436 return critical_images_beacon_enabled_.value(); 01437 } 01438 01439 void set_lazyload_images_after_onload(bool x) { 01440 set_option(x, &lazyload_images_after_onload_); 01441 } 01442 bool lazyload_images_after_onload() const { 01443 return lazyload_images_after_onload_.value(); 01444 } 01445 01446 void set_lazyload_images_blank_url(const StringPiece& p) { 01447 set_option(GoogleString(p.data(), p.size()), &lazyload_images_blank_url_); 01448 } 01449 const GoogleString& lazyload_images_blank_url() const { 01450 return lazyload_images_blank_url_.value(); 01451 } 01452 01453 void set_max_inlined_preview_images_index(int x) { 01454 set_option(x, &max_inlined_preview_images_index_); 01455 } 01456 int max_inlined_preview_images_index() const { 01457 return max_inlined_preview_images_index_.value(); 01458 } 01459 01460 void set_min_image_size_low_resolution_bytes(int64 x) { 01461 set_option(x, &min_image_size_low_resolution_bytes_); 01462 } 01463 int64 min_image_size_low_resolution_bytes() const { 01464 return min_image_size_low_resolution_bytes_.value(); 01465 } 01466 01467 void set_max_image_size_low_resolution_bytes(int64 x) { 01468 set_option(x, &max_image_size_low_resolution_bytes_); 01469 } 01470 int64 max_image_size_low_resolution_bytes() const { 01471 return max_image_size_low_resolution_bytes_.value(); 01472 } 01473 01474 void set_furious_cookie_duration_ms(int64 x) { 01475 set_option(x, &furious_cookie_duration_ms_); 01476 } 01477 int64 furious_cookie_duration_ms() const { 01478 return furious_cookie_duration_ms_.value(); 01479 } 01480 01481 void set_finder_properties_cache_expiration_time_ms(int64 x) { 01482 set_option(x, &finder_properties_cache_expiration_time_ms_); 01483 } 01484 int64 finder_properties_cache_expiration_time_ms() const { 01485 return finder_properties_cache_expiration_time_ms_.value(); 01486 } 01487 01488 void set_finder_properties_cache_refresh_time_ms(int64 x) { 01489 set_option(x, &finder_properties_cache_refresh_time_ms_); 01490 } 01491 int64 finder_properties_cache_refresh_time_ms() const { 01492 return finder_properties_cache_refresh_time_ms_.value(); 01493 } 01494 bool css_preserve_urls() const { 01495 return css_preserve_urls_.value(); 01496 } 01497 void set_css_preserve_urls(bool x) { 01498 set_option(x, &css_preserve_urls_); 01499 } 01500 01501 bool image_preserve_urls() const { 01502 return image_preserve_urls_.value(); 01503 } 01504 void set_image_preserve_urls(bool x) { 01505 set_option(x, &image_preserve_urls_); 01506 } 01507 01508 bool js_preserve_urls() const { 01509 return js_preserve_urls_.value(); 01510 } 01511 void set_js_preserve_urls(bool x) { 01512 set_option(x, &js_preserve_urls_); 01513 } 01514 01515 bool image_retain_color_profile() const { 01516 return image_retain_color_profile_.value(); 01517 } 01518 void set_image_retain_color_profile(bool x) { 01519 set_option(x, &image_retain_color_profile_); 01520 } 01521 01522 bool image_retain_color_sampling() const { 01523 return image_retain_color_sampling_.value(); 01524 } 01525 void set_image_retain_color_sampling(bool x) { 01526 set_option(x, &image_retain_color_sampling_); 01527 } 01528 01529 bool image_retain_exif_data() const { 01530 return image_retain_exif_data_.value(); 01531 } 01532 void set_image_retain_exif_data(bool x) { 01533 set_option(x, &image_retain_exif_data_); 01534 } 01535 01536 void set_metadata_cache_staleness_threshold_ms(int64 x) { 01537 set_option(x, &metadata_cache_staleness_threshold_ms_); 01538 } 01539 int64 metadata_cache_staleness_threshold_ms() const { 01540 return metadata_cache_staleness_threshold_ms_.value(); 01541 } 01542 01543 void set_metadata_input_errors_cache_ttl_ms(int64 x) { 01544 set_option(x, &metadata_input_errors_cache_ttl_ms_); 01545 } 01546 int64 metadata_input_errors_cache_ttl_ms() const { 01547 return metadata_input_errors_cache_ttl_ms_.value(); 01548 } 01549 01550 const BeaconUrl& beacon_url() const { return beacon_url_.value(); } 01551 void set_beacon_url(const GoogleString& beacon_url) { 01552 beacon_url_.SetFromString(beacon_url); 01553 } 01554 01556 virtual bool trim_urls_in_css() const { return true; } 01557 01558 int64 image_jpeg_recompress_quality() const { 01559 return image_jpeg_recompress_quality_.value(); 01560 } 01561 void set_image_jpeg_recompress_quality(int64 x) { 01562 set_option(x, &image_jpeg_recompress_quality_); 01563 } 01564 01565 int64 image_recompress_quality() const { 01566 return image_recompress_quality_.value(); 01567 } 01568 void set_image_recompress_quality(int64 x) { 01569 set_option(x, &image_recompress_quality_); 01570 } 01571 01572 int image_limit_optimized_percent() const { 01573 return image_limit_optimized_percent_.value(); 01574 } 01575 void set_image_limit_optimized_percent(int x) { 01576 set_option(x, &image_limit_optimized_percent_); 01577 } 01578 int image_limit_resize_area_percent() const { 01579 return image_limit_resize_area_percent_.value(); 01580 } 01581 void set_image_limit_resize_area_percent(int x) { 01582 set_option(x, &image_limit_resize_area_percent_); 01583 } 01584 01585 int image_jpeg_num_progressive_scans() const { 01586 return image_jpeg_num_progressive_scans_.value(); 01587 } 01588 void set_image_jpeg_num_progressive_scans(int x) { 01589 set_option(x, &image_jpeg_num_progressive_scans_); 01590 } 01591 01592 int64 image_webp_recompress_quality() const { 01593 return image_webp_recompress_quality_.value(); 01594 } 01595 void set_image_webp_recompress_quality(int64 x) { 01596 set_option(x, &image_webp_recompress_quality_); 01597 } 01598 01599 int64 image_webp_timeout_ms() const { 01600 return image_webp_timeout_ms_.value(); 01601 } 01602 void set_image_webp_timeout_ms(int64 x) { 01603 set_option(x, &image_webp_timeout_ms_); 01604 } 01605 01606 bool domain_rewrite_hyperlinks() const { 01607 return domain_rewrite_hyperlinks_.value(); 01608 } 01609 void set_domain_rewrite_hyperlinks(bool x) { 01610 set_option(x, &domain_rewrite_hyperlinks_); 01611 } 01612 01613 bool client_domain_rewrite() const { 01614 return client_domain_rewrite_.value(); 01615 } 01616 void set_client_domain_rewrite(bool x) { 01617 set_option(x, &client_domain_rewrite_); 01618 } 01619 01620 void set_flush_more_resources_early_if_time_permits(bool x) { 01621 set_option(x, &flush_more_resources_early_if_time_permits_); 01622 } 01623 bool flush_more_resources_early_if_time_permits() const { 01624 return flush_more_resources_early_if_time_permits_.value(); 01625 } 01626 01627 void set_flush_more_resources_in_ie_and_firefox(bool x) { 01628 set_option(x, &flush_more_resources_in_ie_and_firefox_); 01629 } 01630 bool flush_more_resources_in_ie_and_firefox() const { 01631 return flush_more_resources_in_ie_and_firefox_.value(); 01632 } 01633 01634 void set_enable_defer_js_experimental(bool x) { 01635 set_option(x, &enable_defer_js_experimental_); 01636 } 01637 bool enable_defer_js_experimental() const { 01638 return enable_defer_js_experimental_.value(); 01639 } 01640 01641 void set_enable_inline_preview_images_experimental(bool x) { 01642 set_option(x, &enable_inline_preview_images_experimental_); 01643 } 01644 bool enable_inline_preview_images_experimental() const { 01645 return enable_inline_preview_images_experimental_.value(); 01646 } 01647 01648 void set_enable_blink_debug_dashboard(bool x) { 01649 set_option(x, &enable_blink_debug_dashboard_); 01650 } 01651 bool enable_blink_debug_dashboard() const { 01652 return enable_blink_debug_dashboard_.value(); 01653 } 01654 01655 void set_enable_blink_html_change_detection(bool x) { 01656 set_option(x, &enable_blink_html_change_detection_); 01657 } 01658 bool enable_blink_html_change_detection() const { 01659 return enable_blink_html_change_detection_.value(); 01660 } 01661 01662 void set_enable_blink_html_change_detection_logging(bool x) { 01663 set_option(x, &enable_blink_html_change_detection_logging_); 01664 } 01665 bool enable_blink_html_change_detection_logging() const { 01666 return enable_blink_html_change_detection_logging_.value(); 01667 } 01668 01669 void set_use_smart_diff_in_blink(bool x) { 01670 set_option(x, &use_smart_diff_in_blink_); 01671 } 01672 bool use_smart_diff_in_blink() const { 01673 return use_smart_diff_in_blink_.value(); 01674 } 01675 01676 void set_enable_lazyload_in_blink(bool x) { 01677 set_option(x, &enable_lazyload_in_blink_); 01678 } 01679 bool enable_lazyload_in_blink() const { 01680 return enable_lazyload_in_blink_.value(); 01681 } 01682 01683 void set_enable_prioritizing_scripts(bool x) { 01684 set_option(x, &enable_prioritizing_scripts_); 01685 } 01686 bool enable_prioritizing_scripts() const { 01687 return enable_prioritizing_scripts_.value(); 01688 } 01689 01690 void set_blink_html_change_detection_time_ms(int64 x) { 01691 set_option(x, &blink_html_change_detection_time_ms_); 01692 } 01693 int64 blink_html_change_detection_time_ms() const { 01694 return blink_html_change_detection_time_ms_.value(); 01695 } 01696 01697 void set_override_blink_cache_time_ms(int64 x) { 01698 set_option(x, &override_blink_cache_time_ms_); 01699 } 01700 int64 override_blink_cache_time_ms() const { 01701 return override_blink_cache_time_ms_.value(); 01702 } 01703 01704 void set_blink_non_cacheables_for_all_families(const StringPiece& p) { 01705 set_option(GoogleString(p.data(), p.size()), 01706 &blink_non_cacheables_for_all_families_); 01707 } 01708 const GoogleString& blink_non_cacheables_for_all_families() const { 01709 return blink_non_cacheables_for_all_families_.value(); 01710 } 01711 01712 const GoogleString& blocking_rewrite_key() const { 01713 return blocking_rewrite_key_.value(); 01714 } 01715 void set_blocking_rewrite_key(const StringPiece& p) { 01716 set_option(p.as_string(), &blocking_rewrite_key_); 01717 } 01718 01721 bool IsInBlinkCacheableFamily(const GoogleUrl& gurl) const; 01722 01727 int64 GetBlinkCacheTimeFor(const GoogleUrl& gurl) const; 01728 01733 GoogleString GetBlinkNonCacheableElementsFor(const GoogleUrl& gurl) const; 01734 01736 void AddBlinkCacheableFamily(const StringPiece url_pattern, 01737 int64 cache_time_ms, 01738 const StringPiece non_cacheable_elements); 01739 01740 void set_running_furious_experiment(bool x) { 01741 set_option(x, &running_furious_); 01742 } 01743 bool running_furious() const { 01744 return running_furious_.value(); 01745 } 01746 01748 void set_furious_ga_slot(int x) { 01749 set_option(x, &furious_ga_slot_); 01750 } 01751 01752 int furious_ga_slot() const { return furious_ga_slot_.value(); } 01753 01754 void set_report_unload_time(bool x) { 01755 set_option(x, &report_unload_time_); 01756 } 01757 bool report_unload_time() const { 01758 return report_unload_time_.value(); 01759 } 01760 01761 void set_implicit_cache_ttl_ms(int64 x) { 01762 set_option(x, &implicit_cache_ttl_ms_); 01763 } 01764 int64 implicit_cache_ttl_ms() const { 01765 return implicit_cache_ttl_ms_.value(); 01766 } 01767 01768 void set_x_header_value(const StringPiece& p) { 01769 set_option(p.as_string(), &x_header_value_); 01770 } 01771 const GoogleString& x_header_value() const { 01772 return x_header_value_.value(); 01773 } 01774 01775 void set_avoid_renaming_introspective_javascript(bool x) { 01776 set_option(x, &avoid_renaming_introspective_javascript_); 01777 } 01778 bool avoid_renaming_introspective_javascript() const { 01779 return avoid_renaming_introspective_javascript_.value(); 01780 } 01781 01782 void set_use_fixed_user_agent_for_blink_cache_misses(bool x) { 01783 set_option(x, &use_fixed_user_agent_for_blink_cache_misses_); 01784 } 01785 bool use_fixed_user_agent_for_blink_cache_misses() const { 01786 return use_fixed_user_agent_for_blink_cache_misses_.value(); 01787 } 01788 01789 void set_blink_desktop_user_agent(const StringPiece& p) { 01790 set_option(GoogleString(p.data(), p.size()), &blink_desktop_user_agent_); 01791 } 01792 const GoogleString& blink_desktop_user_agent() const { 01793 return blink_desktop_user_agent_.value(); 01794 } 01795 01796 void set_passthrough_blink_for_last_invalid_response_code(bool x) { 01797 set_option(x, &passthrough_blink_for_last_invalid_response_code_); 01798 } 01799 bool passthrough_blink_for_last_invalid_response_code() const { 01800 return passthrough_blink_for_last_invalid_response_code_.value(); 01801 } 01802 01803 int64 blink_max_html_size_rewritable() const { 01804 return blink_max_html_size_rewritable_.value(); 01805 } 01806 void set_blink_max_html_size_rewritable(int64 x) { 01807 set_option(x, &blink_max_html_size_rewritable_); 01808 } 01809 01810 void set_apply_blink_if_no_families(bool x) { 01811 set_option(x, &apply_blink_if_no_families_); 01812 } 01813 bool apply_blink_if_no_families() const { 01814 return apply_blink_if_no_families_.value(); 01815 } 01816 01817 void set_critical_line_config(const StringPiece& p) { 01818 set_option(GoogleString(p.data(), p.size()), &critical_line_config_); 01819 } 01820 const GoogleString& critical_line_config() const { 01821 return critical_line_config_.value(); 01822 } 01823 01824 void set_forbid_all_disabled_filters(bool x) { 01825 set_option(x, &forbid_all_disabled_filters_); 01826 } 01827 bool forbid_all_disabled_filters() const { 01828 return forbid_all_disabled_filters_.value(); 01829 } 01830 01831 bool reject_blacklisted() const { return reject_blacklisted_.value(); } 01832 void set_reject_blacklisted(bool x) { 01833 set_option(x, &reject_blacklisted_); 01834 } 01835 01836 HttpStatus::Code reject_blacklisted_status_code() const { 01837 return static_cast<HttpStatus::Code>( 01838 reject_blacklisted_status_code_.value()); 01839 } 01840 void set_reject_blacklisted_status_code(HttpStatus::Code x) { 01841 set_option(static_cast<int>(x), &reject_blacklisted_status_code_); 01842 } 01843 01844 bool support_noscript_enabled() const { 01845 return support_noscript_enabled_.value(); 01846 } 01847 void set_support_noscript_enabled(bool x) { 01848 set_option(x, &support_noscript_enabled_); 01849 } 01850 01851 void set_max_combined_js_bytes(int64 x) { 01852 set_option(x, &max_combined_js_bytes_); 01853 } 01854 int64 max_combined_js_bytes() const { 01855 return max_combined_js_bytes_.value(); 01856 } 01857 01858 void set_pre_connect_url(const StringPiece& p) { 01859 set_option(GoogleString(p.data(), p.size()), &pre_connect_url_); 01860 } 01861 const GoogleString& pre_connect_url() const { 01862 return pre_connect_url_.value(); 01863 } 01864 void set_property_cache_http_status_stability_threshold(int x) { 01865 set_option(x, &property_cache_http_status_stability_threshold_); 01866 } 01867 int property_cache_http_status_stability_threshold() const { 01868 return property_cache_http_status_stability_threshold_.value(); 01869 } 01870 01871 void set_max_rewrite_info_log_size(int x) { 01872 set_option(x, &max_rewrite_info_log_size_); 01873 } 01874 int max_rewrite_info_log_size() const { 01875 return max_rewrite_info_log_size_.value(); 01876 } 01877 01878 void set_enable_aggressive_rewriters_for_mobile(bool x) { 01879 set_option(x, &enable_aggressive_rewriters_for_mobile_); 01880 } 01881 bool enable_aggressive_rewriters_for_mobile() const { 01882 return enable_aggressive_rewriters_for_mobile_.value(); 01883 } 01884 01900 virtual void Merge(const RewriteOptions& src); 01901 01904 void Allow(const StringPiece& wildcard_pattern) { 01905 Modify(); 01906 allow_resources_.Allow(wildcard_pattern); 01907 } 01908 01911 void Disallow(const StringPiece& wildcard_pattern) { 01912 Modify(); 01913 allow_resources_.Disallow(wildcard_pattern); 01914 } 01915 01919 virtual void DisallowTroublesomeResources(); 01920 01921 DomainLawyer* domain_lawyer() { return &domain_lawyer_; } 01922 const DomainLawyer* domain_lawyer() const { return &domain_lawyer_; } 01923 01924 FileLoadPolicy* file_load_policy() { return &file_load_policy_; } 01925 const FileLoadPolicy* file_load_policy() const { return &file_load_policy_; } 01926 01929 bool IsAllowed(const StringPiece& url) const { 01930 return allow_resources_.Match(url, true); 01931 } 01932 01934 void RetainComment(const StringPiece& comment) { 01935 Modify(); 01936 retain_comments_.Allow(comment); 01937 } 01938 01942 bool IsRetainedComment(const StringPiece& comment) const { 01943 return retain_comments_.Match(comment, false); 01944 } 01945 01947 void DisableLazyloadForClassName(const StringPiece& class_name) { 01948 Modify(); 01949 lazyload_enabled_classes_.Disallow(class_name); 01950 } 01951 01953 bool IsLazyloadEnabledForClassName(const StringPiece& class_name) const { 01954 return lazyload_enabled_classes_.Match(class_name, true); 01955 } 01956 01957 void set_override_caching_ttl_ms(int64 x) { 01958 set_option(x, &override_caching_ttl_ms_); 01959 } 01960 int64 override_caching_ttl_ms() const { 01961 return override_caching_ttl_ms_.value(); 01962 } 01963 01966 void AddOverrideCacheTtl(const StringPiece& wildcard) { 01967 Modify(); 01968 override_caching_wildcard_.Allow(wildcard); 01969 } 01970 01972 bool IsCacheTtlOverridden(const StringPiece& url) const { 01973 return override_caching_wildcard_.Match(url, false); 01974 } 01975 01976 void AddRejectedUrlWildcard(const GoogleString& wildcard) { 01977 AddRejectedHeaderWildcard(kRejectedRequestUrlKeyName, wildcard); 01978 } 01979 01980 void AddRejectedHeaderWildcard(const StringPiece& header_name, 01981 const GoogleString& wildcard) { 01982 Modify(); 01983 std::pair<FastWildcardGroupMap::iterator, bool> insert_result = 01984 rejected_request_map_.insert(std::make_pair( 01985 header_name, static_cast<FastWildcardGroup*>(NULL))); 01986 01987 if (insert_result.second) { 01988 insert_result.first->second = new FastWildcardGroup; 01989 } 01990 insert_result.first->second->Allow(wildcard); 01991 } 01992 01993 bool IsRejectedUrl(const GoogleString& url) const { 01994 return IsRejectedRequest(kRejectedRequestUrlKeyName, url); 01995 } 01996 01997 bool IsRejectedRequest(const StringPiece& header_name, 01998 const StringPiece& value) const { 01999 FastWildcardGroupMap::const_iterator it = rejected_request_map_.find( 02000 header_name); 02001 if (it != rejected_request_map_.end()) { 02002 return it->second->Match(value, false); 02003 } 02004 return false; 02005 } 02009 virtual RewriteOptions* Clone() const; 02010 02016 void ComputeSignature(const Hasher* hasher); 02017 02024 void ClearSignatureWithCaution() { 02025 frozen_ = false; 02026 signature_.clear(); 02027 } 02028 02031 void ClearSignatureForTesting() { 02032 ClearSignatureWithCaution(); 02033 } 02034 02036 const GoogleString& signature() const { 02044 ThreadSystem::ScopedReader lock(cache_invalidation_timestamp_.mutex()); 02045 DCHECK(frozen_); 02046 return signature_; 02047 } 02048 02049 virtual GoogleString OptionsToString() const; 02050 02053 virtual GoogleString ToExperimentString() const; 02054 02058 virtual GoogleString ToExperimentDebugString() const; 02059 02061 virtual bool NeedLowResImages() const { 02062 return Enabled(kDelayImages); 02063 } 02064 02067 static Filter LookupFilterById(const StringPiece& filter_id); 02068 02072 static OptionEnum LookupOptionEnumById(const StringPiece& option_id); 02073 02075 static const char* LookupOptionEnum(OptionEnum option_enum) { 02076 return (option_enum < kEndOfOptions) ? 02077 option_enum_to_name_array_[option_enum] : NULL; 02078 } 02079 02080 static OptionEnum LookupOption(const StringPiece& option_name); 02081 02084 const OptionBaseVector& all_options() const { 02085 return all_options_; 02086 } 02087 02088 protected: 02092 template<class ValueType> 02093 class Property : public PropertyBase { 02094 public: 02099 Property(ValueType default_value, 02100 const char* id, 02101 OptionEnum option_enum) 02102 : PropertyBase(id, option_enum), 02103 default_value_(default_value) { 02104 } 02105 02106 void set_default(ValueType value) { default_value_ = value; } 02107 const ValueType& default_value() const { return default_value_; } 02108 02109 private: 02110 ValueType default_value_; 02111 02112 DISALLOW_COPY_AND_ASSIGN(Property); 02113 }; 02114 02129 template<class RewriteOptionsSubclass, class OptionClass> 02130 class PropertyLeaf : public Property<typename OptionClass::ValueType> { 02131 public: 02135 typedef OptionClass RewriteOptionsSubclass::*OptionOffset; 02136 typedef typename OptionClass::ValueType ValueType; 02137 02138 PropertyLeaf(ValueType default_value, 02139 OptionOffset offset, 02140 const char* id, 02141 OptionEnum option_enum) 02142 : Property<ValueType>(default_value, id, option_enum), 02143 offset_(offset) { 02144 } 02145 02146 virtual void InitializeOption(RewriteOptions* options) const { 02147 RewriteOptionsSubclass* options_subclass = 02148 static_cast<RewriteOptionsSubclass*>(options); 02149 OptionClass& option = options_subclass->*offset_; 02150 option.set_property(this); 02151 DCHECK_NE(-1, this->index()) << "Call Property::set_index first."; 02152 options->set_option_at(this->index(), &option); 02153 } 02154 02155 private: 02156 OptionOffset offset_; 02157 02158 DISALLOW_COPY_AND_ASSIGN(PropertyLeaf); 02159 }; 02160 02170 template<class T> class OptionTemplateBase : public OptionBase { 02171 public: 02172 typedef T ValueType; 02173 02174 OptionTemplateBase() : was_set_(false), property_(NULL) {} 02175 02176 virtual bool was_set() const { return was_set_; } 02177 02178 void set(const T& val) { 02179 was_set_ = true; 02180 value_ = val; 02181 } 02182 02183 void set_default(const T& val) { 02184 if (!was_set_) { 02185 value_ = val; 02186 } 02187 } 02188 02189 const T& value() const { return value_; } 02190 02196 virtual void Merge(const OptionBase* src) { 02197 DCHECK(option_enum() == src->option_enum()); 02198 MergeHelper(static_cast<const OptionTemplateBase*>(src)); 02199 } 02200 02201 void MergeHelper(const OptionTemplateBase* src) { 02204 if (src->was_set_ || !was_set_) { 02205 value_ = src->value_; 02206 was_set_ = src->was_set_; 02207 } 02208 } 02209 02211 void set_property(const Property<T>* property) { 02212 property_ = property; 02213 02218 value_ = property->default_value(); 02219 } 02220 virtual const Property<T>* property() const { return property_; } 02221 02230 void set_global_default(const T& val) { 02231 Property<T>* property = const_cast<Property<T>*>(property_); 02232 property->set_default(val); 02233 } 02234 02243 void DoNotUseForSignatureComputation() { 02244 Property<T>* property = const_cast<Property<T>*>(property_); 02245 property->set_do_not_use_for_signature_computation(true); 02246 } 02247 02248 private: 02249 bool was_set_; 02250 T value_; 02251 const Property<T>* property_; 02252 02253 DISALLOW_COPY_AND_ASSIGN(OptionTemplateBase); 02254 }; 02255 02260 template<class T> class Option : public OptionTemplateBase<T> { 02261 public: 02262 Option() {} 02263 02265 virtual bool SetFromString(const GoogleString& value_string) { 02266 T value; 02267 bool success = RewriteOptions::ParseFromString(value_string, &value); 02268 if (success) { 02269 this->set(value); 02270 } 02271 return success; 02272 } 02273 02274 virtual GoogleString Signature(const Hasher* hasher) const { 02275 return RewriteOptions::OptionSignature(this->value(), hasher); 02276 } 02277 02278 virtual GoogleString ToString() const { 02279 return RewriteOptions::ToString(this->value()); 02280 } 02281 02282 private: 02283 DISALLOW_COPY_AND_ASSIGN(Option); 02284 }; 02285 02298 class MutexedOptionInt64MergeWithMax : public Option<int64> { 02299 public: 02300 MutexedOptionInt64MergeWithMax(); 02301 virtual ~MutexedOptionInt64MergeWithMax(); 02302 02307 virtual void Merge(const OptionBase* src_base); 02308 02319 void checked_set(const int64& value) { 02320 mutex_->DCheckLocked(); 02321 Option<int64>::set(value); 02322 } 02323 02337 ThreadSystem::RWLock* mutex() const { return mutex_.get(); } 02338 02344 void set_mutex(ThreadSystem::RWLock* lock) { mutex_.reset(lock); } 02345 02346 private: 02347 scoped_ptr<ThreadSystem::RWLock> mutex_; 02348 }; 02349 02350 protected: 02352 template<class RewriteOptionsSubclass, class OptionClass> 02353 static void AddProperty(typename OptionClass::ValueType default_value, 02354 OptionClass RewriteOptionsSubclass::*offset, 02355 const char* id, 02356 OptionEnum option_enum, 02357 Properties* properties) { 02358 properties->push_back(new PropertyLeaf<RewriteOptionsSubclass, OptionClass>( 02359 default_value, offset, id, option_enum)); 02360 } 02361 02362 02376 static void MergeSubclassProperties(Properties* properties); 02377 02379 void ForbidFiltersForPreserveUrl(); 02380 02386 void set_option_at(int index, OptionBase* option) { 02387 all_options_[index] = option; 02388 } 02389 02393 template<class T> 02394 void set_option(const T& new_value, OptionTemplateBase<T>* option) { 02395 option->set(new_value); 02396 Modify(); 02397 } 02398 02400 void Modify(); 02401 02409 void set_default_x_header_value(const StringPiece& x_header_value) { 02410 x_header_value_.set_global_default(x_header_value.as_string()); 02411 } 02412 02415 bool SetupFuriousRewriters(); 02416 02418 virtual void SetRequiredFuriousFilters(); 02419 02423 bool InsertFuriousSpecInVector(FuriousSpec* spec); 02424 02426 Option<BeaconUrl> beacon_url_; 02427 02429 Option<GoogleString> x_header_value_; 02430 02431 private: 02432 struct OptionIdCompare; 02433 02434 static Properties* properties_; 02435 static Properties* all_properties_; 02436 02437 FRIEND_TEST(RewriteOptionsTest, FuriousMergeTest); 02438 typedef std::vector<Filter> FilterVector; 02439 02446 struct PrioritizeVisibleContentFamily { 02447 PrioritizeVisibleContentFamily(StringPiece url_pattern_string, 02448 int64 cache_time_ms_in, 02449 StringPiece non_cacheable_elements_in) 02450 : url_pattern(url_pattern_string), 02451 cache_time_ms(cache_time_ms_in), 02452 non_cacheable_elements(non_cacheable_elements_in.data(), 02453 non_cacheable_elements_in.size()) {} 02454 02455 PrioritizeVisibleContentFamily* Clone() const { 02456 return new PrioritizeVisibleContentFamily( 02457 url_pattern.spec(), cache_time_ms, non_cacheable_elements); 02458 } 02459 02460 GoogleString ComputeSignature() const { 02461 return StrCat(url_pattern.spec(), ";", Integer64ToString(cache_time_ms), 02462 ";", non_cacheable_elements); 02463 } 02464 02465 GoogleString ToString() const { 02466 return StrCat("URL pattern: ", url_pattern.spec(), ", Cache time (ms): ", 02467 Integer64ToString(cache_time_ms), ", Non-cacheable: ", 02468 non_cacheable_elements); 02469 } 02470 02471 Wildcard url_pattern; 02472 int64 cache_time_ms; 02473 GoogleString non_cacheable_elements; 02474 }; 02475 02478 struct UrlCacheInvalidationEntry { 02479 UrlCacheInvalidationEntry(StringPiece url_pattern_in, 02480 int64 timestamp_ms_in, 02481 bool is_strict_in) 02482 : url_pattern(url_pattern_in), 02483 timestamp_ms(timestamp_ms_in), 02484 is_strict(is_strict_in) {} 02485 02486 UrlCacheInvalidationEntry* Clone() const { 02487 return new UrlCacheInvalidationEntry( 02488 url_pattern.spec(), timestamp_ms, is_strict); 02489 } 02490 02491 GoogleString ComputeSignature() const { 02492 if (is_strict) { 02493 return ""; 02494 } 02495 return StrCat(url_pattern.spec(), "@", Integer64ToString(timestamp_ms)); 02496 } 02497 02498 GoogleString ToString() const { 02499 return StrCat( 02500 url_pattern.spec(), ", ", (is_strict ? "STRICT" : "REFERENCE"), " @ ", 02501 Integer64ToString(timestamp_ms)); 02502 } 02503 02504 Wildcard url_pattern; 02505 int64 timestamp_ms; 02506 bool is_strict; 02507 }; 02508 02509 typedef std::vector<UrlCacheInvalidationEntry*> 02510 UrlCacheInvalidationEntryVector; 02511 02527 template<class OptionClass, class RewriteOptionsSubclass> 02528 static void add_option(typename OptionClass::ValueType default_value, 02529 OptionClass RewriteOptionsSubclass::*offset, 02530 const char* id) { 02531 AddProperty(default_value, offset, id, kEndOfOptions, properties_); 02532 } 02533 02536 template<class RewriteOptionsSubclass, class OptionClass> 02537 static void add_option(typename OptionClass::ValueType default_value, 02538 OptionClass RewriteOptionsSubclass::*offset, 02539 const char* id, 02540 OptionEnum option_enum) { 02541 AddProperty(default_value, offset, id, option_enum, properties_); 02542 } 02543 02544 static void AddProperties(); 02545 bool AddCommaSeparatedListToFilterSetState( 02546 const StringPiece& filters, FilterSet* set, MessageHandler* handler); 02547 static bool AddCommaSeparatedListToFilterSet( 02548 const StringPiece& filters, FilterSet* set, MessageHandler* handler); 02549 static Filter LookupFilter(const StringPiece& filter_name); 02552 void ResolveConflicts(); 02555 static void InitOptionEnumToNameArray(); 02557 static void InitFilterIdToEnumArray(); 02558 static void InitOptionIdToEnumArray(); 02561 const PrioritizeVisibleContentFamily* FindPrioritizeVisibleContentFamily( 02562 const StringPiece str) const; 02563 02567 OptionSettingResult FormatSetOptionMessage( 02568 OptionSettingResult result, OptionEnum option_enum, StringPiece name, 02569 StringPiece value, GoogleString* msg); 02570 02573 static GoogleString OptionSignature(bool x, const Hasher* hasher) { 02574 return x ? "T" : "F"; 02575 } 02576 static GoogleString OptionSignature(int x, const Hasher* hasher) { 02577 return IntegerToString(x); 02578 } 02579 static GoogleString OptionSignature(int64 x, const Hasher* hasher) { 02580 return Integer64ToString(x); 02581 } 02582 static GoogleString OptionSignature(const GoogleString& x, 02583 const Hasher* hasher); 02584 static GoogleString OptionSignature(RewriteLevel x, 02585 const Hasher* hasher); 02586 static GoogleString OptionSignature(const BeaconUrl& beacon_url, 02587 const Hasher* hasher); 02588 02591 static GoogleString ToString(bool x) { 02592 return x ? "True" : "False"; 02593 } 02594 static GoogleString ToString(int x) { 02595 return IntegerToString(x); 02596 } 02597 static GoogleString ToString(int64 x) { 02598 return Integer64ToString(x); 02599 } 02600 static GoogleString ToString(const GoogleString& x) { 02601 return x; 02602 } 02603 static GoogleString ToString(RewriteLevel x); 02604 static GoogleString ToString(const BeaconUrl& beacon_url); 02605 02608 static bool PropertyLessThanByEnum(PropertyBase* p1, PropertyBase* p2) { 02609 return p1->option_enum() < p2->option_enum(); 02610 } 02611 02613 static bool OptionEnumLessThanArg(OptionBase* option, OptionEnum arg) { 02614 return option->option_enum() < arg; 02615 } 02616 02618 static bool CompareUrlCacheInvalidationEntry(UrlCacheInvalidationEntry* e1, 02619 UrlCacheInvalidationEntry* e2) { 02620 return e1->timestamp_ms < e2->timestamp_ms; 02621 } 02622 02624 static bool FilterEnumToIdAndNameEntryLessThanById( 02625 const FilterEnumToIdAndNameEntry* e1, 02626 const FilterEnumToIdAndNameEntry* e2) { 02627 return strcmp(e1->filter_id, e2->filter_id) < 0; 02628 } 02629 02630 bool modified_; 02631 bool frozen_; 02632 FilterSet enabled_filters_; 02633 FilterSet disabled_filters_; 02634 FilterSet forbidden_filters_; 02635 02641 Option<RewriteLevel> level_; 02642 02645 UrlCacheInvalidationEntryVector url_cache_invalidation_entries_; 02646 02647 MutexedOptionInt64MergeWithMax cache_invalidation_timestamp_; 02648 Option<int64> css_flatten_max_bytes_; 02649 Option<bool> cache_small_images_unrewritten_; 02651 Option<int64> image_resolution_limit_bytes_; 02652 Option<int64> css_image_inline_max_bytes_; 02653 Option<int64> css_inline_max_bytes_; 02654 Option<int64> css_outline_min_bytes_; 02655 02657 Option<bool> css_preserve_urls_; 02658 Option<bool> js_preserve_urls_; 02659 Option<bool> image_preserve_urls_; 02660 02661 Option<int64> image_inline_max_bytes_; 02662 Option<int64> js_inline_max_bytes_; 02663 Option<int64> js_outline_min_bytes_; 02664 Option<int64> progressive_jpeg_min_bytes_; 02666 Option<int64> max_html_cache_time_ms_; 02669 Option<int64> max_html_parse_bytes_; 02671 Option<int64> max_image_bytes_for_webp_in_css_; 02673 Option<int64> min_resource_cache_time_to_rewrite_ms_; 02674 Option<int64> idle_flush_time_ms_; 02675 Option<int64> flush_buffer_limit_bytes_; 02676 02680 Option<int64> blocking_fetch_timeout_ms_; 02681 02684 Option<int64> image_recompress_quality_; 02685 02687 Option<int64> image_jpeg_recompress_quality_; 02688 Option<int> image_jpeg_num_progressive_scans_; 02689 Option<bool> image_retain_color_profile_; 02690 Option<bool> image_retain_color_sampling_; 02691 Option<bool> image_retain_exif_data_; 02692 02694 Option<int> image_limit_optimized_percent_; 02695 Option<int> image_limit_resize_area_percent_; 02696 02698 Option<int64> image_webp_recompress_quality_; 02699 Option<int64> image_webp_timeout_ms_; 02700 02701 Option<int> image_max_rewrites_at_once_; 02702 Option<int> max_url_segment_size_; 02703 Option<int> max_url_size_; 02704 02705 02706 Option<int> rewrite_deadline_ms_; 02708 Option<int> domain_shard_count_; 02709 02710 Option<EnabledEnum> enabled_; 02711 02714 Option<bool> add_options_to_urls_; 02715 02717 Option<bool> in_place_rewriting_enabled_; 02719 Option<bool> in_place_wait_for_optimized_; 02722 Option<int> in_place_rewrite_deadline_ms_; 02725 Option<bool> in_place_preemptive_rewrite_css_; 02727 Option<bool> in_place_preemptive_rewrite_css_images_; 02730 Option<bool> in_place_preemptive_rewrite_images_; 02733 Option<bool> in_place_preemptive_rewrite_javascript_; 02734 Option<bool> combine_across_paths_; 02735 Option<bool> log_rewrite_timing_; 02736 Option<bool> lowercase_html_names_; 02737 Option<bool> always_rewrite_css_; 02738 Option<bool> respect_vary_; 02739 Option<bool> respect_x_forwarded_proto_; 02740 Option<bool> flush_html_; 02743 Option<bool> serve_stale_if_fetch_error_; 02745 Option<bool> enable_blink_critical_line_; 02750 Option<bool> default_cache_html_; 02755 Option<bool> modify_caching_headers_; 02759 Option<bool> lazyload_images_after_onload_; 02762 Option<GoogleString> lazyload_images_blank_url_; 02766 Option<bool> inline_only_critical_images_; 02769 Option<bool> critical_images_beacon_enabled_; 02772 Option<bool> client_domain_rewrite_; 02775 Option<bool> domain_rewrite_hyperlinks_; 02776 02780 Option<bool> running_furious_; 02781 02782 Option<int> furious_ga_slot_; 02783 02786 Option<bool> increase_speed_tracking_; 02787 02791 Option<bool> report_unload_time_; 02792 02794 Option<bool> flush_more_resources_early_if_time_permits_; 02795 02797 Option<bool> flush_more_resources_in_ie_and_firefox_; 02798 02800 Option<bool> enable_defer_js_experimental_; 02801 02803 Option<bool> enable_inline_preview_images_experimental_; 02804 02807 Option<bool> avoid_renaming_introspective_javascript_; 02808 02810 Option<bool> override_ie_document_mode_; 02811 02813 Option<bool> test_instant_fetch_rewrite_deadline_; 02814 02820 Option<GoogleString> blocking_rewrite_key_; 02821 02824 Option<int> max_inlined_preview_images_index_; 02826 Option<int64> min_image_size_low_resolution_bytes_; 02828 Option<int64> max_image_size_low_resolution_bytes_; 02829 02832 Option<bool> oblivious_pagespeed_urls_; 02833 02835 Option<int64> finder_properties_cache_expiration_time_ms_; 02836 02840 Option<int64> finder_properties_cache_refresh_time_ms_; 02843 Option<int64> furious_cookie_duration_ms_; 02844 02847 Option<int64> metadata_cache_staleness_threshold_ms_; 02848 02850 Option<int64> metadata_input_errors_cache_ttl_ms_; 02851 02855 Option<int64> implicit_cache_ttl_ms_; 02856 02858 Option<int64> max_cacheable_response_content_length_; 02859 02866 std::vector<PrioritizeVisibleContentFamily*> 02867 prioritize_visible_content_families_; 02868 02869 Option<GoogleString> ga_id_; 02870 02873 Option<bool> use_fixed_user_agent_for_blink_cache_misses_; 02876 Option<GoogleString> blink_desktop_user_agent_; 02879 Option<bool> passthrough_blink_for_last_invalid_response_code_; 02881 Option<int64> blink_max_html_size_rewritable_; 02884 Option<int64> blink_html_change_detection_time_ms_; 02888 Option<bool> apply_blink_if_no_families_; 02890 Option<bool> enable_blink_debug_dashboard_; 02892 Option<bool> enable_blink_html_change_detection_; 02894 Option<bool> enable_blink_html_change_detection_logging_; 02896 Option<bool> use_smart_diff_in_blink_; 02898 Option<bool> enable_lazyload_in_blink_; 02900 Option<bool> enable_prioritizing_scripts_; 02902 Option<int64> override_blink_cache_time_ms_; 02905 Option<GoogleString> blink_non_cacheables_for_all_families_; 02907 Option<GoogleString> critical_line_config_; 02913 Option<bool> forbid_all_disabled_filters_; 02915 Option<bool> enable_aggressive_rewriters_for_mobile_; 02916 02922 Option<bool> reject_blacklisted_; 02923 Option<int> reject_blacklisted_status_code_; 02924 02928 Option<bool> support_noscript_enabled_; 02929 02932 Option<int64> max_combined_js_bytes_; 02933 02935 Option<GoogleString> pre_connect_url_; 02938 Option<int> property_cache_http_status_stability_threshold_; 02940 Option<int> max_rewrite_info_log_size_; 02941 02946 Option<int64> override_caching_ttl_ms_; 02947 FastWildcardGroup override_caching_wildcard_; 02948 02952 OptionBaseVector all_options_; 02953 size_t initialized_options_; 02954 02956 static const char* option_enum_to_name_array_[kEndOfOptions]; 02957 02960 static const FilterEnumToIdAndNameEntry* filter_id_to_enum_array_[ 02961 kEndOfFilters]; 02962 02967 static const PropertyBase** option_id_to_property_array_; 02968 02975 bool options_uniqueness_checked_; 02976 02978 bool need_to_store_experiment_data_; 02980 int furious_id_; 02981 int furious_percent_; 02982 std::vector<FuriousSpec*> furious_specs_; 02983 02985 std::vector<NameValue*> custom_fetch_headers_; 02986 02989 scoped_ptr<std::vector<ElementAttributeCategory> > url_valued_attributes_; 02990 02991 JavascriptLibraryIdentification javascript_library_identification_; 02992 02993 DomainLawyer domain_lawyer_; 02994 FileLoadPolicy file_load_policy_; 02995 02996 FastWildcardGroup allow_resources_; 02997 FastWildcardGroup retain_comments_; 02998 FastWildcardGroup lazyload_enabled_classes_; 02999 03002 typedef std::map<StringPiece, FastWildcardGroup*> FastWildcardGroupMap; 03003 FastWildcardGroupMap rejected_request_map_; 03004 03005 GoogleString signature_; 03006 03007 DISALLOW_COPY_AND_ASSIGN(RewriteOptions); 03008 }; 03009 03010 } 03011 03012 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_