Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / frame / UseCounter.cpp
1
2 /*
3  * Copyright (C) 2012 Google, Inc. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #include "core/frame/UseCounter.h"
29
30 #include "core/css/CSSStyleSheet.h"
31 #include "core/css/StyleSheetContents.h"
32 #include "core/dom/Document.h"
33 #include "core/dom/ExecutionContext.h"
34 #include "core/frame/DOMWindow.h"
35 #include "core/frame/FrameConsole.h"
36 #include "core/frame/FrameHost.h"
37 #include "core/frame/LocalFrame.h"
38 #include "public/platform/Platform.h"
39
40 namespace WebCore {
41
42 static int totalPagesMeasuredCSSSampleId() { return 1; }
43
44 int UseCounter::m_muteCount = 0;
45
46 // FIXME : This mapping should be autogenerated. This function should
47 //         be moved to a separate file and a script run at build time
48 //         to detect new values in CSSPropertyID and add them to the
49 //         end of this function. This file would be checked in.
50 //         https://code.google.com/p/chromium/issues/detail?id=234940
51 int UseCounter::mapCSSPropertyIdToCSSSampleIdForHistogram(int id)
52 {
53     CSSPropertyID cssPropertyID = convertToCSSPropertyID(id);
54
55     switch (cssPropertyID) {
56     // Begin at 2, because 1 is reserved for totalPagesMeasuredCSSSampleId.
57     case CSSPropertyColor: return 2;
58     case CSSPropertyDirection: return 3;
59     case CSSPropertyDisplay: return 4;
60     case CSSPropertyFont: return 5;
61     case CSSPropertyFontFamily: return 6;
62     case CSSPropertyFontSize: return 7;
63     case CSSPropertyFontStyle: return 8;
64     case CSSPropertyFontVariant: return 9;
65     case CSSPropertyFontWeight: return 10;
66     case CSSPropertyTextRendering: return 11;
67     case CSSPropertyWebkitFontFeatureSettings: return 12;
68     case CSSPropertyFontKerning: return 13;
69     case CSSPropertyWebkitFontSmoothing: return 14;
70     case CSSPropertyFontVariantLigatures: return 15;
71     case CSSPropertyWebkitLocale: return 16;
72     case CSSPropertyWebkitTextOrientation: return 17;
73     case CSSPropertyWebkitWritingMode: return 18;
74     case CSSPropertyZoom: return 19;
75     case CSSPropertyLineHeight: return 20;
76     case CSSPropertyBackground: return 21;
77     case CSSPropertyBackgroundAttachment: return 22;
78     case CSSPropertyBackgroundClip: return 23;
79     case CSSPropertyBackgroundColor: return 24;
80     case CSSPropertyBackgroundImage: return 25;
81     case CSSPropertyBackgroundOrigin: return 26;
82     case CSSPropertyBackgroundPosition: return 27;
83     case CSSPropertyBackgroundPositionX: return 28;
84     case CSSPropertyBackgroundPositionY: return 29;
85     case CSSPropertyBackgroundRepeat: return 30;
86     case CSSPropertyBackgroundRepeatX: return 31;
87     case CSSPropertyBackgroundRepeatY: return 32;
88     case CSSPropertyBackgroundSize: return 33;
89     case CSSPropertyBorder: return 34;
90     case CSSPropertyBorderBottom: return 35;
91     case CSSPropertyBorderBottomColor: return 36;
92     case CSSPropertyBorderBottomLeftRadius: return 37;
93     case CSSPropertyBorderBottomRightRadius: return 38;
94     case CSSPropertyBorderBottomStyle: return 39;
95     case CSSPropertyBorderBottomWidth: return 40;
96     case CSSPropertyBorderCollapse: return 41;
97     case CSSPropertyBorderColor: return 42;
98     case CSSPropertyBorderImage: return 43;
99     case CSSPropertyBorderImageOutset: return 44;
100     case CSSPropertyBorderImageRepeat: return 45;
101     case CSSPropertyBorderImageSlice: return 46;
102     case CSSPropertyBorderImageSource: return 47;
103     case CSSPropertyBorderImageWidth: return 48;
104     case CSSPropertyBorderLeft: return 49;
105     case CSSPropertyBorderLeftColor: return 50;
106     case CSSPropertyBorderLeftStyle: return 51;
107     case CSSPropertyBorderLeftWidth: return 52;
108     case CSSPropertyBorderRadius: return 53;
109     case CSSPropertyBorderRight: return 54;
110     case CSSPropertyBorderRightColor: return 55;
111     case CSSPropertyBorderRightStyle: return 56;
112     case CSSPropertyBorderRightWidth: return 57;
113     case CSSPropertyBorderSpacing: return 58;
114     case CSSPropertyBorderStyle: return 59;
115     case CSSPropertyBorderTop: return 60;
116     case CSSPropertyBorderTopColor: return 61;
117     case CSSPropertyBorderTopLeftRadius: return 62;
118     case CSSPropertyBorderTopRightRadius: return 63;
119     case CSSPropertyBorderTopStyle: return 64;
120     case CSSPropertyBorderTopWidth: return 65;
121     case CSSPropertyBorderWidth: return 66;
122     case CSSPropertyBottom: return 67;
123     case CSSPropertyBoxShadow: return 68;
124     case CSSPropertyBoxSizing: return 69;
125     case CSSPropertyCaptionSide: return 70;
126     case CSSPropertyClear: return 71;
127     case CSSPropertyClip: return 72;
128     case CSSPropertyWebkitClipPath: return 73;
129     case CSSPropertyContent: return 74;
130     case CSSPropertyCounterIncrement: return 75;
131     case CSSPropertyCounterReset: return 76;
132     case CSSPropertyCursor: return 77;
133     case CSSPropertyEmptyCells: return 78;
134     case CSSPropertyFloat: return 79;
135     case CSSPropertyFontStretch: return 80;
136     case CSSPropertyHeight: return 81;
137     case CSSPropertyImageRendering: return 82;
138     case CSSPropertyLeft: return 83;
139     case CSSPropertyLetterSpacing: return 84;
140     case CSSPropertyListStyle: return 85;
141     case CSSPropertyListStyleImage: return 86;
142     case CSSPropertyListStylePosition: return 87;
143     case CSSPropertyListStyleType: return 88;
144     case CSSPropertyMargin: return 89;
145     case CSSPropertyMarginBottom: return 90;
146     case CSSPropertyMarginLeft: return 91;
147     case CSSPropertyMarginRight: return 92;
148     case CSSPropertyMarginTop: return 93;
149     case CSSPropertyMaxHeight: return 94;
150     case CSSPropertyMaxWidth: return 95;
151     case CSSPropertyMinHeight: return 96;
152     case CSSPropertyMinWidth: return 97;
153     case CSSPropertyOpacity: return 98;
154     case CSSPropertyOrphans: return 99;
155     case CSSPropertyOutline: return 100;
156     case CSSPropertyOutlineColor: return 101;
157     case CSSPropertyOutlineOffset: return 102;
158     case CSSPropertyOutlineStyle: return 103;
159     case CSSPropertyOutlineWidth: return 104;
160     case CSSPropertyOverflow: return 105;
161     case CSSPropertyOverflowWrap: return 106;
162     case CSSPropertyOverflowX: return 107;
163     case CSSPropertyOverflowY: return 108;
164     case CSSPropertyPadding: return 109;
165     case CSSPropertyPaddingBottom: return 110;
166     case CSSPropertyPaddingLeft: return 111;
167     case CSSPropertyPaddingRight: return 112;
168     case CSSPropertyPaddingTop: return 113;
169     case CSSPropertyPage: return 114;
170     case CSSPropertyPageBreakAfter: return 115;
171     case CSSPropertyPageBreakBefore: return 116;
172     case CSSPropertyPageBreakInside: return 117;
173     case CSSPropertyPointerEvents: return 118;
174     case CSSPropertyPosition: return 119;
175     case CSSPropertyQuotes: return 120;
176     case CSSPropertyResize: return 121;
177     case CSSPropertyRight: return 122;
178     case CSSPropertySize: return 123;
179     case CSSPropertySrc: return 124;
180     case CSSPropertySpeak: return 125;
181     case CSSPropertyTableLayout: return 126;
182     case CSSPropertyTabSize: return 127;
183     case CSSPropertyTextAlign: return 128;
184     case CSSPropertyTextDecoration: return 129;
185     case CSSPropertyTextIndent: return 130;
186     /* Removed CSSPropertyTextLineThrough - 131 */
187     case CSSPropertyTextLineThroughColor: return 132;
188     case CSSPropertyTextLineThroughMode: return 133;
189     case CSSPropertyTextLineThroughStyle: return 134;
190     case CSSPropertyTextLineThroughWidth: return 135;
191     case CSSPropertyTextOverflow: return 136;
192     /* Removed CSSPropertyTextOverline - 137 */
193     case CSSPropertyTextOverlineColor: return 138;
194     case CSSPropertyTextOverlineMode: return 139;
195     case CSSPropertyTextOverlineStyle: return 140;
196     case CSSPropertyTextOverlineWidth: return 141;
197     case CSSPropertyTextShadow: return 142;
198     case CSSPropertyTextTransform: return 143;
199     /* Removed CSSPropertyTextUnderline - 144 */
200     case CSSPropertyTextUnderlineColor: return 145;
201     case CSSPropertyTextUnderlineMode: return 146;
202     case CSSPropertyTextUnderlineStyle: return 147;
203     case CSSPropertyTextUnderlineWidth: return 148;
204     case CSSPropertyTop: return 149;
205     case CSSPropertyTransition: return 150;
206     case CSSPropertyTransitionDelay: return 151;
207     case CSSPropertyTransitionDuration: return 152;
208     case CSSPropertyTransitionProperty: return 153;
209     case CSSPropertyTransitionTimingFunction: return 154;
210     case CSSPropertyUnicodeBidi: return 155;
211     case CSSPropertyUnicodeRange: return 156;
212     case CSSPropertyVerticalAlign: return 157;
213     case CSSPropertyVisibility: return 158;
214     case CSSPropertyWhiteSpace: return 159;
215     case CSSPropertyWidows: return 160;
216     case CSSPropertyWidth: return 161;
217     case CSSPropertyWordBreak: return 162;
218     case CSSPropertyWordSpacing: return 163;
219     case CSSPropertyWordWrap: return 164;
220     case CSSPropertyZIndex: return 165;
221     case CSSPropertyWebkitAnimation: return 166;
222     case CSSPropertyWebkitAnimationDelay: return 167;
223     case CSSPropertyWebkitAnimationDirection: return 168;
224     case CSSPropertyWebkitAnimationDuration: return 169;
225     case CSSPropertyWebkitAnimationFillMode: return 170;
226     case CSSPropertyWebkitAnimationIterationCount: return 171;
227     case CSSPropertyWebkitAnimationName: return 172;
228     case CSSPropertyWebkitAnimationPlayState: return 173;
229     case CSSPropertyWebkitAnimationTimingFunction: return 174;
230     case CSSPropertyWebkitAppearance: return 175;
231     case CSSPropertyWebkitAspectRatio: return 176;
232     case CSSPropertyWebkitBackfaceVisibility: return 177;
233     case CSSPropertyWebkitBackgroundClip: return 178;
234     case CSSPropertyWebkitBackgroundComposite: return 179;
235     case CSSPropertyWebkitBackgroundOrigin: return 180;
236     case CSSPropertyWebkitBackgroundSize: return 181;
237     case CSSPropertyWebkitBorderAfter: return 182;
238     case CSSPropertyWebkitBorderAfterColor: return 183;
239     case CSSPropertyWebkitBorderAfterStyle: return 184;
240     case CSSPropertyWebkitBorderAfterWidth: return 185;
241     case CSSPropertyWebkitBorderBefore: return 186;
242     case CSSPropertyWebkitBorderBeforeColor: return 187;
243     case CSSPropertyWebkitBorderBeforeStyle: return 188;
244     case CSSPropertyWebkitBorderBeforeWidth: return 189;
245     case CSSPropertyWebkitBorderEnd: return 190;
246     case CSSPropertyWebkitBorderEndColor: return 191;
247     case CSSPropertyWebkitBorderEndStyle: return 192;
248     case CSSPropertyWebkitBorderEndWidth: return 193;
249     case CSSPropertyWebkitBorderFit: return 194;
250     case CSSPropertyWebkitBorderHorizontalSpacing: return 195;
251     case CSSPropertyWebkitBorderImage: return 196;
252     case CSSPropertyWebkitBorderRadius: return 197;
253     case CSSPropertyWebkitBorderStart: return 198;
254     case CSSPropertyWebkitBorderStartColor: return 199;
255     case CSSPropertyWebkitBorderStartStyle: return 200;
256     case CSSPropertyWebkitBorderStartWidth: return 201;
257     case CSSPropertyWebkitBorderVerticalSpacing: return 202;
258     case CSSPropertyWebkitBoxAlign: return 203;
259     case CSSPropertyWebkitBoxDirection: return 204;
260     case CSSPropertyWebkitBoxFlex: return 205;
261     case CSSPropertyWebkitBoxFlexGroup: return 206;
262     case CSSPropertyWebkitBoxLines: return 207;
263     case CSSPropertyWebkitBoxOrdinalGroup: return 208;
264     case CSSPropertyWebkitBoxOrient: return 209;
265     case CSSPropertyWebkitBoxPack: return 210;
266     case CSSPropertyWebkitBoxReflect: return 211;
267     case CSSPropertyWebkitBoxShadow: return 212;
268     // CSSPropertyWebkitColumnAxis was 214
269     case CSSPropertyWebkitColumnBreakAfter: return 215;
270     case CSSPropertyWebkitColumnBreakBefore: return 216;
271     case CSSPropertyWebkitColumnBreakInside: return 217;
272     case CSSPropertyWebkitColumnCount: return 218;
273     case CSSPropertyWebkitColumnGap: return 219;
274     // CSSPropertyWebkitColumnProgression was 220
275     case CSSPropertyWebkitColumnRule: return 221;
276     case CSSPropertyWebkitColumnRuleColor: return 222;
277     case CSSPropertyWebkitColumnRuleStyle: return 223;
278     case CSSPropertyWebkitColumnRuleWidth: return 224;
279     case CSSPropertyWebkitColumnSpan: return 225;
280     case CSSPropertyWebkitColumnWidth: return 226;
281     case CSSPropertyWebkitColumns: return 227;
282 #if defined(ENABLE_CSS_BOX_DECORATION_BREAK) && ENABLE_CSS_BOX_DECORATION_BREAK
283     case CSSPropertyWebkitBoxDecorationBreak: return 228;
284 #endif
285 #if defined(ENABLE_CSS_FILTERS) && ENABLE_CSS_FILTERS
286     case CSSPropertyWebkitFilter: return 229;
287 #endif
288     case CSSPropertyAlignContent: return 230;
289     case CSSPropertyAlignItems: return 231;
290     case CSSPropertyAlignSelf: return 232;
291     case CSSPropertyFlex: return 233;
292     case CSSPropertyFlexBasis: return 234;
293     case CSSPropertyFlexDirection: return 235;
294     case CSSPropertyFlexFlow: return 236;
295     case CSSPropertyFlexGrow: return 237;
296     case CSSPropertyFlexShrink: return 238;
297     case CSSPropertyFlexWrap: return 239;
298     case CSSPropertyJustifyContent: return 240;
299     case CSSPropertyWebkitFontSizeDelta: return 241;
300     case CSSPropertyGridTemplateColumns: return 242;
301     case CSSPropertyGridTemplateRows: return 243;
302     case CSSPropertyGridColumnStart: return 244;
303     case CSSPropertyGridColumnEnd: return 245;
304     case CSSPropertyGridRowStart: return 246;
305     case CSSPropertyGridRowEnd: return 247;
306     case CSSPropertyGridColumn: return 248;
307     case CSSPropertyGridRow: return 249;
308     case CSSPropertyGridAutoFlow: return 250;
309     case CSSPropertyWebkitHighlight: return 251;
310     case CSSPropertyWebkitHyphenateCharacter: return 252;
311     case CSSPropertyWebkitLineBoxContain: return 257;
312     // case CSSPropertyWebkitLineAlign: return 258;
313     case CSSPropertyWebkitLineBreak: return 259;
314     case CSSPropertyWebkitLineClamp: return 260;
315     // case CSSPropertyWebkitLineGrid: return 261;
316     // case CSSPropertyWebkitLineSnap: return 262;
317     case CSSPropertyWebkitLogicalWidth: return 263;
318     case CSSPropertyWebkitLogicalHeight: return 264;
319     case CSSPropertyWebkitMarginAfterCollapse: return 265;
320     case CSSPropertyWebkitMarginBeforeCollapse: return 266;
321     case CSSPropertyWebkitMarginBottomCollapse: return 267;
322     case CSSPropertyWebkitMarginTopCollapse: return 268;
323     case CSSPropertyWebkitMarginCollapse: return 269;
324     case CSSPropertyWebkitMarginAfter: return 270;
325     case CSSPropertyWebkitMarginBefore: return 271;
326     case CSSPropertyWebkitMarginEnd: return 272;
327     case CSSPropertyWebkitMarginStart: return 273;
328     // CSSPropertyWebkitMarquee was 274.
329     // CSSPropertyInternalMarquee* were 275-279.
330     case CSSPropertyWebkitMask: return 280;
331     case CSSPropertyWebkitMaskBoxImage: return 281;
332     case CSSPropertyWebkitMaskBoxImageOutset: return 282;
333     case CSSPropertyWebkitMaskBoxImageRepeat: return 283;
334     case CSSPropertyWebkitMaskBoxImageSlice: return 284;
335     case CSSPropertyWebkitMaskBoxImageSource: return 285;
336     case CSSPropertyWebkitMaskBoxImageWidth: return 286;
337     case CSSPropertyWebkitMaskClip: return 287;
338     case CSSPropertyWebkitMaskComposite: return 288;
339     case CSSPropertyWebkitMaskImage: return 289;
340     case CSSPropertyWebkitMaskOrigin: return 290;
341     case CSSPropertyWebkitMaskPosition: return 291;
342     case CSSPropertyWebkitMaskPositionX: return 292;
343     case CSSPropertyWebkitMaskPositionY: return 293;
344     case CSSPropertyWebkitMaskRepeat: return 294;
345     case CSSPropertyWebkitMaskRepeatX: return 295;
346     case CSSPropertyWebkitMaskRepeatY: return 296;
347     case CSSPropertyWebkitMaskSize: return 297;
348     case CSSPropertyWebkitMaxLogicalWidth: return 298;
349     case CSSPropertyWebkitMaxLogicalHeight: return 299;
350     case CSSPropertyWebkitMinLogicalWidth: return 300;
351     case CSSPropertyWebkitMinLogicalHeight: return 301;
352     // WebkitNbspMode has been deleted, was return 302;
353     case CSSPropertyOrder: return 303;
354     case CSSPropertyWebkitPaddingAfter: return 304;
355     case CSSPropertyWebkitPaddingBefore: return 305;
356     case CSSPropertyWebkitPaddingEnd: return 306;
357     case CSSPropertyWebkitPaddingStart: return 307;
358     case CSSPropertyWebkitPerspective: return 308;
359     case CSSPropertyWebkitPerspectiveOrigin: return 309;
360     case CSSPropertyWebkitPerspectiveOriginX: return 310;
361     case CSSPropertyWebkitPerspectiveOriginY: return 311;
362     case CSSPropertyWebkitPrintColorAdjust: return 312;
363     case CSSPropertyWebkitRtlOrdering: return 313;
364     case CSSPropertyWebkitRubyPosition: return 314;
365     case CSSPropertyWebkitTextCombine: return 315;
366     case CSSPropertyWebkitTextDecorationsInEffect: return 316;
367     case CSSPropertyWebkitTextEmphasis: return 317;
368     case CSSPropertyWebkitTextEmphasisColor: return 318;
369     case CSSPropertyWebkitTextEmphasisPosition: return 319;
370     case CSSPropertyWebkitTextEmphasisStyle: return 320;
371     case CSSPropertyWebkitTextFillColor: return 321;
372     case CSSPropertyWebkitTextSecurity: return 322;
373     case CSSPropertyWebkitTextStroke: return 323;
374     case CSSPropertyWebkitTextStrokeColor: return 324;
375     case CSSPropertyWebkitTextStrokeWidth: return 325;
376     case CSSPropertyWebkitTransform: return 326;
377     case CSSPropertyWebkitTransformOrigin: return 327;
378     case CSSPropertyWebkitTransformOriginX: return 328;
379     case CSSPropertyWebkitTransformOriginY: return 329;
380     case CSSPropertyWebkitTransformOriginZ: return 330;
381     case CSSPropertyWebkitTransformStyle: return 331;
382     case CSSPropertyWebkitTransition: return 332;
383     case CSSPropertyWebkitTransitionDelay: return 333;
384     case CSSPropertyWebkitTransitionDuration: return 334;
385     case CSSPropertyWebkitTransitionProperty: return 335;
386     case CSSPropertyWebkitTransitionTimingFunction: return 336;
387     case CSSPropertyWebkitUserDrag: return 337;
388     case CSSPropertyWebkitUserModify: return 338;
389     case CSSPropertyWebkitUserSelect: return 339;
390     // case CSSPropertyWebkitFlowInto: return 340;
391     // case CSSPropertyWebkitFlowFrom: return 341;
392     // case CSSPropertyWebkitRegionFragment: return 342;
393     // case CSSPropertyWebkitRegionBreakAfter: return 343;
394     // case CSSPropertyWebkitRegionBreakBefore: return 344;
395     // case CSSPropertyWebkitRegionBreakInside: return 345;
396     // case CSSPropertyShapeInside: return 346;
397     case CSSPropertyShapeOutside: return 347;
398     case CSSPropertyShapeMargin: return 348;
399     // case CSSPropertyShapePadding: return 349;
400     case CSSPropertyWebkitWrapFlow: return 350;
401     case CSSPropertyWebkitWrapThrough: return 351;
402     // CSSPropertyWebkitWrap was 352.
403 #if defined(ENABLE_TOUCH_EVENTS) && ENABLE_TOUCH_EVENTS
404     case CSSPropertyWebkitTapHighlightColor: return 353;
405 #endif
406 #if defined(ENABLE_DRAGGABLE_REGION) && ENABLE_DRAGGABLE_REGION
407     case CSSPropertyWebkitAppRegion: return 354;
408 #endif
409     case CSSPropertyClipPath: return 355;
410     case CSSPropertyClipRule: return 356;
411     case CSSPropertyMask: return 357;
412     case CSSPropertyEnableBackground: return 358;
413     case CSSPropertyFilter: return 359;
414     case CSSPropertyFloodColor: return 360;
415     case CSSPropertyFloodOpacity: return 361;
416     case CSSPropertyLightingColor: return 362;
417     case CSSPropertyStopColor: return 363;
418     case CSSPropertyStopOpacity: return 364;
419     case CSSPropertyColorInterpolation: return 365;
420     case CSSPropertyColorInterpolationFilters: return 366;
421     // case CSSPropertyColorProfile: return 367;
422     case CSSPropertyColorRendering: return 368;
423     case CSSPropertyFill: return 369;
424     case CSSPropertyFillOpacity: return 370;
425     case CSSPropertyFillRule: return 371;
426     case CSSPropertyMarker: return 372;
427     case CSSPropertyMarkerEnd: return 373;
428     case CSSPropertyMarkerMid: return 374;
429     case CSSPropertyMarkerStart: return 375;
430     case CSSPropertyMaskType: return 376;
431     case CSSPropertyShapeRendering: return 377;
432     case CSSPropertyStroke: return 378;
433     case CSSPropertyStrokeDasharray: return 379;
434     case CSSPropertyStrokeDashoffset: return 380;
435     case CSSPropertyStrokeLinecap: return 381;
436     case CSSPropertyStrokeLinejoin: return 382;
437     case CSSPropertyStrokeMiterlimit: return 383;
438     case CSSPropertyStrokeOpacity: return 384;
439     case CSSPropertyStrokeWidth: return 385;
440     case CSSPropertyAlignmentBaseline: return 386;
441     case CSSPropertyBaselineShift: return 387;
442     case CSSPropertyDominantBaseline: return 388;
443     case CSSPropertyGlyphOrientationHorizontal: return 389;
444     case CSSPropertyGlyphOrientationVertical: return 390;
445     // CSSPropertyKerning has been removed, was return 391;
446     case CSSPropertyTextAnchor: return 392;
447     case CSSPropertyVectorEffect: return 393;
448     case CSSPropertyWritingMode: return 394;
449     // CSSPropertyWebkitSvgShadow has been removed, was return 395;
450 #if defined(ENABLE_CURSOR_VISIBILITY) && ENABLE_CURSOR_VISIBILITY
451     case CSSPropertyWebkitCursorVisibility: return 396;
452 #endif
453     // CSSPropertyImageOrientation has been removed, was return 397;
454     // CSSPropertyImageResolution has been removed, was return 398;
455 #if defined(ENABLE_CSS_COMPOSITING) && ENABLE_CSS_COMPOSITING
456     case CSSPropertyWebkitBlendMode: return 399;
457     case CSSPropertyWebkitBackgroundBlendMode: return 400;
458 #endif
459     case CSSPropertyTextDecorationLine: return 401;
460     case CSSPropertyTextDecorationStyle: return 402;
461     case CSSPropertyTextDecorationColor: return 403;
462     case CSSPropertyTextAlignLast: return 404;
463     case CSSPropertyTextUnderlinePosition: return 405;
464     case CSSPropertyMaxZoom: return 406;
465     case CSSPropertyMinZoom: return 407;
466     case CSSPropertyOrientation: return 408;
467     case CSSPropertyUserZoom: return 409;
468     // CSSPropertyWebkitDashboardRegion was 410.
469     // CSSPropertyWebkitOverflowScrolling was 411.
470     case CSSPropertyWebkitAppRegion: return 412;
471     case CSSPropertyWebkitFilter: return 413;
472     case CSSPropertyWebkitBoxDecorationBreak: return 414;
473     case CSSPropertyWebkitTapHighlightColor: return 415;
474     case CSSPropertyBufferedRendering: return 416;
475     case CSSPropertyGridAutoRows: return 417;
476     case CSSPropertyGridAutoColumns: return 418;
477     case CSSPropertyBackgroundBlendMode: return 419;
478     case CSSPropertyMixBlendMode: return 420;
479     case CSSPropertyTouchAction: return 421;
480     case CSSPropertyGridArea: return 422;
481     case CSSPropertyGridTemplateAreas: return 423;
482     case CSSPropertyAnimation: return 424;
483     case CSSPropertyAnimationDelay: return 425;
484     case CSSPropertyAnimationDirection: return 426;
485     case CSSPropertyAnimationDuration: return 427;
486     case CSSPropertyAnimationFillMode: return 428;
487     case CSSPropertyAnimationIterationCount: return 429;
488     case CSSPropertyAnimationName: return 430;
489     case CSSPropertyAnimationPlayState: return 431;
490     case CSSPropertyAnimationTimingFunction: return 432;
491     case CSSPropertyObjectFit: return 433;
492     case CSSPropertyPaintOrder: return 434;
493     case CSSPropertyMaskSourceType: return 435;
494     case CSSPropertyIsolation: return 436;
495     case CSSPropertyObjectPosition: return 437;
496     case CSSPropertyInternalCallback: return 438;
497     case CSSPropertyShapeImageThreshold: return 439;
498     case CSSPropertyColumnFill: return 440;
499     case CSSPropertyTextJustify: return 441;
500     case CSSPropertyTouchActionDelay: return 442;
501     case CSSPropertyJustifySelf: return 443;
502     case CSSPropertyScrollBehavior: return 444;
503     case CSSPropertyWillChange: return 445;
504     case CSSPropertyTransform: return 446;
505     case CSSPropertyTransformOrigin: return 447;
506     case CSSPropertyTransformStyle: return 448;
507     case CSSPropertyPerspective: return 449;
508     case CSSPropertyPerspectiveOrigin: return 450;
509     case CSSPropertyBackfaceVisibility: return 451;
510     case CSSPropertyGridTemplate: return 452;
511     case CSSPropertyGrid: return 453;
512
513     // Add new features above this line (don't change the assigned numbers of the existing
514     // items) and update maximumCSSSampleId() with the new maximum value.
515
516     // Internal properties should not be counted.
517     case CSSPropertyInternalMarqueeDirection:
518     case CSSPropertyInternalMarqueeIncrement:
519     case CSSPropertyInternalMarqueeRepetition:
520     case CSSPropertyInternalMarqueeSpeed:
521     case CSSPropertyInternalMarqueeStyle:
522     case CSSPropertyInvalid:
523         ASSERT_NOT_REACHED();
524         return 0;
525     }
526
527     ASSERT_NOT_REACHED();
528     return 0;
529 }
530
531 static int maximumCSSSampleId() { return 453; }
532
533 void UseCounter::muteForInspector()
534 {
535     UseCounter::m_muteCount++;
536 }
537
538 void UseCounter::unmuteForInspector()
539 {
540     UseCounter::m_muteCount--;
541 }
542
543 UseCounter::UseCounter()
544 {
545     m_CSSFeatureBits.ensureSize(lastCSSProperty + 1);
546     m_CSSFeatureBits.clearAll();
547 }
548
549 UseCounter::~UseCounter()
550 {
551     // We always log PageDestruction so that we have a scale for the rest of the features.
552     blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserver", PageDestruction, NumberOfFeatures);
553
554     updateMeasurements();
555 }
556
557 void UseCounter::updateMeasurements()
558 {
559     blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserver", PageVisits, NumberOfFeatures);
560
561     if (m_countBits) {
562         for (unsigned i = 0; i < NumberOfFeatures; ++i) {
563             if (m_countBits->quickGet(i))
564                 blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserver", i, NumberOfFeatures);
565         }
566         // Clearing count bits is timing sensitive.
567         m_countBits->clearAll();
568     }
569
570     // FIXME: Sometimes this function is called more than once per page. The following
571     //        bool guards against incrementing the page count when there are no CSS
572     //        bits set. http://crbug.com/236262.
573     bool needsPagesMeasuredUpdate = false;
574     for (int i = firstCSSProperty; i <= lastCSSProperty; ++i) {
575         if (m_CSSFeatureBits.quickGet(i)) {
576             int cssSampleId = mapCSSPropertyIdToCSSSampleIdForHistogram(i);
577             blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserver.CSSProperties", cssSampleId, maximumCSSSampleId());
578             needsPagesMeasuredUpdate = true;
579         }
580     }
581
582     if (needsPagesMeasuredUpdate)
583         blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserver.CSSProperties", totalPagesMeasuredCSSSampleId(), maximumCSSSampleId());
584
585     m_CSSFeatureBits.clearAll();
586 }
587
588 void UseCounter::didCommitLoad()
589 {
590     updateMeasurements();
591 }
592
593 void UseCounter::count(const Document& document, Feature feature)
594 {
595     FrameHost* host = document.frameHost();
596     if (!host)
597         return;
598
599     ASSERT(host->useCounter().deprecationMessage(feature).isEmpty());
600     host->useCounter().recordMeasurement(feature);
601 }
602
603 void UseCounter::count(const ExecutionContext* context, Feature feature)
604 {
605     if (!context || !context->isDocument())
606         return;
607     count(*toDocument(context), feature);
608 }
609
610 void UseCounter::countDeprecation(ExecutionContext* context, Feature feature)
611 {
612     if (!context || !context->isDocument())
613         return;
614     UseCounter::countDeprecation(*toDocument(context), feature);
615 }
616
617 void UseCounter::countDeprecation(const DOMWindow* window, Feature feature)
618 {
619     if (!window || !window->document())
620         return;
621     UseCounter::countDeprecation(*window->document(), feature);
622 }
623
624 void UseCounter::countDeprecation(const Document& document, Feature feature)
625 {
626     FrameHost* host = document.frameHost();
627     LocalFrame* frame = document.frame();
628     if (!host || !frame)
629         return;
630
631     if (host->useCounter().recordMeasurement(feature)) {
632         ASSERT(!host->useCounter().deprecationMessage(feature).isEmpty());
633         frame->console().addMessage(DeprecationMessageSource, WarningMessageLevel, host->useCounter().deprecationMessage(feature));
634     }
635 }
636
637 String UseCounter::deprecationMessage(Feature feature)
638 {
639     switch (feature) {
640     // Quota
641     case PrefixedStorageInfo:
642         return "'window.webkitStorageInfo' is deprecated. Please use 'navigator.webkitTemporaryStorage' or 'navigator.webkitPersistentStorage' instead.";
643
644     // HTML Media Capture
645     case CaptureAttributeAsEnum:
646         return "Using the 'capture' attribute as an enum is deprecated. Please use it as a boolean and specify the media types that should be accepted in the 'accept' attribute.";
647
648     // Keyboard Event (DOM Level 3)
649     case KeyboardEventKeyLocation:
650         return "'KeyboardEvent.keyLocation' is deprecated. Please use 'KeyboardEvent.location' instead.";
651
652     case ConsoleMarkTimeline:
653         return "console.markTimeline is deprecated. Please use the console.timeStamp instead.";
654
655     case FileError:
656         return "FileError is deprecated. Please use the 'name' or 'message' attributes of DOMError rather than 'code'.";
657
658     case ShowModalDialog:
659         return "showModalDialog is deprecated. Please use window.open and postMessage instead.";
660
661     case CSSStyleSheetInsertRuleOptionalArg:
662         return "Calling CSSStyleSheet.insertRule() with one argument is deprecated. Please pass the index argument as well: insertRule(x, 0).";
663
664     case PrefixedVideoSupportsFullscreen:
665         return "'HTMLVideoElement.webkitSupportsFullscreen' is deprecated. Its value is true if the video is loaded.";
666
667     case PrefixedVideoDisplayingFullscreen:
668         return "'HTMLVideoElement.webkitDisplayingFullscreen' is deprecated. Please use the 'fullscreenchange' and 'webkitfullscreenchange' events instead.";
669
670     case PrefixedVideoEnterFullscreen:
671         return "'HTMLVideoElement.webkitEnterFullscreen()' is deprecated. Please use 'Element.requestFullscreen()' and 'Element.webkitRequestFullscreen()' instead.";
672
673     case PrefixedVideoExitFullscreen:
674         return "'HTMLVideoElement.webkitExitFullscreen()' is deprecated. Please use 'Document.exitFullscreen()' and 'Document.webkitExitFullscreen()' instead.";
675
676     case PrefixedVideoEnterFullScreen:
677         return "'HTMLVideoElement.webkitEnterFullScreen()' is deprecated. Please use 'Element.requestFullscreen()' and 'Element.webkitRequestFullscreen()' instead.";
678
679     case PrefixedVideoExitFullScreen:
680         return "'HTMLVideoElement.webkitExitFullScreen()' is deprecated. Please use 'Document.exitFullscreen()' and 'Document.webkitExitFullscreen()' instead.";
681
682     case MediaErrorEncrypted:
683         return "'MediaError.MEDIA_ERR_ENCRYPTED' is deprecated. This error code is never used.";
684
685     case PrefixedGamepad:
686         return "'navigator.webkitGetGamepads' is deprecated. Please use 'navigator.getGamepads' instead.";
687
688     case PrefixedRequestAnimationFrame:
689         return "'webkitRequestAnimationFrame' is vendor-specific. Please use the standard 'requestAnimationFrame' instead.";
690
691     case PrefixedCancelAnimationFrame:
692         return "'webkitCancelAnimationFrame' is vendor-specific. Please use the standard 'cancelAnimationFrame' instead.";
693
694     case PrefixedCancelRequestAnimationFrame:
695         return "'webkitCancelRequestAnimationFrame' is vendor-specific. Please use the standard 'cancelAnimationFrame' instead.";
696
697     case HTMLHtmlElementManifest:
698         return "'HTMLHtmlElement.manifest' is deprecated. The manifest attribute only has an effect during the early stages of document load.";
699
700     case DocumentCreateAttributeNS:
701         return "'Document.createAttributeNS' is deprecated and has been removed from DOM4 (http://w3.org/tr/dom).";
702
703     case AttributeOwnerElement:
704         return "'Attr.ownerElement' is deprecated and has been removed from DOM4 (http://w3.org/tr/dom).";
705
706     case ElementSetAttributeNodeNS:
707         return "'Element.setAttributeNodeNS' is deprecated and has been removed from DOM4 (http://w3.org/tr/dom).";
708
709     case NodeIteratorDetach:
710         return "'NodeIterator.detach' is now a no-op, as per DOM (http://dom.spec.whatwg.org/#dom-nodeiterator-detach).";
711
712     case AttrNodeValue:
713         return "'Attr.nodeValue' is deprecated. Please use 'value' instead.";
714
715     case AttrTextContent:
716         return "'Attr.textContent' is deprecated. Please use 'value' instead.";
717
718     case NodeIteratorExpandEntityReferences:
719         return "'NodeIterator.expandEntityReferences' is deprecated and has been removed from DOM. It always returns false.";
720
721     case TreeWalkerExpandEntityReferences:
722         return "'TreeWalker.expandEntityReferences' is deprecated and has been removed from DOM. It always returns false.";
723
724     case RangeDetach:
725         return "'Range.detach' is now a no-op, as per DOM (http://dom.spec.whatwg.org/#dom-range-detach).";
726
727     case DocumentImportNodeOptionalArgument:
728         return "The behavior of importNode() with no boolean argument is about to change from doing a deep clone to doing a shallow clone.  "
729             "Make sure to pass an explicit boolean argument to keep your current behavior.";
730
731     // Features that aren't deprecated don't have a deprecation message.
732     default:
733         return String();
734     }
735 }
736
737 void UseCounter::count(CSSParserContext context, CSSPropertyID feature)
738 {
739     ASSERT(feature >= firstCSSProperty);
740     ASSERT(feature <= lastCSSProperty);
741     ASSERT(!isInternalProperty(feature));
742
743     if (!isUseCounterEnabledForMode(context.mode()))
744         return;
745
746     m_CSSFeatureBits.quickSet(feature);
747 }
748
749 void UseCounter::count(Feature feature)
750 {
751     ASSERT(deprecationMessage(feature).isEmpty());
752     recordMeasurement(feature);
753 }
754
755 UseCounter* UseCounter::getFrom(const Document* document)
756 {
757     if (document && document->frameHost())
758         return &document->frameHost()->useCounter();
759     return 0;
760 }
761
762 UseCounter* UseCounter::getFrom(const CSSStyleSheet* sheet)
763 {
764     if (sheet)
765         return getFrom(sheet->contents());
766     return 0;
767 }
768
769 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents)
770 {
771     // FIXME: We may want to handle stylesheets that have multiple owners
772     //        http://crbug.com/242125
773     if (sheetContents && sheetContents->hasSingleOwnerNode())
774         return getFrom(sheetContents->singleOwnerDocument());
775     return 0;
776 }
777
778 } // namespace WebCore