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

Side by Side Diff: third_party/WebKit/Source/platform/network/ResourceResponse.cpp

Issue 2674953003: Only generate suggested filenames when actually dragging an image. (Closed)
Patch Set: Maybe? Created 3 years, 10 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Google Inc. All rights reserved. 3 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
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
11 * notice, this list of conditions and the following disclaimer in the 11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution. 12 * documentation and/or other materials provided with the distribution.
13 * 13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "platform/network/ResourceResponse.h" 27 #include "platform/network/ResourceResponse.h"
28 28
29 #include "platform/HTTPNames.h"
29 #include "wtf/CurrentTime.h" 30 #include "wtf/CurrentTime.h"
30 #include "wtf/PtrUtil.h" 31 #include "wtf/PtrUtil.h"
31 #include "wtf/StdLibExtras.h" 32 #include "wtf/StdLibExtras.h"
33
32 #include <memory> 34 #include <memory>
33 35
34 namespace blink { 36 namespace blink {
35 37
36 namespace { 38 namespace {
37 39
38 template <typename Interface> 40 template <typename Interface>
39 Vector<Interface> isolatedCopy(const Vector<Interface>& src) { 41 Vector<Interface> isolatedCopy(const Vector<Interface>& src) {
40 Vector<Interface> result; 42 Vector<Interface> result;
41 result.reserveCapacity(src.size()); 43 result.reserveCapacity(src.size());
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 m_serviceWorkerResponseType(WebServiceWorkerResponseTypeDefault), 102 m_serviceWorkerResponseType(WebServiceWorkerResponseTypeDefault),
101 m_responseTime(0), 103 m_responseTime(0),
102 m_remotePort(0), 104 m_remotePort(0),
103 m_encodedDataLength(0), 105 m_encodedDataLength(0),
104 m_encodedBodyLength(0), 106 m_encodedBodyLength(0),
105 m_decodedBodyLength(0) {} 107 m_decodedBodyLength(0) {}
106 108
107 ResourceResponse::ResourceResponse(const KURL& url, 109 ResourceResponse::ResourceResponse(const KURL& url,
108 const AtomicString& mimeType, 110 const AtomicString& mimeType,
109 long long expectedLength, 111 long long expectedLength,
110 const AtomicString& textEncodingName, 112 const AtomicString& textEncodingName)
111 const String& filename)
112 : m_url(url), 113 : m_url(url),
113 m_mimeType(mimeType), 114 m_mimeType(mimeType),
114 m_expectedContentLength(expectedLength), 115 m_expectedContentLength(expectedLength),
115 m_textEncodingName(textEncodingName), 116 m_textEncodingName(textEncodingName),
116 m_suggestedFilename(filename),
117 m_httpStatusCode(0), 117 m_httpStatusCode(0),
118 m_lastModifiedDate(0), 118 m_lastModifiedDate(0),
119 m_wasCached(false), 119 m_wasCached(false),
120 m_connectionID(0), 120 m_connectionID(0),
121 m_connectionReused(false), 121 m_connectionReused(false),
122 m_isNull(false), 122 m_isNull(false),
123 m_haveParsedAgeHeader(false), 123 m_haveParsedAgeHeader(false),
124 m_haveParsedDateHeader(false), 124 m_haveParsedDateHeader(false),
125 m_haveParsedExpiresHeader(false), 125 m_haveParsedExpiresHeader(false),
126 m_haveParsedLastModifiedHeader(false), 126 m_haveParsedLastModifiedHeader(false),
(...skipping 18 matching lines...) Expand all
145 m_encodedDataLength(0), 145 m_encodedDataLength(0),
146 m_encodedBodyLength(0), 146 m_encodedBodyLength(0),
147 m_decodedBodyLength(0) {} 147 m_decodedBodyLength(0) {}
148 148
149 ResourceResponse::ResourceResponse(CrossThreadResourceResponseData* data) 149 ResourceResponse::ResourceResponse(CrossThreadResourceResponseData* data)
150 : ResourceResponse() { 150 : ResourceResponse() {
151 setURL(data->m_url); 151 setURL(data->m_url);
152 setMimeType(AtomicString(data->m_mimeType)); 152 setMimeType(AtomicString(data->m_mimeType));
153 setExpectedContentLength(data->m_expectedContentLength); 153 setExpectedContentLength(data->m_expectedContentLength);
154 setTextEncodingName(AtomicString(data->m_textEncodingName)); 154 setTextEncodingName(AtomicString(data->m_textEncodingName));
155 setSuggestedFilename(data->m_suggestedFilename);
156 155
157 setHTTPStatusCode(data->m_httpStatusCode); 156 setHTTPStatusCode(data->m_httpStatusCode);
158 setHTTPStatusText(AtomicString(data->m_httpStatusText)); 157 setHTTPStatusText(AtomicString(data->m_httpStatusText));
159 158
160 m_httpHeaderFields.adopt(std::move(data->m_httpHeaders)); 159 m_httpHeaderFields.adopt(std::move(data->m_httpHeaders));
161 setLastModifiedDate(data->m_lastModifiedDate); 160 setLastModifiedDate(data->m_lastModifiedDate);
162 setResourceLoadTiming(data->m_resourceLoadTiming.release()); 161 setResourceLoadTiming(data->m_resourceLoadTiming.release());
163 m_hasMajorCertificateErrors = data->m_hasMajorCertificateErrors; 162 m_hasMajorCertificateErrors = data->m_hasMajorCertificateErrors;
164 m_securityStyle = data->m_securityStyle; 163 m_securityStyle = data->m_securityStyle;
165 m_securityDetails.protocol = data->m_securityDetails.protocol; 164 m_securityDetails.protocol = data->m_securityDetails.protocol;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 default; 207 default;
209 208
210 std::unique_ptr<CrossThreadResourceResponseData> ResourceResponse::copyData() 209 std::unique_ptr<CrossThreadResourceResponseData> ResourceResponse::copyData()
211 const { 210 const {
212 std::unique_ptr<CrossThreadResourceResponseData> data = 211 std::unique_ptr<CrossThreadResourceResponseData> data =
213 WTF::wrapUnique(new CrossThreadResourceResponseData); 212 WTF::wrapUnique(new CrossThreadResourceResponseData);
214 data->m_url = url().copy(); 213 data->m_url = url().copy();
215 data->m_mimeType = mimeType().getString().isolatedCopy(); 214 data->m_mimeType = mimeType().getString().isolatedCopy();
216 data->m_expectedContentLength = expectedContentLength(); 215 data->m_expectedContentLength = expectedContentLength();
217 data->m_textEncodingName = textEncodingName().getString().isolatedCopy(); 216 data->m_textEncodingName = textEncodingName().getString().isolatedCopy();
218 data->m_suggestedFilename = suggestedFilename().isolatedCopy();
219 data->m_httpStatusCode = httpStatusCode(); 217 data->m_httpStatusCode = httpStatusCode();
220 data->m_httpStatusText = httpStatusText().getString().isolatedCopy(); 218 data->m_httpStatusText = httpStatusText().getString().isolatedCopy();
221 data->m_httpHeaders = httpHeaderFields().copyData(); 219 data->m_httpHeaders = httpHeaderFields().copyData();
222 data->m_lastModifiedDate = lastModifiedDate(); 220 data->m_lastModifiedDate = lastModifiedDate();
223 if (m_resourceLoadTiming) 221 if (m_resourceLoadTiming)
224 data->m_resourceLoadTiming = m_resourceLoadTiming->deepCopy(); 222 data->m_resourceLoadTiming = m_resourceLoadTiming->deepCopy();
225 data->m_hasMajorCertificateErrors = m_hasMajorCertificateErrors; 223 data->m_hasMajorCertificateErrors = m_hasMajorCertificateErrors;
226 data->m_securityStyle = m_securityStyle; 224 data->m_securityStyle = m_securityStyle;
227 data->m_securityDetails.protocol = m_securityDetails.protocol.isolatedCopy(); 225 data->m_securityDetails.protocol = m_securityDetails.protocol.isolatedCopy();
228 data->m_securityDetails.cipher = m_securityDetails.cipher.isolatedCopy(); 226 data->m_securityDetails.cipher = m_securityDetails.cipher.isolatedCopy();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 317 }
320 318
321 void ResourceResponse::setTextEncodingName(const AtomicString& encodingName) { 319 void ResourceResponse::setTextEncodingName(const AtomicString& encodingName) {
322 m_isNull = false; 320 m_isNull = false;
323 321
324 // FIXME: Text encoding is determined by HTTP Content-Type header. We should 322 // FIXME: Text encoding is determined by HTTP Content-Type header. We should
325 // update the header, so that it doesn't disagree with m_textEncodingName. 323 // update the header, so that it doesn't disagree with m_textEncodingName.
326 m_textEncodingName = encodingName; 324 m_textEncodingName = encodingName;
327 } 325 }
328 326
329 // FIXME should compute this on the fly
330 const String& ResourceResponse::suggestedFilename() const {
331 return m_suggestedFilename;
332 }
333
334 void ResourceResponse::setSuggestedFilename(const String& suggestedName) {
335 m_isNull = false;
336
337 // FIXME: Suggested file name is calculated based on other headers. There
338 // should not be a setter for it.
339 m_suggestedFilename = suggestedName;
340 }
341
342 int ResourceResponse::httpStatusCode() const { 327 int ResourceResponse::httpStatusCode() const {
343 return m_httpStatusCode; 328 return m_httpStatusCode;
344 } 329 }
345 330
346 void ResourceResponse::setHTTPStatusCode(int statusCode) { 331 void ResourceResponse::setHTTPStatusCode(int statusCode) {
347 m_httpStatusCode = statusCode; 332 m_httpStatusCode = statusCode;
348 } 333 }
349 334
350 const AtomicString& ResourceResponse::httpStatusText() const { 335 const AtomicString& ResourceResponse::httpStatusText() const {
351 return m_httpStatusText; 336 return m_httpStatusText;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 double ResourceResponse::lastModified() const { 516 double ResourceResponse::lastModified() const {
532 if (!m_haveParsedLastModifiedHeader) { 517 if (!m_haveParsedLastModifiedHeader) {
533 static const char headerName[] = "last-modified"; 518 static const char headerName[] = "last-modified";
534 m_lastModified = parseDateValueInHeader(m_httpHeaderFields, headerName); 519 m_lastModified = parseDateValueInHeader(m_httpHeaderFields, headerName);
535 m_haveParsedLastModifiedHeader = true; 520 m_haveParsedLastModifiedHeader = true;
536 } 521 }
537 return m_lastModified; 522 return m_lastModified;
538 } 523 }
539 524
540 bool ResourceResponse::isAttachment() const { 525 bool ResourceResponse::isAttachment() const {
541 static const char headerName[] = "content-disposition";
542 static const char attachmentString[] = "attachment"; 526 static const char attachmentString[] = "attachment";
543 String value = m_httpHeaderFields.get(headerName); 527 String value = m_httpHeaderFields.get(HTTPNames::Content_Disposition);
544 size_t loc = value.find(';'); 528 size_t loc = value.find(';');
545 if (loc != kNotFound) 529 if (loc != kNotFound)
546 value = value.left(loc); 530 value = value.left(loc);
547 value = value.stripWhiteSpace(); 531 value = value.stripWhiteSpace();
548 return equalIgnoringCase(value, attachmentString); 532 return equalIgnoringCase(value, attachmentString);
549 } 533 }
550 534
551 void ResourceResponse::setLastModifiedDate(time_t lastModifiedDate) { 535 void ResourceResponse::setLastModifiedDate(time_t lastModifiedDate) {
552 m_lastModifiedDate = lastModifiedDate; 536 m_lastModifiedDate = lastModifiedDate;
553 } 537 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 if (a.isNull() != b.isNull()) 623 if (a.isNull() != b.isNull())
640 return false; 624 return false;
641 if (a.url() != b.url()) 625 if (a.url() != b.url())
642 return false; 626 return false;
643 if (a.mimeType() != b.mimeType()) 627 if (a.mimeType() != b.mimeType())
644 return false; 628 return false;
645 if (a.expectedContentLength() != b.expectedContentLength()) 629 if (a.expectedContentLength() != b.expectedContentLength())
646 return false; 630 return false;
647 if (a.textEncodingName() != b.textEncodingName()) 631 if (a.textEncodingName() != b.textEncodingName())
648 return false; 632 return false;
649 if (a.suggestedFilename() != b.suggestedFilename())
650 return false;
651 if (a.httpStatusCode() != b.httpStatusCode()) 633 if (a.httpStatusCode() != b.httpStatusCode())
652 return false; 634 return false;
653 if (a.httpStatusText() != b.httpStatusText()) 635 if (a.httpStatusText() != b.httpStatusText())
654 return false; 636 return false;
655 if (a.httpHeaderFields() != b.httpHeaderFields()) 637 if (a.httpHeaderFields() != b.httpHeaderFields())
656 return false; 638 return false;
657 if (a.resourceLoadTiming() && b.resourceLoadTiming() && 639 if (a.resourceLoadTiming() && b.resourceLoadTiming() &&
658 *a.resourceLoadTiming() == *b.resourceLoadTiming()) 640 *a.resourceLoadTiming() == *b.resourceLoadTiming())
659 return true; 641 return true;
660 if (a.resourceLoadTiming() != b.resourceLoadTiming()) 642 if (a.resourceLoadTiming() != b.resourceLoadTiming())
661 return false; 643 return false;
662 if (a.encodedBodyLength() != b.encodedBodyLength()) 644 if (a.encodedBodyLength() != b.encodedBodyLength())
663 return false; 645 return false;
664 if (a.decodedBodyLength() != b.decodedBodyLength()) 646 if (a.decodedBodyLength() != b.decodedBodyLength())
665 return false; 647 return false;
666 return true; 648 return true;
667 } 649 }
668 650
669 } // namespace blink 651 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698