Home | History | Annotate | Download | only in frame
      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 ExecutionContext;
     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         UnusedSlot04,
    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         UnusedSlot05, // Removed, was document.webkitRegister
    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         DocumentTypeEntities, // Removed from DOM4.
    167         DocumentTypeInternalSubset, // Removed from DOM4.
    168         DocumentTypeNotations, // Removed from DOM4.
    169         ElementGetAttributeNode, // Removed from DOM4.
    170         ElementSetAttributeNode, // Removed from DOM4.
    171         ElementRemoveAttributeNode, // Removed from DOM4.
    172         ElementGetAttributeNodeNS, // Removed from DOM4.
    173         DocumentCreateAttribute, // Removed from DOM4.
    174         DocumentCreateAttributeNS, // Removed from DOM4.
    175         DocumentCreateCDATASection, // Removed from DOM4.
    176         DocumentInputEncoding, // Removed from DOM4.
    177         DocumentXMLEncoding, // Removed from DOM4.
    178         DocumentXMLStandalone, // Removed from DOM4.
    179         DocumentXMLVersion, // Removed from DOM4.
    180         NodeIsSameNode, // Removed from DOM4.
    181         NodeIsSupported, // Removed from DOM4.
    182         NodeNamespaceURI, // Removed from DOM4.
    183         NodePrefix, // Removed from DOM4.
    184         NodeLocalName, // Removed from DOM4.
    185         NavigatorProductSub,
    186         NavigatorVendor,
    187         NavigatorVendorSub,
    188         FileError,
    189         DocumentCharset, // Documented as IE extensions, from KHTML days.
    190         PrefixedAnimationEndEvent,
    191         UnprefixedAnimationEndEvent,
    192         PrefixedAndUnprefixedAnimationEndEvent,
    193         PrefixedAnimationStartEvent,
    194         UnprefixedAnimationStartEvent,
    195         PrefixedAndUnprefixedAnimationStartEvent,
    196         PrefixedAnimationIterationEvent,
    197         UnprefixedAnimationIterationEvent,
    198         PrefixedAndUnprefixedAnimationIterationEvent,
    199         EventReturnValue, // Legacy IE extension.
    200         SVGSVGElement,
    201         SVGAnimateColorElement,
    202         InsertAdjacentText,
    203         InsertAdjacentElement,
    204         HasAttributes, // Removed from DOM4.
    205         DOMSubtreeModifiedEvent,
    206         DOMNodeInsertedEvent,
    207         DOMNodeRemovedEvent,
    208         DOMNodeRemovedFromDocumentEvent,
    209         DOMNodeInsertedIntoDocumentEvent,
    210         DOMCharacterDataModifiedEvent,
    211         DocumentAllTags,
    212         DocumentAllLegacyCall,
    213         HTMLAppletElementLegacyCall,
    214         HTMLEmbedElementLegacyCall,
    215         HTMLObjectElementLegacyCall,
    216         BeforeLoadEvent,
    217         GetMatchedCSSRules,
    218         SVGFontInCSS,
    219         ScrollTopBodyNotQuirksMode,
    220         ScrollLeftBodyNotQuirksMode,
    221         AttributeIsId, // Removed in DOM4.
    222         AttributeOwnerElement, // Removed in DOM4.
    223         AttributeSetPrefix, // Attribute prefix is readonly in DOM4.
    224         AttributeSpecified, // Removed in DOM4.
    225         BeforeLoadEventInIsolatedWorld,
    226         PrefixedAudioDecodedByteCount,
    227         PrefixedVideoDecodedByteCount,
    228         PrefixedVideoSupportsFullscreen,
    229         PrefixedVideoDisplayingFullscreen,
    230         PrefixedVideoEnterFullscreen,
    231         PrefixedVideoExitFullscreen,
    232         PrefixedVideoEnterFullScreen,
    233         PrefixedVideoExitFullScreen,
    234         PrefixedVideoDecodedFrameCount,
    235         PrefixedVideoDroppedFrameCount,
    236         SourceElementCandidate,
    237         SourceElementNonMatchingMedia,
    238         PrefixedElementRequestFullscreen,
    239         PrefixedElementRequestFullScreen,
    240         BarPropLocationbar,
    241         BarPropMenubar,
    242         BarPropPersonalbar,
    243         BarPropScrollbars,
    244         BarPropStatusbar,
    245         BarPropToolbar,
    246         InputTypeEmailMultiple,
    247         InputTypeEmailMaxLength,
    248         InputTypeEmailMultipleMaxLength,
    249         TextTrackCueConstructor,
    250         CSSStyleDeclarationPropertyName, // Removed in CSSOM.
    251         CSSStyleDeclarationFloatPropertyName, // Pending removal in CSSOM.
    252         InputTypeText,
    253         InputTypeTextMaxLength,
    254         InputTypePassword,
    255         InputTypePasswordMaxLength,
    256         SVGInstanceRoot,
    257         ShowModalDialog,
    258         PrefixedPageVisibility,
    259         HTMLFrameElementLocation,
    260         CSSStyleSheetInsertRuleOptionalArg, // Inconsistent with the specification and other browsers.
    261         CSSWebkitRegionAtRule, // @region rule changed to ::region()
    262         DocumentBeforeUnloadRegistered,
    263         DocumentBeforeUnloadFired,
    264         DocumentUnloadRegistered,
    265         DocumentUnloadFired,
    266         SVGLocatableNearestViewportElement,
    267         SVGLocatableFarthestViewportElement,
    268         IsIndexElement,
    269         HTMLHeadElementProfile,
    270         OverflowChangedEvent,
    271         SVGPointMatrixTransform,
    272         HTMLHtmlElementManifest,
    273         DOMFocusInOutEvent,
    274         FileGetLastModifiedDate,
    275         HTMLElementInnerText,
    276         HTMLElementOuterText,
    277         ReplaceDocumentViaJavaScriptURL,
    278         ElementSetAttributeNodeNS, // Removed from DOM4.
    279         ElementPrefixedMatchesSelector,
    280         DOMImplementationCreateCSSStyleSheet,
    281         CSSStyleSheetRules,
    282         CSSStyleSheetAddRule,
    283         CSSStyleSheetRemoveRule,
    284         // Add new features immediately above this line. Don't change assigned
    285         // numbers of each items, and don't reuse unused slots.
    286         NumberOfFeatures, // This enum value must be last.
    287     };
    288 
    289     // "count" sets the bit for this feature to 1. Repeated calls are ignored.
    290     static void count(const Document&, Feature);
    291     static void count(const DOMWindow*, Feature);
    292     void count(CSSParserContext, CSSPropertyID);
    293     void count(Feature);
    294 
    295     // "countDeprecation" sets the bit for this feature to 1, and sends a deprecation
    296     // warning to the console. Repeated calls are ignored.
    297     //
    298     // Be considerate to developers' consoles: features should only send deprecation warnings
    299     // when we're actively interested in removing them from the platform.
    300     static void countDeprecation(const DOMWindow*, Feature);
    301     static void countDeprecation(ExecutionContext*, Feature);
    302     static void countDeprecation(const Document&, Feature);
    303     String deprecationMessage(Feature);
    304 
    305     void didCommitLoad();
    306 
    307     static UseCounter* getFrom(const Document*);
    308     static UseCounter* getFrom(const CSSStyleSheet*);
    309     static UseCounter* getFrom(const StyleSheetContents*);
    310 
    311     static int mapCSSPropertyIdToCSSSampleIdForHistogram(int id);
    312 
    313 private:
    314     bool recordMeasurement(Feature feature)
    315     {
    316         ASSERT(feature != PageDestruction); // PageDestruction is reserved as a scaling factor.
    317         ASSERT(feature < NumberOfFeatures);
    318         if (!m_countBits) {
    319             m_countBits = adoptPtr(new BitVector(NumberOfFeatures));
    320             m_countBits->clearAll();
    321         }
    322 
    323         if (m_countBits->quickGet(feature))
    324             return false;
    325 
    326         m_countBits->quickSet(feature);
    327         return true;
    328     }
    329 
    330     void updateMeasurements();
    331 
    332     OwnPtr<BitVector> m_countBits;
    333     BitVector m_CSSFeatureBits;
    334 };
    335 
    336 } // namespace WebCore
    337 
    338 #endif // UseCounter_h
    339