1 /* 2 * Copyright (C) 2012 Google, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef UseCounter_h 27 #define UseCounter_h 28 29 #include "CSSPropertyNames.h" 30 #include "wtf/BitVector.h" 31 #include "wtf/Noncopyable.h" 32 #include "wtf/OwnPtr.h" 33 #include "wtf/PassOwnPtr.h" 34 #include "wtf/text/WTFString.h" 35 36 namespace WebCore { 37 38 class CSSStyleSheet; 39 class DOMWindow; 40 class Document; 41 class ScriptExecutionContext; 42 class StyleSheetContents; 43 44 // UseCounter is used for counting the number of times features of 45 // Blink are used on real web pages and help us know commonly 46 // features are used and thus when it's safe to remove or change them. 47 // 48 // The Chromium Content layer controls what is done with this data. 49 // For instance, in Google Chrome, these counts are submitted 50 // anonymously through the Histogram recording system in Chrome 51 // for users who opt-in to "Usage Statistics" submission 52 // during their install of Google Chrome: 53 // http://www.google.com/chrome/intl/en/privacy.html 54 55 class UseCounter { 56 WTF_MAKE_NONCOPYABLE(UseCounter); 57 public: 58 UseCounter(); 59 ~UseCounter(); 60 61 enum Feature { 62 PageDestruction, 63 LegacyNotifications, 64 MultipartMainResource, 65 PrefixedIndexedDB, 66 WorkerStart, 67 SharedWorkerStart, 68 LegacyWebAudio, 69 WebAudioStart, 70 PrefixedContentSecurityPolicy, 71 UnprefixedIndexedDB, 72 OpenWebDatabase, 73 UnusedSlot01, // Prior to 7/2013, we used this slot for LegacyHTMLNotifications. 74 LegacyTextNotifications, 75 UnprefixedRequestAnimationFrame, 76 PrefixedRequestAnimationFrame, 77 ContentSecurityPolicy, 78 ContentSecurityPolicyReportOnly, 79 PrefixedContentSecurityPolicyReportOnly, 80 PrefixedTransitionEndEvent, 81 UnprefixedTransitionEndEvent, 82 PrefixedAndUnprefixedTransitionEndEvent, 83 AutoFocusAttribute, 84 UnusedSlot02, // Prior to 4/2013, we used this slot for AutoSaveAttribute. 85 DataListElement, 86 FormAttribute, 87 IncrementalAttribute, 88 InputTypeColor, 89 InputTypeDate, 90 InputTypeDateTime, 91 InputTypeDateTimeFallback, 92 InputTypeDateTimeLocal, 93 InputTypeEmail, 94 InputTypeMonth, 95 InputTypeNumber, 96 InputTypeRange, 97 InputTypeSearch, 98 InputTypeTel, 99 InputTypeTime, 100 InputTypeURL, 101 InputTypeWeek, 102 InputTypeWeekFallback, 103 ListAttribute, 104 MaxAttribute, 105 MinAttribute, 106 PatternAttribute, 107 PlaceholderAttribute, 108 PrecisionAttribute, 109 PrefixedDirectoryAttribute, 110 PrefixedSpeechAttribute, 111 RequiredAttribute, 112 ResultsAttribute, 113 StepAttribute, 114 PageVisits, 115 HTMLMarqueeElement, 116 UnusedSlot03, // Removed, was tracking overflow: -webkit-marquee. 117 Reflection, 118 CursorVisibility, // Removed, was -webkit-cursor-visibility. 119 StorageInfo, 120 XFrameOptions, 121 XFrameOptionsSameOrigin, 122 XFrameOptionsSameOriginWithBadAncestorChain, 123 DeprecatedFlexboxWebContent, 124 DeprecatedFlexboxChrome, 125 DeprecatedFlexboxChromeExtension, 126 SVGTRefElement, 127 UnprefixedPerformanceTimeline, 128 PrefixedPerformanceTimeline, 129 UnprefixedUserTiming, 130 PrefixedUserTiming, 131 WindowEvent, 132 ContentSecurityPolicyWithBaseElement, 133 PrefixedMediaAddKey, 134 PrefixedMediaGenerateKeyRequest, 135 WebAudioLooping, 136 DocumentClear, 137 PrefixedTransitionMediaFeature, 138 SVGFontElement, 139 XMLDocument, 140 XSLProcessingInstruction, 141 XSLTProcessor, 142 SVGSwitchElement, 143 PrefixedDocumentRegister, 144 HTMLShadowElementOlderShadowRoot, 145 DocumentAll, 146 FormElement, 147 DemotedFormElement, 148 CaptureAttributeAsEnum, 149 ShadowDOMPrefixedPseudo, 150 ShadowDOMPrefixedCreateShadowRoot, 151 ShadowDOMPrefixedShadowRoot, 152 SVGAnimationElement, 153 KeyboardEventKeyLocation, 154 CaptureEvents, 155 ReleaseEvents, 156 CSSDisplayRunIn, 157 CSSDisplayCompact, 158 LineClamp, 159 SubFrameBeforeUnloadRegistered, 160 SubFrameBeforeUnloadFired, 161 CSSPseudoElementPrefixedDistributed, 162 TextReplaceWholeText, 163 PrefixedShadowRootConstructor, 164 ConsoleMarkTimeline, 165 CSSPseudoElementUserAgentCustomPseudo, 166 // Add new features immediately above this line. Don't change assigned 167 // numbers of each items, and don't reuse unused slots. 168 NumberOfFeatures, // This enum value must be last. 169 }; 170 171 // "count" sets the bit for this feature to 1. Repeated calls are ignored. 172 static void count(Document*, Feature); 173 static void count(DOMWindow*, Feature); 174 void count(CSSPropertyID); 175 void count(Feature); 176 177 // "countDeprecation" sets the bit for this feature to 1, and sends a deprecation 178 // warning to the console. Repeated calls are ignored. 179 // 180 // Be considerate to developers' consoles: features should only send deprecation warnings 181 // when we're actively interested in removing them from the platform. 182 static void countDeprecation(DOMWindow*, Feature); 183 static void countDeprecation(ScriptExecutionContext*, Feature); 184 static void countDeprecation(Document*, Feature); 185 String deprecationMessage(Feature); 186 187 void didCommitLoad(); 188 189 static UseCounter* getFrom(const Document*); 190 static UseCounter* getFrom(const CSSStyleSheet*); 191 static UseCounter* getFrom(const StyleSheetContents*); 192 193 static int mapCSSPropertyIdToCSSSampleIdForHistogram(int id); 194 195 private: 196 bool recordMeasurement(Feature feature) 197 { 198 ASSERT(feature != PageDestruction); // PageDestruction is reserved as a scaling factor. 199 ASSERT(feature < NumberOfFeatures); 200 if (!m_countBits) { 201 m_countBits = adoptPtr(new BitVector(NumberOfFeatures)); 202 m_countBits->clearAll(); 203 } 204 205 if (m_countBits->quickGet(feature)) 206 return false; 207 208 m_countBits->quickSet(feature); 209 return true; 210 } 211 212 void updateMeasurements(); 213 214 OwnPtr<BitVector> m_countBits; 215 BitVector m_CSSFeatureBits; 216 }; 217 218 } // namespace WebCore 219 220 #endif // UseCounter_h 221