PassOwnPtr<CrossThreadResourceResponseData> ResourceResponse::copyData() const { OwnPtr<CrossThreadResourceResponseData> data = adoptPtr(new CrossThreadResourceResponseData); data->m_url = url().copy(); data->m_mimeType = mimeType().string().isolatedCopy(); data->m_expectedContentLength = expectedContentLength(); data->m_textEncodingName = textEncodingName().string().isolatedCopy(); data->m_suggestedFilename = suggestedFilename().isolatedCopy(); data->m_httpStatusCode = httpStatusCode(); data->m_httpStatusText = httpStatusText().string().isolatedCopy(); data->m_httpHeaders = httpHeaderFields().copyData(); data->m_lastModifiedDate = lastModifiedDate(); if (m_resourceLoadTiming) data->m_resourceLoadTiming = m_resourceLoadTiming->deepCopy(); data->m_securityInfo = CString(m_securityInfo.data(), m_securityInfo.length()); data->m_httpVersion = m_httpVersion; data->m_appCacheID = m_appCacheID; data->m_appCacheManifestURL = m_appCacheManifestURL.copy(); data->m_isMultipartPayload = m_isMultipartPayload; data->m_wasFetchedViaSPDY = m_wasFetchedViaSPDY; data->m_wasNpnNegotiated = m_wasNpnNegotiated; data->m_wasAlternateProtocolAvailable = m_wasAlternateProtocolAvailable; data->m_wasFetchedViaProxy = m_wasFetchedViaProxy; data->m_responseTime = m_responseTime; data->m_remoteIPAddress = m_remoteIPAddress.string().isolatedCopy(); data->m_remotePort = m_remotePort; // Bug https://bugs.webkit.org/show_bug.cgi?id=60397 this doesn't support m_downloadedFile, // or whatever values may be present in the opaque m_extraData structure. return data.release(); }
void ResourceResponse::platformLazyInit(InitLevel initLevel) { if (m_initLevel > initLevel) return; if (m_isNull || !m_cfResponse.get()) return; if (m_initLevel < CommonFieldsOnly && initLevel >= CommonFieldsOnly) { m_url = CFURLResponseGetURL(m_cfResponse.get()); m_mimeType = CFURLResponseGetMIMEType(m_cfResponse.get()); m_expectedContentLength = CFURLResponseGetExpectedContentLength(m_cfResponse.get()); m_textEncodingName = CFURLResponseGetTextEncodingName(m_cfResponse.get()); // Workaround for <rdar://problem/8757088>, can be removed once that is fixed. unsigned textEncodingNameLength = m_textEncodingName.length(); if (textEncodingNameLength >= 2 && m_textEncodingName[0U] == '"' && m_textEncodingName[textEncodingNameLength - 1] == '"') m_textEncodingName = m_textEncodingName.substring(1, textEncodingNameLength - 2); m_lastModifiedDate = toTimeT(CFURLResponseGetLastModifiedDate(m_cfResponse.get())); CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(m_cfResponse.get()); if (httpResponse) { m_httpStatusCode = CFHTTPMessageGetResponseStatusCode(httpResponse); RetainPtr<CFDictionaryRef> headers(AdoptCF, CFHTTPMessageCopyAllHeaderFields(httpResponse)); for (int i = 0; i < numCommonHeaderFields; i++) { CFStringRef value; if (CFDictionaryGetValueIfPresent(headers.get(), commonHeaderFields[i], (const void **)&value)) m_httpHeaderFields.set(commonHeaderFields[i], value); } } else m_httpStatusCode = 0; } if (m_initLevel < CommonAndUncommonFields && initLevel >= CommonAndUncommonFields) { CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(m_cfResponse.get()); if (httpResponse) { RetainPtr<CFStringRef> statusLine(AdoptCF, CFHTTPMessageCopyResponseStatusLine(httpResponse)); m_httpStatusText = extractReasonPhraseFromHTTPStatusLine(statusLine.get()); RetainPtr<CFDictionaryRef> headers(AdoptCF, CFHTTPMessageCopyAllHeaderFields(httpResponse)); CFIndex headerCount = CFDictionaryGetCount(headers.get()); Vector<const void*, 128> keys(headerCount); Vector<const void*, 128> values(headerCount); CFDictionaryGetKeysAndValues(headers.get(), keys.data(), values.data()); for (int i = 0; i < headerCount; ++i) m_httpHeaderFields.set((CFStringRef)keys[i], (CFStringRef)values[i]); } } if (m_initLevel < AllFields && initLevel >= AllFields) { RetainPtr<CFStringRef> suggestedFilename(AdoptCF, CFURLResponseCopySuggestedFilename(m_cfResponse.get())); m_suggestedFilename = suggestedFilename.get(); } m_initLevel = initLevel; }
String WebPage::cachedSuggestedFilenameForURL(const KURL& url) { #if USE(CFNETWORK) RetainPtr<CFCachedURLResponseRef> cachedResponse = cachedResponseForURL(this, url); CFURLResponseRef response = CFCachedURLResponseGetWrappedResponse(cachedResponse.get()); if (!response) return String(); RetainPtr<CFStringRef> suggestedFilename(AdoptCF, CFURLResponseCopySuggestedFilename(response)); return suggestedFilename.get(); #else return String(); #endif }
PassOwnPtr<CrossThreadResourceResponseData> ResourceResponseBase::copyData() const { OwnPtr<CrossThreadResourceResponseData> data = adoptPtr(new CrossThreadResourceResponseData); data->m_url = url().copy(); data->m_mimeType = mimeType().isolatedCopy(); data->m_expectedContentLength = expectedContentLength(); data->m_textEncodingName = textEncodingName().isolatedCopy(); data->m_suggestedFilename = suggestedFilename().isolatedCopy(); data->m_httpStatusCode = httpStatusCode(); data->m_httpStatusText = httpStatusText().isolatedCopy(); data->m_httpHeaders = httpHeaderFields().copyData(); data->m_resourceLoadTiming = m_resourceLoadTiming; return asResourceResponse().doPlatformCopyData(data.release()); }
void ResourceResponse::platformLazyInit() { if (m_isUpToDate) return; m_isUpToDate = true; if (m_isNull) { ASSERT(!m_cfResponse.get()); return; } // FIXME: We may need to do MIME type sniffing here (unless that is done in CFURLResponseGetMIMEType). m_url = CFURLResponseGetURL(m_cfResponse.get()); m_mimeType = CFURLResponseGetMIMEType(m_cfResponse.get()); m_expectedContentLength = CFURLResponseGetExpectedContentLength(m_cfResponse.get()); m_textEncodingName = CFURLResponseGetTextEncodingName(m_cfResponse.get()); m_lastModifiedDate = toTimeT(CFURLResponseGetLastModifiedDate(m_cfResponse.get())); RetainPtr<CFStringRef> suggestedFilename(AdoptCF, CFURLResponseCopySuggestedFilename(m_cfResponse.get())); m_suggestedFilename = suggestedFilename.get(); CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(m_cfResponse.get()); if (httpResponse) { m_httpStatusCode = CFHTTPMessageGetResponseStatusCode(httpResponse); RetainPtr<CFStringRef> statusLine(AdoptCF, CFHTTPMessageCopyResponseStatusLine(httpResponse)); String statusText(statusLine.get()); int spacePos = statusText.find(' '); // Remove the status code from the status text. spacePos = statusText.find(' ', spacePos + 1); statusText = statusText.substring(spacePos + 1); m_httpStatusText = statusText; RetainPtr<CFDictionaryRef> headers(AdoptCF, CFHTTPMessageCopyAllHeaderFields(httpResponse)); CFIndex headerCount = CFDictionaryGetCount(headers.get()); Vector<const void*, 128> keys(headerCount); Vector<const void*, 128> values(headerCount); CFDictionaryGetKeysAndValues(headers.get(), keys.data(), values.data()); for (int i = 0; i < headerCount; ++i) m_httpHeaderFields.set((CFStringRef)keys[i], (CFStringRef)values[i]); } else m_httpStatusCode = 0; }
PassOwnPtr<CrossThreadResourceResponseData> ResourceResponse::copyData() const { OwnPtr<CrossThreadResourceResponseData> data = adoptPtr(new CrossThreadResourceResponseData); data->m_url = url().copy(); data->m_mimeType = mimeType().string().isolatedCopy(); data->m_expectedContentLength = expectedContentLength(); data->m_textEncodingName = textEncodingName().string().isolatedCopy(); data->m_suggestedFilename = suggestedFilename().isolatedCopy(); data->m_httpStatusCode = httpStatusCode(); data->m_httpStatusText = httpStatusText().string().isolatedCopy(); data->m_httpHeaders = httpHeaderFields().copyData(); data->m_lastModifiedDate = lastModifiedDate(); if (m_resourceLoadTiming) data->m_resourceLoadTiming = m_resourceLoadTiming->deepCopy(); data->m_securityInfo = CString(m_securityInfo.data(), m_securityInfo.length()); data->m_hasMajorCertificateErrors = m_hasMajorCertificateErrors; data->m_securityStyle = m_securityStyle; data->m_securityDetails.protocol = m_securityDetails.protocol.isolatedCopy(); data->m_securityDetails.cipher = m_securityDetails.cipher.isolatedCopy(); data->m_securityDetails.keyExchange = m_securityDetails.keyExchange.isolatedCopy(); data->m_securityDetails.mac = m_securityDetails.mac.isolatedCopy(); data->m_securityDetails.certID = m_securityDetails.certID; data->m_httpVersion = m_httpVersion; data->m_appCacheID = m_appCacheID; data->m_appCacheManifestURL = m_appCacheManifestURL.copy(); data->m_isMultipartPayload = m_isMultipartPayload; data->m_wasFetchedViaSPDY = m_wasFetchedViaSPDY; data->m_wasNpnNegotiated = m_wasNpnNegotiated; data->m_wasAlternateProtocolAvailable = m_wasAlternateProtocolAvailable; data->m_wasFetchedViaProxy = m_wasFetchedViaProxy; data->m_wasFetchedViaServiceWorker = m_wasFetchedViaServiceWorker; data->m_wasFallbackRequiredByServiceWorker = m_wasFallbackRequiredByServiceWorker; data->m_serviceWorkerResponseType = m_serviceWorkerResponseType; data->m_originalURLViaServiceWorker = m_originalURLViaServiceWorker.copy(); data->m_responseTime = m_responseTime; data->m_remoteIPAddress = m_remoteIPAddress.string().isolatedCopy(); data->m_remotePort = m_remotePort; data->m_downloadedFilePath = m_downloadedFilePath.isolatedCopy(); data->m_downloadedFileHandle = m_downloadedFileHandle; // Bug https://bugs.webkit.org/show_bug.cgi?id=60397 this doesn't support // whatever values may be present in the opaque m_extraData structure. return data.release(); }
void ResourceResponse::platformLazyInit() { if (m_isUpToDate) return; m_isUpToDate = true; if (m_isNull) { ASSERT(!m_cfResponse.get()); return; } // FIXME: We may need to do MIME type sniffing here (unless that is done in CFURLResponseGetMIMEType). m_url = CFURLResponseGetURL(m_cfResponse.get()); m_mimeType = CFURLResponseGetMIMEType(m_cfResponse.get()); m_expectedContentLength = CFURLResponseGetExpectedContentLength(m_cfResponse.get()); m_textEncodingName = CFURLResponseGetTextEncodingName(m_cfResponse.get()); // Workaround for <rdar://problem/8757088>, can be removed once that is fixed. unsigned textEncodingNameLength = m_textEncodingName.length(); if (textEncodingNameLength >= 2 && m_textEncodingName[0U] == '"' && m_textEncodingName[textEncodingNameLength - 1] == '"') m_textEncodingName = m_textEncodingName.substring(1, textEncodingNameLength - 2); m_lastModifiedDate = toTimeT(CFURLResponseGetLastModifiedDate(m_cfResponse.get())); RetainPtr<CFStringRef> suggestedFilename(AdoptCF, CFURLResponseCopySuggestedFilename(m_cfResponse.get())); m_suggestedFilename = suggestedFilename.get(); CFHTTPMessageRef httpResponse = CFURLResponseGetHTTPResponse(m_cfResponse.get()); if (httpResponse) { m_httpStatusCode = CFHTTPMessageGetResponseStatusCode(httpResponse); RetainPtr<CFStringRef> statusLine(AdoptCF, CFHTTPMessageCopyResponseStatusLine(httpResponse)); m_httpStatusText = extractReasonPhraseFromHTTPStatusLine(statusLine.get()); RetainPtr<CFDictionaryRef> headers(AdoptCF, CFHTTPMessageCopyAllHeaderFields(httpResponse)); CFIndex headerCount = CFDictionaryGetCount(headers.get()); Vector<const void*, 128> keys(headerCount); Vector<const void*, 128> values(headerCount); CFDictionaryGetKeysAndValues(headers.get(), keys.data(), values.data()); for (int i = 0; i < headerCount; ++i) m_httpHeaderFields.set((CFStringRef)keys[i], (CFStringRef)values[i]); } else m_httpStatusCode = 0; }
void NetworkDataTaskBlob::download() { ASSERT(isDownload()); ASSERT(m_pendingDownloadLocation); LOG(NetworkSession, "%p - NetworkDataTaskBlob::download to %s", this, m_pendingDownloadLocation.utf8().data()); m_downloadFile = openFile(m_pendingDownloadLocation, OpenForWrite); if (m_downloadFile == invalidPlatformFileHandle) { didFailDownload(cancelledError(m_firstRequest)); return; } auto& downloadManager = NetworkProcess::singleton().downloadManager(); auto download = std::make_unique<Download>(downloadManager, m_pendingDownloadID, *this, m_session->sessionID(), suggestedFilename()); auto* downloadPtr = download.get(); downloadManager.dataTaskBecameDownloadTask(m_pendingDownloadID, WTFMove(download)); downloadPtr->didCreateDestination(m_pendingDownloadLocation); ASSERT(!m_client); m_buffer.resize(bufferSize); read(); }