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

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

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

Powered by Google App Engine
This is Rietveld 408576698