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 FeatureObserver_h
27#define FeatureObserver_h
28
29#include <wtf/BitVector.h>
30#include <wtf/Noncopyable.h>
31#include <wtf/OwnPtr.h>
32#include <wtf/PassOwnPtr.h>
33
34namespace WebCore {
35
36class DOMWindow;
37class Document;
38
39class FeatureObserver {
40    WTF_MAKE_NONCOPYABLE(FeatureObserver);
41public:
42    FeatureObserver();
43    ~FeatureObserver();
44
45    enum Feature {
46        PageDestruction,
47        LegacyNotifications,
48        MultipartMainResource,
49        PrefixedIndexedDB,
50        WorkerStart,
51        SharedWorkerStart,
52        LegacyWebAudio,
53        WebAudioStart,
54        PrefixedContentSecurityPolicy,
55        UnprefixedIndexedDB,
56        OpenWebDatabase,
57        UnusedSlot01, // We used this slot for LegacyHTMLNotifications.
58        LegacyTextNotifications,
59        UnprefixedRequestAnimationFrame,
60        PrefixedRequestAnimationFrame,
61        ContentSecurityPolicy,
62        ContentSecurityPolicyReportOnly,
63        PrefixedContentSecurityPolicyReportOnly,
64        PrefixedTransitionEndEvent,
65        UnprefixedTransitionEndEvent,
66        PrefixedAndUnprefixedTransitionEndEvent,
67        AutoFocusAttribute,
68        AutoSaveAttribute,
69        DataListElement,
70        FormAttribute,
71        IncrementalAttribute,
72        InputTypeColor,
73        InputTypeDate,
74        InputTypeDateTime,
75        InputTypeDateTimeFallback,
76        InputTypeDateTimeLocal,
77        InputTypeEmail,
78        InputTypeMonth,
79        InputTypeNumber,
80        InputTypeRange,
81        InputTypeSearch,
82        InputTypeTel,
83        InputTypeTime,
84        InputTypeURL,
85        InputTypeWeek,
86        InputTypeWeekFallback,
87        ListAttribute,
88        MaxAttribute,
89        MinAttribute,
90        PatternAttribute,
91        PlaceholderAttribute,
92        PrecisionAttribute,
93        PrefixedDirectoryAttribute,
94        PrefixedSpeechAttribute,
95        RequiredAttribute,
96        ResultsAttribute,
97        StepAttribute,
98        PageVisits,
99        HTMLMarqueeElement,
100        CSSOverflowMarquee,
101        Reflection,
102        CursorVisibility,
103        StorageInfo,
104        XFrameOptions,
105        XFrameOptionsSameOrigin,
106        XFrameOptionsSameOriginWithBadAncestorChain,
107        DeprecatedFlexboxWebContent,
108        DeprecatedFlexboxChrome,
109        DeprecatedFlexboxChromeExtension,
110        // Add new features above this line. Don't change assigned numbers of each items.
111        NumberOfFeatures, // This enum value must be last.
112    };
113
114    static void observe(Document*, Feature);
115    static void observe(DOMWindow*, Feature);
116    void didCommitLoad();
117
118    const BitVector* accumulatedFeatureBits() const { return m_featureBits.get(); }
119
120private:
121    void didObserve(Feature feature)
122    {
123        ASSERT(feature != PageDestruction); // PageDestruction is reserved as a scaling factor.
124        ASSERT(feature < NumberOfFeatures);
125        if (!m_featureBits) {
126            m_featureBits = adoptPtr(new BitVector(NumberOfFeatures));
127            m_featureBits->clearAll();
128        }
129        m_featureBits->quickSet(feature);
130    }
131
132    void updateMeasurements();
133
134    OwnPtr<BitVector> m_featureBits;
135};
136
137} // namespace WebCore
138
139#endif // FeatureObserver_h
140