2 * Copyright (C) 2012 Google, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
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"
41 class ExecutionContext;
42 class StyleSheetContents;
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.
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
56 WTF_MAKE_NONCOPYABLE(UseCounter);
62 // Do not change assigned numbers of existing items: add new features
63 // to the end of the list.
65 LegacyNotifications = 1,
66 PrefixedIndexedDB = 3,
68 SharedWorkerStart = 5,
71 UnprefixedIndexedDB = 9,
73 LegacyTextNotifications = 12,
74 UnprefixedRequestAnimationFrame = 13,
75 PrefixedRequestAnimationFrame = 14,
76 ContentSecurityPolicy = 15,
77 ContentSecurityPolicyReportOnly = 16,
78 PrefixedTransitionEndEvent = 18,
79 UnprefixedTransitionEndEvent = 19,
80 PrefixedAndUnprefixedTransitionEndEvent = 20,
81 AutoFocusAttribute = 21,
84 IncrementalAttribute = 25,
87 InputTypeDateTimeFallback = 29,
88 InputTypeDateTimeLocal = 30,
98 InputTypeWeekFallback = 40,
102 PatternAttribute = 44,
103 PlaceholderAttribute = 45,
104 PrecisionAttribute = 46,
105 PrefixedDirectoryAttribute = 47,
106 PrefixedSpeechAttribute = 48,
107 RequiredAttribute = 49,
108 ResultsAttribute = 50,
111 HTMLMarqueeElement = 53,
113 PrefixedStorageInfo = 57,
115 XFrameOptionsSameOrigin = 59,
116 XFrameOptionsSameOriginWithBadAncestorChain = 60,
117 DeprecatedFlexboxWebContent = 61,
118 DeprecatedFlexboxChrome = 62,
119 DeprecatedFlexboxChromeExtension = 63,
120 UnprefixedPerformanceTimeline = 65,
121 PrefixedPerformanceTimeline = 66,
122 UnprefixedUserTiming = 67,
124 ContentSecurityPolicyWithBaseElement = 70,
125 PrefixedMediaAddKey = 71,
126 PrefixedMediaGenerateKeyRequest = 72,
130 XSLProcessingInstruction = 78,
132 SVGSwitchElement = 80,
135 DemotedFormElement = 85,
136 CaptureAttributeAsEnum = 86,
137 ShadowDOMPrefixedCreateShadowRoot = 88,
138 ShadowDOMPrefixedShadowRoot = 89,
139 SVGAnimationElement = 90,
140 KeyboardEventKeyLocation = 91,
142 SubFrameBeforeUnloadRegistered = 97,
143 SubFrameBeforeUnloadFired = 98,
144 TextReplaceWholeText = 100,
145 PrefixedShadowRootConstructor = 101,
146 ConsoleMarkTimeline = 102,
147 CSSPseudoElementUserAgentCustomPseudo = 103,
148 DocumentTypeInternalSubset = 105, // Removed from DOM4.
149 ElementGetAttributeNode = 107, // Removed from DOM4.
150 ElementSetAttributeNode = 108, // Removed from DOM4.
151 ElementRemoveAttributeNode = 109, // Removed from DOM4.
152 ElementGetAttributeNodeNS = 110, // Removed from DOM4.
153 DocumentCreateAttribute = 111, // Removed from DOM4.
154 DocumentCreateCDATASection = 113, // Removed from DOM4.
155 DocumentInputEncoding = 114, // Removed from DOM4.
156 DocumentXMLEncoding = 115, // Removed from DOM4.
157 DocumentXMLStandalone = 116, // Removed from DOM4.
158 DocumentXMLVersion = 117, // Removed from DOM4.
159 NodeIsSameNode = 118, // Removed from DOM4.
160 NodeNamespaceURI = 120, // Removed from DOM4.
161 NodeLocalName = 122, // Removed from DOM4.
162 NavigatorProductSub = 123,
163 NavigatorVendor = 124,
164 NavigatorVendorSub = 125,
166 DocumentCharset = 127, // Documented as IE extensions = 0, from KHTML days.
167 PrefixedAnimationEndEvent = 128,
168 UnprefixedAnimationEndEvent = 129,
169 PrefixedAndUnprefixedAnimationEndEvent = 130,
170 PrefixedAnimationStartEvent = 131,
171 UnprefixedAnimationStartEvent = 132,
172 PrefixedAndUnprefixedAnimationStartEvent = 133,
173 PrefixedAnimationIterationEvent = 134,
174 UnprefixedAnimationIterationEvent = 135,
175 PrefixedAndUnprefixedAnimationIterationEvent = 136,
176 EventReturnValue = 137, // Legacy IE extension.
178 SVGAnimateColorElement = 139,
179 InsertAdjacentText = 140,
180 InsertAdjacentElement = 141,
181 HasAttributes = 142, // Removed from DOM4.
182 DOMSubtreeModifiedEvent = 143,
183 DOMNodeInsertedEvent = 144,
184 DOMNodeRemovedEvent = 145,
185 DOMNodeRemovedFromDocumentEvent = 146,
186 DOMNodeInsertedIntoDocumentEvent = 147,
187 DOMCharacterDataModifiedEvent = 148,
188 DocumentAllLegacyCall = 150,
189 HTMLAppletElementLegacyCall = 151,
190 HTMLEmbedElementLegacyCall = 152,
191 HTMLObjectElementLegacyCall = 153,
192 GetMatchedCSSRules = 155,
194 AttributeSpecified = 162, // Removed in DOM4.
195 PrefixedAudioDecodedByteCount = 164,
196 PrefixedVideoDecodedByteCount = 165,
197 PrefixedVideoSupportsFullscreen = 166,
198 PrefixedVideoDisplayingFullscreen = 167,
199 PrefixedVideoEnterFullscreen = 168,
200 PrefixedVideoExitFullscreen = 169,
201 PrefixedVideoEnterFullScreen = 170,
202 PrefixedVideoExitFullScreen = 171,
203 PrefixedVideoDecodedFrameCount = 172,
204 PrefixedVideoDroppedFrameCount = 173,
205 PrefixedElementRequestFullscreen = 176,
206 PrefixedElementRequestFullScreen = 177,
207 BarPropLocationbar = 178,
208 BarPropMenubar = 179,
209 BarPropPersonalbar = 180,
210 BarPropScrollbars = 181,
211 BarPropStatusbar = 182,
212 BarPropToolbar = 183,
213 InputTypeEmailMultiple = 184,
214 InputTypeEmailMaxLength = 185,
215 InputTypeEmailMultipleMaxLength = 186,
217 InputTypeTextMaxLength = 191,
218 InputTypePassword = 192,
219 InputTypePasswordMaxLength = 193,
220 SVGInstanceRoot = 194,
221 ShowModalDialog = 195,
222 PrefixedPageVisibility = 196,
223 HTMLFrameElementLocation = 197,
224 CSSStyleSheetInsertRuleOptionalArg = 198, // Inconsistent with the specification and other browsers.
225 DocumentBeforeUnloadRegistered = 200,
226 DocumentBeforeUnloadFired = 201,
227 DocumentUnloadRegistered = 202,
228 DocumentUnloadFired = 203,
229 SVGLocatableNearestViewportElement = 204,
230 SVGLocatableFarthestViewportElement = 205,
231 HTMLHeadElementProfile = 207,
232 OverflowChangedEvent = 208,
233 SVGPointMatrixTransform = 209,
234 HTMLHtmlElementManifest = 210,
235 DOMFocusInOutEvent = 211,
236 FileGetLastModifiedDate = 212,
237 HTMLElementInnerText = 213,
238 HTMLElementOuterText = 214,
239 ReplaceDocumentViaJavaScriptURL = 215,
240 ElementPrefixedMatchesSelector = 217,
241 DOMImplementationCreateCSSStyleSheet = 218,
242 CSSStyleSheetRules = 219,
243 CSSStyleSheetAddRule = 220,
244 CSSStyleSheetRemoveRule = 221,
245 // The above items are available in M33 branch.
247 InitMessageEvent = 222,
248 PrefixedInitMessageEvent = 223,
249 ElementSetPrefix = 224, // Element.prefix is readonly in DOM4.
250 CSSStyleDeclarationGetPropertyCSSValue = 225,
251 PrefixedMediaCancelKeyRequest = 229,
252 DOMImplementationHasFeature = 230,
253 DOMImplementationHasFeatureReturnFalse = 231,
254 CanPlayTypeKeySystem = 232,
255 PrefixedDevicePixelRatioMediaFeature = 233,
256 PrefixedMaxDevicePixelRatioMediaFeature = 234,
257 PrefixedMinDevicePixelRatioMediaFeature = 235,
258 PrefixedTransform2dMediaFeature = 236,
259 PrefixedTransform3dMediaFeature = 237,
260 PrefixedAnimationMediaFeature = 238,
261 PrefixedViewModeMediaFeature = 239,
262 PrefixedStorageQuota = 240,
263 ContentSecurityPolicyReportOnlyInMeta = 241,
264 PrefixedMediaSourceOpen = 242,
265 ResetReferrerPolicy = 243,
266 CaseInsensitiveAttrSelectorMatch = 244, // Case-insensitivity dropped from specification.
267 CaptureAttributeAsBoolean = 245,
268 FormNameAccessForImageElement = 246,
269 FormNameAccessForPastNamesMap = 247,
270 FormAssociationByParser = 248,
271 HTMLSourceElementMedia = 249,
272 SVGSVGElementInDocument = 250,
273 SVGDocumentRootElement = 251,
274 DocumentCreateEventOptionalArgument = 252,
275 MediaErrorEncrypted = 253,
276 EventSourceURL = 254,
278 WorkerSubjectToCSP = 257,
279 WorkerAllowedByChildBlockedByScript = 258,
280 HTMLMediaElementControllerNotNull = 259,
281 DeprecatedWebKitGradient = 260,
282 DeprecatedWebKitLinearGradient = 261,
283 DeprecatedWebKitRepeatingLinearGradient = 262,
284 DeprecatedWebKitRadialGradient = 263,
285 DeprecatedWebKitRepeatingRadialGradient = 264,
286 PrefixedGetImageDataHD = 265,
287 PrefixedPutImageDataHD = 266,
288 PrefixedImageSmoothingEnabled = 267,
289 UnprefixedImageSmoothingEnabled = 268,
290 PromiseConstructor = 270,
293 PromiseResolve = 273,
294 // The above items are available in M34 branch.
296 TextAutosizing = 274,
297 TextAutosizingLayout = 275,
298 HTMLAnchorElementPingAttribute = 276,
299 JavascriptExhaustedMemory = 277,
300 InsertAdjacentHTML = 278,
302 HTMLAppletElement = 280,
303 HTMLMediaElementSeekToFragmentStart = 281,
304 HTMLMediaElementPauseAtFragmentEnd = 282,
305 PrefixedWindowURL = 283,
306 PrefixedWorkerURL = 284,
307 WindowOrientation = 285,
308 DOMStringListContains = 286,
309 DocumentCaptureEvents = 287,
310 DocumentReleaseEvents = 288,
311 WindowCaptureEvents = 289,
312 WindowReleaseEvents = 290,
313 PrefixedGamepad = 291,
314 ElementAnimateKeyframeListEffectObjectTiming = 292,
315 ElementAnimateKeyframeListEffectDoubleTiming = 293,
316 ElementAnimateKeyframeListEffectNoTiming = 294,
317 DocumentXPathCreateExpression = 295,
318 DocumentXPathCreateNSResolver = 296,
319 DocumentXPathEvaluate = 297,
322 AnimationConstructorKeyframeListEffectObjectTiming = 300,
323 AnimationConstructorKeyframeListEffectDoubleTiming = 301,
324 AnimationConstructorKeyframeListEffectNoTiming = 302,
325 AttrSetValueWithElement = 303,
326 PrefixedCancelAnimationFrame = 304,
327 PrefixedCancelRequestAnimationFrame = 305,
328 NamedNodeMapGetNamedItem = 306,
329 NamedNodeMapSetNamedItem = 307,
330 NamedNodeMapRemoveNamedItem = 308,
331 NamedNodeMapItem = 309,
332 NamedNodeMapGetNamedItemNS = 310,
333 NamedNodeMapSetNamedItemNS = 311,
334 NamedNodeMapRemoveNamedItemNS = 312,
335 OpenWebDatabaseInWorker = 313,
336 OpenWebDatabaseSyncInWorker = 314,
337 PrefixedAllowFullscreenAttribute = 315,
338 XHRProgressEventPosition = 316,
339 XHRProgressEventTotalSize = 317,
340 PrefixedDocumentIsFullscreen = 318,
341 PrefixedDocumentFullScreenKeyboardInputAllowed = 319,
342 PrefixedDocumentCurrentFullScreenElement = 320,
343 PrefixedDocumentCancelFullScreen = 321,
344 PrefixedDocumentFullscreenEnabled = 322,
345 PrefixedDocumentFullscreenElement = 323,
346 PrefixedDocumentExitFullscreen = 324,
347 // Add new features immediately above this line. Don't change assigned
348 // numbers of any item, and don't reuse removed slots.
349 NumberOfFeatures, // This enum value must be last.
352 // "count" sets the bit for this feature to 1. Repeated calls are ignored.
353 static void count(const Document&, Feature);
354 static void count(const ExecutionContext*, Feature);
355 void count(CSSParserContext, CSSPropertyID);
358 // "countDeprecation" sets the bit for this feature to 1, and sends a deprecation
359 // warning to the console. Repeated calls are ignored.
361 // Be considerate to developers' consoles: features should only send deprecation warnings
362 // when we're actively interested in removing them from the platform.
363 static void countDeprecation(const DOMWindow*, Feature);
364 static void countDeprecation(ExecutionContext*, Feature);
365 static void countDeprecation(const Document&, Feature);
366 String deprecationMessage(Feature);
368 void didCommitLoad();
370 static UseCounter* getFrom(const Document*);
371 static UseCounter* getFrom(const CSSStyleSheet*);
372 static UseCounter* getFrom(const StyleSheetContents*);
374 static int mapCSSPropertyIdToCSSSampleIdForHistogram(int id);
376 static void muteForInspector();
377 static void unmuteForInspector();
380 static int m_muteCount;
382 bool recordMeasurement(Feature feature)
384 if (UseCounter::m_muteCount)
386 ASSERT(feature != PageDestruction); // PageDestruction is reserved as a scaling factor.
387 ASSERT(feature < NumberOfFeatures);
389 m_countBits = adoptPtr(new BitVector(NumberOfFeatures));
390 m_countBits->clearAll();
393 if (m_countBits->quickGet(feature))
396 m_countBits->quickSet(feature);
400 void updateMeasurements();
402 OwnPtr<BitVector> m_countBits;
403 BitVector m_CSSFeatureBits;
406 } // namespace WebCore
408 #endif // UseCounter_h