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

Side by Side Diff: third_party/WebKit/Source/core/fileapi/FileReaderLoader.cpp

Issue 2568723006: Remove blink::Stream related code from FileReaderLoader (Closed)
Patch Set: Created 4 years 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
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/FileReaderLoader.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 30
31 #include "core/fileapi/FileReaderLoader.h" 31 #include "core/fileapi/FileReaderLoader.h"
32 32
33 #include "core/dom/DOMArrayBuffer.h" 33 #include "core/dom/DOMArrayBuffer.h"
34 #include "core/dom/ExecutionContext.h" 34 #include "core/dom/ExecutionContext.h"
35 #include "core/fetch/FetchInitiatorTypeNames.h" 35 #include "core/fetch/FetchInitiatorTypeNames.h"
36 #include "core/fileapi/Blob.h" 36 #include "core/fileapi/Blob.h"
37 #include "core/fileapi/FileReaderLoaderClient.h" 37 #include "core/fileapi/FileReaderLoaderClient.h"
38 #include "core/html/parser/TextResourceDecoder.h" 38 #include "core/html/parser/TextResourceDecoder.h"
39 #include "core/loader/ThreadableLoader.h" 39 #include "core/loader/ThreadableLoader.h"
40 #include "core/streams/Stream.h"
41 #include "platform/blob/BlobRegistry.h" 40 #include "platform/blob/BlobRegistry.h"
42 #include "platform/blob/BlobURL.h" 41 #include "platform/blob/BlobURL.h"
43 #include "platform/network/ResourceError.h" 42 #include "platform/network/ResourceError.h"
44 #include "platform/network/ResourceRequest.h" 43 #include "platform/network/ResourceRequest.h"
45 #include "platform/network/ResourceResponse.h" 44 #include "platform/network/ResourceResponse.h"
46 #include "public/platform/WebURLRequest.h" 45 #include "public/platform/WebURLRequest.h"
47 #include "wtf/PassRefPtr.h" 46 #include "wtf/PassRefPtr.h"
48 #include "wtf/PtrUtil.h" 47 #include "wtf/PtrUtil.h"
49 #include "wtf/RefPtr.h" 48 #include "wtf/RefPtr.h"
50 #include "wtf/Vector.h" 49 #include "wtf/Vector.h"
51 #include "wtf/text/Base64.h" 50 #include "wtf/text/Base64.h"
52 #include "wtf/text/StringBuilder.h" 51 #include "wtf/text/StringBuilder.h"
53 #include <memory> 52 #include <memory>
54 53
55 namespace blink { 54 namespace blink {
56 55
57 FileReaderLoader::FileReaderLoader(ReadType readType, 56 FileReaderLoader::FileReaderLoader(ReadType readType,
58 FileReaderLoaderClient* client) 57 FileReaderLoaderClient* client)
59 : m_readType(readType), 58 : m_readType(readType),
60 m_client(client), 59 m_client(client),
61 m_urlForReadingIsStream(false),
62 m_isRawDataConverted(false), 60 m_isRawDataConverted(false),
63 m_stringResult(""), 61 m_stringResult(""),
64 m_finishedLoading(false), 62 m_finishedLoading(false),
65 m_bytesLoaded(0), 63 m_bytesLoaded(0),
66 m_totalBytes(-1), 64 m_totalBytes(-1),
67 m_hasRange(false), 65 m_hasRange(false),
68 m_rangeStart(0), 66 m_rangeStart(0),
69 m_rangeEnd(0), 67 m_rangeEnd(0),
70 m_errorCode(FileError::kOK) {} 68 m_errorCode(FileError::kOK) {}
71 69
72 FileReaderLoader::~FileReaderLoader() { 70 FileReaderLoader::~FileReaderLoader() {
73 cleanup(); 71 cleanup();
74 if (!m_urlForReading.isEmpty()) { 72 if (!m_urlForReading.isEmpty()) {
75 if (m_urlForReadingIsStream) 73 BlobRegistry::revokePublicBlobURL(m_urlForReading);
76 BlobRegistry::unregisterStreamURL(m_urlForReading);
77 else
78 BlobRegistry::revokePublicBlobURL(m_urlForReading);
79 } 74 }
80 } 75 }
81 76
82 void FileReaderLoader::startInternal(ExecutionContext& executionContext, 77 void FileReaderLoader::start(ExecutionContext* executionContext,
83 const Stream* stream, 78 PassRefPtr<BlobDataHandle> blobData) {
84 PassRefPtr<BlobDataHandle> blobData) { 79 DCHECK(executionContext);
85 // The blob is read by routing through the request handling layer given a 80 // The blob is read by routing through the request handling layer given a
86 // temporary public url. 81 // temporary public url.
87 m_urlForReading = 82 m_urlForReading =
88 BlobURL::createPublicURL(executionContext.getSecurityOrigin()); 83 BlobURL::createPublicURL(executionContext->getSecurityOrigin());
89 if (m_urlForReading.isEmpty()) { 84 if (m_urlForReading.isEmpty()) {
90 failed(FileError::kSecurityErr); 85 failed(FileError::kSecurityErr);
91 return; 86 return;
92 } 87 }
93 88
94 if (blobData) { 89 BlobRegistry::registerPublicBlobURL(executionContext->getSecurityOrigin(),
95 ASSERT(!stream); 90 m_urlForReading, std::move(blobData));
96 BlobRegistry::registerPublicBlobURL(executionContext.getSecurityOrigin(),
97 m_urlForReading, std::move(blobData));
98 } else {
99 ASSERT(stream);
100 BlobRegistry::registerStreamURL(executionContext.getSecurityOrigin(),
101 m_urlForReading, stream->url());
102 }
103
104 // Construct and load the request. 91 // Construct and load the request.
105 ResourceRequest request(m_urlForReading); 92 ResourceRequest request(m_urlForReading);
106 request.setExternalRequestStateFromRequestorAddressSpace( 93 request.setExternalRequestStateFromRequestorAddressSpace(
107 executionContext.securityContext().addressSpace()); 94 executionContext->securityContext().addressSpace());
108 95
109 // FIXME: Should this really be 'internal'? Do we know anything about the 96 // FIXME: Should this really be 'internal'? Do we know anything about the
110 // actual request that generated this fetch? 97 // actual request that generated this fetch?
111 request.setRequestContext(WebURLRequest::RequestContextInternal); 98 request.setRequestContext(WebURLRequest::RequestContextInternal);
112 99
113 request.setHTTPMethod(HTTPNames::GET); 100 request.setHTTPMethod(HTTPNames::GET);
114 if (m_hasRange) 101 if (m_hasRange)
115 request.setHTTPHeaderField( 102 request.setHTTPHeaderField(
116 HTTPNames::Range, 103 HTTPNames::Range,
117 AtomicString(String::format("bytes=%d-%d", m_rangeStart, m_rangeEnd))); 104 AtomicString(String::format("bytes=%d-%d", m_rangeStart, m_rangeEnd)));
118 105
119 ThreadableLoaderOptions options; 106 ThreadableLoaderOptions options;
120 options.preflightPolicy = ConsiderPreflight; 107 options.preflightPolicy = ConsiderPreflight;
121 options.crossOriginRequestPolicy = DenyCrossOriginRequests; 108 options.crossOriginRequestPolicy = DenyCrossOriginRequests;
122 // FIXME: Is there a directive to which this load should be subject? 109 // FIXME: Is there a directive to which this load should be subject?
123 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPolicy; 110 options.contentSecurityPolicyEnforcement = DoNotEnforceContentSecurityPolicy;
124 // Use special initiator to hide the request from the inspector. 111 // Use special initiator to hide the request from the inspector.
125 options.initiator = FetchInitiatorTypeNames::internal; 112 options.initiator = FetchInitiatorTypeNames::internal;
126 113
127 ResourceLoaderOptions resourceLoaderOptions; 114 ResourceLoaderOptions resourceLoaderOptions;
128 resourceLoaderOptions.allowCredentials = AllowStoredCredentials; 115 resourceLoaderOptions.allowCredentials = AllowStoredCredentials;
129 116
130 if (m_client) { 117 if (m_client) {
131 m_loader = ThreadableLoader::create(executionContext, this, options, 118 DCHECK(!m_loader);
119 m_loader = ThreadableLoader::create(*executionContext, this, options,
132 resourceLoaderOptions); 120 resourceLoaderOptions);
133 m_loader->start(request); 121 m_loader->start(request);
134 } else { 122 } else {
135 ThreadableLoader::loadResourceSynchronously( 123 ThreadableLoader::loadResourceSynchronously(
136 executionContext, request, *this, options, resourceLoaderOptions); 124 *executionContext, request, *this, options, resourceLoaderOptions);
137 } 125 }
138 } 126 }
139 127
140 void FileReaderLoader::start(ExecutionContext* executionContext,
141 PassRefPtr<BlobDataHandle> blobData) {
142 ASSERT(executionContext);
143 m_urlForReadingIsStream = false;
144 startInternal(*executionContext, 0, std::move(blobData));
145 }
146
147 void FileReaderLoader::start(ExecutionContext* executionContext,
148 const Stream& stream,
149 unsigned readSize) {
150 ASSERT(executionContext);
151 if (readSize > 0) {
152 m_hasRange = true;
153 m_rangeStart = 0;
154 m_rangeEnd = readSize - 1; // End is inclusive so (0,0) is a 1-byte read.
155 }
156
157 m_urlForReadingIsStream = true;
158 startInternal(*executionContext, &stream, nullptr);
159 }
160
161 void FileReaderLoader::cancel() { 128 void FileReaderLoader::cancel() {
162 m_errorCode = FileError::kAbortErr; 129 m_errorCode = FileError::kAbortErr;
163 cleanup(); 130 cleanup();
164 } 131 }
165 132
166 void FileReaderLoader::cleanup() { 133 void FileReaderLoader::cleanup() {
167 if (m_loader) { 134 if (m_loader) {
168 m_loader->cancel(); 135 m_loader->cancel();
169 m_loader = nullptr; 136 m_loader = nullptr;
170 } 137 }
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 382
416 m_stringResult = builder.toString(); 383 m_stringResult = builder.toString();
417 } 384 }
418 385
419 void FileReaderLoader::setEncoding(const String& encoding) { 386 void FileReaderLoader::setEncoding(const String& encoding) {
420 if (!encoding.isEmpty()) 387 if (!encoding.isEmpty())
421 m_encoding = WTF::TextEncoding(encoding); 388 m_encoding = WTF::TextEncoding(encoding);
422 } 389 }
423 390
424 } // namespace blink 391 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/fileapi/FileReaderLoader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698