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

Side by Side Diff: Source/core/xmlhttprequest/XMLHttpRequest.cpp

Issue 1342443004: [MIGRATED] Make deprecation warnings on XHR's setRequestHeader more accurate (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@temp1288263003
Patch Set: Reflect tyoshino's comments. Created 5 years, 2 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
« no previous file with comments | « Source/core/frame/UseCounter.cpp ('k') | no next file » | 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) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org>
4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org>
5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved.
6 * Copyright (C) 2012 Intel Corporation 6 * Copyright (C) 2012 Intel Corporation
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 if (!isValidHTTPToken(name)) { 1176 if (!isValidHTTPToken(name)) {
1177 exceptionState.throwDOMException(SyntaxError, "'" + name + "' is not a v alid HTTP header field name."); 1177 exceptionState.throwDOMException(SyntaxError, "'" + name + "' is not a v alid HTTP header field name.");
1178 return; 1178 return;
1179 } 1179 }
1180 1180
1181 if (!isValidHTTPHeaderValue(value)) { 1181 if (!isValidHTTPHeaderValue(value)) {
1182 exceptionState.throwDOMException(SyntaxError, "'" + value + "' is not a valid HTTP header field value."); 1182 exceptionState.throwDOMException(SyntaxError, "'" + value + "' is not a valid HTTP header field value.");
1183 return; 1183 return;
1184 } 1184 }
1185 1185
1186 // Show deprecation warnings and count occurrences of such deprecated header values.
1187 if (!value.isEmpty() && !isValidHTTPFieldContentRFC7230(value))
1188 UseCounter::countDeprecation(executionContext(), UseCounter::HeaderValue NotMatchingRFC7230);
1189
1190 // No script (privileged or not) can set unsafe headers. 1186 // No script (privileged or not) can set unsafe headers.
1191 if (FetchUtils::isForbiddenHeaderName(name)) { 1187 if (FetchUtils::isForbiddenHeaderName(name)) {
1192 logConsoleError(executionContext(), "Refused to set unsafe header \"" + name + "\""); 1188 logConsoleError(executionContext(), "Refused to set unsafe header \"" + name + "\"");
1193 return; 1189 return;
1194 } 1190 }
1195 1191
1196 setRequestHeaderInternal(name, value); 1192 setRequestHeaderInternal(name, value);
1197 } 1193 }
1198 1194
1199 void XMLHttpRequest::setRequestHeaderInternal(const AtomicString& name, const At omicString& value) 1195 void XMLHttpRequest::setRequestHeaderInternal(const AtomicString& name, const At omicString& value)
1200 { 1196 {
1197 // We show deprecation warnings if |value| is still invalid header value
1198 // after normalization (i.e. contains invalid octets).
1199 String normalizedValue = FetchUtils::normalizeHeaderValue(value);
1200 if (!normalizedValue.isEmpty() && !isValidHTTPFieldContentRFC7230(normalized Value))
1201 UseCounter::countDeprecation(executionContext(), UseCounter::HeaderValue NotMatchingRFC7230);
1202
1201 HTTPHeaderMap::AddResult result = m_requestHeaders.add(name, value); 1203 HTTPHeaderMap::AddResult result = m_requestHeaders.add(name, value);
1202 if (!result.isNewEntry) 1204 if (result.isNewEntry)
1203 result.storedValue->value = result.storedValue->value + ", " + value; 1205 return;
1206
1207 AtomicString newValue = result.storedValue->value + ", " + value;
1208
1209 // We show deprecation warnings if this call to setRequestHeader() is
1210 // affected by header value normalization.
1211 // Without normalization at XHR level here, the actual header value
1212 // sent to the network is |newValue| with leading/trailing whitespaces
1213 // stripped (i.e. |normalizeHeaderValue(newValue)|).
1214 // With normalization at XHR level here as the spec requires, the
1215 // actual header value sent to the network is |normalizedNewValue|.
1216 // If these two are different, introducing normalization here affects
1217 // the header value sent to the network so we show warnings.
1218 String normalizedNewValue = FetchUtils::normalizeHeaderValue(result.storedVa lue->value) + ", " + FetchUtils::normalizeHeaderValue(value);
1219 if (FetchUtils::normalizeHeaderValue(newValue) != normalizedNewValue)
1220 UseCounter::countDeprecation(executionContext(), UseCounter::XHRSetReque stHeaderAffectedByNormalization);
1221
1222 result.storedValue->value = newValue;
1204 } 1223 }
1205 1224
1206 const AtomicString& XMLHttpRequest::getRequestHeader(const AtomicString& name) c onst 1225 const AtomicString& XMLHttpRequest::getRequestHeader(const AtomicString& name) c onst
1207 { 1226 {
1208 return m_requestHeaders.get(name); 1227 return m_requestHeaders.get(name);
1209 } 1228 }
1210 1229
1211 String XMLHttpRequest::getAllResponseHeaders() const 1230 String XMLHttpRequest::getAllResponseHeaders() const
1212 { 1231 {
1213 if (m_state < HEADERS_RECEIVED || m_error) 1232 if (m_state < HEADERS_RECEIVED || m_error)
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 visitor->trace(m_responseDocumentParser); 1716 visitor->trace(m_responseDocumentParser);
1698 visitor->trace(m_progressEventThrottle); 1717 visitor->trace(m_progressEventThrottle);
1699 visitor->trace(m_upload); 1718 visitor->trace(m_upload);
1700 visitor->trace(m_blobLoader); 1719 visitor->trace(m_blobLoader);
1701 XMLHttpRequestEventTarget::trace(visitor); 1720 XMLHttpRequestEventTarget::trace(visitor);
1702 DocumentParserClient::trace(visitor); 1721 DocumentParserClient::trace(visitor);
1703 ActiveDOMObject::trace(visitor); 1722 ActiveDOMObject::trace(visitor);
1704 } 1723 }
1705 1724
1706 } // namespace blink 1725 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/UseCounter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698