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

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

Issue 2080623002: Revert "Remove OwnPtr from Blink." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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) 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 #include "platform/SharedBuffer.h" 70 #include "platform/SharedBuffer.h"
71 #include "platform/blob/BlobData.h" 71 #include "platform/blob/BlobData.h"
72 #include "platform/network/HTTPParsers.h" 72 #include "platform/network/HTTPParsers.h"
73 #include "platform/network/ParsedContentType.h" 73 #include "platform/network/ParsedContentType.h"
74 #include "platform/network/ResourceError.h" 74 #include "platform/network/ResourceError.h"
75 #include "platform/network/ResourceRequest.h" 75 #include "platform/network/ResourceRequest.h"
76 #include "public/platform/WebURLRequest.h" 76 #include "public/platform/WebURLRequest.h"
77 #include "wtf/Assertions.h" 77 #include "wtf/Assertions.h"
78 #include "wtf/StdLibExtras.h" 78 #include "wtf/StdLibExtras.h"
79 #include "wtf/text/CString.h" 79 #include "wtf/text/CString.h"
80 #include <memory>
81 80
82 namespace blink { 81 namespace blink {
83 82
84 namespace { 83 namespace {
85 84
86 // This class protects the wrapper of the associated XMLHttpRequest object 85 // This class protects the wrapper of the associated XMLHttpRequest object
87 // via hasPendingActivity method which returns true if 86 // via hasPendingActivity method which returns true if
88 // m_eventDispatchRecursionLevel is positive. 87 // m_eventDispatchRecursionLevel is positive.
89 class ScopedEventDispatchProtect final { 88 class ScopedEventDispatchProtect final {
90 public: 89 public:
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 if (!m_responseBlob) { 327 if (!m_responseBlob) {
329 if (m_downloadingToFile) { 328 if (m_downloadingToFile) {
330 ASSERT(!m_binaryResponseBuilder); 329 ASSERT(!m_binaryResponseBuilder);
331 330
332 // When responseType is set to "blob", we redirect the downloaded 331 // When responseType is set to "blob", we redirect the downloaded
333 // data to a file-handle directly in the browser process. We get 332 // data to a file-handle directly in the browser process. We get
334 // the file-path from the ResourceResponse directly instead of 333 // the file-path from the ResourceResponse directly instead of
335 // copying the bytes between the browser and the renderer. 334 // copying the bytes between the browser and the renderer.
336 m_responseBlob = Blob::create(createBlobDataHandleFromResponse()); 335 m_responseBlob = Blob::create(createBlobDataHandleFromResponse());
337 } else { 336 } else {
338 std::unique_ptr<BlobData> blobData = BlobData::create(); 337 OwnPtr<BlobData> blobData = BlobData::create();
339 size_t size = 0; 338 size_t size = 0;
340 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { 339 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) {
341 size = m_binaryResponseBuilder->size(); 340 size = m_binaryResponseBuilder->size();
342 blobData->appendBytes(m_binaryResponseBuilder->data(), size); 341 blobData->appendBytes(m_binaryResponseBuilder->data(), size);
343 blobData->setContentType(finalResponseMIMETypeWithFallback().low er()); 342 blobData->setContentType(finalResponseMIMETypeWithFallback().low er());
344 m_binaryResponseBuilder.clear(); 343 m_binaryResponseBuilder.clear();
345 } 344 }
346 m_responseBlob = Blob::create(BlobDataHandle::create(std::move(blobD ata), size)); 345 m_responseBlob = Blob::create(BlobDataHandle::create(std::move(blobD ata), size));
347 } 346 }
348 } 347 }
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1017 if (!m_loader) 1016 if (!m_loader)
1018 return true; 1017 return true;
1019 1018
1020 // Cancelling the ThreadableLoader m_loader may result in calling 1019 // Cancelling the ThreadableLoader m_loader may result in calling
1021 // window.onload synchronously. If such an onload handler contains open() 1020 // window.onload synchronously. If such an onload handler contains open()
1022 // call on the same XMLHttpRequest object, reentry happens. 1021 // call on the same XMLHttpRequest object, reentry happens.
1023 // 1022 //
1024 // If, window.onload contains open() and send(), m_loader will be set to 1023 // If, window.onload contains open() and send(), m_loader will be set to
1025 // non 0 value. So, we cannot continue the outer open(). In such case, 1024 // non 0 value. So, we cannot continue the outer open(). In such case,
1026 // just abort the outer open() by returning false. 1025 // just abort the outer open() by returning false.
1027 std::unique_ptr<ThreadableLoader> loader = std::move(m_loader); 1026 OwnPtr<ThreadableLoader> loader = std::move(m_loader);
1028 loader->cancel(); 1027 loader->cancel();
1029 1028
1030 // If abort() called internalAbort() and a nested open() ended up 1029 // If abort() called internalAbort() and a nested open() ended up
1031 // clearing the error flag, but didn't send(), make sure the error 1030 // clearing the error flag, but didn't send(), make sure the error
1032 // flag is still set. 1031 // flag is still set.
1033 bool newLoadStarted = m_loader.get(); 1032 bool newLoadStarted = m_loader.get();
1034 if (!newLoadStarted) 1033 if (!newLoadStarted)
1035 m_error = true; 1034 m_error = true;
1036 1035
1037 return !newLoadStarted; 1036 return !newLoadStarted;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); 1429 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel);
1431 1430
1432 if (m_error) 1431 if (m_error)
1433 return; 1432 return;
1434 handleNetworkError(); 1433 handleNetworkError();
1435 } 1434 }
1436 1435
1437 PassRefPtr<BlobDataHandle> XMLHttpRequest::createBlobDataHandleFromResponse() 1436 PassRefPtr<BlobDataHandle> XMLHttpRequest::createBlobDataHandleFromResponse()
1438 { 1437 {
1439 ASSERT(m_downloadingToFile); 1438 ASSERT(m_downloadingToFile);
1440 std::unique_ptr<BlobData> blobData = BlobData::create(); 1439 OwnPtr<BlobData> blobData = BlobData::create();
1441 String filePath = m_response.downloadedFilePath(); 1440 String filePath = m_response.downloadedFilePath();
1442 // If we errored out or got no data, we return an empty handle. 1441 // If we errored out or got no data, we return an empty handle.
1443 if (!filePath.isEmpty() && m_lengthDownloadedToFile) { 1442 if (!filePath.isEmpty() && m_lengthDownloadedToFile) {
1444 blobData->appendFile(filePath, 0, m_lengthDownloadedToFile, invalidFileT ime()); 1443 blobData->appendFile(filePath, 0, m_lengthDownloadedToFile, invalidFileT ime());
1445 // FIXME: finalResponseMIMETypeWithFallback() defaults to 1444 // FIXME: finalResponseMIMETypeWithFallback() defaults to
1446 // text/xml which may be incorrect. Replace it with 1445 // text/xml which may be incorrect. Replace it with
1447 // finalResponseMIMEType() after compatibility investigation. 1446 // finalResponseMIMEType() after compatibility investigation.
1448 blobData->setContentType(finalResponseMIMETypeWithFallback().lower()); 1447 blobData->setContentType(finalResponseMIMETypeWithFallback().lower());
1449 } 1448 }
1450 return BlobDataHandle::create(std::move(blobData), m_lengthDownloadedToFile) ; 1449 return BlobDataHandle::create(std::move(blobData), m_lengthDownloadedToFile) ;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1503 if (m_uploadEventsAllowed) 1502 if (m_uploadEventsAllowed)
1504 m_upload->dispatchProgressEvent(bytesSent, totalBytesToBeSent); 1503 m_upload->dispatchProgressEvent(bytesSent, totalBytesToBeSent);
1505 1504
1506 if (bytesSent == totalBytesToBeSent && !m_uploadComplete) { 1505 if (bytesSent == totalBytesToBeSent && !m_uploadComplete) {
1507 m_uploadComplete = true; 1506 m_uploadComplete = true;
1508 if (m_uploadEventsAllowed) 1507 if (m_uploadEventsAllowed)
1509 m_upload->dispatchEventAndLoadEnd(EventTypeNames::load, true, bytesS ent, totalBytesToBeSent); 1508 m_upload->dispatchEventAndLoadEnd(EventTypeNames::load, true, bytesS ent, totalBytesToBeSent);
1510 } 1509 }
1511 } 1510 }
1512 1511
1513 void XMLHttpRequest::didReceiveResponse(unsigned long identifier, const Resource Response& response, std::unique_ptr<WebDataConsumerHandle> handle) 1512 void XMLHttpRequest::didReceiveResponse(unsigned long identifier, const Resource Response& response, PassOwnPtr<WebDataConsumerHandle> handle)
1514 { 1513 {
1515 ASSERT_UNUSED(handle, !handle); 1514 ASSERT_UNUSED(handle, !handle);
1516 WTF_LOG(Network, "XMLHttpRequest %p didReceiveResponse(%lu)", this, identifi er); 1515 WTF_LOG(Network, "XMLHttpRequest %p didReceiveResponse(%lu)", this, identifi er);
1517 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel); 1516 ScopedEventDispatchProtect protect(&m_eventDispatchRecursionLevel);
1518 1517
1519 m_response = response; 1518 m_response = response;
1520 if (!m_mimeTypeOverride.isEmpty()) { 1519 if (!m_mimeTypeOverride.isEmpty()) {
1521 m_response.setHTTPHeaderField(HTTPNames::Content_Type, m_mimeTypeOverrid e); 1520 m_response.setHTTPHeaderField(HTTPNames::Content_Type, m_mimeTypeOverrid e);
1522 m_finalResponseCharset = extractCharsetFromMediaType(m_mimeTypeOverride) ; 1521 m_finalResponseCharset = extractCharsetFromMediaType(m_mimeTypeOverride) ;
1523 } 1522 }
(...skipping 14 matching lines...) Expand all
1538 m_responseDocumentParser->addClient(this); 1537 m_responseDocumentParser->addClient(this);
1539 } 1538 }
1540 ASSERT(m_responseDocumentParser); 1539 ASSERT(m_responseDocumentParser);
1541 1540
1542 if (m_responseDocumentParser->needsDecoder()) 1541 if (m_responseDocumentParser->needsDecoder())
1543 m_responseDocumentParser->setDecoder(createDecoder()); 1542 m_responseDocumentParser->setDecoder(createDecoder());
1544 1543
1545 m_responseDocumentParser->appendBytes(data, len); 1544 m_responseDocumentParser->appendBytes(data, len);
1546 } 1545 }
1547 1546
1548 std::unique_ptr<TextResourceDecoder> XMLHttpRequest::createDecoder() const 1547 PassOwnPtr<TextResourceDecoder> XMLHttpRequest::createDecoder() const
1549 { 1548 {
1550 if (m_responseTypeCode == ResponseTypeJSON) 1549 if (m_responseTypeCode == ResponseTypeJSON)
1551 return TextResourceDecoder::create("application/json", "UTF-8"); 1550 return TextResourceDecoder::create("application/json", "UTF-8");
1552 1551
1553 if (!m_finalResponseCharset.isEmpty()) 1552 if (!m_finalResponseCharset.isEmpty())
1554 return TextResourceDecoder::create("text/plain", m_finalResponseCharset) ; 1553 return TextResourceDecoder::create("text/plain", m_finalResponseCharset) ;
1555 1554
1556 // allow TextResourceDecoder to look inside the m_response if it's XML or HT ML 1555 // allow TextResourceDecoder to look inside the m_response if it's XML or HT ML
1557 if (responseIsXML()) { 1556 if (responseIsXML()) {
1558 std::unique_ptr<TextResourceDecoder> decoder = TextResourceDecoder::crea te("application/xml"); 1557 OwnPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("appli cation/xml");
1559 // Don't stop on encoding errors, unlike it is done for other kinds 1558 // Don't stop on encoding errors, unlike it is done for other kinds
1560 // of XML resources. This matches the behavior of previous WebKit 1559 // of XML resources. This matches the behavior of previous WebKit
1561 // versions, Firefox and Opera. 1560 // versions, Firefox and Opera.
1562 decoder->useLenientXMLDecoding(); 1561 decoder->useLenientXMLDecoding();
1563 1562
1564 return decoder; 1563 return decoder;
1565 } 1564 }
1566 1565
1567 if (responseIsHTML()) 1566 if (responseIsHTML())
1568 return TextResourceDecoder::create("text/html", "UTF-8"); 1567 return TextResourceDecoder::create("text/html", "UTF-8");
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1710 visitor->trace(m_responseArrayBuffer); 1709 visitor->trace(m_responseArrayBuffer);
1711 visitor->trace(m_progressEventThrottle); 1710 visitor->trace(m_progressEventThrottle);
1712 visitor->trace(m_upload); 1711 visitor->trace(m_upload);
1713 visitor->trace(m_blobLoader); 1712 visitor->trace(m_blobLoader);
1714 XMLHttpRequestEventTarget::trace(visitor); 1713 XMLHttpRequestEventTarget::trace(visitor);
1715 DocumentParserClient::trace(visitor); 1714 DocumentParserClient::trace(visitor);
1716 ActiveDOMObject::trace(visitor); 1715 ActiveDOMObject::trace(visitor);
1717 } 1716 }
1718 1717
1719 } // namespace blink 1718 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698