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 "core/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 PrefixedIndexedDB = 3,
67 SharedWorkerStart = 5,
68 UnprefixedIndexedDB = 9,
70 UnprefixedRequestAnimationFrame = 13,
71 PrefixedRequestAnimationFrame = 14,
72 ContentSecurityPolicy = 15,
73 ContentSecurityPolicyReportOnly = 16,
74 PrefixedTransitionEndEvent = 18,
75 UnprefixedTransitionEndEvent = 19,
76 PrefixedAndUnprefixedTransitionEndEvent = 20,
77 AutoFocusAttribute = 21,
80 IncrementalAttribute = 25,
83 InputTypeDateTimeFallback = 29,
84 InputTypeDateTimeLocal = 30,
94 InputTypeWeekFallback = 40,
98 PatternAttribute = 44,
99 PlaceholderAttribute = 45,
100 PrefixedDirectoryAttribute = 47,
101 RequiredAttribute = 49,
102 ResultsAttribute = 50,
105 HTMLMarqueeElement = 53,
107 PrefixedStorageInfo = 57,
109 XFrameOptionsSameOrigin = 59,
110 XFrameOptionsSameOriginWithBadAncestorChain = 60,
111 DeprecatedFlexboxWebContent = 61,
112 DeprecatedFlexboxChrome = 62,
113 DeprecatedFlexboxChromeExtension = 63,
114 UnprefixedPerformanceTimeline = 65,
115 UnprefixedUserTiming = 67,
117 ContentSecurityPolicyWithBaseElement = 70,
118 PrefixedMediaAddKey = 71,
119 PrefixedMediaGenerateKeyRequest = 72,
123 XSLProcessingInstruction = 78,
125 SVGSwitchElement = 80,
128 DemotedFormElement = 85,
129 SVGAnimationElement = 90,
130 KeyboardEventKeyLocation = 91,
132 SubFrameBeforeUnloadRegistered = 97,
133 SubFrameBeforeUnloadFired = 98,
134 TextReplaceWholeText = 100,
135 ConsoleMarkTimeline = 102,
136 CSSPseudoElementUserAgentCustomPseudo = 103,
137 ElementGetAttributeNode = 107, // Removed from DOM4.
138 ElementSetAttributeNode = 108, // Removed from DOM4.
139 ElementRemoveAttributeNode = 109, // Removed from DOM4.
140 ElementGetAttributeNodeNS = 110, // Removed from DOM4.
141 DocumentCreateAttribute = 111, // Removed from DOM4.
142 DocumentCreateAttributeNS = 112, // Removed from DOM4.
143 DocumentCreateCDATASection = 113, // Removed from DOM4.
144 DocumentInputEncoding = 114, // Removed from DOM4.
145 DocumentXMLEncoding = 115, // Removed from DOM4.
146 DocumentXMLStandalone = 116, // Removed from DOM4.
147 DocumentXMLVersion = 117, // Removed from DOM4.
148 NodeIsSameNode = 118, // Removed from DOM4.
149 NodeNamespaceURI = 120, // Removed from DOM4.
150 NodeLocalName = 122, // Removed from DOM4.
151 NavigatorProductSub = 123,
152 NavigatorVendor = 124,
153 NavigatorVendorSub = 125,
155 DocumentCharset = 127, // Documented as IE extensions = 0, from KHTML days.
156 PrefixedAnimationEndEvent = 128,
157 UnprefixedAnimationEndEvent = 129,
158 PrefixedAndUnprefixedAnimationEndEvent = 130,
159 PrefixedAnimationStartEvent = 131,
160 UnprefixedAnimationStartEvent = 132,
161 PrefixedAndUnprefixedAnimationStartEvent = 133,
162 PrefixedAnimationIterationEvent = 134,
163 UnprefixedAnimationIterationEvent = 135,
164 PrefixedAndUnprefixedAnimationIterationEvent = 136,
165 EventReturnValue = 137, // Legacy IE extension.
167 InsertAdjacentText = 140,
168 InsertAdjacentElement = 141,
169 HasAttributes = 142, // Removed from DOM4.
170 DOMSubtreeModifiedEvent = 143,
171 DOMNodeInsertedEvent = 144,
172 DOMNodeRemovedEvent = 145,
173 DOMNodeRemovedFromDocumentEvent = 146,
174 DOMNodeInsertedIntoDocumentEvent = 147,
175 DOMCharacterDataModifiedEvent = 148,
176 DocumentAllLegacyCall = 150,
177 HTMLAppletElementLegacyCall = 151,
178 HTMLEmbedElementLegacyCall = 152,
179 HTMLObjectElementLegacyCall = 153,
180 GetMatchedCSSRules = 155,
182 AttributeOwnerElement = 160, // Removed in DOM4.
183 AttributeSpecified = 162, // Removed in DOM4.
184 PrefixedAudioDecodedByteCount = 164,
185 PrefixedVideoDecodedByteCount = 165,
186 PrefixedVideoSupportsFullscreen = 166,
187 PrefixedVideoDisplayingFullscreen = 167,
188 PrefixedVideoEnterFullscreen = 168,
189 PrefixedVideoExitFullscreen = 169,
190 PrefixedVideoEnterFullScreen = 170,
191 PrefixedVideoExitFullScreen = 171,
192 PrefixedVideoDecodedFrameCount = 172,
193 PrefixedVideoDroppedFrameCount = 173,
194 PrefixedElementRequestFullscreen = 176,
195 PrefixedElementRequestFullScreen = 177,
196 BarPropLocationbar = 178,
197 BarPropMenubar = 179,
198 BarPropPersonalbar = 180,
199 BarPropScrollbars = 181,
200 BarPropStatusbar = 182,
201 BarPropToolbar = 183,
202 InputTypeEmailMultiple = 184,
203 InputTypeEmailMaxLength = 185,
204 InputTypeEmailMultipleMaxLength = 186,
206 InputTypeTextMaxLength = 191,
207 InputTypePassword = 192,
208 InputTypePasswordMaxLength = 193,
209 ShowModalDialog = 195,
210 PrefixedPageVisibility = 196,
211 CSSStyleSheetInsertRuleOptionalArg = 198, // Inconsistent with the specification and other browsers.
212 DocumentBeforeUnloadRegistered = 200,
213 DocumentBeforeUnloadFired = 201,
214 DocumentUnloadRegistered = 202,
215 DocumentUnloadFired = 203,
216 SVGLocatableNearestViewportElement = 204,
217 SVGLocatableFarthestViewportElement = 205,
218 HTMLHeadElementProfile = 207,
219 OverflowChangedEvent = 208,
220 SVGPointMatrixTransform = 209,
221 DOMFocusInOutEvent = 211,
222 FileGetLastModifiedDate = 212,
223 HTMLElementInnerText = 213,
224 HTMLElementOuterText = 214,
225 ReplaceDocumentViaJavaScriptURL = 215,
226 ElementSetAttributeNodeNS = 216, // Removed from DOM4.
227 ElementPrefixedMatchesSelector = 217,
228 CSSStyleSheetRules = 219,
229 CSSStyleSheetAddRule = 220,
230 CSSStyleSheetRemoveRule = 221,
231 // The above items are available in M33 branch.
233 InitMessageEvent = 222,
234 ElementSetPrefix = 224, // Element.prefix is readonly in DOM4.
235 CSSStyleDeclarationGetPropertyCSSValue = 225,
236 PrefixedMediaCancelKeyRequest = 229,
237 DOMImplementationHasFeature = 230,
238 DOMImplementationHasFeatureReturnFalse = 231,
239 CanPlayTypeKeySystem = 232,
240 PrefixedDevicePixelRatioMediaFeature = 233,
241 PrefixedMaxDevicePixelRatioMediaFeature = 234,
242 PrefixedMinDevicePixelRatioMediaFeature = 235,
243 PrefixedTransform3dMediaFeature = 237,
244 PrefixedStorageQuota = 240,
245 ContentSecurityPolicyReportOnlyInMeta = 241,
246 ResetReferrerPolicy = 243,
247 CaseInsensitiveAttrSelectorMatch = 244, // Case-insensitivity dropped from specification.
248 FormNameAccessForImageElement = 246,
249 FormNameAccessForPastNamesMap = 247,
250 FormAssociationByParser = 248,
251 SVGSVGElementInDocument = 250,
252 SVGDocumentRootElement = 251,
253 MediaErrorEncrypted = 253,
254 EventSourceURL = 254,
256 WorkerSubjectToCSP = 257,
257 WorkerAllowedByChildBlockedByScript = 258,
258 DeprecatedWebKitGradient = 260,
259 DeprecatedWebKitLinearGradient = 261,
260 DeprecatedWebKitRepeatingLinearGradient = 262,
261 DeprecatedWebKitRadialGradient = 263,
262 DeprecatedWebKitRepeatingRadialGradient = 264,
263 PrefixedImageSmoothingEnabled = 267,
264 UnprefixedImageSmoothingEnabled = 268,
265 // The above items are available in M34 branch.
267 TextAutosizing = 274,
268 HTMLAnchorElementPingAttribute = 276,
269 InsertAdjacentHTML = 278,
271 HTMLAppletElement = 280,
272 HTMLMediaElementSeekToFragmentStart = 281,
273 HTMLMediaElementPauseAtFragmentEnd = 282,
274 PrefixedWindowURL = 283,
275 PrefixedWorkerURL = 284, // This didn't work because of crbug.com/376039. Available since M37.
276 WindowOrientation = 285,
277 DOMStringListContains = 286,
278 DocumentCaptureEvents = 287,
279 DocumentReleaseEvents = 288,
280 WindowCaptureEvents = 289,
281 WindowReleaseEvents = 290,
282 PrefixedGamepad = 291,
283 ElementAnimateKeyframeListEffectObjectTiming = 292,
284 ElementAnimateKeyframeListEffectDoubleTiming = 293,
285 ElementAnimateKeyframeListEffectNoTiming = 294,
286 DocumentXPathCreateExpression = 295,
287 DocumentXPathCreateNSResolver = 296,
288 DocumentXPathEvaluate = 297,
291 AnimationConstructorKeyframeListEffectObjectTiming = 300,
292 AnimationConstructorKeyframeListEffectDoubleTiming = 301,
293 AnimationConstructorKeyframeListEffectNoTiming = 302,
294 AttrSetValueWithElement = 303,
295 PrefixedCancelAnimationFrame = 304,
296 PrefixedCancelRequestAnimationFrame = 305,
297 NamedNodeMapGetNamedItem = 306,
298 NamedNodeMapSetNamedItem = 307,
299 NamedNodeMapRemoveNamedItem = 308,
300 NamedNodeMapItem = 309,
301 NamedNodeMapGetNamedItemNS = 310,
302 NamedNodeMapSetNamedItemNS = 311,
303 NamedNodeMapRemoveNamedItemNS = 312,
304 OpenWebDatabaseInWorker = 313, // This didn't work because of crbug.com/376039. Available since M37.
305 OpenWebDatabaseSyncInWorker = 314, // This didn't work because of crbug.com/376039. Available since M37.
306 XHRProgressEventPosition = 316,
307 XHRProgressEventTotalSize = 317,
308 PrefixedDocumentIsFullscreen = 318,
309 PrefixedDocumentFullScreenKeyboardInputAllowed = 319,
310 PrefixedDocumentCurrentFullScreenElement = 320,
311 PrefixedDocumentCancelFullScreen = 321,
312 PrefixedDocumentFullscreenEnabled = 322,
313 PrefixedDocumentFullscreenElement = 323,
314 PrefixedDocumentExitFullscreen = 324,
315 // The above items are available in M35 branch.
317 SVGForeignObjectElement = 325,
318 SelectionSetPosition = 327,
319 AnimationPlayerFinishEvent = 328,
320 SVGSVGElementInXMLDocument = 329,
321 CanvasRenderingContext2DSetAlpha = 330,
322 CanvasRenderingContext2DSetCompositeOperation = 331,
323 CanvasRenderingContext2DSetLineWidth = 332,
324 CanvasRenderingContext2DSetLineCap = 333,
325 CanvasRenderingContext2DSetLineJoin = 334,
326 CanvasRenderingContext2DSetMiterLimit = 335,
327 CanvasRenderingContext2DClearShadow = 336,
328 CanvasRenderingContext2DSetStrokeColor = 337,
329 CanvasRenderingContext2DSetFillColor = 338,
330 CanvasRenderingContext2DDrawImageFromRect = 339,
331 CanvasRenderingContext2DSetShadow = 340,
332 PrefixedPerformanceClearResourceTimings = 341,
333 PrefixedPerformanceSetResourceTimingBufferSize = 342,
334 EventSrcElement = 343,
335 EventCancelBubble = 344,
337 EventClipboardData = 346,
338 NodeIteratorDetach = 347,
340 AttrTextContent = 349,
341 EventGetReturnValueTrue = 350,
342 EventGetReturnValueFalse = 351,
343 EventSetReturnValueTrue = 352,
344 EventSetReturnValueFalse = 353,
345 NodeIteratorExpandEntityReferences = 354,
346 TreeWalkerExpandEntityReferences = 355,
347 WindowOffscreenBuffering = 356,
348 WindowDefaultStatus = 357,
349 WindowDefaultstatus = 358,
350 PrefixedTransitionEventConstructor = 361,
351 PrefixedMutationObserverConstructor = 362,
352 PrefixedIDBCursorConstructor = 363,
353 PrefixedIDBDatabaseConstructor = 364,
354 PrefixedIDBFactoryConstructor = 365,
355 PrefixedIDBIndexConstructor = 366,
356 PrefixedIDBKeyRangeConstructor = 367,
357 PrefixedIDBObjectStoreConstructor = 368,
358 PrefixedIDBRequestConstructor = 369,
359 PrefixedIDBTransactionConstructor = 370,
360 NotificationPermission = 371,
362 HTMLTableElementVspace = 374,
363 HTMLTableElementHspace = 375,
364 PrefixedTouchRadiusX = 378,
365 PrefixedTouchRadiusY = 379,
366 PrefixedTouchRotationAngle = 380,
367 PrefixedTouchForce = 381,
368 PrefixedMouseEventMovementX = 382,
369 PrefixedMouseEventMovementY = 383,
370 PrefixedFileRelativePath = 386,
371 DocumentCaretRangeFromPoint = 387,
372 DocumentGetCSSCanvasContext = 388,
373 ElementScrollIntoViewIfNeeded = 389,
374 RangeCompareNode = 392,
376 HTMLImageElementX = 396,
377 HTMLImageElementY = 397,
378 SelectionBaseNode = 400,
379 SelectionBaseOffset = 401,
380 SelectionExtentNode = 402,
381 SelectionExtentOffset = 403,
383 SelectionModify = 405,
384 SelectionSetBaseAndExtent = 406,
385 SelectionEmpty = 407,
388 VTTCueRenderVertical = 411,
389 VTTCueRenderSnapToLinesFalse = 412,
390 VTTCueRenderLineNotAuto = 413,
391 VTTCueRenderPositionNot50 = 414,
392 VTTCueRenderSizeNot100 = 415,
393 VTTCueRenderAlignNotMiddle = 416,
394 // The above items are available in M36 branch.
396 ElementRequestPointerLock = 417,
397 VTTCueRenderRtl = 418,
398 PostMessageFromSecureToInsecure = 419,
399 PostMessageFromInsecureToSecure = 420,
400 DocumentExitPointerLock = 421,
401 DocumentPointerLockElement = 422,
402 PrefixedCursorZoomIn = 424,
403 PrefixedCursorZoomOut = 425,
404 CSSCharsetRuleEncoding = 426,
405 DocumentSetCharset = 427,
406 DocumentDefaultCharset = 428,
407 TextEncoderConstructor = 429,
408 TextEncoderEncode = 430,
409 TextDecoderConstructor = 431,
410 TextDecoderDecode = 432,
411 FocusInOutEvent = 433,
412 MouseEventMovementX = 434,
413 MouseEventMovementY = 435,
414 MixedContentRaw = 437,
415 MixedContentImage = 438,
416 MixedContentMedia = 439,
418 MixedContentFormsSubmitted = 441,
419 FormsSubmitted = 442,
420 TextInputEventOnInput = 443,
421 TextInputEventOnTextArea = 444,
422 TextInputEventOnContentEditable = 445,
423 TextInputEventOnNotNode = 446,
424 WebkitBeforeTextInsertedOnInput = 447,
425 WebkitBeforeTextInsertedOnTextArea = 448,
426 WebkitBeforeTextInsertedOnContentEditable = 449,
427 WebkitBeforeTextInsertedOnNotNode = 450,
428 WebkitEditableContentChangedOnInput = 451,
429 WebkitEditableContentChangedOnTextArea = 452,
430 WebkitEditableContentChangedOnContentEditable = 453,
431 WebkitEditableContentChangedOnNotNode = 454,
433 ElementCreateShadowRoot = 456,
434 DocumentRegisterElement = 457,
435 EditingAppleInterchangeNewline = 458,
436 EditingAppleConvertedSpace = 459,
437 EditingApplePasteAsQuotation = 460,
438 EditingAppleStyleSpanClass = 461,
439 EditingAppleTabSpanClass = 462,
440 HTMLImportsAsyncAttribute = 463,
441 FontFaceSetReady = 464,
442 XMLHttpRequestSynchronous = 465,
443 CSSSelectorPseudoUnresolved = 466,
444 CSSSelectorPseudoShadow = 467,
445 CSSSelectorPseudoContent = 468,
446 CSSSelectorPseudoHost = 469,
447 CSSSelectorPseudoHostContext = 470,
448 CSSDeepCombinator = 471,
449 SyncXHRWithCredentials = 472,
450 // The above items are available in M37 branch.
453 KeyEventNotAllowedInFullScreen = 474,
455 DOMWindowOpenFeatures = 476,
456 MediaStreamTrackGetSources = 478,
457 AspectRatioFlexItem = 479,
458 DetailsElement = 480,
462 ProgressElement = 484,
463 VideoFullscreenAllowedExemption = 485,
465 PrefixedHTMLElementDropzone = 490,
466 WheelEventWheelDeltaX = 491,
467 WheelEventWheelDeltaY = 492,
468 WheelEventWheelDelta = 493,
470 SendBeaconQuotaExceeded = 495,
471 SVGSMILElementInDocument = 501,
472 MouseEventOffsetX = 502,
473 MouseEventOffsetY = 503,
476 MouseEventFromElement = 506,
477 MouseEventToElement = 507,
478 RequestFileSystem = 508,
479 RequestFileSystemWorker = 509,
480 RequestFileSystemSyncWorker = 510,
485 BgPropertiesFixed = 515,
486 HTMLImageElementComposite = 516,
487 DevToolsConsoleTimeline = 517,
488 DevToolsConsoleProfile = 518,
489 SVGStyleElementTitle = 519,
490 PictureSourceSrc = 520,
491 // Add new features immediately above this line. Don't change assigned
492 // numbers of any item, and don't reuse removed slots.
493 // Also, run update_use_counter_feature_enum.py in chromium/src/tools/metrics/histograms/
494 // to update the UMA mapping.
495 NumberOfFeatures, // This enum value must be last.
498 // "count" sets the bit for this feature to 1. Repeated calls are ignored.
499 static void count(const Document&, Feature);
500 // This doesn't count for ExecutionContexts for shared workers and service
502 static void count(const ExecutionContext*, Feature);
503 void count(CSSParserContext, CSSPropertyID);
506 // "countDeprecation" sets the bit for this feature to 1, and sends a deprecation
507 // warning to the console. Repeated calls are ignored.
509 // Be considerate to developers' consoles: features should only send
510 // deprecation warnings when we're actively interested in removing them from
513 // The ExecutionContext* overload doesn't work for shared workers and
515 static void countDeprecation(const LocalDOMWindow*, Feature);
516 static void countDeprecation(ExecutionContext*, Feature);
517 static void countDeprecation(const Document&, Feature);
518 String deprecationMessage(Feature);
520 void didCommitLoad();
522 static UseCounter* getFrom(const Document*);
523 static UseCounter* getFrom(const CSSStyleSheet*);
524 static UseCounter* getFrom(const StyleSheetContents*);
526 static int mapCSSPropertyIdToCSSSampleIdForHistogram(int id);
528 static void muteForInspector();
529 static void unmuteForInspector();
532 static int m_muteCount;
534 bool recordMeasurement(Feature feature)
536 if (UseCounter::m_muteCount)
538 ASSERT(feature != PageDestruction); // PageDestruction is reserved as a scaling factor.
539 ASSERT(feature < NumberOfFeatures);
541 m_countBits = adoptPtr(new BitVector(NumberOfFeatures));
542 m_countBits->clearAll();
545 if (m_countBits->quickGet(feature))
548 m_countBits->quickSet(feature);
552 void updateMeasurements();
554 OwnPtr<BitVector> m_countBits;
555 BitVector m_CSSFeatureBits;
560 #endif // UseCounter_h