Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: Source/core/page/PageConsole.cpp

Issue 14320022: Warn developers about deprecated features only once per page-load. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: PageConsole. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/page/PageConsole.h ('k') | Source/devtools/front_end/ConsoleModel.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Apple Inc. All rights reserved. 2 * Copyright (C) 2013 Apple 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 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 #include <stdio.h> 47 #include <stdio.h>
48 #include <wtf/UnusedParam.h> 48 #include <wtf/UnusedParam.h>
49 #include <wtf/text/CString.h> 49 #include <wtf/text/CString.h>
50 #include <wtf/text/WTFString.h> 50 #include <wtf/text/WTFString.h>
51 51
52 #include "TraceEvent.h" 52 #include "TraceEvent.h"
53 53
54 namespace WebCore { 54 namespace WebCore {
55 55
56 namespace { 56 namespace {
57 int muteCount = 0; 57
58 int muteCount = 0;
59
60 // Ensure that this stays in sync with the DeprecatedFeature enum.
61 static const char* const deprecationMessages[] = {
62 "The 'X-WebKit-CSP' headers are deprecated; please consider using the canoni cal 'Content-Security-Policy' header instead."
63 };
64
65 COMPILE_ASSERT(WTF_ARRAY_LENGTH(deprecationMessages) == static_cast<int>(WebCore ::PageConsole::NumberOfFeatures), DeprecationMessages_matches_enum);
66
58 } 67 }
59 68
60 PageConsole::PageConsole(Page* page) : m_page(page) { } 69 PageConsole::PageConsole(Page* page) : m_page(page) { }
61 70
62 PageConsole::~PageConsole() { } 71 PageConsole::~PageConsole() { }
63 72
64 void PageConsole::addMessage(MessageSource source, MessageLevel level, const Str ing& message, unsigned long requestIdentifier, Document* document) 73 void PageConsole::addMessage(MessageSource source, MessageLevel level, const Str ing& message, unsigned long requestIdentifier, Document* document)
65 { 74 {
66 String url; 75 String url;
67 if (document) 76 if (document)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 muteCount++; 115 muteCount++;
107 } 116 }
108 117
109 // static 118 // static
110 void PageConsole::unmute() 119 void PageConsole::unmute()
111 { 120 {
112 ASSERT(muteCount > 0); 121 ASSERT(muteCount > 0);
113 muteCount--; 122 muteCount--;
114 } 123 }
115 124
125 // static
126 void PageConsole::reportDeprecation(Document* document, DeprecatedFeature featur e)
127 {
128 if (!document)
129 return;
130
131 Page* page = document->page();
132 if (!page || !page->console())
133 return;
134
135 page->console()->addDeprecationMessage(feature);
136 }
137
138 void PageConsole::addDeprecationMessage(DeprecatedFeature feature)
139 {
140 ASSERT(feature < NumberOfFeatures);
141
142 if (!m_deprecationNotifications) {
143 m_deprecationNotifications = adoptPtr(new BitVector(NumberOfFeatures));
pfeldman 2013/04/19 14:19:50 BitVector is not going to take much space.
144 m_deprecationNotifications->clearAll();
145 }
146
147 if (m_deprecationNotifications->quickGet(feature))
148 return;
149
150 m_deprecationNotifications->quickSet(feature);
151 addMessage(DeprecationMessageSource, WarningMessageLevel, ASCIILiteral(depre cationMessages[feature]));
152 }
153
116 } // namespace WebCore 154 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/page/PageConsole.h ('k') | Source/devtools/front_end/ConsoleModel.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698