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

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: rebase 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 m_didServiceWorkerNavigationPreload(false), 103 m_didServiceWorkerNavigationPreload(false),
102 m_responseTime(0), 104 m_responseTime(0),
103 m_remotePort(0), 105 m_remotePort(0),
104 m_encodedDataLength(0), 106 m_encodedDataLength(0),
105 m_encodedBodyLength(0), 107 m_encodedBodyLength(0),
106 m_decodedBodyLength(0) {} 108 m_decodedBodyLength(0) {}
107 109
108 ResourceResponse::ResourceResponse(const KURL& url, 110 ResourceResponse::ResourceResponse(const KURL& url,
109 const AtomicString& mimeType, 111 const AtomicString& mimeType,
110 long long expectedLength, 112 long long expectedLength,
111 const AtomicString& textEncodingName, 113 const AtomicString& textEncodingName)
112 const String& filename)
113 : m_url(url), 114 : m_url(url),
114 m_mimeType(mimeType), 115 m_mimeType(mimeType),
115 m_expectedContentLength(expectedLength), 116 m_expectedContentLength(expectedLength),
116 m_textEncodingName(textEncodingName), 117 m_textEncodingName(textEncodingName),
117 m_suggestedFilename(filename),
118 m_httpStatusCode(0), 118 m_httpStatusCode(0),
119 m_lastModifiedDate(0), 119 m_lastModifiedDate(0),
120 m_wasCached(false), 120 m_wasCached(false),
121 m_connectionID(0), 121 m_connectionID(0),
122 m_connectionReused(false), 122 m_connectionReused(false),
123 m_isNull(false), 123 m_isNull(false),
124 m_haveParsedAgeHeader(false), 124 m_haveParsedAgeHeader(false),
125 m_haveParsedDateHeader(false), 125 m_haveParsedDateHeader(false),
126 m_haveParsedExpiresHeader(false), 126 m_haveParsedExpiresHeader(false),
127 m_haveParsedLastModifiedHeader(false), 127 m_haveParsedLastModifiedHeader(false),
(...skipping 19 matching lines...) Expand all
147 m_encodedDataLength(0), 147 m_encodedDataLength(0),
148 m_encodedBodyLength(0), 148 m_encodedBodyLength(0),
149 m_decodedBodyLength(0) {} 149 m_decodedBodyLength(0) {}
150 150
151 ResourceResponse::ResourceResponse(CrossThreadResourceResponseData* data) 151 ResourceResponse::ResourceResponse(CrossThreadResourceResponseData* data)
152 : ResourceResponse() { 152 : ResourceResponse() {
153 setURL(data->m_url); 153 setURL(data->m_url);
154 setMimeType(AtomicString(data->m_mimeType)); 154 setMimeType(AtomicString(data->m_mimeType));
155 setExpectedContentLength(data->m_expectedContentLength); 155 setExpectedContentLength(data->m_expectedContentLength);
156 setTextEncodingName(AtomicString(data->m_textEncodingName)); 156 setTextEncodingName(AtomicString(data->m_textEncodingName));
157 setSuggestedFilename(data->m_suggestedFilename);
158 157
159 setHTTPStatusCode(data->m_httpStatusCode); 158 setHTTPStatusCode(data->m_httpStatusCode);
160 setHTTPStatusText(AtomicString(data->m_httpStatusText)); 159 setHTTPStatusText(AtomicString(data->m_httpStatusText));
161 160
162 m_httpHeaderFields.adopt(std::move(data->m_httpHeaders)); 161 m_httpHeaderFields.adopt(std::move(data->m_httpHeaders));
163 setLastModifiedDate(data->m_lastModifiedDate); 162 setLastModifiedDate(data->m_lastModifiedDate);
164 setResourceLoadTiming(data->m_resourceLoadTiming.release()); 163 setResourceLoadTiming(data->m_resourceLoadTiming.release());
165 m_hasMajorCertificateErrors = data->m_hasMajorCertificateErrors; 164 m_hasMajorCertificateErrors = data->m_hasMajorCertificateErrors;
166 m_securityStyle = data->m_securityStyle; 165 m_securityStyle = data->m_securityStyle;
167 m_securityDetails.protocol = data->m_securityDetails.protocol; 166 m_securityDetails.protocol = data->m_securityDetails.protocol;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 default; 211 default;
213 212
214 std::unique_ptr<CrossThreadResourceResponseData> ResourceResponse::copyData() 213 std::unique_ptr<CrossThreadResourceResponseData> ResourceResponse::copyData()
215 const { 214 const {
216 std::unique_ptr<CrossThreadResourceResponseData> data = 215 std::unique_ptr<CrossThreadResourceResponseData> data =
217 WTF::wrapUnique(new CrossThreadResourceResponseData); 216 WTF::wrapUnique(new CrossThreadResourceResponseData);
218 data->m_url = url().copy(); 217 data->m_url = url().copy();
219 data->m_mimeType = mimeType().getString().isolatedCopy(); 218 data->m_mimeType = mimeType().getString().isolatedCopy();
220 data->m_expectedContentLength = expectedContentLength(); 219 data->m_expectedContentLength = expectedContentLength();
221 data->m_textEncodingName = textEncodingName().getString().isolatedCopy(); 220 data->m_textEncodingName = textEncodingName().getString().isolatedCopy();
222 data->m_suggestedFilename = suggestedFilename().isolatedCopy();
223 data->m_httpStatusCode = httpStatusCode(); 221 data->m_httpStatusCode = httpStatusCode();
224 data->m_httpStatusText = httpStatusText().getString().isolatedCopy(); 222 data->m_httpStatusText = httpStatusText().getString().isolatedCopy();
225 data->m_httpHeaders = httpHeaderFields().copyData(); 223 data->m_httpHeaders = httpHeaderFields().copyData();
226 data->m_lastModifiedDate = lastModifiedDate(); 224 data->m_lastModifiedDate = lastModifiedDate();
227 if (m_resourceLoadTiming) 225 if (m_resourceLoadTiming)
228 data->m_resourceLoadTiming = m_resourceLoadTiming->deepCopy(); 226 data->m_resourceLoadTiming = m_resourceLoadTiming->deepCopy();
229 data->m_hasMajorCertificateErrors = m_hasMajorCertificateErrors; 227 data->m_hasMajorCertificateErrors = m_hasMajorCertificateErrors;
230 data->m_securityStyle = m_securityStyle; 228 data->m_securityStyle = m_securityStyle;
231 data->m_securityDetails.protocol = m_securityDetails.protocol.isolatedCopy(); 229 data->m_securityDetails.protocol = m_securityDetails.protocol.isolatedCopy();
232 data->m_securityDetails.cipher = m_securityDetails.cipher.isolatedCopy(); 230 data->m_securityDetails.cipher = m_securityDetails.cipher.isolatedCopy();
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 } 323 }
326 324
327 void ResourceResponse::setTextEncodingName(const AtomicString& encodingName) { 325 void ResourceResponse::setTextEncodingName(const AtomicString& encodingName) {
328 m_isNull = false; 326 m_isNull = false;
329 327
330 // FIXME: Text encoding is determined by HTTP Content-Type header. We should 328 // FIXME: Text encoding is determined by HTTP Content-Type header. We should
331 // update the header, so that it doesn't disagree with m_textEncodingName. 329 // update the header, so that it doesn't disagree with m_textEncodingName.
332 m_textEncodingName = encodingName; 330 m_textEncodingName = encodingName;
333 } 331 }
334 332
335 // FIXME should compute this on the fly
336 const String& ResourceResponse::suggestedFilename() const {
337 return m_suggestedFilename;
338 }
339
340 void ResourceResponse::setSuggestedFilename(const String& suggestedName) {
341 m_isNull = false;
342
343 // FIXME: Suggested file name is calculated based on other headers. There
344 // should not be a setter for it.
345 m_suggestedFilename = suggestedName;
346 }
347
348 int ResourceResponse::httpStatusCode() const { 333 int ResourceResponse::httpStatusCode() const {
349 return m_httpStatusCode; 334 return m_httpStatusCode;
350 } 335 }
351 336
352 void ResourceResponse::setHTTPStatusCode(int statusCode) { 337 void ResourceResponse::setHTTPStatusCode(int statusCode) {
353 m_httpStatusCode = statusCode; 338 m_httpStatusCode = statusCode;
354 } 339 }
355 340
356 const AtomicString& ResourceResponse::httpStatusText() const { 341 const AtomicString& ResourceResponse::httpStatusText() const {
357 return m_httpStatusText; 342 return m_httpStatusText;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
537 double ResourceResponse::lastModified() const { 522 double ResourceResponse::lastModified() const {
538 if (!m_haveParsedLastModifiedHeader) { 523 if (!m_haveParsedLastModifiedHeader) {
539 static const char headerName[] = "last-modified"; 524 static const char headerName[] = "last-modified";
540 m_lastModified = parseDateValueInHeader(m_httpHeaderFields, headerName); 525 m_lastModified = parseDateValueInHeader(m_httpHeaderFields, headerName);
541 m_haveParsedLastModifiedHeader = true; 526 m_haveParsedLastModifiedHeader = true;
542 } 527 }
543 return m_lastModified; 528 return m_lastModified;
544 } 529 }
545 530
546 bool ResourceResponse::isAttachment() const { 531 bool ResourceResponse::isAttachment() const {
547 static const char headerName[] = "content-disposition";
548 static const char attachmentString[] = "attachment"; 532 static const char attachmentString[] = "attachment";
549 String value = m_httpHeaderFields.get(headerName); 533 String value = m_httpHeaderFields.get(HTTPNames::Content_Disposition);
550 size_t loc = value.find(';'); 534 size_t loc = value.find(';');
551 if (loc != kNotFound) 535 if (loc != kNotFound)
552 value = value.left(loc); 536 value = value.left(loc);
553 value = value.stripWhiteSpace(); 537 value = value.stripWhiteSpace();
554 return equalIgnoringCase(value, attachmentString); 538 return equalIgnoringCase(value, attachmentString);
555 } 539 }
556 540
557 void ResourceResponse::setLastModifiedDate(time_t lastModifiedDate) { 541 void ResourceResponse::setLastModifiedDate(time_t lastModifiedDate) {
558 m_lastModifiedDate = lastModifiedDate; 542 m_lastModifiedDate = lastModifiedDate;
559 } 543 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 if (a.isNull() != b.isNull()) 629 if (a.isNull() != b.isNull())
646 return false; 630 return false;
647 if (a.url() != b.url()) 631 if (a.url() != b.url())
648 return false; 632 return false;
649 if (a.mimeType() != b.mimeType()) 633 if (a.mimeType() != b.mimeType())
650 return false; 634 return false;
651 if (a.expectedContentLength() != b.expectedContentLength()) 635 if (a.expectedContentLength() != b.expectedContentLength())
652 return false; 636 return false;
653 if (a.textEncodingName() != b.textEncodingName()) 637 if (a.textEncodingName() != b.textEncodingName())
654 return false; 638 return false;
655 if (a.suggestedFilename() != b.suggestedFilename())
656 return false;
657 if (a.httpStatusCode() != b.httpStatusCode()) 639 if (a.httpStatusCode() != b.httpStatusCode())
658 return false; 640 return false;
659 if (a.httpStatusText() != b.httpStatusText()) 641 if (a.httpStatusText() != b.httpStatusText())
660 return false; 642 return false;
661 if (a.httpHeaderFields() != b.httpHeaderFields()) 643 if (a.httpHeaderFields() != b.httpHeaderFields())
662 return false; 644 return false;
663 if (a.resourceLoadTiming() && b.resourceLoadTiming() && 645 if (a.resourceLoadTiming() && b.resourceLoadTiming() &&
664 *a.resourceLoadTiming() == *b.resourceLoadTiming()) 646 *a.resourceLoadTiming() == *b.resourceLoadTiming())
665 return true; 647 return true;
666 if (a.resourceLoadTiming() != b.resourceLoadTiming()) 648 if (a.resourceLoadTiming() != b.resourceLoadTiming())
667 return false; 649 return false;
668 if (a.encodedBodyLength() != b.encodedBodyLength()) 650 if (a.encodedBodyLength() != b.encodedBodyLength())
669 return false; 651 return false;
670 if (a.decodedBodyLength() != b.decodedBodyLength()) 652 if (a.decodedBodyLength() != b.decodedBodyLength())
671 return false; 653 return false;
672 return true; 654 return true;
673 } 655 }
674 656
675 } // namespace blink 657 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/platform/network/ResourceResponse.h ('k') | third_party/WebKit/public/platform/WebDragData.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698