033f964c18530b83d8116e86e9c07c742d3b9ec5
[WebKit-https.git] / Source / WebCore / page / FeatureObserver.h
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
34 namespace WebCore {
35
36 class DOMWindow;
37 class Document;
38
39 class FeatureObserver {
40     WTF_MAKE_NONCOPYABLE(FeatureObserver);
41 public:
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         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         // Add new features above this line. Don't change assigned numbers of each items.
108         NumberOfFeatures, // This enum value must be last.
109     };
110
111     static void observe(Document*, Feature);
112     static void observe(DOMWindow*, Feature);
113     void didCommitLoad();
114
115 private:
116     void didObserve(Feature feature)
117     {
118         ASSERT(feature != PageDestruction); // PageDestruction is reserved as a scaling factor.
119         ASSERT(feature < NumberOfFeatures);
120         if (!m_featureBits) {
121             m_featureBits = adoptPtr(new BitVector(NumberOfFeatures));
122             m_featureBits->clearAll();
123         }
124         m_featureBits->quickSet(feature);
125     }
126
127     void updateMeasurements();
128
129     OwnPtr<BitVector> m_featureBits;
130 };
131
132 } // namespace WebCore
133     
134 #endif // FeatureObserver_h