OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Google, Inc. All rights reserved. | 2 * Copyright (C) 2013 Google, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "UseCounter.h" | 27 #include "DeprecationAgent.h" |
28 | 28 |
29 #include "DOMWindow.h" | |
30 #include "Document.h" | 29 #include "Document.h" |
31 #include "HistogramSupport.h" | |
32 #include "Page.h" | 30 #include "Page.h" |
31 #include "PageConsole.h" | |
32 #include <wtf/BitVector.h> | |
33 #include <wtf/Noncopyable.h> | |
34 #include <wtf/OwnPtr.h> | |
35 #include <wtf/PassOwnPtr.h> | |
36 #include <wtf/text/WTFString.h> | |
33 | 37 |
34 namespace WebCore { | 38 namespace WebCore { |
35 | 39 |
36 UseCounter::UseCounter() | 40 namespace { |
41 | |
42 // Ensure that this stays in sync with the Feature enum. | |
43 static const char* const deprecationMessages[] = { | |
44 "The 'X-WebKit-CSP' headers are deprecated; please consider using the canoni cal 'Content-Security-Policy' header instead." | |
45 }; | |
46 | |
47 // COMPILE_ASSERT(WTF_ARRAY_LENGTH(deprecationMessages) == static_cast<int>(WebC ore::DeprecationAgent::NumberOfFeatures), DeprecationMessages_matches_Feature_en um); | |
pfeldman
2013/04/19 13:04:22
It should work, right?
| |
48 | |
49 } | |
50 | |
51 DeprecationAgent::DeprecationAgent() | |
37 { | 52 { |
38 } | 53 } |
39 | 54 |
40 UseCounter::~UseCounter() | 55 DeprecationAgent::~DeprecationAgent() |
41 { | 56 { |
42 // We always log PageDestruction so that we have a scale for the rest of the features. | |
43 HistogramSupport::histogramEnumeration("WebCore.FeatureObserver", PageDestru ction, NumberOfFeatures); | |
44 | |
45 updateMeasurements(); | |
46 } | 57 } |
47 | 58 |
48 void UseCounter::updateMeasurements() | 59 void DeprecationAgent::notify(Document* document, Feature feature) |
49 { | |
50 HistogramSupport::histogramEnumeration("WebCore.FeatureObserver", PageVisits , NumberOfFeatures); | |
51 | |
52 if (!m_countBits) | |
53 return; | |
54 | |
55 for (unsigned i = 0; i < NumberOfFeatures; ++i) { | |
56 if (m_countBits->quickGet(i)) | |
57 HistogramSupport::histogramEnumeration("WebCore.FeatureObserver", i, NumberOfFeatures); | |
58 } | |
59 | |
60 // Clearing count bits is timing sensitive. | |
61 m_countBits->clearAll(); | |
62 } | |
63 | |
64 void UseCounter::didCommitLoad() | |
65 { | |
66 updateMeasurements(); | |
67 } | |
68 | |
69 void UseCounter::observe(Document* document, Feature feature) | |
70 { | 60 { |
71 if (!document) | 61 if (!document) |
72 return; | 62 return; |
73 | 63 |
74 Page* page = document->page(); | 64 Page* page = document->page(); |
75 if (!page) | 65 if (!page) |
76 return; | 66 return; |
77 | 67 |
78 page->useCounter()->didObserve(feature); | 68 page->deprecationAgent()->sendNotification(page->console(), feature); |
79 } | 69 } |
80 | 70 |
81 void UseCounter::observe(DOMWindow* domWindow, Feature feature) | 71 void DeprecationAgent::sendNotification(PageConsole* console, Feature feature) |
82 { | 72 { |
83 ASSERT(domWindow); | 73 ASSERT(feature < NumberOfFeatures); |
84 observe(domWindow->document(), feature); | 74 ASSERT(console); |
75 | |
76 if (!m_countBits) { | |
77 m_countBits = adoptPtr(new BitVector(NumberOfFeatures)); | |
78 m_countBits->clearAll(); | |
79 } | |
80 | |
81 if (m_countBits->quickGet(feature)) | |
pfeldman
2013/04/19 13:04:22
Is this covered with the tests? I.e. are you gener
| |
82 return; | |
83 | |
84 m_countBits->quickSet(feature); | |
85 console->addMessage(DeprecationMessageSource, WarningMessageLevel, ASCIILite ral(deprecationMessages[feature])); | |
85 } | 86 } |
86 | 87 |
87 } // namespace WebCore | 88 } // namespace WebCore |
OLD | NEW |